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
59 property Class dataType
61 set { dataType = value; if(value) { alignment = (Alignment)value.defaultAlignment; } } // NOTE: Class::defaultAlignment does not seem to be used anywhere
62 get { return dataType; }
64 property bool editable { set { editable = value; } };
65 property bool fixed { set { fixed = value; } get { return fixed; } };
66 property Alignment alignment
71 if(headButton) headButton.alignment = value;
72 if(listBox) listBox.Update(null);
74 get { return alignment; }
80 width = Max(value, -EXTRA_SPACE);
82 listBox.AdaptToFieldWidth(this, false);
86 property int index { get { return this ? index : 0; } };
95 for(field = listBox.fields.first; field; field = field.next)
97 if(index == value - 2)
110 for(field = listBox.fields.first; field; field = field.next)
122 property int sortOrder { get { return this ? sortOrder : 0; } };
123 property const char * header
129 headButton.text = header;
132 property void * userData
140 return this ? userData : null;
143 property bool freeData
145 set { freeData = value; } get { return freeData; }
147 property DataField prev { get { return prev; } };
148 property DataField next { get { return next; } };
150 void Move(DataField after)
154 listBox.fields.Move(this, after);
157 listBox.OnResize(listBox.clientSize.w, listBox.clientSize.h);
158 listBox.Update(null);
164 if(listBox && dataType)
166 Display display = listBox.display;
167 Font boldFont = listBox.boldFont.font;
168 Font font = listBox.fontObject;
172 display.FontExtent(boldFont, header, strlen(header), &width, null);
173 width += EXTRA_SPACE;
174 for(row = listBox.firstRow; row; row = row.GetNextRow())
178 for(i = 0, cell = row.cells.first; i != index; i++, cell = cell.next);
179 if(cell && cell.isSet && dataType)
181 static char tempString[4096];
184 if(dataType.type == normalClass || dataType.type == noHeadClass)
185 string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, cell.data[0], tempString, userData, null);
187 string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, cell.data, tempString, userData, null);
189 display.FontExtent(row.header ? boldFont : font, string, strlen(string), &tw, null);
191 display.FontExtent(row.header ? boldFont : font, "", 0, &tw, null);
192 if(tw > width) width = tw;
196 property::width = width;
203 // property::dataType = "String";
204 property::dataType = "char *";
216 headButton.Destroy(0);
221 listBox.fields.Remove(this);
222 for(field = listBox.fields.first; field; field = field.next)
224 if(field.index >= index)
227 if(listBox.currentField == this)
228 listBox.currentField = null;
230 listBox.OnResize(listBox.clientSize.w, listBox.clientSize.h);
235 DataField prev, next;
259 property int64 tag { set { if(this) tag = value; } get { return this ? tag : 0; } };
260 property DataRow previous { get { return prev; } };
261 property DataRow next { get { return next; } };
262 property int index { get { return (this && (!parent || parent.IsExpanded())) ? index : -1; } };
263 property const char * string
265 set { SetData(listBox.fields.first, value); }
266 get { return GetData(listBox.fields.first); }
268 property bool isHeader { set { header = value; } get { return this ? header : false; } };
269 property BitmapResource icon { set { if(this) icon = value; } get { return this ? icon : null; } };
270 property bool collapsed
274 if(this && collapsed != value)
277 if(parent.IsExpanded())
284 for(search = subRows.first; search; search = search.next)
285 search.selectedFlag = 0;
287 if(listBox.clickedRow && !listBox.clickedRow.parent.IsExpanded())
289 listBox.clickedRow = GetNextRow();
290 if(!listBox.clickedRow)
291 listBox.clickedRow = this;
293 if(listBox.currentRow && !listBox.currentRow.parent.IsExpanded())
295 listBox.SetCurrentRow(this, true);
297 if(listBox.firstRowShown && !listBox.firstRowShown.parent.IsExpanded())
299 listBox.firstRowShown = GetPrevRow();
300 if(!listBox.firstRowShown)
301 listBox.firstRowShown = this;
306 for(search = GetNextRow(); search; search = search.GetNextRow())
308 listBox.rowCount = ix;
310 listBox.HideEditBox(false, false, true);
312 listBox.SetScrollArea(
314 (listBox.rowCount * listBox.rowHeight) +
315 ((listBox.style.header) ? listBox.rowHeight : 0) -
316 ((!((listBox.clientSize.h+1) % listBox.rowHeight)) ? listBox.rowHeight : 0), true);
317 listBox.Update(null);
318 listBox.NotifyCollapse(listBox.master, listBox, this, value);
322 if(this && !skipCheck)
323 listBox.CheckConsistency();
326 get { return this ? collapsed : false; }
328 property bool selected
334 selectedFlag = value ? selected : unselected;
335 listBox.Update(null);
338 get { return selectedFlag == selected || selectedFlag == tempSelected; }
340 property DataRow parent
344 if(this && (value != this))
347 DataRow after = value ? value.subRows.last : listBox.rows.last;
348 int ixCount = (!collapsed && subRows.count) ? GetLastRow().index - index + 1 : 1;
349 if(parent.IsExpanded())
351 for(search = GetNextRow(); search; search = search.GetNextRow())
352 search.index -= ixCount;
353 listBox.rowCount -= ixCount;
356 listBox.HideEditBox(false, false, true);
359 if(this == listBox.clickedRow)
361 listBox.clickedRow = GetNextRow();
362 if(!listBox.clickedRow)
363 listBox.clickedRow = GetPrevRow();
366 if(this == listBox.currentRow)
368 DataRow newCurrentRow = GetNextRow();
369 if(!listBox.newCurrentRow)
370 listBox.newCurrentRow = GetPrevRow();
371 listBox.SetCurrentRow(newCurrentRow, true);
374 if(this == listBox.firstRowShown)
376 listBox.firstRowShown = GetPrevRow();
377 if(!listBox.firstRowShown)
378 listBox.firstRowShown = GetNextRow();
382 (parent ? parent.subRows : listBox.rows).Remove(this);
385 value.subRows.Insert(after, this);
387 listBox.rows.Insert(after, this);
391 if(value && listBox.style.expandOnAdd)
394 value.skipCheck = true;
396 value.collapsed = false;
398 value.skipCheck = false;
402 if(value.IsExpanded())
406 if(after && after.subRows.first && !after.collapsed)
408 search = after.GetLastRow();
409 index = search.index + 1;
412 index = after ? (after.index + 1) : (index + 1);
414 listBox.rowCount += ixCount;
418 for(search = GetNextRow(); search; search = search.GetNextRow())
422 listBox.SetScrollArea(
424 (listBox.rowCount * listBox.rowHeight) +
425 ((listBox.style.header) ? listBox.rowHeight : 0) -
426 ((!((listBox.clientSize.h+1) % listBox.rowHeight)) ? listBox.rowHeight : 0), true);
427 if(listBox.style.autoScroll)
428 listBox.SetScrollPosition(0, MAXINT - listBox.rowHeight);
430 // TESTING THIS HERE...
432 listBox.Sort(listBox.sortField, listBox.sortField.sortOrder);
435 int headerSize = ((listBox.style.header) ? listBox.rowHeight : 0);
436 int height = listBox.clientSize.h + 1 - headerSize;
437 if(listBox.currentRow && listBox.currentRow.index * listBox.rowHeight > listBox.scroll.y + height - listBox.rowHeight)
438 listBox.SetScrollPosition(listBox.scroll.x, listBox.currentRow.index * listBox.rowHeight - height + listBox.rowHeight);
439 else if(!listBox.currentRow || listBox.currentRow.index * listBox.rowHeight < listBox.scroll.y)
441 int line = listBox.currentRow ? listBox.currentRow.index * listBox.rowHeight : 0;
442 listBox.SetScrollPosition(listBox.scroll.x, line);
445 listBox.OnVScroll(0, listBox.scroll.y, 0);
447 listBox.Update(null);
455 property DataRow lastRow { get { return this ? subRows.last : null; } };
456 property DataRow firstRow { get { return this ? subRows.first : null; } };
458 void Edit(DataField field)
464 if(!field || !field.editable)
466 for(field = listBox.fields.first; field; field = field.next)
467 if(field.editable) break;
469 if(field && field.editable)
471 listBox.SetCurrentRow(this, true);
472 listBox.PopupEditBox(field, false);
478 // NOTE: This does not support reparenting (Use row.parent = first)
479 void Move(DataRow after)
484 if(listBox && prev != after)
487 int headerSize = ((listBox.style.header) ? listBox.rowHeight : 0);
488 int height = listBox.clientSize.h + 1 - headerSize;
489 int ixCount = (!collapsed && subRows.count) ? GetLastRow().index - index + 1 : 1;
491 if(!after || after.index < index)
493 if((after && after == listBox.firstRowShown.prev) || (!after && !parent /*&& listBox.firstRowShown.prev*/))
494 listBox.firstRowShown = this;
496 // All rows between AFTER (exclusive) and ROW (exclusive) are incremented by one
497 // ROW is equal to AFTER's index + 1
499 for(search = after ? after.next : (parent ? parent.subRows.first : listBox.rows.first); search && search != this; search = search.GetNextRow())
500 search.index += ixCount;
502 if(after && after.subRows.first && !after.collapsed)
504 search = after.GetLastRow();
505 index = search.index + 1;
508 index = after ? (after.index + 1) : parent ? parent.index + 1 : 0;
510 // Fix indices of sub rows
514 for(c = 1, search = GetNextRow(); search && c < ixCount; c++, search = search.GetNextRow())
521 int afterIXCount = 1;
523 nextRow = GetNextRow();
524 if(this == listBox.firstRowShown)
525 listBox.firstRowShown = nextRow;
527 // All rows between ROW (exclusive) and AFTER (inclusive) are decremented by one
528 // ROW is equal to AFTER's index
530 for(search = nextRow; search; search = search.GetNextRow())
532 search.index -= ixCount;
533 if(search == after) break;
536 // Fix up's after's sub rows
537 if(after && !after.collapsed)
539 DataRow last = after.GetLastRow();
542 int ix = after.index+1;
543 for(search = after.GetNextRow(); search; search = search.GetNextRow())
547 if(search == last) break;
551 index = after.index + afterIXCount;
553 // Fix indices of sub rows
557 for(c = 1, search = GetNextRow(); search && c < ixCount; c++, search = search.GetNextRow())
561 (parent ? parent.subRows : listBox.rows).Move(this, after);
564 listBox.CheckConsistency();
567 listBox.HideEditBox(true, false, true);
570 if(listBox.currentRow && listBox.currentRow.index * listBox.rowHeight > listBox.scroll.y + height - listBox.rowHeight)
571 listBox.SetScrollPosition(listBox.scroll.x, listBox.currentRow.index * listBox.rowHeight - height + listBox.rowHeight);
572 else if(!listBox.currentRow || listBox.currentRow.index * listBox.rowHeight < listBox.scroll.y)
574 int line = listBox.currentRow ? listBox.currentRow.index * listBox.rowHeight : 0;
575 //SNAPUP(line, listBox.rowHeight);
576 listBox.SetScrollPosition(listBox.scroll.x, line);
579 listBox.OnVScroll(0, listBox.scroll.y, 0);
581 listBox.modifiedDocument = true;
583 listBox.Update(null);
590 any_object GetData(DataField field)
594 ListBoxCell cell = listBox.GetCell(&this, &field);
595 if(cell && cell.isSet && cell.data)
597 if((field.dataType.type == normalClass || field.dataType.type == noHeadClass))
606 void * SetData(DataField field, any_object newData)
610 ListBoxCell cell = listBox.GetCell(&this, &field);
613 Class dataType = field.dataType;
617 if(dataType.type == normalClass || dataType.type == noHeadClass)
619 if(cell.data[0] && field.freeData)
620 ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, cell.data[0]);
622 if(eClass_IsDerived(dataType, class(char *)) && field.freeData)
623 ((void (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCopy])(dataType, cell.data, newData);
625 cell.data[0] = (void *)newData;
629 // Free old data first
630 ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, cell.data);
631 ((void (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCopy])(dataType, cell.data, newData);
635 listBox.modifiedDocument = true;
636 listBox.Update(null);
637 if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
646 void UnsetData(DataField field)
650 ListBoxCell cell = listBox.GetCell(&this, &field);
653 Class dataType = field.dataType;
657 if(dataType.type == normalClass || dataType.type == noHeadClass)
659 if(cell.data[0] && field.freeData)
660 ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, cell.data[0]);
665 int size = (field.dataType && field.dataType.typeSize) ?
666 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
667 // Free old data first
668 ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, cell.data);
669 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
673 listBox.Update(null);
678 DataRow FindRow(int64 tag)
681 for(row = subRows.first; row; row = row.next)
683 if(!row.noneRow && row.tag == tag)
689 DataRow FindSubRow(int64 tag)
692 for(row = subRows.first; row; row = row.next)
694 if(!row.noneRow && row.tag == tag)
696 if(row.subRows.first)
698 DataRow subRow = row.FindSubRow(tag);
706 DataRow AddRowAfter(DataRow after)
716 subRows.Insert(after, row);
717 row.listBox = listBox;
721 for(c = 0; c<listBox.fields.count; c++)
723 for(field = listBox.fields.first; field; field = field.next)
724 if((int)field.index == c)
728 int size = (field.dataType && field.dataType.typeSize) ?
729 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
730 ListBoxCell cell = (ListBoxCell)new0 byte[size];
732 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
741 if(after && after.subRows.first && !after.collapsed)
743 for(search = after.subRows.last; !search.collapsed && search.subRows.last; )
744 search = search.subRows.last;
745 row.index = search.index + 1;
748 row.index = after ? (after.index + 1) : (index + 1);
752 for(search = row.GetNextRow(); search; search = search.GetNextRow())
755 listBox.SetScrollArea(
757 (listBox.rowCount * listBox.rowHeight) +
758 ((listBox.style.header) ? listBox.rowHeight : 0) -
759 ((!((listBox.clientSize.h+1) % listBox.rowHeight)) ? listBox.rowHeight : 0), true);
760 if(listBox.style.autoScroll)
761 listBox.SetScrollPosition(0, MAXINT - listBox.rowHeight);
764 listBox.modifiedDocument = true;
767 listBox.CheckConsistency();
777 return AddRowAfter(subRows.last);
781 DataRow AddStringf(const char * format, ...)
786 char string[MAX_F_STRING];
788 va_start(args, format);
789 vsnprintf(string, sizeof(string), format, args);
790 string[sizeof(string)-1] = 0;
794 row.SetData(null, string);
800 DataRow AddString(const char * string)
806 row.SetData(listBox.fields.first, string);
816 subRows.offset = (uint)(uintptr)&((DataRow)0).prev;
821 ListBoxCell cell, next;
826 while((subRow = subRows.first))
828 subRows.Remove(subRow);
832 for(cell = cells.first; cell; cell = next, cellIndex++)
837 for(field = listBox.fields.first; field && field.index != cellIndex; field = field.next);
838 if(field && field.dataType)
840 // TOCHECK: Is this check good? Will need incref/decref sometime?
841 if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
843 if(cell.data[0] && field.freeData)
844 ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data[0]);
847 ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data);
857 return !this || (!collapsed && (!parent || parent.IsExpanded()));
860 int Compare(DataRow b, DataField sortField)
863 ListBoxCell cell1, cell2;
865 for(index = 0, cell1 = cells.first, cell2 = b.cells.first;
866 index != sortField.index;
867 index++, cell1 = cell1.next, cell2 = cell2.next);
869 if(!cell1.isSet && !cell2.isSet)
871 else if(!cell1.isSet)
873 else if(!cell2.isSet)
876 if(noneRow && !b.noneRow) return -1;
877 else if(!noneRow && b.noneRow) return 1;
878 else if(noneRow && b.noneRow) return 0;
880 if(sortField.dataType._vTbl[__ecereVMethodID_class_OnCompare])
882 if(sortField.dataType.type == normalClass || sortField.dataType.type == noHeadClass)
884 result = ((int (*)(void *, void *, void *))(void *)sortField.dataType._vTbl[__ecereVMethodID_class_OnCompare])(sortField.dataType,
885 (cell1.isSet && cell1.data) ? cell1.data[0] : null,
886 (cell2.isSet && cell2.data) ? cell2.data[0] : null);
890 result = ((int (*)(void *, void *, void *))(void *)sortField.dataType._vTbl[__ecereVMethodID_class_OnCompare])(sortField.dataType,
891 cell1.isSet ? cell1.data : null,
892 cell2.isSet ? cell2.data : null);
895 return sortField.sortOrder * result;
898 void _SortSubRows(DataField field, int order)
901 for(search = subRows.first; search; search = search.next)
902 search._SortSubRows(field, order);
903 subRows.Sort(Compare, field);
906 public void SortSubRows(bool scrollToCurrent)
908 if(this && listBox && listBox.sortField)
910 _SortSubRows(listBox.sortField, listBox.sortField.sortOrder);
915 for(search = this; search; search = search.GetNextRow())
920 int headerSize = ((listBox.style.header) ? listBox.rowHeight : 0);
921 int height = listBox.clientSize.h + 1 - headerSize;
922 if(listBox.currentRow && listBox.currentRow.index * listBox.rowHeight > listBox.scroll.y + height - listBox.rowHeight)
923 listBox.SetScrollPosition(listBox.scroll.x, listBox.currentRow.index * listBox.rowHeight - height + listBox.rowHeight);
924 else if(!listBox.currentRow || listBox.currentRow.index * listBox.rowHeight < listBox.scroll.y)
925 listBox.SetScrollPosition(listBox.scroll.x, listBox.currentRow ? listBox.currentRow.index * listBox.rowHeight : 0);
926 listBox.OnVScroll(0, listBox.scroll.y, 0);
931 public DataRow GetPrevRow()
937 for(row = prev; row && !row.collapsed && row.subRows.last; row = row.subRows.last);
944 public DataRow GetNextRow()
948 if(subRows.first && !collapsed)
952 for(row = this; row; row = row.parent)
954 if(row.next) { row = row.next; break; }
960 private DataRow GetLastRow()
963 while(row && !row.collapsed && row.subRows.last)
964 row = row.subRows.last;
971 SelectedFlag selectedFlag;
982 public class ListBox : CommonControl
984 hasVertScroll = true;
985 // background = white;
987 snapVertScroll = true;
989 class_property(icon) = "<:ecere>controls/listBox.png";
993 property bool freeSelect { property_category $"Behavior" set { style.freeSelect = value; } get { return style.freeSelect; } };
994 property DataRow currentRow { property_category $"Private" /*"Behavior"*/ set { if(this) SetCurrentRow(value, false); } get { return this ? currentRow : null; } };
995 property DataField currentField
997 get { return currentField; }
998 // TODO: Document what this does
1001 currentField = value;
1002 HideEditBox(true, true, false);
1003 if(value && value.editable)
1004 PopupEditBox(currentField, false);
1008 property int rowHeight
1010 property_category $"Appearance"
1011 isset { return style.heightSet; }
1016 style.heightSet = true;
1018 SetScrollLineStep(8, value);
1022 style.heightSet = false;
1027 get { return this ? rowHeight : 0; }
1029 property Seconds typingTimeout
1031 property_category $"Behavior"
1034 typedString[0] = '\0';
1035 typingTimer.delay = value;
1036 typingTimeOut = value;
1038 get { return typingTimeOut; }
1040 property bool moveRows { property_category $"Behavior" set { style.moveRows = value; } get { return style.moveRows; } };
1041 property bool moveFields { property_category $"Behavior" set { style.moveFields = value; } get { return style.moveFields; } };
1042 property bool resizable { property_category $"Behavior" set { style.resizable = value; } get { return style.resizable; } };
1043 property bool autoScroll { property_category $"Behavior" set { style.autoScroll = value; } get { return style.autoScroll; } };
1044 property bool alwaysHighLight { property_category $"Appearance" set { style.alwaysHL = value; } get { return style.alwaysHL; } };
1045 property bool hasClearHeader { property_category $"Appearance" set { style.clearHeader = value; if(value) property::hasHeader = true; } get { return style.clearHeader; } };
1046 property bool hasHeader
1048 property_category $"Appearance"
1051 if(value && !style.header)
1057 bevel = !guiApp.textMode && !style.clearHeader;
1058 dontScrollVert = true;
1061 NotifyPushed = HeaderPushed;
1062 NotifyClicked = HeaderClicked;
1063 NotifyDoubleClick = HeaderDoubleClicked;
1064 NotifyReleased = HeaderReleased;
1065 NotifyMouseMove = HeaderMouseMove;
1069 endBevel.visible = false;
1071 style.header = value;
1073 get { return style.header; }
1075 property bool multiSelect { property_category $"Behavior" set { style.multiSelect = value; } get { return style.multiSelect; } };
1076 property bool alwaysEdit { property_category $"Behavior" set { style.alwaysEdit = value; } get { return style.alwaysEdit; } };
1077 property bool fullRowSelect { property_category $"Appearance" set { style.fullRowSelect = value; } get { return style.fullRowSelect; } };
1078 property bool collapseControl { property_category $"Appearance" set { style.collapse = value; } get { return style.collapse; } };
1079 property bool treeBranches { property_category $"Appearance" set { style.treeBranch = value; } get { return style.treeBranch; } };
1080 property bool rootCollapseButton { property_category $"Appearance" set { style.rootCollapse = value; } get { return style.rootCollapse; } };
1081 property bool sortable { property_category $"Behavior" set { style.sortable = value; } get { return style.sortable; } };
1082 property bool noDragging { property_category $"Behavior" set { style.noDragging = value; } get { return style.noDragging; } };
1083 property bool fillLastField
1085 property_category $"Behavior"
1088 style.fillLastField = value;
1090 get { return style.fillLastField; }
1092 property int numSelections
1096 int numSelections = 0;
1097 if(this && style.multiSelect)
1100 for(row = rows.first; row; row = row.GetNextRow())
1101 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
1104 return numSelections;
1107 property int currentIndex
1109 get { return currentRow ? currentRow.index : -1; }
1111 property DataRow lastRow { get { return this ? rows.last : null; } };
1112 property DataRow firstRow { get { return this ? rows.first : null; } };
1113 property int rowCount { get { return rowCount; } };
1114 property DataField firstField { get { return this ? fields.first : null; } };
1115 property Color selectionColor { set { selectionColor = value; } get { return selectionColor; } isset { return selectionColor ? true : false; } };
1116 property Color selectionText { set { selectionText = value; } get { return selectionText; } isset { return selectionText ? true : false; } };
1117 property Color stippleColor { set { stippleColor = value; } get { return stippleColor; } };
1118 property bool expandOnAdd { set { style.expandOnAdd = value; } get { return style.expandOnAdd; } };
1121 virtual bool Window::NotifySelect(ListBox listBox, DataRow row, Modifiers mods);
1122 virtual bool Window::NotifyHighlight(ListBox listBox, DataRow row, Modifiers mods);
1123 virtual bool Window::NotifyReclick(ListBox listBox, DataRow row, Modifiers mods);
1124 virtual bool Window::NotifySort(ListBox listBox, DataField field, Modifiers mods);
1125 virtual bool Window::NotifyChanged(ListBox listBox, DataRow row);
1126 virtual bool Window::NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch);
1127 virtual bool Window::NotifyEdited(ListBox listBox, DataRow row);
1128 virtual bool Window::NotifyEditDone(ListBox listBox, DataRow row);
1129 virtual bool Window::NotifyMovedField(ListBox listBox, DataField field, Modifiers mods);
1130 virtual bool Window::NotifyMove(ListBox listBox, DataRow row, Modifiers mods);
1131 virtual bool Window::NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods);
1132 virtual bool Window::NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods);
1133 virtual bool Window::NotifyResized(ListBox listBox, DataField field, Modifiers mods);
1134 virtual bool Window::NotifyCollapse(ListBox listBox, DataRow row, bool collapsed);
1135 virtual bool Window::NotifyKeyHit(ListBox listBox, DataRow row, Key key, unichar ch);
1136 virtual bool Window::NotifyModified(ListBox listBox, DataRow row);
1137 virtual bool Window::NotifyEditing(ListBox listBox, DataRow row);
1138 virtual void Window::NotifyMoved(ListBox listBox, DataRow row, Modifiers mods);
1141 private void CheckConsistency()
1146 for(r = rows.first; r; r = r.GetNextRow())
1148 if(r.index != index++)
1156 void AddField(DataField addedField)
1161 if(fields.first && ((DataField)fields.first).defaultField)
1163 DataField defaultField = fields.first;
1164 defaultField.Free();
1165 delete defaultField;
1169 addedField = DataField { };
1173 addedField.listBox = this;
1174 fields.Add(addedField);
1176 addedField.sortOrder = 1;
1177 addedField.index = numFields;
1181 addedField.headButton.Destroy(0);
1182 delete addedField.headButton;
1183 addedField.headButton = Button
1188 dontScrollVert = true;
1189 id = (int64)(intptr)addedField;
1190 text = addedField.header;
1191 bevel = (!guiApp.textMode && !style.clearHeader);
1193 alignment = addedField.alignment;
1194 NotifyPushed = HeaderPushed;
1195 NotifyClicked = HeaderClicked;
1196 NotifyDoubleClick = HeaderDoubleClicked;
1197 NotifyReleased = HeaderReleased;
1198 NotifyMouseMove = HeaderMouseMove;
1200 incref addedField.headButton;
1201 addedField.headButton.Create();
1204 addedField.headButton.background = Color { 0, 170, 0 };
1210 for(row = rows.first; row; )
1212 int size = (field.dataType && field.dataType.typeSize) ?
1213 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1214 ListBoxCell cell = (ListBoxCell)new0 byte[size];
1215 row.cells.Add(cell);
1216 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
1219 if(row.subRows.first)
1220 row = row.subRows.first;
1223 for(; row; row = row.parent)
1225 if(row.next) { row = row.next; break; }
1230 OnResize(clientSize.w, clientSize.h);
1239 Clear(); // Ensure data is cleared first
1240 while((field = fields.first))
1245 endBevel.visible = false;
1250 void RemoveField(DataField field)
1256 int index = field.index;
1259 if(sortField == field)
1262 for(row = rows.first; row; )
1267 for(cell = row.cells.first, c = 0; c < index && cell; c++, cell = cell.next);
1268 if(cell && index == c)
1272 // TOCHECK: Is this check good? Will need incref/decref sometime?
1273 if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
1275 if(cell.data[0] && field.freeData)
1276 ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data[0]);
1279 ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data);
1282 row.cells.Remove(cell);
1286 if(row.subRows.first)
1287 row = row.subRows.first;
1290 for(; row; row = row.parent)
1292 if(row.next) { row = row.next; break; }
1301 endBevel.visible = false;
1305 DataRow AddRowNone()
1307 DataRow row { noneRow = true };
1314 rows.Insert(null, row);
1317 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1323 firstRowShown = row;
1327 (rowCount * rowHeight) +
1328 ((style.header) ? rowHeight : 0) -
1329 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1330 if(style.autoScroll)
1331 SetScrollPosition(0, MAXINT - rowHeight);
1332 modifiedDocument = true;
1351 // Find very last row
1354 for(lastRow = rows.last; lastRow && !lastRow.collapsed && lastRow.subRows.last; lastRow = lastRow.subRows.last);
1355 row.index = lastRow ? (lastRow.index + 1) : 0;
1363 for(c = 0; c<fields.count; c++)
1365 for(field = fields.first; field; field = field.next)
1366 if((int)field.index == c)
1370 int size = (field.dataType && field.dataType.typeSize) ?
1371 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1372 ListBoxCell cell = (ListBoxCell) new0 byte[size];
1373 row.cells.Add(cell);
1374 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
1381 firstRowShown = row;
1387 (rowCount * rowHeight) +
1388 ((style.header) ? rowHeight : 0) -
1389 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1390 if(style.autoScroll)
1391 SetScrollPosition(0, MAXINT - rowHeight);
1392 modifiedDocument = true;
1403 DataRow AddRowAfter(DataRow after)
1415 if(after && after.subRows.first && !after.collapsed)
1417 for(search = after.subRows.last; !search.collapsed && search.subRows.last; )
1418 search = search.subRows.last;
1419 row.index = search.index + 1;
1422 row.index = after ? (after.index + 1) : 0;
1423 rows.Insert(after, row);
1426 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1431 for(c = 0; c<fields.count; c++)
1433 for(field = fields.first; field; field = field.next)
1434 if((int)field.index == c)
1438 int size = (field.dataType && field.dataType.typeSize) ?
1439 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1440 ListBoxCell cell = (ListBoxCell) new0 byte[size];
1441 row.cells.Add(cell);
1442 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
1446 if(!firstRowShown || !after)
1448 firstRowShown = row;
1453 (rowCount * rowHeight) +
1454 ((style.header) ? rowHeight : 0) -
1455 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1456 if(style.autoScroll)
1457 SetScrollPosition(0, MAXINT - rowHeight);
1458 modifiedDocument = true;
1468 DataRow AddStringf(const char * format, ...)
1474 char string[MAX_F_STRING];
1477 va_start(args, format);
1478 vsnprintf(string, sizeof(string), format ? format : "", args);
1479 string[sizeof(string)-1] = 0;
1483 row.SetData(fields.first, string);
1489 DataRow AddString(const char * string)
1495 row.SetData(fields.first, string);
1501 void SelectRow(DataRow row)
1503 SetCurrentRow(row, true);
1506 void DeleteRow(DataRow row)
1508 if(!row) row = currentRow;
1511 DataRow sub, next, search;
1512 // Trying to move this here (Messed up deleting watches)
1513 //HideEditBox(false, false, true);
1516 for(sub = row.subRows.first; sub; sub = next)
1522 if(row.parent.IsExpanded())
1524 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1529 HideEditBox(false, false, true);
1531 if(row == clickedRow)
1533 clickedRow = row.GetNextRow();
1535 clickedRow = row.GetPrevRow();
1538 if(row == currentRow)
1540 DataRow newCurrentRow = row.GetNextRow();
1542 newCurrentRow = row.GetPrevRow();
1543 SetCurrentRow(newCurrentRow, true);
1546 if(row == firstRowShown)
1548 firstRowShown = row.GetPrevRow();
1550 firstRowShown = row.GetNextRow();
1553 (row.parent ? row.parent.subRows: rows).Remove(row);
1556 //HideEditBox(false, false, true);
1560 (rowCount * rowHeight) +
1561 ((style.header) ? rowHeight : 0) -
1562 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1564 modifiedDocument = true;
1573 DataRow FindRow(int64 tag)
1578 for(row = rows.first; row; row = row.next)
1580 if(!row.noneRow && row.tag == tag)
1588 DataRow FindString(const char * searchedString)
1591 bool checkNextField = true;
1593 for(field = fields.first; field; field = field.next)
1595 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1598 for(row = rows.first; row; row = row.GetNextRow())
1602 void * data = row.GetData(field);
1603 char tempString[1024] = "";
1604 bool needClass = false;
1605 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1607 if(string && string[0])
1608 checkNextField = false;
1609 if(string && string[0] && !strcmp(string, searchedString))
1614 if(!checkNextField) break;
1619 DataRow FindSubString(const char * subString)
1622 bool checkNextField = true;
1623 int len = subString ? strlen(subString) : 0;
1627 for(field = fields.first; field; field = field.next)
1629 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1632 for(row = rows.first; row; row = row.GetNextRow())
1636 void * data = row.GetData(field);
1637 char tempString[1024] = "";
1638 bool needClass = false;
1639 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1641 if(string && string[0])
1642 checkNextField = false;
1643 if(string && string[0] && !strncmp(string, subString, len))
1648 if(!checkNextField) break;
1654 DataRow FindSubStringi(const char * subString)
1657 bool checkNextField = true;
1658 int len = subString ? strlen(subString) : 0;
1659 DataRow result = null;
1660 const char * bestResult = null;
1665 for(field = fields.first; field; field = field.next)
1667 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1670 for(row = rows.first; row; row = row.GetNextRow())
1674 void * data = row.GetData(field);
1675 char tempString[1024] = "";
1676 bool needClass = false;
1677 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1679 if(string && string[0])
1680 checkNextField = false;
1681 if(string && string[0])
1683 int stringLen = strlen(string);
1685 if(!strnicmp(string, subString, Min(len, stringLen)))
1687 if(bestLen < Min(len, stringLen))
1689 if(!bestResult || strcmpi(string, bestResult) < 0)
1691 bestLen = Min(len, stringLen);
1692 bestResult = string;
1700 if(!checkNextField) break;
1706 DataRow FindSubStringAfter(DataRow after, const char * subString)
1709 bool checkNextField = true;
1710 int len = subString ? strlen(subString) : 0;
1714 for(field = fields.first; field; field = field.next)
1716 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1719 for(row = after.GetNextRow(); row && row != after; row = row.GetNextRow(), (!row) ? (row = rows.first) : null)
1723 void * data = row.GetData(field);
1724 char tempString[1024] = "";
1725 bool needClass = false;
1726 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1728 if(string && string[0])
1729 checkNextField = false;
1730 if(string && string[0] && !strncmp(string, subString, len))
1735 if(!checkNextField) break;
1741 DataRow FindSubRow(int64 tag)
1747 for(row = rows.first; row; row = row.next)
1749 if(!row.noneRow && row.tag == tag)
1751 if(!row.noneRow && row.subRows.first)
1753 DataRow subRow = row.FindSubRow(tag);
1767 Window master = this.master;
1769 HideEditBox(false, true, false);
1770 editData.Destroy(0);
1772 firstRowShown = currentRow = null;
1777 if(style.freeSelect)
1778 NotifyHighlight(master, this, currentRow ? currentRow : null, 0);
1780 NotifySelect(master, this, currentRow ? currentRow : null, 0);
1783 if(style.alwaysEdit && currentRow)
1784 currentRow.Edit(currentField);
1791 (rowCount * rowHeight) +
1792 ((style.header) ? rowHeight : 0) -
1793 ((rowHeight && !((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1798 void Sort(DataField field, int order)
1803 int headerSize = ((style.header) ? rowHeight : 0);
1804 int height = clientSize.h + 1 - headerSize;
1806 if(!field) field = fields.first;
1808 field.sortOrder = order ? order : 1;
1809 rows.Sort(DataRow::Compare, field);
1811 for(search = rows.first; search; search = search.next)
1812 search._SortSubRows(field, order);
1816 for(search = rows.first; search; search = search.GetNextRow())
1817 search.index = index++;
1820 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
1821 SetScrollPosition(scroll.x, currentRow.index * rowHeight - height + rowHeight);
1822 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
1823 SetScrollPosition(scroll.x, currentRow ? currentRow.index * rowHeight : 0);
1825 OnVScroll(0, scroll.y, 0);
1827 // SetScrollPosition(0, scroll.y);
1832 void StopEditing(bool save)
1834 HideEditBox(save, false, true);
1837 void GetMultiSelection(OldList list)
1840 if(this && style.multiSelect)
1844 for(row = rows.first; row; row = row.GetNextRow())
1846 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
1848 list.Add(OldLink { data = row });
1854 // Convenience Current Row Methods
1855 void * SetData(DataField field, any_object data)
1857 return currentRow.SetData(field, data);
1860 any_object GetData(DataField field)
1862 return (void *)currentRow.GetData(field);
1867 return currentRow ? currentRow.tag : 0;
1873 DataField defaultField { };
1874 rows.offset = (uint)(uintptr)&((DataRow)0).prev;
1875 fields.offset = (uint)(uintptr)&((DataField)0).prev;
1876 style.fullRowSelect = true;
1877 style.fillLastField = true;
1878 style.expandOnAdd = true;
1879 typingTimeOut = 0.5;
1880 rowHeight = 16; // Stuff depending on creation and default property checking
1883 defaultField.defaultField = true;
1885 AddField(defaultField);
1887 typedString = new char[1];
1888 typedString[0] = '\0';
1903 while((field = fields.first))
1905 // fields.Remove(field);
1915 while((row = rows.first))
1922 ListBoxCell GetCell(DataRow * row, DataField * field)
1924 ListBoxCell cell = null;
1925 if(!*row) *row = currentRow;
1928 if(!*field) *field = this ? currentField : null;
1931 for(*field = fields.first; (*field).index != 0; *field = (*field).next);
1936 if(field->listBox == this)
1938 for(index = 0, cell = (*row).cells.first; cell && index != (*field).index; index++, cell = cell.next);
1945 void HideEditBox(bool save, bool alwaysStopEdit, bool repositionOnly)
1947 if(editData && editData.visible)
1950 editData.SaveData();
1952 editData.visible = false;
1953 NotifyEditDone(master, this, currentRow);
1955 // ENSURE DATA BOX IS NOT VISIBLE
1956 editData.visible = false;
1958 if(style.alwaysEdit && !alwaysStopEdit)
1961 int height = rowHeight - (style.alwaysEdit ? 1 : 0);
1962 int y = currentRow.index * rowHeight + (style.header ? rowHeight : 0);
1963 int x = currentField.x;
1964 int width = (!currentField.next && style.fillLastField && (!hasHorzScroll || clientSize.w - currentField.x > currentField.width + EXTRA_SPACE)) ?
1965 clientSize.w - currentField.x : (currentField.width + EXTRA_SPACE);
1967 if(!style.alwaysEdit)
1969 editData.position = { x, y };
1970 editData.size = { width, height };
1974 editData.position = { x, y - editData.clientStart.y };
1975 editData.size = { width, height + editData.clientStart.y * 2 };
1977 editData.visible = true;
1978 if(style.alwaysEdit)
1979 editData.Deactivate();
1981 PopupEditBox(currentField, repositionOnly);
1985 currentField = null;*/
1989 void SetCurrentRow(DataRow row, bool notify)
1991 if(this && (currentRow != row || (currentRow && currentRow.selectedFlag == unselected)))
1993 int headerSize = ((style.header) ? rowHeight : 0);
1994 int height = clientSize.h + 1 - headerSize;
1996 // true: destroy edit box
1997 HideEditBox(true, true, false);
1999 if(!(style.multiSelect) && currentRow)
2000 currentRow.selectedFlag = unselected;
2004 if(style.multiSelect)
2008 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
2009 selRow.selectedFlag = unselected;
2011 currentRow.selectedFlag = selected;
2016 currentRow.selectedFlag = selected;
2018 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
2019 SetScrollPosition(scroll.x,
2020 currentRow.index * rowHeight - height + rowHeight);
2021 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
2023 int line = currentRow ? currentRow.index * rowHeight : 0;
2024 //SNAPUP(line, rowHeight);
2025 SetScrollPosition(scroll.x, line);
2030 Window master = this.master;
2033 if(style.freeSelect && visible)
2034 NotifyHighlight(master, this, currentRow ? currentRow : null, 0);
2036 NotifySelect(master, this, currentRow ? currentRow : null, 0);
2037 if(style.alwaysEdit && currentRow)
2038 currentRow.Edit(currentField);
2046 void RepositionFieldEditor()
2048 if(editData && editData.visible)
2050 int height = rowHeight - (style.alwaysEdit ? 1 : 0);
2052 int y = currentRow.index * rowHeight + (style.header ? rowHeight : 0);
2056 if(style.collapse && !(style.treeBranch))
2058 for(field = fields.first; field; field = field.next)
2060 width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2061 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2062 if(field == currentField) break;
2065 if(!style.alwaysEdit)
2067 editData.position = { x, y - editData.clientStart.y };
2068 editData.size = { width, height + editData.clientStart.y * 2 };
2072 editData.position = { x, y };
2073 editData.size = { width, height };
2078 void PopupEditBox(DataField whichField, bool repositionOnly)
2080 if((!editData || !editData.visible || currentField != whichField) && currentRow)
2082 // true: destroy edit box
2083 HideEditBox(true, true, false);
2086 int height = rowHeight - (style.alwaysEdit ? 1 : 0);
2088 int y = currentRow.index * rowHeight + (style.header ? rowHeight : 0);
2090 //void * data = currentRow.GetData(whichField);
2095 if(style.collapse && !(style.treeBranch))
2098 for(field = fields.first; field; field = field.next)
2100 width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2101 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2102 if(field == whichField) break;
2106 currentField = whichField;
2107 cell = GetCell(&row, ¤tField);
2114 background = dataBoxBackground;
2115 foreground = dataBoxForeground;
2117 bool NotifyChanged(DataBox dataBox, bool closingDropDown)
2120 DataField field = null;
2121 ListBoxCell cell = GetCell(&row, &field);
2125 modifiedDocument = true;
2127 NotifyChanged(master, this, currentRow);
2132 bool NotifyModified()
2134 //DataRow row = null;
2135 //DataField field = null;
2136 //ListBoxCell cell = GetCell(&row, &field);
2137 //cell.isSet = true;
2138 modifiedDocument = true;
2140 NotifyModified(master, this, currentRow);
2144 bool OnKeyDown(Key key, unichar ch)
2146 bool result = DataBox::OnKeyDown(key, ch);
2147 if(visible && active) // Added this check here, because we will not use enter/escape otherwise, and lose DataBox's result
2149 if((SmartKey)key == enter || (SmartKey)key == escape)
2158 editData.Destroy(0);
2159 editData.type = whichField.dataType;
2160 editData.fieldData = whichField.userData;
2161 editData.borderStyle = style.alwaysEdit ? 0 : deep;
2162 editData.data = cell ? cell.data : null;
2165 // Might not really need this anymore...
2166 NotifyEditing(master, this, currentRow);
2169 if(!style.alwaysEdit)
2171 editData.position = { x, y - editData.clientStart.y };
2172 editData.size = { width, height + editData.clientStart.y * 2 };
2176 editData.position = { x, y };
2177 editData.size = { width, height };
2181 editData.visible = true;
2183 if(style.alwaysEdit)
2184 editData.Deactivate();
2186 // MOVED THIS HIGHER FOR DATALIST EDITOR
2188 // Might not really need this anymore...
2189 NotifyEdited(master, this, currentRow);
2194 void OnRedraw(Surface surface)
2197 int y = (style.header) ? rowHeight : 0;
2198 bool isActive = active;
2199 Font font = fontObject;
2200 Font boldFont = this.boldFont.font;
2203 if(style.alwaysEdit && style.fullRowSelect)
2206 int y = (style.header) ? rowHeight : 0;
2207 int x = -scroll.x - 1;// + EXTRA_SPACE;// / 2 - 1;
2208 int w = clientSize.w;
2209 int h = clientSize.h;
2213 // Fill out indent column
2214 if(style.collapse && !(style.treeBranch) && (style.header || rows.first))
2217 surface.SetBackground(formColor);
2218 surface.Area(-scroll.x, 0, x, clientSize.h);
2221 surface.SetForeground(formColor);
2222 for(row = firstRowShown; row; row = row.GetNextRow())
2225 surface.HLine(x + 1, w-1, y-1);
2231 for(field = fields.first; field; field = field.next)
2233 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2234 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2235 if(field.prev && y > 0)
2236 surface.VLine(0, y-1, x);
2241 surface.foreground = this.foreground;
2242 surface.TextOpacity(false);
2244 // Draw the tree branches
2245 if(style.treeBranch)
2247 int y = -scroll.y + ((style.header) ? rowHeight : 0);
2248 surface.LineStipple(0x5555);
2249 surface.SetForeground(branchesColor);
2250 for(row = rows.first; row; row = row.GetNextRow() )
2252 int x = -scroll.x + EXTRA_SPACE / 2-1;
2253 int rowStart = -scroll.x;
2258 for(parent = row.parent; parent; parent = parent.parent)
2259 if(!parent.header) indent += 20;
2260 if(style.rootCollapse) indent += 20;
2262 plusIndent = (style.treeBranch) ? (indent - 20 + 4) : indent;
2267 if(row.subRows.first)
2270 int y1 = y + PLUSY + 4;
2274 for(child = row.collapsed ? null : row.subRows.first; child && child != row; )
2277 if(child.subRows.first && !child.collapsed && child != row.subRows.last)
2278 child = child.subRows.first;
2283 for(; child && child != row; child = child.parent)
2293 y2 = y + numRows * rowHeight + PLUSY + 4;
2294 surface.VLine(y1, y2, rowStart + plusIndent + 7 + 20);
2296 surface.HLine(rowStart + plusIndent + 7, rowStart + indent, y + PLUSY + 4);
2299 if(y >= clientSize.h)
2302 // Root Vertical Lines
2303 if(style.rootCollapse && rows.first)
2308 y = -scroll.y + ((style.header) ? rowHeight : 0);
2310 for(child = rows.first; child && child != rows.last; )
2313 if(child.subRows.first && !child.collapsed && child != rows.last)
2314 child = child.subRows.first;
2319 for(; child; child = child.parent)
2329 y2 = y + numRows * rowHeight + PLUSY + 4;
2330 surface.VLine(y1, y2, -scroll.x + 11);
2332 surface.LineStipple(0);
2335 for(row = firstRowShown; row; row = row.GetNextRow() )
2337 int x = -scroll.x + EXTRA_SPACE / 2-1;
2340 Color foreground = this.foreground /*black*/, background = this.background /*white*/;
2341 DataDisplayFlags dataDisplayFlags = 0;
2342 int rowStart = -scroll.x;
2345 Bitmap icon = row.icon ? row.icon.bitmap : null;
2346 int collapseRowStart = 0;
2347 bool lastWasHeader = row.header;
2349 for(parent = row.parent; parent; parent = parent.parent)
2351 if(!parent.header || lastWasHeader)
2353 if(style.treeBranch)
2359 if(style.rootCollapse) indent += 20;
2362 dataDisplayFlags.fullRow = style.fullRowSelect;
2363 dataDisplayFlags.active = isActive;
2364 dataDisplayFlags.header = row.header;
2369 collapseRowStart = rowStart;
2371 if(!(style.treeBranch))
2378 if(style.multiSelect)
2380 dataDisplayFlags.selected = row.selectedFlag == selected || row.selectedFlag == tempSelected;
2381 dataDisplayFlags.current = row == currentRow || (!currentRow && row == firstRowShown);
2385 dataDisplayFlags.selected = row.selectedFlag == selected || row.selectedFlag == tempSelected;
2386 dataDisplayFlags.current = row == currentRow || (!currentRow && row == firstRowShown);
2388 if(row == currentRow)
2390 dataDisplayFlags.current = true;
2391 dataDisplayFlags.selectedFlag = true;
2393 else if(!currentRow && row == firstRowShown)
2395 dataDisplayFlags.current = true;
2399 surface.TextOpacity(true);
2401 background = this.background;
2402 foreground = this.foreground;
2404 // Draw the current row background
2407 Color colors[] = { formColor, azure, mistyRose, linen, floralWhite, lavender, lavenderBlush, lemonChiffon };
2410 while((p = p.parent)) level++;
2411 background = colors[level % (sizeof(colors)/sizeof(colors[0]))];
2412 surface.SetBackground(background);
2413 surface.Area(rowStart, y, clientSize.w, (y + rowHeight) - 1);
2414 foreground = branchesColor;
2416 else if(dataDisplayFlags.selected)
2418 if(dataDisplayFlags.selected && (isActive || style.alwaysHL || (style.alwaysEdit && style.fullRowSelect)))
2420 if(!isActive && style.alwaysEdit)
2421 background = formColor;
2423 background = selectionColor ? selectionColor : SELECTION_COLOR;
2424 if(style.fullRowSelect)
2426 int offset = (style.alwaysEdit) ? 2 : 1;
2427 surface.SetBackground(background);
2428 surface.Area(rowStart, y, clientSize.w, (y + rowHeight) - offset);
2430 if(isActive || !(style.alwaysEdit))
2431 foreground = selectionText ? selectionText : SELECTION_TEXT;
2433 foreground = branchesColor;
2439 surface.Blit(icon, x + (20 - icon.width) /2,y + 2,0,0, icon.width, icon.height);
2445 int width = clientSize.w;
2447 dataDisplayFlags.firstField = true;
2448 clip.left = x - EXTRA_SPACE / 2+1;
2450 clip.right = x + width - EXTRA_SPACE/2 - 0;
2451 clip.bottom = y + rowHeight - 1;
2452 surface.Clip(&clip);
2454 surface.TextFont(font);
2456 surface.SetForeground(foreground);
2457 surface.SetBackground(background);
2459 ((void (*)(void *, const void *, void *, int, int, int, void *, uint, uint))(void *)class(String)._vTbl[__ecereVMethodID_class_OnDisplay])(class(String), "(none)", surface, x, y - 1 + (rowHeight - fontH)/2, width - EXTRA_SPACE/2, null, Alignment::left, dataDisplayFlags);
2463 if(opacity < 1) surface.TextOpacity(false);
2465 for(field = fields.first; field; field = field.next)
2468 int width = ((!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) || row.header) ?
2469 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2471 // Box clip = { x, y+1, x + field.width - EXTRA_SPACE - 1, y + rowHeight - 2 };
2474 //width -= EXTRA_SPACE;
2476 if(!field.prev) width -= indent;
2479 dataDisplayFlags.firstField = field.prev ? false : true;
2481 if(!dataDisplayFlags.firstField && !dataDisplayFlags.fullRow)
2483 background = this.background;
2484 foreground = this.foreground;
2487 if(!isActive && dataDisplayFlags.selected && style.alwaysEdit && field.editable && opacity)
2490 surface.SetBackground(background);
2491 surface.Area(x-3, y, x+width-1, y + rowHeight-2);
2494 clip.left = x - EXTRA_SPACE / 2+1;
2496 clip.right = x + width - EXTRA_SPACE/2 - 0;
2497 clip.bottom = y + rowHeight - 1;
2498 surface.Clip(&clip);
2500 for(index = 0, cell = row.cells.first; cell && index != field.index; index++, cell = cell.next);
2501 // Should always be as many cells in the row as fields in the listbox
2502 if(cell && cell.isSet && field.dataType)
2505 surface.TextFont(boldFont);
2507 surface.TextFont(font);
2509 surface.SetForeground(foreground);
2510 surface.SetBackground(background);
2512 if(field.dataType.type == noHeadClass || field.dataType.type == normalClass)
2513 ((void (*)(void *, void *, void *, int, int, int, void *, uint, uint))(void *)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);
2515 ((void (*)(void *, void *, void *, int, int, int, void *, uint, uint))(void *)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);
2518 if(!isActive && dataDisplayFlags.selected && style.alwaysEdit && field.editable)
2519 background = formColor;
2521 if(!dataDisplayFlags.firstField && !dataDisplayFlags.fullRow)
2523 background = formColor;
2524 foreground = this.background;
2528 // surface.WriteTextf(x + 100, y, "ix: %d", row.index);
2531 x += width;// + EXTRA_SPACE;
2533 if(row.header) break;
2539 int plusIndent = (style.treeBranch) ? (indent - 20 + 4) : indent;
2541 if(row.subRows.first && (row.parent || !(style.treeBranch) || (style.rootCollapse)))
2543 surface.SetForeground(row.header ? headerCollapseForeground : this.foreground);
2544 surface.Rectangle(collapseRowStart + 3 + plusIndent, y + PLUSY, collapseRowStart + 11 + plusIndent, y + PLUSY + 8);
2546 surface.SetBackground(row.header ? (formColor) : (this.background)); //white
2547 surface.Area(collapseRowStart + 4 + plusIndent, y + PLUSY + 1, collapseRowStart + 10 + plusIndent, y + PLUSY + 7);
2549 surface.HLine(collapseRowStart + 5 + plusIndent, collapseRowStart + 9 + plusIndent, y+PLUSY+4);
2551 surface.VLine(y + PLUSY + 2, y + PLUSY + 6, collapseRowStart + 7 + plusIndent);
2556 // Draw the current row stipple
2557 if(style.fullRowSelect && !(style.alwaysEdit) && (dataDisplayFlags.current) && isActive)
2562 surface.LineStipple(0x5555);
2563 if(dataDisplayFlags.selected)
2564 surface.SetForeground(stippleColor);
2566 surface.SetForeground(this.foreground);
2569 surface.SetForeground(selectionColor ? selectionColor : SELECTION_COLOR);
2570 surface.Rectangle(0, y, clientSize.w-1, (y + rowHeight) - 1);
2571 surface.LineStipple(0);
2575 if(y >= clientSize.h)
2578 if(firstRowShown) surface.Clip(null);
2579 if(dragRow && dropIndex != -1)
2584 if(!style.multiSelect && currentRow.index < dropIndex)
2586 surface.DrawingChar(223);
2588 y = style.header ? rowHeight : 0;
2589 y += ix * rowHeight - scroll.y;
2591 surface.SetForeground(Color { 85, 85, 255 });
2592 surface.HLine(0, clientSize.w-1, y);
2593 surface.HLine(0, clientSize.w-1, y + 1);
2597 void OnDrawOverChildren(Surface surface)
2599 if(draggingField && dropField)
2601 int position = dropField.x;
2602 if(draggingField.x < position)
2603 position += dropField.width + EXTRA_SPACE;
2605 surface.SetForeground(Color { 85, 85, 255 });
2606 surface.VLine(0, rowHeight - 1, position - scroll.x - 2);
2607 surface.VLine(0, rowHeight - 1, position - scroll.x);
2609 if(sortField && !style.clearHeader && style.header)
2611 DataField field = sortField;
2612 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2613 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2616 surface.TextExtent(field.header, strlen(field.header), &tw, &th);
2617 if(tw < width - EXTRA_SPACE)
2619 bool up = field.sortOrder == 1;
2623 field.x + 2 - scroll.x, 0,
2624 field.x + width + EXTRA_SPACE - 1 - scroll.x, rowHeight
2626 surface.Clip(&clip);
2627 if(field.alignment == left || field.alignment == center)
2629 if(field.alignment == center)
2630 x = field.x + (width + EXTRA_SPACE - tw) / 2 + tw + EXTRA_SPACE + 4;
2632 x = field.x + tw + EXTRA_SPACE + 4;
2634 x = Min(x, field.x + width - 4);
2636 else if(field.alignment == right)
2638 x = field.x + width - tw - 2*EXTRA_SPACE - 4;
2639 x = Max(x, field.x + 2);
2645 // surface.SetForeground((wmenu.selectedFlag == item) ? white : black);
2646 // surface.WriteText(clientSize.w-8, y+(wmenu.rh - 8)/2, "\020", 1);
2652 surface.SetForeground(Color { 128,128,128 } );
2653 surface.DrawLine(x + 3, y, x, y + 5);
2654 surface.PutPixel(x + 1, y + 5);
2655 surface.PutPixel(x + 1, y + 3);
2656 surface.PutPixel(x + 2, y + 1);
2658 surface.SetForeground(white);
2659 surface.DrawLine(x + 4, y, x + 7, y + 5);
2660 surface.PutPixel(x + 6, y + 5);
2661 surface.PutPixel(x + 6, y + 3);
2662 surface.PutPixel(x + 5, y + 1);
2664 surface.DrawLine(x, y + 6, x + 7, y + 6);
2668 surface.SetForeground(Color { 128,128,128 });
2669 surface.DrawLine(x + 3, y+6, x, y+1);
2670 surface.PutPixel(x + 1, y+1);
2671 surface.PutPixel(x + 1, y+3);
2672 surface.PutPixel(x + 2, y+5);
2674 surface.SetForeground(white);
2675 surface.DrawLine(x + 4, y+6, x + 7, y+1);
2676 surface.PutPixel(x + 6, y+1);
2677 surface.PutPixel(x + 6, y+3);
2678 surface.PutPixel(x + 5, y+5);
2680 surface.DrawLine(x, y, x + 7, y);
2689 void OnResize(int w, int h)
2692 bool showEndBevel = false;
2694 if(style.collapse && !style.treeBranch)
2696 for(field = fields.first; field; field = field.next)
2698 int width = field.width + EXTRA_SPACE;
2706 (rowCount * rowHeight) +
2707 ((style.header) ? rowHeight : 0) -
2708 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
2710 for(field = fields.first; field; field = field.next)
2712 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2713 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2714 if(style.header && field.headButton)
2716 showEndBevel = true;
2719 field.headButton.position = { field.x, 0 };
2720 field.headButton.size = { width, rowHeight };
2721 field.headButton.visible = true;
2724 field.headButton.visible = false;
2728 if(!style.fillLastField && showEndBevel && endBevel)
2730 endBevel.position = { x, 0 };
2731 endBevel.size = { clientSize.w + 2 - x, rowHeight };
2732 endBevel.visible = true;
2735 endBevel.visible = false;
2737 if(style.alwaysEdit && editData && editData.visible)
2739 HideEditBox(true, false, true);
2741 else if(editData && editData.visible)
2742 RepositionFieldEditor();
2745 void AdaptToFieldWidth(DataField field, bool doScroll)
2747 OnResize(clientSize.w, clientSize.h);
2749 // Scroll appropriately
2752 if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x &&
2753 field.x >= field.x + field.width + EXTRA_SPACE - clientSize.w)
2755 SetScrollPosition(field.x + field.width + EXTRA_SPACE - clientSize.w, scroll.y);
2757 else if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x ||
2759 SetScrollPosition(field.x, scroll.y);
2764 bool HeaderPushed(Button control, int x, int y, Modifiers mods)
2766 DataField field = (DataField)(intptr)control.id;
2767 // false: dont destroy edit box
2768 HideEditBox(true, false, true);
2769 if(style.resizable && ((!field && x < RESIZE_BORDER && fields.last) ||
2770 (field && x < RESIZE_BORDER && field.prev) ||
2771 (field && x >= control.clientSize.w - RESIZE_BORDER)))
2774 field = fields.last;
2775 else if(x < RESIZE_BORDER && field.prev)
2778 if(field.fixed) return false;
2779 resizingField = field;
2780 resizeX = x + control.position.x;
2781 startWidth = field.width;
2782 oldX = x - scroll.x;
2787 if(field.fixed) return false;
2788 draggingField = field;
2789 if(style.moveFields)
2790 field.headButton.stayDown = true;
2791 else if(!style.sortable)
2799 bool HeaderMouseMove(Button control, int x, int y, Modifiers mods)
2804 DataField field = resizingField;
2806 x += control.position.x;
2808 // Tweak to prevent shrinking field if we're actually moving right
2809 if(x - scroll.x > oldX &&
2810 startWidth + x - resizeX < field.width)
2812 oldX = x - scroll.x;
2815 oldX = x - scroll.x;
2817 field.width = startWidth + x - resizeX;
2818 field.width = Max(field.width, - EXTRA_SPACE);
2820 AdaptToFieldWidth(field, true);
2822 else if(draggingField)
2824 x += control.position.x;
2825 if(style.moveFields)
2827 DataField field = fields.last;
2829 for(field = fields.first; field; field = field.next)
2831 fieldX += ((field.width || style.resizable) ?
2832 field.width : clientSize.w) + EXTRA_SPACE;
2836 if(draggingField == field)
2838 // Reset scroll position
2839 if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x &&
2840 field.x >= field.x + field.width + EXTRA_SPACE - clientSize.w)
2843 field.x + field.width + EXTRA_SPACE - clientSize.w,
2846 else if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x ||
2848 SetScrollPosition(field.x, scroll.y);
2851 if(dropField != field)
2856 int position = field.x;
2858 if(draggingField.x < position)
2860 position += field.width + EXTRA_SPACE - clientSize.w;
2861 if(position > scroll.x)
2862 SetScrollPosition(position, scroll.y);
2867 if(position < scroll.x)
2868 SetScrollPosition(position, scroll.y);
2871 movingFields = true;
2877 else if(style.resizable)
2879 DataField field = (DataField)(intptr)control.id;
2882 if(x < RESIZE_BORDER && field.prev)
2884 if(!field.prev.fixed)
2885 control.cursor = guiApp.GetCursor(sizeWE);
2887 else if(x >= control.clientSize.w - RESIZE_BORDER)
2888 control.cursor = guiApp.GetCursor(sizeWE);
2890 control.cursor = null;
2894 if(x < RESIZE_BORDER && fields.last)
2895 control.cursor = guiApp.GetCursor(sizeWE);
2897 control.cursor = null;
2903 bool HeaderReleased(Button control, int x, int y, Modifiers mods)
2907 NotifyResized(master, this, resizingField, mods);
2908 resizingField = null;
2915 if(style.moveFields)
2920 DataField switchField = fields.last;
2924 x += draggingField.x;
2925 for(field = fields.first; field; field = field.next)
2927 fieldX += ((field.width || style.resizable) ?
2928 field.width : clientSize.w) + EXTRA_SPACE;
2931 switchField = field;
2935 if(switchField && draggingField != switchField && dropField)
2937 for(field = fields.first; field; field = field.next)
2939 if(field == switchField || field == draggingField)
2943 // Switch field first: move before
2944 if(field == switchField)
2945 draggingField.Move(switchField.prev);
2946 // Dragged field first: move after
2948 draggingField.Move(switchField);
2950 NotifyMovedField(master, this, draggingField, mods);
2952 draggingField.headButton.stayDown = false;
2957 movingFields = false;
2959 draggingField = null;
2965 bool HeaderClicked(Button control, int x, int y, Modifiers mods)
2967 if(style.header && !dropField && style.sortable)
2969 DataField field = (DataField)(intptr)control.id;
2970 if(sortField == field)
2971 field.sortOrder *= -1;
2976 Sort(sortField, field.sortOrder);
2977 NotifySort(master, this, field, mods);
2983 bool HeaderDoubleClicked(Button control, int x, int y, Modifiers mods)
2987 DataField field = (DataField)(intptr)control.id;
2990 if(x < RESIZE_BORDER && field.prev)
2992 else if(x >= control.clientSize.w - RESIZE_BORDER);
2998 if(x < RESIZE_BORDER && fields.last)
2999 field = fields.last;
3011 if(style.freeSelect)
3016 rolledOver = dragging = false;
3023 bool OnLoadGraphics()
3025 display.FontExtent(fontObject, "W", 1, null, &fontH);
3026 if(!style.heightSet)
3028 rowHeight = Max(fontH + 2, 16) + (style.alwaysEdit ? 1 : 0);
3029 SetScrollLineStep(8, rowHeight);
3034 void OnApplyGraphics()
3036 SetScrollLineStep(8, rowHeight);
3040 for(field = fields.first; field; field = field.next)
3042 if(field.headButton)
3044 field.headButton.bevel = (!guiApp.textMode && !style.clearHeader);
3046 field.headButton.background = Color { 0, 170, 0 };
3050 OnResize(clientSize.w, clientSize.h);
3053 bool OnResizing(int *w, int *h)
3057 if(!initSize.w && (!anchor.left.type || !anchor.right.type) && !*w)
3062 Font font = fontObject;
3063 Font boldFont = this.boldFont.font;
3064 Display display = this.display;
3066 for(row = rows.first; row; row = row.GetNextRow())
3068 Bitmap icon = row.icon ? row.icon.bitmap : null;
3069 int x = -scroll.x + EXTRA_SPACE / 2-1;
3073 for(parent = row.parent; parent; parent = parent.parent)
3077 if(style.treeBranch)
3083 if(style.rootCollapse) indent += 20;
3085 if(style.collapse && !(style.treeBranch)) x += 15;
3089 // Compute the rows size
3090 for(field = fields.first; field; field = field.next)
3092 if(((style.resizable && (!(style.alwaysEdit) || field.next)) || field.width) && !row.header)
3093 x += field.width - (field.prev ? 0 : indent);
3098 for(index = 0, cell = row.cells.first; index != field.index; index++, cell = cell.next);
3100 // Should always be as many cells in the row as fields in the listbox
3101 if(cell && cell.isSet && field.dataType)
3103 static char tempString[4096];
3104 const char * string;
3106 if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
3107 string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, cell.data[0], tempString, field.userData, null);
3109 string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, cell.data, tempString, field.userData, null);
3111 if(!string) string = "";
3112 display.FontExtent(row.header ? boldFont : font, string, strlen(string), &tw, &th);
3115 display.FontExtent(row.header ? boldFont : font, string, strlen(string), &tw, &th);
3117 display.FontExtent(row.header ? boldFont : font, "", 0, &tw, &th);
3120 if(row.header) break;
3124 maxWidth = Max(maxWidth, x);
3130 *h = Min(maxShown, rowCount) * rowHeight;
3135 if(!*w) *w = rowHeight * 5;
3136 if(!*h) *h = rowHeight * 5;
3143 FontResource font = this.font;
3144 FontResource boldFont
3146 faceName = font.faceName, size = font.size, bold = true
3148 AddResource(boldFont);
3149 RemoveResource(this.boldFont);
3150 this.boldFont = boldFont;
3154 SetInitSize(initSize);
3157 bool OnMouseMove(int x, int y, Modifiers mods)
3159 bool isTimer = false;
3160 int realX = x, realY = y;
3162 if(insideNotifySelect) return true;
3164 if(style.alwaysEdit && style.resizable &&
3165 resizingField && !(mods.isSideEffect))
3168 DataField field = resizingField;
3169 field.width = startWidth + x - resizeX;
3170 field.width = Max(field.width, - EXTRA_SPACE);
3172 AdaptToFieldWidth(field, true);
3176 if(style.alwaysEdit && style.resizable)
3178 int vx = -scroll.x - 1;
3181 if(style.collapse && !(style.treeBranch))
3184 for(field = fields.first; field; field = field.next)
3186 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3187 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3193 cursor = guiApp.GetCursor(sizeWE);
3197 vx += width + EXTRA_SPACE;
3201 if((editData && editData.visible) || (style.alwaysEdit))
3204 if(x == MAXINT && y == MAXINT)
3211 // ADDED THIS CHECK FOR FieldDropBox LEAKS
3212 if(/*!mods.isSideEffect && */(rolledOver || !dragging))
3214 int rowY = (style.header) ? rowHeight : 0;
3215 DataRow row = null, nextRow;
3222 ((vertScroll && vertScroll.visible &&
3223 (y < 0 || y >= clientSize.h)) ||
3224 (horzScroll && horzScroll.visible &&
3225 (x < 0 || x >= clientSize.w))))
3230 if(vertScroll && vertScroll.visible &&
3231 (y < 0 || y >= clientSize.h))
3232 vertScroll.Action((y<0)?up:down, 0, 0);
3233 if(horzScroll && horzScroll.visible &&
3234 (x < 0 || x >= clientSize.w))
3235 horzScroll.Action((x<0)?up:down, 0, 0);
3241 // This must be done after the scrolling took place
3242 rowIndex = firstRowShown ? firstRowShown.index : -1;
3244 y = Min(y, clientSize.h - ((dragRow && style.moveRows) ? rowHeight : 0)-1);
3245 for(row = firstRowShown; row; row = nextRow, rowIndex ++)
3247 nextRow = row.GetNextRow();
3249 if(rowY > y || !nextRow)
3255 if(dragRow && style.moveRows)
3257 if(row && row == currentRow)
3258 row = row.GetNextRow();
3260 if(row && row.parent == currentRow)
3261 row = row.GetNextRow();
3264 if(row && currentRow != row)
3266 if(dragRow && style.moveRows)
3268 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
3270 else if(style.multiSelect)
3273 for(thisRow = rows.first; thisRow; thisRow = thisRow.GetNextRow())
3274 if((thisRow.selectedFlag == selected || thisRow.selectedFlag == tempSelected) ||
3280 if(dropIndex != rowIndex)
3282 dropIndex = rowIndex;
3288 else if((style.freeSelect || dragging) && ((realX>= 0 && realY >= 0 && realX< clientSize.w && realY < clientSize.h) || rolledOver))
3290 if(!(style.multiSelect))
3292 if(currentRow)currentRow.selectedFlag = unselected;
3293 if(row)row.selectedFlag = selected;
3297 if(style.multiSelect)
3301 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3303 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3304 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3307 if(rowIndex >= clickedRow.index)
3309 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
3311 selRow.selectedFlag = (selRow.selectedFlag == selected) ? tempUnselected : tempSelected;
3318 for(selRow = row; selRow; selRow = selRow.GetNextRow())
3320 selRow.selectedFlag = (selRow.selectedFlag == selected) ? tempUnselected : tempSelected;
3321 if(selRow == clickedRow)
3327 if(style.freeSelect)
3328 NotifyHighlight(master, this, currentRow, mods);
3331 insideNotifySelect = true;
3332 NotifySelect(master, this, currentRow, mods);
3333 insideNotifySelect = false;
3336 if(style.alwaysEdit && currentRow)
3337 currentRow.Edit(currentField);
3344 bool OnMouseOver(int x, int y, Modifiers mods)
3351 bool OnActivate(bool active, Window swap, bool * goOnWithActivation, bool direct)
3353 // TOCHECK: WAS THIS MISSING ? CHECK FOR SLOWDOWN
3354 if(!active) Update(null);
3356 if(!active && (!swap || !swap.isModal))
3358 // true: destroy edit box
3359 HideEditBox(true, true, false);
3361 else if(!swap || !swap.isModal)
3363 // Bring back edit box
3364 if(currentRow && style.alwaysEdit)
3366 currentRow.Edit(currentField ? currentField : null);
3370 return true; //NotifyActivate(master, this, active, swap, 0);
3374 bool OnButtonDown(int x, int y, Modifiers mods, bool right)
3377 // Check to see if we're dragging the vertical divider
3378 if(style.alwaysEdit && style.resizable && !right)
3380 int vx = -scroll.x - 1;// + EXTRA_SPACE;// / 2 - 1;
3383 if(style.collapse && !(style.treeBranch))
3386 for(field = fields.first; field; field = field.next)
3388 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3389 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3395 resizingField = field.prev;
3397 startWidth = resizingField.width;
3399 SetMouseRangeToClient();
3403 vx += width + EXTRA_SPACE;
3407 if(!(style.freeSelect))
3409 int rowY = (style.header) ? rowHeight : 0;
3411 int rowIndex = firstRowShown ? firstRowShown.index : -1;
3412 DataRow previousRow = currentRow;
3413 DataRow newCurrentRow = null;
3414 bool moveMultiple = false;
3415 int numSelected = 0;
3416 int rowStart = -scroll.x;
3418 if(style.multiSelect)
3425 for(row = rows.first; row; row = row.GetNextRow())
3427 if(row.selectedFlag == tempSelected)
3428 row.selectedFlag = selected;
3429 else if(row.selectedFlag == tempUnselected)
3430 row.selectedFlag = unselected;
3431 if(row.selectedFlag == selected)
3438 for(row = firstRowShown; row; row = row.GetNextRow(), rowIndex ++)
3441 if(rowY > y || (style.multiSelect && !row.GetNextRow()))
3444 if(style.treeBranch)
3447 for(parent = (style.rootCollapse) ? row.parent : (row.parent ? row.parent.parent : null); parent; parent = parent.parent)
3453 /* THIS WAS TOO STRICT:
3454 if(style.collapse && row.subRows.first && (row.parent || !(style.treeBranch) || (style.rootCollapse)) &&
3455 (x >= rowStart + 3 + plusIndent && y >= rowY - rowHeight + PLUSY && x <= rowStart + 11 + plusIndent && y <= rowY - rowHeight + PLUSY + 8))
3457 if(style.collapse &&
3458 (x >= rowStart && y >= rowY - rowHeight && x <= rowStart + 18 + plusIndent && y <= rowY + rowHeight-1))
3460 if(row.subRows.first && (row.parent || !(style.treeBranch) || (style.rootCollapse)) && x >= plusIndent)
3461 row.collapsed = !row.collapsed;
3468 newCurrentRow = row;
3470 if(style.multiSelect)
3472 // Deselect everything if user didn't clicked on a row
3476 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3477 selRow.selectedFlag = unselected;
3479 //clickedRowIndex = rowIndex;
3481 else if(style.moveRows && !(mods.shift) &&
3482 (row.selectedFlag == selected || row.selectedFlag == tempSelected) &&
3483 !right && !(mods.isActivate))
3484 moveMultiple = true;
3490 if(row.selectedFlag == tempUnselected || row.selectedFlag == unselected)
3492 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3493 selRow.selectedFlag = unselected;
3494 row.selectedFlag = selected;
3497 //clickedRowIndex = rowIndex;
3503 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3504 selRow.selectedFlag = unselected;
3508 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3510 if(selRow != clickedRow)
3512 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3513 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3520 if(rowIndex >= clickedRow.index)
3522 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
3526 if(selRow != clickedRow)
3528 if(selRow.selectedFlag)
3529 selRow.selectedFlag = tempUnselected;
3531 selRow.selectedFlag = tempSelected;
3535 selRow.selectedFlag = selected;
3542 for(selRow = row; selRow; selRow = selRow.GetNextRow())
3546 if(selRow != clickedRow)
3548 if(selRow.selectedFlag)
3549 selRow.selectedFlag = tempUnselected;
3551 selRow.selectedFlag = tempSelected;
3555 selRow.selectedFlag = selected;
3556 if(selRow == clickedRow)
3565 if(row.selectedFlag)
3566 row.selectedFlag = tempUnselected;
3567 else row.selectedFlag = tempSelected;
3570 row.selectedFlag = tempSelected;
3572 //clickedRowIndex = rowIndex;
3582 // true: destroy edit box
3585 incref newCurrentRow;
3588 if(currentRow != newCurrentRow)
3589 HideEditBox(true, true, false);
3593 if(newCurrentRow._refCount <= 1)
3594 delete newCurrentRow;
3596 newCurrentRow._refCount--;
3601 if(!(style.multiSelect))
3603 if(currentRow) currentRow.selectedFlag = unselected;
3604 if(newCurrentRow) newCurrentRow.selectedFlag = selected;
3608 if(currentRow != newCurrentRow)
3611 // true: destroy edit box
3614 //incref newCurrentRow;
3615 incref newCurrentRow;
3618 HideEditBox(true, true, false);
3623 int headerSize = ((style.header) ? rowHeight : 0);
3624 int height = clientSize.h + 1 - headerSize;
3626 /*if(newCurrentRow._refCount <= 1)
3627 delete newCurrentRow;
3630 newCurrentRow._refCount--;
3631 //newCurrentRow._refCount--;
3634 currentRow = newCurrentRow;
3636 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
3637 SetScrollPosition(scroll.x,
3638 currentRow.index * rowHeight - height + rowHeight);
3639 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
3641 int line = currentRow ? currentRow.index * rowHeight : 0;
3642 //SNAPUP(line, rowHeight);
3643 SetScrollPosition(scroll.x, line);
3646 // GO THROUGH SetCurrentRow eventually?
3647 // SetCurrentRow(newCurrentRow, true);
3651 if(style.freeSelect)
3652 NotifyHighlight(master, this, currentRow, mods);
3653 else if((moveMultiple || (!(style.multiSelect) && previousRow == currentRow)) &&
3654 newCurrentRow && !(mods.shift))
3658 if(!(mods.isActivate))
3662 dragRow = currentRow;
3668 if(editData && editData.visible && style.alwaysEdit)
3675 if(style.collapse && !style.treeBranch)
3678 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3680 indent += (style.treeBranch) ? 20 : 15;
3683 for(field = fields.first; field; field = field.next)
3685 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3686 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3688 if(!field.prev) width -= indent;
3689 if(x >= sx && x < sx + width)
3693 if(field == currentField)
3694 editData.Deactivate();
3697 currentRow.Edit(field);
3698 editData.Activate();
3701 else if(!(mods.ctrl) && numSelected <= 1)
3702 editRow = currentRow;
3704 if(style.noDragging && newCurrentRow)
3705 NotifyReclick(master, this, newCurrentRow, mods);
3709 // If the user clicked exactly on the edited field,
3711 if(editData && editData.visible && newCurrentRow)
3717 if(style.collapse && !(style.treeBranch))
3722 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3724 indent += (style.treeBranch) ? 20 : 15;
3728 for(field = fields.first; field; field = field.next)
3730 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3731 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3732 if(!field.prev) width -= indent;
3733 if(x >= sx && x < sx + width && newCurrentRow)
3738 if(field) //x >= sx && x < sx + width && newCurrentRow)
3740 if(field == currentField)
3741 editData.Activate();
3743 newCurrentRow.Edit(currentField);*/
3745 else if(style.noDragging && newCurrentRow)
3746 NotifyReclick(master, this, newCurrentRow, mods);
3748 else if(style.noDragging && newCurrentRow)
3749 NotifyReclick(master, this, newCurrentRow, mods);
3756 if(result && style.alwaysEdit && currentRow)
3760 DataField field = null;
3765 if(style.collapse && !style.treeBranch)
3768 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3770 indent += (style.treeBranch) ? 20 : 15;
3773 for(field = fields.first; field; field = field.next)
3775 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3776 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3778 if(!field.prev) width -= indent;
3779 if(x >= sx && x < sx + width)
3781 f = currentField = field;
3788 // Moved NotifySelect after setting currentField for the NotifySelect implementation to be aware of which field is now selected (e.g. WatchesView)
3789 result = NotifySelect(master, this, currentRow, mods);
3790 if(result && style.alwaysEdit && currentRow)
3792 // In case the user specifically clicked on a field (f is set), override any change to currentField that NotifySelect could have done
3793 currentRow.Edit(f ? f : currentField);
3795 // If the user clicked exactly on the edited field,
3797 if(editData && editData.visible && newCurrentRow)
3801 editData.Activate();
3803 else if(style.noDragging && newCurrentRow)
3804 NotifyReclick(master, this, newCurrentRow, mods);
3807 else if(style.noDragging && newCurrentRow)
3808 NotifyReclick(master, this, newCurrentRow, mods);
3812 For drop box to capture...
3815 if(x < 0 || y < 0 || x >= clientSize.w || y >= clientSize.h)
3818 master.parent.Activate();
3827 if(!style.noDragging)
3832 if(x >= 0 && y >= 0 && x < clientSize.w && y < clientSize.h)
3839 OnLeftButtonUp(x, y, mods);
3844 bool OnLeftButtonDown(int x, int y, Modifiers mods)
3846 return OnButtonDown(x,y, mods, false);
3849 bool OnLeftButtonUp(int x, int y, Modifiers mods)
3851 if(resizingField && style.alwaysEdit)
3853 Window::FreeMouseRange();
3855 resizingField = null;
3858 if(dragRow || editRow)
3860 DataRow row, switchRow = rows.last;
3861 int rowY = (style.header) ? rowHeight : 0;
3862 while(switchRow.lastRow) switchRow = switchRow.lastRow;
3863 for(row = firstRowShown; row; row = row.GetNextRow())
3872 if(editRow == switchRow && y >= 0)
3877 for(field = fields.first; field; field = field.next)
3879 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3880 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3883 if(fieldX > x + scroll.x)
3887 if(field && field.editable)
3889 // true: destroy edit box
3890 HideEditBox(true, true, false);
3891 PopupEditBox(field, false);
3893 else if(!style.noDragging)
3894 NotifyReclick(master, this, currentRow, mods);
3896 else if(style.moveRows && switchRow)
3898 if(dragRow == switchRow && movedRow == false)
3900 DataRow row = dragRow;
3904 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3905 selRow.selectedFlag = unselected;
3909 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3911 if(selRow != clickedRow)
3913 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3914 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3920 if(row.selectedFlag)
3921 row.selectedFlag = tempUnselected;
3922 else row.selectedFlag = tempSelected;
3925 row.selectedFlag = tempSelected;
3930 if(style.multiSelect)
3932 if(!switchRow.selectedFlag)
3934 bool foundSwitch = false;
3937 DataRow afterRow = switchRow.prev;
3938 for(row = rows.first; row; row = next)
3940 next = row.GetNextRow();
3941 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
3943 if(!foundSwitch && !after)
3946 afterRow = switchRow;
3948 if(!after || !(row.selectedFlag == selected || row.selectedFlag == tempSelected) ||
3955 else if(row == switchRow)
3962 for(row = rows.first; row; row = row.GetNextRow())
3964 if(row == switchRow || row == dragRow)
3968 // Switch row first: move before
3969 if(row == switchRow)
3971 DataRow actualMoveRow;
3973 if(!switchRow.prev && switchRow.parent == dragRow.parent)
3974 actualMoveRow = null;
3977 actualMoveRow = switchRow.prev ? switchRow.prev : switchRow;
3978 while(actualMoveRow && actualMoveRow.parent != dragRow.parent && actualMoveRow.parent)
3979 actualMoveRow = actualMoveRow.parent;
3982 if(!actualMoveRow || (actualMoveRow && actualMoveRow.parent == dragRow.parent))
3983 if(NotifyMove(master, this, actualMoveRow, mods))
3985 dragRow.Move(actualMoveRow);
3986 NotifyMoved(master, this, actualMoveRow, mods);
3989 // Dragged row first: move after
3992 DataRow actualMoveRow = switchRow;
3993 DataRow nextRow = switchRow.GetNextRow();
3995 while(nextRow && nextRow.parent != dragRow.parent)
3996 nextRow = nextRow.parent ? nextRow.parent.next : null;
3998 actualMoveRow = nextRow.prev;
4001 actualMoveRow = dragRow.parent ? dragRow.parent.subRows.last : rows.last;
4003 if(!actualMoveRow || (actualMoveRow != dragRow && actualMoveRow.parent == dragRow.parent))
4004 if(NotifyMove(master, this, actualMoveRow, mods))
4006 dragRow.Move(actualMoveRow);
4007 NotifyMoved(master, this, actualMoveRow, mods);
4023 if(dragging || style.freeSelect)
4027 rolledOver = dragging = false;
4029 if(x >= 0 && y >= 0 && x < clientSize.w && y < clientSize.h && currentRow && style.freeSelect)
4033 result = NotifySelect(master, this, currentRow, mods);
4034 if(style.alwaysEdit)
4035 currentRow.Edit(currentField);
4039 // if(!(style.freeSelect))
4045 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
4047 int rowStart = -scroll.x;
4049 int rowY = (style.header) ? rowHeight : 0;
4052 OnLeftButtonUp(x,y,mods);
4053 if(style.alwaysEdit)
4055 if(!(style.collapse) || x > 15)
4056 if(editData && editData.visible)
4058 editData.Activate();
4059 NotifyDoubleClick(master, this, x, y, mods);
4063 for(row = firstRowShown; row; row = row.GetNextRow())
4066 if(rowY > y || (style.multiSelect && !row.GetNextRow()))
4068 if(style.treeBranch)
4071 for(parent = (style.rootCollapse) ? row.parent : (row.parent ? row.parent.parent : null); parent; parent = parent.parent)
4080 if((row && style.collapse && (x >= rowStart && x <= rowStart + 18 + plusIndent)) ||
4081 NotifyDoubleClick(master, this, x, y, mods))
4085 if(row && row.subRows.first)
4087 row.collapsed = !row.collapsed;
4091 // We need to return true here so that OnLeftButtonDown can popup the DataBox Editors
4097 bool OnRightButtonDown(int x, int y, Modifiers mods)
4099 return OnButtonDown(x,y, mods, true);
4102 bool OnRightButtonUp(int x, int y, Modifiers mods)
4104 OnLeftButtonUp(x,y,mods);
4105 return NotifyRightClick(master, this, x, y, mods);
4108 bool GoToLetter(unichar ch, bool keyHit)
4110 bool result = false;
4112 bool checkNextField = true;
4113 int len = keyHit ? 0 : strlen(typedString);
4115 typedString = renew typedString char[len + 2];
4116 typedString[len++] = (char)tolower(ch); // TODO: FIX UNICODE
4117 typedString[len] = '\0';
4119 for(field = fields.first; field; field = field.next)
4121 DataRow startRow = currentRow ? currentRow : rows.first;
4123 if(startRow && field.dataType && field.dataType._vTbl[__ecereVMethodID_class_OnGetString] && ch)
4126 bool looped = false;
4127 if(len == 1 && currentRow)
4128 startRow = (next = startRow.GetNextRow(), (next ? next : rows.first));
4130 for(row = startRow; row != startRow || !looped; next = row.GetNextRow(), row = next ? next : rows.first)
4132 void * data = row.GetData(field);
4133 char tempString[1024] = "";
4134 bool needClass = false;
4135 const char * string = data ? ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass) : null;
4137 if(string && string[0])
4138 checkNextField = false;
4139 if(string && string[0] && !strnicmp(string, typedString, len))
4141 if(style.multiSelect)
4146 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
4147 selRow.selectedFlag = unselected;
4148 row.selectedFlag = selected;
4150 SetCurrentRow(row, true);
4157 if(typingTimeOut && !keyHit)
4158 typingTimer.Start();
4159 if(!result || !typingTimeOut || keyHit)
4160 typedString[len-1] = '\0';
4162 if(!checkNextField || result) break;
4167 bool OnKeyDown(Key key, unichar ch)
4171 if(key == enter || key == keyPadEnter)
4173 if(editData && editData.visible && editData.active)
4175 HideEditBox(true, false, false);
4179 else if(key == escape)
4181 if(resizingField || movingFields || (editData && editData.visible) || dragRow)
4183 if(editData && editData.visible && style.alwaysEdit && !editData.active)
4185 // false: dont destroy edit box
4186 HideEditBox(false, false, false);
4189 resizingField.width = startWidth;
4190 AdaptToFieldWidth(resizingField, true);
4191 resizingField = null;
4204 movingFields = false;
4205 draggingField = null;
4211 if(!currentField || !currentField.editable)
4212 for(field = fields.first; field; field = field.next)
4216 currentField = field;
4220 if((key == f2 || (style.alwaysEdit && (key == ctrlV || key == ctrlC || key == ctrlX || key == shiftInsert || key == ctrlInsert || key == shiftDel))) &&
4221 currentField && currentField.editable)
4223 PopupEditBox(currentField, false);
4224 if(editData && editData.visible)
4226 if(style.alwaysEdit)
4228 editData.Activate();
4229 if(key == ctrlV || key == ctrlC || key == ctrlX || key == shiftInsert || key == ctrlInsert || key == shiftDel)
4231 editData.OnKeyHit(key, ch);
4235 // For Installer to pop up file dialog
4236 NotifyKeyDown(master, this, currentRow, key, ch);
4242 if(!NotifyKeyDown(master, this, currentRow, key, ch))
4245 // Editable fields...
4248 if(style.alwaysEdit && editData && editData.visible)
4249 return editData.OnKeyDown(key, ch);
4250 return true; // We want to pick up the OnKeyHit to replace contents, but skip GoToLetter
4253 if(ch >=32 && ch != 128 && !key.alt && !key.ctrl && GoToLetter(ch, false))
4255 /*if(inactive && window.state != Hidden)
4256 NotifyHighlight(master, this, currentRow, 0);
4259 NotifySelect(master, this, currentRow, 0);
4266 bool OnKeyHit(Key key, unichar ch)
4268 if(!ch && !key.alt && !key.ctrl)
4270 key.code = (SmartKey)key.code;
4272 if(ch >= 32 && !key.alt && !key.ctrl && ch != 128)
4275 if(!currentField || !currentField.editable)
4276 for(field = fields.first; field; field = field.next)
4280 currentField = field;
4284 if(currentField && currentField.editable)
4286 if((!editData || !editData.visible) || !editData.active)
4288 PopupEditBox(currentField, false);
4289 if(editData && editData.visible)
4291 editData.Activate();
4292 editData.OnKeyHit(key, ch);
4299 if(editData && editData.visible && ch && !key.alt && !key.ctrl && editData.active && (key.code != tab || (editData._class == class(EditBox) && ((EditBox)editData).tabKey)))
4302 if(!key.alt && (style.multiSelect || !key.ctrl))
4307 if(style.alwaysEdit)
4312 for(field = currentField.prev; field; field = field.prev)
4316 currentField = field;
4317 HideEditBox(true, true, false);
4318 PopupEditBox(currentField, false);
4324 if(style.collapse && currentRow /*&& !currentField*/) // THIS PREVENTED COLLAPSING THE PROPERTY SHEET
4326 if(currentRow.subRows.first && !currentRow.collapsed)
4328 currentRow.collapsed = true;
4330 else if(currentRow.parent)
4331 SetCurrentRow(currentRow.parent, true);
4336 if(style.collapse && currentRow && currentRow.subRows.first)
4338 if(currentRow.collapsed)
4339 currentRow.collapsed = false;
4341 SetCurrentRow(currentRow.subRows.first, true);
4344 else if(style.alwaysEdit)
4349 for(field = currentField.next; field; field = field.next)
4353 currentField = field;
4354 HideEditBox(true, true, false);
4355 PopupEditBox(currentField, false);
4363 case pageDown: case pageUp:
4364 case end: case home:
4366 int headerSize = ((style.header) ? rowHeight : 0);
4367 int height = clientSize.h + 1 - headerSize;
4370 // true: destroy edit box
4371 // !!! TESTING true HERE !!!
4372 HideEditBox(true, true, false);
4373 // HideEditBox(false, true, false);
4375 oldRow = currentRow;
4377 SNAPDOWN(height, rowHeight);
4378 if((!currentRow || key.code == home) && key.code != end)
4380 currentRow = rows.first;
4388 if(!(style.multiSelect) && currentRow && !currentRow.selectedFlag)
4391 next = currentRow.GetNextRow();
4398 if(!(style.multiSelect) && currentRow && !currentRow.selectedFlag)
4401 next = currentRow.GetPrevRow();
4409 currentRow = lastRow.GetLastRow();
4415 currentRow && (next = currentRow.GetPrevRow()) && c < height / rowHeight;
4416 c++, currentRow = next);
4423 currentRow && (next = currentRow.GetNextRow()) && c < height / rowHeight;
4424 c++, currentRow = next);
4429 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
4430 SetScrollPosition(scroll.x, currentRow.index * rowHeight - height + rowHeight);
4431 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
4432 SetScrollPosition(scroll.x, currentRow ? currentRow.index * rowHeight : 0);
4434 if(style.multiSelect)
4438 if(!(key.shift) && (key.ctrl))
4441 for(row = rows.first; row; row = row.GetNextRow())
4443 if(row.selectedFlag == tempSelected)
4444 row.selectedFlag = selected;
4445 else if(row.selectedFlag == tempUnselected)
4446 row.selectedFlag = unselected;
4452 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
4453 selRow.selectedFlag = unselected;
4457 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
4459 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
4460 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
4466 if(currentRow.index >= clickedRow.index)
4468 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
4472 if(selRow.selectedFlag) selRow.selectedFlag = tempUnselected; else selRow.selectedFlag = tempSelected;
4475 selRow.selectedFlag = selected;
4476 if(selRow == currentRow)
4482 for(selRow = currentRow; selRow; selRow = selRow.GetNextRow())
4486 if(selRow.selectedFlag) selRow.selectedFlag = tempUnselected; else selRow.selectedFlag = tempSelected;
4489 selRow.selectedFlag = selected;
4490 if(selRow == clickedRow)
4497 if(!(key.ctrl) && currentRow)
4499 currentRow.selectedFlag = selected;
4502 clickedRow = currentRow;
4507 if(oldRow) oldRow.selectedFlag = unselected;
4508 if(currentRow) currentRow.selectedFlag = selected;
4513 if(style.freeSelect)
4514 NotifyHighlight(master, this, currentRow, 0);
4516 NotifySelect(master, this, currentRow, 0);
4518 if(style.alwaysEdit && currentRow)
4519 currentRow.Edit(currentField /*null*/);
4526 if(style.multiSelect && currentRow)
4528 if(currentRow.selectedFlag)
4531 currentRow.selectedFlag = unselected;
4534 currentRow.selectedFlag = selected;
4537 if(style.freeSelect)
4538 NotifyHighlight(master, this, currentRow, 0);
4540 NotifySelect(master, this, currentRow, 0);
4547 if(!NotifyKeyHit(master, this, currentRow, key, ch))
4550 if(ch >=32 && ch != 128 && !key.alt && !key.ctrl && GoToLetter(ch, true))
4552 /*if(inactive && window.state != Hidden)
4553 return NotifyHighlight(master, this, currentRow, 0);
4556 return NotifySelect(master, this, currentRow, 0);
4563 void OnHScroll(ScrollBarAction action, int position, Key key)
4568 void OnVScroll(ScrollBarAction action, int position, Key key)
4573 for(firstRowShown = rows.first; firstRowShown; firstRowShown = next)
4575 next = firstRowShown.GetNextRow();
4576 if(y >= position || !next) break;
4586 DataRow firstRowShown;
4590 DataField sortField;
4594 public double typingTimeOut;
4607 if(guiApp.GetKeyState(shift)) mods.shift = true;
4608 if(guiApp.GetKeyState(alt)) mods.alt = true;
4609 if(guiApp.GetKeyState(control)) mods.ctrl = true;
4610 OnMouseMove(MAXINT, MAXINT, mods);
4618 delay = 0.5; // typingTimeOut
4623 typedString[0] = '\0';
4625 // The next line was commented... Why? When commented typing words stops working ( only first character jumps )
4631 bool dragging, rolledOver;
4640 // For editing fields
4642 DataField currentField;
4645 // For moving fields
4646 DataField draggingField, dropField;
4649 // For resizing fields
4650 DataField resizingField;
4651 int resizeX, oldX, startWidth;
4654 FontResource boldFont;
4657 // Only used for OnMouseMove so far, for avoiding problems with consequential mouse moves
4658 bool insideNotifySelect;
4659 ColorAlpha selectionColor, selectionText, stippleColor;
4660 stippleColor = 0xFFFFFF80;