ecere/gui: Fixes to make MDI work with Stacker containing Toolbar & Workspace in IDE
authorJerome St-Louis <jerome@ecere.com>
Sun, 26 Feb 2012 14:35:27 +0000 (09:35 -0500)
committerJerome St-Louis <jerome@ecere.com>
Thu, 1 Mar 2012 04:53:37 +0000 (23:53 -0500)
ecere/src/gui/Window.ec
ecere/src/gui/controls/Menu.ec
ecere/src/gui/skins/WindowsSkin.ec
ide/src/designer/CodeEditor.ec
ide/src/designer/Designer.ec
ide/src/designer/Sheet.ec
ide/src/ide.ec

index 50a9f32..c376cfc 100644 (file)
@@ -814,6 +814,8 @@ private:
 
    void FigureCaption(char * caption)
    {
+      Window activeClient = null;
+
       caption[0] = '\0';
       if(this.caption)
          strcpy(caption, this.caption);
@@ -831,8 +833,12 @@ private:
          if(modifiedDocument)
             strcat(caption, " *");
       }
-      if(activeClient && menuBar && 
-         activeClient.state == maximized)
+
+      if(menuBar)
+      {
+         for(activeClient = this.activeClient; activeClient && !((BorderBits)activeClient.borderStyle).fixed; activeClient = activeClient.activeClient);
+      }
+      if(activeClient && activeClient.state == maximized)
       {
          if(activeClient.caption)
          {
@@ -2152,6 +2158,21 @@ private:
       }
    }
 
+   Window GetParentMenuBar()
+   {
+      Window menuBarParent;
+      for(menuBarParent = this; menuBarParent; menuBarParent = menuBarParent.parent)
+      {
+         if(menuBarParent.menuBar) break;
+         if(menuBarParent.parent && /*menuBarParent != */!menuBarParent.parent.activeClient)
+         {
+            menuBarParent = null;
+            break;
+         }
+      }
+      return menuBarParent ? menuBarParent.menuBar : null;
+   }
+
    void CreateSystemChildren(void)
    {
       Window parent = this;
@@ -2159,13 +2180,8 @@ private:
       bool hasClose = false, hasMaxMin = false;
       Point scroll = this.scroll;
 
-      if(state == maximized && this.parent.menuBar)
-      {
-         if(this.parent.activeClient == this)
-            parent = this.parent.menuBar;
-         else
-            parent = null;
-      }
+      if(state == maximized)
+         parent = GetParentMenuBar();
 
       if(parent)
       {
@@ -2380,6 +2396,7 @@ private:
                previous.CreateSystemChildren();
          }
       }
+
       if(menu)
       {
          MenuItem item;
@@ -2388,21 +2405,6 @@ private:
          if(menu)
             menu.Clean(this);
 
-         if(activeClient && activeClient.menu && activeClient.state != minimized)
-         {
-            if(mergeMenus)
-            {
-               //activeClient.menu.Clean(activeClient);
-               menu.Merge(activeClient.menu, true, activeClient);
-            }
-         }
-         
-         if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
-         {
-            if(mergeMenus)
-               menu.Merge(activeChild.menu, true, activeChild);
-         }
-         
          // Build window list
          if(activeClient)
          {
@@ -2460,9 +2462,26 @@ private:
          if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
          item = menu.FindItem(MenuFileSaveAll, 0);
          if(item) item.disabled = numDocuments < 1;
+
+         if(activeClient && activeClient.menu && activeClient.state != minimized)
+         {
+            if(mergeMenus)
+            {
+               //activeClient.menu.Clean(activeClient);
+               menu.Merge(activeClient.menu, true, activeClient);
+            }
+         }
+
+         if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
+         {
+            if(mergeMenus)
+               menu.Merge(activeChild.menu, true, activeChild);
+         }
       }
       // This is called again for a child window change, with same active client
       OnActivateClient(activeClient, previous);
+      if(!menuBar && !((BorderBits)borderStyle).fixed && parent && parent.activeClient == this)
+         parent.UpdateActiveDocument(null);
    }
 
    void _ShowDecorations(Box box, bool post)
