changeset: 6626:ac4f746e614f
user:      Kevin McCarthy <[email protected]>
date:      Wed Apr 27 17:56:49 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/ac4f746e614f

Add window structures to use for screen layout.

This is a series of 11 patches, centralizing Mutt screen drawing
inside windows (mutt_window_t structures).

Currently, the screen drawing and cursor positioning logic is
distributed all over the code, resulting in many files having the same
logic of where the help, status, message windows are.  Additionally,
the code directly uses move and mvadd*/mvprint* functions, which means
if the layouts are changed, the row/column computation logic needs to
be changed all over the place.

The patch creates a (very simple) mutt_window_t structure and
functions for moving, addch/str/printw, along with clearing the line.
The windows keep track of where they are on the screen, allowing the
Mutt code to simply position elements relative to the window.

During curses initalization, and when the window is resized, the
window sizes and positions and recomputed.  Also, a new option flags,
R_REFLOW is added for options that need to force a reflow when they are changed.

Thanks to Richard Russon for pointing out the slang compilation issue.

changeset: 6627:48676eb3e400
user:      Kevin McCarthy <[email protected]>
date:      Wed Apr 27 17:56:51 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/48676eb3e400

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.

changeset: 6628:47e9732b3a3c
user:      Kevin McCarthy <[email protected]>
date:      Wed Apr 27 17:56:52 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/47e9732b3a3c

Modify the curs_lib.c to use windows.

This changes some of the "prompting" routines to use the MuttMessageWindow.

changeset: 6629:1b8abb069c37
user:      Kevin McCarthy <[email protected]>
date:      Wed Apr 27 17:56:53 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/1b8abb069c37

Modify enter.c routines to use windows.

This modifies the mutt_enter_string() functions to use MuttMessageWindow.

Thanks to Richard Russon for pointing out slang doesn't support getcurx.

changeset: 6630:4e20ab8ebf42
user:      Kevin McCarthy <[email protected]>
date:      Wed Apr 27 17:56:54 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/4e20ab8ebf42

Modify the index to use windows.

Change the index screen to use MuttIndexWindow and MuttStatusWindow.

changeset: 6631:fd3fe386c24a
user:      Kevin McCarthy <[email protected]>
date:      Wed Apr 27 17:56:55 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/fd3fe386c24a

Modify the pager to use windows.

The pager view is somewhat complex, due to the "mini-index" and the
positioning of the index_status vs pager_status changes depending on
$status_on_top as well as $pager_index_lines and $help.

To make things simpler, it creates four "pager windows":
index_status_window, index_window, pager_status_window, pager_window.

mutt_term_width() is renamed to mutt_window_wrap_cols() and a
mutt_window_t parameter passed in.

Also, the pager drawing loop calling display_line() has a
mutt_window_move() added to move to the beginning of the next line
each time.  This is in case the pager_window isn't flush with the left
side of the terminal.

changeset: 6632:0989f9d01b5c
user:      Kevin McCarthy <[email protected]>
date:      Wed Apr 27 17:56:56 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/0989f9d01b5c

Modify the compose screen to use windows.

The header field positions enum is now started at 0: the windows
compute the relative positioning as needed.  A small improvement from
this is that the headers now align with the top: there isn't a gap if
$help is turned off.

changeset: 6633:8ad6164d9fe4
user:      Kevin McCarthy <[email protected]>
date:      Wed Apr 27 17:56:56 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/8ad6164d9fe4

Modify the built-in editor to use windows.

This only involved changing to use the MuttMessageWindow.

changeset: 6634:9f9bcde2d0ff
user:      Kevin McCarthy <[email protected]>
date:      Wed Apr 27 17:56:57 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/9f9bcde2d0ff

Change remailer to use mutt windows.

changeset: 6635:04f1846c56c1
user:      Kevin McCarthy <[email protected]>
date:      Wed Apr 27 17:56:58 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/04f1846c56c1

Fix remaining direct usages of COLS/LINES to use mutt window functions.

Most of these were just message update/clearing.

changeset: 6636:efa6f7910c94
user:      Kevin McCarthy <[email protected]>
date:      Wed Apr 27 17:56:59 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/efa6f7910c94

Add cols parameter to mutt_FormatString()

Continuing with the conversion to using windows for screen drawing,
mutt_FormatString() was directly using COLS for right justification
and similar formatting.  Instead pass in a parameter, cols.

This change involved seeding the parameter through callback functions
too, as many of them call mutt_FormatString() back.

diffs (truncated from 2389 to 950 lines):

diff -r 8083387557d9 -r efa6f7910c94 addrbook.c
--- a/addrbook.c        Wed Apr 27 13:21:15 2016 -0700
+++ b/addrbook.c        Wed Apr 27 17:56:59 2016 -0700
@@ -43,7 +43,7 @@
 };
 
 static const char *
