sdk: const correctness
[sdk] / ecere / src / gui / FormDesigner.ec
index 5c485c7..dd73a6f 100644 (file)
@@ -36,7 +36,7 @@ class FormDesigner : ClassDesignerBase
          if(form)
             form.visible = true;
       }
-      
+
       selected = control;
       Update(null);
       //activeDesigner.Update(null);
@@ -61,7 +61,7 @@ class FormDesigner : ClassDesignerBase
       else
       {
          // instance.parent = _class;
-      }   
+      }
    }
 
    void ::PostCreateObject(Window instance, ObjectInfo object, bool isClass, Window _class)
@@ -82,7 +82,7 @@ class FormDesigner : ClassDesignerBase
    void ::DroppedObject(Window instance, ObjectInfo object, bool isClass, Window _class)
    {
       instance.parent = _class;
-      instance.text = object.name;
+      instance.caption = object.name;
       instance.Create();
    }
 
@@ -90,17 +90,17 @@ class FormDesigner : ClassDesignerBase
    {
       if(form)
       {
-         OnLeftButtonUp(
-            selected.absPosition.x - absPosition.x - clientStart.x + selected.clientStart.x + GridSnap,
-            selected.absPosition.y - absPosition.y - clientStart.y + selected.clientStart.y + GridSnap, 0);
-         Activate();
+         AddControl(form, GridSnap, GridSnap);
+         if(visible)
+            Activate();
       }
    }
 
    void ::ListClasses(DesignerBase designer, Class _class)
    {
-      OldLink link;
-      designer.AddToolBoxClass(_class);
+      //OldLink link;
+      if(eClass_GetProperty(_class, "icon"))
+         designer.AddToolBoxClass(_class);
       /*
       for(link = _class.derivatives.first; link; link = link.next)
          designer.AddToolBoxClass(link.data);
@@ -113,10 +113,18 @@ class FormDesigner : ClassDesignerBase
       Class commonControlClass = eSystem_FindClass(_class.module, "CommonControl");
       for(link = commonControlClass.derivatives.first; link; link = link.next)
       {
-         ListClasses(designer, link.data);
+         ListSubClasses(designer, link.data);
       }
    }
 
+   void ::ListSubClasses(DesignerBase designer, Class c)
+   {
+      OldLink link;
+      ListClasses(designer, c);
+      for(link = c.derivatives.first; link; link = link.next)
+         ListSubClasses(designer, link.data);
+   }
+
    void ::PrepareTestObject(DesignerBase designer, Window test)
    {
       test.parent = designer;
@@ -140,21 +148,21 @@ class FormDesigner : ClassDesignerBase
    void ::FixProperty(Property prop, Window object)
    {
       FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
-      
+
       if(!strcmp(prop.name, "parent"))
       {
          if(object.parent == guiApp.desktop)
             object.parent = designer.form;
 
          if(object.parent == designer.form)
-         {  
+         {
             ObjectInfo previous = object.object;
             while((previous = previous.prev) && ((Window)previous.instance).parent != designer.form);
             if(previous)
                object.parent.children.Move(object, (Window)previous.instance);
          }
       }
-      
+
       if(!strcmp(prop.name, "master") && !object.master)
          object.master = designer.form;
 
@@ -165,14 +173,14 @@ class FormDesigner : ClassDesignerBase
       }
    }
 
-   void ::CreateNew(EditBox editBox, Size clientSize, char * name, char * inherit)
+   void ::CreateNew(EditBox editBox, Size clientSize, const char * name, const char * inherit)
    {
-      int w = 640, h = 480;
+      int w = 632, h = 438;
       if(clientSize.w - 40 -200 < w)
       {
          w = (clientSize.w - 40 - 200);
          w -= w % GridSnap;
-         h = h * w / 640;
+         h = h * w / 632;
          h -= h % GridSnap;
          w = Max(w, 304);
          h = Max(h, 304);
@@ -182,19 +190,19 @@ class FormDesigner : ClassDesignerBase
       editBox.Printf("import \"ecere\"\n\n");
       editBox.Printf("class %s : %s\n", name, inherit);
       editBox.Printf("{\n");
-      
-      editBox.Printf("   text = \"%s\";\n", name);
+
+      editBox.Printf("   caption = $\"%s\";\n", name);
       //editBox.Printf("   background = Color { 212, 208, 200 };\n");
-      
-      editBox.Printf("   background = activeBorder;\n");
+
+      editBox.Printf("   background = formColor;\n");
       editBox.Printf("   borderStyle = sizable;\n");
       editBox.Printf("   hasMaximize = true;\n");
       editBox.Printf("   hasMinimize = true;\n");
       editBox.Printf("   hasClose = true;\n");
       //editBox.Printf("   position = { 20, 20 };\n");
-      editBox.Printf("   size = { %d, %d };\n", w, h);
-      
-      
+      editBox.Printf("   clientSize = { %d, %d };\n", w, h);
+
+
       //editBox.Printf("   Button ok { parent = this, position = { 100, 100 }, size = { 80, 20 } };\n");
 
       //editBox.Printf("\n   Button ok\n   {\n      parent = this;\n\n      bool NotifyClicked()\n      {\n      }\n   };\n");
@@ -203,7 +211,7 @@ class FormDesigner : ClassDesignerBase
       /*
       editBox.Printf("class %s : %s\n", "SecondForm", inherit);
       editBox.Printf("{\n");
-      editBox.Printf("   text = \"%s\";\n", "SecondForm");
+      editBox.Printf("   caption = \"%s\";\n", "SecondForm");
       editBox.Printf("   background = Color { 100, 90, 120 };\n");
       editBox.Printf("   borderStyle = sizable;\n");
       editBox.Printf("   hasMaximize = true;\n");
@@ -211,7 +219,7 @@ class FormDesigner : ClassDesignerBase
       editBox.Printf("   hasClose = true;\n");
       editBox.Printf("   position = { 20, 20 };\n");
       editBox.Printf("   size = { %d, %d };\n", 320, 200);
-      editBox.Printf("   Button ok { parent = this, text = \"OK\", position = { A_RIGHT|10, A_RIGHT|10 }, size = { 80, 20 } };\n");
+      editBox.Printf("   Button ok { parent = this, caption = \"OK\", position = { A_RIGHT|10, A_RIGHT|10 }, size = { 80, 20 } };\n");
       editBox.Printf("}\n");
       */
    }
