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);
143 DataRow r = dropBox.currentRow;
145 for(r = r.parent; r; r = r.parent)
153 char * OnGetString(char * tempString, void * fieldData, bool * needClass)
158 Table tbl = *class_data(table);
159 Field idField = tbl.FindField(defaultIdField);
164 if(r.Find(idField, middle, nil, this))
167 Field * nameField = class_data(nameField);
168 char * fn = nameField->name;
169 r.GetData(*nameField, name);
172 strcpy(tempString, name);
176 strcpy(tempString, "");
181 sprintf(tempString, "(Click to add a new %s...)", "item"/*class_data(addText)*/);
194 class_data Class type;
195 class_property Class type
197 set { class_data(type) = value; }
198 get { return class_data(type); }
210 public bool Includes(Id id)
215 for(c = 0; c < count; c++)
222 public bool Add(Id id)
225 for(c = 0; c < count; c++)
226 if(ids[c] == id) break;
229 ids = renew ids Id[count + 1];
237 public bool Delete(Id id)
240 for(c = 0; c < count; c++)
244 memcpy(ids + c, ids + c + 1, (count - 1 - c) * sizeof(Id));
245 ids = renew ids Id[count - 1];
252 void OnUnserialize(IOChannel channel)
258 channel.Unserialize(count);
259 if(count != MAXDWORD)
261 this = eInstance_New(_class); //IdList { };
262 for(c = 0; c < count; c++)
265 channel.Unserialize(id);
271 void OnSerialize(IOChannel channel)
276 channel.Serialize(count);
277 for(c = 0; c < count; c++)
278 channel.Serialize(ids[c]);
283 channel.Serialize(none);
287 void OnDisplay(Surface surface, int x, int y, int width, void * fieldData, Alignment alignment, DataDisplayFlags displayFlags)
292 char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
298 for(c = 0; c<count; c++)
300 char tempString[256];
301 Class type = class_data(type);
302 if(c) strcat(stringOutput, ", ");
305 type._vTbl[__ecereVMethodID_class_OnGetString](type, &ids[c], tempString, null, null);
306 // strcatf(stringOutput, "%d", ids[c]);
307 strcat(stringOutput, tempString);
313 bool OnGetDataFromString(char * string)
317 while(GetAlNum(&string, value, sizeof(value)))
318 if(isdigit(value[0]))
323 int OnCompare(IdList b)
325 if(count > b.count) return 1;
326 else if(count < b.count) return -1;
330 for(c = 0; c<count; c++)
332 int idA = ids[c], idB = b.ids[c];
333 if(idA > idB) return 1;
334 else if(idA < idB) return -1;
340 Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
347 anchor = { 0, 0, 0, 0 };
349 bool DataBox::NotifyChanged(ListBox listBox, DataRow row)
351 Id id = row.GetData(null);
355 listBox.DeleteRow(row);
359 if(row == listBox.lastRow)
361 row = listBox.AddRow();
362 row.SetData(null, 0);
363 listBox.scroll.y = listBox.scrollArea.h;
365 else if(row.next == listBox.lastRow)
366 listBox.scroll.y = listBox.scrollArea.h;
376 this = eInstance_New(_class);
378 if(this || !this) // FIXME
380 Class type = class_data(type);
381 list.AddField({ type, editable = true });
383 for(c = 0; c < (this ? count : 0); c++)
386 r.SetData(null, ids[c]);
391 list.modifiedDocument = false;
395 bool OnSaveEdit(Window window, void * object)
397 ListBox list = (ListBox) window;
398 if(list.modifiedDocument)
402 this = eInstance_New(_class);
404 for(r = list.firstRow; r; r = r.next)
406 Id id = r.GetData(null);
421 static void FreeString(String string)
426 public class StringList
428 StringBinaryTree strings
430 CompareKey = (void *)BinaryTree::CompareString;
431 FreeKey = (void *)FreeString;
439 bool Includes(String string)
441 return strings.FindString(string) != null;
444 bool Add(String string)
446 BTNode node { key = (uint)CopyString(string) };
447 if(strings.Add(node))
451 FreeString((String)node.key);
457 bool Delete(String string)
459 BTNode node = strings.FindString(string);
462 strings.Delete(node);
468 void _OnUnserialize(IOChannel channel)
470 channel.Get(strings);
473 void OnUnserialize(IOChannel channel)
475 this = eInstance_New(class(StringList));
476 _OnUnserialize(channel);
479 void OnSerialize(IOChannel channel)
481 channel.Put(strings);
484 int OnCompare(StringList b)
486 BTNode nodeA = strings.first, nodeB = b.strings.first;
487 for(; nodeA || nodeB; nodeA = nodeA ? nodeA.next : null, nodeB = nodeB ? nodeB.next : null)
490 if(nodeA && !nodeB) return 1;
491 else if(nodeB && !nodeA) return -1;
494 result = strcmp((char *)nodeA.key, (char *)nodeB.key);
495 if(result) return result;
501 Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
508 anchor = { 0, 0, 0, 0 };
510 bool OnKeyHit(Key key, unichar ch)
512 return (key == enter) ? false : ListBox::OnKeyHit(key, ch);
515 bool DataBox::NotifyChanged(ListBox listBox, DataRow row)
517 String string = row.GetData(null);
518 if(!string || !string[0])
522 listBox.DeleteRow(row);
523 listBox.firstChild.Activate();
528 if(row == listBox.lastRow)
530 row = listBox.AddRow();
531 row.SetData(null, null);
532 listBox.scroll.y = listBox.scrollArea.h;
538 if(row.next == listBox.lastRow)
539 listBox.scroll.y = listBox.scrollArea.h;
542 listBox.SelectRow(row);
548 bool DataBox::NotifyEdited(ListBox listBox, DataRow row)
550 listBox.firstChild.Activate();
554 bool DataBox::NotifyModified(ListBox listBox, DataRow row)
556 String string = row.GetData(null);
557 if(!string || !string[0])
561 listBox.DeleteRow(row);
562 listBox.firstChild.Activate();
567 if(row == listBox.lastRow)
569 row = listBox.AddRow();
570 row.SetData(null, null);
571 listBox.scroll.y = listBox.scrollArea.h;
573 else if(row.next == listBox.lastRow)
574 listBox.scroll.y = listBox.scrollArea.h;
587 this = eInstance_New(_class);
591 if(this || !this) // FIXME
593 list.AddField({ class(char *), editable = true });
595 for(node = strings.first; node; node = node.next)
598 r.SetData(null, (String)node.key);
601 r.SetData(null, null);
603 list.modifiedDocument = false;
607 bool OnSaveEdit(Window window, void * object)
609 ListBox list = (ListBox) window;
610 if(list.modifiedDocument)
615 ((DataBox)list.activeChild).SaveData();
618 this = eInstance_New(_class);
620 // TODO: Fix how to get the data box...
622 for(r = list.firstRow; r; r = r.next)
624 String string = r.GetData(null);
641 public class FixedMultiLineString : String
643 Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
645 // Don't show the editbox right away so that the text is highlighted by default
649 dataBox, visible = false,
651 textHorzScroll = true,
652 modifyVirtualArea = false,
653 anchor = { 0, 0, 0, 0 };
656 void DataBox::NotifyUpdate(EditBox editBox)
659 modifiedDocument = true;
662 editBox.contents = this;
663 editBox.visible = true;
667 editBox.contents = this;
671 bool OnSaveEdit(Window window, void * object)
673 bool changed = false;
674 EditBox editBox = (EditBox)window;
675 if(editBox.modifiedDocument)
683 for(line = editBox.firstLine; line; line = line.next)
684 size += line.count+1;
685 this = string = new char[size+1];
687 for(line = editBox.firstLine; line; line = line.next)
689 memcpy(string + size, line.text, line.count);
702 public class CIString : String
707 public class MultiLineString : String
709 Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
711 // Don't show the editbox right away so that the text is highlighted by default
715 dataBox, visible = false,
717 hasHorzScroll = true, hasVertScroll = true,
718 modifyVirtualArea = false,
719 anchor = { 0, 0, 0, 0 };
722 void DataBox::NotifyUpdate(EditBox editBox)
725 modifiedDocument = true;
728 editBox.contents = this;
729 editBox.visible = true;
733 editBox.contents = this;
737 bool OnSaveEdit(Window window, void * object)
739 bool changed = false;
740 EditBox editBox = (EditBox)window;
741 if(editBox.modifiedDocument)
749 for(line = editBox.firstLine; line; line = line.next)
750 size += line.count+1;
751 this = string = new char[size+1];
753 for(line = editBox.firstLine; line; line = line.next)
755 memcpy(string + size, line.text, line.count);
768 public struct DataList : OldList
770 class_data Class type;
771 class_data char * typeName;
772 // class_property Class type { set { class_data(type) = value; } };
773 class_property char * type { set { class_data(typeName) = value; } };
774 class_property Class dataType { get { return class_data(type); } };
776 void OnUnserialize(IOChannel channel)
779 if(!class_data(type))
780 class_data(type) = eSystem_FindClass(__thisModule.application, class_data(typeName));
781 type = class_data(type);
789 channel.Unserialize(truth);
795 if(type.type == structClass)
796 link.data = new0 byte[type.structSize];
797 type._vTbl[__ecereVMethodID_class_OnUnserialize](type, (type.type == structClass) ? link.data : &link.data, channel);
803 void OnSerialize(IOChannel channel)
805 OldLink node = first;
807 if(!class_data(type))
808 class_data(type) = eSystem_FindClass(__thisModule.application, class_data(typeName));
809 type = class_data(type);
816 channel.Serialize(truth);
817 if(type.type == bitClass || type.type == unitClass || (type.type == systemClass && type.typeSize))
818 type._vTbl[__ecereVMethodID_class_OnSerialize](type, &node.data, channel);
820 type._vTbl[__ecereVMethodID_class_OnSerialize](type, node.data, channel);
826 channel.Serialize(truth);
833 int OnCompare(DataList b)
835 OldLink nodeA = first, nodeB = b.first;
836 for(; nodeA || nodeB; nodeA = nodeA ? nodeA.next : null, nodeB = nodeB ? nodeB.next : null)
839 if(nodeA && !nodeB) return 1;
840 else if(nodeB && !nodeA) return -1;
843 Class type = class_data(type);
844 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
845 (type.type == systemClass || type.type == bitClass || type.type == enumClass || type.type == unitClass) ? &nodeA.data : (void *)nodeA.data,
846 (type.type == systemClass || type.type == bitClass || type.type == enumClass || type.type == unitClass) ? &nodeB.data : (void *)nodeB.data);
847 if(result) return result;
853 Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
860 anchor = { 0, 0, 0, 0 };
862 bool OnKeyHit(Key key, unichar ch)
864 return (key == enter) ? false : ListBox::OnKeyHit(key, ch);
867 bool DataBox::NotifyChanged(ListBox listBox, DataRow row)
869 Class type = ((subclass(DataList))this.type).dataType;
870 if(type.type == normalClass && !strcmp(type.dataTypeString, "char *"))
872 String string = row.GetData(null);
873 if(!string || !string[0])
877 listBox.DeleteRow(row);
878 listBox.firstChild.Activate();
883 if(row == listBox.lastRow)
885 /*row = listBox.AddRow();
886 row.SetData(null, null);
887 listBox.scroll.y = listBox.scrollArea.h;*/
893 listBox.SelectRow(row);
900 bool DataBox::NotifyModified(ListBox listBox, DataRow row)
902 Class type = ((subclass(DataList))this.type).dataType;
903 if(type.type == normalClass && !strcmp(type.dataTypeString, "char *"))
905 String string = row.GetData(null);
906 if(!string || !string[0])
910 listBox.DeleteRow(row);
911 listBox.firstChild.Activate();
916 if(row == listBox.lastRow)
918 row = listBox.AddRow();
919 row.SetData(null, null);
920 listBox.scroll.y = listBox.scrollArea.h;
922 else if(row.next == listBox.lastRow)
923 listBox.scroll.y = listBox.scrollArea.h;
930 bool DataBox::NotifyEditing(ListBox listBox, DataRow row)
932 Class type = ((subclass(DataList))this.type).dataType;
933 DataBox editData = (DataBox)listBox.firstChild;
934 // if(type.type != normalClass || strcmp(type.dataTypeString, "char *"))
938 if(type.type == normalClass && !*(void **)editData.data && strcmp(type.dataTypeString, "char *"))
940 *(void **)editData.data = eInstance_New(type);
941 row.SetData(null, *(void **)editData.data);
945 if(row == listBox.lastRow)
947 listBox.alwaysEdit = false;
948 if(type.type == normalClass || type.type == structClass || type.type == noHeadClass)
949 listBox.AddRow().SetData(null, null);
951 listBox.AddRow().SetData(null, 0);
952 listBox.scroll.y = listBox.scrollArea.h;
953 listBox.alwaysEdit = true;
959 bool DataBox::NotifyEdited(ListBox listBox, DataRow row)
961 listBox.firstChild.Activate();
965 bool DataBox::NotifyEditDone(ListBox listBox, DataRow row)
967 Class type = ((subclass(DataList))this.type).dataType;
968 // if(type.type != normalClass || strcmp(type.dataTypeString, "char *"))
971 void * data = ((type.type == normalClass || type.type == noHeadClass || type.type == structClass) ? row.GetData(null) : *(uint *)row.GetData(null));
974 //if(strcmp(type.dataTypeString, char *"))
975 //listBox.currentRow = null;
976 if(row != listBox.lastRow)
978 listBox.alwaysEdit = false;
979 listBox.DeleteRow(row);
980 listBox.alwaysEdit = true;
990 Class type = firstField.dataType;
991 // if(type.type != normalClass || strcmp(type.dataTypeString, "char *"))
994 if(type.type == normalClass && strcmp(type.dataTypeString, "char *"))
995 eInstance_Delete(lastRow.GetData(null));
996 if(type.type == normalClass || type.type == structClass || type.type == noHeadClass)
997 lastRow.SetData(null, null);
999 lastRow.SetData(null, 0);
1007 if(!class_data(type))
1008 class_data(type) = eSystem_FindClass(__thisModule.application, class_data(typeName));
1009 type = class_data(type);
1011 list.AddField({ type, editable = true });
1012 for(node = first; node; node = node.next)
1017 if(type.type == normalClass && !strcmp(type.dataTypeString, "char *"))
1018 r.SetData(null, CopyString((String)node.data));
1020 r.SetData(null, node.data);
1024 if(type.type == normalClass || type.type == structClass || type.type == noHeadClass)
1025 r.SetData(null, null);
1029 list.modifiedDocument = false;
1033 bool OnSaveEdit(Window window, void * object)
1035 ListBox list = (ListBox) window;
1036 if(list.modifiedDocument)
1038 Class type = class_data(type);
1040 if(list.activeChild)
1041 ((DataBox)list.activeChild).SaveData();
1043 if(type.type != normalClass || !strcmp(type.dataTypeString, "char *"))
1045 else if(type.type == structClass)
1046 Free(OldLink::Free);
1050 for(r = list.firstRow; r; r = r.next)
1052 if(type.type == noHeadClass || type.type == normalClass || type.type == structClass)
1054 void * data = r.GetData(null);
1057 if(type.type == normalClass && !strcmp(type.dataTypeString, "char *"))
1058 Add(OldLink { data = CopyString(data) });
1059 else if(type.type == structClass)
1061 OldLink link { data = new byte[type.structSize] };
1063 memcpy(link.data, data, type.structSize);
1066 Add(OldLink { data = data });
1071 uint i = r.GetData(null);
1073 Add(OldLink { data = (void *)i });
1086 if(!class_data(type))
1087 class_data(type) = eSystem_FindClass(__thisModule.application, class_data(typeName));
1088 type = class_data(type);
1091 // TO STUDY: ONFREE SHOULD BE USED ONLY FOR LISTBOX?
1094 if(type.type == normalClass && strcmp(type.dataTypeString, "char *"))
1095 eInstance_Delete(node.data);
1096 else if(type.type == structClass)
1099 type._vTbl[__ecereVMethodID_class_OnFree](type, node.data);