-alias_format_str (char *dest, size_t destlen, size_t col, char op, const char 
*src,
+alias_format_str (char *dest, size_t destlen, size_t col, int cols, char op, 
const char *src,
                  const char *fmt, const char *ifstring, const char *elsestring,
                  unsigned long data, format_flag flags)
 {
@@ -80,7 +80,7 @@
 
 static void alias_entry (char *s, size_t slen, MUTTMENU *m, int num)
 {
-  mutt_FormatString (s, slen, 0, NONULL (AliasFmt), alias_format_str, 
(unsigned long) ((ALIAS **) m->data)[num], M_FORMAT_ARROWCURSOR);
+  mutt_FormatString (s, slen, 0, MuttIndexWindow->cols, NONULL (AliasFmt), 
alias_format_str, (unsigned long) ((ALIAS **) m->data)[num], 
M_FORMAT_ARROWCURSOR);
 }
 
 static int alias_tag (MUTTMENU *menu, int n, int m)
diff -r 8083387557d9 -r efa6f7910c94 browser.c
--- a/browser.c Wed Apr 27 13:21:15 2016 -0700
+++ b/browser.c Wed Apr 27 17:56:59 2016 -0700
@@ -142,7 +142,7 @@
 }
 
 static const char *
-folder_format_str (char *dest, size_t destlen, size_t col, char op, const char 
*src,
+folder_format_str (char *dest, size_t destlen, size_t col, int cols, char op, 
const char *src,
                   const char *fmt, const char *ifstring, const char 
*elsestring,
                   unsigned long data, format_flag flags)
 {
@@ -317,9 +317,9 @@
   }
 
   if (optional)
-    mutt_FormatString (dest, destlen, col, ifstring, folder_format_str, data, 
0);
+    mutt_FormatString (dest, destlen, col, cols, ifstring, folder_format_str, 
data, 0);
   else if (flags & M_FORMAT_OPTIONAL)
-    mutt_FormatString (dest, destlen, col, elsestring, folder_format_str, 
data, 0);
+    mutt_FormatString (dest, destlen, col, cols, elsestring, 
folder_format_str, data, 0);
 
   return (src);
 }
@@ -515,7 +515,7 @@
   folder.ff = &((struct folder_file *) menu->data)[num];
   folder.num = num;
   
-  mutt_FormatString (s, slen, 0, NONULL(FolderFormat), folder_format_str, 
+  mutt_FormatString (s, slen, 0, MuttIndexWindow->cols, NONULL(FolderFormat), 
folder_format_str, 
       (unsigned long) &folder, M_FORMAT_ARROWCURSOR);
 }
 
diff -r 8083387557d9 -r efa6f7910c94 buffy.c
--- a/buffy.c   Wed Apr 27 13:21:15 2016 -0700
+++ b/buffy.c   Wed Apr 27 17:56:59 2016 -0700
@@ -511,7 +511,8 @@
     strfcpy (path, tmp->path, sizeof (path));
     mutt_pretty_mailbox (path, sizeof (path));
     
-    if (!first && (COLS - 7 >= 0) && (pos + strlen (path) >= (size_t)COLS - 7))
+    if (!first && (MuttMessageWindow->cols >= 7) &&
+        (pos + strlen (path) >= (size_t)MuttMessageWindow->cols - 7))
       break;
     
     if (!first)
diff -r 8083387557d9 -r efa6f7910c94 commands.c
--- a/commands.c        Wed Apr 27 13:21:15 2016 -0700
+++ b/commands.c        Wed Apr 27 17:56:59 2016 -0700
@@ -309,10 +309,10 @@
   snprintf (scratch, sizeof (scratch),
            (h ? _("Bounce message to %s") : _("Bounce messages to %s")), buf);
 
-  if (mutt_strwidth (prompt) > COLS - extra_space)
+  if (mutt_strwidth (prompt) > MuttMessageWindow->cols - extra_space)
   {
     mutt_format_string (prompt, sizeof (prompt),
-                       0, COLS-extra_space, FMT_LEFT, 0,
+                       0, MuttMessageWindow->cols-extra_space, FMT_LEFT, 0,
                        scratch, sizeof (scratch), 0);
     safe_strcat (prompt, sizeof (prompt), "...?");
   }
@@ -322,12 +322,12 @@
   if (query_quadoption (OPT_BOUNCE, prompt) != M_YES)
   {
     rfc822_free_address (&adr);
-    CLEARLINE (LINES - 1);
+    mutt_window_clearline (MuttMessageWindow, 0);
     mutt_message (h ? _("Message not bounced.") : _("Messages not bounced."));
     return;
   }
 
-  CLEARLINE (LINES - 1);
+  mutt_window_clearline (MuttMessageWindow, 0);
   
   rc = mutt_bounce_message (NULL, h, adr);
   rfc822_free_address (&adr);
@@ -598,7 +598,7 @@
       strfcpy (buf, Shell, sizeof (buf));
     if(buf[0])
     {
-      CLEARLINE (LINES-1);
+      mutt_window_clearline (MuttMessageWindow, 0);
       mutt_endwin (NULL);
       fflush (stdout);
       if (mutt_system (buf) != 0 || option (OPTWAITKEY))
diff -r 8083387557d9 -r efa6f7910c94 compose.c
--- a/compose.c Wed Apr 27 13:21:15 2016 -0700
+++ b/compose.c Wed Apr 27 17:56:59 2016 -0700
@@ -52,7 +52,7 @@
 
 enum
 {
-  HDR_FROM  = 1,
+  HDR_FROM  = 0,
   HDR_TO,
   HDR_CC,
   HDR_BCC,
@@ -72,7 +72,7 @@
 
 #define HDR_XOFFSET 10
 #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
-#define W (COLS - HDR_XOFFSET)
+#define W (MuttIndexWindow->cols - HDR_XOFFSET)
 
 static const char * const Prompts[] =
 {
@@ -99,7 +99,7 @@
 
 static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num)
 {
-    mutt_FormatString (b, blen, 0, NONULL (AttachFormat), mutt_attach_fmt,
+  mutt_FormatString (b, blen, 0, MuttIndexWindow->cols, NONULL (AttachFormat), 
mutt_attach_fmt,
            (unsigned long)(((ATTACHPTR **) menu->data)[num]),
            M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
 }
@@ -110,7 +110,7 @@
 
 static void redraw_crypt_lines (HEADER *msg)
 {
-  mvaddstr (HDR_CRYPT, 0, "Security: ");
+  mutt_window_mvaddstr (MuttIndexWindow, HDR_CRYPT, 0, "Security: ");
 
   if ((WithCrypto & (APPLICATION_PGP | APPLICATION_SMIME)) == 0)
   {
@@ -144,9 +144,9 @@
   if (option (OPTCRYPTOPPORTUNISTICENCRYPT) && (msg->security & OPPENCRYPT))
       addstr (_(" (OppEnc mode)"));
 
-  clrtoeol ();
-  move (HDR_CRYPTINFO, 0);
-  clrtoeol ();
+  mutt_window_clrtoeol (MuttIndexWindow);
+  mutt_window_move (MuttIndexWindow, HDR_CRYPTINFO, 0);
+  mutt_window_clrtoeol (MuttIndexWindow);
 
   if ((WithCrypto & APPLICATION_PGP)
       && (msg->security & APPLICATION_PGP) && (msg->security & SIGN))
@@ -162,7 +162,7 @@
       && (msg->security & ENCRYPT)
       && SmimeCryptAlg
       && *SmimeCryptAlg) {
-      mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
+    mutt_window_mvprintw (MuttIndexWindow, HDR_CRYPTINFO, 40, "%s%s", 
_("Encrypt with: "),
                NONULL(SmimeCryptAlg));
   }
 }
@@ -175,12 +175,12 @@
   int c;
   char *t;
 
-  mvaddstr (HDR_MIX, 0,     "     Mix: ");
+  mutt_window_mvaddstr (MuttIndexWindow, HDR_MIX, 0,     "     Mix: ");
 
   if (!chain)
   {
     addstr ("<no chain defined>");
-    clrtoeol ();
+    mutt_window_clrtoeol (MuttIndexWindow);
     return;
   }
   
@@ -190,7 +190,7 @@
     if (t && t[0] == '0' && t[1] == '\0')
       t = "<random>";
     
-    if (c + mutt_strlen (t) + 2 >= COLS)
+    if (c + mutt_strlen (t) + 2 >= MuttIndexWindow->cols)
       break;
 
     addstr (NONULL(t));
@@ -242,7 +242,7 @@
 
   buf[0] = 0;
   rfc822_write_address (buf, sizeof (buf), addr, 1);
-  mvprintw (line, 0, TITLE_FMT, Prompts[line - 1]);
+  mutt_window_mvprintw (MuttIndexWindow, line, 0, TITLE_FMT, Prompts[line]);
   mutt_paddstr (W, buf);
 }
 
@@ -252,10 +252,10 @@
   draw_envelope_addr (HDR_TO, msg->env->to);
   draw_envelope_addr (HDR_CC, msg->env->cc);
   draw_envelope_addr (HDR_BCC, msg->env->bcc);
-  mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
+  mutt_window_mvprintw (MuttIndexWindow, HDR_SUBJECT, 0, TITLE_FMT, 
Prompts[HDR_SUBJECT]);
   mutt_paddstr (W, NONULL (msg->env->subject));
   draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
-  mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
+  mutt_window_mvprintw (MuttIndexWindow, HDR_FCC, 0, TITLE_FMT, 
Prompts[HDR_FCC]);
   mutt_paddstr (W, fcc);
 
   if (WithCrypto)
@@ -266,8 +266,8 @@
 #endif
 
   SETCOLOR (MT_COLOR_STATUS);
-  mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments"));
-  clrtoeol ();
+  mutt_window_mvaddstr (MuttIndexWindow, HDR_ATTACH - 1, 0, _("-- 
Attachments"));
+  mutt_window_clrtoeol (MuttIndexWindow);
 
   NORMAL_COLOR;
 }
@@ -279,7 +279,7 @@
   
   mutt_addrlist_to_local (*addr);
   rfc822_write_address (buf, sizeof (buf), *addr, 0);
-  if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0)
+  if (mutt_get_field (Prompts[line], buf, sizeof (buf), M_ALIAS) == 0)
   {
     rfc822_free_address (addr);
     *addr = mutt_parse_adrlist (*addr, buf);
@@ -302,7 +302,7 @@
   /* redraw the expanded list so the user can see the result */
   buf[0] = 0;
   rfc822_write_address (buf, sizeof (buf), *addr, 1);
-  move (line, HDR_XOFFSET);
+  mutt_window_move (MuttIndexWindow, line, HDR_XOFFSET);
   mutt_paddstr (W, buf);
   
   return 0;
@@ -402,7 +402,7 @@
 }
 
 /* prototype for use below */
-static void compose_status_line (char *buf, size_t buflen, size_t col, 
MUTTMENU *menu, 
+static void compose_status_line (char *buf, size_t buflen, size_t col, int 
cols, MUTTMENU *menu, 
       const char *p);
 
 /*
@@ -418,7 +418,7 @@
  */
 
 static const char *
-compose_format_str (char *buf, size_t buflen, size_t col, char op, const char 
*src,
+compose_format_str (char *buf, size_t buflen, size_t col, int cols, char op, 
const char *src,
                   const char *prefix, const char *ifstring,
                   const char *elsestring,
                   unsigned long data, format_flag flags)
@@ -461,17 +461,17 @@
   }
 
   if (optional)
-    compose_status_line (buf, buflen, col, menu, ifstring);
+    compose_status_line (buf, buflen, col, cols, menu, ifstring);
   else if (flags & M_FORMAT_OPTIONAL)
-    compose_status_line (buf, buflen, col, menu, elsestring);
+    compose_status_line (buf, buflen, col, cols, menu, elsestring);
 
   return (src);
 }
 
-static void compose_status_line (char *buf, size_t buflen, size_t col, 
MUTTMENU *menu, 
-      const char *p)
+static void compose_status_line (char *buf, size_t buflen, size_t col, int 
cols,
+                                 MUTTMENU *menu, const char *p)
 {
-  mutt_FormatString (buf, buflen, col, p, compose_format_str, 
+  mutt_FormatString (buf, buflen, col, cols, p, compose_format_str, 
         (unsigned long) menu, 0);
 }
 
@@ -515,7 +515,7 @@
   menu->tag = mutt_tag_attach;
   menu->data = idx;
   menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, 
ComposeHelp);
-  
+
   while (loop)
   {
     switch (op = mutt_menuLoop (menu))
@@ -523,7 +523,7 @@
       case OP_REDRAW:
        draw_envelope (msg, fcc);
        menu->offset = HDR_ATTACH;
-       menu->pagelen = LINES - HDR_ATTACH - 2;
+       menu->pagelen = MuttIndexWindow->rows - HDR_ATTACH;
        break;
       case OP_COMPOSE_EDIT_FROM:
        menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
@@ -564,11 +564,11 @@
        if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
        {
          mutt_str_replace (&msg->env->subject, buf);
-         move (HDR_SUBJECT, HDR_XOFFSET);
+         mutt_window_move (MuttIndexWindow, HDR_SUBJECT, HDR_XOFFSET);
          if (msg->env->subject)
            mutt_paddstr (W, msg->env->subject);
          else
-           clrtoeol();
+           mutt_window_clrtoeol(MuttIndexWindow);
        }
         mutt_message_hook (NULL, msg, M_SEND2HOOK);
         break;
@@ -582,7 +582,7 @@
        {
          strfcpy (fcc, buf, fcclen);
          mutt_pretty_mailbox (fcc, fcclen);
-         move (HDR_FCC, HDR_XOFFSET);
+         mutt_window_move (MuttIndexWindow, HDR_FCC, HDR_XOFFSET);
          mutt_paddstr (W, fcc);
          fccSet = 1;
        }
@@ -1055,7 +1055,7 @@
          int itype;
          FILE *fp;
 
-         CLEARLINE (LINES-1);
+          mutt_window_clearline (MuttMessageWindow, 0);
          fname[0] = 0;
          if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
              != 0 || !fname[0])
@@ -1313,10 +1313,10 @@
     /* Draw formatted compose status line */
     if (menu->redraw & REDRAW_STATUS) 
     {
-       compose_status_line (buf, sizeof (buf), 0, menu, NONULL(ComposeFormat));
-       move(option (OPTSTATUSONTOP) ? 0 : LINES-2, 0);
+        compose_status_line (buf, sizeof (buf), 0, MuttStatusWindow->cols, 
menu, NONULL(ComposeFormat));
+       mutt_window_move (MuttStatusWindow, 0, 0);
        SETCOLOR (MT_COLOR_STATUS);
-       mutt_paddstr (COLS, buf);
+       mutt_paddstr (MuttStatusWindow->cols, buf);
        NORMAL_COLOR;
        menu->redraw &= ~REDRAW_STATUS;
     }
diff -r 8083387557d9 -r efa6f7910c94 copy.c
--- a/copy.c    Wed Apr 27 13:21:15 2016 -0700
+++ b/copy.c    Wed Apr 27 17:56:59 2016 -0700
@@ -288,7 +288,8 @@
       if (flags & (CH_DECODE|CH_PREFIX))
       {
        if (mutt_write_one_header (out, 0, headers[x], 
-                                  flags & CH_PREFIX ? prefix : 0, 
mutt_term_width (Wrap), flags) == -1)
+                                  flags & CH_PREFIX ? prefix : 0,
+                                   mutt_window_wrap_cols (MuttIndexWindow, 
Wrap), flags) == -1)
        {
          error = TRUE;
          break;
diff -r 8083387557d9 -r efa6f7910c94 crypt-gpgme.c
--- a/crypt-gpgme.c     Wed Apr 27 13:21:15 2016 -0700
+++ b/crypt-gpgme.c     Wed Apr 27 17:56:59 2016 -0700
@@ -2744,6 +2744,7 @@
 static const char *crypt_entry_fmt (char *dest,
                                     size_t destlen,
                                    size_t col,
+                                    int cols,
                                     char op,
                                     const char *src,
                                     const char *prefix,
@@ -2941,9 +2942,9 @@
   }
 
   if (optional)
-    mutt_FormatString (dest, destlen, col, ifstring, mutt_attach_fmt, data, 0);
+    mutt_FormatString (dest, destlen, col, cols, ifstring, mutt_attach_fmt, 
data, 0);
   else if (flags & M_FORMAT_OPTIONAL)
-    mutt_FormatString (dest, destlen, col, elsestring, mutt_attach_fmt, data, 
0);
+    mutt_FormatString (dest, destlen, col, cols, elsestring, mutt_attach_fmt, 
data, 0);
   return (src);
 }
       
@@ -2956,7 +2957,7 @@
   entry.key = key_table[num];
   entry.num = num + 1;
 
-  mutt_FormatString (s, l, 0, NONULL (PgpEntryFormat), crypt_entry_fmt, 
+  mutt_FormatString (s, l, 0, MuttIndexWindow->cols, NONULL (PgpEntryFormat), 
crypt_entry_fmt, 
                     (unsigned long) &entry, M_FORMAT_ARROWCURSOR);
 }
 
diff -r 8083387557d9 -r efa6f7910c94 curs_lib.c
--- a/curs_lib.c        Wed Apr 27 13:21:15 2016 -0700
+++ b/curs_lib.c        Wed Apr 27 17:56:59 2016 -0700
@@ -63,6 +63,14 @@
 static size_t UngetLen = 0;
 static event_t *UngetKeyEvents;
 
+mutt_window_t *MuttHelpWindow = NULL;
+mutt_window_t *MuttIndexWindow = NULL;
+mutt_window_t *MuttStatusWindow = NULL;
+mutt_window_t *MuttMessageWindow = NULL;
+#ifdef USE_SIDEBAR
+mutt_window_t *MuttSidebarWindow = NULL;
+#endif
+
 void mutt_refresh (void)
 {
   /* don't refresh when we are waiting for a child. */
@@ -146,22 +154,22 @@
 int _mutt_get_field (const char *field, char *buf, size_t buflen, int 
complete, int multiple, char ***files, int *numfiles)
 {
   int ret;
-  int x, y;
+  int x;
 
   ENTER_STATE *es = mutt_new_enter_state();
   
   do
   {
-    CLEARLINE (LINES-1);
+    mutt_window_clearline (MuttMessageWindow, 0);
     SETCOLOR (MT_COLOR_PROMPT);
     addstr ((char *)field); /* cast to get around bad prototypes */
     NORMAL_COLOR;
     mutt_refresh ();
-    getyx (stdscr, y, x);
-    ret = _mutt_enter_string (buf, buflen, y, x, complete, multiple, files, 
numfiles, es);
+    mutt_window_getyx (MuttMessageWindow, &ret, &x);  /* don't care about y: 
avoiding unused var warning */
+    ret = _mutt_enter_string (buf, buflen, x, complete, multiple, files, 
numfiles, es);
   }
   while (ret == 1);
-  CLEARLINE (LINES-1);
+  mutt_window_clearline (MuttMessageWindow, 0);
   mutt_free_enter_state (&es);
   
   return (ret);
@@ -182,7 +190,7 @@
 {
   Errorbuf[0] = 0;
   if (!option(OPTNOCURSES))
-    CLEARLINE (LINES-1);
+    mutt_window_clearline (MuttMessageWindow, 0);
 }
 
 void mutt_edit_file (const char *editor, const char *data)
@@ -229,7 +237,7 @@
             !REGCOMP (&reno, expr, REG_NOSUB);
 #endif
 
-  CLEARLINE(LINES-1);
+  mutt_window_clearline (MuttMessageWindow, 0);
 
   /*
    * In order to prevent the default answer to the question to wrapped
@@ -240,7 +248,7 @@
   safe_asprintf (&answer_string, " ([%s]/%s): ", def == M_YES ? yes : no, def 
== M_YES ? no : yes);
   answer_string_len = mutt_strwidth (answer_string);
   /* maxlen here is sort of arbitrary, so pick a reasonable upper bound */
-  msglen = mutt_wstr_trunc (msg, 4*COLS, COLS - answer_string_len, NULL);
+  msglen = mutt_wstr_trunc (msg, 4*MuttMessageWindow->cols, 
MuttMessageWindow->cols - answer_string_len, NULL);
   SETCOLOR (MT_COLOR_PROMPT);
   addnstr (msg, msglen);
   addstr (answer_string);
@@ -333,16 +341,16 @@
 
   dprint (1, (debugfile, "%s\n", scratch));
   mutt_format_string (Errorbuf, sizeof (Errorbuf),
-                     0, COLS, FMT_LEFT, 0, scratch, sizeof (scratch), 0);
+                     0, MuttMessageWindow->cols, FMT_LEFT, 0, scratch, sizeof 
(scratch), 0);
 
   if (!option (OPTKEEPQUIET))
   {
     if (error)
       BEEP ();
     SETCOLOR (error ? MT_COLOR_ERROR : MT_COLOR_MESSAGE);
-    mvaddstr (LINES-1, 0, Errorbuf);
+    mutt_window_mvaddstr (MuttMessageWindow, 0, 0, Errorbuf);
     NORMAL_COLOR;
-    clrtoeol ();
+    mutt_window_clrtoeol (MuttMessageWindow);
     mutt_refresh ();
   }
 
@@ -479,15 +487,161 @@
     mutt_clear_error ();
 }
 
+void mutt_init_windows ()
+{
+  MuttHelpWindow = safe_calloc (sizeof (mutt_window_t), 1);
+  MuttIndexWindow = safe_calloc (sizeof (mutt_window_t), 1);
+  MuttStatusWindow = safe_calloc (sizeof (mutt_window_t), 1);
+  MuttMessageWindow = safe_calloc (sizeof (mutt_window_t), 1);
+#ifdef USE_SIDEBAR
+  MuttSidebarWindow = safe_calloc (sizeof (mutt_window_t), 1);
+#endif
+
+  mutt_reflow_windows ();
+}
+
+void mutt_free_windows ()
+{
+  FREE (&MuttHelpWindow);
+  FREE (&MuttIndexWindow);
+  FREE (&MuttStatusWindow);
+  FREE (&MuttMessageWindow);
+#ifdef USE_SIDEBAR
+  FREE (&MuttSidebarWindow);
+#endif
+}
+
+void mutt_reflow_windows (void)
+{
+  if (option (OPTNOCURSES))
+    return;
+
+  dprint (2, (debugfile, "In mutt_reflow_windows\n"));
+
+  MuttStatusWindow->rows = 1;
+  MuttStatusWindow->cols = COLS;
+  MuttStatusWindow->row_offset = option (OPTSTATUSONTOP) ? 0 : LINES - 2;
+  MuttStatusWindow->col_offset = 0;
+
+  memcpy (MuttHelpWindow, MuttStatusWindow, sizeof (mutt_window_t));
+  if (! option (OPTHELP))
+    MuttHelpWindow->rows = 0;
+  else
+    MuttHelpWindow->row_offset = option (OPTSTATUSONTOP) ? LINES - 2 : 0;
+
+  memcpy (MuttMessageWindow, MuttStatusWindow, sizeof (mutt_window_t));
+  MuttMessageWindow->row_offset = LINES - 1;
+
+  memcpy (MuttIndexWindow, MuttStatusWindow, sizeof (mutt_window_t));
+  MuttIndexWindow->rows = LINES - MuttStatusWindow->rows - 
MuttHelpWindow->rows -
+                          MuttMessageWindow->rows;
+  MuttIndexWindow->row_offset = option (OPTSTATUSONTOP) ? 
MuttStatusWindow->rows :
+                                                          MuttHelpWindow->rows;
+
+#ifdef USE_SIDEBAR
+  if (option (OPTSIDEBAR))
+  {
+    memcpy (MuttSidebarWindow, MuttIndexWindow, sizeof (mutt_window_t));
+    MuttSidebarWindow->cols = SidebarWidth;
+
+    MuttIndexWindow->cols -= SidebarWidth;
+    MuttIndexWindow->col_offset += SidebarWidth;
+  }
+#endif
+}
+
+int mutt_window_move (mutt_window_t *win, int row, int col)
+{
+  return move (win->row_offset + row, win->col_offset + col);
+}
+
+int mutt_window_mvaddch (mutt_window_t *win, int row, int col, const chtype ch)
+{
+  return mvaddch (win->row_offset + row, win->col_offset + col, ch);
+}
+
+int mutt_window_mvaddstr (mutt_window_t *win, int row, int col, const char 
*str)
+{
+  return mvaddstr (win->row_offset + row, win->col_offset + col, str);
+}
+
+#ifdef USE_SLANG_CURSES
+static int vw_printw (SLcurses_Window_Type *win, const char *fmt, va_list ap)
+{
+  char buf[LONG_STRING];
+
+  (void) SLvsnprintf (buf, sizeof (buf), (char *)fmt, ap);
+  SLcurses_waddnstr (win, buf, -1);
+  return 0;
+}
+#endif
+
+int mutt_window_mvprintw (mutt_window_t *win, int row, int col, const char 
*fmt, ...)
+{
+  va_list ap;
+  int rv;
+
+  if ((rv = mutt_window_move (win, row, col) != ERR))
+  {
+    va_start (ap, fmt);
+    rv = vw_printw (stdscr, fmt, ap);
+    va_end (ap);
+  }
+
+  return rv;
+}
+
+/* Assumes the cursor has already been positioned within the
+ * window.
+ */
+void mutt_window_clrtoeol (mutt_window_t *win)
+{
+  int row, col, curcol;
+
+  if (win->col_offset + win->cols == COLS)
+    clrtoeol ();
+  else
+  {
+    getyx (stdscr, row, col);
+    curcol = col;
+    while (curcol < win->col_offset + win->cols)
+    {
+      addch (' ');
+      curcol++;
+    }
+    move (row, col);
+  }
+}
+
+void mutt_window_clearline (mutt_window_t *win, int row)
+{
+  mutt_window_move (win, row, 0);
+  mutt_window_clrtoeol (win);
+}
+
+/* Assumes the current position is inside the window.
+ * Otherwise it will happily return negative or values outside
+ * the window boundaries
+ */
+void mutt_window_getyx (mutt_window_t *win, int *y, int *x)
+{
+  int row, col;
+
+  getyx (stdscr, row, col);
+  *y = row - win->row_offset;
+  *x = col - win->col_offset;
+}
+
+
 void mutt_show_error (void)
 {
   if (option (OPTKEEPQUIET))
     return;
   
   SETCOLOR (option (OPTMSGERR) ? MT_COLOR_ERROR : MT_COLOR_MESSAGE);
-  mvaddstr(LINES-1, 0, Errorbuf);
+  mutt_window_mvaddstr (MuttMessageWindow, 0, 0, Errorbuf);
   NORMAL_COLOR;
-  clrtoeol();
+  mutt_window_clrtoeol(MuttMessageWindow);
 }
 
 void mutt_endwin (const char *msg)
@@ -582,18 +736,18 @@
   event_t ch;
 
   SETCOLOR (MT_COLOR_PROMPT);
-  mvaddstr (LINES-1, 0, (char *) prompt);
+  mutt_window_mvaddstr (MuttMessageWindow, 0, 0, (char *) prompt);
   addstr (_(" ('?' for list): "));
   NORMAL_COLOR;
   if (buf[0])
     addstr (buf);
-  clrtoeol ();
+  mutt_window_clrtoeol (MuttMessageWindow);
   mutt_refresh ();
 
   ch = mutt_getch();
   if (ch.ch < 0)
   {
-    CLEARLINE (LINES-1);
+    mutt_window_clearline (MuttMessageWindow, 0);
     return (-1);
   }
   else if (ch.ch == '?')
@@ -706,9 +860,9 @@
   char *p;
 
   SETCOLOR (MT_COLOR_PROMPT);
-  mvaddstr (LINES - 1, 0, prompt);
+  mutt_window_mvaddstr (MuttMessageWindow, 0, 0, prompt);
   NORMAL_COLOR;
-  clrtoeol ();
+  mutt_window_clrtoeol (MuttMessageWindow);
   FOREVER
   {
     mutt_refresh ();
@@ -736,7 +890,7 @@
     }
     BEEP ();
   }
-  CLEARLINE (LINES - 1);
+  mutt_window_clearline (MuttMessageWindow, 0);
   mutt_refresh ();
   return choice;
 }
diff -r 8083387557d9 -r efa6f7910c94 curs_main.c
--- a/curs_main.c       Wed Apr 27 13:21:15 2016 -0700
+++ b/curs_main.c       Wed Apr 27 17:56:59 2016 -0700
@@ -510,8 +510,6 @@
   int attach_msg = option(OPTATTACHMSG);
 
   menu = mutt_new_menu (MENU_MAIN);
-  menu->offset = 1;
-  menu->pagelen = LINES - 3;
   menu->make_entry = index_make_entry;
   menu->color = index_color;
   menu->current = ci_first_message ();
@@ -631,9 +629,9 @@
       if (menu->redraw & REDRAW_STATUS)
       {
        menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
-       move (option (OPTSTATUSONTOP) ? 0 : LINES-2, 0);
+        mutt_window_move (MuttStatusWindow, 0, 0);
        SETCOLOR (MT_COLOR_STATUS);
-       mutt_paddstr (COLS, buf);
+       mutt_paddstr (MuttStatusWindow->cols, buf);
        NORMAL_COLOR;
        menu->redraw &= ~REDRAW_STATUS;
        if (option(OPTTSENABLED) && TSSupported)
@@ -652,11 +650,12 @@
        menu->oldcurrent = -1;
 
       if (option (OPTARROWCURSOR))
-       move (menu->current - menu->top + menu->offset, 2);
+       mutt_window_move (MuttIndexWindow, menu->current - menu->top + 
menu->offset, 2);
       else if (option (OPTBRAILLEFRIENDLY))
-       move (menu->current - menu->top + menu->offset, 0);
+       mutt_window_move (MuttIndexWindow, menu->current - menu->top + 
menu->offset, 0);
       else
-       move (menu->current - menu->top + menu->offset, COLS - 1);
+       mutt_window_move (MuttIndexWindow, menu->current - menu->top + 
menu->offset,
+                          MuttIndexWindow->cols - 1);
       mutt_refresh ();
 
 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
@@ -703,14 +702,14 @@
        tag = 1;
 
        /* give visual indication that the next command is a tag- command */
-       mvaddstr (LINES - 1, 0, "tag-");
-       clrtoeol ();
+       mutt_window_mvaddstr (MuttMessageWindow, 0, 0, "tag-");
+       mutt_window_clrtoeol (MuttMessageWindow);
 
        /* get the real command */
        if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX)
        {
          /* abort tag sequence */
-         CLEARLINE (LINES-1);
+          mutt_window_clearline (MuttMessageWindow, 0);
          continue;
        }
       }
