eda:gui:FieldDataBox; remove bad check for control visible on Init/Load/Save.
[sdk] / eda / libeda / src / gui.ec
index dc6a7f3..e4486e6 100644 (file)
@@ -27,7 +27,8 @@ public class Group : Window
    tabCycle = true;
    //inactive = true; // TOFIX causes problems...
 
-   public Label title { this, font = { $"Arial", 10, bold = true }, position = { 16, 2 } };
+public:
+   Label title { this, font = { $"Arial", 10, bold = true }, position = { 16, 2 } };
 
    bool OnCreate()
    {
@@ -56,7 +57,6 @@ public class CheckBool : bool
 {
    Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
    {
-      if(this || !this) {     // FIXME
       Button button = dataBox.keepEditor ? (Button)obsolete : null;
       if(!button)
       {
@@ -64,12 +64,15 @@ public class CheckBool : bool
          {
             dataBox, borderStyle = 0, text = dataBox.text, anchor = { 0, 0, 0, 0 },
             // size = { 100, 22 };
-            modifyVirtualArea = false, isCheckbox = true;            
+            modifyVirtualArea = false, isCheckbox = true;
 
             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;
             }
          };
@@ -77,8 +80,6 @@ public class CheckBool : bool
       button.checked = this;
       button.Create();
       return button;
-      }
-      return null;
    }
 }
 
@@ -111,14 +112,15 @@ public class TableDropBox : DropBox
    anchor = { left = 130, top = 180, right = shadowS + sgs * 2 };
    borderStyle = deep;
 
-   public uint filter;
-   public bool filtered;
-   public Field nameField;
-   public uint exclusion;
-   public Table table;
-   public Field filterField;
+public:
+   uint filter;
+   bool filtered;
+   Field nameField;
+   uint exclusion;
+   Table table;
+   Field filterField;
 
-   public property uint filter
+   property uint filter
    {
       set
       {
@@ -127,11 +129,11 @@ public class TableDropBox : DropBox
       }
       get { return filter; }
    }
-   public property Field nameField { set { nameField = value; } }
-   public property uint exclusion { set { exclusion = value; } }
-   public property Table table { set { table = value; if(!nameField && value) nameField = value.FindField(defaultNameField); } }
+   property Field nameField { set { nameField = value; } }
+   property uint exclusion { set { exclusion = value; } }
+   property Table table { set { table = value; if(!nameField && value) nameField = value.FindField(defaultNameField); } }
 
-   public virtual void Refill()
+   virtual void Refill()
    {
       Clear();
       if(table)
@@ -157,7 +159,7 @@ public class TableDropBox : DropBox
                      tbl.GenerateIndex(1, indexedFields, false);
 
                      r = Row { tbl };
-                     
+
                      for(r.Find(filterField, middle, nil, filter); !r.nil; r.Next()) //while(r.Next())
                      {
                         Id id;
@@ -224,7 +226,7 @@ public class TableDropBox : DropBox
       Sort(null, 1);
    }
 
-   public property Field filterField { set { filterField = value; } }
+   property Field filterField { set { filterField = value; } }
 
    bool OnKeyHit(Key key, unichar ch)
    {
@@ -235,7 +237,7 @@ public class TableDropBox : DropBox
       }
       else if((SmartKey)key == enter)
          parent.CycleChildren(true, false, false, true);
-      
+
       return DropBox::OnKeyHit(key, ch);
    }
 
@@ -251,13 +253,13 @@ public class TableDropBox : DropBox
       return true;
    }
 
-   public void EditNotifyCharsAdded()
+   void EditNotifyCharsAdded()
    {
       if(!editBox.NotifyUpdate || editBox.NotifyUpdate == EditBox::NotifyUpdate)
          editBox.NotifyUpdate = EditNotifyUpdate;
    }
 
