sdk: const correctness
[sdk] / ecere / src / gui / FormDesigner.ec
index 1789f7d..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)
@@ -90,16 +90,15 @@ 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;
+      //OldLink link;
       if(eClass_GetProperty(_class, "icon"))
          designer.AddToolBoxClass(_class);
       /*
@@ -149,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;
 
@@ -174,7 +173,7 @@ 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 = 632, h = 438;
       if(clientSize.w - 40 -200 < w)
@@ -191,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("   caption = \"%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("   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");
@@ -256,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;
 
@@ -279,9 +278,9 @@ class FormDesigner : ClassDesignerBase
                   }
                   else if(resizeX > 0)
                   {
-                     w += dx;            
+                     w += dx;
                   }
-            
+
                   if(resizeY < 0)
                   {
                      y += dy;
@@ -291,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;
@@ -317,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)
@@ -329,7 +328,7 @@ class FormDesigner : ClassDesignerBase
                   x -= x % GridSnap;
                   y -= y % GridSnap;
                }
-               
+
                activeDesigner.ModifyCode();
 
                moved.Move(x, y, w, h);
@@ -351,7 +350,7 @@ class FormDesigner : ClassDesignerBase
 
                {
                   int vpw, vph;
-                  
+
                   // Fix Anchor
                   x = moved.position.x;
                   y = moved.position.y;
@@ -388,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;
@@ -412,7 +411,7 @@ class FormDesigner : ClassDesignerBase
                box.top -= 7;
                box.right += 7;
                box.bottom += 7;
-         
+
                Update(box);
                //activeDesigner.Update(box);
 
@@ -448,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;
@@ -544,7 +543,7 @@ class FormDesigner : ClassDesignerBase
                ((control == form) ? (Window)this : form).SetMouseRangeToWindow();
             else
                ((control == form) ? (Window)this : form).SetMouseRangeToClient();
-            
+
             xClicked = x;
             yClicked = y;
 
@@ -566,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)
@@ -576,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.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);
-            }
+               AddControl(parent, x, y);
          }
       }
       return true;
@@ -650,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;
@@ -667,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;
@@ -727,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;
@@ -754,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;
@@ -852,7 +862,7 @@ static bool OnKeyDown(Window window, Key key, unichar ch)
          if(!confirmation)
          {
             activeDesigner.ModifyCode();
-         
+
             designer.selected.Destroy(0);
             //activeDesigner.Update(null);
             designer.Update(null);