Make the sidebar live in a proper independent window.
[apps/madmutt.git] / lib-ui / menu.c
index 1ce9f47..0a1d716 100644 (file)
@@ -7,9 +7,8 @@
  * please see the file GPL in the top level source directory.
  */
 
-#include <lib-lib/lib-lib.h>
+#include <lib-ui/lib-ui.h>
 
-#include "curses.h"
 #include "enter.h"
 #include "menu.h"
 
@@ -38,87 +37,52 @@ static void print_enriched_string (int attr, unsigned char *s, int do_color)
       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 (stdscr, 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 (stdscr, 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 (stdscr, 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 (stdscr, 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 (stdscr, 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 (stdscr, 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 (stdscr, ACS_BTEE);
           break;
         case M_TREE_SPACE:
-          addch (' ');
+          waddch (stdscr, ' ');
           break;
         case M_TREE_RARROW:
-          addch ('>');
+          waddch (stdscr, '>');
           break;
         case M_TREE_STAR:
-          addch ('*');          /* fake thread indicator */
+          waddch (stdscr, '*');          /* fake thread indicator */
           break;
         case M_TREE_HIDDEN:
-          addch ('&');
+          waddch (stdscr, '&');
           break;
         case M_TREE_EQUALS:
-          addch ('=');
+          waddch (stdscr, '=');
           break;
         case M_TREE_MISSING:
-          addch ('?');
+          waddch (stdscr, '?');
           break;
         }
         s++, n--;
       }
       if (do_color)
-        attrset (attr);
+        wattrset (stdscr, attr);
     }
     else if ((k = mbrtowc (&wc, (char *) s, n, &mbstate)) != (size_t)-1) {
-      addnstr ((char *) s, k);
+      waddnstr (stdscr, (char *) s, k);
       s += k, n -= k;
     }
     else
@@ -150,25 +114,16 @@ 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, "");
-    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();
+  /* wclear(stdscr) doesn't optimize screen redraws */
+  wmove (stdscr, 0, 0);
+  wclrtobot (stdscr);
 
+  SETCOLOR (MT_COLOR_STATUS);
+  wmove (stdscr, option (OPTSTATUSONTOP) ? LINES - 2 : 0, SW);
+  mutt_paddstr (COLS-SW, "");
+  SETCOLOR (MT_COLOR_NORMAL);
+  menu->offset = 1;
+  menu->pagelen = LINES - 3;
   mutt_show_error ();
 
   menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
@@ -180,11 +135,10 @@ void menu_redraw_status (MUTTMENU * menu)
 
   snprintf (buf, sizeof (buf), M_MODEFMT, menu->title);
   SETCOLOR (MT_COLOR_STATUS);
-  move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
+  wmove (stdscr, option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
   mutt_paddstr (COLS-SW, buf);
   SETCOLOR (MT_COLOR_NORMAL);
   menu->redraw &= ~REDRAW_STATUS;
-  sidebar_draw_frames();
 }
 
 void menu_redraw_index (MUTTMENU * menu)
@@ -197,7 +151,7 @@ void menu_redraw_index (MUTTMENU * menu)
       menu_make_entry (buf, sizeof (buf), menu, i);
       menu_pad_string (buf, sizeof (buf));
 
-      attrset (menu->color (i));
+      wattrset (stdscr, menu->color (i));
 
       if (i == menu->current) {
         ADDCOLOR (MT_COLOR_INDICATOR);
@@ -206,7 +160,7 @@ void menu_redraw_index (MUTTMENU * menu)
 
       CLEARLINE_WIN (i - menu->top + menu->offset);
 
-      move (i - menu->top + menu->offset, SW);
+      wmove (stdscr, i - menu->top + menu->offset, SW);
       print_enriched_string (menu->color (i), (unsigned char *) buf,
                              i != menu->current);
       SETCOLOR (MT_COLOR_NORMAL);
@@ -229,13 +183,13 @@ void menu_redraw_motion (MUTTMENU * menu)
     return;
   }
 
-  move (menu->oldcurrent + menu->offset - menu->top, SW);
+  wmove (stdscr, menu->oldcurrent + menu->offset - menu->top, SW);
   SETCOLOR (MT_COLOR_NORMAL);
   BKGDSET (MT_COLOR_NORMAL);
 
   /* erase the current indicator */
-  attrset (menu->color (menu->oldcurrent));
-  clrtoeol ();
+  wattrset (stdscr, menu->color (menu->oldcurrent));
+  wclrtoeol (stdscr);
   menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
   menu_pad_string (buf, sizeof (buf));
   print_enriched_string (menu->color (menu->oldcurrent),
@@ -244,11 +198,11 @@ void menu_redraw_motion (MUTTMENU * menu)
   /* 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));
+  wattrset (stdscr, 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);
+  wmove (stdscr, menu->current + menu->offset - menu->top, SW);
   print_enriched_string (menu->color (menu->current), (unsigned char *) buf,
                          0);
   SETCOLOR (MT_COLOR_NORMAL);
@@ -261,14 +215,14 @@ void menu_redraw_current (MUTTMENU * menu)
 {
   char buf[STRING];
 
-  move (menu->current + menu->offset - menu->top, SW);
+  wmove (stdscr, menu->current + menu->offset - menu->top, SW);
   menu_make_entry (buf, sizeof (buf), menu, menu->current);
   menu_pad_string (buf, sizeof (buf));
 
-  attrset (menu->color (menu->current));
+  wattrset (stdscr, menu->color (menu->current));
   ADDCOLOR (MT_COLOR_INDICATOR);
   BKGDSET (MT_COLOR_INDICATOR);
-  clrtoeol ();
+  wclrtoeol (stdscr);
   print_enriched_string (menu->color (menu->current), (unsigned char *) buf,
                          0);
   SETCOLOR (MT_COLOR_NORMAL);
@@ -289,8 +243,8 @@ static void menu_redraw_prompt (MUTTMENU * menu)
       mutt_clear_error ();
 
     SETCOLOR (MT_COLOR_NORMAL);
-    mvaddstr (LINES - 1, 0, menu->prompt);
-    clrtoeol ();
+    mvwaddstr (stdscr, LINES - 1, 0, menu->prompt);
+    wclrtoeol (stdscr);
   }
 }
 
@@ -736,9 +690,9 @@ int mutt_menuLoop (MUTTMENU * menu)
     menu->oldcurrent = menu->current;
 
     if (option (OPTBRAILLEFRIENDLY))
-      move (menu->current - menu->top + menu->offset, SW);
+      wmove (stdscr, menu->current - menu->top + menu->offset, SW);
     else
-      move (menu->current - menu->top + menu->offset, COLS - 1);
+      wmove (stdscr, menu->current - menu->top + menu->offset, COLS - 1);
 
     mutt_refresh ();
 
@@ -750,8 +704,8 @@ 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 (stdscr, LINES - 1, 0, "Tag-");
+        wclrtoeol (stdscr);
         i = km_dokey (menu->menu);
         menu->tagprefix = 1;
         CLEARLINE (LINES - 1);
@@ -783,10 +737,8 @@ int mutt_menuLoop (MUTTMENU * menu)
     mutt_curs_set (1);
 
     if (SigWinch) {
-      mutt_resize_screen ();
+      ui_layout_resize();
       menu->redraw = REDRAW_FULL;
-      SigWinch = 0;
-      clearok (stdscr, TRUE);   /*force complete redraw */
     }
 
     if (i == -1)