]> granicus.if.org Git - neomutt/commitdiff
split out window functions
authorRichard Russon <rich@flatcap.org>
Sun, 1 Apr 2018 04:12:17 +0000 (05:12 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 1 Apr 2018 04:12:17 +0000 (05:12 +0100)
41 files changed:
Makefile.autosetup
addrbook.c
browser.c
buffy.c
commands.c
compose.c
copy.c
curs_lib.c
curs_main.c
edit.c
enter.c
filter.c
flags.c
handler.c
hdrline.c
help.c
history.c
init.c
keymap.c
main.c
menu.c
mutt_curses.h
mutt_logging.c
mutt_window.c [new file with mode: 0644]
mutt_window.h [new file with mode: 0644]
muttlib.c
ncrypt/crypt_gpgme.c
ncrypt/pgpinvoke.c
ncrypt/pgpkey.c
ncrypt/smime.c
newsrc.c
pager.c
query.c
recvattach.c
recvcmd.c
remailer.c
resize.c
rfc3676.c
sendlib.c
sidebar.c
status.c

index a49de85af34d69f1100702abd699699f949f432c..847d2945505c0f1545e5f6be6fa9639704c90326 100644 (file)
@@ -65,7 +65,7 @@ NEOMUTTOBJS=  addrbook.o alias.o attach.o bcache.o body.o browser.o buffy.o \
                enter.o envelope.o filter.o flags.o from.o group.o handler.o \
                hdrline.o header.o help.o history.o hook.o init.o keymap.o \
                main.o mbox.o menu.o mh.o muttlib.o mutt_account.o \
-               mutt_logging.o mutt_signal.o mutt_socket.o mx.o newsrc.o \
+               mutt_logging.o mutt_signal.o mutt_socket.o mutt_window.o mx.o newsrc.o \
                nntp.o pager.o parse.o pattern.o pop.o pop_auth.o pop_lib.o \
                postpone.o query.o recvattach.o recvcmd.o resize.o rfc1524.o \
                rfc2047.o rfc2231.o rfc3676.o safe_asprintf.o score.o send.o \
index 643aaff3e44c2f12278e2cc158f9c30aa1db17d9..7fd999869949fea5d4c771a2e944517b4f2eb7d6 100644 (file)
@@ -32,6 +32,7 @@
 #include "keymap.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "opcodes.h"
 #include "options.h"
 #include "protos.h"
index 7d64c501d5f193b9da195b955a9c82da650388ef..e09dfd0c24ce5cdf2182d998f96fde35263bb74f 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -50,6 +50,7 @@
 #include "mutt_account.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "opcodes.h"
 #include "options.h"
diff --git a/buffy.c b/buffy.c
index 652f4ebd5415b21b55e9553feb5cc75a3031dc55..afbd34035f51f93a9f0002e49718fd073edc0198 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -39,6 +39,7 @@
 #include "mailbox.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "options.h"
 #include "protos.h"
index 334a4d1dc9bbc279b20051b8e51b72eec3040388..41f0ab49c62f6a374e3bfe2e155bd5419c938826 100644 (file)
@@ -46,6 +46,7 @@
 #include "mailbox.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "ncrypt/ncrypt.h"
 #include "options.h"
index 689f4ff2ba1622f9afe805c0cebaa5a51ecb136c..ef5a81a3f0e57abcf0cd9f30e79e0f171664d520 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -45,6 +45,7 @@
 #include "mailbox.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "ncrypt/ncrypt.h"
 #include "opcodes.h"
diff --git a/copy.c b/copy.c
index 2d0b6c3f3c937b8bb3882fcbb5b341b5b13e7db3..ab5487c51fca6b7fa6ad6337e7e026cf46f39eca 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -35,6 +35,7 @@
 #include "header.h"
 #include "mailbox.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "ncrypt/ncrypt.h"
 #include "options.h"
index 5773acf66c13a7f2e14662cc6c0eee8fa5a90c8f..6d801dcdb178b6f7feed302d90d85b97d5c95e4c 100644 (file)
@@ -46,6 +46,7 @@
 #include "header.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "opcodes.h"
 #include "options.h"
 #include "pager.h"
@@ -76,16 +77,6 @@ static size_t UngetCount = 0;
 static size_t UngetLen = 0;
 static struct Event *UngetKeyEvents;
 
-struct MuttWindow *MuttHelpWindow = NULL;
-struct MuttWindow *MuttIndexWindow = NULL;
-struct MuttWindow *MuttStatusWindow = NULL;
-struct MuttWindow *MuttMessageWindow = NULL;
-#ifdef USE_SIDEBAR
-struct MuttWindow *MuttSidebarWindow = NULL;
-#endif
-
-static void reflow_message_window_rows(int mw_rows);
-
 void mutt_refresh(void)
 {
   /* don't refresh when we are waiting for a child. */
@@ -191,7 +182,7 @@ int mutt_get_field_full(const char *field, char *buf, size_t buflen,
     addstr((char *) field); /* cast to get around bad prototypes */
     NORMAL_COLOR;
     mutt_refresh();
-    mutt_window_getyx(MuttMessageWindow, NULL, &x);
+    mutt_window_getxy(MuttMessageWindow, &x, NULL);
     ret = mutt_enter_string_full(buf, buflen, x, complete, multiple, files, numfiles, es);
   } while (ret == 1);
   mutt_window_clearline(MuttMessageWindow, 0);
@@ -283,7 +274,7 @@ int mutt_yesorno(const char *msg, int def)
       }
       if (prompt_lines != MuttMessageWindow->rows)
       {
-        reflow_message_window_rows(prompt_lines);
+        mutt_window_reflow_message_rows(prompt_lines);
         mutt_menu_current_redraw();
       }
 
@@ -341,7 +332,7 @@ int mutt_yesorno(const char *msg, int def)
 
   if (MuttMessageWindow->rows != 1)
   {
-    reflow_message_window_rows(1);
+    mutt_window_reflow_message_rows(1);
     mutt_menu_current_redraw();
   }
   else
@@ -551,190 +542,6 @@ out:
     mutt_clear_error();
 }
 
