From e326aba1fe402bb7a58895f0cb21ea9fa7f0a327 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Wed, 7 Nov 2012 21:39:48 +0000
Subject: [PATCH] remember menu size

---
 Common/Context.h        |  2 +-
 Common/DefaultOptions.h |  4 ++-
 Common/Options.cpp      |  9 ++++++
 Common/Options.h        |  1 +
 Fltk/FlGui.cpp          |  5 ++++
 Fltk/graphicWindow.cpp  | 61 ++++++++++++++++++++++++++++++++++++++---
 Fltk/graphicWindow.h    |  7 ++++-
 7 files changed, 82 insertions(+), 7 deletions(-)

diff --git a/Common/Context.h b/Common/Context.h
index f0bc9a6a99..e936995a98 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -103,7 +103,7 @@ class CTX {
   // show tootips in the GUI?
   int tooltips;
   // position and size of various windows in the GUI
-  int glPosition[2], glSize[2], msgSize;
+  int glPosition[2], glSize[2], msgSize, menuSize;
   int optPosition[2], visPosition[2], hotPosition[2], clipPosition[2], manipPosition[2];
   int statPosition[2], ctxPosition[2];
   int pluginPosition[2], pluginSize[2], fieldPosition[2], fieldSize[2];
diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index 7a1447cd92..71749234ea 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -417,7 +417,7 @@ StringXNumber GeneralOptions_Number[] = {
   { F|S, "GraphicsPositionY" , opt_general_graphics_position1 , 50. ,
     "Vertical position (in pixels) of the upper left corner of the graphic "
     "window" },
-  { F|S, "GraphicsWidth" , opt_general_graphics_size0 , 600. ,
+  { F|S, "GraphicsWidth" , opt_general_graphics_size0 , 800. ,
     "Width (in pixels) of the graphic window" },
 
   { F|O, "InitialModule", opt_general_initial_context, 0. ,
@@ -505,6 +505,8 @@ StringXNumber GeneralOptions_Number[] = {
     "Maximum model coordinate along the Y-axis (read-only)" },
   { F,   "MaxZ" , opt_general_zmax , 0. ,
     "Maximum model coordinate along the Z-axis (read-only)" },
+  { F|S, "MenuWidth" , opt_general_menu_size , 300. ,
+    "Width (in pixels) of the menu tree" },
   { F|S, "MessageHeight" , opt_general_message_size , 300. ,
     "Height (in pixels) of the message console" },
   { F,   "MinX" , opt_general_xmin , 0. ,
diff --git a/Common/Options.cpp b/Common/Options.cpp
index a47fb543aa..b0e39e3390 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1847,6 +1847,15 @@ double opt_general_message_size(OPT_ARGS_NUM)
   return CTX::instance()->msgSize;
 }
 
+double opt_general_menu_size(OPT_ARGS_NUM)
+{
+  if(action & GMSH_SET){
+    CTX::instance()->menuSize = (int)val;
+    if(CTX::instance()->menuSize < 0) CTX::instance()->menuSize = 0;
+  }
+  return CTX::instance()->menuSize;
+}
+
 double opt_general_option_position0(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET)
diff --git a/Common/Options.h b/Common/Options.h
index af3918cdd2..620e7cd2d8 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -112,6 +112,7 @@ double opt_general_polygon_offset_factor(OPT_ARGS_NUM);
 double opt_general_polygon_offset_units(OPT_ARGS_NUM);
 double opt_general_system_menu_bar(OPT_ARGS_NUM);
 double opt_general_message_size(OPT_ARGS_NUM);
+double opt_general_menu_size(OPT_ARGS_NUM);
 double opt_general_option_position0(OPT_ARGS_NUM);
 double opt_general_option_position1(OPT_ARGS_NUM);
 double opt_general_plugin_position0(OPT_ARGS_NUM);
diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp
index 9bf64ee85f..9495bf26b1 100644
--- a/Fltk/FlGui.cpp
+++ b/Fltk/FlGui.cpp
@@ -372,6 +372,10 @@ int FlGui::testGlobalShortcuts(int event)
     file_quit_cb(0, 0);
     status = 1;
   }
+  else if(Fl::test_shortcut(FL_CTRL + 't') || Fl::test_shortcut(FL_META + 't')){
+    menu_cb(0, 0);
+    status = 1;
+  }
   else if(Fl::test_shortcut('g')) {
     FlGui::instance()->openModule("Geometry");
     status = 1;
@@ -794,6 +798,7 @@ void FlGui::storeCurrentWindowsInfo()
   CTX::instance()->glSize[0] = graph[0]->win->w();
   CTX::instance()->glSize[1] = (graph[0]->win->h() - graph[0]->bottom->h());
   CTX::instance()->msgSize = graph[0]->getMessageHeight();
+  CTX::instance()->menuSize = graph[0]->getMenuWidth();
   CTX::instance()->optPosition[0] = options->win->x();
   CTX::instance()->optPosition[1] = options->win->y();
   CTX::instance()->pluginPosition[0] = plugins->win->x();
diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp
index efd29ab120..2a3f8efd7f 100644
--- a/Fltk/graphicWindow.cpp
+++ b/Fltk/graphicWindow.cpp
@@ -2603,6 +2603,18 @@ void message_cb(Fl_Widget *w, void *data)
   FlGui::check();
 }
 
+void menu_cb(Fl_Widget *w, void *data)
+{
+  graphicWindow *g = getGraphicWindow
+    (FlGui::instance()->getCurrentOpenglWindow()->parent());
+  if(!g->onelab) return;
+  if(g->onelab->w())
+    g->hideMenu();
+  else
+    g->showMenu();
+  FlGui::check();
+}
+
 static void message_menu_scroll_cb(Fl_Widget *w, void *data)
 {
   graphicWindow *g = (graphicWindow*)data;
@@ -2677,7 +2689,7 @@ graphicWindow::graphicWindow(bool main, int numTiles) : _autoScrollMessages(true
   int sh = 2 * FL_NORMAL_SIZE - 4; // status bar height
   int sw = FL_NORMAL_SIZE + 3; // status button width
 
-  int mheight = main ? 10 : 0; // dummy (nonzero)
+  int mheight = main ? 10 /* dummy, nonzero! */ : 0;
   int glheight = CTX::instance()->glSize[1] - mheight;
   int height = mh + glheight + mheight + sh;
   // make sure height < screen height
@@ -2687,7 +2699,7 @@ graphicWindow::graphicWindow(bool main, int numTiles) : _autoScrollMessages(true
     CTX::instance()->glSize[1] = glheight;
   }
 
-  int twidth = main ? (13 * sw + 2 * FL_NORMAL_SIZE + 2) : 0;
+  int twidth = main ? 14 * sw : 0;
   int glwidth = CTX::instance()->glSize[0] - twidth;
   int width = glwidth + twidth;
   // make sure width < screen width
@@ -2822,7 +2834,7 @@ graphicWindow::graphicWindow(bool main, int numTiles) : _autoScrollMessages(true
   minHeight = 100;
   win->size_range(minWidth, minHeight);
 
-  // tiled windows (menu tree, opengl, messages)
+  // tiled windows (tree menu, opengl, messages)
   tile = new Fl_Tile(0, mh, glwidth + twidth, glheight + mheight);
 
   int w2 = glwidth / 2, h2 = glheight / 2;
@@ -2890,10 +2902,15 @@ graphicWindow::graphicWindow(bool main, int numTiles) : _autoScrollMessages(true
 
   tile->end();
 
-  // resize the tile to match the prescribed sizes
+  // resize the tiles to match the prescribed sizes
   tile->position(0, mh + glheight, 0, mh + CTX::instance()->glSize[1]);
   _savedMessageHeight = CTX::instance()->msgSize;
 
+  // should we allow a zero-sized menu?
+  if(CTX::instance()->menuSize < 10) CTX::instance()->menuSize = 10;
+  tile->position(twidth, 0, CTX::instance()->menuSize, 0);
+  _savedMenuWidth = CTX::instance()->menuSize;
+
   win->position(CTX::instance()->glPosition[0], CTX::instance()->glPosition[1]);
   win->end();
 }
@@ -3002,6 +3019,42 @@ void graphicWindow::checkAnimButtons()
   }
 }
 
+void graphicWindow::resizeMenu(int dh)
+{
+  if(!onelab) return;
+  for(unsigned int i = 0; i < gl.size(); i++){
+    if(gl[i]->x() == onelab->x() + onelab->w())
+      gl[i]->resize(gl[i]->x() + dh, gl[i]->y(), gl[i]->w() - dh, gl[i]->h());
+  }
+  onelab->resize(onelab->x(), onelab->y(), onelab->w() + dh, onelab->h());
+  onelab->redraw();
+}
+
+void graphicWindow::showMenu()
+{
+  if(!onelab || !win->shown()) return;
+  if(onelab->w() < 5){
+    int width = _savedMenuWidth;
+    if(width < 5) width = 200;
+    int maxw = win->w();
+    if(width > maxw) width = maxw / 2;
+    resizeMenu(width - onelab->w());
+  }
+}
+
+void graphicWindow::hideMenu()
+{
+  if(!onelab) return;
+  _savedMenuWidth = onelab->w();
+  resizeMenu(-onelab->w());
+}
+
+int graphicWindow::getMenuWidth()
+{
+  if(!onelab) return 0;
+  return onelab->w();
+}
+
 void graphicWindow::resizeMessages(int dh)
 {
   if(!browser) return;
diff --git a/Fltk/graphicWindow.h b/Fltk/graphicWindow.h
index df08af9b15..f3d807ccda 100644
--- a/Fltk/graphicWindow.h
+++ b/Fltk/graphicWindow.h
@@ -24,7 +24,7 @@
 class graphicWindow{
  private:
   std::string _title;
-  int _savedMessageHeight;
+  int _savedMessageHeight, _savedMenuWidth;
   bool _autoScrollMessages;
  public:
   Fl_Window *win;
@@ -58,6 +58,10 @@ class graphicWindow{
   void saveMessages(const char *filename);
   void copySelectedMessagesToClipboard();
   void fillRecentHistoryMenu();
+  void resizeMenu(int dh);
+  void showMenu();
+  void hideMenu();
+  int getMenuWidth();
 };
 
 void file_quit_cb(Fl_Widget *w, void *data);
@@ -77,5 +81,6 @@ void status_xyz1p_cb(Fl_Widget *w, void *data);
 void status_options_cb(Fl_Widget *w, void *data);
 void status_play_manual(int time, int incr, bool redraw=true);
 void message_cb(Fl_Widget *w, void *data);
+void menu_cb(Fl_Widget *w, void *data);
 
 #endif
-- 
GitLab