X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-ui%2Fmenu.c;h=0a1d716d17377249b5fdb7ad8d33e1fd7e5d1f30;hp=6290e99714f4ddfae6679ef32ad658ca32183ff2;hb=5dcac54e5db074dc4572f843666c7f7acaf2d109;hpb=c438da3f93727117c7af936b48a85f7747d3b087 diff --git a/lib-ui/menu.c b/lib-ui/menu.c index 6290e99..0a1d716 100644 --- a/lib-ui/menu.c +++ b/lib-ui/menu.c @@ -7,28 +7,16 @@ * please see the file GPL in the top level source directory. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif +#include -#include -#include -#include - -#include "curses.h" #include "enter.h" #include "menu.h" #include "mutt.h" #include "charset.h" -#include "sidebar.h" #include - -#include -#include - -#include +#include #define SW (option(OPTMBOXPANE)?SidebarWidth:0) @@ -49,87 +37,52 @@ static void print_enriched_string (int attr, unsigned char *s, int do_color) 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); + waddch (stdscr, 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); + waddch (stdscr, 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); + waddch (stdscr, 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); + waddch (stdscr, 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); + waddch (stdscr, 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); + waddch (stdscr, 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); + waddch (stdscr, ACS_BTEE); break; case M_TREE_SPACE: - addch (' '); + waddch (stdscr, ' '); break; case M_TREE_RARROW: - addch ('>'); + waddch (stdscr, '>'); break; case M_TREE_STAR: - addch ('*'); /* fake thread indicator */ + waddch (stdscr, '*'); /* fake thread indicator */ break; case M_TREE_HIDDEN: - addch ('&'); + waddch (stdscr, '&'); break; case M_TREE_EQUALS: - addch ('='); + waddch (stdscr, '='); break; case M_TREE_MISSING: - addch ('?'); + waddch (stdscr, '?'); break; } s++, n--; } if (do_color) - attrset (attr); + wattrset (stdscr, attr); } - else if ((k = mbrtowc (&wc, (char *) s, n, &mbstate)) > 0) { - addnstr ((char *) s, k); + else if ((k = mbrtowc (&wc, (char *) s, n, &mbstate)) != (size_t)-1) { + waddnstr (stdscr, (char *) s, k); s += k, n -= k; } else @@ -147,16 +100,11 @@ static void menu_make_entry (char *s, int l, MUTTMENU * menu, int i) menu->make_entry (s, l, menu, i); } -void menu_pad_string (char *s, size_t n) +static void menu_pad_string (char *s, size_t n) { - int shift = option (OPTARROWCURSOR) ? 3 : 0; - int cols; + int cols = COLS - SW; char *tmpbuf = p_new(char, n); - if (option (OPTMBOXPANE)) - cols = COLS - shift - SidebarWidth; - else - cols = COLS - shift; mutt_format_string (tmpbuf, n, cols, cols, 0, ' ', s, m_strlen(s), 1); tmpbuf[n - 1] = 0; snprintf (s, n, "%s", tmpbuf); /* overkill */ @@ -166,25 +114,16 @@ void menu_pad_string (char *s, size_t n) void menu_redraw_full (MUTTMENU * menu) { SETCOLOR (MT_COLOR_NORMAL); - /* clear() doesn't optimize screen redraws */ - move (0, 0); - clrtobot (); - - if (option (OPTHELP)) { - SETCOLOR (MT_COLOR_STATUS); - move (option (OPTSTATUSONTOP) ? LINES - 2 : 0, SW); - mutt_paddstr (COLS-SW, menu->help); - SETCOLOR (MT_COLOR_NORMAL); - menu->offset = 1; - menu->pagelen = LINES - 3; - } - else { - menu->offset = option (OPTSTATUSONTOP) ? 1 : 0; - menu->pagelen = LINES - 2; - } - - sidebar_draw_frames(); + /* wclear(stdscr) doesn't optimize screen redraws */ + wmove (stdscr, 0, 0); + wclrtobot (stdscr); + SETCOLOR (MT_COLOR_STATUS); + wmove (stdscr, option (OPTSTATUSONTOP) ? LINES - 2 : 0, SW); + mutt_paddstr (COLS-SW, ""); + SETCOLOR (MT_COLOR_NORMAL); + menu->offset = 1; + menu->pagelen = LINES - 3; mutt_show_error (); menu->redraw = REDRAW_INDEX | REDRAW_STATUS; @@ -196,11 +135,10 @@ void menu_redraw_status (MUTTMENU * menu) snprintf (buf, sizeof (buf), M_MODEFMT, menu->title); SETCOLOR (MT_COLOR_STATUS); - move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW); + wmove (stdscr, option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW); mutt_paddstr (COLS-SW, buf); SETCOLOR (MT_COLOR_NORMAL); menu->redraw &= ~REDRAW_STATUS; - sidebar_draw_frames(); } void menu_redraw_index (MUTTMENU * menu) @@ -213,50 +151,25 @@ void menu_redraw_index (MUTTMENU * menu) menu_make_entry (buf, sizeof (buf), menu, i); menu_pad_string (buf, sizeof (buf)); - if (option (OPTARROWCURSOR)) { - attrset (menu->color (i)); - CLEARLINE_WIN (i - menu->top + menu->offset); - - if (i == menu->current) { - attrset (menu->color (i)); - ADDCOLOR (MT_COLOR_INDICATOR); - BKGDSET (MT_COLOR_INDICATOR); - addstr ("->"); - attrset (menu->color (i)); - addch (' '); - } - else { - attrset (menu->color (i)); - move (i - menu->top + menu->offset, SW); - addstr (" "); - } + wattrset (stdscr, menu->color (i)); - print_enriched_string (menu->color (i), (unsigned char *) buf, 1); - SETCOLOR (MT_COLOR_NORMAL); - BKGDSET (MT_COLOR_NORMAL); + if (i == menu->current) { + ADDCOLOR (MT_COLOR_INDICATOR); + BKGDSET (MT_COLOR_INDICATOR); } - else { - attrset (menu->color (i)); - if (i == menu->current) { - ADDCOLOR (MT_COLOR_INDICATOR); - BKGDSET (MT_COLOR_INDICATOR); - } - - CLEARLINE_WIN (i - menu->top + menu->offset); + CLEARLINE_WIN (i - menu->top + menu->offset); - move (i - menu->top + menu->offset, SW); - print_enriched_string (menu->color (i), (unsigned char *) buf, - i != menu->current); - SETCOLOR (MT_COLOR_NORMAL); - BKGDSET (MT_COLOR_NORMAL); - } - } - else + wmove (stdscr, i - menu->top + menu->offset, SW); + print_enriched_string (menu->color (i), (unsigned char *) buf, + i != menu->current); + SETCOLOR (MT_COLOR_NORMAL); + BKGDSET (MT_COLOR_NORMAL); + } else { CLEARLINE_WIN (i - menu->top + menu->offset); + } } - sidebar_draw (1); -/* sidebar_draw_frames(); */ + sidebar_draw (); menu->redraw = 0; } @@ -270,54 +183,31 @@ void menu_redraw_motion (MUTTMENU * menu) return; } - move (menu->oldcurrent + menu->offset - menu->top, SW); + wmove (stdscr, menu->oldcurrent + menu->offset - menu->top, SW); SETCOLOR (MT_COLOR_NORMAL); BKGDSET (MT_COLOR_NORMAL); - if (option (OPTARROWCURSOR)) { - /* clear the pointer */ - attrset (menu->color (menu->oldcurrent)); - addstr (" "); + /* erase the current indicator */ + wattrset (stdscr, menu->color (menu->oldcurrent)); + wclrtoeol (stdscr); + 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); - 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, SW + 3); - print_enriched_string (menu->color (menu->oldcurrent), - (unsigned char *) buf, 1); - SETCOLOR (MT_COLOR_NORMAL); - } + /* now draw the new one to reflect the change */ + menu_make_entry (buf, sizeof (buf), menu, menu->current); + menu_pad_string (buf, sizeof (buf)); + wattrset (stdscr, menu->color (menu->current)); + ADDCOLOR (MT_COLOR_INDICATOR); + BKGDSET (MT_COLOR_INDICATOR); + CLEARLINE_WIN (menu->current - menu->top + menu->offset); + wmove (stdscr, menu->current + menu->offset - menu->top, SW); + print_enriched_string (menu->color (menu->current), (unsigned char *) buf, + 0); + SETCOLOR (MT_COLOR_NORMAL); + BKGDSET (MT_COLOR_NORMAL); - /* now draw it in the new location */ - move (menu->current + menu->offset - menu->top, SW); - attrset (menu->color (menu->current)); - ADDCOLOR (MT_COLOR_INDICATOR); - addstr ("->"); - SETCOLOR (MT_COLOR_NORMAL); - } - 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); - - /* now draw the new one to reflect the change */ - menu_make_entry (buf, sizeof (buf), menu, menu->current); - menu_pad_string (buf, sizeof (buf)); - attrset (menu->color (menu->current)); - ADDCOLOR (MT_COLOR_INDICATOR); - BKGDSET (MT_COLOR_INDICATOR); - CLEARLINE_WIN (menu->current - menu->top + menu->offset); - move (menu->current + menu->offset - menu->top, SW); - print_enriched_string (menu->color (menu->current), (unsigned char *) buf, - 0); - SETCOLOR (MT_COLOR_NORMAL); - BKGDSET (MT_COLOR_NORMAL); - } menu->redraw &= REDRAW_STATUS; } @@ -325,39 +215,23 @@ void menu_redraw_current (MUTTMENU * menu) { char buf[STRING]; - move (menu->current + menu->offset - menu->top, SW); + wmove (stdscr, menu->current + menu->offset - menu->top, SW); menu_make_entry (buf, sizeof (buf), menu, menu->current); menu_pad_string (buf, sizeof (buf)); - if (option (OPTARROWCURSOR)) { - int attr = menu->color (menu->current); - - attrset (attr); - clrtoeol (); - attrset (menu->color (menu->current)); - ADDCOLOR (MT_COLOR_INDICATOR); - addstr ("->"); - attrset (attr); - addch (' '); - menu_pad_string (buf, sizeof (buf)); - print_enriched_string (menu->color (menu->current), (unsigned char *) buf, - 1); - SETCOLOR (MT_COLOR_NORMAL); - } - 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); - SETCOLOR (MT_COLOR_NORMAL); - BKGDSET (MT_COLOR_NORMAL); - } + wattrset (stdscr, menu->color (menu->current)); + ADDCOLOR (MT_COLOR_INDICATOR); + BKGDSET (MT_COLOR_INDICATOR); + wclrtoeol (stdscr); + 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) +static void menu_redraw_prompt (MUTTMENU * menu) { if (menu->dialog) { if (option (OPTMSGERR)) { @@ -369,8 +243,8 @@ void menu_redraw_prompt (MUTTMENU * menu) mutt_clear_error (); SETCOLOR (MT_COLOR_NORMAL); - mvaddstr (LINES - 1, 0, menu->prompt); - clrtoeol (); + mvwaddstr (stdscr, LINES - 1, 0, menu->prompt); + wclrtoeol (stdscr); } } @@ -409,7 +283,7 @@ void menu_check_recenter (MUTTMENU * menu) void menu_jump (MUTTMENU * menu) { int n; - char buf[SHORT_STRING]; + char buf[STRING]; if (menu->max) { mutt_ungetch (LastKey, 0); @@ -470,7 +344,7 @@ void menu_prev_line (MUTTMENU * menu) * halfdown: jumplen == pagelen/2 */ #define DIRECTION ((neg * 2) + 1) -void menu_length_jump (MUTTMENU *menu, int jumplen) { +static void menu_length_jump (MUTTMENU *menu, int jumplen) { int tmp, neg = (jumplen >= 0) ? 0 : -1; int c = MIN (MenuContext, menu->pagelen / 2); @@ -608,7 +482,7 @@ void menu_current_bottom (MUTTMENU * menu) mutt_error _("No entries."); } -void menu_next_entry (MUTTMENU * menu) +static void menu_next_entry (MUTTMENU * menu) { if (menu->current < menu->max - 1) { menu->current++; @@ -618,7 +492,7 @@ void menu_next_entry (MUTTMENU * menu) mutt_error _("You are on the last entry."); } -void menu_prev_entry (MUTTMENU * menu) +static void menu_prev_entry (MUTTMENU * menu) { if (menu->current) { menu->current--; @@ -679,7 +553,7 @@ static int menu_search (MUTTMENU * menu, int op) int r; int searchDir; regex_t re; - char buf[SHORT_STRING]; + char buf[STRING]; if (op != OP_SEARCH_NEXT && op != OP_SEARCH_OPPOSITE) { m_strcpy(buf, sizeof(buf), NONULL(menu->searchBuf)); @@ -815,12 +689,10 @@ int mutt_menuLoop (MUTTMENU * menu) menu->oldcurrent = menu->current; - if (option (OPTARROWCURSOR)) - move (menu->current - menu->top + menu->offset, SW + 2); - else if (option (OPTBRAILLEFRIENDLY)) - move (menu->current - menu->top + menu->offset, SW); + if (option (OPTBRAILLEFRIENDLY)) + wmove (stdscr, menu->current - menu->top + menu->offset, SW); else - move (menu->current - menu->top + menu->offset, COLS - 1); + wmove (stdscr, menu->current - menu->top + menu->offset, COLS - 1); mutt_refresh (); @@ -832,8 +704,8 @@ int mutt_menuLoop (MUTTMENU * menu) i = km_dokey (menu->menu); if (i == OP_TAG_PREFIX || i == OP_TAG_PREFIX_COND) { if (menu->tagged) { - mvaddstr (LINES - 1, 0, "Tag-"); - clrtoeol (); + mvwaddstr (stdscr, LINES - 1, 0, "Tag-"); + wclrtoeol (stdscr); i = km_dokey (menu->menu); menu->tagprefix = 1; CLEARLINE (LINES - 1); @@ -864,14 +736,10 @@ int mutt_menuLoop (MUTTMENU * menu) mutt_curs_set (1); -#if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM) if (SigWinch) { - mutt_resize_screen (); + ui_layout_resize(); menu->redraw = REDRAW_FULL; - SigWinch = 0; - clearok (stdscr, TRUE); /*force complete redraw */ } -#endif if (i == -1) continue; @@ -999,10 +867,6 @@ int mutt_menuLoop (MUTTMENU * menu) mutt_what_key (); break; - case OP_REBUILD_CACHE: - mx_rebuild_cache (); - break; - case OP_REDRAW: clearok (stdscr, TRUE); menu->redraw = REDRAW_FULL;