-void mutt_init_windows(void)
-{
-  MuttHelpWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
-  MuttIndexWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
-  MuttStatusWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
-  MuttMessageWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
-#ifdef USE_SIDEBAR
-  MuttSidebarWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
-#endif
-}
-
-void mutt_free_windows(void)
-{
-  FREE(&MuttHelpWindow);
-  FREE(&MuttIndexWindow);
-  FREE(&MuttStatusWindow);
-  FREE(&MuttMessageWindow);
-#ifdef USE_SIDEBAR
-  FREE(&MuttSidebarWindow);
-#endif
-}
-
-void mutt_reflow_windows(void)
-{
-  if (OPT_NO_CURSES)
-    return;
-
-  mutt_debug(2, "entering\n");
-
-  MuttStatusWindow->rows = 1;
-  MuttStatusWindow->cols = COLS;
-  MuttStatusWindow->row_offset = StatusOnTop ? 0 : LINES - 2;
-  MuttStatusWindow->col_offset = 0;
-
-  memcpy(MuttHelpWindow, MuttStatusWindow, sizeof(struct MuttWindow));
-  if (!Help)
-    MuttHelpWindow->rows = 0;
-  else
-    MuttHelpWindow->row_offset = StatusOnTop ? LINES - 2 : 0;
-
-  memcpy(MuttMessageWindow, MuttStatusWindow, sizeof(struct MuttWindow));
-  MuttMessageWindow->row_offset = LINES - 1;
-
-  memcpy(MuttIndexWindow, MuttStatusWindow, sizeof(struct MuttWindow));
-  MuttIndexWindow->rows = MAX(
-      LINES - MuttStatusWindow->rows - MuttHelpWindow->rows - MuttMessageWindow->rows, 0);
-  MuttIndexWindow->row_offset =
-      StatusOnTop ? MuttStatusWindow->rows : MuttHelpWindow->rows;
-
-#ifdef USE_SIDEBAR
-  if (SidebarVisible)
-  {
-    memcpy(MuttSidebarWindow, MuttIndexWindow, sizeof(struct MuttWindow));
-    MuttSidebarWindow->cols = SidebarWidth;
-    MuttIndexWindow->cols -= SidebarWidth;
-
-    if (SidebarOnRight)
-    {
-      MuttSidebarWindow->col_offset = COLS - SidebarWidth;
-    }
-    else
-    {
-      MuttIndexWindow->col_offset += SidebarWidth;
-    }
-  }
-#endif
-
-  mutt_menu_set_current_redraw_full();
-  /* the pager menu needs this flag set to recalc line_info */
-  mutt_menu_set_current_redraw(REDRAW_FLOW);
-}
-
-static void reflow_message_window_rows(int mw_rows)
-{
-  MuttMessageWindow->rows = mw_rows;
-  MuttMessageWindow->row_offset = LINES - mw_rows;
-
-  MuttStatusWindow->row_offset = StatusOnTop ? 0 : LINES - mw_rows - 1;
-
-  if (Help)
-    MuttHelpWindow->row_offset = StatusOnTop ? LINES - mw_rows - 1 : 0;
-
-  MuttIndexWindow->rows = MAX(
-      LINES - MuttStatusWindow->rows - MuttHelpWindow->rows - MuttMessageWindow->rows, 0);
-
-#ifdef USE_SIDEBAR
-  if (SidebarVisible)
-    MuttSidebarWindow->rows = MuttIndexWindow->rows;
-#endif
-
-  /* We don't also set REDRAW_FLOW because this function only
-   * changes rows and is a temporary adjustment. */
-  mutt_menu_set_current_redraw_full();
-}
-
-int mutt_window_move(struct MuttWindow *win, int row, int col)
-{
-  return move(win->row_offset + row, win->col_offset + col);
-}
-
-int mutt_window_mvaddch(struct MuttWindow *win, int row, int col, const chtype ch)
-{
-  return mvaddch(win->row_offset + row, win->col_offset + col, ch);
-}
-
-int mutt_window_mvaddstr(struct MuttWindow *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(struct MuttWindow *win, int row, int col, const char *fmt, ...)
-{
-  int rc = mutt_window_move(win, row, col);
-  if (rc != ERR)
-  {
-    va_list ap;
-    va_start(ap, fmt);
-    rc = vw_printw(stdscr, fmt, ap);
-    va_end(ap);
-  }
-
-  return rc;
-}
-
-/**
- * mutt_window_clrtoeol - Clear to the end of the line
- *
- * Assumes the cursor has already been positioned within the window.
- */
-void mutt_window_clrtoeol(struct MuttWindow *win)
-{
-  if (!win || !stdscr)
-    return;
-
-  if (win->col_offset + win->cols == COLS)
-    clrtoeol();
-  else
-  {
-    int row, col;
-    getyx(stdscr, row, col);
-    int curcol = col;
-    while (curcol < win->col_offset + win->cols)
-    {
-      addch(' ');
-      curcol++;
-    }
-    move(row, col);
-  }
-}
-
-void mutt_window_clearline(struct MuttWindow *win, int row)
-{
-  mutt_window_move(win, row, 0);
-  mutt_window_clrtoeol(win);
-}
-
-/**
- * mutt_window_getyx - Get the cursor position in the window
- *
- * Assumes the current position is inside the window.  Otherwise it will
- * happily return negative or values outside the window boundaries
- */
-void mutt_window_getyx(struct MuttWindow *win, int *y, int *x)
-{
-  int row, col;
-
-  getyx(stdscr, row, col);
-  if (y)
-    *y = row - win->row_offset;
-  if (x)
-    *x = col - win->col_offset;
-}
-
 void mutt_show_error(void)
 {
   if (OPT_KEEP_QUIET || !ErrorBufMessage)
@@ -1006,7 +813,7 @@ int mutt_multi_choice(char *prompt, char *letters)
       }
       if (prompt_lines != MuttMessageWindow->rows)
       {
-        reflow_message_window_rows(prompt_lines);
+        mutt_window_reflow_message_rows(prompt_lines);
         mutt_menu_current_redraw();
       }
 
@@ -1048,7 +855,7 @@ int mutt_multi_choice(char *prompt, char *letters)
   }
   if (MuttMessageWindow->rows != 1)
   {
-    reflow_message_window_rows(1);
+    mutt_window_reflow_message_rows(1);
     mutt_menu_current_redraw();
   }
   else
