ide/Designer/Sheet: (#676) Multi-line editing of EditBox contents in property sheet
authorJerome St-Louis <jerome@ecere.com>
Wed, 26 Mar 2014 18:00:15 +0000 (14:00 -0400)
committerJerome St-Louis <jerome@ecere.com>
Wed, 26 Mar 2014 18:02:01 +0000 (14:02 -0400)
- Moved MultiLineString class from EDA to Ecere

ecere/src/gui/typeEdit.ec
eda/libeda/src/idList.ec
ide/src/designer/Sheet.ec

index e91a0c8..eae1d9c 100644 (file)
@@ -224,6 +224,77 @@ static Window OnEdit(Class _class, void * data, Window window, Window master,
 
 }
 
+public class MultiLineString : String
+{
+   Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
+   {
+      // Don't show the editbox right away so that the text is highlighted by default
+      char * string = "";
+      EditBox editBox
+      {
+         dataBox, visible = false,
+         borderStyle = 0,
+         hasHorzScroll = true, hasVertScroll = true,
+         modifyVirtualArea = false,
+         autoSize = dataBox.autoSize;
+         anchor = { 0, 0, 0, 0 };
+         multiLine = true;
+
+         void DataBox::NotifyUpdate(EditBox editBox)
+         {
+            Modified();
+            modifiedDocument = true;
+         }
+
+         bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
+         {
+            opacity = active ? 1.0f : parent.opacity;
+            return true;
+         }
+      };
+      editBox.contents = this;
+      editBox.visible = true;
+
+      editBox.Create();
+      if(!dataBox.active)
+         editBox.contents = this;
+      return editBox;
+   }
+
+   bool OnSaveEdit(Window window, void * object)
+   {
+      bool changed = false;
+      EditBox editBox = (EditBox)window;
+      if(editBox.modifiedDocument)
+      {
+         EditLine line;
+         int size = 0;
+         char * string;
+
+         delete this;
+
+         for(line = editBox.firstLine; line; line = line.next)
+            size += line.count+1;
+         this = string = new char[size+1];
+         size = 0;
+         for(line = editBox.firstLine; line; line = line.next)
+         {
+            memcpy(string + size, line.text, line.count);
+            size += line.count;
+            if(line.next)
+            {
+               string[size] = '\n';
+               size++;
+            }
+         }
+         string[size] = '\0';
+
+         changed = true;
+      }
+      return changed;
+   }
+};
+
 __on_register_module()
 {
    Class baseClass = eSystem_FindClass(module, "class");
index 8845b90..00d0633 100644 (file)
@@ -768,77 +768,6 @@ public class CIString : String
 
 }
 
-public class MultiLineString : String
-{
-   Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
-   {
-      // Don't show the editbox right away so that the text is highlighted by default
-      char * string = "";
-      EditBox editBox
-      {
-         dataBox, visible = false,
-         borderStyle = 0,
-         hasHorzScroll = true, hasVertScroll = true,
-         modifyVirtualArea = false,
-         autoSize = dataBox.autoSize;
-         anchor = { 0, 0, 0, 0 };
-         multiLine = true;
-
-         void DataBox::NotifyUpdate(EditBox editBox)
-         {
-            Modified();
-            modifiedDocument = true;
-         }
-
-         bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
-         {
-            opacity = active ? 1.0f : parent.opacity;
-            return true;
-         }
-      };
-      editBox.contents = this;
-      editBox.visible = true;
-
-      editBox.Create();
-      if(!dataBox.active)
-         editBox.contents = this;
-      return editBox;
-   }
-
-   bool OnSaveEdit(Window window, void * object)
-   {
-      bool changed = false;
-      EditBox editBox = (EditBox)window;
-      if(editBox.modifiedDocument)
-      {
-         EditLine line;
-         int size = 0;
-         char * string;
-
-         delete this;
-
-         for(line = editBox.firstLine; line; line = line.next)
-            size += line.count+1;
-         this = string = new char[size+1];
-         size = 0;
-         for(line = editBox.firstLine; line; line = line.next)
-         {
-            memcpy(string + size, line.text, line.count);
-            size += line.count;
-            if(line.next)
-            {
-               string[size] = '\n';
-               size++;
-            }
-         }
-         string[size] = '\0';
-
-         changed = true;
-      }
-      return changed;
-   }
-};
-
 public struct DataList : OldList
 {
    class_data Class type;
index a022f51..cf8492d 100644 (file)
@@ -1557,6 +1557,7 @@ public:
             void * dataPtr, * data = null, * subData = null;
             DataValue valueData, valueSubData;
             uint64 bitValue;
+            bool isEditBoxMultiLineContents = false;
 
             // Get main prop
             if(dataType.type == structClass)
@@ -1567,7 +1568,19 @@ public:
             }
             else
             {
-               GetProperty(prop, object, &valueData);
+               bool freeDataForm = false, freeDataTest = false;
+               // Because contents property is broken for mutiline EditBox at the moment
+               if(!strcmp(prop.name, "contents") && !strcmp(prop._class.name, "EditBox") && ((EditBox)object).multiLine)
+               {
+                  isEditBoxMultiLineContents = true;
+                  dataType = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, "MultiLineString");
+                  valueData.p = ((EditBox)object).multiLineContents;
+                  dataBox.size.h = 3*(h-2);
+                  h = dataBox.clientSize.h;
+               }
+               else
+                  GetProperty(prop, object, &valueData);
+
                if(dataType.type == normalClass)
                   dataPtr = valueData.p;
                else
@@ -1627,6 +1640,9 @@ public:
             delete data;
             delete subData;
 
+            if(isEditBoxMultiLineContents)
+               delete valueData.p;
+
             editData.font = { font.faceName, font.size, font.bold };
             if(eClass_IsDerived(editData._class, class(DropBox)))
             {
@@ -1727,6 +1743,10 @@ public:
             mainDataType = prop.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, prop.dataTypeString);
          dataType = mainDataType;
 
+         // Because contents property is broken for mutiline EditBox at the moment
+         if(!strcmp(prop.name, "contents") && !strcmp(prop._class.name, "EditBox") && ((EditBox)object).multiLine)
+            dataType = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, "MultiLineString");
+
          // Prepare main prop
          if(dataType.type == structClass)
          {