default:
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
{
- font = { "Arial", 10, bold = true };
+ font = { $"Arial", 10, bold = true };
creationActivation = doNothing;
}
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()
{
{
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;
+ Button button = dataBox.keepEditor ? (Button)dataBox.editor : null;
if(!button)
{
button = Button
{
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;
}
};
button.checked = this;
button.Create();
return button;
+ }
+}
+
+String GetNameString(Row r, Field nameField)
+{
+ String s = null;
+ if(nameField.type != class(String) && nameField.type != class(char *))
+ {
+ char tempString[4096];
+ Class type = nameField.type;
+ int64 data = 0;
+ if(type.type == structClass)
+ 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 *)(intptr)data;
+ delete _data;
}
- return null;
}
+ else
+ r.GetData(nameField, s);
+ return s;
}
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:
+ Id filter;
+ bool filtered;
+ Field nameField;
+ Id exclusion;
+ Table table;
+ Field filterField;
- public property uint filter
+ property Id filter
{
set
{
}
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 Id 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)
{
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)
tbl.GenerateIndex(1, indexedFields, false);
r = Row { tbl };
-
+
for(r.Find(filterField, middle, nil, filter); !r.nil; r.Next()) //while(r.Next())
{
Id id;
break;
if(!exclusion || id != exclusion)
{
- String s;
- r.GetData(nameField, s);
+ String s = GetNameString(r, nameField);
AddString(s).tag = id;
delete s;
}
r.GetData(fldId, id);
if(idList && idList.Includes(filter) && (!exclusion || !idList.Includes(exclusion)))
{
- String s;
- r.GetData(nameField, s);
+ String s = GetNameString(r, nameField);
AddString(s).tag = id;
delete s;
}
r.GetData(fldId, id);
if(id != exclusion)
{
- String s;
- r.GetData(nameField, s);
+ String s = GetNameString(r, nameField);
AddString(s).tag = id;
delete s;
}
while(r.Next())
{
Id id;
- String s;
+ String s = GetNameString(r, nameField);
r.GetData(fldId, id);
- r.GetData(nameField, s);
AddString(s).tag = id;
delete s;
}
Sort(null, 1);
}
- public property Field filterField { set { filterField = value; } }
+ property Field filterField { set { filterField = value; } }
bool OnKeyHit(Key key, unichar ch)
{
}
else if((SmartKey)key == enter)
parent.CycleChildren(true, false, false, true);
-
+
return DropBox::OnKeyHit(key, ch);
}
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;
+ const char * contents = editBox.contents;
int len = strlen(contents);
if(len && editBox.charPos == len)
{
{
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);
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 Id filter { set { filtered = true; filter = value; } get { return filter; } }
+ property bool filtered { set { filtered = value; } }
+ property Id 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)
{
TableDropBox dropBox = (TableDropBox) editor;
- uint id = data ? *(uint *)data : MAXDWORD;
+ Id id = data ? *(Id *)data : MAXDWORD;
void * notifyChanged = (void *)NotifyChanged;
OnConfigure(dropBox);
dropBox.filter = filter;
else
dropBox.filtered = false;
-
+
dropBox.exclusion = exclusion;
dropBox.showNone = showNone;
}
+
+private:
+ Field nameField;
+ Field filterField;
+ Id exclusion;
+ Id filter;
+ bool filtered;
+ bool showNone;
}
public class EditDropDataBox : DropDataBox
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;
+ // TOCHECK: Testing this for GenericEditor performance issue?
+ keepEditor = true;
- public property Row row
+public:
+ property Row row
{
set { row = value; }
get { return row; }
}
- public property EditSection editor
+ property EditSection editor
{
set
{
}
};
- public property Field field
+ property Field field
{
set
{
if(dataHolder)
{
- type._vTbl[__ecereVMethodID_class_OnFree](type, 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;
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
}
}
- 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)(intptr)CopyString("");
+ else
+ dataHolder = (int64)(intptr)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;
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;
}
}
}
- 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();
}
{
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;
if(dataHolder)
{
- type._vTbl[__ecereVMethodID_class_OnFree](type, 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;
}
}
+
+private:
+ Field field;
+ int64 dataHolder; // THERE SEEMS(ED?) TO BE A BUG WHEN ACCESSING row ACROSS .so
+ Row row;
}
public class FieldCheckButton : 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 Id filter { set { filtered = true; filter = value; } get { return filter; } }
+ property bool filtered { set { filtered = value; } }
+ property Id 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)
{
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));
dropBox.exclusion = exclusion;
dropBox.showNone = showNone;
}
+
+private:
+ Field nameField;
+ Field filterField;
+ Id exclusion;
+ Id filter;
+ bool filtered;
+ bool showNone;
}
public class EditFieldDropDataBox : FieldDropDataBox
{
// showNone = false;
-
+public:
void OnConfigure(TableDropBox dropBox)
{
FieldDropDataBox::OnConfigure(dropBox);
void Save()
{
TableDropBox dropBox = (TableDropBox) editor;
-
+
if(!dropBox.currentRow && dropBox.contents[0])
{
Row row { dropBox.table };
FieldDataBox::Save();
}
- public 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);
public class ListSection : Group
{
- text = "List";
+ 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
{
}
}
- public property Table table
+ property Table table
{
set
{
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();
+ 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)
return true;
}
- public void RefillList()
+ void RefillList()
{
list.Clear();
//if(fldId && fldName)
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)
{
- 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;
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;
}
}
}
- 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";
+ this, anchor = { right = shadowS + sgs * 2, top = 24 }, hotKey = altW, text = $"New";
bool NotifyClicked(Button button, int x, int y, Modifiers mods)
{
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
{
r.GetData(fldId, id);
}
else
id = 1;
-
+
editor.EditClear();
{
bool active = true;
r.SetData(fldId, id);
}
if(!strcmp(fldName.type.dataTypeString, "char *"))
- r.SetData(fldName, "[New]");
+ r.SetData(fldName, $"[New]");
if(fldActive)
r.SetData(fldActive, active);
if(NotifyNew(master, this, r))
- list.currentRow = list.AddString("[New]");
+ list.currentRow = list.AddString($"[New]");
delete r;
}
}
};
- public virtual bool Window::NotifyDeleteConfirmation(ListSection listSection)
+ virtual bool Window::NotifyDeleteConfirmation(ListSection listSection)
{
- return MessageBox { master = this, type = yesNo, text = "List Editor",
- contents = "You are about to delete an entry.\n"
- "Do you wish to continue?"
+ 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";
+ this, anchor = { right = shadowS + sgs * 2, top = 24 }, hotKey = altD, text = $"Delete";
bool NotifyClicked(Button button, int x, int y, Modifiers mods)
{
}
};
- public bool FilterNotifyChanged(bool closeDropDown)
+ bool FilterNotifyChanged(DataBox dataBox, bool closeDropDown)
{
editor.EditClear();
RefillList();
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;
if(/*row && */row != lastRow)
{
- uint id;
if(editor.modifiedDocument)
{
if(row)
}
};
- public virtual void Window::NotifySelectListRow(ListSection listSection, uint id);
-
- public void SelectListRow(DataRow row)
+ virtual void Window::NotifySelectListRow(ListSection listSection, Id id);
+
+ void SelectListRow(DataRow row)
{
// Time startTime = GetTime();
if(row)
{
- uint id = row.tag;
+ Id id = row.tag;
lastRow = row;
if(list.currentRow != row)
// 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)
{
- 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;
}
}
-
+
void OnResize(int width, int height)
{
int x = width - btnDelete.size.w - 20;
return Window::OnPostCreate();
}
+private:
+ EditSection editor;
+ Table table;
+ DataRow lastRow;
}
public class EditSection : Group
{
tabCycle = true;
- text = "Entry";
+ text = $"Entry";
size = { 710, 55 };
anchor = { right = sgs, top = 32 + sgs * 3, bottom = 55 + sgs * 3 };
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";
+ this, anchor = { right = shadowS + sgs * 2, top = 24 }, hotKey = altV, text = $"Save";
bool NotifyClicked(Button button, int x, int y, Modifiers mods)
{
- EditSave(editRow);
+ EditSave();
return true;
}
};
- public ButtonStyle btnReload
+ ButtonStyle btnReload
{
- this, anchor = { left = 10, top = 24 }, hotKey = altV, text = "Revert";
+ this, anchor = { left = 10, top = 24 }, hotKey = altV, text = $"Revert";
bool NotifyClicked(Button button, int x, int y, Modifiers mods)
{
- EditLoad(editRow);
+ EditLoad();
return true;
}
};
}
virtual void Window::NotifyInitFields(EditSection editSection);
-
+
void InitFields()
{
OldLink link;
void EditNew()
{
-
modifiedDocument = false;
}
{
edit.listRow.string = name;
}
-
+
void EditSave()
{
bool stringName = !strcmp(list.fldName.type.dataTypeString, "char *");