index 77f115c1abc1f51d75a1d52cf9eb96459b5eb081..f967f15ce6fd47571edcba49dc0a340fa80d6e87 100644 (file)
@@ -43,6 +43,7 @@
 #include "mailbox.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "ncrypt/ncrypt.h"
 #include "opcodes.h"
@@ -3276,7 +3277,7 @@ int mutt_index_menu(void)
 
       case OP_SIDEBAR_TOGGLE_VISIBLE:
         SidebarVisible = !SidebarVisible;
-        mutt_reflow_windows();
+        mutt_window_reflow();
         break;
 
       case OP_SIDEBAR_TOGGLE_VIRTUAL:
diff --git a/edit.c b/edit.c
index 6dfce77b05767254e1b902a1d4391cdbc40d6fb2..b6a878c5f10aa8b8d080898d4b6bd089273017a8 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -38,6 +38,7 @@
 #include "globals.h"
 #include "header.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #include "options.h"
 #include "protos.h"
 
diff --git a/enter.c b/enter.c
index 86cd2f146c048c29648de33d68d98119918fe632..a3eb41a3fe58b95ec6976f07b959b612566e2b76 100644 (file)
--- a/enter.c
+++ b/enter.c
@@ -34,6 +34,7 @@
 #include "history.h"
 #include "keymap.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #include "opcodes.h"
 #include "protos.h"
 
