From ca1516364e91006f0a0e6f3be8f20a8431cbf8c0 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Sat, 3 Jan 2009 10:15:41 +0000
Subject: [PATCH] tent fix for weird multiwin behavour on win32

---
 Fltk/GUI.cpp           |  4 ++--
 Fltk/Makefile          | 37 +++++++++++++++---------------
 Fltk/dialogWindow.h    |  1 -
 Fltk/graphicWindow.cpp | 52 +++++++++---------------------------------
 Fltk/graphicWindow.h   |  2 +-
 Fltk/mainWindow.h      | 49 +++++++++++++++++++++++++++++++++++++++
 Fltk/menuWindow.cpp    | 40 ++------------------------------
 Fltk/openglWindow.cpp  |  6 ++++-
 8 files changed, 89 insertions(+), 102 deletions(-)
 create mode 100644 Fltk/mainWindow.h

diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp
index 93af50f8e8..4accfe3250 100644
--- a/Fltk/GUI.cpp
+++ b/Fltk/GUI.cpp
@@ -80,7 +80,7 @@ GUI::GUI(int argc, char **argv)
   // since the shortcuts should be valid even for hidden windows, and
   // we don't want to test for widget existence every time
   menu = new menuWindow();
-  graph.push_back(new graphicWindow(CTX.num_tiles));
+  graph.push_back(new graphicWindow(true, CTX.num_tiles));
 
 #if defined(WIN32)
   graph[0]->win->icon
@@ -121,7 +121,7 @@ GUI::GUI(int argc, char **argv)
 
   // create additional graphic windows
   for(int i = 1; i < CTX.num_windows; i++){
-    graph.push_back(new graphicWindow(CTX.num_tiles));
+    graph.push_back(new graphicWindow(false, CTX.num_tiles));
     graph.back()->win->size(400, 400);
     graph.back()->win->show();
   }
diff --git a/Fltk/Makefile b/Fltk/Makefile
index f403a30785..8d5a2ca6c5 100644
--- a/Fltk/Makefile
+++ b/Fltk/Makefile
@@ -108,11 +108,11 @@ GUI${OBJEXT}: GUI.cpp GUI.h graphicWindow.h openglWindow.h \
   ../Mesh/PartitionOptions.h
 graphicWindow${OBJEXT}: graphicWindow.cpp GUI.h graphicWindow.h openglWindow.h \
   ../Graphics/drawContext.h ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h \
-  menuWindow.h popupButton.h messageWindow.h manipWindow.h extraDialogs.h \
-  Draw.h ../Post/PView.h ../Post/PViewData.h ../Numeric/GmshMatrix.h \
-  ../Common/GmshMessage.h ../Common/OS.h ../Common/Options.h \
-  ../Post/ColorTable.h ../Common/Context.h ../Geo/CGNSOptions.h \
-  ../Mesh/PartitionOptions.h
+  dialogWindow.h mainWindow.h menuWindow.h popupButton.h messageWindow.h \
+  manipWindow.h extraDialogs.h Draw.h ../Post/PView.h ../Post/PViewData.h \
+  ../Numeric/GmshMatrix.h ../Common/GmshMessage.h ../Common/OS.h \
+  ../Common/Options.h ../Post/ColorTable.h ../Common/Context.h \
+  ../Geo/CGNSOptions.h ../Mesh/PartitionOptions.h
 openglWindow${OBJEXT}: openglWindow.cpp openglWindow.h ../Graphics/drawContext.h \
   ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h graphicWindow.h manipWindow.h \
   contextWindow.h ../Common/GmshDefines.h ../Common/GmshMessage.h \
@@ -131,24 +131,25 @@ openglWindow${OBJEXT}: openglWindow.cpp openglWindow.h ../Graphics/drawContext.h
   ../Numeric/GmshMatrix.h GUI.h ../Common/VertexArray.h \
   ../Common/Context.h ../Geo/CGNSOptions.h ../Mesh/PartitionOptions.h
 menuWindow${OBJEXT}: menuWindow.cpp GUI.h Draw.h menuWindow.h popupButton.h \
