eda, compiler, documentor: Proper prototypes for invoking virtual methods directly
[sdk] / eda / libeda / src / idList.ec
index 99fe17c..272fa33 100644 (file)
@@ -68,7 +68,8 @@ public class Id : uint
 
                bool DataBox::NotifySelect(DropBox control, DataRow row, Modifiers mods)
                {
-                  uint id = row ? row.tag : 0;
+                  // TOFIX: Id is still 32 bit
+                  uint id = (uint)(row ? row.tag : 0);
                   SetData(&id, mods.closingDropDown);
                   return true;
                }
@@ -174,7 +175,14 @@ public class Id : uint
          // FIXME
          Table tbl = *class_data(table);
          Field idField = tbl.FindField(defaultIdField);
-         Row r { tbl };
+         Row r;
+         idRowCacheMutex.Wait();
+         if(!tbl.cachedIdRow)
+         {
+            tbl.cachedIdRow = Row { tbl };
+            incref tbl.cachedIdRow;
+         }
+         r = tbl.cachedIdRow;
 
          if(this)
          {
@@ -182,38 +190,48 @@ public class Id : uint
             {
                String name = null;
                Field * nameField = class_data(nameField);
-               char * fn = nameField->name;
+               if(nameField)
+               {
+#ifdef _DEBUG
+                  char * fn = nameField->name;
+#endif
+                  // Get name data from row
+                  int64 data = 0;
+                  Class type = nameField->type;
+                  if(type.type == unitClass && !type.typeSize)
+                  {
+                     Class dataType = eSystem_FindClass(type.module, type.dataTypeString);
+                     if(dataType)
+                        type = dataType;
+                  }
+                  if(type.type == structClass)
+                     data = (int64)new0 byte[type.structSize];
+                  ((bool (*)())(void *)r.GetData)(r, *nameField, type, (type.type == structClass) ? (void *)data : &data);
 
-               // r.GetData(*nameField, name);
+                  if(type.type == systemClass || type.type == unitClass || type.type == bitClass || type.type == enumClass)
+                     name = ((char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, (void *)&data, tempString, null, null);
+                  else
+                     name = ((char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, (void *)data, tempString, null, null);
 
-               // Get name data from row
-               int64 data = 0;
-               Class type = nameField->type;
-               if(type.type == unitClass && !type.typeSize)
-               {
-                  Class dataType = eSystem_FindClass(type.module, type.dataTypeString);
-                  if(dataType)
-                     type = dataType;
+                  if(name && name != tempString)
+                     strcpy(tempString, name ? name : "");
+                  if(!(type.type == systemClass || type.type == unitClass || type.type == bitClass || type.type == enumClass))
+                     ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)data);
                }
-               if(type.type == structClass)
-                  data = (int64)new0 byte[type.structSize];
-               ((bool (*)())(void *)r.GetData)(r, *nameField, type, (type.type == structClass) ? (void *)data : &data);
-
-               if(type.type == systemClass || type.type == unitClass || type.type == bitClass || type.type == enumClass)
-                  name = (String)type._vTbl[__ecereVMethodID_class_OnGetString](type, (void *)&data, tempString, null, null);
                else
-                  name = (String)type._vTbl[__ecereVMethodID_class_OnGetString](type, (void *)data, tempString, null, null);
-
-               strcpy(tempString, name ? name : "");
-               if(!(type.type == systemClass || type.type == unitClass || type.type == bitClass || type.type == enumClass))
-                  type._vTbl[__ecereVMethodID_class_OnFree](type, data);
+               {
+                  PrintLn("Id::OnGetString -- data type"/*, this._class.name, */" has no class_data(nameField)");
+               }
             }
+            else
+               sprintf(tempString, "(Invalid %s entry: %d)", tbl.name, this);
          }
          else
          {
             sprintf(tempString, $"(Click to add a new %s...)", $"item"/*class_data(addText)*/);
          }
-         delete r;
+         // delete r;
+         idRowCacheMutex.Release();
       }
       return tempString;
    }
@@ -320,11 +338,12 @@ public:
          channel.Serialize(none);
       }
    }
-
+   /*
    void OnDisplay(Surface surface, int x, int y, int width, void * fieldData, Alignment alignment, DataDisplayFlags displayFlags)
    {
 
    }
+   */
    
    char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
    {
@@ -336,12 +355,13 @@ public:
          {
             char tempString[256];
             Class type = class_data(type);
+            String s;
             if(c) strcat(stringOutput, ", ");
 
             if(type)
-               type._vTbl[__ecereVMethodID_class_OnGetString](type, &ids[c], tempString, null, null);
+               s = ((char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &ids[c], tempString, null, null);
             // strcatf(stringOutput, "%d", ids[c]);
-            strcat(stringOutput, tempString);
+            strcat(stringOutput, s);
          }
       }
       return stringOutput;
@@ -359,7 +379,10 @@ public:
 
    int OnCompare(IdList b)
    {
-      if(count > b.count) return 1;
+      if(!this && !b) return 0;
+      else if(this && !b) return 1;
+      else if(!this && b) return -1;
+      else if(count > b.count) return 1;
       else if(count < b.count) return -1;
       else
       {
@@ -480,7 +503,7 @@ public class StringList
 
    bool Add(String string)
    {
-      BTNode node { key = (uint)CopyString(string) };
+      BTNode node { key = (uintptr)CopyString(string) };
       if(strings.Add(node))
          return true;
       else
@@ -756,6 +779,7 @@ public class MultiLineString : String
          borderStyle = 0,
          hasHorzScroll = true, hasVertScroll = true,
          modifyVirtualArea = false,
+         autoSize = dataBox.autoSize;
          anchor = { 0, 0, 0, 0 };
          multiLine = true;
 
@@ -764,6 +788,12 @@ public class MultiLineString : String
             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;
@@ -837,7 +867,7 @@ public struct DataList : OldList
          {
             if(type.type == structClass)
                link.data = new0 byte[type.structSize];
-            type._vTbl[__ecereVMethodID_class_OnUnserialize](type, (type.type == structClass) ? link.data : &link.data, channel);
+            ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnUnserialize])(type, (type.type == structClass) ? link.data : &link.data, channel);
          }
          Add(link);
       }
@@ -858,9 +888,9 @@ public struct DataList : OldList
          {
             channel.Serialize(truth);
             if(type.type == bitClass || type.type == unitClass || (type.type == systemClass && type.typeSize))
-               type._vTbl[__ecereVMethodID_class_OnSerialize](type, &node.data, channel);
+               ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnSerialize])(type, &node.data, channel);
             else
-               type._vTbl[__ecereVMethodID_class_OnSerialize](type, node.data, channel);
+               ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnSerialize])(type, node.data, channel);
             node = node.next;
          }
          else
@@ -884,7 +914,7 @@ public struct DataList : OldList
          else
          {
             Class type = class_data(type);
-            result = type._vTbl[__ecereVMethodID_class_OnCompare](type, 
+            result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, 
                (type.type == systemClass || type.type == bitClass || type.type == enumClass || type.type == unitClass) ? &nodeA.data : (void *)nodeA.data,
                (type.type == systemClass || type.type == bitClass || type.type == enumClass || type.type == unitClass) ? &nodeB.data : (void *)nodeB.data);
             if(result) return result;
@@ -1139,7 +1169,7 @@ public struct DataList : OldList
             else if(type.type == structClass)
                delete node.data;
             else
-               type._vTbl[__ecereVMethodID_class_OnFree](type, node.data);
+               ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, node.data);
          }
          Delete(node);
       }