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.

-- 
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA
http://www.8t8.us/configs/gpg-key-transition-statement.txt
# HG changeset patch
# User Kevin McCarthy <ke...@8t8.us>
# Date 1461084682 25200
#      Tue Apr 19 09:51:22 2016 -0700
# Node ID 0fd22c9aaf4f29545dcdcce1e353c319c883ec46
# Parent  404cf1094ee708fc85044b95d9f274e9acbc3565
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
--- a/menu.c
+++ b/menu.c
@@ -175,62 +175,57 @@
   {
     strncpy (s, menu->dialog[i], l);
     menu->current = -1; /* hide menubar */
   }
   else
     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;
   FREE (&scratch);
 }
 
 void menu_redraw_full (MUTTMENU *menu)
 {
   NORMAL_COLOR;
   /* clear() doesn't optimize screen redraws */
   move (0, 0);
   clrtobot ();
 
   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 ();
 
   menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
 }
 
 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, 0);
-  mutt_paddstr (COLS, buf);
+  mutt_window_move (menu->statuswin, 0, 0);
+  mutt_paddstr (menu->statuswin->cols, buf);
   NORMAL_COLOR;
   menu->redraw &= ~REDRAW_STATUS;
 }
 
 void menu_redraw_index (MUTTMENU *menu)
 {
   char buf[LONG_STRING];
   int i;
@@ -239,20 +234,20 @@
 
   for (i = menu->top; i < menu->top + menu->pagelen; i++)
   {
     if (i < menu->max)
     {
       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)
       {
          SETCOLOR(MT_COLOR_INDICATOR);
          if (option(OPTARROWCURSOR))
          {
            addstr ("->");
@@ -265,87 +260,87 @@
       else if (option(OPTARROWCURSOR))
        addstr("   ");
 
       print_enriched_string (attr, (unsigned char *) buf, do_color);
     }
     else
     {
       NORMAL_COLOR;
-      CLEARLINE(i - menu->top + menu->offset);
+      mutt_window_clearline (menu->indexwin, i - menu->top + menu->offset);
     }
   }
   NORMAL_COLOR;
   menu->redraw = 0;
 }
 
 void menu_redraw_motion (MUTTMENU *menu)
 {
   char buf[LONG_STRING];
 
   if (menu->dialog) 
   {
     menu->redraw &= ~REDRAW_MOTION;
     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))
   {
     /* clear the pointer */
     addstr ("  ");
 
     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;
   NORMAL_COLOR;
 }
 
 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))
   {
     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
     print_enriched_string (attr, (unsigned char *) buf, 0);
   menu->redraw &= REDRAW_STATUS;
   NORMAL_COLOR;
 }
 
@@ -357,18 +352,18 @@
     {
       mutt_sleep (1);
       unset_option (OPTMSGERR);
     }
 
     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);
   }
 }
 
 void menu_check_recenter (MUTTMENU *menu)
 {
   int c = MIN (MenuContext, menu->pagelen / 2);
   int old_top = menu->top;
 
@@ -683,19 +678,23 @@
   MUTTMENU *p = (MUTTMENU *) safe_calloc (1, sizeof (MUTTMENU));
 
   if ((menu < 0) || (menu >= MENU_MAX))
     menu = MENU_GENERIC;
 
   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);
 }
 
 void mutt_menuDestroy (MUTTMENU **p)
 {
   int i;
@@ -868,38 +867,39 @@
     
     menu->oldcurrent = menu->current;
 
 
     /* move the cursor out of the way */
     
     
     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 ();
     
     /* 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)
       {
-       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)
       {
        mutt_error _("No tagged entries.");
        i = -1;
       }
       else /* None tagged, OP_TAG_PREFIX_COND */
       {
diff --git a/mutt_curses.h b/mutt_curses.h
--- a/mutt_curses.h
+++ b/mutt_curses.h
@@ -72,17 +72,16 @@
 #define curs_set(x)
 #endif
 
 #if (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
 void mutt_curs_set (int);
 #else
 #define mutt_curs_set(x)
 #endif
-#define PAGELEN (LINES-3)
 
 #define ctrl(c) ((c)-'@')
 
 #ifdef KEY_ENTER
 #define CI_is_return(c) ((c) == '\r' || (c) == '\n' || (c) == KEY_ENTER)
 #else
 #define CI_is_return(c) ((c) == '\r' || (c) == '\n')
 #endif
diff --git a/mutt_menu.h b/mutt_menu.h
--- a/mutt_menu.h
+++ b/mutt_menu.h
@@ -20,16 +20,17 @@
  * This file is named mutt_menu.h so it doesn't collide with ncurses menu.h
  */
 
 #ifndef _MUTT_MENU_H_
 #define _MUTT_MENU_H_ 1
 
 #include "keymap.h"
 #include "mutt_regex.h"
+#include "mutt_curses.h"
 
 #define REDRAW_INDEX           (1)
 #define REDRAW_MOTION          (1<<1)
 #define REDRAW_MOTION_RESYNCH  (1<<2)
 #define REDRAW_CURRENT         (1<<3)
 #define REDRAW_STATUS          (1<<4)
 #define REDRAW_FULL            (1<<5)
 #define REDRAW_BODY            (1<<6)
@@ -41,19 +42,23 @@
 {
   char *title;   /* the title of this menu */
   char *help;    /* quickref for the current menu */
   void *data;    /* extra data for the current menu */
   int current;   /* current entry */
   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
    * normal menu movement keys. This can cause problems with scrolling, if 
    * prompt keys override movement keys.
    */
   char **dialog;       /* dialog lines themselves */
   char *prompt;                /* prompt for user, similar to 
mutt_multi_choice */

Attachment: signature.asc
Description: PGP signature

Reply via email to