X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-ui%2Fmenu.c;h=928834cadd0c42ee94085eadeced0417f89b2ace;hp=19ab550e84ea66f0e393567e47df701542ca9812;hb=7dcd7ee09b8760133ac8ec00562e4d60b2f0aebd;hpb=0ab517261694b001d2eb17f06f167a4cdd2c7c07 diff --git a/lib-ui/menu.c b/lib-ui/menu.c index 19ab550..928834c 100644 --- a/lib-ui/menu.c +++ b/lib-ui/menu.c @@ -7,9 +7,8 @@ * please see the file GPL in the top level source directory. */ -#include +#include -#include "curses.h" #include "enter.h" #include "menu.h" @@ -19,8 +18,6 @@ #include #include -#define SW (option(OPTMBOXPANE)?SidebarWidth:0) - extern size_t UngetCount; static void print_enriched_string (int attr, unsigned char *s, int do_color) @@ -34,91 +31,56 @@ static void print_enriched_string (int attr, unsigned char *s, int do_color) while (*s) { if (*s < M_TREE_MAX) { if (do_color) - SETCOLOR (MT_COLOR_TREE); + SETCOLOR(main_w, 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); + waddch (main_w, 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 (main_w, 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 (main_w, 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 (main_w, 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 (main_w, 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 (main_w, 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 (main_w, ACS_BTEE); break; case M_TREE_SPACE: - addch (' '); + waddch (main_w, ' '); break; case M_TREE_RARROW: - addch ('>'); + waddch (main_w, '>'); break; case M_TREE_STAR: - addch ('*'); /* fake thread indicator */ + waddch (main_w, '*'); /* fake thread indicator */ break; case M_TREE_HIDDEN: - addch ('&'); + waddch (main_w, '&'); break; case M_TREE_EQUALS: - addch ('='); + waddch (main_w, '='); break; case M_TREE_MISSING: - addch ('?'); + waddch (main_w, '?'); break; } s++, n--; } if (do_color) - attrset (attr); + wattrset (main_w, 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 (main_w, (char *) s, k); s += k, n -= k; } else @@ -138,11 +100,9 @@ static void menu_make_entry (char *s, int l, MUTTMENU * menu, int i) static void menu_pad_string (char *s, size_t n) { - int shift = option (OPTARROWCURSOR) ? 3 : 0; - int cols; + int cols = getmaxx(main_w); char *tmpbuf = p_new(char, n); - cols = COLS - SW - shift; mutt_format_string (tmpbuf, n, cols, cols, 0, ' ', s, m_strlen(s), 1); tmpbuf[n - 1] = 0; snprintf (s, n, "%s", tmpbuf); /* overkill */ @@ -151,26 +111,17 @@ static 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(); - + SETCOLOR(main_w, MT_COLOR_NORMAL); + /* wclear() doesn't optimize screen redraws */ + wmove (main_w, 0, 0); + wclrtobot (main_w); + + SETCOLOR(main_w, MT_COLOR_STATUS); + wmove (main_w, LINES - 2, 0); + mutt_paddstr (main_w, getmaxx(main_w), ""); + SETCOLOR(main_w, MT_COLOR_NORMAL); + menu->offset = 1; + menu->pagelen = LINES - 3; mutt_show_error (); menu->redraw = REDRAW_INDEX | REDRAW_STATUS; @@ -181,12 +132,11 @@ void menu_redraw_status (MUTTMENU * menu) char buf[STRING]; snprintf (buf, sizeof (buf), M_MODEFMT, menu->title); - SETCOLOR (MT_COLOR_STATUS); - move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW); - mutt_paddstr (COLS-SW, buf); - SETCOLOR (MT_COLOR_NORMAL); + SETCOLOR(main_w, MT_COLOR_STATUS); + wmove (main_w, 0, 0); + mutt_paddstr (main_w, getmaxx(main_w), buf); + SETCOLOR(main_w, MT_COLOR_NORMAL); menu->redraw &= ~REDRAW_STATUS; - sidebar_draw_frames(); } void menu_redraw_index (MUTTMENU * menu) @@ -199,47 +149,23 @@ 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 (main_w, 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(main_w, MT_COLOR_INDICATOR); + BKGDSET(main_w, 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(main_w, 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); - } + wmove (main_w, i - menu->top + menu->offset, 0); + print_enriched_string (menu->color (i), (unsigned char *) buf, + i != menu->current); + SETCOLOR(main_w, MT_COLOR_NORMAL); + BKGDSET(main_w, MT_COLOR_NORMAL); + } else { + CLEARLINE(main_w, i - menu->top + menu->offset); } - else - CLEARLINE_WIN (i - menu->top + menu->offset); } sidebar_draw (); @@ -255,54 +181,31 @@ void menu_redraw_motion (MUTTMENU * menu) return; } - move (menu->oldcurrent + menu->offset - menu->top, SW); - SETCOLOR (MT_COLOR_NORMAL); - BKGDSET (MT_COLOR_NORMAL); + wmove (main_w, menu->oldcurrent + menu->offset - menu->top, 0); + SETCOLOR(main_w, MT_COLOR_NORMAL); + BKGDSET(main_w, MT_COLOR_NORMAL); - if (option (OPTARROWCURSOR)) { - /* clear the pointer */ - attrset (menu->color (menu->oldcurrent)); - addstr (" "); + /* erase the current indicator */ + wattrset (main_w, menu->color (menu->oldcurrent)); + wclrtoeol (main_w); + 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 (main_w, menu->color (menu->current)); + ADDCOLOR(main_w, MT_COLOR_INDICATOR); + BKGDSET(main_w, MT_COLOR_INDICATOR); + CLEARLINE(main_w, menu->current - menu->top + menu->offset); + wmove (main_w, menu->current + menu->offset - menu->top, 0); + print_enriched_string (menu->color (menu->current), (unsigned char *) buf, + 0); + SETCOLOR(main_w, MT_COLOR_NORMAL); + BKGDSET(main_w, 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; } @@ -310,35 +213,19 @@ void menu_redraw_current (MUTTMENU * menu) { char buf[STRING]; - move (menu->current + menu->offset - menu->top, SW); + wmove (main_w, menu->current + menu->offset - menu->top, 0); 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 (main_w, menu->color (menu->current)); + ADDCOLOR(main_w, MT_COLOR_INDICATOR); + BKGDSET(main_w, MT_COLOR_INDICATOR); + wclrtoeol (main_w); + print_enriched_string (menu->color (menu->current), (unsigned char *) buf, + 0); + SETCOLOR(main_w, MT_COLOR_NORMAL); + BKGDSET(main_w, MT_COLOR_NORMAL); + menu->redraw &= REDRAW_STATUS; } @@ -353,9 +240,9 @@ static void menu_redraw_prompt (MUTTMENU * menu) if (*Errorbuf) mutt_clear_error (); - SETCOLOR (MT_COLOR_NORMAL); - mvaddstr (LINES - 1, 0, menu->prompt); - clrtoeol (); + SETCOLOR(main_w, MT_COLOR_NORMAL); + mvwaddstr (main_w, LINES - 1, 0, menu->prompt); + wclrtoeol (main_w); } } @@ -364,27 +251,18 @@ 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 (menu->top != 0) { - menu->top = 0; - set_option (OPTNEEDREDRAW); - } + if ((menu->pagelen <= 0) || (c < MenuContext)) { + if (menu->current < menu->top + c) + menu->top = menu->current - c; + else if (menu->current >= menu->top + menu->pagelen - c) + menu->top = menu->current - menu->pagelen + c + 1; } else { - if (option (OPTMENUSCROLL) || (menu->pagelen <= 0) || (c < MenuContext)) { - if (menu->current < menu->top + c) - menu->top = menu->current - c; - else if (menu->current >= menu->top + menu->pagelen - c) - menu->top = menu->current - menu->pagelen + c + 1; - } else { - if (menu->current < menu->top + c) - menu->top -= (menu->pagelen - c) * ((menu->top + menu->pagelen - 1 - menu->current) / (menu->pagelen - c)) - c; - else if ((menu->current >= menu->top + menu->pagelen - c)) - menu->top += (menu->pagelen - c) * ((menu->current - menu->top) / (menu->pagelen - c)) - c; - } + if (menu->current < menu->top + c) + menu->top -= (menu->pagelen - c) * ((menu->top + menu->pagelen - 1 - menu->current) / (menu->pagelen - c)) - c; + else if ((menu->current >= menu->top + menu->pagelen - c)) + menu->top += (menu->pagelen - c) * ((menu->current - menu->top) / (menu->pagelen - c)) - c; } - if (!option (OPTMENUMOVEOFF)) /* make entries stick to bottom */ - menu->top = MIN (menu->top, menu->max - menu->pagelen); menu->top = MAX (menu->top, 0); if (menu->top != old_top) @@ -418,20 +296,17 @@ void menu_next_line (MUTTMENU * menu) 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) { menu->top++; if (menu->current < menu->top + c && menu->current < menu->max - 1) menu->current++; menu->redraw = REDRAW_INDEX; - } - else + } else { mutt_error _("You cannot scroll down farther."); - } - else + } + } else { mutt_error _("No entries."); + } } void menu_prev_line (MUTTMENU * menu) @@ -466,7 +341,7 @@ static void menu_length_jump (MUTTMENU *menu, int jumplen) { menu->top += jumplen; /* jumped too long? */ - if ((neg || !option (OPTMENUMOVEOFF)) && DIRECTION * menu->top > tmp) + if (neg && DIRECTION * menu->top > tmp) menu->top = tmp; /* need to move the cursor? */ @@ -634,7 +509,7 @@ MUTTMENU *mutt_new_menu (void) p->top = 0; p->offset = 1; p->redraw = REDRAW_FULL; - p->pagelen = PAGELEN; + p->pagelen = LINES - 3; p->color = default_color; p->search = menu_search_generic; return (p); @@ -799,17 +674,8 @@ int mutt_menuLoop (MUTTMENU * menu) return OP_REDRAW; 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); - 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; @@ -817,11 +683,11 @@ 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 (main_w, LINES - 1, 0, "Tag-"); + wclrtoeol (main_w); i = km_dokey (menu->menu); menu->tagprefix = 1; - CLEARLINE (LINES - 1); + CLEARLINE(main_w, LINES - 1); } else if (i == OP_TAG_PREFIX) { mutt_error _("No tagged entries."); @@ -849,14 +715,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; @@ -985,7 +847,7 @@ int mutt_menuLoop (MUTTMENU * menu) break; case OP_REDRAW: - clearok (stdscr, TRUE); + clearok (main_w, TRUE); menu->redraw = REDRAW_FULL; break;