-  dialogWindow.h graphicWindow.h openglWindow.h ../Graphics/drawContext.h \
+  mainWindow.h graphicWindow.h openglWindow.h ../Graphics/drawContext.h \
   ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h optionWindow.h \
   spherePositionWidget.h colorbarWindow.h ../Post/ColorTable.h \
   statisticsWindow.h messageWindow.h contextWindow.h visibilityWindow.h \
   clippingWindow.h manipWindow.h fieldWindow.h pluginWindow.h \
   solverWindow.h aboutWindow.h fileDialogs.h partitionDialog.h \
-  projectionEditor.h ../Geo/fourierProjectionFace.h ../Geo/GModel.h \
-  ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
-  ../Geo/SBoundingBox3d.h ../Geo/GPoint.h ../Geo/SPoint2.h ../Geo/GEdge.h \
-  ../Geo/GEntity.h ../Geo/GVertex.h ../Geo/SVector3.h ../Geo/SPoint3.h \
-  ../Geo/SPoint3.h ../Geo/SPoint2.h ../Geo/GFace.h ../Geo/GEntity.h \
-  ../Geo/GPoint.h ../Geo/GEdgeLoop.h ../Geo/GEdge.h ../Geo/SPoint2.h \
-  ../Geo/SVector3.h ../Geo/Pair.h ../Geo/GRegion.h ../Geo/GEntity.h \
-  ../Geo/SPoint3.h ../Geo/SBoundingBox3d.h ../Geo/Range.h \
-  classificationEditor.h ../Geo/MElement.h ../Common/GmshDefines.h \
-  ../Geo/MVertex.h ../Geo/SPoint2.h ../Geo/SPoint3.h ../Geo/MEdge.h \
-  ../Geo/MVertex.h ../Geo/SVector3.h ../Geo/MFace.h ../Geo/MVertex.h \
-  ../Geo/SVector3.h ../Common/GmshMessage.h ../Numeric/FunctionSpace.h \
+  projectionEditor.h dialogWindow.h ../Geo/fourierProjectionFace.h \
+  ../Geo/GModel.h ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h \
+  ../Geo/SPoint3.h ../Geo/SBoundingBox3d.h ../Geo/GPoint.h \
+  ../Geo/SPoint2.h ../Geo/GEdge.h ../Geo/GEntity.h ../Geo/GVertex.h \
+  ../Geo/SVector3.h ../Geo/SPoint3.h ../Geo/SPoint3.h ../Geo/SPoint2.h \
+  ../Geo/GFace.h ../Geo/GEntity.h ../Geo/GPoint.h ../Geo/GEdgeLoop.h \
+  ../Geo/GEdge.h ../Geo/SPoint2.h ../Geo/SVector3.h ../Geo/Pair.h \
+  ../Geo/GRegion.h ../Geo/GEntity.h ../Geo/SPoint3.h \
+  ../Geo/SBoundingBox3d.h ../Geo/Range.h classificationEditor.h \
+  ../Geo/MElement.h ../Common/GmshDefines.h ../Geo/MVertex.h \
+  ../Geo/SPoint2.h ../Geo/SPoint3.h ../Geo/MEdge.h ../Geo/MVertex.h \
+  ../Geo/SVector3.h ../Geo/MFace.h ../Geo/MVertex.h ../Geo/SVector3.h \
+  ../Common/GmshMessage.h ../Numeric/FunctionSpace.h \
   ../Numeric/GmshMatrix.h ../Numeric/Gauss.h ../Common/Options.h \
   Solvers.h ../Common/CommandLine.h ../Mesh/Generator.h \
   ../Mesh/HighOrder.h ../Post/PView.h ../Post/PViewData.h \
diff --git a/Fltk/dialogWindow.h b/Fltk/dialogWindow.h
index c0dbea7ee1..4c5f57edc0 100644
--- a/Fltk/dialogWindow.h
+++ b/Fltk/dialogWindow.h
@@ -8,7 +8,6 @@
 
 #include <FL/Fl.H>
 #include <FL/Fl_Double_Window.H>
-#include <FL/fl_ask.H>
 
 // Derive special windows from Fl_Double_Window to correctly process
 // the OS-specific shorcuts (Esc & Cmd-w on Mac, Alt+F4 on Windows)
diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp
index 9d4e8ad180..60b1e3a651 100644
--- a/Fltk/graphicWindow.cpp
+++ b/Fltk/graphicWindow.cpp
@@ -8,6 +8,8 @@
 #include <FL/fl_ask.H>
 #include "GUI.h"
 #include "graphicWindow.h"