index 9d172c1f02f7be55b5c80096590cfb24affb8a08..83fac2dc51f54560f1e983a2b28330c89a06faad 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -28,6 +28,7 @@
 #include "mutt.h"
 #include "filter.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #include "protos.h"
 
 /**
diff --git a/flags.c b/flags.c
index 549c5aae67bf635a058ae56bfa4f82108d03e4d5..28c75cd31b7c8529c557708fe8396aa5b47cbe01 100644 (file)
--- a/flags.c
+++ b/flags.c
@@ -30,6 +30,7 @@
 #include "header.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "options.h"
 #include "protos.h"
index 9609925e5f52cded14e6ea40ac4cbc843517828f..3282f4afec34f85a3308b8976fa113461065f057 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -42,6 +42,7 @@
 #include "globals.h"
 #include "keymap.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #include "ncrypt/ncrypt.h"
 #include "opcodes.h"
 #include "options.h"
index 11c5f4b8754798a7f56abef2b9f22f7934f3b0be..b15fe75abb1a4f8ecee96d561caccb34e6738a87 100644 (file)
--- a/hdrline.c
+++ b/hdrline.c
@@ -39,6 +39,7 @@
 #include "header.h"
 #include "mbtable.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #include "ncrypt/ncrypt.h"
 #include "options.h"
 #include "protos.h"
diff --git a/help.c b/help.c
index 3ab1258780b2d87a2ebb1ee389ee70db971f1e33..e7d47173eddea1961a98243172f37ebdb714237d 100644 (file)
--- a/help.c
+++ b/help.c
@@ -31,6 +31,7 @@
 #include "globals.h"
 #include "keymap.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #include "opcodes.h"
 #include "options.h"
 #include "pager.h"
index 088f531848cad86e854d1b37b54e3b22535036cd..b64d423abb3477d463cfedbdb376b49b5b560841 100644 (file)
--- a/history.c
+++ b/history.c
@@ -80,6 +80,7 @@
 #include "keymap.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "opcodes.h"
 #include "options.h"
 #include "protos.h"
diff --git a/init.c b/init.c
index 1db6f7796dbd0bda7fa4bc1230d667486b9fe26c..d83f16373d24ffc7816dc05c2a2a73666dee99ea 100644 (file)
--- a/init.c
+++ b/init.c
@@ -50,6 +50,7 @@
 #include "mbtable.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "myvar.h"
 #include "ncrypt/ncrypt.h"
@@ -1967,7 +1968,7 @@ static void restore_default(struct Option *p)
   if (p->flags & R_TREE)
     OPT_REDRAW_TREE = true;
   if (p->flags & R_REFLOW)
-    mutt_reflow_windows();
+    mutt_window_reflow();
 #ifdef USE_SIDEBAR
   if (p->flags & R_SIDEBAR)
     mutt_menu_set_current_redraw(REDRAW_SIDEBAR);
@@ -2715,7 +2716,7 @@ static int parse_set(struct Buffer *tmp, struct Buffer *s, unsigned long data,
       if (MuttVars[idx].flags & R_TREE)
         OPT_REDRAW_TREE = true;
       if (MuttVars[idx].flags & R_REFLOW)
-        mutt_reflow_windows();
+        mutt_window_reflow();
 #ifdef USE_SIDEBAR
       if (MuttVars[idx].flags & R_SIDEBAR)
         mutt_menu_set_current_redraw(REDRAW_SIDEBAR);
index fef10d21e7b71e3bba413fc63b3d4ca1accc3555..02fde9215c5a5b64b073c0a097256ad87231b295 100644 (file)
--- a/keymap.c
+++ b/keymap.c
@@ -34,6 +34,7 @@
 #include "functions.h"
 #include "globals.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #include "ncrypt/ncrypt.h"
 #include "opcodes.h"
 #include "options.h"
diff --git a/main.c b/main.c
index 83b0cab0a4234aa1f79948546498f1afad739053..34e1efa09381936a5d47ee7518c2219ac920d00e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -49,6 +49,7 @@
 #include "mutt_curses.h"
 #include "mutt_logging.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "myvar.h"
 #include "ncrypt/ncrypt.h"
 #include "options.h"
@@ -160,7 +161,7 @@ static int start_curses(void)
   meta(stdscr, true);
 #endif
   init_extended_keys();
-  mutt_reflow_windows();
+  mutt_window_reflow();
   return 0;
 }
 
@@ -509,7 +510,7 @@ int main(int argc, char *argv[], char *envp[])
 
   /* Always create the mutt_windows because batch mode has some shared code
    * paths that end up referencing them. */
-  mutt_init_windows();
+  mutt_window_init();
 
   /* This must come before mutt_init() because curses needs to be started
    * before calling the init_pair() function to set the color scheme.  */
@@ -946,7 +947,7 @@ int main(int argc, char *argv[], char *envp[])
       FREE(&tempfile);
     }
 
-    mutt_free_windows();
+    mutt_window_free();
 
     if (rv != 0)
       goto main_curses; // TEST36: neomutt -H existing -s test john@example.com -E (cancel sending)
@@ -1048,7 +1049,7 @@ int main(int argc, char *argv[], char *envp[])
     log_queue_empty();
     mutt_log_stop();
     mutt_free_opts();
-    mutt_free_windows();
+    mutt_window_free();
     // TEST43: neomutt (no change to mailbox)
     // TEST44: neomutt (change mailbox)
   }
diff --git a/menu.c b/menu.c
index e7194ceee2097f9e91c0342a004e1df05691ad2d..97311db5f4475bdd1e2e9c85e4a2e471ad9292cd 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -34,6 +34,7 @@
 #include "keymap.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "opcodes.h"
 #include "options.h"
 #include "pattern.h"
