From: Kevin McCarthy Date: Thu, 28 Apr 2016 00:56:51 +0000 (-0700) Subject: Modify the menu code to use windows. X-Git-Tag: neomutt-20160822~167 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=30d6fe8faa6926c31fb9b22f9d5d32b430b46842;p=neomutt Modify the menu code to use windows. Change menu.c to use the mutt_window_t structures and functions. The index/stats/help/message window pointers are stored inside the menu_t. This is useful for the pager, where the "index" we want to use is a mini-index. --- diff --git a/menu.c b/menu.c index 828df9c10..a715fb91e 100644 --- a/menu.c +++ b/menu.c @@ -180,11 +180,11 @@ static void menu_make_entry (char *s, int l, MUTTMENU *menu, int i) menu->make_entry (s, l, menu, i); } -static void menu_pad_string (char *s, size_t n) +static void menu_pad_string (MUTTMENU *menu, char *s, size_t n) { char *scratch = safe_strdup (s); int shift = option (OPTARROWCURSOR) ? 3 : 0; - int cols = COLS - shift; + int cols = menu->indexwin->cols - shift; mutt_format_string (s, n, cols, cols, FMT_LEFT, ' ', scratch, mutt_strlen (scratch), 1); s[n - 1] = 0; @@ -193,6 +193,9 @@ static void menu_pad_string (char *s, size_t n) void menu_redraw_full (MUTTMENU *menu) { +#if ! (defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)) + mutt_reflow_windows (); +#endif NORMAL_COLOR; /* clear() doesn't optimize screen redraws */ move (0, 0); @@ -201,17 +204,12 @@ void menu_redraw_full (MUTTMENU *menu) if (option (OPTHELP)) { SETCOLOR (MT_COLOR_STATUS); - move (option (OPTSTATUSONTOP) ? LINES-2 : 0, 0); - mutt_paddstr (COLS, menu->help); + mutt_window_move (menu->helpwin, 0, 0); + mutt_paddstr (menu->helpwin->cols, menu->help); NORMAL_COLOR; - menu->offset = 1; - menu->pagelen = LINES - 3; - } - else - { - menu->offset = option (OPTSTATUSONTOP) ? 1 : 0; - menu->pagelen = LINES - 2; } + menu->offset = 0; + menu->pagelen = menu->indexwin->rows; mutt_show_error (); @@ -224,8 +222,8 @@ void menu_redraw_status (MUTTMENU *menu) snprintf (buf, sizeof (buf), M_MODEFMT, menu->title); SETCOLOR (MT_COLOR_STATUS); - move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, 0); - mutt_paddstr (COLS, buf); + mutt_window_move (menu->statuswin, 0, 0); + mutt_paddstr (menu->statuswin->cols, buf); NORMAL_COLOR; menu->redraw &= ~REDRAW_STATUS; } @@ -244,10 +242,10 @@ void menu_redraw_index (MUTTMENU *menu) attr = menu->color(i); menu_make_entry (buf, sizeof (buf), menu, i); - menu_pad_string (buf, sizeof (buf)); + menu_pad_string (menu, buf, sizeof (buf)); ATTRSET(attr); - move(i - menu->top + menu->offset, 0); + mutt_window_move (menu->indexwin, i - menu->top + menu->offset, 0); do_color = 1; if (i == menu->current) @@ -270,7 +268,7 @@ void menu_redraw_index (MUTTMENU *menu) else { NORMAL_COLOR; - CLEARLINE(i - menu->top + menu->offset); + mutt_window_clearline (menu->indexwin, i - menu->top + menu->offset); } } NORMAL_COLOR; @@ -287,7 +285,7 @@ void menu_redraw_motion (MUTTMENU *menu) return; } - move (menu->oldcurrent + menu->offset - menu->top, 0); + mutt_window_move (menu->indexwin, menu->oldcurrent + menu->offset - menu->top, 0); ATTRSET(menu->color (menu->oldcurrent)); if (option (OPTARROWCURSOR)) @@ -298,27 +296,27 @@ void menu_redraw_motion (MUTTMENU *menu) if (menu->redraw & REDRAW_MOTION_RESYNCH) { menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent); - menu_pad_string (buf, sizeof (buf)); - move (menu->oldcurrent + menu->offset - menu->top, 3); + menu_pad_string (menu, buf, sizeof (buf)); + mutt_window_move (menu->indexwin, menu->oldcurrent + menu->offset - menu->top, 3); print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1); } /* now draw it in the new location */ SETCOLOR(MT_COLOR_INDICATOR); - mvaddstr(menu->current + menu->offset - menu->top, 0, "->"); + mutt_window_mvaddstr (menu->indexwin, menu->current + menu->offset - menu->top, 0, "->"); } else { /* erase the current indicator */ menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent); - menu_pad_string (buf, sizeof (buf)); + menu_pad_string (menu, 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)); + menu_pad_string (menu, buf, sizeof (buf)); SETCOLOR(MT_COLOR_INDICATOR); - move(menu->current - menu->top + menu->offset, 0); + mutt_window_move (menu->indexwin, menu->current + menu->offset - menu->top, 0); print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0); } menu->redraw &= REDRAW_STATUS; @@ -329,10 +327,10 @@ void menu_redraw_current (MUTTMENU *menu) { char buf[LONG_STRING]; int attr = menu->color (menu->current); - - move (menu->current + menu->offset - menu->top, 0); + + mutt_window_move (menu->indexwin, menu->current + menu->offset - menu->top, 0); menu_make_entry (buf, sizeof (buf), menu, menu->current); - menu_pad_string (buf, sizeof (buf)); + menu_pad_string (menu, buf, sizeof (buf)); SETCOLOR(MT_COLOR_INDICATOR); if (option (OPTARROWCURSOR)) @@ -340,7 +338,7 @@ void menu_redraw_current (MUTTMENU *menu) addstr ("->"); ATTRSET(attr); addch (' '); - menu_pad_string (buf, sizeof (buf)); + menu_pad_string (menu, buf, sizeof (buf)); print_enriched_string (attr, (unsigned char *) buf, 1); } else @@ -362,8 +360,8 @@ static void menu_redraw_prompt (MUTTMENU *menu) if (*Errorbuf) mutt_clear_error (); - mvaddstr (LINES - 1, 0, menu->prompt); - clrtoeol (); + mutt_window_mvaddstr (menu->messagewin, 0, 0, menu->prompt); + mutt_window_clrtoeol (menu->messagewin); } } @@ -688,9 +686,13 @@ MUTTMENU *mutt_new_menu (int menu) p->menu = menu; p->current = 0; p->top = 0; - p->offset = 1; + p->offset = 0; p->redraw = REDRAW_FULL; - p->pagelen = PAGELEN; + p->pagelen = MuttIndexWindow->rows; + p->indexwin = MuttIndexWindow; + p->statuswin = MuttStatusWindow; + p->helpwin = MuttHelpWindow; + p->messagewin = MuttMessageWindow; p->color = default_color; p->search = menu_search_generic; return (p); @@ -873,11 +875,12 @@ int mutt_menuLoop (MUTTMENU *menu) if (option (OPTARROWCURSOR)) - move (menu->current - menu->top + menu->offset, 2); + mutt_window_move (menu->indexwin, menu->current - menu->top + menu->offset, 2); else if (option (OPTBRAILLEFRIENDLY)) - move (menu->current - menu->top + menu->offset, 0); + mutt_window_move (menu->indexwin, menu->current - menu->top + menu->offset, 0); else - move (menu->current - menu->top + menu->offset, COLS - 1); + mutt_window_move (menu->indexwin, menu->current - menu->top + menu->offset, + menu->indexwin->cols - 1); mutt_refresh (); @@ -890,11 +893,11 @@ int mutt_menuLoop (MUTTMENU *menu) { if (menu->tagged) { - mvaddstr (LINES - 1, 0, "Tag-"); - clrtoeol (); + mutt_window_mvaddstr (menu->messagewin, 0, 0, "Tag-"); + mutt_window_clrtoeol (menu->messagewin); i = km_dokey (menu->menu); menu->tagprefix = 1; - CLEARLINE (LINES - 1); + mutt_window_clearline (menu->messagewin, 0); } else if (i == OP_TAG_PREFIX) { diff --git a/mutt_curses.h b/mutt_curses.h index 0f6608c7f..2d2fb2802 100644 --- a/mutt_curses.h +++ b/mutt_curses.h @@ -77,7 +77,6 @@ void mutt_curs_set (int); #else #define mutt_curs_set(x) #endif -#define PAGELEN (LINES-3) #define ctrl(c) ((c)-'@') diff --git a/mutt_menu.h b/mutt_menu.h index 8192019e2..6f4ed74d9 100644 --- a/mutt_menu.h +++ b/mutt_menu.h @@ -25,6 +25,7 @@ #include "keymap.h" #include "mutt_regex.h" +#include "mutt_curses.h" #define REDRAW_INDEX (1) #define REDRAW_MOTION (1<<1) @@ -46,9 +47,13 @@ typedef struct menu_t int max; /* the number of entries in the menu */ int redraw; /* when to redraw the screen */ int menu; /* menu definition for keymap entries. */ - int offset; /* which screen row to start the index */ + int offset; /* row offset within the window to start the index */ int pagelen; /* number of entries per screen */ int tagprefix; + mutt_window_t *indexwin; + mutt_window_t *statuswin; + mutt_window_t *helpwin; + mutt_window_t *messagewin; /* Setting dialog != NULL overrides normal menu behavior. * In dialog mode menubar is hidden and prompt keys are checked before