@@ -247,7 +255,7 @@ class FormDesigner : ClassDesignerBase
                int h = moved.size.h;
                Box box;
                Anchor anchor = moved.anchor;
-               
+
                x = xBefore + parentBefore.absPosition.x - curParent.absPosition.x + parentBefore.clientStart.x - curParent.clientStart.x;
                y = yBefore + parentBefore.absPosition.y - curParent.absPosition.y + parentBefore.clientStart.y - curParent.clientStart.y;
 
@@ -270,9 +278,9 @@ class FormDesigner : ClassDesignerBase
                   }
                   else if(resizeX > 0)
                   {
-                     w += dx;            
+                     w += dx;
                   }
-            
+
                   if(resizeY < 0)
                   {
                      y += dy;
@@ -282,12 +290,12 @@ class FormDesigner : ClassDesignerBase
                   {
                      h += dy;
                   }
-                  if(resizeX) 
+                  if(resizeX)
                   {
                      w = Max(w, GridSnap);
                      moved.size.w = w;
                   }
-                  if(resizeY) 
+                  if(resizeY)
                   {
                      h = Max(h, GridSnap);
                      moved.size.h = h;
@@ -308,7 +316,7 @@ class FormDesigner : ClassDesignerBase
 
                      moved.parent = parent;
                      if(parent == form)
-                     {  
+                     {
                         ObjectInfo previous = moved.object;
                         while((previous = previous.prev) && ((Window)previous.instance).parent != form);
                         if(previous)
@@ -320,7 +328,7 @@ class FormDesigner : ClassDesignerBase
                   x -= x % GridSnap;
                   y -= y % GridSnap;
                }
-               
+
                activeDesigner.ModifyCode();
 
                moved.Move(x, y, w, h);
@@ -342,7 +350,7 @@ class FormDesigner : ClassDesignerBase
 
                {
                   int vpw, vph;
-                  
+
                   // Fix Anchor
                   x = moved.position.x;
                   y = moved.position.y;
@@ -379,7 +387,7 @@ class FormDesigner : ClassDesignerBase
                      //anchor.horz.type = anchor.horz.distance ? offset : 0;
                   }
                   else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
-                  if(!anchor.top.type && !anchor.bottom.type) 
+                  if(!anchor.top.type && !anchor.bottom.type)
                   {
                      anchor.vert.distance = (y + h / 2) - (vph / 2);
                      //anchor.vert.type = anchor.vert.distance ? offset : 0;
@@ -403,7 +411,7 @@ class FormDesigner : ClassDesignerBase
                box.top -= 7;
                box.right += 7;
                box.bottom += 7;
-         
+
                Update(box);
                //activeDesigner.Update(box);
 
@@ -439,13 +447,13 @@ class FormDesigner : ClassDesignerBase
 
    bool OnLeftButtonDown(int x, int y, Modifiers mods)
    {
-      char * objectClass = activeDesigner.objectClass;
+      const char * objectClass = activeDesigner.objectClass;
 
       if(!objectClass && selected)
       {
          Window control = FindWindow(form, master, null, x, y, false, null, null);
          bool onBorder = false;
-         Window parent = selected.parent;
+         //Window parent = selected.parent;
          //if(control && (parent == control || parent == control.parent))
          {
             int cx = selected.absPosition.x - absPosition.x - clientStart.x;
@@ -535,7 +543,7 @@ class FormDesigner : ClassDesignerBase
                ((control == form) ? (Window)this : form).SetMouseRangeToWindow();
             else
                ((control == form) ? (Window)this : form).SetMouseRangeToClient();
-            
+
             xClicked = x;
             yClicked = y;
 
@@ -557,6 +565,58 @@ class FormDesigner : ClassDesignerBase
       return true;
    }
 
+   void AddControl(Window parent, int x, int y)
+   {
+      const char * objectClass = activeDesigner.objectClass;
+      ObjectInfo object;
+      Window control;
+      Class c = eSystem_FindClass(form._class.module, objectClass);
+      if(!c)
+         c = eSystem_FindClass(form._class.module.application, objectClass);
+      if(c)
+      {
+         control = (Window)eInstance_New(c);
+
+         activeDesigner.CodeAddObject(control, &object);
+
+         while(!parent.name)
+         {
+            x += parent.position.x + parent.clientStart.x;
+            y += parent.position.y + parent.clientStart.y;
+            parent = parent.parent;
+         }
+
+         control.object = object;
+
+         control.parent = parent;
+         control.master = form;
+
+         x -= x % GridSnap;
+         y -= y % GridSnap;
+
+         control.position.x = x;
+         control.position.y = y;
+         control.caption = object.name;
+
+         LockControls(control, control);
+
+         control.Create();
+         if(parent == form)
+         {
+            ObjectInfo previous = control.object;
+            while((previous = previous.prev) && ((Window)previous.instance).parent != form);
+            if(previous)
+               control.parent.children.Move(control, (Window)previous.instance);
+         }
+
+         activeDesigner.SheetAddObject(object);
+
+         //selected = control;
+         //activeDesigner.Update(null);
+         Update(null);
+      }
+   }
+
    bool OnLeftButtonUp(int x, int y, Modifiers mods)
    {
       if(moved)
@@ -567,53 +627,12 @@ class FormDesigner : ClassDesignerBase
       }
       else
       {
-         char * objectClass = activeDesigner.objectClass;
+         const char * objectClass = activeDesigner.objectClass;
          if(objectClass)
          {
             Window parent = FindWindow(form, activeDesigner, null, x, y, true, &x, &y);
             if(parent)
-            {
-               ObjectInfo object;
-               Window control = (Window)eInstance_New(eSystem_FindClass(form._class.module, objectClass));
-
-               activeDesigner.CodeAddObject(control, &object);
-
-               while(!parent.name) 
-               {
-                  x += parent.position.x + parent.clientStart.x;
-                  y += parent.position.y + parent.clientStart.y;
-                  parent = parent.parent;
-               }
-
-               control.object = object;
-
-               control.parent = parent;
-               control.master = form;
-
-               x -= x % GridSnap;
-               y -= y % GridSnap;
-
-               control.position.x = x;
-               control.position.y = y;
-               control.text = object.name;
-
-               LockControls(control, control);
-
-               control.Create();
-               if(parent == form)
-               {  
-                  ObjectInfo previous = control.object;
-                  while((previous = previous.prev) && ((Window)previous.instance).parent != form);
-                  if(previous)
-                     control.parent.children.Move(control, (Window)previous.instance);
-               }
-
-               activeDesigner.SheetAddObject(object);
-
-               //selected = control;
-               //activeDesigner.Update(null);
-               Update(null);
-            }
+               AddControl(parent, x, y);
          }
       }
       return true;
@@ -641,7 +660,7 @@ class FormDesigner : ClassDesignerBase
          window.OnSysKeyDown = ecere::gui::OnSysKey;
          window.OnSysKeyHit = ecere::gui::OnSysKey;
          window.OnSysKeyUp = ecere::gui::OnSysKey;
-            
+
          if(object != object.oClass)
          {
             window.OnActivate = Control_OnActivate;
@@ -658,12 +677,12 @@ class FormDesigner : ClassDesignerBase
 
    void DrawSelection(Window window, Surface surface)
    {
-      Window result = null, control;
+      Window control;
       for(control = window.lastChild; control; control = control.prev)
       {
          if(selected == control)
          {
-            Window parent = selected.parent;
+            //Window parent = selected.parent;
             int x;
             int y;
             int w = selected.size.w;
@@ -718,7 +737,7 @@ static bool Control_OnActivate(Window window, bool active, Window previous, bool
    }
    return true;
 }
-
+/*
 static Window GetWindow(Window window, int x, int y, int * rx, int * ry)
 {
    Window result = null, control;
@@ -745,7 +764,7 @@ static Window GetWindow(Window window, int x, int y, int * rx, int * ry)
    }
    return result;
 }
-
+*/
 static Window FindWindow(Window form, Window window, Window moved, int x, int y, bool asParent, int * dx, int * dy)
 {
    Window result = null, control;
@@ -821,7 +840,7 @@ static bool OnKeyDown(Window window, Key key, unichar ch)
          bool confirmation = activeDesigner.ObjectContainsCode(designer.selected.object);
 
          if(confirmation)
-            confirmation = MessageBox { type = okCancel, master = window.master, text = "Deleting control with code", contents = "Control contains code. Delete anyways?" }.Modal() != ok;
+            confirmation = MessageBox { type = okCancel, master = window.master, caption = $"Deleting control with code", contents = $"Control contains code. Delete anyways?" }.Modal() != ok;
 
          // Confirmation if control contains other controls
          if(!confirmation)
@@ -837,13 +856,13 @@ static bool OnKeyDown(Window window, Key key, unichar ch)
             }
 
             if(confirmation)
-               confirmation = MessageBox { type = okCancel, master = window.master, text = "Deleting control with children", contents = "Control contains other controls. Delete control and children?"}.Modal() != ok;
+               confirmation = MessageBox { type = okCancel, master = window.master, caption = $"Deleting control with children", contents = $"Control contains other controls. Delete control and children?"}.Modal() != ok;
          }
 
          if(!confirmation)
          {
             activeDesigner.ModifyCode();
-         
+
             designer.selected.Destroy(0);
             //activeDesigner.Update(null);
             designer.Update(null);