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;
305 index = this.index+1;
306 for(search = GetNextRow(); search; search = search.GetNextRow())
307 search.index = index++;
308 listBox.rowCount = index;
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 // Free old data first
666 ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, cell.data);
670 listBox.Update(null);
675 DataRow FindRow(int64 tag)
678 for(row = subRows.first; row; row = row.next)
680 if(!row.noneRow && row.tag == tag)
686 DataRow FindSubRow(int64 tag)
689 for(row = subRows.first; row; row = row.next)
691 if(!row.noneRow && row.tag == tag)
693 if(row.subRows.first)
695 DataRow subRow = row.FindSubRow(tag);
703 DataRow AddRowAfter(DataRow after)
713 subRows.Insert(after, row);
714 row.listBox = listBox;
718 for(c = 0; c<listBox.fields.count; c++)
720 for(field = listBox.fields.first; field; field = field.next)
721 if((int)field.index == c)
725 int size = (field.dataType && field.dataType.typeSize) ?
726 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
727 ListBoxCell cell = (ListBoxCell)new0 byte[size];
729 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
738 if(after && after.subRows.first && !after.collapsed)
740 for(search = after.subRows.last; !search.collapsed && search.subRows.last; )
741 search = search.subRows.last;
742 row.index = search.index + 1;
745 row.index = after ? (after.index + 1) : (index + 1);
749 for(search = row.GetNextRow(); search; search = search.GetNextRow())
752 listBox.SetScrollArea(
754 (listBox.rowCount * listBox.rowHeight) +
755 ((listBox.style.header) ? listBox.rowHeight : 0) -
756 ((!((listBox.clientSize.h+1) % listBox.rowHeight)) ? listBox.rowHeight : 0), true);
757 if(listBox.style.autoScroll)
758 listBox.SetScrollPosition(0, MAXINT - listBox.rowHeight);
761 listBox.modifiedDocument = true;
764 listBox.CheckConsistency();
774 return AddRowAfter(subRows.last);
778 DataRow AddStringf(const char * format, ...)
783 char string[MAX_F_STRING];
785 va_start(args, format);
786 vsnprintf(string, sizeof(string), format, args);
787 string[sizeof(string)-1] = 0;
791 row.SetData(null, string);
797 DataRow AddString(const char * string)
803 row.SetData(listBox.fields.first, string);
813 subRows.offset = (uint)(uintptr)&((DataRow)0).prev;
818 ListBoxCell cell, next;
823 while((subRow = subRows.first))
825 subRows.Remove(subRow);
829 for(cell = cells.first; cell; cell = next, cellIndex++)
834 for(field = listBox.fields.first; field && field.index != cellIndex; field = field.next);
835 if(field && field.dataType)
837 // TOCHECK: Is this check good? Will need incref/decref sometime?
838 if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
840 if(cell.data[0] && field.freeData)
841 ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data[0]);
844 ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data);
854 return !this || (!collapsed && (!parent || parent.IsExpanded()));
857 int Compare(DataRow b, DataField sortField)
860 ListBoxCell cell1, cell2;
862 for(index = 0, cell1 = cells.first, cell2 = b.cells.first;
863 index != sortField.index;
864 index++, cell1 = cell1.next, cell2 = cell2.next);
866 if(!cell1.isSet && !cell2.isSet)
868 else if(!cell1.isSet)
870 else if(!cell2.isSet)
873 if(noneRow && !b.noneRow) return -1;
874 else if(!noneRow && b.noneRow) return 1;
875 else if(noneRow && b.noneRow) return 0;
877 if(sortField.dataType._vTbl[__ecereVMethodID_class_OnCompare])
879 if(sortField.dataType.type == normalClass || sortField.dataType.type == noHeadClass)
881 result = ((int (*)(void *, void *, void *))(void *)sortField.dataType._vTbl[__ecereVMethodID_class_OnCompare])(sortField.dataType,
882 (cell1.isSet && cell1.data) ? cell1.data[0] : null,
883 (cell2.isSet && cell2.data) ? cell2.data[0] : null);
887 result = ((int (*)(void *, void *, void *))(void *)sortField.dataType._vTbl[__ecereVMethodID_class_OnCompare])(sortField.dataType,
888 cell1.isSet ? cell1.data : null,
889 cell2.isSet ? cell2.data : null);
892 return sortField.sortOrder * result;
895 void _SortSubRows(DataField field, int order)
898 for(search = subRows.first; search; search = search.next)
899 search._SortSubRows(field, order);
900 subRows.Sort(Compare, field);
903 public void SortSubRows(bool scrollToCurrent)
905 if(this && listBox && listBox.sortField)
907 _SortSubRows(listBox.sortField, listBox.sortField.sortOrder);
911 int index = this.index;
912 for(search = this; search; search = search.GetNextRow())
913 search.index = index++;
917 int headerSize = ((listBox.style.header) ? listBox.rowHeight : 0);
918 int height = listBox.clientSize.h + 1 - headerSize;
919 if(listBox.currentRow && listBox.currentRow.index * listBox.rowHeight > listBox.scroll.y + height - listBox.rowHeight)
920 listBox.SetScrollPosition(listBox.scroll.x, listBox.currentRow.index * listBox.rowHeight - height + listBox.rowHeight);
921 else if(!listBox.currentRow || listBox.currentRow.index * listBox.rowHeight < listBox.scroll.y)
922 listBox.SetScrollPosition(listBox.scroll.x, listBox.currentRow ? listBox.currentRow.index * listBox.rowHeight : 0);
923 listBox.OnVScroll(0, listBox.scroll.y, 0);
928 public DataRow GetPrevRow()
934 for(row = prev; row && !row.collapsed && row.subRows.last; row = row.subRows.last);
941 public DataRow GetNextRow()
945 if(subRows.first && !collapsed)
949 for(row = this; row; row = row.parent)
951 if(row.next) { row = row.next; break; }
957 private DataRow GetLastRow()
960 while(row && !row.collapsed && row.subRows.last)
961 row = row.subRows.last;
968 SelectedFlag selectedFlag;
979 public class ListBox : CommonControl
981 hasVertScroll = true;
982 // background = white;
984 snapVertScroll = true;
986 class_property(icon) = "<:ecere>controls/listBox.png";
990 property bool freeSelect { property_category $"Behavior" set { style.freeSelect = value; } get { return style.freeSelect; } };
991 property DataRow currentRow { property_category $"Private" /*"Behavior"*/ set { if(this) SetCurrentRow(value, false); } get { return this ? currentRow : null; } };
992 property DataField currentField
994 get { return currentField; }
995 // TODO: Document what this does
998 currentField = value;
999 HideEditBox(true, true, false);
1000 if(value && value.editable)
1001 PopupEditBox(currentField, false);
1005 property int rowHeight
1007 property_category $"Appearance"
1008 isset { return style.heightSet; }
1013 style.heightSet = true;
1015 SetScrollLineStep(8, value);
1019 style.heightSet = false;
1024 get { return this ? rowHeight : 0; }
1026 property Seconds typingTimeout
1028 property_category $"Behavior"
1031 typedString[0] = '\0';
1032 typingTimer.delay = value;
1033 typingTimeOut = value;
1035 get { return typingTimeOut; }
1037 property bool moveRows { property_category $"Behavior" set { style.moveRows = value; } get { return style.moveRows; } };
1038 property bool moveFields { property_category $"Behavior" set { style.moveFields = value; } get { return style.moveFields; } };
1039 property bool resizable { property_category $"Behavior" set { style.resizable = value; } get { return style.resizable; } };
1040 property bool autoScroll { property_category $"Behavior" set { style.autoScroll = value; } get { return style.autoScroll; } };
1041 property bool alwaysHighLight { property_category $"Appearance" set { style.alwaysHL = value; } get { return style.alwaysHL; } };
1042 property bool hasClearHeader { property_category $"Appearance" set { style.clearHeader = value; if(value) property::hasHeader = true; } get { return style.clearHeader; } };
1043 property bool hasHeader
1045 property_category $"Appearance"
1048 if(value && !style.header)
1054 bevel = !guiApp.textMode && !style.clearHeader;
1055 dontScrollVert = true;
1058 NotifyPushed = HeaderPushed;
1059 NotifyClicked = HeaderClicked;
1060 NotifyDoubleClick = HeaderDoubleClicked;
1061 NotifyReleased = HeaderReleased;
1062 NotifyMouseMove = HeaderMouseMove;
1066 endBevel.visible = false;
1068 style.header = value;
1070 get { return style.header; }
1072 property bool multiSelect { property_category $"Behavior" set { style.multiSelect = value; } get { return style.multiSelect; } };
1073 property bool alwaysEdit { property_category $"Behavior" set { style.alwaysEdit = value; } get { return style.alwaysEdit; } };
1074 property bool fullRowSelect { property_category $"Appearance" set { style.fullRowSelect = value; } get { return style.fullRowSelect; } };
1075 property bool collapseControl { property_category $"Appearance" set { style.collapse = value; } get { return style.collapse; } };
1076 property bool treeBranches { property_category $"Appearance" set { style.treeBranch = value; } get { return style.treeBranch; } };
1077 property bool rootCollapseButton { property_category $"Appearance" set { style.rootCollapse = value; } get { return style.rootCollapse; } };
1078 property bool sortable { property_category $"Behavior" set { style.sortable = value; } get { return style.sortable; } };
1079 property bool noDragging { property_category $"Behavior" set { style.noDragging = value; } get { return style.noDragging; } };
1080 property bool fillLastField
1082 property_category $"Behavior"
1085 style.fillLastField = value;
1087 get { return style.fillLastField; }
1089 property int numSelections
1093 int numSelections = 0;
1094 if(this && style.multiSelect)
1097 for(row = rows.first; row; row = row.GetNextRow())
1098 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
1101 return numSelections;
1104 property int currentIndex
1106 get { return currentRow ? currentRow.index : -1; }
1108 property DataRow lastRow { get { return this ? rows.last : null; } };
1109 property DataRow firstRow { get { return this ? rows.first : null; } };
1110 property int rowCount { get { return rowCount; } };
1111 property DataField firstField { get { return this ? fields.first : null; } };
1112 property Color selectionColor { set { selectionColor = value; } get { return selectionColor; } isset { return selectionColor ? true : false; } };
1113 property Color selectionText { set { selectionText = value; } get { return selectionText; } isset { return selectionText ? true : false; } };
1114 property Color stippleColor { set { stippleColor = value; } get { return stippleColor; } };
1115 property bool expandOnAdd { set { style.expandOnAdd = value; } get { return style.expandOnAdd; } };
1118 virtual bool Window::NotifySelect(ListBox listBox, DataRow row, Modifiers mods);
1119 virtual bool Window::NotifyHighlight(ListBox listBox, DataRow row, Modifiers mods);
1120 virtual bool Window::NotifyReclick(ListBox listBox, DataRow row, Modifiers mods);
1121 virtual bool Window::NotifySort(ListBox listBox, DataField field, Modifiers mods);
1122 virtual bool Window::NotifyChanged(ListBox listBox, DataRow row);
1123 virtual bool Window::NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch);
1124 virtual bool Window::NotifyEdited(ListBox listBox, DataRow row);
1125 virtual bool Window::NotifyEditDone(ListBox listBox, DataRow row);
1126 virtual bool Window::NotifyMovedField(ListBox listBox, DataField field, Modifiers mods);
1127 virtual bool Window::NotifyMove(ListBox listBox, DataRow row, Modifiers mods);
1128 virtual bool Window::NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods);
1129 virtual bool Window::NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods);
1130 virtual bool Window::NotifyResized(ListBox listBox, DataField field, Modifiers mods);
1131 virtual bool Window::NotifyCollapse(ListBox listBox, DataRow row, bool collapsed);
1132 virtual bool Window::NotifyKeyHit(ListBox listBox, DataRow row, Key key, unichar ch);
1133 virtual bool Window::NotifyModified(ListBox listBox, DataRow row);
1134 virtual bool Window::NotifyEditing(ListBox listBox, DataRow row);
1135 virtual void Window::NotifyMoved(ListBox listBox, DataRow row, Modifiers mods);
1138 private void CheckConsistency()
1143 for(r = rows.first; r; r = r.GetNextRow())
1145 if(r.index != index++)
1153 void AddField(DataField addedField)
1158 if(fields.first && ((DataField)fields.first).defaultField)
1160 DataField defaultField = fields.first;
1161 defaultField.Free();
1162 delete defaultField;
1166 addedField = DataField { };
1170 addedField.listBox = this;
1171 fields.Add(addedField);
1173 addedField.sortOrder = 1;
1174 addedField.index = numFields;
1178 addedField.headButton.Destroy(0);
1179 delete addedField.headButton;
1180 addedField.headButton = Button
1185 dontScrollVert = true;
1186 id = (int64)(intptr)addedField;
1187 text = addedField.header;
1188 bevel = (!guiApp.textMode && !style.clearHeader);
1190 alignment = addedField.alignment;
1191 NotifyPushed = HeaderPushed;
1192 NotifyClicked = HeaderClicked;
1193 NotifyDoubleClick = HeaderDoubleClicked;
1194 NotifyReleased = HeaderReleased;
1195 NotifyMouseMove = HeaderMouseMove;
1197 incref addedField.headButton;
1198 addedField.headButton.Create();
1201 addedField.headButton.background = Color { 0, 170, 0 };
1207 for(row = rows.first; row; )
1209 int size = (field.dataType && field.dataType.typeSize) ?
1210 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1211 ListBoxCell cell = (ListBoxCell)new0 byte[size];
1212 row.cells.Add(cell);
1213 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
1216 if(row.subRows.first)
1217 row = row.subRows.first;
1220 for(; row; row = row.parent)
1222 if(row.next) { row = row.next; break; }
1227 OnResize(clientSize.w, clientSize.h);
1236 Clear(); // Ensure data is cleared first
1237 while((field = fields.first))
1242 endBevel.visible = false;
1247 void RemoveField(DataField field)
1253 int index = field.index;
1256 if(sortField == field)
1259 for(row = rows.first; row; )
1264 for(cell = row.cells.first, c = 0; c < index && cell; c++, cell = cell.next);
1265 if(cell && index == c)
1269 // TOCHECK: Is this check good? Will need incref/decref sometime?
1270 if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
1272 if(cell.data[0] && field.freeData)
1273 ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data[0]);
1276 ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data);
1279 row.cells.Remove(cell);
1283 if(row.subRows.first)
1284 row = row.subRows.first;
1287 for(; row; row = row.parent)
1289 if(row.next) { row = row.next; break; }
1298 endBevel.visible = false;
1302 DataRow AddRowNone()
1304 DataRow row { noneRow = true };
1311 rows.Insert(null, row);
1314 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1320 firstRowShown = row;
1324 (rowCount * rowHeight) +
1325 ((style.header) ? rowHeight : 0) -
1326 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1327 if(style.autoScroll)
1328 SetScrollPosition(0, MAXINT - rowHeight);
1329 modifiedDocument = true;
1348 // Find very last row
1351 for(lastRow = rows.last; lastRow && !lastRow.collapsed && lastRow.subRows.last; lastRow = lastRow.subRows.last);
1352 row.index = lastRow ? (lastRow.index + 1) : 0;
1360 for(c = 0; c<fields.count; c++)
1362 for(field = fields.first; field; field = field.next)
1363 if((int)field.index == c)
1367 int size = (field.dataType && field.dataType.typeSize) ?
1368 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1369 ListBoxCell cell = (ListBoxCell) new0 byte[size];
1370 row.cells.Add(cell);
1371 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
1378 firstRowShown = row;
1384 (rowCount * rowHeight) +
1385 ((style.header) ? rowHeight : 0) -
1386 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1387 if(style.autoScroll)
1388 SetScrollPosition(0, MAXINT - rowHeight);
1389 modifiedDocument = true;
1400 DataRow AddRowAfter(DataRow after)
1412 if(after && after.subRows.first && !after.collapsed)
1414 for(search = after.subRows.last; !search.collapsed && search.subRows.last; )
1415 search = search.subRows.last;
1416 row.index = search.index + 1;
1419 row.index = after ? (after.index + 1) : 0;
1420 rows.Insert(after, row);
1423 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1428 for(c = 0; c<fields.count; c++)
1430 for(field = fields.first; field; field = field.next)
1431 if((int)field.index == c)
1435 int size = (field.dataType && field.dataType.typeSize) ?
1436 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1437 ListBoxCell cell = (ListBoxCell) new0 byte[size];
1438 row.cells.Add(cell);
1439 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
1443 if(!firstRowShown || !after)
1445 firstRowShown = row;
1450 (rowCount * rowHeight) +
1451 ((style.header) ? rowHeight : 0) -
1452 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1453 if(style.autoScroll)
1454 SetScrollPosition(0, MAXINT - rowHeight);
1455 modifiedDocument = true;
1465 DataRow AddStringf(const char * format, ...)
1471 char string[MAX_F_STRING];
1474 va_start(args, format);
1475 vsnprintf(string, sizeof(string), format ? format : "", args);
1476 string[sizeof(string)-1] = 0;
1480 row.SetData(fields.first, string);
1486 DataRow AddString(const char * string)
1492 row.SetData(fields.first, string);
1498 void SelectRow(DataRow row)
1500 SetCurrentRow(row, true);
1503 void DeleteRow(DataRow row)
1505 if(!row) row = currentRow;
1508 DataRow sub, next, search;
1509 // Trying to move this here (Messed up deleting watches)
1510 //HideEditBox(false, false, true);
1513 for(sub = row.subRows.first; sub; sub = next)
1519 if(row.parent.IsExpanded())
1521 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1526 HideEditBox(false, false, true);
1528 if(row == clickedRow)
1530 clickedRow = row.GetNextRow();
1532 clickedRow = row.GetPrevRow();
1535 if(row == currentRow)
1537 DataRow newCurrentRow = row.GetNextRow();
1539 newCurrentRow = row.GetPrevRow();
1540 SetCurrentRow(newCurrentRow, true);
1543 if(row == firstRowShown)
1545 firstRowShown = row.GetPrevRow();
1547 firstRowShown = row.GetNextRow();
1550 (row.parent ? row.parent.subRows: rows).Remove(row);
1553 //HideEditBox(false, false, true);
1557 (this.rowCount * rowHeight) +
1558 ((style.header) ? rowHeight : 0) -
1559 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1561 modifiedDocument = true;
1570 DataRow FindRow(int64 tag)
1575 for(row = rows.first; row; row = row.next)
1577 if(!row.noneRow && row.tag == tag)
1585 DataRow FindString(const char * searchedString)
1588 bool checkNextField = true;
1590 for(field = fields.first; field; field = field.next)
1592 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1595 for(row = rows.first; row; row = row.GetNextRow())
1599 void * data = row.GetData(field);
1600 char tempString[1024] = "";
1601 bool needClass = false;
1602 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1604 if(string && string[0])
1605 checkNextField = false;
1606 if(string && string[0] && !strcmp(string, searchedString))
1611 if(!checkNextField) break;
1616 DataRow FindSubString(const char * subString)
1619 bool checkNextField = true;
1620 int len = subString ? strlen(subString) : 0;
1624 for(field = fields.first; field; field = field.next)
1626 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1629 for(row = rows.first; row; row = row.GetNextRow())
1633 void * data = row.GetData(field);
1634 char tempString[1024] = "";
1635 bool needClass = false;
1636 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1638 if(string && string[0])
1639 checkNextField = false;
1640 if(string && string[0] && !strncmp(string, subString, len))
1645 if(!checkNextField) break;
1651 DataRow FindSubStringi(const char * subString)
1654 bool checkNextField = true;
1655 int len = subString ? strlen(subString) : 0;
1656 DataRow result = null;
1657 const char * bestResult = null;
1662 for(field = fields.first; field; field = field.next)
1664 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1667 for(row = rows.first; row; row = row.GetNextRow())
1671 void * data = row.GetData(field);
1672 char tempString[1024] = "";
1673 bool needClass = false;
1674 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1676 if(string && string[0])
1677 checkNextField = false;
1678 if(string && string[0])
1680 int stringLen = strlen(string);
1682 if(!strnicmp(string, subString, Min(len, stringLen)))
1684 if(bestLen < Min(len, stringLen))
1686 if(!bestResult || strcmpi(string, bestResult) < 0)
1688 bestLen = Min(len, stringLen);
1689 bestResult = string;
1697 if(!checkNextField) break;
1703 DataRow FindSubStringAfter(DataRow after, const char * subString)
1706 bool checkNextField = true;
1707 int len = subString ? strlen(subString) : 0;
1711 for(field = fields.first; field; field = field.next)
1713 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1716 for(row = after.GetNextRow(); row && row != after; row = row.GetNextRow(), (!row) ? (row = rows.first) : null)
1720 void * data = row.GetData(field);
1721 char tempString[1024] = "";
1722 bool needClass = false;
1723 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1725 if(string && string[0])
1726 checkNextField = false;
1727 if(string && string[0] && !strncmp(string, subString, len))
1732 if(!checkNextField) break;
1738 DataRow FindSubRow(int64 tag)
1744 for(row = rows.first; row; row = row.next)
1746 if(!row.noneRow && row.tag == tag)
1748 if(!row.noneRow && row.subRows.first)
1750 DataRow subRow = row.FindSubRow(tag);
1764 Window master = this.master;
1766 HideEditBox(false, true, false);
1767 editData.Destroy(0);
1769 firstRowShown = currentRow = null;
1774 if(style.freeSelect)
1775 NotifyHighlight(master, this, currentRow ? currentRow : null, 0);
1777 NotifySelect(master, this, currentRow ? currentRow : null, 0);
1780 if(style.alwaysEdit && currentRow)
1781 currentRow.Edit(currentField);
1788 (this.rowCount * rowHeight) +
1789 ((style.header) ? rowHeight : 0) -
1790 ((rowHeight && !((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1795 void Sort(DataField field, int order)
1800 int headerSize = ((style.header) ? rowHeight : 0);
1801 int height = clientSize.h + 1 - headerSize;
1803 if(!field) field = fields.first;
1805 field.sortOrder = order ? order : 1;
1806 rows.Sort(DataRow::Compare, field);
1808 for(search = rows.first; search; search = search.next)
1809 search._SortSubRows(field, order);
1813 for(search = rows.first; search; search = search.GetNextRow())
1814 search.index = index++;
1817 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
1818 SetScrollPosition(scroll.x, currentRow.index * rowHeight - height + rowHeight);
1819 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
1820 SetScrollPosition(scroll.x, currentRow ? currentRow.index * rowHeight : 0);
1822 OnVScroll(0, scroll.y, 0);
1824 // SetScrollPosition(0, scroll.y);
1829 void StopEditing(bool save)
1831 HideEditBox(save, false, true);
1834 void GetMultiSelection(OldList list)
1837 if(this && style.multiSelect)
1841 for(row = rows.first; row; row = row.GetNextRow())
1843 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
1845 list.Add(OldLink { data = row });
1851 // Convenience Current Row Methods
1852 void * SetData(DataField field, any_object data)
1854 return currentRow.SetData(field, data);
1857 any_object GetData(DataField field)
1859 return (void *)currentRow.GetData(field);
1864 return currentRow ? currentRow.tag : 0;
1870 DataField defaultField { };
1871 rows.offset = (uint)(uintptr)&((DataRow)0).prev;
1872 fields.offset = (uint)(uintptr)&((DataField)0).prev;
1873 style.fullRowSelect = true;
1874 style.fillLastField = true;
1875 style.expandOnAdd = true;
1876 typingTimeOut = 0.5;
1877 rowHeight = 16; // Stuff depending on creation and default property checking
1880 defaultField.defaultField = true;
1882 AddField(defaultField);
1884 typedString = new char[1];
1885 typedString[0] = '\0';
1900 while((field = fields.first))
1902 // fields.Remove(field);
1912 while((row = rows.first))
1919 ListBoxCell GetCell(DataRow * row, DataField * field)
1921 ListBoxCell cell = null;
1922 if(!*row) *row = currentRow;
1925 if(!*field) *field = this ? currentField : null;
1928 for(*field = fields.first; (*field).index != 0; *field = (*field).next);
1933 if(field->listBox == this)
1935 for(index = 0, cell = (*row).cells.first; cell && index != (*field).index; index++, cell = cell.next);
1942 void HideEditBox(bool save, bool alwaysStopEdit, bool repositionOnly)
1944 if(editData && editData.visible)
1947 editData.SaveData();
1949 editData.visible = false;
1950 NotifyEditDone(master, this, currentRow);
1952 // ENSURE DATA BOX IS NOT VISIBLE
1953 editData.visible = false;
1955 if(style.alwaysEdit && !alwaysStopEdit)
1958 int height = rowHeight - (style.alwaysEdit ? 1 : 0);
1959 int y = currentRow.index * rowHeight + (style.header ? rowHeight : 0);
1960 int x = currentField.x;
1961 int width = (!currentField.next && style.fillLastField && (!hasHorzScroll || clientSize.w - currentField.x > currentField.width + EXTRA_SPACE)) ?
1962 clientSize.w - currentField.x : (currentField.width + EXTRA_SPACE);
1964 if(!style.alwaysEdit)
1966 editData.position = { x, y };
1967 editData.size = { width, height };
1971 editData.position = { x, y - editData.clientStart.y };
1972 editData.size = { width, height + editData.clientStart.y * 2 };
1974 editData.visible = true;
1975 if(style.alwaysEdit)
1976 editData.Deactivate();
1978 PopupEditBox(currentField, repositionOnly);
1982 currentField = null;*/
1986 void SetCurrentRow(DataRow row, bool notify)
1988 if(this && (currentRow != row || (currentRow && currentRow.selectedFlag == unselected)))
1990 int headerSize = ((style.header) ? rowHeight : 0);
1991 int height = clientSize.h + 1 - headerSize;
1993 // true: destroy edit box
1994 HideEditBox(true, true, false);
1996 if(!(style.multiSelect) && currentRow)
1997 currentRow.selectedFlag = unselected;
2001 if(style.multiSelect)
2005 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
2006 selRow.selectedFlag = unselected;
2008 currentRow.selectedFlag = selected;
2013 currentRow.selectedFlag = selected;
2015 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
2016 SetScrollPosition(scroll.x,
2017 currentRow.index * rowHeight - height + rowHeight);
2018 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
2020 int line = currentRow ? currentRow.index * rowHeight : 0;
2021 //SNAPUP(line, rowHeight);
2022 SetScrollPosition(scroll.x, line);
2027 Window master = this.master;
2030 if(style.freeSelect && visible)
2031 NotifyHighlight(master, this, currentRow ? currentRow : null, 0);
2033 NotifySelect(master, this, currentRow ? currentRow : null, 0);
2034 if(style.alwaysEdit && currentRow)
2035 currentRow.Edit(currentField);
2043 void RepositionFieldEditor()
2045 if(editData && editData.visible)
2047 int height = rowHeight - (style.alwaysEdit ? 1 : 0);
2049 int y = currentRow.index * rowHeight + (style.header ? rowHeight : 0);
2053 if(style.collapse && !(style.treeBranch))
2055 for(field = fields.first; field; field = field.next)
2057 width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2058 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2059 if(field == currentField) break;
2062 if(!style.alwaysEdit)
2064 editData.position = { x, y - editData.clientStart.y };
2065 editData.size = { width, height + editData.clientStart.y * 2 };
2069 editData.position = { x, y };
2070 editData.size = { width, height };
2075 void PopupEditBox(DataField whichField, bool repositionOnly)
2077 if((!editData || !editData.visible || currentField != whichField) && currentRow)
2079 // true: destroy edit box
2080 HideEditBox(true, true, false);
2083 int height = rowHeight - (style.alwaysEdit ? 1 : 0);
2085 int y = currentRow.index * rowHeight + (style.header ? rowHeight : 0);
2087 //void * data = currentRow.GetData(whichField);
2092 if(style.collapse && !(style.treeBranch))
2095 for(field = fields.first; field; field = field.next)
2097 width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2098 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2099 if(field == whichField) break;
2103 currentField = whichField;
2104 cell = GetCell(&row, ¤tField);
2111 background = dataBoxBackground;
2112 foreground = dataBoxForeground;
2114 bool NotifyChanged(DataBox dataBox, bool closingDropDown)
2117 DataField field = null;
2118 ListBoxCell cell = GetCell(&row, &field);
2122 modifiedDocument = true;
2124 NotifyChanged(master, this, currentRow);
2129 bool NotifyModified()
2131 //DataRow row = null;
2132 //DataField field = null;
2133 //ListBoxCell cell = GetCell(&row, &field);
2134 //cell.isSet = true;
2135 modifiedDocument = true;
2137 NotifyModified(master, this, currentRow);
2141 bool OnKeyDown(Key key, unichar ch)
2143 bool result = DataBox::OnKeyDown(key, ch);
2144 if(visible && active) // Added this check here, because we will not use enter/escape otherwise, and lose DataBox's result
2146 if((SmartKey)key == enter || (SmartKey)key == escape)
2155 editData.Destroy(0);
2156 editData.type = whichField.dataType;
2157 editData.fieldData = whichField.userData;
2158 editData.borderStyle = style.alwaysEdit ? 0 : deep;
2159 editData.data = cell ? cell.data : null;
2162 // Might not really need this anymore...
2163 NotifyEditing(master, this, currentRow);
2166 if(!style.alwaysEdit)
2168 editData.position = { x, y - editData.clientStart.y };
2169 editData.size = { width, height + editData.clientStart.y * 2 };
2173 editData.position = { x, y };
2174 editData.size = { width, height };
2178 editData.visible = true;
2180 if(style.alwaysEdit)
2181 editData.Deactivate();
2183 // MOVED THIS HIGHER FOR DATALIST EDITOR
2185 // Might not really need this anymore...
2186 NotifyEdited(master, this, currentRow);
2191 void OnRedraw(Surface surface)
2194 int y = (style.header) ? rowHeight : 0;
2195 bool isActive = active;
2196 Font font = fontObject;
2197 Font boldFont = this.boldFont.font;
2201 if(style.alwaysEdit && style.fullRowSelect)
2204 int y = (style.header) ? rowHeight : 0;
2205 int x = -scroll.x - 1;// + EXTRA_SPACE;// / 2 - 1;
2206 int w = clientSize.w;
2207 int h = clientSize.h;
2211 // Fill out indent column
2212 if(style.collapse && !(style.treeBranch) && (style.header || rows.first))
2215 surface.SetBackground(formColor);
2216 surface.Area(-scroll.x, 0, x, clientSize.h);
2219 surface.SetForeground(formColor);
2220 for(row = firstRowShown; row; row = row.GetNextRow())
2223 surface.HLine(x + 1, w-1, y-1);
2229 for(field = fields.first; field; field = field.next)
2231 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2232 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2233 if(field.prev && y > 0)
2234 surface.VLine(0, y-1, x);
2239 surface.foreground = this.foreground;
2240 surface.TextOpacity(false);
2242 // Draw the tree branches
2243 if(style.treeBranch)
2245 int y = -scroll.y + ((style.header) ? rowHeight : 0);
2246 surface.LineStipple(0x5555);
2247 surface.SetForeground(branchesColor);
2248 for(row = rows.first; row; row = row.GetNextRow() )
2250 int x = -scroll.x + EXTRA_SPACE / 2-1;
2251 int rowStart = -scroll.x;
2256 for(parent = row.parent; parent; parent = parent.parent)
2257 if(!parent.header) indent += 20;
2258 if(style.rootCollapse) indent += 20;
2260 plusIndent = (style.treeBranch) ? (indent - 20 + 4) : indent;
2265 if(row.subRows.first)
2268 int y1 = y + PLUSY + 4;
2272 for(child = row.collapsed ? null : row.subRows.first; child && child != row; )
2275 if(child.subRows.first && !child.collapsed && child != row.subRows.last)
2276 child = child.subRows.first;
2281 for(; child && child != row; child = child.parent)
2291 y2 = y + numRows * rowHeight + PLUSY + 4;
2292 surface.VLine(y1, y2, rowStart + plusIndent + 7 + 20);
2294 surface.HLine(rowStart + plusIndent + 7, rowStart + indent, y + PLUSY + 4);
2297 if(y >= clientSize.h)
2300 // Root Vertical Lines
2301 if(style.rootCollapse && rows.first)
2306 y = -scroll.y + ((style.header) ? rowHeight : 0);
2308 for(child = rows.first; child && child != rows.last; )
2311 if(child.subRows.first && !child.collapsed && child != rows.last)
2312 child = child.subRows.first;
2317 for(; child; child = child.parent)
2327 y2 = y + numRows * rowHeight + PLUSY + 4;
2328 surface.VLine(y1, y2, -scroll.x + 11);
2330 surface.LineStipple(0);
2333 for(row = firstRowShown; row; row = row.GetNextRow() )
2335 int x = -scroll.x + EXTRA_SPACE / 2-1;
2338 Color foreground = this.foreground /*black*/, background = this.background /*white*/;
2339 DataDisplayFlags dataDisplayFlags = 0;
2340 int rowStart = -scroll.x;
2343 Bitmap icon = row.icon ? row.icon.bitmap : null;
2344 int collapseRowStart = 0;
2345 bool lastWasHeader = row.header;
2347 for(parent = row.parent; parent; parent = parent.parent)
2349 if(!parent.header || lastWasHeader)
2351 if(style.treeBranch)
2357 if(style.rootCollapse) indent += 20;
2360 dataDisplayFlags.fullRow = style.fullRowSelect;
2361 dataDisplayFlags.active = isActive;
2362 dataDisplayFlags.header = row.header;
2367 collapseRowStart = rowStart;
2369 if(!(style.treeBranch))
2376 if(style.multiSelect)
2378 dataDisplayFlags.selected = row.selectedFlag == selected || row.selectedFlag == tempSelected;
2379 dataDisplayFlags.current = row == currentRow || (!currentRow && row == firstRowShown);
2383 dataDisplayFlags.selected = row.selectedFlag == selected || row.selectedFlag == tempSelected;
2384 dataDisplayFlags.current = row == currentRow || (!currentRow && row == firstRowShown);
2386 if(row == currentRow)
2388 dataDisplayFlags.current = true;
2389 dataDisplayFlags.selectedFlag = true;
2391 else if(!currentRow && row == firstRowShown)
2393 dataDisplayFlags.current = true;
2397 surface.TextOpacity(true);
2399 background = this.background;
2400 foreground = this.foreground;
2402 // Draw the current row background
2405 Color colors[] = { formColor, azure, mistyRose, linen, floralWhite, lavender, lavenderBlush, lemonChiffon };
2408 while((p = p.parent)) level++;
2409 background = colors[level % (sizeof(colors)/sizeof(colors[0]))];
2410 surface.SetBackground(background);
2411 surface.Area(rowStart, y, clientSize.w, (y + rowHeight) - 1);
2412 foreground = branchesColor;
2414 else if(dataDisplayFlags.selected)
2416 if(dataDisplayFlags.selected && (isActive || style.alwaysHL || (style.alwaysEdit && style.fullRowSelect)))
2418 if(!isActive && style.alwaysEdit)
2419 background = formColor;
2421 background = selectionColor ? selectionColor : SELECTION_COLOR;
2422 if(style.fullRowSelect)
2424 int offset = (style.alwaysEdit) ? 2 : 1;
2425 surface.SetBackground(background);
2426 surface.Area(rowStart, y, clientSize.w, (y + rowHeight) - offset);
2428 if(isActive || !(style.alwaysEdit))
2429 foreground = selectionText ? selectionText : SELECTION_TEXT;
2431 foreground = branchesColor;
2437 surface.Blit(icon, x + (20 - icon.width) /2,y + 2,0,0, icon.width, icon.height);
2443 int width = clientSize.w;
2445 dataDisplayFlags.firstField = true;
2446 clip.left = x - EXTRA_SPACE / 2+1;
2448 clip.right = x + width - EXTRA_SPACE/2 - 0;
2449 clip.bottom = y + rowHeight - 1;
2450 surface.Clip(&clip);
2452 surface.TextFont(font);
2454 surface.SetForeground(foreground);
2455 surface.SetBackground(background);
2457 ((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);
2461 if(opacity < 1) surface.TextOpacity(false);
2463 for(field = fields.first; field; field = field.next)
2466 int width = ((!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) || row.header) ?
2467 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2469 // Box clip = { x, y+1, x + field.width - EXTRA_SPACE - 1, y + rowHeight - 2 };
2472 //width -= EXTRA_SPACE;
2474 if(!field.prev) width -= indent;
2477 dataDisplayFlags.firstField = field.prev ? false : true;
2479 if(!dataDisplayFlags.firstField && !dataDisplayFlags.fullRow)
2481 background = this.background;
2482 foreground = this.foreground;
2485 if(!isActive && dataDisplayFlags.selected && style.alwaysEdit && field.editable && opacity)
2488 surface.SetBackground(background);
2489 surface.Area(x-3, y, x+width-1, y + rowHeight-2);
2492 clip.left = x - EXTRA_SPACE / 2+1;
2494 clip.right = x + width - EXTRA_SPACE/2 - 0;
2495 clip.bottom = y + rowHeight - 1;
2496 surface.Clip(&clip);
2498 for(index = 0, cell = row.cells.first; cell && index != field.index; index++, cell = cell.next);
2499 // Should always be as many cells in the row as fields in the listbox
2500 if(cell && cell.isSet && field.dataType)
2503 surface.TextFont(boldFont);
2505 surface.TextFont(font);
2507 surface.SetForeground(foreground);
2508 surface.SetBackground(background);
2510 if(field.dataType.type == noHeadClass || field.dataType.type == normalClass)
2511 ((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);
2513 ((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);
2516 if(!isActive && dataDisplayFlags.selected && style.alwaysEdit && field.editable)
2517 background = formColor;
2519 if(!dataDisplayFlags.firstField && !dataDisplayFlags.fullRow)
2521 background = formColor;
2522 foreground = this.background;
2526 // surface.WriteTextf(x + 100, y, "ix: %d", row.index);
2529 x += width;// + EXTRA_SPACE;
2531 if(row.header) break;
2537 int plusIndent = (style.treeBranch) ? (indent - 20 + 4) : indent;
2539 if(row.subRows.first && (row.parent || !(style.treeBranch) || (style.rootCollapse)))
2541 surface.SetForeground(row.header ? headerCollapseForeground : this.foreground);
2542 surface.Rectangle(collapseRowStart + 3 + plusIndent, y + PLUSY, collapseRowStart + 11 + plusIndent, y + PLUSY + 8);
2544 surface.SetBackground(row.header ? (formColor) : (this.background)); //white
2545 surface.Area(collapseRowStart + 4 + plusIndent, y + PLUSY + 1, collapseRowStart + 10 + plusIndent, y + PLUSY + 7);
2547 surface.HLine(collapseRowStart + 5 + plusIndent, collapseRowStart + 9 + plusIndent, y+PLUSY+4);
2549 surface.VLine(y + PLUSY + 2, y + PLUSY + 6, collapseRowStart + 7 + plusIndent);
2554 // Draw the current row stipple
2555 if(style.fullRowSelect && !(style.alwaysEdit) && (dataDisplayFlags.current) && isActive)
2560 surface.LineStipple(0x5555);
2561 if(dataDisplayFlags.selected)
2562 surface.SetForeground(stippleColor);
2564 surface.SetForeground(this.foreground);
2567 surface.SetForeground(selectionColor ? selectionColor : SELECTION_COLOR);
2568 surface.Rectangle(0, y, clientSize.w-1, (y + rowHeight) - 1);
2569 surface.LineStipple(0);
2573 if(y >= clientSize.h)
2576 if(firstRowShown) surface.Clip(null);
2577 if(this.dragRow && this.dropIndex != -1)
2579 int dropIndex = this.dropIndex;
2582 if(!style.multiSelect && currentRow.index < this.dropIndex)
2584 surface.DrawingChar(223);
2586 y = style.header ? rowHeight : 0;
2587 y += dropIndex * rowHeight - scroll.y;
2589 surface.SetForeground(Color { 85, 85, 255 });
2590 surface.HLine(0, clientSize.w-1, y);
2591 surface.HLine(0, clientSize.w-1, y + 1);
2595 void OnDrawOverChildren(Surface surface)
2597 if(draggingField && this.dropField)
2599 int position = this.dropField.x;
2600 if(draggingField.x < position)
2601 position += this.dropField.width + EXTRA_SPACE;
2603 surface.SetForeground(Color { 85, 85, 255 });
2604 surface.VLine(0, rowHeight - 1, position - scroll.x - 2);
2605 surface.VLine(0, rowHeight - 1, position - scroll.x);
2607 if(sortField && !style.clearHeader && style.header)
2609 DataField field = sortField;
2610 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2611 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2614 surface.TextExtent(field.header, strlen(field.header), &tw, &th);
2615 if(tw < width - EXTRA_SPACE)
2617 bool up = field.sortOrder == 1;
2621 field.x + 2 - scroll.x, 0,
2622 field.x + width + EXTRA_SPACE - 1 - scroll.x, rowHeight
2624 surface.Clip(&clip);
2625 if(field.alignment == left || field.alignment == center)
2627 if(field.alignment == center)
2628 x = field.x + (width + EXTRA_SPACE - tw) / 2 + tw + EXTRA_SPACE + 4;
2630 x = field.x + tw + EXTRA_SPACE + 4;
2632 x = Min(x, field.x + width - 4);
2634 else if(field.alignment == right)
2636 x = field.x + width - tw - 2*EXTRA_SPACE - 4;
2637 x = Max(x, field.x + 2);
2643 // surface.SetForeground((wmenu.selectedFlag == item) ? white : black);
2644 // surface.WriteText(clientSize.w-8, y+(wmenu.rh - 8)/2, "\020", 1);
2650 surface.SetForeground(Color { 128,128,128 } );
2651 surface.DrawLine(x + 3, y, x, y + 5);
2652 surface.PutPixel(x + 1, y + 5);
2653 surface.PutPixel(x + 1, y + 3);
2654 surface.PutPixel(x + 2, y + 1);
2656 surface.SetForeground(white);
2657 surface.DrawLine(x + 4, y, x + 7, y + 5);
2658 surface.PutPixel(x + 6, y + 5);
2659 surface.PutPixel(x + 6, y + 3);
2660 surface.PutPixel(x + 5, y + 1);
2662 surface.DrawLine(x, y + 6, x + 7, y + 6);
2666 surface.SetForeground(Color { 128,128,128 });
2667 surface.DrawLine(x + 3, y+6, x, y+1);
2668 surface.PutPixel(x + 1, y+1);
2669 surface.PutPixel(x + 1, y+3);
2670 surface.PutPixel(x + 2, y+5);
2672 surface.SetForeground(white);
2673 surface.DrawLine(x + 4, y+6, x + 7, y+1);
2674 surface.PutPixel(x + 6, y+1);
2675 surface.PutPixel(x + 6, y+3);
2676 surface.PutPixel(x + 5, y+5);
2678 surface.DrawLine(x, y, x + 7, y);
2687 void OnResize(int w, int h)
2690 bool showEndBevel = false;
2692 if(style.collapse && !style.treeBranch)
2694 for(field = fields.first; field; field = field.next)
2696 int width = field.width + EXTRA_SPACE;
2704 (rowCount * rowHeight) +
2705 ((style.header) ? rowHeight : 0) -
2706 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
2708 for(field = fields.first; field; field = field.next)
2710 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2711 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2712 if(style.header && field.headButton)
2714 showEndBevel = true;
2717 field.headButton.position = { field.x, 0 };
2718 field.headButton.size = { width, rowHeight };
2719 field.headButton.visible = true;
2722 field.headButton.visible = false;
2726 if(!style.fillLastField && showEndBevel && endBevel)
2728 endBevel.position = { x, 0 };
2729 endBevel.size = { clientSize.w + 2 - x, rowHeight };
2730 endBevel.visible = true;
2733 endBevel.visible = false;
2735 if(style.alwaysEdit && editData && editData.visible)
2737 HideEditBox(true, false, true);
2739 else if(editData && editData.visible)
2740 RepositionFieldEditor();
2743 void AdaptToFieldWidth(DataField field, bool doScroll)
2745 OnResize(clientSize.w, clientSize.h);
2747 // Scroll appropriately
2750 if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x &&
2751 field.x >= field.x + field.width + EXTRA_SPACE - clientSize.w)
2753 SetScrollPosition(field.x + field.width + EXTRA_SPACE - clientSize.w, scroll.y);
2755 else if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x ||
2757 SetScrollPosition(field.x, scroll.y);
2762 bool HeaderPushed(Button control, int x, int y, Modifiers mods)
2764 DataField field = (DataField)(intptr)control.id;
2765 // false: dont destroy edit box
2766 HideEditBox(true, false, true);
2767 if(style.resizable && ((!field && x < RESIZE_BORDER && fields.last) ||
2768 (field && x < RESIZE_BORDER && field.prev) ||
2769 (field && x >= control.clientSize.w - RESIZE_BORDER)))
2772 field = fields.last;
2773 else if(x < RESIZE_BORDER && field.prev)
2776 if(field.fixed) return false;
2777 resizingField = field;
2778 this.resizeX = x + control.position.x;
2779 this.startWidth = field.width;
2780 this.oldX = x - scroll.x;
2785 if(field.fixed) return false;
2786 draggingField = field;
2787 if(style.moveFields)
2788 field.headButton.stayDown = true;
2789 else if(!style.sortable)
2797 bool HeaderMouseMove(Button control, int x, int y, Modifiers mods)
2802 DataField field = resizingField;
2804 x += control.position.x;
2806 // Tweak to prevent shrinking field if we're actually moving right
2807 if(x - scroll.x > this.oldX &&
2808 this.startWidth + x - this.resizeX < field.width)
2810 this.oldX = x - scroll.x;
2813 this.oldX = x - scroll.x;
2815 field.width = this.startWidth + x - this.resizeX;
2816 field.width = Max(field.width, - EXTRA_SPACE);
2818 AdaptToFieldWidth(field, true);
2820 else if(draggingField)
2822 x += control.position.x;
2823 if(style.moveFields)
2825 DataField field = fields.last;
2827 for(field = fields.first; field; field = field.next)
2829 fieldX += ((field.width || style.resizable) ?
2830 field.width : clientSize.w) + EXTRA_SPACE;
2834 if(draggingField == field)
2836 // Reset scroll position
2837 if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x &&
2838 field.x >= field.x + field.width + EXTRA_SPACE - clientSize.w)
2841 field.x + field.width + EXTRA_SPACE - clientSize.w,
2844 else if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x ||
2846 SetScrollPosition(field.x, scroll.y);
2849 if(this.dropField != field)
2851 this.dropField = field;
2854 int position = field.x;
2856 if(draggingField.x < position)
2858 position += field.width + EXTRA_SPACE - clientSize.w;
2859 if(position > scroll.x)
2860 SetScrollPosition(position, scroll.y);
2865 if(position < scroll.x)
2866 SetScrollPosition(position, scroll.y);
2869 this.movingFields = true;
2875 else if(style.resizable)
2877 DataField field = (DataField)(intptr)control.id;
2880 if(x < RESIZE_BORDER && field.prev)
2882 if(!field.prev.fixed)
2883 control.cursor = guiApp.GetCursor(sizeWE);
2885 else if(x >= control.clientSize.w - RESIZE_BORDER)
2886 control.cursor = guiApp.GetCursor(sizeWE);
2888 control.cursor = null;
2892 if(x < RESIZE_BORDER && fields.last)
2893 control.cursor = guiApp.GetCursor(sizeWE);
2895 control.cursor = null;
2901 bool HeaderReleased(Button control, int x, int y, Modifiers mods)
2905 NotifyResized(master, this, resizingField, mods);
2906 resizingField = null;
2913 if(style.moveFields)
2918 DataField switchField = fields.last;
2922 x += draggingField.x;
2923 for(field = fields.first; field; field = field.next)
2925 fieldX += ((field.width || style.resizable) ?
2926 field.width : clientSize.w) + EXTRA_SPACE;
2929 switchField = field;
2933 if(switchField && draggingField != switchField && this.dropField)
2935 for(field = fields.first; field; field = field.next)
2937 if(field == switchField || field == draggingField)
2941 // Switch field first: move before
2942 if(field == switchField)
2943 draggingField.Move(switchField.prev);
2944 // Dragged field first: move after
2946 draggingField.Move(switchField);
2948 NotifyMovedField(master, this, draggingField, mods);
2950 draggingField.headButton.stayDown = false;
2955 movingFields = false;
2957 draggingField = null;
2963 bool HeaderClicked(Button control, int x, int y, Modifiers mods)
2965 if(style.header && !this.dropField && style.sortable)
2967 DataField field = (DataField)(intptr)control.id;
2968 if(sortField == field)
2969 field.sortOrder *= -1;
2974 Sort(sortField, field.sortOrder);
2975 NotifySort(master, this, field, mods);
2981 bool HeaderDoubleClicked(Button control, int x, int y, Modifiers mods)
2985 DataField field = (DataField)(intptr)control.id;
2988 if(x < RESIZE_BORDER && field.prev)
2990 else if(x >= control.clientSize.w - RESIZE_BORDER);
2996 if(x < RESIZE_BORDER && fields.last)
2997 field = fields.last;
3009 if(style.freeSelect)
3014 rolledOver = dragging = false;
3021 bool OnLoadGraphics()
3023 display.FontExtent(fontObject, "W", 1, null, &fontH);
3024 if(!style.heightSet)
3026 rowHeight = Max(fontH + 2, 16) + (style.alwaysEdit ? 1 : 0);
3027 SetScrollLineStep(8, rowHeight);
3032 void OnApplyGraphics()
3034 SetScrollLineStep(8, rowHeight);
3038 for(field = fields.first; field; field = field.next)
3040 if(field.headButton)
3042 field.headButton.bevel = (!guiApp.textMode && !style.clearHeader);
3044 field.headButton.background = Color { 0, 170, 0 };
3048 OnResize(clientSize.w, clientSize.h);
3051 bool OnResizing(int *w, int *h)
3055 if(!initSize.w && (!anchor.left.type || !anchor.right.type) && !*w)
3060 Font font = fontObject;
3061 Font boldFont = this.boldFont.font;
3062 Display display = this.display;
3064 for(row = rows.first; row; row = row.GetNextRow())
3066 Bitmap icon = row.icon ? row.icon.bitmap : null;
3067 int x = -scroll.x + EXTRA_SPACE / 2-1;
3071 for(parent = row.parent; parent; parent = parent.parent)
3075 if(style.treeBranch)
3081 if(style.rootCollapse) indent += 20;
3083 if(style.collapse && !(style.treeBranch)) x += 15;
3087 // Compute the rows size
3088 for(field = fields.first; field; field = field.next)
3090 if(((style.resizable && (!(style.alwaysEdit) || field.next)) || field.width) && !row.header)
3091 x += field.width - (field.prev ? 0 : indent);
3096 for(index = 0, cell = row.cells.first; index != field.index; index++, cell = cell.next);
3098 // Should always be as many cells in the row as fields in the listbox
3099 if(cell && cell.isSet && field.dataType)
3101 static char tempString[4096];
3102 const char * string;
3104 if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
3105 string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, cell.data[0], tempString, field.userData, null);
3107 string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, cell.data, tempString, field.userData, null);
3109 if(!string) string = "";
3110 display.FontExtent(row.header ? boldFont : font, string, strlen(string), &tw, &th);
3113 display.FontExtent(row.header ? boldFont : font, string, strlen(string), &tw, &th);
3115 display.FontExtent(row.header ? boldFont : font, "", 0, &tw, &th);
3118 if(row.header) break;
3122 maxWidth = Max(maxWidth, x);
3128 *h = Min(this.maxShown, this.rowCount) * rowHeight;
3133 if(!*w) *w = rowHeight * 5;
3134 if(!*h) *h = rowHeight * 5;
3141 FontResource font = this.font;
3142 FontResource boldFont
3144 faceName = font.faceName, size = font.size, bold = true
3146 AddResource(boldFont);
3147 RemoveResource(this.boldFont);
3148 this.boldFont = boldFont;
3152 SetInitSize(initSize);
3155 bool OnMouseMove(int x, int y, Modifiers mods)
3157 bool isTimer = false;
3158 int realX = x, realY = y;
3160 if(insideNotifySelect) return true;
3162 if(style.alwaysEdit && style.resizable &&
3163 resizingField && !(mods.isSideEffect))
3166 DataField field = resizingField;
3167 field.width = this.startWidth + x - this.resizeX;
3168 field.width = Max(field.width, - EXTRA_SPACE);
3170 AdaptToFieldWidth(field, true);
3174 if(style.alwaysEdit && style.resizable)
3176 int vx = -scroll.x - 1;
3179 if(style.collapse && !(style.treeBranch))
3182 for(field = fields.first; field; field = field.next)
3184 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3185 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3191 cursor = guiApp.GetCursor(sizeWE);
3195 vx += width + EXTRA_SPACE;
3199 if((editData && editData.visible) || (style.alwaysEdit))
3202 if(x == MAXINT && y == MAXINT)
3209 // ADDED THIS CHECK FOR FieldDropBox LEAKS
3210 if(/*!mods.isSideEffect && */(rolledOver || !dragging))
3212 int rowY = (style.header) ? rowHeight : 0;
3213 DataRow row = null, nextRow;
3220 ((vertScroll && vertScroll.visible &&
3221 (y < 0 || y >= clientSize.h)) ||
3222 (horzScroll && horzScroll.visible &&
3223 (x < 0 || x >= clientSize.w))))
3228 if(vertScroll && vertScroll.visible &&
3229 (y < 0 || y >= clientSize.h))
3230 vertScroll.Action((y<0)?up:down, 0, 0);
3231 if(horzScroll && horzScroll.visible &&
3232 (x < 0 || x >= clientSize.w))
3233 horzScroll.Action((x<0)?up:down, 0, 0);
3239 // This must be done after the scrolling took place
3240 rowIndex = firstRowShown ? firstRowShown.index : -1;
3242 y = Min(y, clientSize.h-rowHeight-1);
3243 for(row = firstRowShown; row; row = nextRow, rowIndex ++)
3245 nextRow = row.GetNextRow();
3247 if(rowY > y || !nextRow)
3252 if(row && row == currentRow)
3253 row = row.GetNextRow();
3254 if(row && row.parent == currentRow)
3255 row = row.GetNextRow();
3257 if(row && currentRow != row)
3259 if(this.dragRow && style.moveRows)
3261 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
3263 else if(style.multiSelect)
3266 for(thisRow = rows.first; thisRow; thisRow = thisRow.GetNextRow())
3267 if((thisRow.selectedFlag == selected || thisRow.selectedFlag == tempSelected) ||
3273 if(this.dropIndex != rowIndex)
3275 this.dropIndex = rowIndex;
3276 this.editRow = null;
3278 this.movedRow = true;
3281 else if((style.freeSelect || this.dragging) && ((realX>= 0 && realY >= 0 && realX< clientSize.w && realY < clientSize.h) || rolledOver))
3283 if(!(style.multiSelect))
3285 if(currentRow)currentRow.selectedFlag = unselected;
3286 if(row)row.selectedFlag = selected;
3290 if(style.multiSelect)
3294 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3296 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3297 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3300 if(rowIndex >= clickedRow.index)
3302 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
3304 selRow.selectedFlag = (selRow.selectedFlag == selected) ? tempUnselected : tempSelected;
3311 for(selRow = row; selRow; selRow = selRow.GetNextRow())
3313 selRow.selectedFlag = (selRow.selectedFlag == selected) ? tempUnselected : tempSelected;
3314 if(selRow == clickedRow)
3320 if(style.freeSelect)
3321 NotifyHighlight(master, this, currentRow, mods);
3324 insideNotifySelect = true;
3325 NotifySelect(master, this, currentRow, mods);
3326 insideNotifySelect = false;
3329 if(style.alwaysEdit && currentRow)
3330 currentRow.Edit(currentField);
3337 bool OnMouseOver(int x, int y, Modifiers mods)
3344 bool OnActivate(bool active, Window swap, bool * goOnWithActivation, bool direct)
3346 // TOCHECK: WAS THIS MISSING ? CHECK FOR SLOWDOWN
3347 if(!active) Update(null);
3349 if(!active && (!swap || !swap.isModal))
3351 // true: destroy edit box
3352 HideEditBox(true, true, false);
3354 else if(!swap || !swap.isModal)
3356 // Bring back edit box
3357 if(currentRow && style.alwaysEdit)
3359 currentRow.Edit(currentField ? currentField : null);
3363 return true; //NotifyActivate(master, this, active, swap, 0);
3367 bool OnButtonDown(int x, int y, Modifiers mods, bool right)
3370 // Check to see if we're dragging the vertical divider
3371 if(style.alwaysEdit && style.resizable && !right)
3373 int vx = -scroll.x - 1;// + EXTRA_SPACE;// / 2 - 1;
3376 if(style.collapse && !(style.treeBranch))
3379 for(field = fields.first; field; field = field.next)
3381 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3382 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3388 resizingField = field.prev;
3390 this.startWidth = resizingField.width;
3392 SetMouseRangeToClient();
3396 vx += width + EXTRA_SPACE;
3400 if(!(style.freeSelect))
3402 int rowY = (style.header) ? rowHeight : 0;
3404 int rowIndex = firstRowShown ? firstRowShown.index : -1;
3405 DataRow previousRow = currentRow;
3406 DataRow newCurrentRow = null;
3407 bool moveMultiple = false;
3408 int numSelected = 0;
3409 int rowStart = -scroll.x;
3411 if(style.multiSelect)
3418 for(row = rows.first; row; row = row.GetNextRow())
3420 if(row.selectedFlag == tempSelected)
3421 row.selectedFlag = selected;
3422 else if(row.selectedFlag == tempUnselected)
3423 row.selectedFlag = unselected;
3424 if(row.selectedFlag == selected)
3431 for(row = firstRowShown; row; row = row.GetNextRow(), rowIndex ++)
3434 if(rowY > y || (style.multiSelect && !row.GetNextRow()))
3437 if(style.treeBranch)
3440 for(parent = (style.rootCollapse) ? row.parent : (row.parent ? row.parent.parent : null); parent; parent = parent.parent)
3446 /* THIS WAS TOO STRICT:
3447 if(style.collapse && row.subRows.first && (row.parent || !(style.treeBranch) || (style.rootCollapse)) &&
3448 (x >= rowStart + 3 + plusIndent && y >= rowY - rowHeight + PLUSY && x <= rowStart + 11 + plusIndent && y <= rowY - rowHeight + PLUSY + 8))
3450 if(style.collapse &&
3451 (x >= rowStart && y >= rowY - rowHeight && x <= rowStart + 18 + plusIndent && y <= rowY + rowHeight-1))
3453 if(row.subRows.first && (row.parent || !(style.treeBranch) || (style.rootCollapse)) && x >= plusIndent)
3454 row.collapsed = !row.collapsed;
3461 newCurrentRow = row;
3463 if(style.multiSelect)
3465 // Deselect everything if user didn't clicked on a row
3469 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3470 selRow.selectedFlag = unselected;
3472 //this.clickedRowIndex = rowIndex;
3474 else if(style.moveRows && !(mods.shift) &&
3475 (row.selectedFlag == selected || row.selectedFlag == tempSelected) &&
3476 !right && !(mods.isActivate))
3477 moveMultiple = true;
3483 if(row.selectedFlag == tempUnselected || row.selectedFlag == unselected)
3485 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3486 selRow.selectedFlag = unselected;
3487 row.selectedFlag = selected;
3490 //this.clickedRowIndex = rowIndex;
3496 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3497 selRow.selectedFlag = unselected;
3501 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3503 if(selRow != clickedRow)
3505 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3506 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3513 if(rowIndex >= clickedRow.index)
3515 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
3519 if(selRow != clickedRow)
3521 if(selRow.selectedFlag)
3522 selRow.selectedFlag = tempUnselected;
3524 selRow.selectedFlag = tempSelected;
3528 selRow.selectedFlag = selected;
3535 for(selRow = row; selRow; selRow = selRow.GetNextRow())
3539 if(selRow != clickedRow)
3541 if(selRow.selectedFlag)
3542 selRow.selectedFlag = tempUnselected;
3544 selRow.selectedFlag = tempSelected;
3548 selRow.selectedFlag = selected;
3549 if(selRow == clickedRow)
3558 if(row.selectedFlag)
3559 row.selectedFlag = tempUnselected;
3560 else row.selectedFlag = tempSelected;
3563 row.selectedFlag = tempSelected;
3565 //this.clickedRowIndex = rowIndex;
3575 // true: destroy edit box
3578 incref newCurrentRow;
3581 if(currentRow != newCurrentRow)
3582 HideEditBox(true, true, false);
3586 if(newCurrentRow._refCount <= 1)
3587 delete newCurrentRow;
3589 newCurrentRow._refCount--;
3594 if(!(style.multiSelect))
3596 if(currentRow) currentRow.selectedFlag = unselected;
3597 if(newCurrentRow) newCurrentRow.selectedFlag = selected;
3601 if(currentRow != newCurrentRow)
3604 // true: destroy edit box
3607 //incref newCurrentRow;
3608 incref newCurrentRow;
3611 HideEditBox(true, true, false);
3616 int headerSize = ((style.header) ? rowHeight : 0);
3617 int height = clientSize.h + 1 - headerSize;
3619 /*if(newCurrentRow._refCount <= 1)
3620 delete newCurrentRow;
3623 newCurrentRow._refCount--;
3624 //newCurrentRow._refCount--;
3627 currentRow = newCurrentRow;
3629 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
3630 SetScrollPosition(scroll.x,
3631 currentRow.index * rowHeight - height + rowHeight);
3632 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
3634 int line = currentRow ? currentRow.index * rowHeight : 0;
3635 //SNAPUP(line, rowHeight);
3636 SetScrollPosition(scroll.x, line);
3639 // GO THROUGH SetCurrentRow eventually?
3640 // SetCurrentRow(newCurrentRow, true);
3644 if(style.freeSelect)
3645 NotifyHighlight(master, this, currentRow, mods);
3646 else if((moveMultiple || (!(style.multiSelect) && previousRow == currentRow)) &&
3647 newCurrentRow && !(mods.shift))
3651 if(!(mods.isActivate))
3655 this.dragRow = currentRow;
3656 this.dropIndex = -1;
3657 this.movedRow = false;
3661 if(editData && editData.visible && style.alwaysEdit)
3668 if(style.collapse && !style.treeBranch)
3671 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3673 indent += (style.treeBranch) ? 20 : 15;
3676 for(field = fields.first; field; field = field.next)
3678 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3679 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3681 if(!field.prev) width -= indent;
3682 if(x >= sx && x < sx + width)
3686 if(field == currentField)
3687 editData.Deactivate();
3690 currentRow.Edit(field);
3691 editData.Activate();
3694 else if(!(mods.ctrl) && numSelected <= 1)
3695 this.editRow = currentRow;
3697 if(style.noDragging && newCurrentRow)
3698 NotifyReclick(master, this, newCurrentRow, mods);
3702 // If the user clicked exactly on the edited field,
3704 if(editData && editData.visible && newCurrentRow)
3710 if(style.collapse && !(style.treeBranch))
3715 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3717 indent += (style.treeBranch) ? 20 : 15;
3721 for(field = fields.first; field; field = field.next)
3723 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3724 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3725 if(!field.prev) width -= indent;
3726 if(x >= sx && x < sx + width && newCurrentRow)
3731 if(field) //x >= sx && x < sx + width && newCurrentRow)
3733 if(field == currentField)
3734 editData.Activate();
3736 newCurrentRow.Edit(currentField);*/
3738 else if(style.noDragging && newCurrentRow)
3739 NotifyReclick(master, this, newCurrentRow, mods);
3741 else if(style.noDragging && newCurrentRow)
3742 NotifyReclick(master, this, newCurrentRow, mods);
3749 if(result && style.alwaysEdit && currentRow)
3753 DataField field = null;
3758 if(style.collapse && !style.treeBranch)
3761 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3763 indent += (style.treeBranch) ? 20 : 15;
3766 for(field = fields.first; field; field = field.next)
3768 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3769 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3771 if(!field.prev) width -= indent;
3772 if(x >= sx && x < sx + width)
3774 f = currentField = field;
3781 // Moved NotifySelect after setting currentField for the NotifySelect implementation to be aware of which field is now selected (e.g. WatchesView)
3782 result = NotifySelect(master, this, currentRow, mods);
3783 if(result && style.alwaysEdit && currentRow)
3785 // In case the user specifically clicked on a field (f is set), override any change to currentField that NotifySelect could have done
3786 currentRow.Edit(f ? f : currentField);
3788 // If the user clicked exactly on the edited field,
3790 if(editData && editData.visible && newCurrentRow)
3794 editData.Activate();
3796 else if(style.noDragging && newCurrentRow)
3797 NotifyReclick(master, this, newCurrentRow, mods);
3800 else if(style.noDragging && newCurrentRow)
3801 NotifyReclick(master, this, newCurrentRow, mods);
3805 For drop box to capture...
3808 if(x < 0 || y < 0 || x >= clientSize.w || y >= clientSize.h)
3811 master.parent.Activate();
3820 if(!style.noDragging)
3825 if(x >= 0 && y >= 0 && x < clientSize.w && y < clientSize.h)
3831 this.dragging = false;
3832 OnLeftButtonUp(x, y, mods);
3837 bool OnLeftButtonDown(int x, int y, Modifiers mods)
3839 return OnButtonDown(x,y, mods, false);
3842 bool OnLeftButtonUp(int x, int y, Modifiers mods)
3844 if(resizingField && style.alwaysEdit)
3846 Window::FreeMouseRange();
3848 resizingField = null;
3851 if(dragRow || editRow)
3853 DataRow row, switchRow = rows.last;
3854 int rowY = (style.header) ? rowHeight : 0;
3855 while(switchRow.lastRow) switchRow = switchRow.lastRow;
3856 for(row = firstRowShown; row; row = row.GetNextRow())
3865 if(this.editRow == switchRow && y >= 0)
3870 for(field = fields.first; field; field = field.next)
3872 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3873 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3876 if(fieldX > x + scroll.x)
3880 if(field && field.editable)
3882 // true: destroy edit box
3883 HideEditBox(true, true, false);
3884 PopupEditBox(field, false);
3886 else if(!style.noDragging)
3887 NotifyReclick(master, this, currentRow, mods);
3889 else if(style.moveRows && switchRow)
3891 if(this.dragRow == switchRow && this.movedRow == false)
3893 DataRow row = this.dragRow;
3897 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3898 selRow.selectedFlag = unselected;
3902 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3904 if(selRow != clickedRow)
3906 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3907 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3913 if(row.selectedFlag)
3914 row.selectedFlag = tempUnselected;
3915 else row.selectedFlag = tempSelected;
3918 row.selectedFlag = tempSelected;
3923 if(style.multiSelect)
3925 if(!switchRow.selectedFlag)
3927 bool foundSwitch = false;
3930 DataRow afterRow = switchRow.prev;
3931 for(row = rows.first; row; row = next)
3933 next = row.GetNextRow();
3934 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
3936 if(!foundSwitch && !after)
3939 afterRow = switchRow;
3941 if(!after || !(row.selectedFlag == selected || row.selectedFlag == tempSelected) ||
3948 else if(row == switchRow)
3955 for(row = rows.first; row; row = row.GetNextRow())
3957 if(row == switchRow || row == this.dragRow)
3961 // Switch row first: move before
3962 if(row == switchRow)
3964 DataRow actualMoveRow;
3966 if(!switchRow.prev && switchRow.parent == dragRow.parent)
3967 actualMoveRow = null;
3970 actualMoveRow = switchRow.prev ? switchRow.prev : switchRow;
3971 while(actualMoveRow && actualMoveRow.parent != dragRow.parent && actualMoveRow.parent)
3972 actualMoveRow = actualMoveRow.parent;
3975 if(!actualMoveRow || (actualMoveRow && actualMoveRow.parent == dragRow.parent))
3976 if(NotifyMove(master, this, actualMoveRow, mods))
3978 dragRow.Move(actualMoveRow);
3979 NotifyMoved(master, this, actualMoveRow, mods);
3982 // Dragged row first: move after
3985 DataRow actualMoveRow = switchRow;
3986 DataRow nextRow = switchRow.GetNextRow();
3988 while(nextRow && nextRow.parent != dragRow.parent)
3989 nextRow = nextRow.parent ? nextRow.parent.next : null;
3991 actualMoveRow = nextRow.prev;
3994 actualMoveRow = dragRow.parent ? dragRow.parent.subRows.last : rows.last;
3996 if(!actualMoveRow || (actualMoveRow != dragRow && actualMoveRow.parent == dragRow.parent))
3997 if(NotifyMove(master, this, actualMoveRow, mods))
3999 dragRow.Move(actualMoveRow);
4000 NotifyMoved(master, this, actualMoveRow, mods);
4016 if(dragging || style.freeSelect)
4020 rolledOver = dragging = false;
4022 if(x >= 0 && y >= 0 && x < clientSize.w && y < clientSize.h && currentRow && style.freeSelect)
4026 result = NotifySelect(master, this, currentRow, mods);
4027 if(style.alwaysEdit)
4028 currentRow.Edit(currentField);
4032 // if(!(style.freeSelect))
4038 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
4040 int rowStart = -scroll.x;
4042 int rowY = (style.header) ? rowHeight : 0;
4045 OnLeftButtonUp(x,y,mods);
4046 if(style.alwaysEdit)
4048 if(!(style.collapse) || x > 15)
4049 if(editData && editData.visible)
4051 editData.Activate();
4052 NotifyDoubleClick(master, this, x, y, mods);
4056 for(row = firstRowShown; row; row = row.GetNextRow())
4059 if(rowY > y || (style.multiSelect && !row.GetNextRow()))
4061 if(style.treeBranch)
4064 for(parent = (style.rootCollapse) ? row.parent : (row.parent ? row.parent.parent : null); parent; parent = parent.parent)
4073 if((row && style.collapse && (x >= rowStart && x <= rowStart + 18 + plusIndent)) ||
4074 NotifyDoubleClick(master, this, x, y, mods))
4078 if(row && row.subRows.first)
4080 row.collapsed = !row.collapsed;
4084 // We need to return true here so that OnLeftButtonDown can popup the DataBox Editors
4090 bool OnRightButtonDown(int x, int y, Modifiers mods)
4092 return OnButtonDown(x,y, mods, true);
4095 bool OnRightButtonUp(int x, int y, Modifiers mods)
4097 OnLeftButtonUp(x,y,mods);
4098 return NotifyRightClick(master, this, x, y, mods);
4101 bool GoToLetter(unichar ch, bool keyHit)
4103 bool result = false;
4105 bool checkNextField = true;
4106 int len = keyHit ? 0 : strlen(typedString);
4108 typedString = renew typedString char[len + 2];
4109 typedString[len++] = (char)tolower(ch); // TODO: FIX UNICODE
4110 typedString[len] = '\0';
4112 for(field = fields.first; field; field = field.next)
4114 DataRow startRow = currentRow ? currentRow : rows.first;
4116 if(startRow && field.dataType && field.dataType._vTbl[__ecereVMethodID_class_OnGetString] && ch)
4119 bool looped = false;
4120 if(len == 1 && currentRow)
4121 startRow = (next = startRow.GetNextRow(), (next ? next : rows.first));
4123 for(row = startRow; row != startRow || !looped; next = row.GetNextRow(), row = next ? next : rows.first)
4125 void * data = row.GetData(field);
4126 char tempString[1024] = "";
4127 bool needClass = false;
4128 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;
4130 if(string && string[0])
4131 checkNextField = false;
4132 if(string && string[0] && !strnicmp(string, typedString, len))
4134 if(style.multiSelect)
4139 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
4140 selRow.selectedFlag = unselected;
4141 row.selectedFlag = selected;
4143 SetCurrentRow(row, true);
4150 if(this.typingTimeOut && !keyHit)
4151 typingTimer.Start();
4152 if(!result || !this.typingTimeOut || keyHit)
4153 typedString[len-1] = '\0';
4155 if(!checkNextField || result) break;
4160 bool OnKeyDown(Key key, unichar ch)
4164 if(key == enter || key == keyPadEnter)
4166 if(editData && editData.visible && editData.active)
4168 HideEditBox(true, false, false);
4172 else if(key == escape)
4174 if(resizingField || this.movingFields || (editData && editData.visible) || dragRow)
4176 if(editData && editData.visible && style.alwaysEdit && !editData.active)
4178 // false: dont destroy edit box
4179 HideEditBox(false, false, false);
4182 resizingField.width = this.startWidth;
4183 AdaptToFieldWidth(resizingField, true);
4184 resizingField = null;
4197 this.movingFields = false;
4198 draggingField = null;
4204 if(!currentField || !currentField.editable)
4205 for(field = fields.first; field; field = field.next)
4209 currentField = field;
4213 if((key == f2 || (style.alwaysEdit && (key == ctrlV || key == ctrlC || key == ctrlX || key == shiftInsert || key == ctrlInsert || key == shiftDel))) &&
4214 currentField && currentField.editable)
4216 PopupEditBox(currentField, false);
4217 if(editData && editData.visible)
4219 if(style.alwaysEdit)
4221 editData.Activate();
4222 if(key == ctrlV || key == ctrlC || key == ctrlX || key == shiftInsert || key == ctrlInsert || key == shiftDel)
4224 editData.OnKeyHit(key, ch);
4228 // For Installer to pop up file dialog
4229 NotifyKeyDown(master, this, currentRow, key, ch);
4235 if(!NotifyKeyDown(master, this, currentRow, key, ch))
4238 // Editable fields...
4241 if(style.alwaysEdit && editData && editData.visible)
4242 return editData.OnKeyDown(key, ch);
4243 return true; // We want to pick up the OnKeyHit to replace contents, but skip GoToLetter
4246 if(ch >=32 && ch != 128 && !key.alt && !key.ctrl && GoToLetter(ch, false))
4248 /*if(inactive && window.state != Hidden)
4249 NotifyHighlight(master, this, currentRow, 0);
4252 NotifySelect(master, this, currentRow, 0);
4259 bool OnKeyHit(Key key, unichar ch)
4261 if(!ch && !key.alt && !key.ctrl)
4263 key.code = (SmartKey)key.code;
4265 if(ch >= 32 && !key.alt && !key.ctrl && ch != 128)
4268 if(!currentField || !currentField.editable)
4269 for(field = fields.first; field; field = field.next)
4273 currentField = field;
4277 if(currentField && currentField.editable)
4279 if((!editData || !editData.visible) || !editData.active)
4281 PopupEditBox(currentField, false);
4282 if(editData && editData.visible)
4284 editData.Activate();
4285 editData.OnKeyHit(key, ch);
4292 if(editData && editData.visible && ch && !key.alt && !key.ctrl && editData.active && (key.code != tab || (editData._class == class(EditBox) && ((EditBox)editData).tabKey)))
4295 if(!key.alt && (style.multiSelect || !key.ctrl))
4300 if(style.alwaysEdit)
4305 for(field = currentField.prev; field; field = field.prev)
4309 currentField = field;
4310 HideEditBox(true, true, false);
4311 PopupEditBox(currentField, false);
4317 if(style.collapse && currentRow /*&& !currentField*/) // THIS PREVENTED COLLAPSING THE PROPERTY SHEET
4319 if(currentRow.subRows.first && !currentRow.collapsed)
4321 currentRow.collapsed = true;
4323 else if(currentRow.parent)
4324 SetCurrentRow(currentRow.parent, true);
4329 if(style.collapse && currentRow && currentRow.subRows.first)
4331 if(currentRow.collapsed)
4332 currentRow.collapsed = false;
4334 SetCurrentRow(currentRow.subRows.first, true);
4337 else if(style.alwaysEdit)
4342 for(field = currentField.next; field; field = field.next)
4346 currentField = field;
4347 HideEditBox(true, true, false);
4348 PopupEditBox(currentField, false);
4356 case pageDown: case pageUp:
4357 case end: case home:
4359 int headerSize = ((style.header) ? rowHeight : 0);
4360 int height = clientSize.h + 1 - headerSize;
4363 // true: destroy edit box
4364 // !!! TESTING true HERE !!!
4365 HideEditBox(true, true, false);
4366 // HideEditBox(false, true, false);
4368 oldRow = currentRow;
4370 SNAPDOWN(height, rowHeight);
4371 if((!currentRow || key.code == home) && key.code != end)
4373 currentRow = rows.first;
4381 if(!(style.multiSelect) && currentRow && !currentRow.selectedFlag)
4384 next = currentRow.GetNextRow();
4391 if(!(style.multiSelect) && currentRow && !currentRow.selectedFlag)
4394 next = currentRow.GetPrevRow();
4402 currentRow = lastRow.GetLastRow();
4408 currentRow && (next = currentRow.GetPrevRow()) && c < height / rowHeight;
4409 c++, currentRow = next);
4416 currentRow && (next = currentRow.GetNextRow()) && c < height / rowHeight;
4417 c++, currentRow = next);
4422 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
4423 SetScrollPosition(scroll.x, currentRow.index * rowHeight - height + rowHeight);
4424 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
4425 SetScrollPosition(scroll.x, currentRow ? currentRow.index * rowHeight : 0);
4427 if(style.multiSelect)
4431 if(!(key.shift) && (key.ctrl))
4434 for(row = rows.first; row; row = row.GetNextRow())
4436 if(row.selectedFlag == tempSelected)
4437 row.selectedFlag = selected;
4438 else if(row.selectedFlag == tempUnselected)
4439 row.selectedFlag = unselected;
4445 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
4446 selRow.selectedFlag = unselected;
4450 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
4452 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
4453 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
4459 if(currentRow.index >= clickedRow.index)
4461 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
4465 if(selRow.selectedFlag) selRow.selectedFlag = tempUnselected; else selRow.selectedFlag = tempSelected;
4468 selRow.selectedFlag = selected;
4469 if(selRow == currentRow)
4475 for(selRow = currentRow; selRow; selRow = selRow.GetNextRow())
4479 if(selRow.selectedFlag) selRow.selectedFlag = tempUnselected; else selRow.selectedFlag = tempSelected;
4482 selRow.selectedFlag = selected;
4483 if(selRow == clickedRow)
4490 if(!(key.ctrl) && currentRow)
4492 currentRow.selectedFlag = selected;
4495 clickedRow = currentRow;
4500 if(oldRow) oldRow.selectedFlag = unselected;
4501 if(currentRow) currentRow.selectedFlag = selected;
4506 if(style.freeSelect)
4507 NotifyHighlight(master, this, currentRow, 0);
4509 NotifySelect(master, this, currentRow, 0);
4511 if(style.alwaysEdit && currentRow)
4512 currentRow.Edit(currentField /*null*/);
4519 if(style.multiSelect && currentRow)
4521 if(currentRow.selectedFlag)
4524 currentRow.selectedFlag = unselected;
4527 currentRow.selectedFlag = selected;
4530 if(style.freeSelect)
4531 NotifyHighlight(master, this, currentRow, 0);
4533 NotifySelect(master, this, currentRow, 0);
4540 if(!NotifyKeyHit(master, this, currentRow, key, ch))
4543 if(ch >=32 && ch != 128 && !key.alt && !key.ctrl && GoToLetter(ch, true))
4545 /*if(inactive && window.state != Hidden)
4546 return NotifyHighlight(master, this, currentRow, 0);
4549 return NotifySelect(master, this, currentRow, 0);
4556 void OnHScroll(ScrollBarAction action, int position, Key key)
4561 void OnVScroll(ScrollBarAction action, int position, Key key)
4566 for(firstRowShown = rows.first; firstRowShown; firstRowShown = next)
4568 next = firstRowShown.GetNextRow();
4569 if(y >= position || !next) break;
4579 DataRow firstRowShown;
4583 DataField sortField;
4587 double typingTimeOut;
4600 if(guiApp.GetKeyState(shift)) mods.shift = true;
4601 if(guiApp.GetKeyState(alt)) mods.alt = true;
4602 if(guiApp.GetKeyState(control)) mods.ctrl = true;
4603 OnMouseMove(MAXINT, MAXINT, mods);
4611 delay = 0.5; // typingTimeOut
4616 typedString[0] = '\0';
4618 // The next line was commented... Why? When commented typing words stops working ( only first character jumps )
4624 bool dragging, rolledOver;
4633 // For editing fields
4635 DataField currentField;
4638 // For moving fields
4639 DataField draggingField, dropField;
4642 // For resizing fields
4643 DataField resizingField;
4644 int resizeX, oldX, startWidth;
4647 FontResource boldFont;
4650 // Only used for OnMouseMove so far, for avoiding problems with consequential mouse moves
4651 bool insideNotifySelect;
4652 ColorAlpha selectionColor, selectionText, stippleColor;
4653 stippleColor = 0xFFFFFF80;