+#include "dialogWindow.h"
+#include "mainWindow.h"
 #include "menuWindow.h"
 #include "messageWindow.h"
 #include "manipWindow.h"
@@ -277,11 +279,6 @@ static void status_stepforward_cb(Fl_Widget *w, void *data)
 
 static void remove_graphic_window_cb(Fl_Widget *w, void *data)
 {
-  if(GUI::instance()->graph.size() == 1){
-    file_quit_cb(0, 0);
-    return;
-  }
-
   std::vector<graphicWindow*> graph2;
   graphicWindow *deleteMe = 0;
   for(unsigned int i = 0; i < GUI::instance()->graph.size(); i++){
@@ -297,39 +294,6 @@ static void remove_graphic_window_cb(Fl_Widget *w, void *data)
   }
 }
 
-// We derive the window from Fl_Window instead of Fl_Double_Window: it
-// shows up faster this way (and the opengl subwindow is
-// double-buffered on its own anyway)
-class normalWindow : public Fl_Window {
- private:
-  int handle(int event)
-  {
-    switch (event) {
-    case FL_SHORTCUT:
-    case FL_KEYBOARD:
-#if defined(__APPLE__)
-      if(Fl::test_shortcut(FL_META+'w')){
-#elif defined(WIN32)
-      if(Fl::test_shortcut(FL_ALT+FL_F+4)){
-#else
-      if(Fl::test_shortcut(FL_CTRL+'w')){
-#endif
-        if(GUI::instance()->graph.size() == 1){
-          if(fl_choice("Do you really want to quit?", "Cancel", "Quit", 0))
-            do_callback();
-        }
-        else
-          do_callback();
-        return 1;
-      }
-      break;
-    }
-    return Fl_Window::handle(event);
-  }
- public:
-  normalWindow(int w, int h, const char *l=0) : Fl_Window(w, h, l) {}
-};
-
 // This dummy box class permits to define a box widget that will not
 // eat the FL_ENTER/FL_LEAVE events (the new Box widget in fltk > 1.1
 // does that, so that gl->handle() was not called when the mouse
@@ -341,7 +305,7 @@ class dummyBox : public Fl_Box {
   dummyBox(int x, int y, int w, int h, const char *l=0) : Fl_Box(x, y, w, h, l) {}
 };
 
-graphicWindow::graphicWindow(int numTiles)
+graphicWindow::graphicWindow(bool main, int numTiles)
 {
   static bool first = true;
   if(first){
@@ -364,8 +328,14 @@ graphicWindow::graphicWindow(int numTiles)
   
   // the graphic window should be a "normal" window (neither modal nor
   // non-modal)
-  win = new normalWindow(width, height);
-  win->callback(remove_graphic_window_cb);
+  if(main){
+    win = new mainWindow(width, height, false);
+    win->callback(file_quit_cb);
+  }
+  else{
+    win = new dialogWindow(width, height, false);
+    win->callback(remove_graphic_window_cb);
+  }
 
   // bottom button bar
   bottom = new Fl_Box(0, glheight, width, sh);
diff --git a/Fltk/graphicWindow.h b/Fltk/graphicWindow.h
index 0e1d0fea44..4ceace8f11 100644
--- a/Fltk/graphicWindow.h
+++ b/Fltk/graphicWindow.h
@@ -22,7 +22,7 @@ class graphicWindow{
   Fl_Button *butt[12];
   Fl_Box *label[2];
  public:
-  graphicWindow(int numTiles=1);
+  graphicWindow(bool main=true, int numTiles=1);
   ~graphicWindow();
   void split(openglWindow *g, char how);
   void setAnimButtons(int mode);
diff --git a/Fltk/mainWindow.h b/Fltk/mainWindow.h
new file mode 100644
index 0000000000..195a70e6b6
--- /dev/null
+++ b/Fltk/mainWindow.h
@@ -0,0 +1,49 @@
+// Gmsh - Copyright (C) 1997-2009 C. Geuzaine, J.-F. Remacle
+//
+// See the LICENSE.txt file for license information. Please report all
+// bugs and problems to <gmsh@geuz.org>.
+
+#ifndef _MAIN_WINDOW_H
+#define _MAIN_WINDOW_H
+
+#include <FL/Fl.H>
+#include <FL/Fl_Double_Window.H>
+#include <FL/fl_ask.H>
+
+// Derive the main window from Fl_Window (it shows up faster that way)
+class mainWindow : public Fl_Window {
+ private:
+  int handle(int event)
+  {
+    switch (event) {
+    case FL_SHORTCUT:
+    case FL_KEYBOARD:
+#if defined(__APPLE__)
+      if(Fl::test_shortcut(FL_META+'w')){
+#elif defined(WIN32)
+      if(Fl::test_shortcut(FL_ALT+FL_F+4)){
+#else
+      if(Fl::test_shortcut(FL_CTRL+'w')){
+#endif
+        if(fl_choice("Do you really want to quit?", "Cancel", "Quit", 0))
+          do_callback();
+        return 1;
+      }
+      break;
+    }
+    return Fl_Window::handle(event);
+  }
+ public:
+  mainWindow(int w, int h, bool nonmodal=false, const char *l=0) 
+    : Fl_Window(w, h, l) 
+  {
+    if(nonmodal) set_non_modal();
+  }
+  void show()
+  {
+    if(non_modal() && !shown()) Fl_Window::show(); // fix ordering
+    Fl_Window::show();
+  }
+};
+
+#endif
diff --git a/Fltk/menuWindow.cpp b/Fltk/menuWindow.cpp
index 6215b13ad6..61363e69c5 100644
--- a/Fltk/menuWindow.cpp
+++ b/Fltk/menuWindow.cpp
@@ -11,7 +11,7 @@
 #include "GUI.h"
 #include "Draw.h"
 #include "menuWindow.h"
-#include "dialogWindow.h"
+#include "mainWindow.h"
 #include "graphicWindow.h"
 #include "optionWindow.h"
 #include "statisticsWindow.h"
@@ -153,7 +153,7 @@ static void file_window_cb(Fl_Widget *w, void *data)
   std::string str((const char*)data);
   if(str == "new"){
     graphicWindow *g1 = GUI::instance()->graph.back();
-    graphicWindow *g2 = new graphicWindow(CTX.num_tiles);
+    graphicWindow *g2 = new graphicWindow(false, CTX.num_tiles);
     GUI::instance()->graph.push_back(g2);
     g2->win->label(g1->win->label());
     g2->win->resize(g1->win->x() + 10, g1->win->y() + 10,
@@ -2441,42 +2441,6 @@ contextItem menu_post[] = {
   {0} 
 };
 
-// Derive the main window from Fl_Window (it shows up faster that way)
-class mainWindow : public Fl_Window {
- private:
-  int handle(int event)
-  {
-    switch (event) {
-    case FL_SHORTCUT:
-    case FL_KEYBOARD:
-#if defined(__APPLE__)
-      if(Fl::test_shortcut(FL_META+'w')){
-#elif defined(WIN32)
-      if(Fl::test_shortcut(FL_ALT+FL_F+4)){
-#else
-      if(Fl::test_shortcut(FL_CTRL+'w')){
-#endif
-        if(fl_choice("Do you really want to quit?", "Cancel", "Quit", 0))
-          do_callback();
-        return 1;
-      }
-      break;
-    }
-    return Fl_Window::handle(event);
-  }
- public:
-  mainWindow(int w, int h, bool nonmodal=false, const char *l=0) 
-    : Fl_Window(w, h, l) 
-  {
-    if(nonmodal) set_non_modal();
-  }
-  void show()
-  {
-    if(non_modal() && !shown()) Fl_Window::show(); // fix ordering
-    Fl_Window::show();
-  }
-};
-
 menuWindow::menuWindow()
 {
   int width = 14 * FL_NORMAL_SIZE;
diff --git a/Fltk/openglWindow.cpp b/Fltk/openglWindow.cpp
index accae25c8a..f0071d57eb 100644
--- a/Fltk/openglWindow.cpp
+++ b/Fltk/openglWindow.cpp
@@ -125,8 +125,12 @@ void openglWindow::drawBorder()
       Fl::get_color(FL_BACKGROUND_COLOR, r, g, b);
     */
     glColor3ub(r, g, b);
+    glLineWidth(1);
+#if defined(__APPLE__)
     int ww = 1;
-    glLineWidth(ww);
+#else
+    int ww = 0;
+#endif
     glBegin(GL_LINE_LOOP);
     glVertex2d(_ctx->viewport[0], _ctx->viewport[1]);
     glVertex2d(_ctx->viewport[2] - ww, _ctx->viewport[1]);
-- 
GitLab