@@ -4461,12 +4480,16 @@ private:
                                  status = false;
                                  break;
                               }
-                           if(style.tabCycle ||
-                              CycleChildren(key.shift, true, false, true))
+                           if(style.tabCycle)
                            {
                               delete this;
                               return true;
                            }
+                           if(CycleChildren(key.shift, true, false, true))
+                           {
+                              status = false;
+                              break;
+                           }
                         }
                         break;
                      /*
@@ -7409,7 +7432,7 @@ public:
       while(true)
       {
          Window sibling = cycle.data;
-         if(sibling.style.isActiveClient)
+         if(sibling.style.isActiveClient && sibling.visible && !sibling.style.nonClient)
          {
             if(c == id)
                break;
index bf5b1c3..c69392e 100644 (file)
@@ -1569,6 +1569,14 @@ public class PopupMenu : Window
       {
          ItemPtr ptr;
 
+         // Default width & height for merging menus into menu bars
+         if(isMenuBar)
+         {
+            FontExtent(display, font, "W",1, &maxW, &maxH);
+            if(!guiApp.textMode)
+               maxH += 6;
+         }
+
          for(ptr = menu.items.first; ptr; ptr = ptr.next)
          {
             MenuItem item = ptr.item;
@@ -1868,6 +1876,9 @@ public class PopupMenu : Window
          {
             Window master = this.master;
             Window activeClient = master.activeClient;
+            // TOFIX: Fix need for a cast here...
+            while(activeClient && !((BorderBits)activeClient.borderStyle).fixed)
+               activeClient = activeClient.activeClient;
             if(activeClient && activeClient.state == maximized)
                activeClient.SetState(normal, false, mods);
          }
index 146f3e8..e071ec1 100644 (file)
@@ -191,7 +191,7 @@ public class WindowsSkin_Window : Window
          *w += 2 * BORDER;
          *h += TOP + BOTTOM;
       }
-      if(((BorderBits)borderStyle).fixed && (state != maximized || !parent.menuBar))
+      if(((BorderBits)borderStyle).fixed && (state != maximized || !GetParentMenuBar()))
       {
          *h += CAPTION;
          if(!((BorderBits)borderStyle).sizable || state == minimized)
@@ -211,7 +211,7 @@ public class WindowsSkin_Window : Window
    {
       bool isNormal = (state == normal);
       if(nativeDecorations && rootWindow == this) return;
-      if(((BorderBits)borderStyle).fixed && (state != maximized || !parent.menuBar))
+      if(((BorderBits)borderStyle).fixed && (state != maximized || !GetParentMenuBar()))
       {
          *mw = MIN_WIDTH;
          *mh = MIN_HEIGHT;
@@ -280,7 +280,7 @@ public class WindowsSkin_Window : Window
             *y += TOP;
          }
 
-         if(((BorderBits)borderStyle).fixed && (state != maximized || !parent.menuBar))
+         if(((BorderBits)borderStyle).fixed && (state != maximized || !GetParentMenuBar()))
          {
             *y += CAPTION;
             if(!((BorderBits)borderStyle).sizable || state == minimized)
@@ -309,6 +309,7 @@ public class WindowsSkin_Window : Window
    {
       bool isNormal = (state == normal);
       int top = 0, border = 0, bottom = 0;
+      Window parentMenuBar = GetParentMenuBar() != null;
 
       if(nativeDecorations && rootWindow == this) return;
 
@@ -339,7 +340,7 @@ public class WindowsSkin_Window : Window
          if(((BorderBits)borderStyle).contour)
          {
             deepBorder = border;
-            deepTop = (((BorderBits)borderStyle).fixed && (state != maximized || !parent.menuBar)) ? (top + CAPTION) : top;
+            deepTop = (((BorderBits)borderStyle).fixed && (state != maximized || !parentMenuBar)) ? (top + CAPTION) : top;
             deepBottom = (((BorderBits)borderStyle).sizable && isNormal) ? bottom : border;
          }
 
@@ -347,7 +348,7 @@ public class WindowsSkin_Window : Window
             size.w - deepBorder - deepBorder, size.h - deepBottom - deepTop);
       }
 
-      if(((BorderBits)borderStyle).fixed && (state != maximized || !parent.menuBar))
+      if(((BorderBits)borderStyle).fixed && (state != maximized || !parentMenuBar))
       {
          if(state != maximized || !((BorderBits)borderStyle).sizable)
          {
@@ -411,7 +412,7 @@ public class WindowsSkin_Window : Window
       bool result = false;
       if(nativeDecorations && rootWindow == this) return false;
 
-      if(((BorderBits)borderStyle).fixed && (state != maximized || !parent.menuBar))
+      if(((BorderBits\)borderStyle).fixed && (state != maximized || !GetParentMenuBar()))
       {
          int corner = 0, border = 0, top = 0;
          if(((BorderBits)borderStyle).sizable && isNormal)
@@ -478,7 +479,7 @@ public class WindowsSkin_Window : Window
             top = border = DEAD_BORDER;
          else if(((BorderBits)borderStyle).sizable)
          {
-            if(state == maximized && parent.menuBar)
+            if(state == maximized && GetParentMenuBar())
             {
                top = 2;
                border = 2;
index 3bd4adb..17e4396 100644 (file)
@@ -1976,11 +1976,11 @@ class CodeEditor : Window
       designer.parent = parent;
       designer.Create();
 
-      toolBox = ((IDE)master).toolBox;
+      toolBox = ((IDEWorkSpace)master).toolBox;
       incref toolBox;
       // Debugger bug here: value of toolBox appears as 0
 
-      sheet = ((IDE)master).sheet;
+      sheet = ((IDEWorkSpace)master).sheet;
       incref sheet;
       return true;
    }
index 12b4164..bc03153 100644 (file)
@@ -36,7 +36,7 @@ class Designer : DesignerBase
 
    void AddToolBoxClass(Class _class)
    {
-      ((IDE)master).toolBox.AddControl(_class);
+      ((IDEWorkSpace)master).toolBox.AddControl(_class);
    }
    
    void AddDefaultMethod(Instance instance, Instance classInstance)
index 7db5d6c..d9cdd26 100644 (file)
@@ -299,7 +299,7 @@ class Sheet : Window
       bool NotifySelect(DropBox control, DataRow row, Modifiers keyFlags)
       {
          ObjectInfo selected = (ObjectInfo)(row ? row.tag : null);
-         ToolBox toolBox = ((IDE)parent).toolBox;
+         ToolBox toolBox = ((IDEWorkSpace)parent).toolBox;
 
          if(codeEditor && selected)
             codeEditor.SelectObject(selected);
@@ -407,7 +407,7 @@ class Sheet : Window
 
          properties.Activate();
 
-         // ((IDE)master).SheetSelected(Properties);
+         // ((IDEWorkSpace)master).SheetSelected(Properties);
          return true;
       }
    };
@@ -436,7 +436,7 @@ class Sheet : Window
 
          methods.Activate();
                        
-         // ((IDE)master).SheetSelected(Methods);
+         // ((IDEWorkSpace)master).SheetSelected(Methods);
          return true;
       }
    };
index e5fe677..ff5e660 100644 (file)
@@ -193,27 +193,73 @@ void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int
    }
 }
 
-class IDE : Window
+public class ToolBar : public Stacker
 {
-   nativeDecorations = true;
-   icon = { ":icon.png" };
-   text = titleECEREIDE;
-   background = Color { 85, 85, 85 };
+   direction = horizontal;
+   background = activeBorder;
+   opacity = 1.0f;
+   gap = 0;
+
+   anchor = Anchor { left = 0, right = 0 };
+   clientSize = { h = 32 };
+   borderStyle = bevel;
+}
+
+class IDEMainFrame : Window
+{
+   background = activeBorder;
    borderStyle = sizable;
    hasMaximize = true;
    hasMinimize = true;
    hasClose = true;
+   size = { 840, 480 };
+   minClientSize = { 600, 300 };
+   nativeDecorations = true; 
+   borderStyle = sizable;
+   hasMaximize = true;
+   hasMinimize = true;
+   hasClose = true;
+   hasMenuBar = true;
+   icon = { ":icon.png" };
+   text = titleECEREIDE;
+
+   Stacker stack
+   {
+      this;
+      menu = { };
+      isActiveClient = true;
+      gap = 0;
+      direction = vertical;
+      background = activeBorder;
+      anchor = { left = 0, top = 0, right = 0, bottom = 0 };
+   };
+
+   ToolBar toolBar
+   {
+      stack, this;
+      size = { h = 32 };
+   };
+
+   IDEWorkSpace ideWorkSpace { stack, this };
+}
+
+define ide = ideMainFrame.ideWorkSpace;
+
+class IDEWorkSpace : Window
+{
+   background = Color { 85, 85, 85 };
+
    //tabCycle = true;
    hasVertScroll = true;
    hasHorzScroll = true;
-   hasMenuBar = true;
    hasStatusBar = true;
+   isActiveClient = true;
 #if 0 //def _DEBUG
    //stayOnTop = true;
    size = { 800, 600 };
    anchor = { top = 0, right = 0, bottom = 0 };
 #else
-   state = maximized;
+   //state = maximized;
    anchor = { left = 0, top = 0, right = 0, bottom = 0 };
 #endif
    menu = Menu {  };
@@ -572,7 +618,16 @@ class IDE : Window
       Menu recentFiles { fileMenu, $"Recent Files", r };
       Menu recentProjects { fileMenu, $"Recent Projects", p };
       MenuDivider { fileMenu };
-      MenuItem exitItem { fileMenu, $"Exit", x, altF4, NotifySelect = MenuFileExit };
+      MenuItem exitItem
+      {
+         fileMenu, $"Exit", x, altF4, NotifySelect = MenuFileExit;
+
+         bool NotifySelect(MenuItem selection, Modifiers mods)
+         {
+            ideMainFrame.Destroy(0);
+            return true;
+         }
+      };
 
       bool FileRecentFile(MenuItem selection, Modifiers mods)
       {
@@ -1244,7 +1299,7 @@ class IDE : Window
       // Leave it after Create to avoid flicker due to seeing IDE without a project view
       projectView.workspace = workspace;
       projectView.project = project;
-      SetText("%s - %s", project.topNode.name, titleECEREIDE);
+      ideMainFrame.SetText("%s - %s", project.topNode.name, titleECEREIDE);
 
       AdjustMenus();
 
@@ -1616,7 +1671,7 @@ class IDE : Window
                         if(document)
                            document.fileName = filePath;
 
-                        SetText("%s - %s", filePath, titleECEREIDE);
+                        ideMainFrame.SetText("%s - %s", filePath, titleECEREIDE);
 
                         // this crashes on starting ide with epj file, solution please?
                         // app.UpdateDisplay();
@@ -2190,6 +2245,7 @@ class IDE : Window
          workspace.timer.Stop();
          workspace.Save();
       }
+      ideMainFrame.Destroy(0);
       return true;
    }
 
@@ -2417,7 +2473,7 @@ class IDE : Window
       }
    }
 
-   IDE()
+   IDEWorkSpace()
    {
       // Graphics Driver Menu
       int c;
@@ -2496,7 +2552,7 @@ class IDE : Window
       }
    }
 
-   ~IDE()
+   ~IDEWorkSpace()
    {
       delete driverItems;
       delete skinItems;
@@ -2564,7 +2620,7 @@ class IDEApp : GuiApplication
    }
 }
 
-IDE ide { };
+IDEMainFrame ideMainFrame { };
 
 define app = ((IDEApp)__thisModule);
 #ifdef _DEBUG