X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=menu.c;h=404dc796fecc7f0b54975713b6b1905aaca2c889;hp=8ff8ace769349a0f8f3ace560e8cbe5655e77f13;hb=7ff4900e87f7b836b9b5904b420f2818e390a073;hpb=fdf0986350bf8b49a817aaf53526904f8ed5b8de diff --git a/menu.c b/menu.c index 8ff8ace..404dc79 100644 --- a/menu.c +++ b/menu.c @@ -1,19 +1,10 @@ /* + * Copyright notice from original mutt: * Copyright (C) 1996-2000 Michael R. Elkins * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. */ #if HAVE_CONFIG_H @@ -21,6 +12,7 @@ #endif #include "mutt.h" +#include "enter.h" #include "mutt_curses.h" #include "mutt_menu.h" #include "mbyte.h" @@ -30,10 +22,14 @@ #include "imap.h" #endif +#include "lib/mem.h" +#include "lib/intl.h" +#include "lib/str.h" + #include #include -extern int Charset_is_utf8; /* FIXME: bad modularisation */ +extern int Charset_is_utf8; /* FIXME: bad modularisation */ extern size_t UngetCount; @@ -41,115 +37,110 @@ static void print_enriched_string (int attr, unsigned char *s, int do_color) { wchar_t wc; size_t k; - size_t n = mutt_strlen ((char *)s); + size_t n = str_len ((char *) s); mbstate_t mbstate; memset (&mbstate, 0, sizeof (mbstate)); - while (*s) - { - if (*s < M_TREE_MAX) - { + while (*s) { + if (*s < M_TREE_MAX) { if (do_color) SETCOLOR (MT_COLOR_TREE); - while (*s && *s < M_TREE_MAX) - { - switch (*s) - { - case M_TREE_LLCORNER: - if (option (OPTASCIICHARS)) - addch ('`'); - else if (Charset_is_utf8) - addstr ("\342\224\224"); /* WACS_LLCORNER */ - else - addch (ACS_LLCORNER); - break; - case M_TREE_ULCORNER: - if (option (OPTASCIICHARS)) - addch (','); - else if (Charset_is_utf8) - addstr ("\342\224\214"); /* WACS_ULCORNER */ - else - addch (ACS_ULCORNER); - break; - case M_TREE_LTEE: - if (option (OPTASCIICHARS)) - addch ('|'); - else if (Charset_is_utf8) - addstr ("\342\224\234"); /* WACS_LTEE */ - else - addch (ACS_LTEE); - break; - case M_TREE_HLINE: - if (option (OPTASCIICHARS)) - addch ('-'); - else if (Charset_is_utf8) - addstr ("\342\224\200"); /* WACS_HLINE */ - else - addch (ACS_HLINE); - break; - case M_TREE_VLINE: - if (option (OPTASCIICHARS)) - addch ('|'); - else if (Charset_is_utf8) - addstr ("\342\224\202"); /* WACS_VLINE */ - else - addch (ACS_VLINE); - break; - case M_TREE_TTEE: - if (option (OPTASCIICHARS)) - addch ('-'); - else if (Charset_is_utf8) - addstr ("\342\224\254"); /* WACS_TTEE */ - else - addch (ACS_TTEE); - break; - case M_TREE_BTEE: - if (option (OPTASCIICHARS)) - addch ('-'); - else if (Charset_is_utf8) - addstr ("\342\224\264"); /* WACS_BTEE */ - else - addch (ACS_BTEE); - break; - case M_TREE_SPACE: - addch (' '); - break; - case M_TREE_RARROW: - addch ('>'); - break; - case M_TREE_STAR: - addch ('*'); /* fake thread indicator */ - break; - case M_TREE_HIDDEN: - addch ('&'); - break; - case M_TREE_EQUALS: - addch ('='); - break; - case M_TREE_MISSING: - addch ('?'); - break; + while (*s && *s < M_TREE_MAX) { + switch (*s) { + case M_TREE_LLCORNER: + if (option (OPTASCIICHARS)) + addch ('`'); + else if (Charset_is_utf8) + addstr ("\342\224\224"); /* WACS_LLCORNER */ + else + addch (ACS_LLCORNER); + break; + case M_TREE_ULCORNER: + if (option (OPTASCIICHARS)) + addch (','); + else if (Charset_is_utf8) + addstr ("\342\224\214"); /* WACS_ULCORNER */ + else + addch (ACS_ULCORNER); + break; + case M_TREE_LTEE: + if (option (OPTASCIICHARS)) + addch ('|'); + else if (Charset_is_utf8) + addstr ("\342\224\234"); /* WACS_LTEE */ + else + addch (ACS_LTEE); + break; + case M_TREE_HLINE: + if (option (OPTASCIICHARS)) + addch ('-'); + else if (Charset_is_utf8) + addstr ("\342\224\200"); /* WACS_HLINE */ + else + addch (ACS_HLINE); + break; + case M_TREE_VLINE: + if (option (OPTASCIICHARS)) + addch ('|'); + else if (Charset_is_utf8) + addstr ("\342\224\202"); /* WACS_VLINE */ + else + addch (ACS_VLINE); + break; + case M_TREE_TTEE: + if (option (OPTASCIICHARS)) + addch ('-'); + else if (Charset_is_utf8) + addstr ("\342\224\254"); /* WACS_TTEE */ + else + addch (ACS_TTEE); + break; + case M_TREE_BTEE: + if (option (OPTASCIICHARS)) + addch ('-'); + else if (Charset_is_utf8) + addstr ("\342\224\264"); /* WACS_BTEE */ + else + addch (ACS_BTEE); + break; + case M_TREE_SPACE: + addch (' '); + break; + case M_TREE_RARROW: + addch ('>'); + break; + case M_TREE_STAR: + addch ('*'); /* fake thread indicator */ + break; + case M_TREE_HIDDEN: + addch ('&'); + break; + case M_TREE_EQUALS: + addch ('='); + break; + case M_TREE_MISSING: + addch ('?'); + break; } s++, n--; } - if (do_color) attrset(attr); + if (do_color) + attrset (attr); } - else if ((k = mbrtowc (&wc, (char *)s, n, &mbstate)) > 0) - { - addnstr ((char *)s, k); - s += k, n-= k; + else if ((k = mbrtowc (&wc, (char *) s, n, &mbstate)) > 0) { + addnstr ((char *) s, k); + s += k, n -= k; } else break; } } -static void menu_make_entry (char *s, int l, MUTTMENU *menu, int i) +static void menu_make_entry (char *s, int l, MUTTMENU * menu, int i) { - if (menu->dialog) - { + if (menu->dialog) { strncpy (s, menu->dialog[i], l); - menu->current = -1; /* hide menubar */ + menu->current = -1; /* hide menubar */ } else menu->make_entry (s, l, menu, i); @@ -158,36 +149,35 @@ static void menu_make_entry (char *s, int l, MUTTMENU *menu, int i) void menu_pad_string (char *s, size_t n) { int shift = option (OPTARROWCURSOR) ? 3 : 0; - int cols; - char* tmpbuf = safe_malloc (n); - if (option(OPTMBOXPANE)) + int cols; + char *tmpbuf = mem_malloc (n); + + if (option (OPTMBOXPANE)) cols = COLS - shift - SidebarWidth; else cols = COLS - shift; - mutt_format_string (tmpbuf, n, cols, cols, 0, ' ', s, strlen (s), 1); + mutt_format_string (tmpbuf, n, cols, cols, 0, ' ', s, str_len (s), 1); tmpbuf[n - 1] = 0; - snprintf(s,n,"%s",tmpbuf); /* overkill */ - FREE(&tmpbuf); + snprintf (s, n, "%s", tmpbuf); /* overkill */ + mem_free (&tmpbuf); } -void menu_redraw_full (MUTTMENU *menu) +void menu_redraw_full (MUTTMENU * menu) { SETCOLOR (MT_COLOR_NORMAL); /* clear() doesn't optimize screen redraws */ move (0, 0); clrtobot (); - if (option (OPTHELP)) - { + if (option (OPTHELP)) { SETCOLOR (MT_COLOR_STATUS); - move (option (OPTSTATUSONTOP) ? LINES-2 : 0, 0); + move (option (OPTSTATUSONTOP) ? LINES - 2 : 0, 0); mutt_paddstr (COLS, menu->help); SETCOLOR (MT_COLOR_NORMAL); menu->offset = 1; menu->pagelen = LINES - 3; } - else - { + else { menu->offset = option (OPTSTATUSONTOP) ? 1 : 0; menu->pagelen = LINES - 2; } @@ -197,7 +187,7 @@ void menu_redraw_full (MUTTMENU *menu) menu->redraw = REDRAW_INDEX | REDRAW_STATUS; } -void menu_redraw_status (MUTTMENU *menu) +void menu_redraw_status (MUTTMENU * menu) { char buf[STRING]; @@ -209,50 +199,48 @@ void menu_redraw_status (MUTTMENU *menu) menu->redraw &= ~REDRAW_STATUS; } -void menu_redraw_index (MUTTMENU *menu) +void menu_redraw_index (MUTTMENU * menu) { char buf[STRING]; int i; - draw_sidebar(1); - for (i = menu->top; i < menu->top + menu->pagelen; i++) - { - if (i < menu->max) - { + sidebar_draw (1); + for (i = menu->top; i < menu->top + menu->pagelen; i++) { + if (i < menu->max) { menu_make_entry (buf, sizeof (buf), menu, i); menu_pad_string (buf, sizeof (buf)); - if (option (OPTARROWCURSOR)) - { + if (option (OPTARROWCURSOR)) { attrset (menu->color (i)); CLEARLINE_WIN (i - menu->top + menu->offset); - if (i == menu->current) - { + if (i == menu->current) { attrset (menu->color (i)); ADDCOLOR (MT_COLOR_INDICATOR); addstr ("->"); attrset (menu->color (i)); addch (' '); } - else - move (i - menu->top + menu->offset, SidebarWidth + 3); + else { + attrset (menu->color (i)); + move (i - menu->top + menu->offset, SidebarWidth); + addstr (" "); + } - print_enriched_string (menu->color(i), (unsigned char *) buf, 1); - SETCOLOR (MT_COLOR_NORMAL); + print_enriched_string (menu->color (i), (unsigned char *) buf, 1); + SETCOLOR (MT_COLOR_NORMAL); } - else - { + else { attrset (menu->color (i)); - - if (i == menu->current) - { + + if (i == menu->current) { ADDCOLOR (MT_COLOR_INDICATOR); BKGDSET (MT_COLOR_INDICATOR); } CLEARLINE_WIN (i - menu->top + menu->offset); - print_enriched_string (menu->color(i), (unsigned char *) buf, i != menu->current); + print_enriched_string (menu->color (i), (unsigned char *) buf, + i != menu->current); SETCOLOR (MT_COLOR_NORMAL); BKGDSET (MT_COLOR_NORMAL); } @@ -263,33 +251,31 @@ void menu_redraw_index (MUTTMENU *menu) menu->redraw = 0; } -void menu_redraw_motion (MUTTMENU *menu) +void menu_redraw_motion (MUTTMENU * menu) { char buf[STRING]; - if (menu->dialog) - { + if (menu->dialog) { menu->redraw &= ~REDRAW_MOTION; return; } - + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth); SETCOLOR (MT_COLOR_NORMAL); BKGDSET (MT_COLOR_NORMAL); - if (option (OPTARROWCURSOR)) - { + if (option (OPTARROWCURSOR)) { /* clear the pointer */ attrset (menu->color (menu->oldcurrent)); addstr (" "); - if (menu->redraw & REDRAW_MOTION_RESYNCH) - { + if (menu->redraw & REDRAW_MOTION_RESYNCH) { clrtoeol (); menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent); menu_pad_string (buf, sizeof (buf)); move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth + 3); - print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1); + print_enriched_string (menu->color (menu->oldcurrent), + (unsigned char *) buf, 1); SETCOLOR (MT_COLOR_NORMAL); } @@ -300,14 +286,14 @@ void menu_redraw_motion (MUTTMENU *menu) addstr ("->"); SETCOLOR (MT_COLOR_NORMAL); } - else - { + else { /* erase the current indicator */ attrset (menu->color (menu->oldcurrent)); clrtoeol (); menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent); menu_pad_string (buf, sizeof (buf)); - print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1); + print_enriched_string (menu->color (menu->oldcurrent), + (unsigned char *) buf, 1); /* now draw the new one to reflect the change */ menu_make_entry (buf, sizeof (buf), menu, menu->current); @@ -316,24 +302,25 @@ void menu_redraw_motion (MUTTMENU *menu) ADDCOLOR (MT_COLOR_INDICATOR); BKGDSET (MT_COLOR_INDICATOR); CLEARLINE_WIN (menu->current - menu->top + menu->offset); - print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0); + print_enriched_string (menu->color (menu->current), (unsigned char *) buf, + 0); SETCOLOR (MT_COLOR_NORMAL); BKGDSET (MT_COLOR_NORMAL); } menu->redraw &= REDRAW_STATUS; } -void menu_redraw_current (MUTTMENU *menu) +void menu_redraw_current (MUTTMENU * menu) { char buf[STRING]; - + move (menu->current + menu->offset - menu->top, SidebarWidth); menu_make_entry (buf, sizeof (buf), menu, menu->current); menu_pad_string (buf, sizeof (buf)); - if (option (OPTARROWCURSOR)) - { + if (option (OPTARROWCURSOR)) { int attr = menu->color (menu->current); + attrset (attr); clrtoeol (); attrset (menu->color (menu->current)); @@ -342,28 +329,27 @@ void menu_redraw_current (MUTTMENU *menu) attrset (attr); addch (' '); menu_pad_string (buf, sizeof (buf)); - print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 1); + print_enriched_string (menu->color (menu->current), (unsigned char *) buf, + 1); SETCOLOR (MT_COLOR_NORMAL); } - else - { + else { attrset (menu->color (menu->current)); ADDCOLOR (MT_COLOR_INDICATOR); BKGDSET (MT_COLOR_INDICATOR); clrtoeol (); - print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0); + print_enriched_string (menu->color (menu->current), (unsigned char *) buf, + 0); SETCOLOR (MT_COLOR_NORMAL); BKGDSET (MT_COLOR_NORMAL); } menu->redraw &= REDRAW_STATUS; } -void menu_redraw_prompt (MUTTMENU *menu) +void menu_redraw_prompt (MUTTMENU * menu) { - if (menu->dialog) - { - if (option (OPTMSGERR)) - { + if (menu->dialog) { + if (option (OPTMSGERR)) { mutt_sleep (1); unset_option (OPTMSGERR); } @@ -377,31 +363,33 @@ void menu_redraw_prompt (MUTTMENU *menu) } } -void menu_check_recenter (MUTTMENU *menu) +void menu_check_recenter (MUTTMENU * menu) { int c = MIN (MenuContext, menu->pagelen / 2); int old_top = menu->top; - if (!option (OPTMENUMOVEOFF) && menu->max <= menu->pagelen) /* less entries than lines */ - { + if (!option (OPTMENUMOVEOFF) && menu->max <= menu->pagelen) { /* less entries than lines */ if (menu->top != 0) { menu->top = 0; set_option (OPTNEEDREDRAW); } } - else if (menu->current >= menu->top + menu->pagelen - c) /* indicator below bottom threshold */ - { + else if (menu->current >= menu->top + menu->pagelen - c) { /* indicator below bottom threshold */ if (option (OPTMENUSCROLL) || (menu->pagelen <= 0)) menu->top = menu->current - menu->pagelen + c + 1; else - menu->top += (menu->pagelen - c) * ((menu->current - menu->top) / (menu->pagelen - c)) - c; + menu->top += + (menu->pagelen - + c) * ((menu->current - menu->top) / (menu->pagelen - c)) - c; } - else if (menu->current < menu->top + c) /* indicator above top threshold */ - { + else if (menu->current < menu->top + c) { /* indicator above top threshold */ if (option (OPTMENUSCROLL) || (menu->pagelen <= 0)) menu->top = menu->current - c; else - menu->top -= (menu->pagelen - c) * ((menu->top + menu->pagelen - 1 - menu->current) / (menu->pagelen - c)) - c; + menu->top -= + (menu->pagelen - + c) * ((menu->top + menu->pagelen - 1 - + menu->current) / (menu->pagelen - c)) - c; } if (!option (OPTMENUMOVEOFF)) /* make entries stick to bottom */ @@ -412,20 +400,17 @@ void menu_check_recenter (MUTTMENU *menu) menu->redraw |= REDRAW_INDEX; } -void menu_jump (MUTTMENU *menu) +void menu_jump (MUTTMENU * menu) { int n; char buf[SHORT_STRING]; - if (menu->max) - { + if (menu->max) { mutt_ungetch (LastKey, 0); buf[0] = 0; - if (mutt_get_field (_("Jump to: "), buf, sizeof (buf), 0) == 0 && buf[0]) - { + if (mutt_get_field (_("Jump to: "), buf, sizeof (buf), 0) == 0 && buf[0]) { n = atoi (buf) - 1; - if (n >= 0 && n < menu->max) - { + if (n >= 0 && n < menu->max) { menu->current = n; menu->redraw = REDRAW_MOTION; } @@ -437,15 +422,15 @@ void menu_jump (MUTTMENU *menu) mutt_error _("No entries."); } -void menu_next_line (MUTTMENU *menu) +void menu_next_line (MUTTMENU * menu) { - if (menu->max) - { + if (menu->max) { int c = MIN (MenuContext, menu->pagelen / 2); - if (menu->top + 1 < menu->max - c - && (option(OPTMENUMOVEOFF) || (menu->max > menu->pagelen && menu->top < menu->max - menu->pagelen))) - { + if (menu->top + 1 < menu->max - c && (option (OPTMENUMOVEOFF) + || (menu->max > menu->pagelen + && menu->top < + menu->max - menu->pagelen))) { menu->top++; if (menu->current < menu->top + c && menu->current < menu->max - 1) menu->current++; @@ -458,10 +443,9 @@ void menu_next_line (MUTTMENU *menu) mutt_error _("No entries."); } -void menu_prev_line (MUTTMENU *menu) +void menu_prev_line (MUTTMENU * menu) { - if (menu->top > 0) - { + if (menu->top > 0) { int c = MIN (MenuContext, menu->pagelen / 2); menu->top--; @@ -473,19 +457,16 @@ void menu_prev_line (MUTTMENU *menu) mutt_error _("You cannot scroll up farther."); } -void menu_next_page (MUTTMENU *menu) +void menu_next_page (MUTTMENU * menu) { - if (menu->max) - { - if (menu->top + menu->pagelen < menu->max) - { + if (menu->max) { + if (menu->top + menu->pagelen < menu->max) { menu->top += menu->pagelen; if (menu->current < menu->top) menu->current = menu->top; menu->redraw = REDRAW_INDEX; } - else if (menu->current != menu->max - 1 && !menu->dialog) - { + else if (menu->current != menu->max - 1 && !menu->dialog) { menu->current = menu->max - 1; menu->redraw = REDRAW_MOTION; } @@ -496,20 +477,18 @@ void menu_next_page (MUTTMENU *menu) mutt_error _("No entries."); } -void menu_prev_page (MUTTMENU *menu) +void menu_prev_page (MUTTMENU * menu) { int c = MIN (MenuContext, menu->pagelen / 2); - if (menu->top > c) - { + if (menu->top > c) { if ((menu->top -= menu->pagelen) < 0) menu->top = 0; if (menu->current >= menu->top + menu->pagelen) menu->current = menu->top + menu->pagelen - 1; menu->redraw = REDRAW_INDEX; } - else if (menu->current && !menu->dialog) - { + else if (menu->current && !menu->dialog) { menu->current = 0; menu->redraw = REDRAW_MOTION; } @@ -517,19 +496,17 @@ void menu_prev_page (MUTTMENU *menu) mutt_error _("You are on the first page."); } -void menu_top_page (MUTTMENU *menu) +void menu_top_page (MUTTMENU * menu) { - if (menu->current != menu->top) - { + if (menu->current != menu->top) { menu->current = menu->top; menu->redraw = REDRAW_MOTION; } } -void menu_bottom_page (MUTTMENU *menu) +void menu_bottom_page (MUTTMENU * menu) { - if (menu->max) - { + if (menu->max) { menu->current = menu->top + menu->pagelen - 1; if (menu->current > menu->max - 1) menu->current = menu->max - 1; @@ -539,12 +516,11 @@ void menu_bottom_page (MUTTMENU *menu) mutt_error _("No entries."); } -void menu_middle_page (MUTTMENU *menu) +void menu_middle_page (MUTTMENU * menu) { int i; - if (menu->max) - { + if (menu->max) { i = menu->top + menu->pagelen; if (i > menu->max - 1) i = menu->max - 1; @@ -555,10 +531,9 @@ void menu_middle_page (MUTTMENU *menu) mutt_error _("No entries."); } -void menu_first_entry (MUTTMENU *menu) +void menu_first_entry (MUTTMENU * menu) { - if (menu->max) - { + if (menu->max) { menu->current = 0; menu->redraw = REDRAW_MOTION; } @@ -566,10 +541,9 @@ void menu_first_entry (MUTTMENU *menu) mutt_error _("No entries."); } -void menu_last_entry (MUTTMENU *menu) +void menu_last_entry (MUTTMENU * menu) { - if (menu->max) - { + if (menu->max) { menu->current = menu->max - 1; menu->redraw = REDRAW_MOTION; } @@ -577,18 +551,16 @@ void menu_last_entry (MUTTMENU *menu) mutt_error _("No entries."); } -void menu_half_up (MUTTMENU *menu) +void menu_half_up (MUTTMENU * menu) { - if (menu->top > 0) - { + if (menu->top > 0) { if ((menu->top -= menu->pagelen / 2) < 0) menu->top = 0; if (menu->current >= menu->top + menu->pagelen) menu->current = menu->top + menu->pagelen - 1; menu->redraw = REDRAW_INDEX; } - else if (menu->current && !menu->dialog) - { + else if (menu->current && !menu->dialog) { menu->current = 0; menu->redraw = REDRAW_MOTION; } @@ -596,19 +568,16 @@ void menu_half_up (MUTTMENU *menu) mutt_error _("First entry is shown."); } -void menu_half_down (MUTTMENU *menu) +void menu_half_down (MUTTMENU * menu) { - if (menu->max) - { - if (menu->top + menu->pagelen < menu->max) - { + if (menu->max) { + if (menu->top + menu->pagelen < menu->max) { menu->top += menu->pagelen / 2; if (menu->current < menu->top) menu->current = menu->top; menu->redraw = REDRAW_INDEX; } - else if (menu->current != menu->max - 1 && !menu->dialog) - { + else if (menu->current != menu->max - 1 && !menu->dialog) { menu->current = menu->max - 1; menu->redraw = REDRAW_INDEX; } @@ -619,10 +588,9 @@ void menu_half_down (MUTTMENU *menu) mutt_error _("No entries."); } -void menu_current_top (MUTTMENU *menu) +void menu_current_top (MUTTMENU * menu) { - if (menu->max) - { + if (menu->max) { menu->top = menu->current; menu->redraw = REDRAW_INDEX; } @@ -630,10 +598,9 @@ void menu_current_top (MUTTMENU *menu) mutt_error _("No entries."); } -void menu_current_middle (MUTTMENU *menu) +void menu_current_middle (MUTTMENU * menu) { - if (menu->max) - { + if (menu->max) { menu->top = menu->current - menu->pagelen / 2; if (menu->top < 0) menu->top = 0; @@ -643,10 +610,9 @@ void menu_current_middle (MUTTMENU *menu) mutt_error _("No entries."); } -void menu_current_bottom (MUTTMENU *menu) +void menu_current_bottom (MUTTMENU * menu) { - if (menu->max) - { + if (menu->max) { menu->top = menu->current - menu->pagelen + 1; if (menu->top < 0) menu->top = 0; @@ -656,10 +622,9 @@ void menu_current_bottom (MUTTMENU *menu) mutt_error _("No entries."); } -void menu_next_entry (MUTTMENU *menu) +void menu_next_entry (MUTTMENU * menu) { - if (menu->current < menu->max - 1) - { + if (menu->current < menu->max - 1) { menu->current++; menu->redraw = REDRAW_MOTION; } @@ -667,10 +632,9 @@ void menu_next_entry (MUTTMENU *menu) mutt_error _("You are on the last entry."); } -void menu_prev_entry (MUTTMENU *menu) +void menu_prev_entry (MUTTMENU * menu) { - if (menu->current) - { + if (menu->current) { menu->current--; menu->redraw = REDRAW_MOTION; } @@ -680,10 +644,10 @@ void menu_prev_entry (MUTTMENU *menu) static int default_color (int i) { - return ColorDefs[MT_COLOR_NORMAL]; + return ColorDefs[MT_COLOR_NORMAL]; } -static int menu_search_generic (MUTTMENU *m, regex_t *re, int n) +static int menu_search_generic (MUTTMENU * m, regex_t * re, int n) { char buf[LONG_STRING]; @@ -693,7 +657,7 @@ static int menu_search_generic (MUTTMENU *m, regex_t *re, int n) MUTTMENU *mutt_new_menu (void) { - MUTTMENU *p = (MUTTMENU *) safe_calloc (1, sizeof (MUTTMENU)); + MUTTMENU *p = (MUTTMENU *) mem_calloc (1, sizeof (MUTTMENU)); p->current = 0; p->top = 0; @@ -705,48 +669,45 @@ MUTTMENU *mutt_new_menu (void) return (p); } -void mutt_menuDestroy (MUTTMENU **p) +void mutt_menuDestroy (MUTTMENU ** p) { int i; - FREE (&(*p)->searchBuf); + mem_free (&(*p)->searchBuf); - if ((*p)->dialog) - { - for (i=0; i < (*p)->max; i++) - FREE (&(*p)->dialog[i]); + if ((*p)->dialog) { + for (i = 0; i < (*p)->max; i++) + mem_free (&(*p)->dialog[i]); - FREE (& (*p)->dialog); + mem_free (&(*p)->dialog); } - FREE (p); + mem_free (p); } #define M_SEARCH_UP 1 #define M_SEARCH_DOWN 2 -static int menu_search (MUTTMENU *menu, int op) +static int menu_search (MUTTMENU * menu, int op) { int r; int searchDir; regex_t re; char buf[SHORT_STRING]; - if (op != OP_SEARCH_NEXT && op != OP_SEARCH_OPPOSITE) - { + if (op != OP_SEARCH_NEXT && op != OP_SEARCH_OPPOSITE) { strfcpy (buf, menu->searchBuf ? menu->searchBuf : "", sizeof (buf)); - if (mutt_get_field ((op == OP_SEARCH) ? _("Search for: ") : - _("Reverse search for: "), - buf, sizeof (buf), M_CLEAR) != 0 || !buf[0]) + if (mutt_get_field ((op == OP_SEARCH) ? _("Search for: ") : + _("Reverse search for: "), + buf, sizeof (buf), M_CLEAR) != 0 || !buf[0]) return (-1); - mutt_str_replace (&menu->searchBuf, buf); + str_replace (&menu->searchBuf, buf); menu->searchDir = (op == OP_SEARCH) ? M_SEARCH_DOWN : M_SEARCH_UP; } - else - { - if (!menu->searchBuf) - { + else { + if (!menu->searchBuf) { mutt_error _("No search pattern."); + return (-1); } } @@ -755,8 +716,9 @@ static int menu_search (MUTTMENU *menu, int op) if (op == OP_SEARCH_OPPOSITE) searchDir = -searchDir; - if ((r = REGCOMP (&re, menu->searchBuf, REG_NOSUB | mutt_which_case (menu->searchBuf))) != 0) - { + if ((r = + REGCOMP (&re, menu->searchBuf, + REG_NOSUB | mutt_which_case (menu->searchBuf))) != 0) { regerror (r, &re, buf, sizeof (buf)); regfree (&re); mutt_error ("%s", buf); @@ -764,10 +726,8 @@ static int menu_search (MUTTMENU *menu, int op) } r = menu->current + searchDir; - while (r >= 0 && r < menu->max) - { - if (menu->search (menu, &re, r) == 0) - { + while (r >= 0 && r < menu->max) { + if (menu->search (menu, &re, r) == 0) { regfree (&re); return r; } @@ -777,66 +737,64 @@ static int menu_search (MUTTMENU *menu, int op) regfree (&re); mutt_error _("Not found."); + return (-1); } static int menu_dialog_translate_op (int i) { - switch (i) - { - case OP_NEXT_ENTRY: - return OP_NEXT_LINE; - case OP_PREV_ENTRY: - return OP_PREV_LINE; - case OP_CURRENT_TOP: case OP_FIRST_ENTRY: - return OP_TOP_PAGE; - case OP_CURRENT_BOTTOM: case OP_LAST_ENTRY: - return OP_BOTTOM_PAGE; - case OP_CURRENT_MIDDLE: - return OP_MIDDLE_PAGE; + switch (i) { + case OP_NEXT_ENTRY: + return OP_NEXT_LINE; + case OP_PREV_ENTRY: + return OP_PREV_LINE; + case OP_CURRENT_TOP: + case OP_FIRST_ENTRY: + return OP_TOP_PAGE; + case OP_CURRENT_BOTTOM: + case OP_LAST_ENTRY: + return OP_BOTTOM_PAGE; + case OP_CURRENT_MIDDLE: + return OP_MIDDLE_PAGE; } - + return i; } -static int menu_dialog_dokey (MUTTMENU *menu, int *ip) +static int menu_dialog_dokey (MUTTMENU * menu, int *ip) { event_t ch; char *p; ch = mutt_getch (); - if (ch.ch == -1) - { + if (ch.ch == -1) { *ip = -1; return 0; } - if (ch.ch && (p = strchr (menu->keys, ch.ch))) - { + if (ch.ch && (p = strchr (menu->keys, ch.ch))) { *ip = OP_MAX + (p - menu->keys + 1); return 0; } - else - { + else { mutt_ungetch (ch.op ? 0 : ch.ch, ch.op ? ch.op : 0); return -1; } } -int menu_redraw (MUTTMENU *menu) +int menu_redraw (MUTTMENU * menu) { /* See if all or part of the screen needs to be updated. */ - if (menu->redraw & REDRAW_FULL) - { + if (menu->redraw & REDRAW_FULL) { menu_redraw_full (menu); /* allow the caller to do any local configuration */ return (OP_REDRAW); } - + if (!menu->dialog) menu_check_recenter (menu); - + if (menu->redraw & REDRAW_STATUS) menu_redraw_status (menu); if (menu->redraw & REDRAW_INDEX) @@ -845,26 +803,24 @@ int menu_redraw (MUTTMENU *menu) menu_redraw_motion (menu); else if (menu->redraw == REDRAW_CURRENT) menu_redraw_current (menu); - + if (menu->dialog) menu_redraw_prompt (menu); - + return OP_NULL; } -int mutt_menuLoop (MUTTMENU *menu) +int mutt_menuLoop (MUTTMENU * menu) { int i = OP_NULL; - FOREVER - { - if (option (OPTMENUCALLER)) - { + FOREVER { + if (option (OPTMENUCALLER)) { unset_option (OPTMENUCALLER); return OP_NULL; } - - + + mutt_curs_set (0); #ifdef USE_IMAP @@ -873,45 +829,48 @@ int mutt_menuLoop (MUTTMENU *menu) if (menu_redraw (menu) == OP_REDRAW) return OP_REDRAW; - - menu->oldcurrent = menu->current; + menu->oldcurrent = menu->current; - /* move the cursor out of the way */ - move (menu->current - menu->top + menu->offset, - (option (OPTARROWCURSOR) ? 2 : COLS-1)); + if (option (OPTARROWCURSOR)) + move (menu->current - menu->top + menu->offset, 2); + else if (option (OPTBRAILLEFRIENDLY)) + move (menu->current - menu->top + menu->offset, 0); + else + move (menu->current - menu->top + menu->offset, COLS - 1); mutt_refresh (); - + + /* try to catch dialog keys before ops */ if (menu->dialog && menu_dialog_dokey (menu, &i) == 0) return i; - + i = km_dokey (menu->menu); - if (i == OP_TAG_PREFIX || i == OP_TAG_PREFIX_COND) - { - if (menu->tagged) - { + if (i == OP_TAG_PREFIX || i == OP_TAG_PREFIX_COND) { + if (menu->tagged) { mvaddstr (LINES - 1, 0, "Tag-"); clrtoeol (); i = km_dokey (menu->menu); menu->tagprefix = 1; CLEARLINE (LINES - 1); } - else if (i == OP_TAG_PREFIX) - { + else if (i == OP_TAG_PREFIX) { mutt_error _("No tagged entries."); + i = -1; } - else /* None tagged, OP_TAG_PREFIX_COND */ - { + else { /* None tagged, OP_TAG_PREFIX_COND */ + event_t tmp; - while(UngetCount>0) - { - tmp=mutt_getch(); - if(tmp.op==OP_END_COND)break; + + while (UngetCount > 0) { + tmp = mutt_getch (); + if (tmp.op == OP_END_COND) + break; } mutt_message _("Nothing to do."); + i = -1; } } @@ -923,12 +882,11 @@ int mutt_menuLoop (MUTTMENU *menu) mutt_curs_set (1); #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM) - if (SigWinch) - { + if (SigWinch) { mutt_resize_screen (); menu->redraw = REDRAW_FULL; SigWinch = 0; - clearok(stdscr,TRUE);/*force complete redraw*/ + clearok (stdscr, TRUE); /*force complete redraw */ } #endif @@ -939,149 +897,144 @@ int mutt_menuLoop (MUTTMENU *menu) mutt_clear_error (); /* Convert menubar movement to scrolling */ - if (menu->dialog) + if (menu->dialog) i = menu_dialog_translate_op (i); - switch (i) - { - case OP_NEXT_ENTRY: - menu_next_entry (menu); - break; - case OP_PREV_ENTRY: - menu_prev_entry (menu); - break; - case OP_HALF_DOWN: - menu_half_down (menu); - break; - case OP_HALF_UP: - menu_half_up (menu); - break; - case OP_NEXT_PAGE: - menu_next_page (menu); - break; - case OP_PREV_PAGE: - menu_prev_page (menu); - break; - case OP_NEXT_LINE: - menu_next_line (menu); - break; - case OP_PREV_LINE: - menu_prev_line (menu); - break; - case OP_FIRST_ENTRY: - menu_first_entry (menu); - break; - case OP_LAST_ENTRY: - menu_last_entry (menu); - break; - case OP_TOP_PAGE: - menu_top_page (menu); - break; - case OP_MIDDLE_PAGE: - menu_middle_page (menu); - break; - case OP_BOTTOM_PAGE: - menu_bottom_page (menu); - break; - case OP_CURRENT_TOP: - menu_current_top (menu); - break; - case OP_CURRENT_MIDDLE: - menu_current_middle (menu); - break; - case OP_CURRENT_BOTTOM: - menu_current_bottom (menu); - break; - case OP_SEARCH: - case OP_SEARCH_REVERSE: - case OP_SEARCH_NEXT: - case OP_SEARCH_OPPOSITE: - if (menu->search && !menu->dialog) /* Searching dialogs won't work */ - { - menu->oldcurrent = menu->current; - if ((menu->current = menu_search (menu, i)) != -1) - menu->redraw = REDRAW_MOTION; - else - menu->current = menu->oldcurrent; - } + switch (i) { + case OP_NEXT_ENTRY: + menu_next_entry (menu); + break; + case OP_PREV_ENTRY: + menu_prev_entry (menu); + break; + case OP_HALF_DOWN: + menu_half_down (menu); + break; + case OP_HALF_UP: + menu_half_up (menu); + break; + case OP_NEXT_PAGE: + menu_next_page (menu); + break; + case OP_PREV_PAGE: + menu_prev_page (menu); + break; + case OP_NEXT_LINE: + menu_next_line (menu); + break; + case OP_PREV_LINE: + menu_prev_line (menu); + break; + case OP_FIRST_ENTRY: + menu_first_entry (menu); + break; + case OP_LAST_ENTRY: + menu_last_entry (menu); + break; + case OP_TOP_PAGE: + menu_top_page (menu); + break; + case OP_MIDDLE_PAGE: + menu_middle_page (menu); + break; + case OP_BOTTOM_PAGE: + menu_bottom_page (menu); + break; + case OP_CURRENT_TOP: + menu_current_top (menu); + break; + case OP_CURRENT_MIDDLE: + menu_current_middle (menu); + break; + case OP_CURRENT_BOTTOM: + menu_current_bottom (menu); + break; + case OP_SEARCH: + case OP_SEARCH_REVERSE: + case OP_SEARCH_NEXT: + case OP_SEARCH_OPPOSITE: + if (menu->search && !menu->dialog) { /* Searching dialogs won't work */ + menu->oldcurrent = menu->current; + if ((menu->current = menu_search (menu, i)) != -1) + menu->redraw = REDRAW_MOTION; else - mutt_error _("Search is not implemented for this menu."); - break; + menu->current = menu->oldcurrent; + } + else + mutt_error _("Search is not implemented for this menu."); + break; - case OP_JUMP: - if (menu->dialog) - mutt_error _("Jumping is not implemented for dialogs."); - else - menu_jump (menu); - break; - - case OP_ENTER_COMMAND: - CurrentMenu = menu->menu; - mutt_enter_command (); - if (option (OPTFORCEREDRAWINDEX)) - { - menu->redraw = REDRAW_FULL; - unset_option (OPTFORCEREDRAWINDEX); - unset_option (OPTFORCEREDRAWPAGER); + case OP_JUMP: + if (menu->dialog) + mutt_error (_("Jumping is not implemented for dialogs.")); + + else + menu_jump (menu); + break; + + case OP_ENTER_COMMAND: + CurrentMenu = menu->menu; + mutt_enter_command (); + if (option (OPTFORCEREDRAWINDEX)) { + menu->redraw = REDRAW_FULL; + unset_option (OPTFORCEREDRAWINDEX); + unset_option (OPTFORCEREDRAWPAGER); + } + break; + + case OP_TAG: + if (menu->tag && !menu->dialog) { + if (menu->tagprefix && !option (OPTAUTOTAG)) { + for (i = 0; i < menu->max; i++) + menu->tagged += menu->tag (menu, i, 0); + menu->redraw = REDRAW_INDEX; } - break; - - case OP_TAG: - if (menu->tag && !menu->dialog) - { - if (menu->tagprefix && !option (OPTAUTOTAG)) - { - for (i = 0; i < menu->max; i++) - menu->tagged += menu->tag (menu, i, 0); - menu->redraw = REDRAW_INDEX; - } - else if (menu->max) - { - int i = menu->tag (menu, menu->current, -1); - menu->tagged += i; - if (i && option (OPTRESOLVE) && menu->current < menu->max - 1) - { - menu->current++; - menu->redraw = REDRAW_MOTION_RESYNCH; - } - else - menu->redraw = REDRAW_CURRENT; + else if (menu->max) { + int i = menu->tag (menu, menu->current, -1); + + menu->tagged += i; + if (i && option (OPTRESOLVE) && menu->current < menu->max - 1) { + menu->current++; + menu->redraw = REDRAW_MOTION_RESYNCH; } else - mutt_error _("No entries."); + menu->redraw = REDRAW_CURRENT; } else - mutt_error _("Tagging is not supported."); - break; + mutt_error _("No entries."); + } + else + mutt_error _("Tagging is not supported."); + break; - case OP_SHELL_ESCAPE: - mutt_shell_escape (); - MAYBE_REDRAW (menu->redraw); - break; + case OP_SHELL_ESCAPE: + mutt_shell_escape (); + MAYBE_REDRAW (menu->redraw); + break; - case OP_WHAT_KEY: - mutt_what_key (); - break; + case OP_WHAT_KEY: + mutt_what_key (); + break; - case OP_REDRAW: - clearok (stdscr, TRUE); - menu->redraw = REDRAW_FULL; - break; + case OP_REDRAW: + clearok (stdscr, TRUE); + menu->redraw = REDRAW_FULL; + break; - case OP_HELP: - mutt_help (menu->menu); - menu->redraw = REDRAW_FULL; - break; + case OP_HELP: + mutt_help (menu->menu); + menu->redraw = REDRAW_FULL; + break; - case OP_NULL: - km_error_key (menu->menu); - break; + case OP_NULL: + km_error_key (menu->menu); + break; - case OP_END_COND: - break; + case OP_END_COND: + break; - default: - return (i); + default: + return (i); } } /* not reached */