2 public import static "ecere"
11 extern int __ecereVMethodID_class_OnGetString;
12 extern int __ecereVMethodID_class_OnCompare;
13 extern int __ecereVMethodID_class_OnUnserialize;
14 extern int __ecereVMethodID_class_OnSerialize;
15 extern int __ecereVMethodID_class_OnFree;
17 static void UnusedFunction()
25 a.OnEdit(null,null,0,0,0,0,0);
26 a.OnDisplay(null,0,0,0,0,0,0);
27 a.OnGetDataFromString(null);
28 a.OnUnserialize(null);
33 public class Id : uint
35 class_data Table * table; class_property Table * table { set { class_data(table) = value; } get { return class_data(table); } };
36 class_data Field * nameField; class_property Field * nameField { set { class_data(nameField) = value; } get { return class_data(nameField); } };
37 class_data char * addText; class_property char * addText { set { class_data(addText) = value; } };
38 class_data void * Refill; class_property void * Refill { set { class_data(Refill) = value; } };
40 Window OnEdit(DataBox dataBox, void * obsolete, int x, int y, int w, int h, void * userData)
42 if(this || !this) { // FIXME
43 TableDropBox dropBox = dataBox.keepEditor ? (TableDropBox)dataBox.editor /*obsolete*/ : null;
46 dropBox = TableDropBox
48 dataBox, borderStyle = 0, anchor = { 0, 0, 0, 0 },
49 modifyVirtualArea = false, activeStipple = false;
51 nameField = *class_data(nameField);
52 table = *class_data(table);
54 bool DataBox::NotifySelect(DropBox control, DataRow row, Modifiers mods)
56 uint id = row ? row.tag : 0;
57 SetData(&id, mods.closingDropDown);
61 bool DataBox::NotifyTextEntry(DropBox _dropBox, char * string, bool confirmed)
63 TableDropBox dropBox = (TableDropBox)_dropBox;
64 //Table tbl = dropBox.table.db.OpenTable(dropBox.table.name, { tableRows });
67 /*FieldIndex indexedFields[1];
69 char * trimmed = new char[strlen(string) + 1];
70 /*indexedFields[0] = { dropBox.nameField };
71 tbl.GenerateIndex(1, indexedFields, false);
75 TrimLSpaces(string, trimmed);
76 TrimRSpaces(trimmed, trimmed);
78 /*if(r.Find(dropBox.nameField, middle, nil, trimmed))
80 if(dropBox.filterField)
82 // TODO: Improve this... Multi field?
87 Field fldId = dropBox.table.FindField(defaultIdField);
89 row = dropBox.FindSubRow(id);
92 dropBox.SelectRow(row);
95 //if(!r.Find(dropBox.nameField, next, nil, trimmed))
103 Field fldId = dropBox.table.FindField(defaultIdField);
104 r.GetData(fldId, id);
105 dropBox.SelectRow(dropBox.FindSubRow(id));
111 for(row = dropBox.firstRow; row; row = row.next)
113 char * string = row.string;
114 if(string && !strcmp(trimmed, string))
120 dropBox.SelectRow(row);
124 dropBox.changeContents = false;
125 dropBox.contents = trimmed;
126 dropBox.SelectRow(null);
127 dropBox.changeContents = true;
134 if(class_data(Refill))
135 dropBox.Refill = class_data(Refill);
139 dataBox.OnConfigure(dropBox);
141 dropBox.currentRow = dropBox.FindSubRow(this);
142 if(!dropBox.currentRow && this)
143 dataBox.SetData((uint *)&this, false);
145 DataRow r = dropBox.currentRow;
147 for(r = r.parent; r; r = r.parent)
155 char * OnGetString(char * tempString, void * fieldData, bool * needClass)
160 Table tbl = *class_data(table);
161 Field idField = tbl.FindField(defaultIdField);
166 if(r.Find(idField, middle, nil, this))
169 Field * nameField = class_data(nameField);
170 char * fn = nameField->name;
171 r.GetData(*nameField, name);
174 strcpy(tempString, name);
178 strcpy(tempString, "");
183 sprintf(tempString, "(Click to add a new %s...)", "item"/*class_data(addText)*/);
196 class_data Class type;
197 class_property Class type
199 set { class_data(type) = value; }
200 get { return class_data(type); }
212 public bool Includes(Id id)
217 for(c = 0; c < count; c++)
224 public bool Add(Id id)
227 for(c = 0; c < count; c++)
228 if(ids[c] == id) break;
231 ids = renew ids Id[count + 1];
239 public bool Delete(Id id)
242 for(c = 0; c < count; c++)
246 memcpy(ids + c, ids + c + 1, (count - 1 - c) * sizeof(Id));
247 ids = renew ids Id[count - 1];
254 void OnUnserialize(IOChannel channel)
260 channel.Unserialize(count);
261 if(count != MAXDWORD)
263 IdList idList = eInstance_New(_class); //IdList { };
264 idList.count = count;
265 idList.ids = new Id[count];
266 for(c = 0; c < count; c++)
269 channel.Unserialize(id);
277 void OnSerialize(IOChannel channel)
282 channel.Serialize(count);
283 for(c = 0; c < count; c++)
284 channel.Serialize(ids[c]);
289 channel.Serialize(none);
293 void OnDisplay(Surface surface, int x, int y, int width, void * fieldData, Alignment alignment, DataDisplayFlags displayFlags)
298 char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
304 for(c = 0; c<count; c++)
306 char tempString[256];
307 Class type = class_data(type);
308 if(c) strcat(stringOutput, ", ");
311 type._vTbl[__ecereVMethodID_class_OnGetString](type, &ids[c], tempString, null, null);
312 // strcatf(stringOutput, "%d", ids[c]);
313 strcat(stringOutput, tempString);
319 bool OnGetDataFromString(char * string)
323 while(GetAlNum(&string, value, sizeof(value)))
324 if(isdigit(value[0]))
329 int OnCompare(IdList b)
331 if(count > b.count) return 1;
332 else if(count < b.count) return -1;
336 for(c = 0; c<count; c++)
338 int idA = ids[c], idB = b.ids[c];
339 if(idA > idB) return 1;
340 else if(idA < idB) return -1;
346 Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
353 anchor = { 0, 0, 0, 0 };
355 bool DataBox::NotifyChanged(ListBox listBox, DataRow row)
357 Id id = row.GetData(null);
361 listBox.DeleteRow(row);
365 if(row == listBox.lastRow)
367 row = listBox.AddRow();
368 row.SetData(null, 0);
369 listBox.scroll.y = listBox.scrollArea.h;
371 else if(row.next == listBox.lastRow)
372 listBox.scroll.y = listBox.scrollArea.h;
382 this = eInstance_New(_class);
384 if(this || !this) // FIXME
386 Class type = class_data(type);
387 list.AddField({ type, editable = true });
389 for(c = 0; c < (this ? count : 0); c++)
392 r.SetData(null, ids[c]);
397 list.modifiedDocument = false;
401 bool OnSaveEdit(Window window, void * object)
403 ListBox list = (ListBox) window;
404 if(list.modifiedDocument)
408 this = eInstance_New(_class);
410 for(r = list.firstRow; r; r = r.next)
412 Id id = r.GetData(null);
427 static void FreeString(String string)
432 public class StringList
434 StringBinaryTree strings
436 CompareKey = (void *)BinaryTree::CompareString;
437 FreeKey = (void *)FreeString;
445 bool Includes(String string)
447 return strings.FindString(string) != null;
450 bool Add(String string)
452 BTNode node { key = (uint)CopyString(string) };
453 if(strings.Add(node))
457 FreeString((String)node.key);
463 bool Delete(String string)
465 BTNode node = strings.FindString(string);
468 strings.Delete(node);
474 void _OnUnserialize(IOChannel channel)
476 channel.Get(strings);
479 void OnUnserialize(IOChannel channel)
481 this = eInstance_New(class(StringList));
482 _OnUnserialize(channel);
485 void OnSerialize(IOChannel channel)
487 channel.Put(strings);
490 int OnCompare(StringList b)
492 BTNode nodeA = strings.first, nodeB = b.strings.first;
493 for(; nodeA || nodeB; nodeA = nodeA ? nodeA.next : null, nodeB = nodeB ? nodeB.next : null)
496 if(nodeA && !nodeB) return 1;
497 else if(nodeB && !nodeA) return -1;
500 result = strcmp((char *)nodeA.key, (char *)nodeB.key);
501 if(result) return result;
507 Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
514 anchor = { 0, 0, 0, 0 };
516 bool OnKeyHit(Key key, unichar ch)
518 return (key == enter) ? false : ListBox::OnKeyHit(key, ch);
521 bool DataBox::NotifyChanged(ListBox listBox, DataRow row)
523 String string = row.GetData(null);
524 if(!string || !string[0])
528 listBox.DeleteRow(row);
529 listBox.firstChild.Activate();
534 if(row == listBox.lastRow)
536 row = listBox.AddRow();
537 row.SetData(null, null);
538 listBox.scroll.y = listBox.scrollArea.h;
544 if(row.next == listBox.lastRow)
545 listBox.scroll.y = listBox.scrollArea.h;
548 listBox.SelectRow(row);
554 bool DataBox::NotifyEdited(ListBox listBox, DataRow row)
556 listBox.firstChild.Activate();
560 bool DataBox::NotifyModified(ListBox listBox, DataRow row)
562 String string = row.GetData(null);
563 if(!string || !string[0])
567 listBox.DeleteRow(row);
568 listBox.firstChild.Activate();
573 if(row == listBox.lastRow)
575 row = listBox.AddRow();
576 row.SetData(null, null);
577 listBox.scroll.y = listBox.scrollArea.h;
579 else if(row.next == listBox.lastRow)
580 listBox.scroll.y = listBox.scrollArea.h;
593 this = eInstance_New(_class);
597 if(this || !this) // FIXME
599 list.AddField({ class(char *), editable = true });
601 for(node = strings.first; node; node = node.next)
604 r.SetData(null, (String)node.key);
607 r.SetData(null, null);
609 list.modifiedDocument = false;
613 bool OnSaveEdit(Window window, void * object)
615 ListBox list = (ListBox) window;
616 if(list.modifiedDocument)
621 ((DataBox)list.activeChild).SaveData();
624 this = eInstance_New(_class);
626 // TODO: Fix how to get the data box...
628 for(r = list.firstRow; r; r = r.next)
630 String string = r.GetData(null);
647 public class FixedMultiLineString : String
649 Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
651 // Don't show the editbox right away so that the text is highlighted by default
655 dataBox, visible = false,
657 textHorzScroll = true,
658 modifyVirtualArea = false,
659 anchor = { 0, 0, 0, 0 };
662 void DataBox::NotifyUpdate(EditBox editBox)
665 modifiedDocument = true;
668 editBox.contents = this;
669 editBox.visible = true;
673 editBox.contents = this;
677 bool OnSaveEdit(Window window, void * object)
679 bool changed = false;
680 EditBox editBox = (EditBox)window;
681 if(editBox.modifiedDocument)
689 for(line = editBox.firstLine; line; line = line.next)
690 size += line.count+1;
691 this = string = new char[size+1];
693 for(line = editBox.firstLine; line; line = line.next)
695 memcpy(string + size, line.text, line.count);
711 public class CIString : String
716 public class MultiLineString : String
718 Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
720 // Don't show the editbox right away so that the text is highlighted by default
724 dataBox, visible = false,
726 hasHorzScroll = true, hasVertScroll = true,
727 modifyVirtualArea = false,
728 anchor = { 0, 0, 0, 0 };
731 void DataBox::NotifyUpdate(EditBox editBox)
734 modifiedDocument = true;
737 editBox.contents = this;
738 editBox.visible = true;
742 editBox.contents = this;
746 bool OnSaveEdit(Window window, void * object)
748 bool changed = false;
749 EditBox editBox = (EditBox)window;
750 if(editBox.modifiedDocument)
758 for(line = editBox.firstLine; line; line = line.next)
759 size += line.count+1;
760 this = string = new char[size+1];
762 for(line = editBox.firstLine; line; line = line.next)
764 memcpy(string + size, line.text, line.count);
780 public struct DataList : OldList
782 class_data Class type;
783 class_data char * typeName;
784 // class_property Class type { set { class_data(type) = value; } };
785 class_property char * type { set { class_data(typeName) = value; } };
786 class_property Class dataType { get { return class_data(type); } };
788 void OnUnserialize(IOChannel channel)
791 if(!class_data(type))
792 class_data(type) = eSystem_FindClass(__thisModule.application, class_data(typeName));
793 type = class_data(type);
801 channel.Unserialize(truth);
807 if(type.type == structClass)
808 link.data = new0 byte[type.structSize];
809 type._vTbl[__ecereVMethodID_class_OnUnserialize](type, (type.type == structClass) ? link.data : &link.data, channel);
815 void OnSerialize(IOChannel channel)
817 OldLink node = first;
819 if(!class_data(type))
820 class_data(type) = eSystem_FindClass(__thisModule.application, class_data(typeName));
821 type = class_data(type);
828 channel.Serialize(truth);
829 if(type.type == bitClass || type.type == unitClass || (type.type == systemClass && type.typeSize))
830 type._vTbl[__ecereVMethodID_class_OnSerialize](type, &node.data, channel);
832 type._vTbl[__ecereVMethodID_class_OnSerialize](type, node.data, channel);
838 channel.Serialize(truth);
845 int OnCompare(DataList b)
847 OldLink nodeA = first, nodeB = b.first;
848 for(; nodeA || nodeB; nodeA = nodeA ? nodeA.next : null, nodeB = nodeB ? nodeB.next : null)
851 if(nodeA && !nodeB) return 1;
852 else if(nodeB && !nodeA) return -1;
855 Class type = class_data(type);
856 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
857 (type.type == systemClass || type.type == bitClass || type.type == enumClass || type.type == unitClass) ? &nodeA.data : (void *)nodeA.data,
858 (type.type == systemClass || type.type == bitClass || type.type == enumClass || type.type == unitClass) ? &nodeB.data : (void *)nodeB.data);
859 if(result) return result;
865 Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
872 anchor = { 0, 0, 0, 0 };
874 bool OnKeyHit(Key key, unichar ch)
876 return (key == enter) ? false : ListBox::OnKeyHit(key, ch);
879 bool DataBox::NotifyChanged(ListBox listBox, DataRow row)
881 Class type = ((subclass(DataList))this.type).dataType;
882 if(type.type == normalClass && !strcmp(type.dataTypeString, "char *"))
884 String string = row.GetData(null);
885 if(!string || !string[0])
889 listBox.DeleteRow(row);
890 listBox.firstChild.Activate();
895 if(row == listBox.lastRow)
897 /*row = listBox.AddRow();
898 row.SetData(null, null);
899 listBox.scroll.y = listBox.scrollArea.h;*/
905 listBox.SelectRow(row);
912 bool DataBox::NotifyModified(ListBox listBox, DataRow row)
914 Class type = ((subclass(DataList))this.type).dataType;
915 if(type.type == normalClass && !strcmp(type.dataTypeString, "char *"))
917 String string = row.GetData(null);
918 if(!string || !string[0])
922 listBox.DeleteRow(row);
923 listBox.firstChild.Activate();
928 if(row == listBox.lastRow)
930 row = listBox.AddRow();
931 row.SetData(null, null);
932 listBox.scroll.y = listBox.scrollArea.h;
934 else if(row.next == listBox.lastRow)
935 listBox.scroll.y = listBox.scrollArea.h;
942 bool DataBox::NotifyEditing(ListBox listBox, DataRow row)
944 Class type = ((subclass(DataList))this.type).dataType;
945 DataBox editData = (DataBox)listBox.firstChild;
946 // if(type.type != normalClass || strcmp(type.dataTypeString, "char *"))
950 if(type.type == normalClass && !*(void **)editData.data && strcmp(type.dataTypeString, "char *"))
952 *(void **)editData.data = eInstance_New(type);
953 row.SetData(null, *(void **)editData.data);
957 if(row == listBox.lastRow)
959 listBox.alwaysEdit = false;
960 if(type.type == normalClass || type.type == structClass || type.type == noHeadClass)
961 listBox.AddRow().SetData(null, null);
963 listBox.AddRow().SetData(null, 0);
964 listBox.scroll.y = listBox.scrollArea.h;
965 listBox.alwaysEdit = true;
971 bool DataBox::NotifyEdited(ListBox listBox, DataRow row)
973 listBox.firstChild.Activate();
977 bool DataBox::NotifyEditDone(ListBox listBox, DataRow row)
979 Class type = ((subclass(DataList))this.type).dataType;
980 // if(type.type != normalClass || strcmp(type.dataTypeString, "char *"))
983 void * data = ((type.type == normalClass || type.type == noHeadClass || type.type == structClass) ? row.GetData(null) : *(uint *)row.GetData(null));
986 //if(strcmp(type.dataTypeString, char *"))
987 //listBox.currentRow = null;
988 if(row != listBox.lastRow)
990 listBox.alwaysEdit = false;
991 listBox.DeleteRow(row);
992 listBox.alwaysEdit = true;
1002 Class type = firstField.dataType;
1003 // if(type.type != normalClass || strcmp(type.dataTypeString, "char *"))
1006 if(type.type == normalClass && strcmp(type.dataTypeString, "char *"))
1007 eInstance_Delete(lastRow.GetData(null));
1008 if(type.type == normalClass || type.type == structClass || type.type == noHeadClass)
1009 lastRow.SetData(null, null);
1011 lastRow.SetData(null, 0);
1019 if(!class_data(type))
1020 class_data(type) = eSystem_FindClass(__thisModule.application, class_data(typeName));
1021 type = class_data(type);
1023 list.AddField({ type, editable = true });
1024 for(node = first; node; node = node.next)
1029 if(type.type == normalClass && !strcmp(type.dataTypeString, "char *"))
1030 r.SetData(null, CopyString((String)node.data));
1032 r.SetData(null, node.data);
1036 if(type.type == normalClass || type.type == structClass || type.type == noHeadClass)
1037 r.SetData(null, null);
1041 list.modifiedDocument = false;
1045 bool OnSaveEdit(Window window, void * object)
1047 ListBox list = (ListBox) window;
1048 if(list.modifiedDocument)
1050 Class type = class_data(type);
1052 if(list.activeChild)
1053 ((DataBox)list.activeChild).SaveData();
1055 if(type.type != normalClass || !strcmp(type.dataTypeString, "char *"))
1057 else if(type.type == structClass)
1058 Free(OldLink::Free);
1062 for(r = list.firstRow; r; r = r.next)
1064 if(type.type == noHeadClass || type.type == normalClass || type.type == structClass)
1066 void * data = r.GetData(null);
1069 if(type.type == normalClass && !strcmp(type.dataTypeString, "char *"))
1070 Add(OldLink { data = CopyString(data) });
1071 else if(type.type == structClass)
1073 OldLink link { data = new byte[type.structSize] };
1075 memcpy(link.data, data, type.structSize);
1078 Add(OldLink { data = data });
1083 uint i = r.GetData(null);
1085 Add(OldLink { data = (void *)i });
1098 if(!class_data(type))
1099 class_data(type) = eSystem_FindClass(__thisModule.application, class_data(typeName));
1100 type = class_data(type);
1103 // TO STUDY: ONFREE SHOULD BE USED ONLY FOR LISTBOX?
1106 if(type.type == normalClass && strcmp(type.dataTypeString, "char *"))
1107 eInstance_Delete(node.data);
1108 else if(type.type == structClass)
1111 type._vTbl[__ecereVMethodID_class_OnFree](type, node.data);