eda: Using 'Id' rather than uint or uint64
[sdk] / eda / libeda / src / gui.ec
index 9bc58c2..04a9216 100644 (file)
@@ -8,12 +8,12 @@ extern int __ecereVMethodID_class_OnFree;
 extern int __ecereVMethodID_class_OnGetString;
 private:
 
-char * defaultNameField = "Name";
-char * defaultIdField = "Id";
-char * defaultActiveField = "Active";
+const char * defaultNameField = "Name";
+const char * defaultIdField = "Id";
+const char * defaultActiveField = "Active";
 
-public void SetDefaultIdField(char * value) { defaultIdField = value; }
-public void SetDefaultNameField(char * value) { defaultNameField = value; }
+public void SetDefaultIdField(const char * value) { defaultIdField = value; }
+public void SetDefaultNameField(const char * value) { defaultNameField = value; }
 
 public class ButtonStyle : Button
 {
@@ -57,7 +57,7 @@ public class CheckBool : bool
 {
    Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
    {
-      Button button = dataBox.keepEditor ? (Button)obsolete : null;
+      Button button = dataBox.keepEditor ? (Button)dataBox.editor : null;
       if(!button)
       {
          button = Button
@@ -69,7 +69,10 @@ public class CheckBool : bool
             bool DataBox::NotifyClicked(Button control, int x, int y, Modifiers mods)
             {
                bool checked = control.checked;
-               SetData(&checked, false);
+               if(readOnly)
+                  control.checked = !checked;
+               else
+                  SetData(&checked, false);
                return true;
             }
          };
@@ -89,13 +92,16 @@ String GetNameString(Row r, Field nameField)
       Class type = nameField.type;
       int64 data = 0;
       if(type.type == structClass)
-         data = (int64)new0 byte[type.structSize];
-      ((bool (*)())(void *)r.GetData)(r, nameField, type, (type.type == structClass) ? (void *)data : &data);
-      s = CopyString(((char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, (void *)data, tempString, null, null));
-      ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)data);
+         data = (int64)(intptr)new0 byte[type.structSize];
+      ((bool (*)())(void *)r.GetData)(r, nameField, type, (type.type == structClass) ? (void *)(intptr)data : &data);
+      if(type.type == systemClass || type.type == enumClass || type.type == bitClass)
+         s = CopyString(((char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &data, tempString, null, null));
+      else
+         s = CopyString(((char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, (void *)(intptr)data, tempString, null, null));
+      ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)(intptr)data);
       if(type.type == structClass)
       {
-         void * _data = (void *)data;
+         void * _data = (void *)(intptr)data;
          delete _data;
       }
    }
@@ -110,14 +116,14 @@ public class TableDropBox : DropBox
    borderStyle = deep;
 
 public:
-   uint filter;
+   Id filter;
    bool filtered;
    Field nameField;
-   uint exclusion;
+   Id exclusion;
    Table table;
    Field filterField;
 
-   property uint filter
+   property Id filter
    {
       set
       {
@@ -127,7 +133,7 @@ public:
       get { return filter; }
    }
    property Field nameField { set { nameField = value; } }
-   property uint exclusion { set { exclusion = value; } }
+   property Id exclusion { set { exclusion = value; } }
    property Table table { set { table = value; if(!nameField && value) nameField = value.FindField(defaultNameField); } }
 
    virtual void Refill()
@@ -145,7 +151,7 @@ public:
                {
                   FieldIndex indexedFields[1];
                   // Table tbl = table.db.OpenTable(table.name, { tableRows });
-                  char * name = table.name;
+                  const char * name = table.name;
                   Database db = table.db;
                   Table tbl = db.OpenTable(name, { tableRows });
                   if(tbl)
@@ -259,7 +265,7 @@ public:
    void EditNotifyUpdate(EditBox editBox)
    {
       DataRow row;
-      char * contents = editBox.contents;
+      const char * contents = editBox.contents;
       int len = strlen(contents);
       if(len && editBox.charPos == len)
       {
@@ -271,7 +277,7 @@ public:
          {
             for(row = firstRow; row; row = row.next)
             {
-               char * string = row.string;
+               const char * string = row.string;
                if(string && SearchString(string, 0, contents, false, false) == string)
                {
                   // SelectRow(row);
@@ -295,9 +301,9 @@ public class DropDataBox : DataBox
 
 public:
 
-   property uint filter { set { filtered = true; filter = value; } get { return filter; } }
+   property Id filter { set { filtered = true; filter = value; } get { return filter; } }
    property bool filtered { set { filtered = value; } }
-   property uint exclusion { set { exclusion = value; } }
+   property Id exclusion { set { exclusion = value; } }
    property Field filterField { set { filterField = value; } }
    property Field nameField { set { nameField = value; } }
    virtual void TableDropBox::RefillFunction();
@@ -308,7 +314,7 @@ public:
       if(editor)
       {
          TableDropBox dropBox = (TableDropBox) editor;
-         uint id = data ? *(uint *)data : MAXDWORD;
+         Id id = data ? *(Id *)data : MAXDWORD;
          void * notifyChanged = (void *)NotifyChanged;
 
          OnConfigure(dropBox);
@@ -338,8 +344,8 @@ public:
 private:
    Field nameField;
    Field filterField;
-   uint exclusion;
-   uint filter;
+   Id exclusion;
+   Id filter;
    bool filtered;
    bool showNone;
 }
@@ -360,6 +366,9 @@ public class FieldDataBox : DataBox
    anchor = { left = 110, right = shadowS + sgs * 2 };
    borderStyle = deep;
 
+   // TOCHECK: Testing this for GenericEditor performance issue?
+   keepEditor = true;
+
 public:
    property Row row
    {
@@ -386,10 +395,10 @@ public:
 
          if(dataHolder)
          {
-            ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)dataHolder);
+            ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)(intptr)dataHolder);
             if(type.type == structClass)
             {
-               void * dataPtr = (void *)dataHolder;
+               void * dataPtr = (void *)(intptr)dataHolder;
                delete dataPtr;
             }
             dataHolder = 0;
@@ -402,15 +411,15 @@ public:
 
          if(dataType && dataType.type == structClass)
          {
-            dataHolder = (int64)new0 byte[dataType.structSize];
-            data = (void *)dataHolder;
+            dataHolder = (int64)(intptr)new0 byte[dataType.structSize];
+            data = (void *)(intptr)dataHolder;
          }
          else if(dataType && (dataType.type == noHeadClass || dataType.type == normalClass))
          {
             if(eClass_IsDerived(dataType, class(String)))
-               dataHolder = (int64)CopyString("");
+               dataHolder = (int64)(intptr)CopyString("");
             else
-               dataHolder = (int64)eInstance_New(dataType);
+               dataHolder = (int64)(intptr)eInstance_New(dataType);
             data = (void *)&dataHolder;
          }
          else
@@ -424,28 +433,25 @@ public:
 
    void Clear()
    {
-      if(visible)
-      {
-         if(data)
-            SetData(null, false);
-
-         if(type && (type.type == noHeadClass || type.type == normalClass))
-         {
-            if(eClass_IsDerived(type, class(String)))
-               dataHolder = (int64)CopyString("");
-            else
-               dataHolder = (int64)eInstance_New(type);
-            data = (void *)&dataHolder;
-         }
+      if(data)
+         SetData(null, false);
 
-         if(created)
-            Refresh();
+      if(type && (type.type == noHeadClass || type.type == normalClass))
+      {
+         if(eClass_IsDerived(type, class(String)))
+            dataHolder = (int64)(intptr)CopyString("");
+         else
+            dataHolder = (int64)(intptr)eInstance_New(type);
+         data = (void *)&dataHolder;
       }
+
+      if(created)
+         Refresh();
    }
 
    void Load()
    {
-      if(visible && field && row)
+      if(field && row)
       {
          SetData(null, false);
          master.modifiedDocument = false;
@@ -455,9 +461,9 @@ public:
          if(!dataHolder && type && (type.type == noHeadClass || type.type == normalClass))
          {
             if(eClass_IsDerived(type, class(String)))
-               dataHolder = (int64)CopyString("");
+               dataHolder = (int64)(intptr)CopyString("");
             else
-               dataHolder = (int64)eInstance_New(type);
+               dataHolder = (int64)(intptr)eInstance_New(type);
             data = (void *)&dataHolder;
          }
 
@@ -468,8 +474,7 @@ public:
 
    virtual void Save()
    {
-      bool result;
-      if(visible && field && row)
+      if(field && row)
       {
          Class type = field.type;
          if(!DataBox::SaveData())
@@ -482,7 +487,7 @@ public:
 
    void Init()
    {
-      if(visible && created)
+      if(created)
          Refresh();
    }
 
@@ -534,10 +539,10 @@ public:
 
       if(dataHolder)
       {
-         ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)dataHolder);
+         ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)(intptr)dataHolder);
          if(type.type == structClass)
          {
-            void * dataPtr = (void *)dataHolder;
+            void * dataPtr = (void *)(intptr)dataHolder;
             delete dataPtr;
          }
          dataHolder = 0;
@@ -565,9 +570,9 @@ public class FieldDropDataBox : FieldDataBox
    showNone = true;
 
 public:
-   property uint filter { set { filtered = true; filter = value; } get { return filter; } }
+   property Id filter { set { filtered = true; filter = value; } get { return filter; } }
    property bool filtered { set { filtered = value; } }
-   property uint exclusion { set { exclusion = value; } }
+   property Id exclusion { set { exclusion = value; } }
    property Field filterField { set { filterField = value; } }
    property Field nameField { set { nameField = value; } }
    virtual void TableDropBox::RefillFunction();
@@ -578,7 +583,7 @@ public:
       if(editor)
       {
          TableDropBox dropBox = (TableDropBox) editor;
-         uint id = data ? *(uint *)data : MAXDWORD;
+         Id id = data ? *(Id *)data : MAXDWORD;
          OnConfigure(dropBox);
          dropBox.Refill();
          if(id != MAXDWORD) dropBox.SelectRow(dropBox.FindSubRow(id));
@@ -601,8 +606,8 @@ public:
 private:
    Field nameField;
    Field filterField;
-   uint exclusion;
-   uint filter;
+   Id exclusion;
+   Id filter;
    bool filtered;
    bool showNone;
 }
@@ -636,7 +641,7 @@ public:
       FieldDataBox::Save();
    }
 
-   virtual bool OnAddTextEntry(Row row, TableDropBox dropBox, char * entry)
+   virtual bool OnAddTextEntry(Row row, TableDropBox dropBox, const char * entry)
    {
       row.Add();
       row.SetData(dropBox.nameField, entry);
@@ -726,7 +731,8 @@ public:
    {
       if(listSection.fldId && listSection.fldName)
       {
-         bool stringName = !strcmp(listSection.fldName.type.dataTypeString, "char *");
+         Class type = listSection.fldName.type;
+         bool stringName = !strcmp(type.dataTypeString, "char *");
          while(r.Next())
          {
             Id id = 0;
@@ -735,7 +741,10 @@ public:
             if(stringName)
                r.GetData(listSection.fldName, s);
             else
-               s = PrintString("Entry ", id);
+            {
+               s = GetNameString(r, listSection.fldName);
+               // s = PrintString("Entry ", id);
+            }
             listSection.list.AddString(s).tag = id;
             delete s;
          }
@@ -753,7 +762,7 @@ public:
          list.NotifySelect(this, list, null, 0);
          if(!editor.modifiedDocument)
          {
-            uint id; // = table.rowsCount + 1; // this is bad with deleted rows, won't work, how to have unique id?
+            Id id; // = table.rowsCount + 1; // this is bad with deleted rows, won't work, how to have unique id?
             Row r { table };
 
             if(r.Last())   // this will reuse ids in cases where the item(s) with the last id have been deleted
@@ -853,7 +862,6 @@ public:
          bool result = true;
          if(/*row && */row != lastRow)
          {
-            uint id;
             if(editor.modifiedDocument)
             {
                if(row)
@@ -877,14 +885,14 @@ public:
       }
    };
 
-   virtual void Window::NotifySelectListRow(ListSection listSection, uint64 id);
+   virtual void Window::NotifySelectListRow(ListSection listSection, Id id);
 
    void SelectListRow(DataRow row)
    {
       // Time startTime = GetTime();
       if(row)
       {
-         uint64 id = row.tag;
+         Id id = row.tag;
          lastRow = row;
 
          if(list.currentRow != row)
@@ -910,10 +918,10 @@ public:
    {
       if(editor)
       {
-         editor.btnSave.disabled = !(bool)list.currentRow;
-         editor.btnReload.disabled = !(bool)list.currentRow;
-         btnDelete.disabled = !(bool)list.currentRow;
-         editor.disabled = !(bool)list.firstRow;
+         editor.btnSave.disabled = !list.currentRow;
+         editor.btnReload.disabled = !list.currentRow;
+         btnDelete.disabled = !list.currentRow;
+         editor.disabled = !list.firstRow;
       }
    }