eda: Fixes for cross-bit compiling; ecere: Took out non-sense code no longer needed
[sdk] / eda / libeda / src / idList.ec
index 1b08aeb..80fccb5 100644 (file)
@@ -41,130 +41,128 @@ public class Id : uint
 
    Window OnEdit(DataBox dataBox, void * obsolete, int x, int y, int w, int h, void * userData)
    {
-      if(this || !this) {     // FIXME
-         TableDropBox dropBox = dataBox.keepEditor ? (TableDropBox)dataBox.editor /*obsolete*/ : null;
-         if(!dropBox)
-         {
+      TableDropBox dropBox = dataBox.keepEditor ? (TableDropBox)dataBox.editor /*obsolete*/ : null;
+      if(!dropBox)
+      {
 /*
-            if(eClass_IsDerived(dataBox._class, class(FieldDropBox)))
-            {
-               FieldDropBox fieldDropBox = (FieldDropBox)dataBox;
+         if(eClass_IsDerived(dataBox._class, class(FieldDropBox)))
+         {
+            FieldDropBox fieldDropBox = (FieldDropBox)dataBox;
 
-            }
-            else if(eClass_IsDerived(dataBox._class, class(FieldBox)))
-            {
-               FieldBox fieldBox = (FieldBox)dataBox;
+         }
+         else if(eClass_IsDerived(dataBox._class, class(FieldBox)))
+         {
+            FieldBox fieldBox = (FieldBox)dataBox;
 
-            }
+         }
 */
 
-            dropBox = TableDropBox
-            {
-               dataBox, borderStyle = 0, anchor = { 0, 0, 0, 0 }, 
-               modifyVirtualArea = false, activeStipple = false;
-               showNone = true;
-               nameField = *class_data(nameField);
-               table = *class_data(table);
+         dropBox = TableDropBox
+         {
+            dataBox, borderStyle = 0, anchor = { 0, 0, 0, 0 }, 
+            modifyVirtualArea = false, activeStipple = false;
+            showNone = true;
+            nameField = *class_data(nameField);
+            table = *class_data(table);
 
-               bool DataBox::NotifySelect(DropBox control, DataRow row, Modifiers mods)
-               {
-                  uint id = row ? row.tag : 0;
-                  SetData(&id, mods.closingDropDown);
-                  return true;
-               }
+            bool DataBox::NotifySelect(DropBox control, DataRow row, Modifiers mods)
+            {
+               // TOFIX: Id is still 32 bit
+               uint id = (uint)(row ? row.tag : 0);
+               SetData(&id, mods.closingDropDown);
+               return true;
+            }
 
-               bool DataBox::NotifyTextEntry(DropBox _dropBox, char * string, bool confirmed)
+            bool DataBox::NotifyTextEntry(DropBox _dropBox, char * string, bool confirmed)
+            {
+               TableDropBox dropBox = (TableDropBox)_dropBox;
+               //Table tbl = dropBox.table.db.OpenTable(dropBox.table.name, { tableRows });
+               //if(tbl)
                {
-                  TableDropBox dropBox = (TableDropBox)_dropBox;
-                  //Table tbl = dropBox.table.db.OpenTable(dropBox.table.name, { tableRows });
-                  //if(tbl)
+                  /*FieldIndex indexedFields[1];
+                  Row r { };*/
+                  char * trimmed = new char[strlen(string) + 1];
+                  /*indexedFields[0] = { dropBox.nameField };
+                  tbl.GenerateIndex(1, indexedFields, false);
+                  r.tbl = tbl;*/
+                  DataRow row = null;
+
+                  TrimLSpaces(string, trimmed);
+                  TrimRSpaces(trimmed, trimmed);
+
+                  /*if(r.Find(dropBox.nameField, middle, nil, trimmed))
                   {
-                     /*FieldIndex indexedFields[1];
-                     Row r { };*/
-                     char * trimmed = new char[strlen(string) + 1];
-                     /*indexedFields[0] = { dropBox.nameField };
-                     tbl.GenerateIndex(1, indexedFields, false);
-                     r.tbl = tbl;*/
-                     DataRow row = null;
-
-                     TrimLSpaces(string, trimmed);
-                     TrimRSpaces(trimmed, trimmed);
-
-                     /*if(r.Find(dropBox.nameField, middle, nil, trimmed))
+                     if(dropBox.filterField)
                      {
-                        if(dropBox.filterField)
-                        {
-                           // TODO: Improve this... Multi field?
-                           while(true)
-                           {
-                              DataRow row;
-                              Id id = 0;
-                              Field fldId = dropBox.table.FindField(defaultIdField);
-                              r.GetData(fldId, id);
-                              row = dropBox.FindSubRow(id);
-                              if(row)
-                              {
-                                 dropBox.SelectRow(row);
-                                 break;
-                              }
-                              //if(!r.Find(dropBox.nameField, next, nil, trimmed))
-                              if(!r.Next())
-                                 break;
-                           }
-                        }
-                        else
+                        // TODO: Improve this... Multi field?
+                        while(true)
                         {
+                           DataRow row;
                            Id id = 0;
                            Field fldId = dropBox.table.FindField(defaultIdField);
                            r.GetData(fldId, id);
-                           dropBox.SelectRow(dropBox.FindSubRow(id));
-                        }
-                     }
-                     */
-
-                     {
-                        for(row = dropBox.firstRow; row; row = row.next)
-                        {
-                           char * string = row.string;
-                           if(string && !strcmp(trimmed, string))
+                           row = dropBox.FindSubRow(id);
+                           if(row)
+                           {
+                              dropBox.SelectRow(row);
+                              break;
+                           }
+                           //if(!r.Find(dropBox.nameField, next, nil, trimmed))
+                           if(!r.Next())
                               break;
                         }
                      }
-                     if(row)
+                     else
                      {
-                        dropBox.SelectRow(row);
+                        Id id = 0;
+                        Field fldId = dropBox.table.FindField(defaultIdField);
+                        r.GetData(fldId, id);
+                        dropBox.SelectRow(dropBox.FindSubRow(id));
                      }
-                     else
+                  }
+                  */
+
+                  {
+                     for(row = dropBox.firstRow; row; row = row.next)
                      {
-                        dropBox.changeContents = false;
-                        dropBox.contents = trimmed;
-                        dropBox.SelectRow(null);
-                        dropBox.changeContents = true;
+                        char * string = row.string;
+                        if(string && !strcmp(trimmed, string))
+                           break;
                      }
-                     //delete r;
                   }
-                  return true;
+                  if(row)
+                  {
+                     dropBox.SelectRow(row);
+                  }
+                  else
+                  {
+                     dropBox.changeContents = false;
+                     dropBox.contents = trimmed;
+                     dropBox.SelectRow(null);
+                     dropBox.changeContents = true;
+                  }
+                  //delete r;
                }
-            };
-            if(class_data(Refill))
-               dropBox.Refill = class_data(Refill);
+               return true;
+            }
+         };
+         if(class_data(Refill))
+            dropBox.Refill = class_data(Refill);
 
-            // dropBox.Refill();
-         }
-         dataBox.OnConfigure(dropBox);
-         dropBox.Create();
-         dropBox.currentRow = dropBox.FindSubRow(this);
-         if(!dropBox.currentRow && this)
-            dataBox.SetData((uint *)&this, false);
-         {
-            DataRow r = dropBox.currentRow;
-            if(r)
-               for(r = r.parent; r; r = r.parent)
-                  r.collapsed = false;
-         }
-         return dropBox;
+         // dropBox.Refill();
+      }
+      dataBox.OnConfigure(dropBox);
+      dropBox.Create();
+      dropBox.currentRow = dropBox.FindSubRow(this);
+      if(!dropBox.currentRow && this)
+         dataBox.SetData((uint *)&this, false);
+      {
+         DataRow r = dropBox.currentRow;
+         if(r)
+            for(r = r.parent; r; r = r.parent)
+               r.collapsed = false;
       }
-      return null;
+      return dropBox;
    }
 
    char * OnGetString(char * tempString, void * fieldData, bool * needClass)