-   public void EditNotifyUpdate(EditBox editBox)
+   void EditNotifyUpdate(EditBox editBox)
    {
       DataRow row;
       char * contents = editBox.contents;
@@ -292,24 +294,19 @@ public class DropDataBox : DataBox
    size.h = 24;
    keepEditor = true;
    borderStyle = deep;
-
-   Field nameField;
-   Field filterField;
-   uint exclusion;
-   uint filter;
-   bool filtered;
-   bool showNone;
    showNone = false; //true;
 
-   public property uint filter { set { filtered = true; filter = value; } get { return filter; } }
-   public property bool filtered { set { filtered = value; } }
-   public property uint exclusion { set { exclusion = value; } }
-   public property Field filterField { set { filterField = value; } }
-   public property Field nameField { set { nameField = value; } }
-   public virtual void TableDropBox::RefillFunction();
-   public property bool showNone { set { showNone = value; } }
+public:
+
+   property uint filter { set { filtered = true; filter = value; } get { return filter; } }
+   property bool filtered { set { filtered = value; } }
+   property uint exclusion { set { exclusion = value; } }
+   property Field filterField { set { filterField = value; } }
+   property Field nameField { set { nameField = value; } }
+   virtual void TableDropBox::RefillFunction();
+   property bool showNone { set { showNone = value; } }
 
-   public void Refill()
+   void Refill()
    {
       if(editor)
       {
@@ -336,10 +333,18 @@ public class DropDataBox : DataBox
          dropBox.filter = filter;
       else
          dropBox.filtered = false;
-      
+
       dropBox.exclusion = exclusion;
       dropBox.showNone = showNone;
    }
+
+private:
+   Field nameField;
+   Field filterField;
+   uint exclusion;
+   uint filter;
+   bool filtered;
+   bool showNone;
 }
 
 public class EditDropDataBox : DropDataBox
@@ -358,16 +363,13 @@ public class FieldDataBox : DataBox
    anchor = { left = 110, right = shadowS + sgs * 2 };
    borderStyle = deep;
 
-   Field field;
-   int64 dataHolder; // THERE SEEMS TO BE A BUG WHEN ACCESSING row ACROSS .so
-   Row row;
-
-   public property Row row
+public:
+   property Row row
    {
       set { row = value; }
       get { return row; }
    }
-   public property EditSection editor
+   property EditSection editor
    {
       set
       {
@@ -378,7 +380,7 @@ public class FieldDataBox : DataBox
       }
    };
 
-   public property Field field
+   property Field field
    {
       set
       {
@@ -423,30 +425,27 @@ public class FieldDataBox : DataBox
       }
    }
 
-   public void Clear()
+   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)CopyString("");
+         else
+            dataHolder = (int64)eInstance_New(type);
+         data = (void *)&dataHolder;
       }
+
+      if(created)
+         Refresh();
    }
 
-   public void Load()
+   void Load()
    {
-      if(visible && field && row)
+      if(field && row)
       {
          SetData(null, false);
          master.modifiedDocument = false;
@@ -467,23 +466,23 @@ public class FieldDataBox : DataBox
       }
    }
 
-   public virtual void Save()
+   virtual void Save()
    {
       bool result;
-      if(visible && field && row)
+      if(field && row)
       {
          Class type = field.type;
          if(!DataBox::SaveData())
             Refresh();
 
-         ((bool (*)())(void *)Row::SetData)(row, field, type, 
+         ((bool (*)())(void *)Row::SetData)(row, field, type,
             (type.type == noHeadClass || type.type == normalClass) ? *(void **)data : data);
       }
    }
 
-   public void Init()
+   void Init()
    {
-      if(visible && created)
+      if(created)
          Refresh();
    }
 
@@ -512,17 +511,17 @@ public class FieldDataBox : DataBox
    {
       if((SmartKey)key == enter)
          parent.CycleChildren(true, false, false, true);
-      
+
       return DataBox::OnKeyHit(key, ch);
    }
 
-   public bool Window::NotifyChanged(bool closingDropDown)
+   bool Window::NotifyChanged(DataBox dataBox, bool closingDropDown)
    {
       modifiedDocument = true;
       return true;
    }
 
-   public bool Window::NotifyModified()
+   bool Window::NotifyModified()
    {
       modifiedDocument = true;
       return true;
@@ -544,6 +543,11 @@ public class FieldDataBox : DataBox
          dataHolder = 0;
       }
    }
+
+private:
+   Field field;
+   int64 dataHolder; // THERE SEEMS(ED?) TO BE A BUG WHEN ACCESSING row ACROSS .so
+   Row row;
 }
 
 public class FieldCheckButton : FieldDataBox