@@ -301,7 +302,7 @@ static void menu_pad_string(struct Menu *menu, char *buf, size_t buflen)
 
 void menu_redraw_full(struct Menu *menu)
 {
-  mutt_reflow_windows();
+  mutt_window_reflow();
   NORMAL_COLOR;
   /* clear() doesn't optimize screen redraws */
   move(0, 0);
index 9c8fbcd129b4301b1efd53b1eb366d42a5583fe3..35ed76df76e41ef610b509251706d726246908e7 100644 (file)
@@ -226,48 +226,6 @@ void mutt_progress_init(struct Progress *progress, const char *msg,
  * was initialized with positive size, otherwise no percentage is shown */
 void mutt_progress_update(struct Progress *progress, long pos, int percent);
 
-/**
- * struct MuttWindow - A division of the screen
- *
- * Windows for different parts of the screen
- */
-struct MuttWindow
-{
-  int rows;
-  int cols;
-  int row_offset;
-  int col_offset;
-};
-
-extern struct MuttWindow *MuttHelpWindow;
-extern struct MuttWindow *MuttIndexWindow;
-extern struct MuttWindow *MuttStatusWindow;
-extern struct MuttWindow *MuttMessageWindow;
-#ifdef USE_SIDEBAR
-extern struct MuttWindow *MuttSidebarWindow;
-#endif
-
-void mutt_init_windows(void);
-void mutt_free_windows(void);
-void mutt_reflow_windows(void);
-int mutt_window_move(struct MuttWindow *win, int row, int col);
-int mutt_window_mvaddch(struct MuttWindow *win, int row, int col, const chtype ch);
-int mutt_window_mvaddstr(struct MuttWindow *win, int row, int col, const char *str);
-int mutt_window_mvprintw(struct MuttWindow *win, int row, int col, const char *fmt, ...);
-void mutt_window_clrtoeol(struct MuttWindow *win);
-void mutt_window_clearline(struct MuttWindow *win, int row);
-void mutt_window_getyx(struct MuttWindow *win, int *y, int *x);
-
-static inline int mutt_window_wrap_cols(struct MuttWindow *win, short wrap)
-{
-  if (wrap < 0)
-    return win->cols > -wrap ? win->cols + wrap : win->cols;
-  else if (wrap)
-    return wrap < win->cols ? wrap : win->cols;
-  else
-    return win->cols;
-}
-
 extern int *ColorQuote;
 extern int ColorQuoteUsed;
 extern int ColorDefs[];
index f1fa568a34b6560e05a825777fc0ba6cdd521aef..c9c4ff976a3594f0217d8a42b0b32ca5995b7855 100644 (file)
@@ -36,6 +36,7 @@
 #include "mutt/mutt.h"
 #include "globals.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #include "protos.h"
 
 struct timeval LastError = { 0 };
diff --git a/mutt_window.c b/mutt_window.c
new file mode 100644 (file)
index 0000000..4827e7b
--- /dev/null
@@ -0,0 +1,309 @@
+/**
+ * @file
+ * Window management
+ *
+ * @authors
+ * Copyright (C) 2018 Richard Russon <rich@flatcap.org>
+ *
+ * @copyright
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "globals.h"
+#include "mutt/logging.h"
+#include "mutt/mutt.h"
+#include "mutt_menu.h"
+#include "mutt_window.h"
+#include "options.h"
+#include <stdarg.h>
+#include <string.h>
+
+struct MuttWindow *MuttHelpWindow = NULL;
+struct MuttWindow *MuttIndexWindow = NULL;
+struct MuttWindow *MuttStatusWindow = NULL;
+struct MuttWindow *MuttMessageWindow = NULL;
+#ifdef USE_SIDEBAR
+struct MuttWindow *MuttSidebarWindow = NULL;
+#endif
+
+#ifdef USE_SLANG_CURSES
+/**
+ * vw_printw - Write a formatted string to a Window (function missing from Slang)
+ * @param win Window
+ * @param fmt printf format string
+ * @param ap  printf arguments
+ * @retval 0 Always
+ */
+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
+
+/**
+ * mutt_window_clearline - Clear a row of a Window
+ * @param win Window
+ * @param row Row to clear
+ */
+void mutt_window_clearline(struct MuttWindow *win, int row)
+{
+  mutt_window_move(win, row, 0);
+  mutt_window_clrtoeol(win);
+}
+
+/**
+ * mutt_window_clrtoeol - Clear to the end of the line
+ * @param win Window
+ *
+ * @note Assumes the cursor has already been positioned within the window.
+ */
+void mutt_window_clrtoeol(struct MuttWindow *win)
+{
+  if (!win || !stdscr)
+    return;
+
+  if (win->col_offset + win->cols == COLS)
+    clrtoeol();
+  else
+  {
+    int row = 0;
+    int col = 0;
+    getyx(stdscr, row, col);
+    int curcol = col;
+    while (curcol < (win->col_offset + win->cols))
+    {
+      addch(' ');
+      curcol++;
+    }
+    move(row, col);
+  }
+}
+
+/**
+ * mutt_window_free - Free the default Windows
+ */
+void mutt_window_free(void)
+{
+  FREE(&MuttHelpWindow);
+  FREE(&MuttIndexWindow);
+  FREE(&MuttStatusWindow);
+  FREE(&MuttMessageWindow);
+#ifdef USE_SIDEBAR
+  FREE(&MuttSidebarWindow);
+#endif
+}
+
+/**
+ * mutt_window_getxy - Get the cursor position in the Window
+ * @param[in]  win Window
+ * @param[out] x   X-Coordinate
+ * @param[out] y   Y-Coordinate
+ *
+ * Assumes the current position is inside the window.  Otherwise it will
+ * happily return negative or values outside the window boundaries
+ */
+void mutt_window_getxy(struct MuttWindow *win, int *x, int *y)
+{
+  int row = 0;
+  int col = 0;
+
+  getyx(stdscr, row, col);
+  if (x)
+    *x = col - win->col_offset;
+  if (y)
+    *y = row - win->row_offset;
+}
+
+/**
+ * mutt_window_init - Create the default Windows
+ *
+ * Create the Help, Index, Status, Message and Sidebar Windows.
+ */
+void mutt_window_init(void)
+{
+  MuttHelpWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
+  MuttIndexWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
+  MuttStatusWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
+  MuttMessageWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
+#ifdef USE_SIDEBAR
+  MuttSidebarWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
+#endif
+}
+
+/**
+ * mutt_window_move - Move the cursor in a Window
+ * @param win Window
+ * @param row Row to move to
+ * @param col Column to move to
+ * @retval OK  Success
+ * @retval ERR Error
+ */
+int mutt_window_move(struct MuttWindow *win, int row, int col)
+{
+  return move(win->row_offset + row, win->col_offset + col);
+}
+
+/**
+ * mutt_window_mvaddch - Move the cursor and write a character to a Window
+ * @param win Window to write to
+ * @param row Row to move to
+ * @param col Column to move to
+ * @param ch  Character to write
+ * @retval OK  Success
+ * @retval ERR Error
+ */
+int mutt_window_mvaddch(struct MuttWindow *win, int row, int col, const chtype ch)
+{
+  return mvaddch(win->row_offset + row, win->col_offset + col, ch);
+}
+
+/**
+ * mutt_window_mvaddstr - Move the cursor and write a fixed string to a Window
+ * @param win Window to write to
+ * @param row Row to move to
+ * @param col Column to move to
+ * @param str String to write
+ * @retval OK  Success
+ * @retval ERR Error
+ */
+int mutt_window_mvaddstr(struct MuttWindow *win, int row, int col, const char *str)
+{
+  return mvaddstr(win->row_offset + row, win->col_offset + col, str);
+}
+
+/**
+ * mutt_window_mvprintw - Move the cursor and write a formatted string to a Window
+ * @param win Window to write to
+ * @param row Row to move to
+ * @param col Column to move to
+ * @param fmt printf format string
+ * @param ... printf arguments
+ * @retval num Success, number of characters written
+ * @retval ERR Error, move failed
+ */
+int mutt_window_mvprintw(struct MuttWindow *win, int row, int col, const char *fmt, ...)
+{
+  int rc = mutt_window_move(win, row, col);
+  if (rc == ERR)
+    return rc;
+
+  va_list ap;
+  va_start(ap, fmt);
+  rc = vw_printw(stdscr, fmt, ap);
+  va_end(ap);
+
+  return rc;
+}
+
+/**
+ * mutt_window_reflow - Resize the Windows to fit the screen
+ */
+void mutt_window_reflow(void)
+{
+  if (OPT_NO_CURSES)
+    return;
+
+  mutt_debug(2, "entering\n");
+
+  MuttStatusWindow->rows = 1;
+  MuttStatusWindow->cols = COLS;
+  MuttStatusWindow->row_offset = StatusOnTop ? 0 : LINES - 2;
+  MuttStatusWindow->col_offset = 0;
+
+  memcpy(MuttHelpWindow, MuttStatusWindow, sizeof(struct MuttWindow));
+  if (!Help)
+    MuttHelpWindow->rows = 0;
+  else
+    MuttHelpWindow->row_offset = StatusOnTop ? LINES - 2 : 0;
+
+  memcpy(MuttMessageWindow, MuttStatusWindow, sizeof(struct MuttWindow));
+  MuttMessageWindow->row_offset = LINES - 1;
+
+  memcpy(MuttIndexWindow, MuttStatusWindow, sizeof(struct MuttWindow));
+  MuttIndexWindow->rows = MAX(
+      LINES - MuttStatusWindow->rows - MuttHelpWindow->rows - MuttMessageWindow->rows, 0);
+  MuttIndexWindow->row_offset =
+      StatusOnTop ? MuttStatusWindow->rows : MuttHelpWindow->rows;
+
+#ifdef USE_SIDEBAR
+  if (SidebarVisible)
+  {
+    memcpy(MuttSidebarWindow, MuttIndexWindow, sizeof(struct MuttWindow));
+    MuttSidebarWindow->cols = SidebarWidth;
+    MuttIndexWindow->cols -= SidebarWidth;
+
+    if (SidebarOnRight)
+    {
+      MuttSidebarWindow->col_offset = COLS - SidebarWidth;
+    }
+    else
+    {
+      MuttIndexWindow->col_offset += SidebarWidth;
+    }
+  }
+#endif
+
+  mutt_menu_set_current_redraw_full();
+  /* the pager menu needs this flag set to recalc line_info */
+  mutt_menu_set_current_redraw(REDRAW_FLOW);
+}
+
+/**
+ * mutt_window_reflow_message_rows - Resize the Message Window
+ * @param mw_rows Number of rows required
+ *
+ * Resize the other Windows to allow a multi-line message to be displayed.
+ */
+void mutt_window_reflow_message_rows(int mw_rows)
+{
+  MuttMessageWindow->rows = mw_rows;
+  MuttMessageWindow->row_offset = LINES - mw_rows;
+
+  MuttStatusWindow->row_offset = StatusOnTop ? 0 : LINES - mw_rows - 1;
+
+  if (Help)
+    MuttHelpWindow->row_offset = StatusOnTop ? LINES - mw_rows - 1 : 0;
+
+  MuttIndexWindow->rows = MAX(
+      LINES - MuttStatusWindow->rows - MuttHelpWindow->rows - MuttMessageWindow->rows, 0);
+
+#ifdef USE_SIDEBAR
+  if (SidebarVisible)
+    MuttSidebarWindow->rows = MuttIndexWindow->rows;
+#endif
+
+  /* We don't also set REDRAW_FLOW because this function only
+   * changes rows and is a temporary adjustment. */
+  mutt_menu_set_current_redraw_full();
+}
+
+/**
+ * mutt_window_wrap_cols - Calculate the wrap column for a Window
+ *
+ * The wrap variable can be negative, meaning there should be a right margin.
+ */
+int mutt_window_wrap_cols(struct MuttWindow *win, short wrap)
+{
+  if (wrap < 0)
+    return (win->cols > -wrap) ? (win->cols + wrap) : win->cols;
+  else if (wrap)
+    return (wrap < win->cols) ? wrap : win->cols;
+  else
+    return win->cols;
+}
diff --git a/mutt_window.h b/mutt_window.h
new file mode 100644 (file)
index 0000000..51a6f2a
--- /dev/null
@@ -0,0 +1,62 @@
+/**
+ * @file
+ * Window management
+ *
+ * @authors
+ * Copyright (C) 2018 Richard Russon <rich@flatcap.org>
+ *
+ * @copyright
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MUTT_WINDOW_H
+#define _MUTT_WINDOW_H
+
+#include "mutt_curses.h"
+
+/**
+ * struct MuttWindow - A division of the screen
+ *
+ * Windows for different parts of the screen
+ */
+struct MuttWindow
+{
+  int rows;
+  int cols;
+  int row_offset;
+  int col_offset;
+};
+
+extern struct MuttWindow *MuttHelpWindow;
+extern struct MuttWindow *MuttIndexWindow;
+extern struct MuttWindow *MuttMessageWindow;
+#ifdef USE_SIDEBAR
+extern struct MuttWindow *MuttSidebarWindow;
+#endif
+extern struct MuttWindow *MuttStatusWindow;
+
+void mutt_window_clearline(struct MuttWindow *win, int row);
+void mutt_window_clrtoeol(struct MuttWindow *win);
+void mutt_window_free(void);
+void mutt_window_getxy(struct MuttWindow *win, int *x, int *y);
+void mutt_window_init(void);
+int  mutt_window_move(struct MuttWindow *win, int row, int col);
+int  mutt_window_mvaddch(struct MuttWindow *win, int row, int col, const chtype ch);
+int  mutt_window_mvaddstr(struct MuttWindow *win, int row, int col, const char *str);
+int  mutt_window_mvprintw(struct MuttWindow *win, int row, int col, const char *fmt, ...);
+void mutt_window_reflow_message_rows(int mw_rows);
+void mutt_window_reflow(void);
+int  mutt_window_wrap_cols(struct MuttWindow *win, short wrap);
+
+#endif /* _MUTT_WINDOW_H */
index c89ed506f2b643ca3e0bd14c3b309c00d287b058..19ffd780fdedc95a7ea8704d724fb78b3ad4c43e 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -51,6 +51,7 @@
 #include "header.h"
 #include "mailbox.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "ncrypt/ncrypt.h"
 #include "options.h"
index 0c550d06748bc42458c6ce1ad358ad1831cfe504..06cc5a938a5ca8d10fb4aaf0a6ec7a732cc11961 100644 (file)
@@ -54,6 +54,7 @@
 #include "keymap.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "ncrypt.h"
 #include "opcodes.h"
 #include "options.h"
index 6b4ebd02a8a5fde4d39ef665bd638ad5fd8dfa6f..161559fd06c53afaf7b264643d11c7270001e2a6 100644 (file)
@@ -35,6 +35,7 @@
 #include "format_flags.h"
 #include "globals.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #include "ncrypt.h"
 #include "pgp.h"
 #include "pgpkey.h"
index dd05eed15f48f80768553a1326a050e7826ebcbe..2fc30b04dc219b9d735705b6a2603628b6af8722 100644 (file)
@@ -44,6 +44,7 @@
 #include "keymap.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "ncrypt.h"
 #include "opcodes.h"
 #include "options.h"
index 9761a56c0fe459ce14e8686e63a430cb5f887835..6245c4547cfde71f0f1dfefe232d8ab15b4aed5d 100644 (file)
@@ -45,6 +45,7 @@
 #include "keymap.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "ncrypt.h"
 #include "opcodes.h"
 #include "options.h"
index 0afb031761fcd48d525020ca93e3dffd669b0bb1..f6aed906701cb9d723f6e37442e3b2c6c7733e24 100644 (file)
--- a/newsrc.c
+++ b/newsrc.c
@@ -43,6 +43,7 @@
 #include "mutt_account.h"
 #include "mutt_curses.h"
 #include "mutt_socket.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "nntp.h"
 #include "options.h"
diff --git a/pager.c b/pager.c
index e819dec97a5fcf5f0043e298aa26092aa83bc425..2daac8bda0928a721172282da2c0e0cbcab9d389 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -47,6 +47,7 @@
 #include "mailbox.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "ncrypt/ncrypt.h"
 #include "opcodes.h"
@@ -1774,7 +1775,7 @@ static void pager_menu_redraw(struct Menu *pager_menu)
 
   if (pager_menu->redraw & REDRAW_FULL)
   {
-    mutt_reflow_windows();
+    mutt_window_reflow();
     NORMAL_COLOR;
     /* clear() doesn't optimize screen redraws */
     move(0, 0);
@@ -2292,7 +2293,7 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e
       }
       else
       {
-        /* note: mutt_resize_screen() -> mutt_reflow_windows() sets
+        /* note: mutt_resize_screen() -> mutt_window_reflow() sets
          * REDRAW_FULL and REDRAW_FLOW */
         ch = 0;
       }
@@ -3237,7 +3238,7 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e
 
       case OP_SIDEBAR_TOGGLE_VISIBLE:
         SidebarVisible = !SidebarVisible;
-        mutt_reflow_windows();
+        mutt_window_reflow();
         break;
 #endif
 
diff --git a/query.c b/query.c
index faa6f64b5bdbc6247971cc734841b7b8a480692d..189d4c1ec7a64c729da5813d0210c1a5fde6bb5b 100644 (file)
--- a/query.c
+++ b/query.c
@@ -38,6 +38,7 @@
 #include "keymap.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "opcodes.h"
 #include "protos.h"
 
index 3b89e483acbad93d737e8496bdde5fc08edd34f3..514c639cc5edb190e932796e270cd6da040ddec9 100644 (file)
@@ -42,6 +42,7 @@
 #include "mailbox.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "ncrypt/ncrypt.h"
 #include "opcodes.h"
index e7ff676473a05a36d57dcca5ffe36c59f3a7da98..45e42542ba1aa19efc966b68b534f6f8a75697b0 100644 (file)
--- a/recvcmd.c
+++ b/recvcmd.c
@@ -35,6 +35,7 @@
 #include "globals.h"
 #include "header.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #include "options.h"
 #include "protos.h"
 #include "state.h"
index 3ec59e837b67eab7fb169c48c9efd261f86ff2a4..a9afcd83c394d09d882c6aaa0875c45637356337 100644 (file)
@@ -38,6 +38,7 @@
 #include "keymap.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "opcodes.h"
 #include "options.h"
 #include "protos.h"
index 96a963ab76e1a6bece84e0e2e776435effd52545..bf8cea2d0c9d8a40a3f885c107c9f77d6bca7e28 100644 (file)
--- a/resize.c
+++ b/resize.c
@@ -27,6 +27,7 @@
 #include <unistd.h>
 #include "mutt/mutt.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #else
@@ -80,5 +81,5 @@ void mutt_resize_screen(void)
 #else
   resizeterm(SLtt_Screen_Rows, SLtt_Screen_Cols);
 #endif
-  mutt_reflow_windows();
+  mutt_window_reflow();
 }
index ec36d316036cf13c45d9a30b01bae7f88bedec5e..32e6b3fa9d1dbf3e21f2ffc1a312d6888b9b14c7 100644 (file)
--- a/rfc3676.c
+++ b/rfc3676.c
@@ -34,6 +34,7 @@
 #include "globals.h"
 #include "header.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #include "options.h"
 #include "protos.h"
 #include "state.h"
index fbfbbf9b834fbd558f29474dd0fdcc5f870c3783..dd082daf85ddba886fc0b827b57ae19fbf2cbb6a 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -49,6 +49,7 @@
 #include "header.h"
 #include "mailbox.h"
 #include "mutt_curses.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "ncrypt/ncrypt.h"
 #include "options.h"
index 5ef642a55d120ce7169d9b2474f23a89fdf0537c..3567cac0254c9eb82fcb17212e36fb4383eb2de6 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -37,6 +37,7 @@
 #include "globals.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "opcodes.h"
 #include "options.h"
index 2ac69fb44afad92f6ad8e11afe6773c131793167..339c1f6bf655567f28f9f6eba31bcd7ed6530447 100644 (file)
--- a/status.c
+++ b/status.c
@@ -30,6 +30,7 @@
 #include "mbtable.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
+#include "mutt_window.h"
 #include "mx.h"
 #include "options.h"
 #include "protos.h"