@@ -734,14 +733,14 @@
        tag = 1;
 
        /* give visual indication that the next command is a tag- command */
-       mvaddstr (LINES - 1, 0, "tag-");
-       clrtoeol ();
+       mutt_window_mvaddstr (MuttMessageWindow, 0, 0, "tag-");
+       mutt_window_clrtoeol (MuttMessageWindow);
 
        /* get the real command */
        if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX)
        {
          /* abort tag sequence */
-         CLEARLINE (LINES-1);
+         mutt_window_clearline (MuttMessageWindow, 0);
          continue;
        }
       }
@@ -1193,7 +1192,7 @@
          }
          if (!buf[0])
          {
-           CLEARLINE (LINES-1);
+            mutt_window_clearline (MuttMessageWindow, 0);
            break;
          }
        }
diff -r 8083387557d9 -r efa6f7910c94 edit.c
--- a/edit.c    Wed Apr 27 13:21:15 2016 -0700
+++ b/edit.c    Wed Apr 27 17:56:59 2016 -0700
@@ -234,7 +234,7 @@
 {
   char tmp[HUGE_STRING];
 
-  move (LINES-1, 0);
+  mutt_window_move (MuttMessageWindow, 0, 0);
 
   addstr ("To: ");
   tmp[0] = 0;
@@ -242,7 +242,7 @@
   rfc822_write_address (tmp, sizeof (tmp), e->to, 0);
   if (!e->to || force)
   {
-    if (mutt_enter_string (tmp, sizeof (tmp), LINES-1, 4, 0) == 0)
+    if (mutt_enter_string (tmp, sizeof (tmp), 4, 0) == 0)
     {
       rfc822_free_address (&e->to);
       e->to = mutt_parse_adrlist (e->to, tmp);
@@ -250,7 +250,7 @@
       mutt_addrlist_to_intl (e->to, NULL);     /* XXX - IDNA error reporting? 
*/
       tmp[0] = 0;
       rfc822_write_address (tmp, sizeof (tmp), e->to, 1);
-      mvaddstr (LINES - 1, 4, tmp);
+      mutt_window_mvaddstr (MuttMessageWindow, 0, 4, tmp);
     }
   }
   else
@@ -264,7 +264,7 @@
   {
     addstr ("Subject: ");
     strfcpy (tmp, e->subject ? e->subject: "", sizeof (tmp));
-    if (mutt_enter_string (tmp, sizeof (tmp), LINES-1, 9, 0) == 0)
+    if (mutt_enter_string (tmp, sizeof (tmp), 9, 0) == 0)
       mutt_str_replace (&e->subject, tmp);
     addch ('\n');
   }
@@ -275,7 +275,7 @@
     tmp[0] = 0;
     mutt_addrlist_to_local (e->cc);
     rfc822_write_address (tmp, sizeof (tmp), e->cc, 0);
-    if (mutt_enter_string (tmp, sizeof (tmp), LINES-1, 4, 0) == 0)
+    if (mutt_enter_string (tmp, sizeof (tmp), 4, 0) == 0)
     {
       rfc822_free_address (&e->cc);
       e->cc = mutt_parse_adrlist (e->cc, tmp);
@@ -283,7 +283,7 @@
       tmp[0] = 0;
       mutt_addrlist_to_intl (e->cc, NULL);
       rfc822_write_address (tmp, sizeof (tmp), e->cc, 1);
-      mvaddstr (LINES - 1, 4, tmp);
+      mutt_window_mvaddstr (MuttMessageWindow, 0, 4, tmp);
     }
     else
       mutt_addrlist_to_intl (e->cc, NULL);
@@ -296,7 +296,7 @@
     tmp[0] = 0;
     mutt_addrlist_to_local (e->bcc);
     rfc822_write_address (tmp, sizeof (tmp), e->bcc, 0);
-    if (mutt_enter_string (tmp, sizeof (tmp), LINES-1, 5, 0) == 0)
+    if (mutt_enter_string (tmp, sizeof (tmp), 5, 0) == 0)
     {
       rfc822_free_address (&e->bcc);
       e->bcc = mutt_parse_adrlist (e->bcc, tmp);
@@ -304,7 +304,7 @@
       mutt_addrlist_to_intl (e->bcc, NULL);
       tmp[0] = 0;
       rfc822_write_address (tmp, sizeof (tmp), e->bcc, 1);
-      mvaddstr (LINES - 1, 5, tmp);
+      mutt_window_mvaddstr (MuttMessageWindow, 0, 5, tmp);
     }
     else
       mutt_addrlist_to_intl (e->bcc, NULL);
@@ -333,7 +333,7 @@
   tmp[0] = 0;
   while (!done)
   {
-    if (mutt_enter_string (tmp, sizeof (tmp), LINES-1, 0, 0) == -1)
+    if (mutt_enter_string (tmp, sizeof (tmp), 0, 0) == -1)
     {
       tmp[0] = 0;
       continue;
diff -r 8083387557d9 -r efa6f7910c94 enter.c
--- a/enter.c   Wed Apr 27 13:21:15 2016 -0700
+++ b/enter.c   Wed Apr 27 17:56:59 2016 -0700
@@ -210,20 +210,20 @@
  *     -1 if abort.
  */
 
-int  mutt_enter_string(char *buf, size_t buflen, int y, int x, int flags)
+int  mutt_enter_string(char *buf, size_t buflen, int col, int flags)
 {
   int rv;
   ENTER_STATE *es = mutt_new_enter_state ();
-  rv = _mutt_enter_string (buf, buflen, y, x, flags, 0, NULL, NULL, es);
+  rv = _mutt_enter_string (buf, buflen, col, flags, 0, NULL, NULL, es);
   mutt_free_enter_state (&es);
   return rv;
 }
 
-int _mutt_enter_string (char *buf, size_t buflen, int y, int x,
+int _mutt_enter_string (char *buf, size_t buflen, int col,
                        int flags, int multiple, char ***files, int *numfiles,
                        ENTER_STATE *state)
 {
-  int width = COLS - x - 1;
+  int width = MuttMessageWindow->cols - col - 1;
   int redraw;
   int pass = (flags & M_PASS);
   int first = 1;
@@ -280,7 +280,7 @@
       if (state->curpos < state->begin ||
          my_wcswidth (state->wbuf + state->begin, state->curpos - 
state->begin) >= width)
        state->begin = width_ceiling (state->wbuf, state->lastchar, my_wcswidth 
(state->wbuf, state->curpos) - width / 2);
-      move (y, x);
+      mutt_window_move (MuttMessageWindow, 0, col);
       w = 0;
       for (i = state->begin; i < state->lastchar; i++)
       {
@@ -289,8 +289,9 @@
          break;
        my_addwch (state->wbuf[i]);
       }
-      clrtoeol ();
-      move (y, x + my_wcswidth (state->wbuf + state->begin, state->curpos - 
state->begin));
+      mutt_window_clrtoeol (MuttMessageWindow);
+      mutt_window_move (MuttMessageWindow, 0,
+          col + my_wcswidth (state->wbuf + state->begin, state->curpos - 
state->begin));
     }
     mutt_refresh ();
 
diff -r 8083387557d9 -r efa6f7910c94 flags.c
--- a/flags.c   Wed Apr 27 13:21:15 2016 -0700
+++ b/flags.c   Wed Apr 27 17:56:59 2016 -0700
@@ -322,18 +322,19 @@
   int i, flag;
   event_t event;
 
-  mvprintw (LINES - 1, 0, "%s? (D/N/O/r/*/!): ", bf ? _("Set flag") : _("Clear 
flag"));
-  clrtoeol ();
+  mutt_window_mvprintw (MuttMessageWindow, 0, 0,
+                        "%s? (D/N/O/r/*/!): ", bf ? _("Set flag") : _("Clear 
flag"));
+  mutt_window_clrtoeol (MuttMessageWindow);
 
   event = mutt_getch();
   i = event.ch;
   if (i < 0)
   {
-    CLEARLINE (LINES-1);
+    mutt_window_clearline (MuttMessageWindow, 0);
     return (-1);
   }
 
-  CLEARLINE (LINES-1);
+  mutt_window_clearline (MuttMessageWindow, 0);
 
   switch (i)
   {
diff -r 8083387557d9 -r efa6f7910c94 handler.c
--- a/handler.c Wed Apr 27 13:21:15 2016 -0700
+++ b/handler.c Wed Apr 27 17:56:59 2016 -0700
@@ -791,7 +791,8 @@
 
   memset (&stte, 0, sizeof (stte));
   stte.s = s;
-  stte.WrapMargin = ((s->flags & M_DISPLAY) ? (COLS-4) : 
((COLS-4)<72)?(COLS-4):72);
+  stte.WrapMargin = ((s->flags & M_DISPLAY) ? (MuttIndexWindow->cols-4) :
+                     
((MuttIndexWindow->cols-4)<72)?(MuttIndexWindow->cols-4):72);
   stte.line_max = stte.WrapMargin * 4;
   stte.line = (wchar_t *) safe_calloc (1, (stte.line_max + 1) * sizeof 
(wchar_t));

Reply via email to