ecere/gui/Anchor: Fixed stringification on empty anchor
[sdk] / ecere / src / gui / Anchor.ec
index 37868b5..a226752 100644 (file)
@@ -9,8 +9,13 @@ public struct AnchorValue
    union
    {
       int distance;
-      float percent;      
+      float percent;
    };
+   property MinMaxValue
+   {
+      set { distance = value; type = offset; }
+      get { return distance; }
+   }
    property int
    {
       set { distance = value; type = offset; }
@@ -22,7 +27,7 @@ public struct AnchorValue
       get { return (double) percent; }
    }
 
-   char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
+   const char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
    {
       if(type == offset)
       {
@@ -36,7 +41,7 @@ public struct AnchorValue
          c = strlen(stringOutput)-1;
          for( ; c >= 0; c--)
          {
-            if(stringOutput[c] != '0') 
+            if(stringOutput[c] != '0')
                last = Max(last, c);
             if(stringOutput[c] == '.')
             {
@@ -55,13 +60,13 @@ public struct AnchorValue
       return stringOutput;
    }
 
-   bool OnGetDataFromString(char * stringOutput)
+   bool OnGetDataFromString(const char * stringOutput)
    {
       char * end;
       if(strchr(stringOutput, '.'))
       {
          float percent = (float)strtod(stringOutput, &end);
-         
+
          if(end != stringOutput)
          {
             this.percent = percent;
@@ -83,6 +88,7 @@ public struct AnchorValue
       {
          distance = 0;
          type = 0;
+         return true;
       }
       return false;
    }
@@ -95,8 +101,13 @@ public struct MiddleAnchorValue
    union
    {
       int distance;
-      float percent;      
+      float percent;
    };
+   property MinMaxValue
+   {
+      set { distance = value; type = none; }
+      get { return distance; }
+   }
    property int
    {
       set { distance = value; type = none; }
@@ -108,7 +119,7 @@ public struct MiddleAnchorValue
       get { return (double) percent; }
    }
 
-   char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
+   const char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
    {
       if(type == middleRelative)
       {
@@ -118,7 +129,7 @@ public struct MiddleAnchorValue
          c = strlen(stringOutput)-1;
          for( ; c >= 0; c--)
          {
-            if(stringOutput[c] != '0') 
+            if(stringOutput[c] != '0')
                last = Max(last, c);
             if(stringOutput[c] == '.')
             {
@@ -141,7 +152,7 @@ public struct MiddleAnchorValue
       return stringOutput;
    }
 
-   bool OnGetDataFromString(char * stringOutput)
+   bool OnGetDataFromString(const char * stringOutput)
    {
       if(strchr(stringOutput, '.'))
       {
@@ -163,18 +174,19 @@ public struct Anchor
 {
    union { AnchorValue left; MiddleAnchorValue horz; };
    union { AnchorValue top; MiddleAnchorValue vert; };
-   AnchorValue right, bottom;      
+   AnchorValue right, bottom;
 
-   char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
+   const char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
    {
       char tempString[256];
-      char * anchorValue;
+      const char * anchorValue;
       bool subNeedClass;
 
+      stringOutput[0] = 0;
       tempString[0] = '\0';
       anchorValue = left.OnGetString(tempString, null, &subNeedClass);
       if(anchorValue[0]) { if(stringOutput[0]) strcat(stringOutput, ", "); strcat(stringOutput, "left = "); strcat(stringOutput, anchorValue); }
-      
+
       //if(((!left.type && !right.type) && horz.distance) || horz.type == middleRelative)
       if(!right.type && ((!left.type && horz.distance) || horz.type == middleRelative))
       {
@@ -182,11 +194,11 @@ public struct Anchor
          anchorValue = horz.OnGetString(tempString, null, &subNeedClass);
          if(anchorValue[0]) { if(stringOutput[0]) strcat(stringOutput, ", "); strcat(stringOutput, "horz = "); strcat(stringOutput, anchorValue); }
       }
-      
+
       tempString[0] = '\0';
       anchorValue = top.OnGetString(tempString, null, &subNeedClass);
       if(anchorValue[0]) { if(stringOutput[0]) strcat(stringOutput, ", "); strcat(stringOutput, "top = "); strcat(stringOutput, anchorValue); }
-      
+
       tempString[0] = '\0';
       anchorValue = right.OnGetString(tempString, null, &subNeedClass);
       if(anchorValue[0]) { if(stringOutput[0]) strcat(stringOutput, ", "); strcat(stringOutput, "right = "); strcat(stringOutput, anchorValue); }
@@ -198,15 +210,15 @@ public struct Anchor
          anchorValue = vert.OnGetString(tempString, null, &subNeedClass);
          if(anchorValue[0]) { if(stringOutput[0]) strcat(stringOutput, ", "); strcat(stringOutput, "vert = "); strcat(stringOutput, anchorValue); }
       }
-      
+
       tempString[0] = '\0';
       anchorValue = bottom.OnGetString(tempString, null, &subNeedClass);
       if(anchorValue[0]) { if(stringOutput[0]) strcat(stringOutput, ", "); strcat(stringOutput, "bottom = "); strcat(stringOutput, anchorValue); }
-      
+
       return stringOutput;
    }
 
-   bool OnGetDataFromString(char * string)
+   bool OnGetDataFromString(const char * string)
    {
       this = Anchor {};
       return class::OnGetDataFromString(string);
@@ -219,7 +231,7 @@ public struct Anchor
 
    Window OnEdit(Window listBox, Window master, int x, int y, int w, int h, Window control)
    {
-      char * string = "";
+      const char * string = "";
       AnchorDropBox comboBox
       {
          editText = true;
@@ -233,13 +245,13 @@ public struct Anchor
          control = control;
          borderStyle = 0;
       };
-      
+
       comboBox.Create();
 
       {
          char tempString[MAX_F_STRING] = "";
          bool needClass = false;
-         char * result = OnGetString(tempString, null, &needClass);
+         const char * result = OnGetString(tempString, null, &needClass);
          if(result) string = result;
       }
       comboBox.contents = string;
@@ -280,7 +292,7 @@ private class AnchorButton : Button
       Anchor anchor = anchorDropBox.anchorValue;
       Window control = anchorDropBox.control;
       DataBox dropMaster = (DataBox)anchorDropBox.master;
-      int id = button.id;
+      int64 id = button.id;
 
       switch(id)
       {
@@ -357,7 +369,7 @@ private class AnchorButton : Button
       {
          char tempString[1024] = "";
          bool needClass = false;
-         char * string = anchor.OnGetString(tempString, null, &needClass);
+         const char * string = anchor.OnGetString(tempString, null, &needClass);
          anchorDropBox.contents = string;
       }
 
@@ -378,7 +390,7 @@ private class AnchorRelButton : Button
    {
       int cw = clientSize.w;
       int ch = clientSize.h;
-      
+
       if(checked)
       {
          surface.SetForeground(black);
@@ -402,7 +414,7 @@ private class AnchorRelButton : Button
       Anchor anchor = anchorDropBox.anchorValue;
       Window control = anchorDropBox.control;
       DataBox dropMaster = (DataBox)anchorDropBox.master;
-      int id = button.id;
+      int64 id = button.id;
 
       if((id == 0 || id == 2) && ((!anchor.left.type && !anchor.right.type) || anchor.left.type == middleRelative))
       {
@@ -469,7 +481,7 @@ private class AnchorRelButton : Button
             //anchor.horz.type = anchor.horz.distance ? offset : none;
          }
          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 : none;
@@ -480,7 +492,7 @@ private class AnchorRelButton : Button
       {
          char tempString[1024] = "";
          bool needClass = false;
-         char * string = anchor.OnGetString(tempString, null, &needClass);
+         const char * string = anchor.OnGetString(tempString, null, &needClass);
          anchorDropBox.contents = string;
       }
 
@@ -527,8 +539,8 @@ private class AnchorDropBox : DropBox
       };
       for(c = 0; c<4; c++)
       {
-         Button button = buttons[c] = AnchorButton 
-         { 
+         Button button = buttons[c] = AnchorButton
+         {
             anchorEditor, id = c,
             size = Size { (c%2)?10:28, (c%2)?28:10 }
          };
@@ -542,7 +554,7 @@ private class AnchorDropBox : DropBox
             case 0:
                if(anchorValue.left.type && anchorValue.left.type != middleRelative) button.checked = true;
                if(anchorValue.left.type == relative || anchorValue.horz.type == middleRelative) relButton.checked = true;
-               
+
                button.anchor = Anchor { left = 0 };
                relButton.anchor = Anchor { left = 5, vert = 16 };
                break;
@@ -553,14 +565,14 @@ private class AnchorDropBox : DropBox
                button.anchor = Anchor { top = 0 };
                relButton.anchor = Anchor { top = 5, horz = 16 };
                break;
-            case 2: 
+            case 2:
                if(anchorValue.right.type && anchorValue.right.type != middleRelative) button.checked = true;
                if(anchorValue.right.type == relative || anchorValue.horz.type == middleRelative) relButton.checked = true;
-               
+
                button.anchor = Anchor { right = 0 };
                relButton.anchor = Anchor { right = 5, vert = 16 };
                break;
-            case 3: 
+            case 3:
                if(anchorValue.bottom.type && anchorValue.bottom.type != middleRelative) button.checked = true;
                if(anchorValue.bottom.type == relative || anchorValue.vert.type == middleRelative) relButton.checked = true;
 
@@ -572,7 +584,7 @@ private class AnchorDropBox : DropBox
       anchorEditor.Create();
       return anchorEditor;
    }
-      
+
    void OnCloseDropDown(Window anchorEditor)
    {
       // TOFIX: Patch for update bug
@@ -580,10 +592,9 @@ private class AnchorDropBox : DropBox
       anchorEditor.Destroy(0);
    }
 
-   bool DataBox::NotifyTextEntry(AnchorDropBox dropBox, char * string, bool save)
+   bool DataBox::NotifyTextEntry(AnchorDropBox dropBox, const char * string, bool save)
    {
       Anchor anchor = dropBox.anchorValue;
-      Window control = dropBox.control;
 
       if(save)
       {
@@ -597,7 +608,7 @@ private class AnchorDropBox : DropBox
       {
          char tempString[1024] = "";
          bool needClass = false;
-         char * string = anchor.OnGetString(tempString, null, &needClass);
+         const char * string = anchor.OnGetString(tempString, null, &needClass);
          dropBox.contents = string;
       }
       return true;