@@ -174,7 +172,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 +187,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;
    }
@@ -231,7 +246,7 @@ public:
       get { return class_data(type); }
    };
 
-   public void Clear()
+   void Clear()
    {
       if(this)
       {
@@ -240,7 +255,7 @@ public:
       }
    }
    
-   public bool Includes(Id id)
+   bool Includes(Id id)
    {
       if(this)
       {
@@ -252,7 +267,7 @@ public:
       return false;
    }
 
-   public bool Add(Id id)
+   bool Add(Id id)
    {
       int c;
       for(c = 0; c < count; c++)
@@ -267,7 +282,7 @@ public:
       return false;
    }
 
-   public bool Delete(Id id)
+   bool Delete(Id id)
    {
       int c;
       for(c = 0; c < count; c++)
@@ -320,11 +335,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 +352,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 +376,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
       {
@@ -412,7 +432,6 @@ public:
       /*if(!this)
          this = eInstance_New(_class);
          */
-      if(this || !this)    // FIXME
       {
          Class type = class_data(type);
          list.AddField({ type, editable = true });
@@ -480,7 +499,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
@@ -625,10 +644,7 @@ public class StringList
       }
       */
 
-      if(this || !this)    // FIXME
-      {
       list.AddField({ class(char *), editable = true });
-      }
       for(node = strings.first; node; node = node.next)
       {
          r = list.AddRow();
@@ -844,7 +860,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);
       }
@@ -865,9 +881,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
@@ -891,7 +907,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;
@@ -1146,7 +1162,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);
       }