@@ -558,24 +562,18 @@ public class FieldDropDataBox : FieldDataBox
 {
    size.h = 24;
    keepEditor = true;
-
-   Field nameField;
-   Field filterField;
-   uint exclusion;
-   uint filter;
-   bool filtered;
-   bool showNone;
    showNone = true;
 
-   public property uint filter { set { filtered = true; filter = value; } get { return filter; } }
-   public property bool filtered { set { filtered = value; } }
-   public property uint exclusion { set { exclusion = value; } }
-   public property Field filterField { set { filterField = value; } }
-   public property Field nameField { set { nameField = value; } }
-   public virtual void TableDropBox::RefillFunction();
-   public property bool showNone { set { showNone = value; } }
-
-   public void Refill()
+public:
+   property uint filter { set { filtered = true; filter = value; } get { return filter; } }
+   property bool filtered { set { filtered = value; } }
+   property uint exclusion { set { exclusion = value; } }
+   property Field filterField { set { filterField = value; } }
+   property Field nameField { set { nameField = value; } }
+   virtual void TableDropBox::RefillFunction();
+   property bool showNone { set { showNone = value; } }
+
+   void Refill()
    {
       if(editor)
       {
@@ -599,12 +597,20 @@ public class FieldDropDataBox : FieldDataBox
       dropBox.exclusion = exclusion;
       dropBox.showNone = showNone;
    }
+
+private:
+   Field nameField;
+   Field filterField;
+   uint exclusion;
+   uint filter;
+   bool filtered;
+   bool showNone;
 }
 
 public class EditFieldDropDataBox : FieldDropDataBox
 {
    // showNone = false;
-
+public:
    void OnConfigure(TableDropBox dropBox)
    {
       FieldDropDataBox::OnConfigure(dropBox);
@@ -615,7 +621,7 @@ public class EditFieldDropDataBox : FieldDropDataBox
    void Save()
    {
       TableDropBox dropBox = (TableDropBox) editor;
-      
+
       if(!dropBox.currentRow && dropBox.contents[0])
       {
          Row row { dropBox.table };
@@ -630,7 +636,7 @@ public class EditFieldDropDataBox : FieldDropDataBox
       FieldDataBox::Save();
    }
 
-   public virtual bool OnAddTextEntry(Row row, TableDropBox dropBox, char * entry)
+   virtual bool OnAddTextEntry(Row row, TableDropBox dropBox, char * entry)
    {
       row.Add();
       row.SetData(dropBox.nameField, entry);
@@ -643,10 +649,8 @@ public class ListSection : Group
    text = $"List";
    size = { 710, 287 };
    anchor = { left = sgs, top = 32 + sgs * 3, bottom = 55 + sgs * 3 };
-
-   EditSection editor;
-
-   public property EditSection editor
+public:
+   property EditSection editor
    {
       set
       {
@@ -655,7 +659,7 @@ public class ListSection : Group
       }
    }
 
-   public property Table table
+   property Table table
    {
       set
       {
@@ -665,29 +669,28 @@ public class ListSection : Group
             if(table)
             {
                FieldIndex indexedFields[1];
-               
+
                if(!fldId) fldId = table.FindField(defaultIdField);
                if(!fldName) fldName = table.FindField(defaultNameField);
                if(!fldActive) fldActive = table.FindField(defaultActiveField);
-               
+
                indexedFields[0] = { fldId };
                table.Index(1, indexedFields);
-               
+
                editor.editRow.tbl = table;
-               
+
                RefillList();
             }
          }
       }
    }
-   Table table;
-   public Field fldId, fldName, fldActive;
+   Field fldId, fldName, fldActive;
 
-   public virtual DialogResult Window::NotifySaveConfirmation(ListSection listSection)
+   virtual DialogResult Window::NotifySaveConfirmation(ListSection listSection)
    {
       return MessageBox { master = this, type = yesNoCancel, text = $"List Editor", contents = $"You have modified this entry. Would you like to save it before proceeding?" }.Modal();
    }
-   
+
    bool OnClose(bool parentClosing)
    {
       if(editor && editor.modifiedDocument)
@@ -706,7 +709,7 @@ public class ListSection : Group
       return true;
    }
 
-   public void RefillList()
+   void RefillList()
    {
       list.Clear();
       //if(fldId && fldName)
@@ -719,7 +722,7 @@ public class ListSection : Group
       editor.modifiedDocument = false;
    }
 
-   public virtual void Window::NotifyRefillList(ListSection listSection, Row r)
+   virtual void Window::NotifyRefillList(ListSection listSection, Row r)
    {
       if(listSection.fldId && listSection.fldName)
       {
@@ -739,9 +742,9 @@ public class ListSection : Group
       }
    }
 
-   public virtual bool Window::NotifyNew(ListSection listSection, Row r);
+   virtual bool Window::NotifyNew(ListSection listSection, Row r);
 
-   public ButtonStyle btnNew
+   ButtonStyle btnNew
    {
       this, anchor = { right = shadowS + sgs * 2, top = 24 }, hotKey = altW, text = $"New";
 
@@ -750,9 +753,9 @@ public class ListSection : Group
          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? 
+            uint 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
             {
                r.GetData(fldId, id);
@@ -760,7 +763,7 @@ public class ListSection : Group
             }
             else
                id = 1;
-         
+
             editor.EditClear();
             {
                bool active = true;
@@ -793,18 +796,18 @@ public class ListSection : Group
       }
    };
 
-   public virtual bool Window::NotifyDeleteConfirmation(ListSection listSection)
+   virtual bool Window::NotifyDeleteConfirmation(ListSection listSection)
    {
-      return MessageBox {  master = this, type = yesNo, text = $"List Editor", 
+      return MessageBox {  master = this, type = yesNo, text = $"List Editor",
                            contents =  $"You are about to delete an entry.\n"
                                         "Do you wish to continue?"
                   }.Modal() == yes;
    }
 
-   public virtual void Window::NotifyDeleting(ListSection listSection);
-   public virtual void Window::NotifyDeleted(ListSection listSection);
+   virtual void Window::NotifyDeleting(ListSection listSection);
+   virtual void Window::NotifyDeleted(ListSection listSection);
 
-   public ButtonStyle btnDelete
+   ButtonStyle btnDelete
    {
       this, anchor = { right = shadowS + sgs * 2, top = 24 }, hotKey = altD, text = $"Delete";
 
@@ -830,7 +833,7 @@ public class ListSection : Group
       }
    };
 
-   public bool FilterNotifyChanged(bool closeDropDown)
+   bool FilterNotifyChanged(DataBox dataBox, bool closeDropDown)
    {
       editor.EditClear();
       RefillList();
@@ -840,12 +843,11 @@ public class ListSection : Group
       return true;
    }
 
-   DataRow lastRow;
-   public ListBox list
+   ListBox list
    {
       this, anchor = { left = sgs * 2, top = 22 + 22 + sgs * 4, right = shadowS + sgs * 2, bottom = shadowS + sgs * 2 };
       alwaysHighLight = true;
-      
+
       bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
       {
          bool result = true;
@@ -875,9 +877,9 @@ public class ListSection : Group
       }
    };
 
-   public virtual void Window::NotifySelectListRow(ListSection listSection, uint64 id);
-   
-   public void SelectListRow(DataRow row)
+   virtual void Window::NotifySelectListRow(ListSection listSection, uint64 id);
+
+   void SelectListRow(DataRow row)
    {
       // Time startTime = GetTime();
       if(row)
@@ -897,14 +899,14 @@ public class ListSection : Group
       // Logf("SelectListRow took %f seconds\n", GetTime() - startTime);
    }
 
-   public void SelectFirst()
+   void SelectFirst()
    {
       if(list.firstRow)
          SelectListRow(list.firstRow);
       RefreshState();
    }
 
-   public void RefreshState()
+   void RefreshState()
    {
       if(editor)
       {
@@ -914,7 +916,7 @@ public class ListSection : Group
          editor.disabled = !(bool)list.firstRow;
       }
    }
-   
+
    void OnResize(int width, int height)
    {
       int x = width - btnDelete.size.w - 20;
@@ -932,6 +934,10 @@ public class ListSection : Group
       return Window::OnPostCreate();
    }
 
+private:
+   EditSection editor;
+   Table table;
+   DataRow lastRow;
 }
 
 public class EditSection : Group
@@ -966,9 +972,9 @@ public:
    DataRow listRow;
    OldList editBoxes { };
 
-   public Window editArea { this, borderStyle = deep, tabCycle = true, anchor = { left = 8, top = 54, right = 10, bottom = 10 }, hasVertScroll = true, dontHideScroll = true };
-   
-   public ButtonStyle btnSave
+   Window editArea { this, borderStyle = deep, tabCycle = true, anchor = { left = 8, top = 54, right = 10, bottom = 10 }, hasVertScroll = true, dontHideScroll = true };
+
+   ButtonStyle btnSave
    {
       this, anchor = { right = shadowS + sgs * 2, top = 24 }, hotKey = altV, text = $"Save";
 
@@ -979,7 +985,7 @@ public:
       }
    };
 
-   public ButtonStyle btnReload
+   ButtonStyle btnReload
    {
       this, anchor = { left = 10, top = 24 }, hotKey = altV, text = $"Revert";
 
@@ -997,7 +1003,7 @@ public:
    }
 
    virtual void Window::NotifyInitFields(EditSection editSection);
-   
+
    void InitFields()
    {
       OldLink link;
@@ -1018,7 +1024,7 @@ public:
    {
       edit.listRow.string = name;
    }
-   
+
    void EditSave()
    {
       bool stringName = !strcmp(list.fldName.type.dataTypeString, "char *");