compiler/libec; ecere; ide: Safer default virtual method calls
[sdk] / ecere / src / gui / controls / ToolTip.ec
index 3dc0459..4b9885e 100644 (file)
@@ -30,7 +30,7 @@ public class ToolTip : Window
    int margin; margin = 2;
    Point offset; offset = { 0, 20 };
 
-   public property String tip
+   public property const String tip
    {
       set
       {
@@ -44,7 +44,7 @@ public class ToolTip : Window
 
             tip = CopyString(value);
             next = tip[0];
-            for(c = 0; ch = next; c++)
+            for(c = 0; (ch = next); c++)
             {
                next = tip[c+1];
                if(ch == '\n' || next == '\0')
@@ -100,9 +100,9 @@ public class ToolTip : Window
          timer.Stop();
          position =
          {
-            pos.x + offset.x + tippedWindow.clientStart.x + 
+            pos.x + offset.x + tippedWindow.clientStart.x +
                tippedWindow.absPosition.x - parent.position.x;
-            pos.y + offset.y + tippedWindow.clientStart.y + 
+            pos.y + offset.y + tippedWindow.clientStart.y +
                tippedWindow.absPosition.y - parent.position.y;
          };
          Create();
@@ -169,7 +169,7 @@ public class ToolTip : Window
    ToolTip ::Find(Window window)
    {
       Window w;
-      for(w = window.firstSlave; w; w = w.next)
+      for(w = window.firstSlave; w; w = w.nextSlave)
       {
          if(eClass_IsDerived(w._class, class(ToolTip)))
             break;
@@ -186,7 +186,7 @@ public class ToolTip : Window
          toolTip.closeTimer.Stop();
          if(!mods.isSideEffect && !toolTip.created && rootWindow.active)
             toolTip.timer.Start();
-         return toolTip.OrigOnMouseOver(this, x, y, mods);
+         return toolTip.OrigOnMouseOver ? toolTip.OrigOnMouseOver(this, x, y, mods) : true;
       }
       return true;
    }
@@ -198,7 +198,7 @@ public class ToolTip : Window
       {
          toolTip.timer.Stop();
          toolTip.closeTimer.Start();
-         return toolTip.OrigOnMouseLeave(this, mods);
+         return toolTip.OrigOnMouseLeave ? toolTip.OrigOnMouseLeave(this, mods) : true;
       }
       return true;
    }
@@ -210,7 +210,7 @@ public class ToolTip : Window
       {
          toolTip.timer.Stop();
          toolTip.Destroy(0);
-         return toolTip.OrigOnLeftButtonDown(this, x, y, mods);
+         return toolTip.OrigOnLeftButtonDown ? toolTip.OrigOnLeftButtonDown(this, x, y, mods) : true;
       }
       return true;
    }
@@ -227,7 +227,7 @@ public class ToolTip : Window
             toolTip.timer.Stop();
             toolTip.timer.Start();
          }
-         return toolTip.OrigOnMouseMove(this, x, y, mods);
+         return toolTip.OrigOnMouseMove ? toolTip.OrigOnMouseMove(this, x, y, mods) : true;
       }
       return true;
    }
@@ -242,3 +242,88 @@ public class ToolTip : Window
       }
    }
 }
+
+// NOTE: I'm putting this here for now because I don't have time to update all the makefiles right now
+import "Stacker"
+
+public class ToolBar : Stacker
+{
+   direction = horizontal;
+   background = formColor;
+   gap = 0;
+   inactive = true;
+
+   anchor = Anchor { left = 0, right = 0 };
+   clientSize = { h = 32 };
+   borderStyle = bevel;
+
+   watch(master)
+   {
+      Window w;
+      for(w = firstChild; w; w = w.next)
+         w.master = master;
+   };
+}
+
+public class ToolButton : Button
+{
+   bevelOver = true;
+   size = Size { 24, 24 };
+   opacity = 0;
+   bitmapAlignment = center;
+   MenuItem * menuItemPtr;
+
+   watch(master)
+   {
+      if(menuItemPtr)
+      {
+         Window master = this.master;
+         if(master && master.parent && !eClass_IsDerived(master._class, class(Stacker)))
+         {
+            MenuItem menuItem = this.menuItem;
+            BitmapResource bmp;
+
+            if(menuItem && (bmp = menuItem.bitmap))
+            {
+               //bitmap = bmp;
+               // We cannot reuse the same BitmapResource object here, as a BitmapResource is meant to be added with AddResource to a single Window
+               bitmap = { fileName = bmp.fileName, grayed = bmp.grayed, monochrome = bmp.monochrome, transparent = bmp.transparent, alphaBlend = bmp.alphaBlend, keepData = bmp.keepData };
+            }
+         }
+      }
+   };
+
+   NotifyClicked = SelectMenuItem;
+
+   bool Window::SelectMenuItem(Button button, int x, int y, Modifiers mods)
+   {
+      ToolButton toolButton = (ToolButton)button;
+      MenuItem menuItem = toolButton.menuItem;
+      return menuItem ? menuItem.NotifySelect(this, menuItem, 0) : 0;
+   }
+
+public:
+   property MenuItem * menuItemPtr { set { menuItemPtr = value; } }
+   property MenuItem menuItem
+   {
+      get
+      {
+         MenuItem menuItem = menuItemPtr ? *(MenuItem *)((byte *)master + (uintptr)menuItemPtr) : null;
+         return menuItem;
+      }
+   }
+}
+
+public class ToolSeparator : Window
+{
+   size = Size { 4, 24 };
+   opacity = 0;
+
+   void OnRedraw(Surface surface)
+   {
+      surface.foreground = Color { 85, 85, 85 };
+      surface.VLine(0, 23, 1);
+      surface.foreground = white;
+      surface.VLine(0, 23, 2);
+   }
+}