ecere/ToolBar: Fixed crash in ToolButton with default MenuItem NotifyClicked; Improve...
authorJerome St-Louis <jerome@ecere.com>
Thu, 15 Mar 2012 04:22:46 +0000 (00:22 -0400)
committerJerome St-Louis <jerome@ecere.com>
Thu, 15 Mar 2012 04:22:46 +0000 (00:22 -0400)
ecere/src/gui/controls/ToolTip.ec
samples/guiAndGfx/toolBars/toolBarDemo.ec

index bffe9a5..d141ea6 100644 (file)
@@ -294,7 +294,7 @@ public class ToolButton : Button
    {
       ToolButton toolButton = (ToolButton)button;
       MenuItem menuItem = toolButton.menuItem;
-      return menuItem.NotifySelect(this, menuItem, 0);
+      return menuItem ? menuItem.NotifySelect(this, menuItem, 0) : 0;
    }
 
 public:
@@ -303,7 +303,7 @@ public:
    {
       get
       {
-         MenuItem menuItem = *(MenuItem *)((byte *)master + (uint)menuItemPtr);
+         MenuItem menuItem = menuItemPtr ? *(MenuItem *)((byte *)master + (uint)menuItemPtr) : null;
          return menuItem;
       }
    }
index 85e2e3b..dd1c632 100644 (file)
@@ -22,34 +22,53 @@ class ToolBarDemo : Window
       anchor = { left = 0, top = 0, right = 0, bottom = 0 };
    };
 
-   ToolBar toolBar
+   ToolBar toolBar   { stack, this };
+   Window workSpace { stack, this, anchor = { 0, 0, 0, 0 }, background = gray };
+
+   Window s1 { toolBar, size = { w = 8 } };
+   ToolButton goBack
    {
-      stack, this;
-      size = { h = 32 };
+      toolBar, this, id = ToolId::goBack, toolTip = "Go Back", bitmap = { "<:ecere>actions/goPrevious.png" };
 
-      /*bool NotifyClicked(Button button, int x, int y, Modifiers mods)
+      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
       {
-         ToolId id = (ToolId)button.id;
-         switch(id)
-         {
-            case newWindow: break;
-            case goBack:    break;
-            case goForward: break;
-            case goHome:    break;
-         }
+         workSpace.CycleChildren(false, true, false, false);
          return true;
-      }*/
+      }
    };
-
-   Window s1 { toolBar, size = { w = 8 } };
-   ToolButton goBack { toolBar, this, id = ToolId::goBack, toolTip = "Go Back", bitmap = { "<:ecere>actions/goPrevious.png" } };
    Window s2 { toolBar, size = { w = 2 } };
-   ToolButton goForward { toolBar, this, id = ToolId::goForward, toolTip = "Go Forward", bitmap = { "<:ecere>actions/goNext.png" } };
+   ToolButton goForward
+   {
+      toolBar, this, id = ToolId::goForward, toolTip = "Go Forward", bitmap = { "<:ecere>actions/goNext.png" };
+
+      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
+      {
+         workSpace.CycleChildren(true, true, false, false);
+         return true;
+      }
+   };
    Window s3 { toolBar, size = { w = 12 } };
-   ToolButton newWindow { toolBar, this, id = ToolId::newWindow, toolTip = "New Window", bitmap = { "<:ecere>actions/windowNew.png" } };
+   ToolButton newWindow
+   {
+      toolBar, this, id = ToolId::newWindow, toolTip = "New Window", bitmap = { "<:ecere>actions/windowNew.png" };
+
+      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
+      {
+         Window { isActiveClient = true, parent = workSpace, workSpace, hasClose = true, isDocument = true, clientSize = { 320, 200 }, anchor = { { cascade } } }.Create();
+         return true;
+      }
+   };
    Window s4 { toolBar, size = { w = 2 } };
-   ToolButton goHome { toolBar, this, id = ToolId::goHome, toolTip = "Go Home", bitmap = { "<:ecere>actions/goHome.png" } };
+   ToolButton goHome
+   {
+      toolBar, this, id = ToolId::goHome, toolTip = "Go Home", bitmap = { "<:ecere>actions/goHome.png" };
 
+      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
+      {
+         // Go home!
+         return true;
+      }
+   };
 }
 
 ToolBarDemo tbDemo { };