1 namespace gui::controls;
5 static define branchesColor = Color { 85, 85, 85 };
6 static define headerCollapseForeground = Color { 135, 135, 135 };
7 static define dataBoxBackground = Color { 67, 134, 198 };
8 static define dataBoxForeground = lightYellow;
10 #define SNAPDOWN(x, d) \
13 if(x < 0) x -= ((d) - Abs(x) % (d)); else x -= x % (d); \
18 static class ListBoxCell : struct
20 ListBoxCell prev, next;
26 #define RESIZE_BORDER 5
32 bool header:1, freeSelect:1 /*Exclusive to ELS_MULTISELECT*/, fullRowSelect:1, multiSelect:1, autoScroll:1, alwaysHL : 1, moveRows:1, resizable:1;
33 bool moveFields:1, clearHeader:1, alwaysEdit:1, collapse:1, treeBranch:1, rootCollapse:1, heightSet:1;
34 bool sortable:1, noDragging:1, fillLastField:1, expandOnAdd:1;
37 public class DataDisplayFlags
39 public bool selected:1, fullRow:1, current:1, active:1, dropBox:1, header:1, firstField:1;
42 enum SelectedFlag { unselected, selected, tempSelected, tempUnselected };
45 extern int __ecereVMethodID_class_OnEdit;
46 extern int __ecereVMethodID_class_OnDisplay;
47 extern int __ecereVMethodID_class_OnGetString;
48 extern int __ecereVMethodID_class_OnFree;
49 extern int __ecereVMethodID_class_OnCompare;
50 extern int __ecereVMethodID_class_OnCopy;
51 extern int __ecereVMethodID_class_OnSaveEdit;
55 public class DataField
58 property Class dataType
60 set { dataType = value; if(value) alignment = value.defaultAlignment; }
61 get { return dataType; }
63 property bool editable { set { editable = value; } };
64 property Alignment alignment
69 if(headButton) headButton.alignment = value;
70 if(listBox) listBox.Update(null);
77 width = Max(value, -EXTRA_SPACE);
79 listBox.AdaptToFieldWidth(this, false);
83 property int index { get { return this ? index : 0; } };
92 for(field = listBox.fields.first; field; field = field.next)
94 if(index == value - 2)
107 for(field = listBox.fields.first; field; field = field.next)
119 property int sortOrder { get { return this ? sortOrder : 0; } };
120 property char * header
126 headButton.text = header;
129 property void * userData
137 return this ? userData : null;
140 property bool freeData
142 set { freeData = value; } get { return freeData; }
144 property DataField prev { get { return prev; } };
145 property DataField next { get { return next; } };
147 void Move(DataField after)
154 listBox.fields.Move(this, after);
157 listBox.OnResize(listBox.clientSize.w, listBox.clientSize.h);
158 listBox.Update(null);
165 // property::dataType = "String";
166 property::dataType = "char *";
178 headButton.Destroy(0);
183 listBox.fields.Remove(this);
184 for(field = listBox.fields.first; field; field = field.next)
186 if(field.index >= index)
189 if(listBox.currentField == this)
190 listBox.currentField = null;
192 listBox.OnResize(listBox.clientSize.w, listBox.clientSize.h);
197 DataField prev, next;
217 property int tag { set { tag = value; } get { return tag; } };
218 property DataRow previous { get { return prev; } };
219 property DataRow next { get { return next; } };
220 property int index { get { return (this && (!parent || parent.IsExpanded())) ? index : -1; } };
221 property char * string
223 set { SetData(listBox.fields.first, value); }
224 get { return GetData(listBox.fields.first); }
226 property bool isHeader { set { header = value; } get { return this ? header : false; } };
227 property BitmapResource icon { set { icon = value; } get { return icon; } };
228 property bool collapsed
232 if(collapsed != value)
235 if(parent.IsExpanded())
242 for(search = subRows.first; search; search = search.next)
243 search.selectedFlag = 0;
245 if(listBox.clickedRow && !listBox.clickedRow.parent.IsExpanded())
247 listBox.clickedRow = GetNextRow();
248 if(!listBox.clickedRow)
249 listBox.clickedRow = this;
251 if(listBox.currentRow && !listBox.currentRow.parent.IsExpanded())
253 listBox.SetCurrentRow(this, true);
255 if(listBox.firstRowShown && !listBox.firstRowShown.parent.IsExpanded())
257 listBox.firstRowShown = GetPrevRow();
258 if(!listBox.firstRowShown)
259 listBox.firstRowShown = this;
263 // TODO: FIX row indices
264 index = this.index+1;
265 for(search = GetNextRow(); search; search = search.GetNextRow())
266 search.index = index++;
267 listBox.rowCount = index;
269 listBox.HideEditBox(false, false, true);
271 listBox.SetScrollArea(
273 (listBox.rowCount * listBox.rowHeight) +
274 ((listBox.style.header) ? listBox.rowHeight : 0) -
275 ((!((listBox.clientSize.h+1) % listBox.rowHeight)) ? listBox.rowHeight : 0), true);
276 listBox.Update(null);
277 listBox.NotifyCollapse(listBox.master, listBox, this, value);
281 get { return this ? collapsed : false; }
283 property bool selected
289 selectedFlag = value ? selected : unselected;
290 listBox.Update(null);
293 get { return selectedFlag == selected || selectedFlag == tempSelected; }
295 property DataRow parent
302 DataRow after = value ? value.subRows.last : listBox.rows.last;
303 if(parent.IsExpanded())
305 for(search = GetNextRow(); search; search = search.GetNextRow())
310 listBox.HideEditBox(false, false, true);
313 if(this == listBox.clickedRow)
315 listBox.clickedRow = GetNextRow();
316 if(!listBox.clickedRow)
317 listBox.clickedRow = GetPrevRow();
320 if(this == listBox.currentRow)
322 DataRow newCurrentRow = GetNextRow();
323 if(!listBox.newCurrentRow)
324 listBox.newCurrentRow = GetPrevRow();
325 listBox.SetCurrentRow(newCurrentRow, true);
328 if(this == listBox.firstRowShown)
330 listBox.firstRowShown = GetPrevRow();
331 if(!listBox.firstRowShown)
332 listBox.firstRowShown = GetNextRow();
336 (parent ? parent.subRows : listBox.rows).Remove(this);
339 value.subRows.Insert(after, this);
341 listBox.rows.Insert(after, this);
345 if(value && listBox.style.expandOnAdd)
346 value.collapsed = false;
348 if(value.IsExpanded(this))
352 if(after && after.subRows.first && !after.collapsed)
354 for(search = after.subRows.last; !search.collapsed && search.subRows.last; )
355 search = search.subRows.last;
356 index = search.index + 1;
359 index = after ? (after.index + 1) : (index + 1);
363 for(search = GetNextRow(); search; search = search.GetNextRow())
366 listBox.SetScrollArea(
368 (listBox.rowCount * listBox.rowHeight) +
369 ((listBox.style.header) ? listBox.rowHeight : 0) -
370 ((!((listBox.clientSize.h+1) % listBox.rowHeight)) ? listBox.rowHeight : 0), true);
371 if(listBox.style.autoScroll)
372 listBox.SetScrollPosition(0, MAXINT - listBox.rowHeight);
374 // TESTING THIS HERE...
376 listBox.Sort(listBox.sortField, listBox.sortField.sortOrder);
379 int headerSize = ((listBox.style.header) ? listBox.rowHeight : 0);
380 int height = listBox.clientSize.h + 1 - headerSize;
381 if(listBox.currentRow && listBox.currentRow.index * listBox.rowHeight > listBox.scroll.y + height - listBox.rowHeight)
382 listBox.SetScrollPosition(listBox.scroll.x, listBox.currentRow.index * listBox.rowHeight - height + listBox.rowHeight);
383 else if(!listBox.currentRow || listBox.currentRow.index * listBox.rowHeight < listBox.scroll.y)
385 int line = listBox.currentRow ? listBox.currentRow.index * listBox.rowHeight : 0;
386 listBox.SetScrollPosition(listBox.scroll.x, line);
389 listBox.OnVScroll(0, listBox.scroll.y, 0);
391 listBox.Update(null);
399 property DataRow lastRow { get { return this ? subRows.last : null; } };
400 property DataRow firstRow { get { return this ? subRows.first : null; } };
402 void Edit(DataField field)
408 if(!field || !field.editable)
410 for(field = listBox.fields.first; field; field = field.next)
411 if(field.editable) break;
413 if(field && field.editable)
415 listBox.SetCurrentRow(this, true);
416 listBox.PopupEditBox(field, false);
422 void Move(DataRow after)
427 if(listBox && prev != after)
431 int headerSize = ((listBox.style.header) ? listBox.rowHeight : 0);
432 int height = listBox.clientSize.h + 1 - headerSize;
434 if(!after || after.index < index)
436 if(after == listBox.firstRowShown.prev)
437 listBox.firstRowShown = this;
439 // All rows between AFTER (exclusive) and ROW (exclusive) are incremented by one
440 // ROW is equal to AFTER's index + 1
443 for(search = after ? after.next : listBox.rows.first; search && search != this; search = search.GetNextRow())
446 if(after && after.subRows.first && !after.collapsed)
448 for(search = after.subRows.last; !search.collapsed && search.subRows.last; )
449 search = search.subRows.last;
450 index = search.index + 1;
453 index = after ? (after.index + 1) : 0;
457 if(this == listBox.firstRowShown)
459 listBox.firstRowShown = GetNextRow();
462 // All rows between ROW (exclusive) and AFTER (inclusive) are decremented by one
463 // ROW is equal to AFTER's index
466 for(search = GetNextRow(); search; search = search.GetNextRow())
469 if(search == after) break;
471 index = after ? (after.index + 1) : 0;
473 listBox.rows.Move(this, after);
475 listBox.HideEditBox(true, false, true);
478 if(listBox.currentRow && listBox.currentRow.index * listBox.rowHeight > listBox.scroll.y + height - listBox.rowHeight)
479 listBox.SetScrollPosition(listBox.scroll.x, listBox.currentRow.index * listBox.rowHeight - height + listBox.rowHeight);
480 else if(!listBox.currentRow || listBox.currentRow.index * listBox.rowHeight < listBox.scroll.y)
482 int line = listBox.currentRow ? listBox.currentRow.index * listBox.rowHeight : 0;
483 //SNAPUP(line, listBox.rowHeight);
484 listBox.SetScrollPosition(listBox.scroll.x, line);
487 listBox.OnVScroll(0, listBox.scroll.y, 0);
489 listBox.modifiedDocument = true;
491 listBox.Update(null);
498 any_object GetData(DataField field)
502 ListBoxCell cell = listBox.GetCell(&this, &field);
503 if(cell && cell.isSet && cell.data)
505 if((field.dataType.type == normalClass || field.dataType.type == noHeadClass))
508 return (void *)cell.data; // Cast for MemoryGuard
514 void * SetData(DataField field, any_object newData)
518 ListBoxCell cell = listBox.GetCell(&this, &field);
521 Class dataType = field.dataType;
525 if(dataType.type == normalClass || dataType.type == noHeadClass)
527 if(cell.data[0] && field.freeData)
528 dataType._vTbl[__ecereVMethodID_class_OnFree](dataType, cell.data[0]);
530 if(eClass_IsDerived(dataType, class(char *)) && field.freeData)
531 dataType._vTbl[__ecereVMethodID_class_OnCopy](dataType, cell.data, newData);
533 cell.data[0] = (void *)newData;
537 // Free old data first
538 dataType._vTbl[__ecereVMethodID_class_OnFree](dataType, cell.data);
539 dataType._vTbl[__ecereVMethodID_class_OnCopy](dataType, cell.data, newData);
543 listBox.modifiedDocument = true;
544 listBox.Update(null);
545 if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
546 return (void *)cell.data; // Cast for MemoryGuard
554 void UnsetData(DataField field)
558 ListBoxCell cell = listBox.GetCell(&this, &field);
561 Class dataType = field.dataType;
565 if(dataType.type == normalClass || dataType.type == noHeadClass)
567 if(cell.data[0] && field.freeData)
568 dataType._vTbl[__ecereVMethodID_class_OnFree](dataType, cell.data[0]);
573 // Free old data first
574 dataType._vTbl[__ecereVMethodID_class_OnFree](dataType, cell.data);
578 listBox.Update(null);
583 DataRow FindRow(int tag)
586 for(row = subRows.first; row; row = row.next)
588 if(!row.noneRow && row.tag == tag)
594 DataRow FindSubRow(int tag)
597 for(row = subRows.first; row; row = row.next)
599 if(!row.noneRow && row.tag == tag)
601 if(row.subRows.first)
603 DataRow subRow = row.FindSubRow(tag);
611 DataRow AddRowAfter(DataRow after)
621 subRows.Insert(after, row);
622 row.listBox = listBox;
626 for(c = 0; c<listBox.fields.count; c++)
628 for(field = listBox.fields.first; field; field = field.next)
629 if((int)field.index == c)
633 int size = (field.dataType && field.dataType.typeSize) ?
634 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
635 ListBoxCell cell = (ListBoxCell)new0 byte[size];
637 FillBytes(cell.data, 0, size - (uint)&((ListBoxCell)0).data);
646 if(after && after.subRows.first && !after.collapsed)
648 for(search = after.subRows.last; !search.collapsed && search.subRows.last; )
649 search = search.subRows.last;
650 row.index = search.index + 1;
653 row.index = after ? (after.index + 1) : (index + 1);
658 for(search = row.GetNextRow(); search; search = search.GetNextRow())
661 listBox.SetScrollArea(
663 (listBox.rowCount * listBox.rowHeight) +
664 ((listBox.style.header) ? listBox.rowHeight : 0) -
665 ((!((listBox.clientSize.h+1) % listBox.rowHeight)) ? listBox.rowHeight : 0), true);
666 if(listBox.style.autoScroll)
667 listBox.SetScrollPosition(0, MAXINT - listBox.rowHeight);
670 listBox.modifiedDocument = true;
680 return AddRowAfter(subRows.last);
684 DataRow AddStringf(char * format, ...)
689 char string[MAX_F_STRING];
692 va_start(args, format);
693 vsprintf(string, format, args);
697 row.SetData(null, string);
703 DataRow AddString(char * string)
709 row.SetData(listBox.fields.first, string);
719 subRows.offset = (uint)&((DataRow)0).prev;
724 ListBoxCell cell, next;
729 while((subRow = subRows.first))
731 subRows.Remove(subRow);
735 for(cell = cells.first; cell; cell = next, cellIndex++)
740 for(field = listBox.fields.first; field && field.index != cellIndex; field = field.next);
741 if(field.dataType && _vTbl[__ecereVMethodID_class_OnFree])
743 // TOCHECK: Is this check good? Will need incref/decref sometime?
744 if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
746 if(cell.data[0] && field.freeData)
747 field.dataType._vTbl[__ecereVMethodID_class_OnFree](field.dataType, cell.data[0]);
750 field.dataType._vTbl[__ecereVMethodID_class_OnFree](field.dataType, cell.data);
760 return !this || (!collapsed && (!parent || parent.IsExpanded()));
763 int Compare(DataRow b, DataField sortField)
766 ListBoxCell cell1, cell2;
768 for(index = 0, cell1 = cells.first, cell2 = b.cells.first;
769 index != sortField.index;
770 index++, cell1 = cell1.next, cell2 = cell2.next);
772 if(!cell1.isSet && !cell2.isSet)
774 else if(!cell1.isSet)
776 else if(!cell2.isSet)
779 if(noneRow && !b.noneRow) return -1;
780 else if(!noneRow && b.noneRow) return 1;
781 else if(noneRow && b.noneRow) return 0;
783 if(sortField.dataType._vTbl[__ecereVMethodID_class_OnCompare])
785 if(sortField.dataType.type == normalClass || sortField.dataType.type == noHeadClass)
787 result = sortField.dataType._vTbl[__ecereVMethodID_class_OnCompare](sortField.dataType,
788 (cell1.isSet && cell1.data) ? cell1.data[0] : null,
789 (cell2.isSet && cell2.data) ? cell2.data[0] : null);
793 result = sortField.dataType._vTbl[__ecereVMethodID_class_OnCompare](sortField.dataType,
794 cell1.isSet ? cell1.data : null,
795 cell2.isSet ? cell2.data : null);
798 return sortField.sortOrder * result;
801 void _SortSubRows(DataField field, int order)
804 for(search = subRows.first; search; search = search.next)
805 search._SortSubRows(field, order);
806 subRows.Sort(Compare, field);
809 public void SortSubRows(bool scrollToCurrent)
811 if(this && listBox && listBox.sortField)
813 _SortSubRows(listBox.sortField, listBox.sortField.sortOrder);
815 // TODO: Recompute row indices
818 int index = this.index;
819 for(search = this; search; search = search.GetNextRow())
820 search.index = index++;
824 int headerSize = ((listBox.style.header) ? listBox.rowHeight : 0);
825 int height = listBox.clientSize.h + 1 - headerSize;
826 if(listBox.currentRow && listBox.currentRow.index * listBox.rowHeight > listBox.scroll.y + height - listBox.rowHeight)
827 listBox.SetScrollPosition(listBox.scroll.x, listBox.currentRow.index * listBox.rowHeight - height + listBox.rowHeight);
828 else if(!listBox.currentRow || listBox.currentRow.index * listBox.rowHeight < listBox.scroll.y)
829 listBox.SetScrollPosition(listBox.scroll.x, listBox.currentRow ? listBox.currentRow.index * listBox.rowHeight : 0);
830 listBox.OnVScroll(0, listBox.scroll.y, 0);
835 public DataRow GetPrevRow()
841 for(row = prev; row && !row.collapsed && row.subRows.last; row = row.subRows.last);
848 public DataRow GetNextRow()
852 if(subRows.first && !collapsed)
856 for(row = this; row; row = row.parent)
858 if(row.next) { row = row.next; break; }
867 SelectedFlag selectedFlag;
878 public class ListBox : CommonControl
880 hasVertScroll = true;
881 // background = white;
883 snapVertScroll = true;
885 class_property(icon) = "<:ecere>controls/listBox.png";
889 property bool freeSelect { property_category "Behavior" set { style.freeSelect = value; } get { return style.freeSelect; } };
890 property DataRow currentRow { property_category "Private" /*"Behavior"*/ set { SetCurrentRow(value, false); } get { return currentRow; } };
891 property DataField currentField
893 get { return currentField; }
894 // TODO: Needs definition of what this is, testing
897 currentField = value;
898 HideEditBox(true, true, false);
899 if(value && value.editable)
900 PopupEditBox(currentField, false);
904 property int rowHeight
906 property_category "Appearance"
907 isset { return style.heightSet; }
912 style.heightSet = true;
914 SetScrollLineStep(8, value);
918 style.heightSet = false;
923 get { return rowHeight; }
925 property Seconds typingTimeout
927 property_category "Behavior"
930 typedString[0] = '\0';
931 typingTimer.delay = value;
932 typingTimeOut = value;
934 get { return typingTimeOut; }
936 property bool moveRows { property_category "Behavior" set { style.moveRows = value; } get { return style.moveRows; } };
937 property bool moveFields { property_category "Behavior" set { style.moveFields = value; } get { return style.moveFields; } };
938 property bool resizable { property_category "Behavior" set { style.resizable = value; } get { return style.resizable; } };
939 property bool autoScroll { property_category "Behavior" set { style.autoScroll = value; } get { return style.autoScroll; } };
940 property bool alwaysHighLight { property_category "Appearance" set { style.alwaysHL = value; } get { return style.alwaysHL; } };
941 property bool hasClearHeader { property_category "Appearance" set { style.clearHeader = value; if(value) property::hasHeader = true; } get { return style.clearHeader; } };
942 property bool hasHeader
944 property_category "Appearance"
947 if(value && !style.header)
953 bevel = !guiApp.textMode && !style.clearHeader;
954 dontScrollVert = true;
957 NotifyPushed = HeaderPushed;
958 NotifyClicked = HeaderClicked;
959 NotifyReleased = HeaderReleased;
960 NotifyMouseMove = HeaderMouseMove;
964 endBevel.visible = false;
966 style.header = value;
968 get { return style.header; }
970 property bool multiSelect { property_category "Behavior" set { style.multiSelect = value; } get { return style.multiSelect; } };
971 property bool alwaysEdit { property_category "Behavior" set { style.alwaysEdit = value; } get { return style.alwaysEdit; } };
972 property bool fullRowSelect { property_category "Appearance" set { style.fullRowSelect = value; } get { return style.fullRowSelect; } };
973 property bool collapseControl { property_category "Appearance" set { style.collapse = value; } get { return style.collapse; } };
974 property bool treeBranches { property_category "Appearance" set { style.treeBranch = value; } get { return style.treeBranch; } };
975 property bool rootCollapseButton { property_category "Appearance" set { style.rootCollapse = value; } get { return style.rootCollapse; } };
976 property bool sortable { property_category "Behavior" set { style.sortable = value; } get { return style.sortable; } };
977 property bool noDragging { property_category "Behavior" set { style.noDragging = value; } get { return style.noDragging; } };
978 property bool fillLastField
980 property_category "Behavior"
983 style.fillLastField = value;
985 get { return style.fillLastField; }
987 property int numSelections
991 int numSelections = 0;
992 if(this && style.multiSelect)
995 for(row = rows.first; row; row = row.GetNextRow())
996 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
999 return numSelections;
1002 property int currentIndex
1004 get { return currentRow ? currentRow.index : -1; }
1006 property DataRow lastRow { get { return this ? rows.last : null; } };
1007 property DataRow firstRow { get { return this ? rows.first : null; } };
1008 property int rowCount { get { return rowCount; } };
1009 property DataField firstField { get { return this ? fields.first : null; } };
1010 property Color selectionColor { set { selectionColor = value; } get { return selectionColor; } isset { return selectionColor ? true : false; } };
1011 property Color selectionText { set { selectionText = value; } get { return selectionText; } isset { return selectionText ? true : false; } };
1012 property Color stippleColor { set { stippleColor = value; } get { return stippleColor; } };
1013 property bool expandOnAdd { set { style.expandOnAdd = value; } get { return style.expandOnAdd; } };
1016 virtual bool Window::NotifySelect(ListBox listBox, DataRow row, Modifiers mods);
1017 virtual bool Window::NotifyHighlight(ListBox listBox, DataRow row, Modifiers mods);
1018 virtual bool Window::NotifyReclick(ListBox listBox, DataRow row, Modifiers mods);
1019 virtual bool Window::NotifySort(ListBox listBox, DataField field, Modifiers mods);
1020 virtual bool Window::NotifyChanged(ListBox listBox, DataRow row);
1021 virtual bool Window::NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch);
1022 virtual bool Window::NotifyEdited(ListBox listBox, DataRow row);
1023 virtual bool Window::NotifyEditDone(ListBox listBox, DataRow row);
1024 virtual bool Window::NotifyMovedField(ListBox listBox, DataField field, Modifiers mods);
1025 virtual bool Window::NotifyMove(ListBox listBox, DataRow row, Modifiers mods);
1026 virtual bool Window::NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods);
1027 virtual bool Window::NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods);
1028 virtual bool Window::NotifyResized(ListBox listBox, DataField field, Modifiers mods);
1029 virtual bool Window::NotifyCollapse(ListBox listBox, DataRow row, bool collapsed);
1030 virtual bool Window::NotifyKeyHit(ListBox listBox, DataRow row, Key key, unichar ch);
1031 virtual bool Window::NotifyModified(ListBox listBox, DataRow row);
1032 virtual bool Window::NotifyEditing(ListBox listBox, DataRow row);
1035 void AddField(DataField addedField)
1040 if(fields.first && ((DataField)fields.first).defaultField)
1042 DataField defaultField = fields.first;
1044 defaultField.Free();
1045 delete defaultField;
1049 addedField = DataField { };
1053 addedField.listBox = this;
1054 fields.Add(addedField);
1056 addedField.sortOrder = 1;
1057 addedField.index = numFields;
1061 addedField.headButton.Destroy(0);
1062 delete addedField.headButton;
1063 addedField.headButton = Button
1068 dontScrollVert = true;
1069 id = (uint)addedField;
1070 text = addedField.header;
1071 bevel = (!guiApp.textMode && !style.clearHeader);
1073 alignment = addedField.alignment;
1074 NotifyPushed = HeaderPushed;
1075 NotifyClicked = HeaderClicked;
1076 NotifyReleased = HeaderReleased;
1077 NotifyMouseMove = HeaderMouseMove;
1079 incref addedField.headButton;
1080 addedField.headButton.Create();
1083 addedField.headButton.background = Color { 0, 170, 0 };
1089 for(row = rows.first; row; )
1091 int size = (field.dataType && field.dataType.typeSize) ?
1092 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1093 ListBoxCell cell = (ListBoxCell)new0 byte[size];
1094 row.cells.Add(cell);
1095 FillBytes(cell.data, 0, size - (uint)&((ListBoxCell)0).data);
1098 if(row.subRows.first)
1099 row = row.subRows.first;
1102 for(; row; row = row.parent)
1104 if(row.next) { row = row.next; break; }
1109 OnResize(clientSize.w, clientSize.h);
1118 while((field = fields.first))
1124 endBevel.visible = false;
1129 void RemoveField(DataField field)
1135 int index = field.index;
1138 for(row = rows.first; row; )
1143 for(cell = row.cells.first, c = 0; c < index && cell; c++, cell = cell.next);
1144 if(cell && index == c)
1148 // TOCHECK: Is this check good? Will need incref/decref sometime?
1149 if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
1151 if(cell.data[0] && field.freeData)
1152 field.dataType._vTbl[__ecereVMethodID_class_OnFree](field.dataType, cell.data[0]);
1155 field.dataType._vTbl[__ecereVMethodID_class_OnFree](field.dataType, cell.data);
1158 row.cells.Remove(cell);
1162 if(row.subRows.first)
1163 row = row.subRows.first;
1166 for(; row; row = row.parent)
1168 if(row.next) { row = row.next; break; }
1177 endBevel.visible = false;
1181 DataRow AddRowNone()
1183 DataRow row { noneRow = true };
1192 rows.Insert(null, row);
1195 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1201 firstRowShown = row;
1205 (rowCount * rowHeight) +
1206 ((style.header) ? rowHeight : 0) -
1207 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1208 if(style.autoScroll)
1209 SetScrollPosition(0, MAXINT - rowHeight);
1210 modifiedDocument = true;
1229 // Find very last row
1232 for(lastRow = rows.last; lastRow && !lastRow.collapsed && lastRow.subRows.last; lastRow)
1233 lastRow = lastRow.subRows.last;
1234 row.index = lastRow ? (lastRow.index + 1) : 0;
1242 for(c = 0; c<fields.count; c++)
1244 for(field = fields.first; field; field = field.next)
1245 if((int)field.index == c)
1249 int size = (field.dataType && field.dataType.typeSize) ?
1250 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1251 ListBoxCell cell = (ListBoxCell) new0 byte[size];
1252 row.cells.Add(cell);
1253 FillBytes(cell.data, 0, size - (uint)&((ListBoxCell)0).data);
1260 firstRowShown = row;
1266 (rowCount * rowHeight) +
1267 ((style.header) ? rowHeight : 0) -
1268 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1269 if(style.autoScroll)
1270 SetScrollPosition(0, MAXINT - rowHeight);
1271 modifiedDocument = true;
1279 DataRow AddRowAfter(DataRow after)
1291 if(after && after.subRows.first && !after.collapsed)
1293 for(search = after.subRows.last; !search.collapsed && search.subRows.last; )
1294 search = search.subRows.last;
1295 row.index = search.index + 1;
1298 row.index = after ? (after.index + 1) : 0;
1299 rows.Insert(after, row);
1302 // TODO: FIX row indices
1303 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1308 for(c = 0; c<fields.count; c++)
1310 for(field = fields.first; field; field = field.next)
1311 if((int)field.index == c)
1315 int size = (field.dataType && field.dataType.typeSize) ?
1316 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1317 ListBoxCell cell = (ListBoxCell) new0 byte[size];
1318 row.cells.Add(cell);
1319 FillBytes(cell.data, 0, size - (uint)&((ListBoxCell)0).data);
1323 if(!firstRowShown || !after)
1325 firstRowShown = row;
1330 (rowCount * rowHeight) +
1331 ((style.header) ? rowHeight : 0) -
1332 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1333 if(style.autoScroll)
1334 SetScrollPosition(0, MAXINT - rowHeight);
1335 modifiedDocument = true;
1342 DataRow AddStringf(char * format, ...)
1348 char string[MAX_F_STRING];
1351 va_start(args, format);
1352 vsprintf(string, format ? format : "", args);
1356 row.SetData(fields.first, string);
1362 DataRow AddString(char * string)
1368 row.SetData(fields.first, string);
1374 void SelectRow(DataRow row)
1376 SetCurrentRow(row, true);
1379 void DeleteRow(DataRow row)
1381 if(!row) row = currentRow;
1385 // Trying to move this here (Messed up deleting watches)
1386 //HideEditBox(false, false, true);
1387 if(row.parent.IsExpanded())
1389 // TODO: FIX row indices
1390 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1395 HideEditBox(false, false, true);
1397 if(row == clickedRow)
1399 clickedRow = row.GetNextRow();
1401 clickedRow = row.GetPrevRow();
1404 if(row == currentRow)
1406 DataRow newCurrentRow = row.GetNextRow();
1408 newCurrentRow = row.GetPrevRow();
1409 SetCurrentRow(newCurrentRow, true);
1412 if(row == firstRowShown)
1414 firstRowShown = row.GetPrevRow();
1416 firstRowShown = row.GetNextRow();
1419 (row.parent ? row.parent.subRows: rows).Remove(row);
1422 //HideEditBox(false, false, true);
1426 (this.rowCount * rowHeight) +
1427 ((style.header) ? rowHeight : 0) -
1428 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1430 modifiedDocument = true;
1436 DataRow FindRow(int tag)
1441 for(row = rows.first; row; row = row.next)
1443 if(!row.noneRow && row.tag == tag)
1451 DataRow FindString(char * searchedString)
1454 bool checkNextField = true;
1455 int len = searchedString ? strlen(searchedString) : 0;
1457 for(field = fields.first; field; field = field.next)
1459 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1462 for(row = rows.first; row; row = row.GetNextRow())
1466 void * data = row.GetData(field);
1467 char tempString[1024] = "";
1468 bool needClass = false;
1469 char * string = (char *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString](field.dataType, data, tempString, null, &needClass);
1471 if(string && string[0])
1472 checkNextField = false;
1473 if(string && string[0] && !strcmp(string, searchedString))
1478 if(!checkNextField) break;
1483 DataRow FindSubString(char * subString)
1486 bool checkNextField = true;
1487 int len = subString ? strlen(subString) : 0;
1491 for(field = fields.first; field; field = field.next)
1493 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1496 for(row = rows.first; row; row = row.GetNextRow())
1500 void * data = row.GetData(field);
1501 char tempString[1024] = "";
1502 bool needClass = false;
1503 char * string = (char *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString](field.dataType, data, tempString, null, &needClass);
1505 if(string && string[0])
1506 checkNextField = false;
1507 if(string && string[0] && !strncmp(string, subString, len))
1512 if(!checkNextField) break;
1518 DataRow FindSubStringi(char * subString)
1521 bool checkNextField = true;
1522 int len = subString ? strlen(subString) : 0;
1523 DataRow result = null;
1524 char * bestResult = null;
1529 for(field = fields.first; field; field = field.next)
1531 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1534 for(row = rows.first; row; row = row.GetNextRow())
1538 void * data = row.GetData(field);
1539 char tempString[1024] = "";
1540 bool needClass = false;
1541 char * string = (char *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString](field.dataType, data, tempString, null, &needClass);
1543 if(string && string[0])
1544 checkNextField = false;
1545 if(string && string[0])
1547 int stringLen = strlen(string);
1549 if(!strnicmp(string, subString, Min(len, stringLen)))
1551 if(bestLen < Min(len, stringLen))
1553 if(!bestResult || strcmpi(string, bestResult) < 0)
1555 bestLen = Min(len, stringLen);
1556 bestResult = string;
1564 if(!checkNextField) break;
1570 DataRow FindSubStringAfter(DataRow after, char * subString)
1573 bool checkNextField = true;
1574 int len = subString ? strlen(subString) : 0;
1578 for(field = fields.first; field; field = field.next)
1580 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1583 for(row = after.GetNextRow(); row && row != after; row = row.GetNextRow(), (!row) ? (row = rows.first) : null)
1587 void * data = row.GetData(field);
1588 char tempString[1024] = "";
1589 bool needClass = false;
1590 char * string = (char *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString](field.dataType, data, tempString, null, &needClass);
1592 if(string && string[0])
1593 checkNextField = false;
1594 if(string && string[0] && !strncmp(string, subString, len))
1599 if(!checkNextField) break;
1605 DataRow FindSubRow(int tag)
1611 for(row = rows.first; row; row = row.next)
1613 if(!row.noneRow && row.tag == tag)
1615 if(!row.noneRow && row.subRows.first)
1617 DataRow subRow = row.FindSubRow(tag);
1631 Window master = this.master;
1633 HideEditBox(false, true, false);
1634 editData.Destroy(0);
1636 firstRowShown = currentRow = null;
1641 if(style.freeSelect)
1642 NotifyHighlight(master, this, currentRow ? currentRow : null, 0);
1644 NotifySelect(master, this, currentRow ? currentRow : null, 0);
1647 if(style.alwaysEdit && currentRow)
1648 currentRow.Edit(currentField);
1655 (this.rowCount * rowHeight) +
1656 ((style.header) ? rowHeight : 0) -
1657 ((rowHeight && !((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1662 void Sort(DataField field, int order)
1667 int headerSize = ((style.header) ? rowHeight : 0);
1668 int height = clientSize.h + 1 - headerSize;
1670 if(!field) field = fields.first;
1672 field.sortOrder = order ? order : 1;
1673 rows.Sort(DataRow::Compare, field);
1675 for(search = rows.first; search; search = search.next)
1676 search._SortSubRows(field, order);
1678 // TODO: Recompute row indices
1681 for(search = rows.first; search; search = search.GetNextRow())
1682 search.index = index++;
1685 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
1686 SetScrollPosition(scroll.x, currentRow.index * rowHeight - height + rowHeight);
1687 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
1688 SetScrollPosition(scroll.x, currentRow ? currentRow.index * rowHeight : 0);
1690 OnVScroll(0, scroll.y, 0);
1692 // SetScrollPosition(0, scroll.y);
1697 void StopEditing(bool save)
1699 HideEditBox(save, false, true);
1702 void GetMultiSelection(OldList list)
1705 if(this && style.multiSelect)
1709 for(row = rows.first; row; row = row.GetNextRow())
1711 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
1713 list.Add(OldLink { data = row });
1719 // Convenience Current Row Methods
1720 void * SetData(DataField field, any_object data)
1722 return currentRow.SetData(field, data);
1725 any_object GetData(DataField field)
1727 return (void *)currentRow.GetData(field);
1732 return currentRow.tag;
1738 DataField defaultField { };
1739 rows.offset = (uint)&((DataRow)0).prev;
1740 fields.offset = (uint)&((DataField)0).prev;
1741 style.fullRowSelect = true;
1742 style.fillLastField = true;
1743 style.expandOnAdd = true;
1744 typingTimeOut = 0.5;
1745 rowHeight = 16; // Stuff depending on creation and default property checking
1748 defaultField.defaultField = true;
1750 AddField(defaultField);
1752 typedString = new char[1];
1753 typedString[0] = '\0';
1768 while((field = fields.first))
1770 // fields.Remove(field);
1779 while((row = rows.first))
1786 ListBoxCell GetCell(DataRow * row, DataField * field)
1788 ListBoxCell cell = null;
1789 if(!*row) *row = currentRow;
1792 if(!*field) *field = this ? currentField : null;
1795 for(*field = fields.first; (*field).index != 0; *field = (*field).next);
1800 if(field->listBox == this)
1802 for(index = 0, cell = (*row).cells.first; cell && index != (*field).index; index++, cell = cell.next);
1809 void HideEditBox(bool save, bool alwaysStopEdit, bool repositionOnly)
1811 if(editData && editData.visible)
1813 Class dataType = currentField.dataType;
1815 editData.SaveData();
1817 editData.visible = false;
1818 NotifyEditDone(master, this, currentRow);
1820 // ENSURE DATA BOX IS NOT VISIBLE
1821 editData.visible = false;
1823 if(style.alwaysEdit && !alwaysStopEdit)
1826 int height = rowHeight - (style.alwaysEdit ? 1 : 0);
1827 int y = currentRow.index * rowHeight + (style.header ? rowHeight : 0);
1828 int x = currentField.x;
1829 int width = (!currentField.next && style.fillLastField && (!hasHorzScroll || clientSize.w - currentField.x > currentField.width + EXTRA_SPACE)) ?
1830 clientSize.w - currentField.x : (currentField.width + EXTRA_SPACE);
1832 if(!style.alwaysEdit)
1834 editData.position = { x, y };
1835 editData.size = { width, height };
1839 editData.position = { x, y - editData.clientStart.y };
1840 editData.size = { width, height + editData.clientStart.y * 2 };
1842 editData.visible = true;
1843 if(style.alwaysEdit)
1844 editData.Deactivate();
1846 PopupEditBox(currentField, repositionOnly);
1852 currentField = null;*/
1856 void SetCurrentRow(DataRow row, bool notify)
1858 if(currentRow != row || (currentRow && currentRow.selectedFlag == unselected))
1860 int headerSize = ((style.header) ? rowHeight : 0);
1861 int height = clientSize.h + 1 - headerSize;
1863 // true: destroy edit box
1864 HideEditBox(true, true, false);
1866 if(!(style.multiSelect) && currentRow)
1867 currentRow.selectedFlag = unselected;
1871 if(style.multiSelect)
1875 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
1876 selRow.selectedFlag = unselected;
1877 currentRow.selectedFlag = selected;
1882 currentRow.selectedFlag = selected;
1884 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
1885 SetScrollPosition(scroll.x,
1886 currentRow.index * rowHeight - height + rowHeight);
1887 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
1889 int line = currentRow ? currentRow.index * rowHeight : 0;
1890 //SNAPUP(line, rowHeight);
1891 SetScrollPosition(scroll.x, line);
1896 Window master = this.master;
1899 if(style.freeSelect && visible)
1900 NotifyHighlight(master, this, currentRow ? currentRow : null, 0);
1902 NotifySelect(master, this, currentRow ? currentRow : null, 0);
1903 if(style.alwaysEdit && currentRow)
1904 currentRow.Edit(currentField);
1912 void PopupEditBox(DataField whichField, bool repositionOnly)
1914 if((!editData || !editData.visible || currentField != whichField) && currentRow)
1916 // true: destroy edit box
1917 HideEditBox(true, true, false);
1920 int height = rowHeight - (style.alwaysEdit ? 1 : 0);
1922 int y = currentRow.index * rowHeight + (style.header ? rowHeight : 0);
1924 //void * data = currentRow.GetData(whichField);
1929 if(style.collapse && !(style.treeBranch))
1932 for(field = fields.first; field; field = field.next)
1934 width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
1935 clientSize.w - field.x : (field.width + EXTRA_SPACE);
1936 if(field == whichField) break;
1940 currentField = whichField;
1941 cell = GetCell(&row, ¤tField);
1948 background = dataBoxBackground;
1949 foreground = dataBoxForeground;
1951 bool NotifyChanged(bool closingDropDown)
1954 DataField field = null;
1955 ListBoxCell cell = GetCell(&row, &field);
1959 modifiedDocument = true;
1961 NotifyChanged(master, this, currentRow);
1966 bool NotifyModified()
1968 //DataRow row = null;
1969 //DataField field = null;
1970 //ListBoxCell cell = GetCell(&row, &field);
1971 //cell.isSet = true;
1972 modifiedDocument = true;
1974 NotifyModified(master, this, currentRow);
1978 bool OnKeyDown(Key key, unichar ch)
1980 bool result = DataBox::OnKeyDown(key, ch);
1981 if(visible && active) // Added this check here, because we will not use enter/escape otherwise, and lose DataBox's result
1983 if((SmartKey)key == enter || (SmartKey)key == escape)
1992 editData.Destroy(0);
1993 editData.type = whichField.dataType;
1994 editData.fieldData = whichField.userData;
1995 editData.borderStyle = style.alwaysEdit ? 0 : deep;
1996 editData.data = cell ? cell.data : null;
1999 // Might not really need this anymore...
2000 NotifyEditing(master, this, currentRow);
2003 if(!style.alwaysEdit)
2005 editData.position = { x, y - editData.clientStart.y };
2006 editData.size = { width, height + editData.clientStart.y * 2 };
2010 editData.position = { x, y };
2011 editData.size = { width, height };
2015 editData.visible = true;
2017 if(style.alwaysEdit)
2018 editData.Deactivate();
2020 // MOVED THIS HIGHER FOR DATALIST EDITOR
2022 // Might not really need this anymore...
2023 NotifyEdited(master, this, currentRow);
2028 void OnRedraw(Surface surface)
2031 int y = (style.header) ? rowHeight : 0;
2032 bool isActive = active;
2033 Font font = fontObject;
2034 Font boldFont = this.boldFont.font;
2037 if(style.alwaysEdit && style.fullRowSelect)
2040 int y = (style.header) ? rowHeight : 0;
2041 int x = -scroll.x - 1;// + EXTRA_SPACE;// / 2 - 1;
2042 int w = clientSize.w;
2043 int h = clientSize.h;
2047 // Fill out indent column
2048 if(style.collapse && !(style.treeBranch) && rows.first)
2051 surface.SetBackground(activeBorder);
2052 surface.Area(-scroll.x, 0, x, clientSize.h);
2055 surface.SetForeground(activeBorder);
2056 for(row = firstRowShown; row; row = row.GetNextRow())
2059 surface.HLine(x + 1, w-1, y-1);
2065 for(field = fields.first; field; field = field.next)
2067 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2068 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2070 surface.VLine(0, y-1, x);
2075 surface.foreground = this.foreground;
2076 surface.TextOpacity(false);
2078 // Draw the tree branches
2079 if(style.treeBranch)
2081 int y = -scroll.y + ((style.header) ? rowHeight : 0);
2082 surface.LineStipple(0x5555);
2083 surface.SetForeground(branchesColor);
2084 for(row = rows.first; row; row = row.GetNextRow() )
2086 int x = -scroll.x + EXTRA_SPACE / 2-1;
2087 int rowStart = -scroll.x;
2092 for(parent = row.parent; parent; parent = parent.parent)
2093 if(!parent.header) indent += 20;
2094 if(style.rootCollapse) indent += 20;
2096 plusIndent = (style.treeBranch) ? (indent - 20 + 4) : indent;
2101 if(row.subRows.first)
2104 int y1 = y + PLUSY + 4;
2108 for(child = row.collapsed ? null : row.subRows.first; child && child != row; )
2111 if(child.subRows.first && !child.collapsed && child != row.subRows.last)
2112 child = child.subRows.first;
2117 for(; child && child != row; child = child.parent)
2127 y2 = y + numRows * rowHeight + PLUSY + 4;
2128 surface.VLine(y1, y2, rowStart + plusIndent + 7 + 20);
2130 surface.HLine(rowStart + plusIndent + 7, rowStart + indent, y + PLUSY + 4);
2133 if(y >= clientSize.h)
2136 // Root Vertical Lines
2137 if(style.rootCollapse && rows.first)
2142 y = -scroll.y + ((style.header) ? rowHeight : 0);
2144 for(child = rows.first; child && child != rows.last; )
2147 if(child.subRows.first && !child.collapsed && child != rows.last)
2148 child = child.subRows.first;
2153 for(; child; child = child.parent)
2163 y2 = y + numRows * rowHeight + PLUSY + 4;
2164 surface.VLine(y1, y2, -scroll.x + 11);
2166 surface.LineStipple(0);
2169 for(row = firstRowShown; row; row = row.GetNextRow() )
2171 int x = -scroll.x + EXTRA_SPACE / 2-1;
2174 Color foreground = this.foreground /*black*/, background = this.background /*white*/;
2175 DataDisplayFlags dataDisplayFlags = 0;
2176 int rowStart = -scroll.x;
2179 Bitmap icon = row.icon ? row.icon.bitmap : null;
2180 int collapseRowStart;
2182 for(parent = row.parent; parent; parent = parent.parent)
2186 if(style.treeBranch)
2192 if(style.rootCollapse) indent += 20;
2195 dataDisplayFlags.fullRow = style.fullRowSelect;
2196 dataDisplayFlags.active = isActive;
2197 dataDisplayFlags.header = row.header;
2202 collapseRowStart = rowStart;
2204 if(!(style.treeBranch))
2211 if(style.multiSelect)
2213 dataDisplayFlags.selected = row.selectedFlag == selected || row.selectedFlag == tempSelected;
2214 dataDisplayFlags.current = row == currentRow || (!currentRow && row == firstRowShown);
2218 dataDisplayFlags.selected = row.selectedFlag == selected || row.selectedFlag == tempSelected;
2219 dataDisplayFlags.current = row == currentRow || (!currentRow && row == firstRowShown);
2221 if(row == currentRow)
2223 dataDisplayFlags.current = true;
2224 dataDisplayFlags.selectedFlag = true;
2226 else if(!currentRow && row == firstRowShown)
2228 dataDisplayFlags.current = true;
2232 surface.TextOpacity(true);
2234 background = this.background;
2235 foreground = this.foreground;
2237 // Draw the current row background
2240 background = activeBorder;
2241 surface.SetBackground(activeBorder);
2242 surface.Area(rowStart, y, clientSize.w, (y + rowHeight) - 1);
2243 foreground = branchesColor;
2245 else if(dataDisplayFlags.selected)
2247 if(dataDisplayFlags.selected && (isActive || style.alwaysHL || (style.alwaysEdit && style.fullRowSelect)))
2249 if(!isActive && style.alwaysEdit)
2250 background = activeBorder;
2252 background = selectionColor ? selectionColor : SELECTION_COLOR;
2253 if(style.fullRowSelect)
2255 int offset = (style.alwaysEdit) ? 2 : 1;
2256 surface.SetBackground(background);
2257 surface.Area(rowStart, y, clientSize.w, (y + rowHeight) - offset);
2259 if(isActive || !(style.alwaysEdit))
2260 foreground = selectionText ? selectionText : SELECTION_TEXT;
2262 foreground = branchesColor;
2268 surface.Blit(icon, x + (20 - icon.width) /2,y + 2,0,0, icon.width, icon.height);
2274 int width = clientSize.w;
2276 dataDisplayFlags.firstField = true;
2277 clip.left = x - EXTRA_SPACE / 2+1;
2279 clip.right = x + width - EXTRA_SPACE/2 - 0;
2280 clip.bottom = y + rowHeight - 1;
2281 surface.Clip(&clip);
2283 surface.TextFont(font);
2285 surface.SetForeground(foreground);
2286 surface.SetBackground(background);
2288 class(String)._vTbl[__ecereVMethodID_class_OnDisplay](class(String), "(none)", surface, x, y - 1 + (rowHeight - fontH)/2, width - EXTRA_SPACE/2, null, Alignment::left, dataDisplayFlags);
2293 for(field = fields.first; field; field = field.next)
2296 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2297 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2299 // Box clip = { x, y+1, x + field.width - EXTRA_SPACE - 1, y + rowHeight - 2 };
2302 //width -= EXTRA_SPACE;
2304 if(!field.prev) width -= indent;
2307 dataDisplayFlags.firstField = field.prev ? false : true;
2309 if(!dataDisplayFlags.firstField && !dataDisplayFlags.fullRow)
2311 background = this.background;
2312 foreground = this.foreground;
2315 if(!isActive && dataDisplayFlags.selected && style.alwaysEdit && field.editable)
2318 surface.SetBackground(background);
2319 surface.Area(x-3, y, x+width-1, y + rowHeight-2);
2322 clip.left = x - EXTRA_SPACE / 2+1;
2324 clip.right = x + width - EXTRA_SPACE/2 - 0;
2325 clip.bottom = y + rowHeight - 1;
2326 surface.Clip(&clip);
2328 for(index = 0, cell = row.cells.first; cell && index != field.index; index++, cell = cell.next);
2329 // Should always be as many cells in the row as fields in the listbox
2330 if(cell && cell.isSet && field.dataType)
2333 surface.TextFont(boldFont);
2335 surface.TextFont(font);
2337 surface.SetForeground(foreground);
2338 surface.SetBackground(background);
2340 if(field.dataType.type == noHeadClass || field.dataType.type == normalClass)
2341 field.dataType._vTbl[__ecereVMethodID_class_OnDisplay](field.dataType, cell.data[0], surface, x, y - 1 + (rowHeight - fontH)/2, width - EXTRA_SPACE/2, field.userData, field.alignment, dataDisplayFlags);
2343 field.dataType._vTbl[__ecereVMethodID_class_OnDisplay](field.dataType, cell.data, surface, x, y - 1 + (rowHeight - fontH)/2, width - EXTRA_SPACE/2, field.userData, field.alignment, dataDisplayFlags);
2346 if(!isActive && dataDisplayFlags.selected && style.alwaysEdit && field.editable)
2347 background = activeBorder;
2349 if(!dataDisplayFlags.firstField && !dataDisplayFlags.fullRow)
2351 background = activeBorder;
2352 foreground = this.background;
2355 x += width;// + EXTRA_SPACE;
2357 if(row.header) break;
2363 int plusIndent = (style.treeBranch) ? (indent - 20 + 4) : indent;
2365 if(row.subRows.first && (row.parent || !(style.treeBranch) || (style.rootCollapse)))
2367 surface.SetForeground(row.header ? headerCollapseForeground : this.foreground);
2368 surface.Rectangle(collapseRowStart + 3 + plusIndent, y + PLUSY, collapseRowStart + 11 + plusIndent, y + PLUSY + 8);
2370 surface.SetBackground(row.header ? (activeBorder) : (this.background)); //white
2371 surface.Area(collapseRowStart + 4 + plusIndent, y + PLUSY + 1, collapseRowStart + 10 + plusIndent, y + PLUSY + 7);
2373 surface.HLine(collapseRowStart + 5 + plusIndent, collapseRowStart + 9 + plusIndent, y+PLUSY+4);
2375 surface.VLine(y + PLUSY + 2, y + PLUSY + 6, collapseRowStart + 7 + plusIndent);
2380 // Draw the current row stipple
2381 if(style.fullRowSelect && !(style.alwaysEdit) && (dataDisplayFlags.current) && isActive)
2386 surface.LineStipple(0x5555);
2387 if(dataDisplayFlags.selected)
2388 surface.SetForeground(stippleColor);
2390 surface.SetForeground(this.foreground);
2393 surface.SetForeground(selectionColor ? selectionColor : SELECTION_COLOR);
2394 surface.Rectangle(0, y, clientSize.w-1, (y + rowHeight) - 1);
2395 surface.LineStipple(0);
2399 if(y >= clientSize.h)
2402 if(firstRowShown) surface.Clip(null);
2403 if(this.dragRow && this.dropIndex != -1)
2405 int dropIndex = this.dropIndex;
2408 if(!style.multiSelect && currentRow.index < this.dropIndex)
2410 surface.DrawingChar(223);
2412 y = style.header ? rowHeight : 0;
2413 y += dropIndex * rowHeight - scroll.y;
2415 surface.SetForeground(Color { 85, 85, 255 });
2416 surface.HLine(0, clientSize.w-1, y);
2417 surface.HLine(0, clientSize.w-1, y + 1);
2421 void OnDrawOverChildren(Surface surface)
2423 if(draggingField && this.dropField)
2425 int position = this.dropField.x;
2426 if(draggingField.x < position)
2427 position += this.dropField.width + EXTRA_SPACE;
2429 surface.SetForeground(Color { 85, 85, 255 });
2430 surface.VLine(0, rowHeight - 1, position - scroll.x - 2);
2431 surface.VLine(0, rowHeight - 1, position - scroll.x);
2433 if(sortField && !style.clearHeader && style.header)
2435 DataField field = sortField;
2436 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2437 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2440 surface.TextExtent(field.header, strlen(field.header), &tw, &th);
2441 if(tw < width - EXTRA_SPACE)
2443 bool up = field.sortOrder == 1;
2447 field.x + 2 - scroll.x, 0,
2448 field.x + width + EXTRA_SPACE - 1 - scroll.x, rowHeight
2450 surface.Clip(&clip);
2451 if(field.alignment == left || field.alignment == center)
2453 if(field.alignment == center)
2454 x = field.x + (width + EXTRA_SPACE - tw) / 2 + tw + EXTRA_SPACE + 4;
2456 x = field.x + tw + EXTRA_SPACE + 4;
2458 x = Min(x, field.x + width - 4);
2460 else if(field.alignment == right)
2462 x = field.x + width - tw - EXTRA_SPACE - 4;
2463 x = Max(x, field.x + 2);
2469 // surface.SetForeground((wmenu.selectedFlag == item) ? white : black);
2470 // surface.WriteText(clientSize.w-8, y+(wmenu.rh - 8)/2, "\020", 1);
2476 surface.SetForeground(Color { 128,128,128 } );
2477 surface.DrawLine(x + 3, y, x, y + 5);
2478 surface.PutPixel(x + 1, y + 5);
2479 surface.PutPixel(x + 1, y + 3);
2480 surface.PutPixel(x + 2, y + 1);
2482 surface.SetForeground(white);
2483 surface.DrawLine(x + 4, y, x + 7, y + 5);
2484 surface.PutPixel(x + 6, y + 5);
2485 surface.PutPixel(x + 6, y + 3);
2486 surface.PutPixel(x + 5, y + 1);
2488 surface.DrawLine(x, y + 6, x + 7, y + 6);
2492 surface.SetForeground(Color { 128,128,128 });
2493 surface.DrawLine(x + 3, y+6, x, y+1);
2494 surface.PutPixel(x + 1, y+1);
2495 surface.PutPixel(x + 1, y+3);
2496 surface.PutPixel(x + 2, y+5);
2498 surface.SetForeground(white);
2499 surface.DrawLine(x + 4, y+6, x + 7, y+1);
2500 surface.PutPixel(x + 6, y+1);
2501 surface.PutPixel(x + 6, y+3);
2502 surface.PutPixel(x + 5, y+5);
2504 surface.DrawLine(x, y, x + 7, y);
2513 void OnResize(int w, int h)
2516 bool showEndBevel = false;
2518 if(style.collapse && !style.treeBranch)
2520 for(field = fields.first; field; field = field.next)
2522 int width = field.width + EXTRA_SPACE;
2530 (rowCount * rowHeight) +
2531 ((style.header) ? rowHeight : 0) -
2532 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
2534 for(field = fields.first; field; field = field.next)
2536 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2537 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2538 if(style.header && field.headButton)
2540 showEndBevel = true;
2543 field.headButton.position = { field.x, 0 };
2544 field.headButton.size = { width, rowHeight };
2545 field.headButton.visible = true;
2548 field.headButton.visible = false;
2552 if(!style.fillLastField && showEndBevel && endBevel)
2554 endBevel.position = { x, 0 };
2555 endBevel.size = { clientSize.w + 2 - x, rowHeight };
2556 endBevel.visible = true;
2559 endBevel.visible = false;
2561 if(style.alwaysEdit && editData && editData.visible)
2563 HideEditBox(true, false, true);
2567 void AdaptToFieldWidth(DataField field, bool doScroll)
2569 OnResize(clientSize.w, clientSize.h);
2571 // Scroll appropriately
2574 if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x &&
2575 field.x >= field.x + field.width + EXTRA_SPACE - clientSize.w)
2577 SetScrollPosition(field.x + field.width + EXTRA_SPACE - clientSize.w, scroll.y);
2579 else if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x ||
2581 SetScrollPosition(field.x, scroll.y);
2586 bool HeaderPushed(Button control, int x, int y, Modifiers mods)
2588 DataField field = (DataField)control.id;
2589 // false: dont destroy edit box
2590 HideEditBox(true, false, true);
2591 if(style.resizable && ((!field && x < RESIZE_BORDER && fields.last) ||
2592 (field && x < RESIZE_BORDER && field.prev) ||
2593 (field && x >= control.clientSize.w - RESIZE_BORDER)))
2596 field = fields.last;
2597 else if(x < RESIZE_BORDER && field.prev)
2600 resizingField = field;
2601 this.resizeX = x + control.position.x;
2602 this.startWidth = field.width;
2603 this.oldX = x - scroll.x;
2608 draggingField = field;
2609 if(style.moveFields)
2610 field.headButton.stayDown = true;
2611 else if(!style.sortable)
2619 bool HeaderMouseMove(Button control, int x, int y, Modifiers mods)
2624 DataField field = resizingField;
2626 x += control.position.x;
2628 // Tweak to prevent shrinking field if we're actually moving right
2629 if(x - scroll.x > this.oldX &&
2630 this.startWidth + x - this.resizeX < field.width)
2632 this.oldX = x - scroll.x;
2635 this.oldX = x - scroll.x;
2637 field.width = this.startWidth + x - this.resizeX;
2638 field.width = Max(field.width, - EXTRA_SPACE);
2640 AdaptToFieldWidth(field, true);
2642 else if(draggingField)
2644 x += control.position.x;
2645 if(style.moveFields)
2647 DataField field = fields.last;
2649 for(field = fields.first; field; field = field.next)
2651 fieldX += ((field.width || style.resizable) ?
2652 field.width : clientSize.w) + EXTRA_SPACE;
2656 if(draggingField == field)
2658 // Reset scroll position
2659 if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x &&
2660 field.x >= field.x + field.width + EXTRA_SPACE - clientSize.w)
2663 field.x + field.width + EXTRA_SPACE - clientSize.w,
2666 else if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x ||
2668 SetScrollPosition(field.x, scroll.y);
2671 if(this.dropField != field)
2673 this.dropField = field;
2676 int position = field.x;
2678 if(draggingField.x < position)
2680 position += field.width + EXTRA_SPACE - clientSize.w;
2681 if(position > scroll.x)
2682 SetScrollPosition(position, scroll.y);
2687 if(position < scroll.x)
2688 SetScrollPosition(position, scroll.y);
2691 this.movingFields = true;
2697 else if(style.resizable)
2699 DataField field = (DataField)control.id;
2702 if(x < RESIZE_BORDER && field.prev)
2703 control.cursor = guiApp.GetCursor(sizeWE);
2704 else if(x >= control.clientSize.w - RESIZE_BORDER)
2705 control.cursor = guiApp.GetCursor(sizeWE);
2707 control.cursor = null;
2711 if(x < RESIZE_BORDER && fields.last)
2712 control.cursor = guiApp.GetCursor(sizeWE);
2714 control.cursor = null;
2720 bool HeaderReleased(Button control, int x, int y, Modifiers mods)
2724 NotifyResized(master, this, resizingField, mods);
2725 resizingField = null;
2732 if(style.moveFields)
2737 DataField switchField = fields.last;
2741 x += draggingField.x;
2742 for(field = fields.first; field; field = field.next)
2744 fieldX += ((field.width || style.resizable) ?
2745 field.width : clientSize.w) + EXTRA_SPACE;
2748 switchField = field;
2752 if(switchField && draggingField != switchField && this.dropField)
2754 for(field = fields.first; field; field = field.next)
2756 if(field == switchField || field == draggingField)
2760 // Switch field first: move before
2761 if(field == switchField)
2762 draggingField.Move(switchField.prev);
2763 // Dragged field first: move after
2765 draggingField.Move(switchField);
2767 NotifyMovedField(master, this, draggingField, mods);
2769 draggingField.headButton.stayDown = false;
2774 movingFields = false;
2776 draggingField = null;
2782 bool HeaderClicked(Button control, int x, int y, Modifiers mods)
2784 if(style.header && !this.dropField && style.sortable)
2786 DataField field = (DataField)control.id;
2787 if(sortField == field)
2788 field.sortOrder *= -1;
2793 Sort(sortField, field.sortOrder);
2794 NotifySort(master, this, field, mods);
2802 if(style.freeSelect)
2807 this.rolledOver = this.dragging = false;
2814 bool OnLoadGraphics()
2816 display.FontExtent(fontObject, "W", 1, null, &fontH);
2817 if(!style.heightSet)
2819 rowHeight = Max(fontH + 2, 16) + (style.alwaysEdit ? 1 : 0);
2820 SetScrollLineStep(8, rowHeight);
2825 void OnApplyGraphics()
2827 SetScrollLineStep(8, rowHeight);
2831 for(field = fields.first; field; field = field.next)
2833 if(field.headButton)
2835 field.headButton.bevel = (!guiApp.textMode && !style.clearHeader);
2837 field.headButton.background = Color { 0, 170, 0 };
2841 OnResize(clientSize.w, clientSize.h);
2844 bool OnResizing(int *w, int *h)
2848 if(!initSize.w && (!anchor.left.type || !anchor.right.type) /**w*/)
2853 Font font = fontObject;
2854 Font boldFont = this.boldFont.font;
2855 Display display = this.display;
2857 for(row = rows.first; row; row = row.GetNextRow())
2859 Bitmap icon = row.icon ? row.icon.bitmap : null;
2860 int x = -scroll.x + EXTRA_SPACE / 2-1;
2864 for(parent = row.parent; parent; parent = parent.parent)
2868 if(style.treeBranch)
2874 if(style.rootCollapse) indent += 20;
2876 if(style.collapse && !(style.treeBranch)) x += 15;
2880 // Compute the rows size
2881 for(field = fields.first; field; field = field.next)
2883 if(((style.resizable && (!(style.alwaysEdit) || field.next)) || field.width) && !row.header)
2884 x += field.width - (field.prev ? 0 : indent);
2889 for(index = 0, cell = row.cells.first; index != field.index; index++, cell = cell.next);
2891 // Should always be as many cells in the row as fields in the listbox
2892 if(cell && cell.isSet && field.dataType)
2895 char tempString[1024];
2898 if(field.dataType.type == 0 normalClass || field.dataType.type == noHeadClass)
2899 string = (char *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString](field.dataType, cell.data[0], tempString, field.userData, null);
2901 string = (char *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString](field.dataType, cell.data, tempString, field.userData, null);
2903 if(!string) string = "";
2904 display.FontExtent(row.header ? boldFont : font, string, strlen(string), &tw, &th);
2907 display.FontExtent(row.header ? boldFont : font, string, strlen(string), &tw, &th);
2909 display.FontExtent(row.header ? boldFont : font, "", 0, &tw, &th);
2912 if(row.header) break;
2916 maxWidth = Max(maxWidth, x);
2922 *h = Min(this.maxShown, this.rowCount) * rowHeight;
2927 if(!*w) *w = rowHeight * 5;
2928 if(!*h) *h = rowHeight * 5;
2935 FontResource font = this.font;
2936 FontResource boldFont
2938 faceName = font.faceName, size = font.size, bold = true
2940 AddResource(boldFont);
2941 RemoveResource(this.boldFont);
2942 this.boldFont = boldFont;
2946 SetInitSize(initSize);
2949 bool OnMouseMove(int x, int y, Modifiers mods)
2951 bool isTimer = false;
2952 int realX = x, realY = y;
2954 if(insideNotifySelect) return true;
2956 if(style.alwaysEdit && style.resizable &&
2957 resizingField && !(mods.isSideEffect))
2960 DataField field = resizingField;
2961 field.width = this.startWidth + x - this.resizeX;
2962 field.width = Max(field.width, - EXTRA_SPACE);
2964 AdaptToFieldWidth(field, true);
2968 if(style.alwaysEdit && style.resizable)
2970 int vx = -scroll.x - 1;
2973 if(style.collapse && !(style.treeBranch))
2976 for(field = fields.first; field; field = field.next)
2978 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2979 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2985 cursor = guiApp.GetCursor(sizeWE);
2989 vx += width + EXTRA_SPACE;
2993 if((editData && editData.visible) || (style.alwaysEdit))
2996 if(x == MAXINT && y == MAXINT)
3003 // ADDED THIS CHECK FOR FieldDropBox LEAKS
3004 if(/*!mods.isSideEffect && */(this.rolledOver || !this.dragging))
3006 int rowY = (style.header) ? rowHeight : 0;
3014 ((vertScroll && vertScroll.visible &&
3015 (y < 0 || y >= clientSize.h)) ||
3016 (horzScroll && horzScroll.visible &&
3017 (x < 0 || x >= clientSize.w))))
3022 if(vertScroll && vertScroll.visible &&
3023 (y < 0 || y >= clientSize.h))
3024 vertScroll.Action((y<0)?up:down, 0, 0);
3025 if(horzScroll && horzScroll.visible &&
3026 (x < 0 || x >= clientSize.w))
3027 horzScroll.Action((x<0)?up:down, 0, 0);
3033 // This must be done after the scrolling took place
3034 rowIndex = firstRowShown ? firstRowShown.index : -1;
3036 y = Min(y, clientSize.h-1);
3037 for(row = firstRowShown; row; row = row.GetNextRow(), rowIndex ++)
3046 if(row && currentRow != row)
3048 if(this.dragRow && style.moveRows)
3050 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
3052 else if(style.multiSelect)
3055 for(thisRow = rows.first; thisRow; thisRow = thisRow.GetNextRow())
3056 if((thisRow.selectedFlag == selected || thisRow.selectedFlag == tempSelected) ||
3062 if(this.dropIndex != rowIndex)
3064 this.dropIndex = rowIndex;
3065 this.editRow = null;
3067 this.movedRow = true;
3070 else if((style.freeSelect || this.dragging) && ((realX>= 0 && realY >= 0 && realX< clientSize.w && realY < clientSize.h) || this.rolledOver))
3072 if(!(style.multiSelect))
3074 if(currentRow)currentRow.selectedFlag = unselected;
3075 if(row)row.selectedFlag = selected;
3079 if(style.multiSelect)
3083 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3085 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3086 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3089 if(rowIndex >= clickedRow.index)
3091 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
3093 selRow.selectedFlag = (selRow.selectedFlag == selected) ? tempUnselected : tempSelected;
3100 for(selRow = row; selRow; selRow = selRow.GetNextRow())
3102 selRow.selectedFlag = (selRow.selectedFlag == selected) ? tempUnselected : tempSelected;
3103 if(selRow == clickedRow)
3109 if(style.freeSelect)
3110 NotifyHighlight(master, this, currentRow, mods);
3113 insideNotifySelect = true;
3114 NotifySelect(master, this, currentRow, mods);
3115 insideNotifySelect = false;
3118 if(style.alwaysEdit && currentRow)
3119 currentRow.Edit(currentField);
3126 bool OnMouseOver(int x, int y, Modifiers mods)
3129 this.rolledOver = true;
3133 bool OnActivate(bool active, Window swap, bool * goOnWithActivation, bool direct)
3135 // TOCHECK: WAS THIS MISSING ? CHECK FOR SLOWDOWN
3136 if(!active) Update(null);
3138 if(!active && (!swap || !swap.isModal))
3140 // true: destroy edit box
3141 HideEditBox(true, true, false);
3143 else if(!swap || !swap.isModal)
3145 // Bring back edit box
3146 if(currentRow && style.alwaysEdit)
3148 currentRow.Edit(currentField ? currentField : null);
3152 return true; //NotifyActivate(master, this, active, swap, 0);
3156 bool OnButtonDown(int x, int y, Modifiers mods, bool right)
3159 // Check to see if we're dragging the vertical divider
3160 if(style.alwaysEdit && style.resizable && !right)
3162 int vx = -scroll.x - 1;// + EXTRA_SPACE;// / 2 - 1;
3165 if(style.collapse && !(style.treeBranch))
3168 for(field = fields.first; field; field = field.next)
3170 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3171 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3177 resizingField = field.prev;
3179 this.startWidth = resizingField.width;
3181 SetMouseRangeToClient();
3185 vx += width + EXTRA_SPACE;
3189 if(!(style.freeSelect))
3191 int rowY = (style.header) ? rowHeight : 0;
3193 int rowIndex = firstRowShown ? firstRowShown.index : -1;
3194 DataRow previousRow = currentRow;
3195 DataRow newCurrentRow = null;
3196 DataField newCurrentField = null;
3197 bool moveMultiple = false;
3198 int numSelected = 0;
3199 int rowStart = -scroll.x;
3201 if(style.multiSelect)
3208 for(row = rows.first; row; row = row.GetNextRow())
3210 if(row.selectedFlag == tempSelected)
3211 row.selectedFlag = selected;
3212 else if(row.selectedFlag == tempUnselected)
3213 row.selectedFlag = unselected;
3214 if(row.selectedFlag == selected)
3221 for(row = firstRowShown; row; row = row.GetNextRow(), rowIndex ++)
3224 if(rowY > y || (style.multiSelect && !row.GetNextRow()))
3227 if(style.treeBranch)
3230 for(parent = (style.rootCollapse) ? row.parent : (row.parent ? row.parent.parent : null); parent; parent = parent.parent)
3236 /* THIS WAS TOO STRICT:
3237 if(style.collapse && row.subRows.first && (row.parent || !(style.treeBranch) || (style.rootCollapse)) &&
3238 (x >= rowStart + 3 + plusIndent && y >= rowY - rowHeight + PLUSY && x <= rowStart + 11 + plusIndent && y <= rowY - rowHeight + PLUSY + 8))
3240 if(style.collapse &&
3241 (x >= rowStart && y >= rowY - rowHeight && x <= rowStart + 18 + plusIndent && y <= rowY + rowHeight-1))
3243 if(row.subRows.first && (row.parent || !(style.treeBranch) || (style.rootCollapse)) && x >= plusIndent)
3244 row.collapsed = !row.collapsed;
3251 newCurrentRow = row;
3253 if(style.multiSelect)
3255 // Deselect everything if user didn't clicked on a row
3259 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3260 selRow.selectedFlag = unselected;
3262 //this.clickedRowIndex = rowIndex;
3264 else if(style.moveRows && !(mods.shift) &&
3265 (row.selectedFlag == selected || row.selectedFlag == tempSelected) &&
3266 !right && !(mods.isActivate))
3267 moveMultiple = true;
3273 if(row.selectedFlag == tempUnselected || row.selectedFlag == unselected)
3275 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3276 selRow.selectedFlag = unselected;
3277 row.selectedFlag = selected;
3280 //this.clickedRowIndex = rowIndex;
3286 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3287 selRow.selectedFlag = unselected;
3291 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3293 if(selRow != clickedRow)
3295 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3296 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3303 if(rowIndex >= clickedRow.index)
3305 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
3309 if(selRow != clickedRow)
3311 if(selRow.selectedFlag)
3312 selRow.selectedFlag = tempUnselected;
3314 selRow.selectedFlag = tempSelected;
3318 selRow.selectedFlag = selected;
3325 for(selRow = row; selRow; selRow = selRow.GetNextRow())
3329 if(selRow != clickedRow)
3331 if(selRow.selectedFlag)
3332 selRow.selectedFlag = tempUnselected;
3334 selRow.selectedFlag = tempSelected;
3338 selRow.selectedFlag = selected;
3339 if(selRow == clickedRow)
3348 if(row.selectedFlag)
3349 row.selectedFlag = tempUnselected;
3350 else row.selectedFlag = tempSelected;
3353 row.selectedFlag = tempSelected;
3355 //this.clickedRowIndex = rowIndex;
3365 // true: destroy edit box
3368 incref newCurrentRow;
3371 if(currentRow != newCurrentRow)
3372 HideEditBox(true, true, false);
3376 if(newCurrentRow._refCount <= 1)
3377 delete newCurrentRow;
3379 newCurrentRow._refCount--;
3384 if(!(style.multiSelect))
3386 if(currentRow) currentRow.selectedFlag = unselected;
3387 if(newCurrentRow) newCurrentRow.selectedFlag = selected;
3391 if(currentRow != newCurrentRow)
3394 // true: destroy edit box
3397 //incref newCurrentRow;
3398 incref newCurrentRow;
3401 HideEditBox(true, true, false);
3406 int headerSize = ((style.header) ? rowHeight : 0);
3407 int height = clientSize.h + 1 - headerSize;
3409 /*if(newCurrentRow._refCount <= 1)
3410 delete newCurrentRow;
3413 newCurrentRow._refCount--;
3414 //newCurrentRow._refCount--;
3417 currentRow = newCurrentRow;
3419 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
3420 SetScrollPosition(scroll.x,
3421 currentRow.index * rowHeight - height + rowHeight);
3422 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
3424 int line = currentRow ? currentRow.index * rowHeight : 0;
3425 //SNAPUP(line, rowHeight);
3426 SetScrollPosition(scroll.x, line);
3429 // GO THROUGH SetCurrentRow eventually?
3430 // SetCurrentRow(newCurrentRow, true);
3434 if(style.freeSelect)
3435 NotifyHighlight(master, this, currentRow, mods);
3436 else if((moveMultiple || (!(style.multiSelect) && previousRow == currentRow)) &&
3437 newCurrentRow && !(mods.shift))
3441 if(!(mods.isActivate))
3445 this.dragRow = currentRow;
3446 this.dropIndex = -1;
3447 this.movedRow = false;
3449 if(editData && editData.visible && style.alwaysEdit)
3456 if(style.collapse && !style.treeBranch)
3459 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3461 indent += (style.treeBranch) ? 20 : 15;
3464 for(field = fields.first; field; field = field.next)
3466 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3467 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3469 if(!field.prev) width -= indent;
3470 if(x >= sx && x < sx + width)
3474 if(field == currentField)
3475 editData.Deactivate();
3478 currentRow.Edit(field);
3479 editData.Activate();
3482 else if(!(mods.ctrl) && numSelected <= 1)
3483 this.editRow = currentRow;
3485 if(style.noDragging && newCurrentRow)
3486 NotifyReclick(master, this, newCurrentRow, mods);
3490 // If the user clicked exactly on the edited field,
3492 if(editData && editData.visible && newCurrentRow)
3494 DataField field, whichField;
3498 if(style.collapse && !(style.treeBranch))
3501 whichField = currentField;
3505 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3507 indent += (style.treeBranch) ? 20 : 15;
3511 for(field = fields.first; field; field = field.next)
3513 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3514 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3515 if(!field.prev) width -= indent;
3516 if(x >= sx && x < sx + width && newCurrentRow)
3521 if(field) //x >= sx && x < sx + width && newCurrentRow)
3523 if(field == currentField)
3524 editData.Activate();
3526 newCurrentRow.Edit(currentField);*/
3528 else if(style.noDragging && newCurrentRow)
3529 NotifyReclick(master, this, newCurrentRow, mods);
3531 else if(style.noDragging && newCurrentRow)
3532 NotifyReclick(master, this, newCurrentRow, mods);
3538 result = NotifySelect(master, this,
3539 currentRow ? currentRow : null, mods);
3540 if(result && style.alwaysEdit && currentRow)
3544 DataField field = null;
3549 if(style.collapse && !style.treeBranch)
3552 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3554 indent += (style.treeBranch) ? 20 : 15;
3557 for(field = fields.first; field; field = field.next)
3559 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3560 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3562 if(!field.prev) width -= indent;
3563 if(x >= sx && x < sx + width)
3565 currentField = field;
3571 currentRow.Edit(currentField);
3573 // If the user clicked exactly on the edited field,
3575 if(editData && editData.visible && newCurrentRow)
3579 editData.Activate();
3581 else if(style.noDragging && newCurrentRow)
3582 NotifyReclick(master, this, newCurrentRow, mods);
3585 else if(style.noDragging && newCurrentRow)
3586 NotifyReclick(master, this, newCurrentRow, mods);
3590 For drop box to capture...
3593 if(x < 0 || y < 0 || x >= clientSize.w || y >= clientSize.h)
3596 master.parent.Activate();
3605 if(!style.noDragging)
3607 this.dragging = true;
3610 if(x >= 0 && y >= 0 && x < clientSize.w && y < clientSize.h)
3611 this.rolledOver = true;
3616 this.dragging = false;
3617 OnLeftButtonUp(x, y, mods);
3622 bool OnLeftButtonDown(int x, int y, Modifiers mods)
3624 return OnButtonDown(x,y, mods, false);
3627 bool OnLeftButtonUp(int x, int y, Modifiers mods)
3629 if(resizingField && style.alwaysEdit)
3631 Window::FreeMouseRange();
3633 resizingField = null;
3636 if(dragRow || editRow)
3638 DataRow row, switchRow = rows.last;
3639 int rowY = (style.header) ? rowHeight : 0;
3640 for(row = firstRowShown; row; row = row.GetNextRow())
3649 if(this.editRow == switchRow && y >= 0)
3654 for(field = fields.first; field; field = field.next)
3656 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3657 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3660 if(fieldX > x + scroll.x)
3664 if(field && field.editable)
3666 // true: destroy edit box
3667 HideEditBox(true, true, false);
3668 PopupEditBox(field, false);
3670 else if(!style.noDragging)
3671 NotifyReclick(master, this, currentRow, mods);
3673 else if(style.moveRows && switchRow)
3675 if(this.dragRow == switchRow && this.movedRow == false)
3677 DataRow row = this.dragRow;
3681 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3682 selRow.selectedFlag = unselected;
3686 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3688 if(selRow != clickedRow)
3690 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3691 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3697 if(row.selectedFlag)
3698 row.selectedFlag = tempUnselected;
3699 else row.selectedFlag = tempSelected;
3702 row.selectedFlag = tempSelected;
3707 if(style.multiSelect)
3709 if(!switchRow.selectedFlag)
3711 bool foundSwitch = false;
3714 DataRow afterRow = switchRow.prev;
3715 for(row = rows.first; row; row = next)
3717 next = row.GetNextRow();
3718 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
3720 if(!foundSwitch && !after)
3723 afterRow = switchRow;
3725 if(!after || !(row.selectedFlag == selected || row.selectedFlag == tempSelected) ||
3732 else if(row == switchRow)
3739 for(row = rows.first; row; row = row.GetNextRow())
3741 if(row == switchRow || row == this.dragRow)
3745 // Switch row first: move before
3746 if(row == switchRow)
3748 if(NotifyMove(master, this, switchRow.prev, mods))
3749 dragRow.Move(switchRow.prev);
3751 // Dragged row first: move after
3754 if(NotifyMove(master, this, switchRow, mods))
3755 dragRow.Move(switchRow);
3768 if(this.dragging || style.freeSelect)
3772 this.rolledOver = this.dragging = false;
3774 if(x >= 0 && y >= 0 && x < clientSize.w && y < clientSize.h && currentRow && style.freeSelect)
3778 result = NotifySelect(master, this, currentRow, mods);
3779 if(style.alwaysEdit)
3780 currentRow.Edit(currentField);
3784 // if(!(style.freeSelect))
3790 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
3792 int rowStart = -scroll.x;
3794 int rowY = (style.header) ? rowHeight : 0;
3797 OnLeftButtonUp(x,y,mods);
3798 if(style.alwaysEdit)
3800 if(!(style.collapse) || x > 15)
3801 if(editData && editData.visible)
3803 editData.Activate();
3804 NotifyDoubleClick(master, this, x, y, mods);
3808 for(row = firstRowShown; row; row = row.GetNextRow())
3811 if(rowY > y || (style.multiSelect && !row.GetNextRow()))
3813 if(style.treeBranch)
3816 for(parent = (style.rootCollapse) ? row.parent : (row.parent ? row.parent.parent : null); parent; parent = parent.parent)
3825 if((row && style.collapse && (x >= rowStart && x <= rowStart + 18 + plusIndent)) ||
3826 NotifyDoubleClick(master, this, x, y, mods))
3830 if(row && row.subRows.first)
3832 row.collapsed = !row.collapsed;
3836 // We need to return true here so that OnLeftButtonDown can popup the DataBox Editors
3842 bool OnRightButtonDown(int x, int y, Modifiers mods)
3844 return OnButtonDown(x,y, mods, true);
3847 bool OnRightButtonUp(int x, int y, Modifiers mods)
3849 OnLeftButtonUp(x,y,mods);
3850 return NotifyRightClick(master, this, x, y, mods);
3853 bool GoToLetter(unichar ch, bool keyHit)
3855 bool result = false;
3857 bool checkNextField = true;
3858 int len = keyHit ? 0 : strlen(typedString);
3860 typedString = renew typedString char[len + 2];
3861 typedString[len++] = (char)tolower(ch); // TODO: FIX UNICODE
3862 typedString[len] = '\0';
3864 for(field = fields.first; field; field = field.next)
3866 DataRow startRow = currentRow ? currentRow : rows.first;
3868 if(startRow && field.dataType && field.dataType._vTbl[__ecereVMethodID_class_OnGetString] && ch)
3871 bool looped = false;
3872 if(len == 1 && currentRow)
3873 startRow = (next = startRow.GetNextRow(), (next ? next : rows.first));
3875 for(row = startRow; row != startRow || !looped; next = row.GetNextRow(), row = next ? next : rows.first)
3877 void * data = row.GetData(field);
3878 char tempString[1024] = "";
3879 bool needClass = false;
3880 char * string = data ? (char *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString](field.dataType, data, tempString, null, &needClass) : null;
3882 if(string && string[0])
3883 checkNextField = false;
3884 if(string && string[0] && !strnicmp(string, typedString, len))
3886 if(style.multiSelect)
3889 bool foundRow = false;
3891 //this.clickedRowIndex = 0;
3893 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3895 if(selRow == row) foundRow = true;
3896 selRow.selectedFlag = unselected;
3897 //if(!foundRow) this.clickedRowIndex++;
3899 row.selectedFlag = selected;
3901 SetCurrentRow(row, true);
3908 if(this.typingTimeOut && !keyHit)
3909 typingTimer.Start();
3910 if(!result || !this.typingTimeOut || keyHit)
3911 typedString[len-1] = '\0';
3913 if(!checkNextField || result) break;
3918 bool OnKeyDown(Key key, unichar ch)
3922 if(key == enter || key == keyPadEnter)
3924 if(editData && editData.visible && editData.active)
3926 HideEditBox(true, false, false);
3930 else if(key == escape)
3932 if(resizingField || this.movingFields || (editData && editData.visible) || this.dragRow)
3934 if(editData && editData.visible && style.alwaysEdit && !editData.active)
3936 // false: dont destroy edit box
3937 HideEditBox(false, false, false);
3940 resizingField.width = this.startWidth;
3941 AdaptToFieldWidth(resizingField, true);
3942 resizingField = null;
3945 this.dragRow = null;
3948 this.dragging = false;
3952 this.movingFields = false;
3953 draggingField = null;
3959 if(!currentField || !currentField.editable)
3960 for(field = fields.first; field; field = field.next)
3964 currentField = field;
3968 if(key == f2 && currentField && currentField.editable)
3970 PopupEditBox(currentField, false);
3971 if(editData && editData.visible)
3973 if(style.alwaysEdit)
3974 editData.Activate();
3979 if(!NotifyKeyDown(master, this, currentRow, key, ch))
3982 // Editable fields...
3985 if(style.alwaysEdit && editData && editData.visible)
3986 return editData.OnKeyDown(key, ch);
3987 return true; // We want to pick up the OnKeyHit to replace contents, but skip GoToLetter
3990 if(ch != 128 && !key.alt && !key.ctrl && GoToLetter(ch, false))
3992 /*if(inactive && window.state != Hidden)
3993 NotifyHighlight(master, this, currentRow, 0);
3996 NotifySelect(master, this, currentRow, 0);
4003 bool OnKeyHit(Key key, unichar ch)
4005 if(!ch && !key.alt && !key.ctrl)
4007 key.code = (SmartKey)key.code;
4009 if(ch >= 32 && !key.alt && !key.ctrl && ch != 128)
4012 if(!currentField || !currentField.editable)
4013 for(field = fields.first; field; field = field.next)
4017 currentField = field;
4021 if(currentField && currentField.editable)
4023 if((!editData || !editData.visible) || !editData.active)
4025 PopupEditBox(currentField, false);
4026 if(editData && editData.visible)
4028 editData.Activate();
4029 editData.OnKeyHit(key, ch);
4036 if(!(style.multiSelect) && (key.ctrl))
4039 if(editData && editData.visible && ch && !key.alt && !key.ctrl && editData.active)
4045 if(style.alwaysEdit)
4050 for(field = currentField.prev; field; field = field.prev)
4054 currentField = field;
4055 HideEditBox(true, true, false);
4056 PopupEditBox(currentField, false);
4062 if(style.collapse && currentRow /*&& !currentField*/) // THIS PREVENTED COLLAPSING THE PROPERTY SHEET
4064 if(currentRow.subRows.first && !currentRow.collapsed)
4066 currentRow.collapsed = true;
4068 else if(currentRow.parent)
4069 SetCurrentRow(currentRow.parent, true);
4074 if(style.collapse && currentRow && currentRow.subRows.first)
4076 if(currentRow.collapsed)
4077 currentRow.collapsed = false;
4079 SetCurrentRow(currentRow.subRows.first, true);
4082 else if(style.alwaysEdit)
4087 for(field = currentField.next; field; field = field.next)
4091 currentField = field;
4092 HideEditBox(true, true, false);
4093 PopupEditBox(currentField, false);
4101 case pageDown: case pageUp:
4102 case end: case home:
4104 int headerSize = ((style.header) ? rowHeight : 0);
4105 int height = clientSize.h + 1 - headerSize;
4108 // true: destroy edit box
4109 // !!! TESTING true HERE !!!
4110 HideEditBox(true, true, false);
4111 // HideEditBox(false, true, false);
4113 oldRow = currentRow;
4115 SNAPDOWN(height, rowHeight);
4116 if((!currentRow || key.code == home) && key.code != end)
4118 currentRow = rows.first;
4126 if(!(style.multiSelect) && currentRow && !currentRow.selectedFlag)
4129 next = currentRow.GetNextRow();
4136 if(!(style.multiSelect) && currentRow && !currentRow.selectedFlag)
4139 next = currentRow.GetPrevRow();
4147 // TODO: Find very last row
4148 for(currentRow = rows.last; currentRow && !currentRow.collapsed && currentRow.subRows.last;)
4149 currentRow = currentRow.subRows.last;
4155 currentRow && (next = currentRow.GetPrevRow()) && c < height / rowHeight;
4156 c++, currentRow = next);
4163 currentRow && (next = currentRow.GetNextRow()) && c < height / rowHeight;
4164 c++, currentRow = next);
4169 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
4170 SetScrollPosition(scroll.x, currentRow.index * rowHeight - height + rowHeight);
4171 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
4172 SetScrollPosition(scroll.x, currentRow ? currentRow.index * rowHeight : 0);
4174 if(style.multiSelect)
4178 if(!(key.shift) && (key.ctrl))
4181 for(row = rows.first; row; row = row.GetNextRow())
4183 if(row.selectedFlag == tempSelected)
4184 row.selectedFlag = selected;
4185 else if(row.selectedFlag == tempUnselected)
4186 row.selectedFlag = unselected;
4192 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
4193 selRow.selectedFlag = unselected;
4197 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
4199 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
4200 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
4206 if(currentRow.index >= clickedRow.index)
4208 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
4212 if(selRow.selectedFlag) selRow.selectedFlag = tempUnselected; else selRow.selectedFlag = tempSelected;
4215 selRow.selectedFlag = selected;
4216 if(selRow == currentRow)
4222 for(selRow = currentRow; selRow; selRow = selRow.GetNextRow())
4226 if(selRow.selectedFlag) selRow.selectedFlag = tempUnselected; else selRow.selectedFlag = tempSelected;
4229 selRow.selectedFlag = selected;
4230 if(selRow == clickedRow)
4237 if(!(key.ctrl) && currentRow)
4239 currentRow.selectedFlag = selected;
4242 clickedRow = currentRow;
4247 if(oldRow) oldRow.selectedFlag = unselected;
4248 if(currentRow) currentRow.selectedFlag = selected;
4253 if(style.freeSelect)
4254 NotifyHighlight(master, this, currentRow, 0);
4256 NotifySelect(master, this, currentRow, 0);
4258 if(style.alwaysEdit && currentRow)
4259 currentRow.Edit(currentField /*null*/);
4266 if(style.multiSelect && currentRow)
4268 if(currentRow.selectedFlag)
4271 currentRow.selectedFlag = unselected;
4274 currentRow.selectedFlag = selected;
4277 if(style.freeSelect)
4278 NotifyHighlight(master, this, currentRow, 0);
4280 NotifySelect(master, this, currentRow, 0);
4286 if(!NotifyKeyHit(master, this, currentRow, key, ch))
4289 if(ch != 128 && !key.alt && !key.ctrl && GoToLetter(ch, true))
4291 /*if(inactive && window.state != Hidden)
4292 return NotifyHighlight(master, this, currentRow, 0);
4295 return NotifySelect(master, this, currentRow, 0);
4303 void OnHScroll(ScrollBarAction action, int position, Key key)
4308 void OnVScroll(ScrollBarAction action, int position, Key key)
4313 for(firstRowShown = rows.first; firstRowShown; firstRowShown = next)
4315 next = firstRowShown.GetNextRow();
4316 if(y >= position || !next) break;
4326 DataRow firstRowShown;
4330 DataField sortField;
4334 double typingTimeOut;
4347 if(guiApp.GetKeyState(shift)) mods.shift = true;
4348 if(guiApp.GetKeyState(alt)) mods.alt = true;
4349 if(guiApp.GetKeyState(control)) mods.ctrl = true;
4350 OnMouseMove(MAXINT, MAXINT, mods);
4358 delay = 0.5; // typingTimeOut
4363 typedString[0] = '\0';
4365 // The next line was commented... Why? When commented typing words stops working ( only first character jumps )
4371 bool dragging, rolledOver;
4380 // For editing fields
4382 DataField currentField;
4385 // For moving fields
4386 DataField draggingField, dropField;
4389 // For resizing fields
4390 DataField resizingField;
4391 int resizeX, oldX, startWidth;
4394 FontResource boldFont;
4397 // Only used for OnMouseMove so far, for avoiding problems with consequential mouse moves
4398 bool insideNotifySelect;
4399 Color selectionColor, selectionText, stippleColor;
4400 stippleColor = 0xFFFFFF80;