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);
1137 private void CheckConsistency()
1142 for(r = rows.first; r; r = r.GetNextRow())
1144 if(r.index != index++)
1152 void AddField(DataField addedField)
1157 if(fields.first && ((DataField)fields.first).defaultField)
1159 DataField defaultField = fields.first;
1160 defaultField.Free();
1161 delete defaultField;
1165 addedField = DataField { };
1169 addedField.listBox = this;
1170 fields.Add(addedField);
1172 addedField.sortOrder = 1;
1173 addedField.index = numFields;
1177 addedField.headButton.Destroy(0);
1178 delete addedField.headButton;
1179 addedField.headButton = Button
1184 dontScrollVert = true;
1185 id = (int64)(intptr)addedField;
1186 text = addedField.header;
1187 bevel = (!guiApp.textMode && !style.clearHeader);
1189 alignment = addedField.alignment;
1190 NotifyPushed = HeaderPushed;
1191 NotifyClicked = HeaderClicked;
1192 NotifyDoubleClick = HeaderDoubleClicked;
1193 NotifyReleased = HeaderReleased;
1194 NotifyMouseMove = HeaderMouseMove;
1196 incref addedField.headButton;
1197 addedField.headButton.Create();
1200 addedField.headButton.background = Color { 0, 170, 0 };
1206 for(row = rows.first; row; )
1208 int size = (field.dataType && field.dataType.typeSize) ?
1209 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1210 ListBoxCell cell = (ListBoxCell)new0 byte[size];
1211 row.cells.Add(cell);
1212 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
1215 if(row.subRows.first)
1216 row = row.subRows.first;
1219 for(; row; row = row.parent)
1221 if(row.next) { row = row.next; break; }
1226 OnResize(clientSize.w, clientSize.h);
1235 Clear(); // Ensure data is cleared first
1236 while((field = fields.first))
1241 endBevel.visible = false;
1246 void RemoveField(DataField field)
1252 int index = field.index;
1255 if(sortField == field)
1258 for(row = rows.first; row; )
1263 for(cell = row.cells.first, c = 0; c < index && cell; c++, cell = cell.next);
1264 if(cell && index == c)
1268 // TOCHECK: Is this check good? Will need incref/decref sometime?
1269 if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
1271 if(cell.data[0] && field.freeData)
1272 ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data[0]);
1275 ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data);
1278 row.cells.Remove(cell);
1282 if(row.subRows.first)
1283 row = row.subRows.first;
1286 for(; row; row = row.parent)
1288 if(row.next) { row = row.next; break; }
1297 endBevel.visible = false;
1301 DataRow AddRowNone()
1303 DataRow row { noneRow = true };
1310 rows.Insert(null, row);
1313 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1319 firstRowShown = row;
1323 (rowCount * rowHeight) +
1324 ((style.header) ? rowHeight : 0) -
1325 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1326 if(style.autoScroll)
1327 SetScrollPosition(0, MAXINT - rowHeight);
1328 modifiedDocument = true;
1347 // Find very last row
1350 for(lastRow = rows.last; lastRow && !lastRow.collapsed && lastRow.subRows.last; lastRow = lastRow.subRows.last);
1351 row.index = lastRow ? (lastRow.index + 1) : 0;
1359 for(c = 0; c<fields.count; c++)
1361 for(field = fields.first; field; field = field.next)
1362 if((int)field.index == c)
1366 int size = (field.dataType && field.dataType.typeSize) ?
1367 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1368 ListBoxCell cell = (ListBoxCell) new0 byte[size];
1369 row.cells.Add(cell);
1370 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
1377 firstRowShown = row;
1383 (rowCount * rowHeight) +
1384 ((style.header) ? rowHeight : 0) -
1385 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1386 if(style.autoScroll)
1387 SetScrollPosition(0, MAXINT - rowHeight);
1388 modifiedDocument = true;
1399 DataRow AddRowAfter(DataRow after)
1411 if(after && after.subRows.first && !after.collapsed)
1413 for(search = after.subRows.last; !search.collapsed && search.subRows.last; )
1414 search = search.subRows.last;
1415 row.index = search.index + 1;
1418 row.index = after ? (after.index + 1) : 0;
1419 rows.Insert(after, row);
1422 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1427 for(c = 0; c<fields.count; c++)
1429 for(field = fields.first; field; field = field.next)
1430 if((int)field.index == c)
1434 int size = (field.dataType && field.dataType.typeSize) ?
1435 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1436 ListBoxCell cell = (ListBoxCell) new0 byte[size];
1437 row.cells.Add(cell);
1438 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
1442 if(!firstRowShown || !after)
1444 firstRowShown = row;
1449 (rowCount * rowHeight) +
1450 ((style.header) ? rowHeight : 0) -
1451 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1452 if(style.autoScroll)
1453 SetScrollPosition(0, MAXINT - rowHeight);
1454 modifiedDocument = true;
1464 DataRow AddStringf(const char * format, ...)
1470 char string[MAX_F_STRING];
1473 va_start(args, format);
1474 vsnprintf(string, sizeof(string), format ? format : "", args);
1475 string[sizeof(string)-1] = 0;
1479 row.SetData(fields.first, string);
1485 DataRow AddString(const char * string)
1491 row.SetData(fields.first, string);
1497 void SelectRow(DataRow row)
1499 SetCurrentRow(row, true);
1502 void DeleteRow(DataRow row)
1504 if(!row) row = currentRow;
1507 DataRow sub, next, search;
1508 // Trying to move this here (Messed up deleting watches)
1509 //HideEditBox(false, false, true);
1512 for(sub = row.subRows.first; sub; sub = next)
1518 if(row.parent.IsExpanded())
1520 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1525 HideEditBox(false, false, true);
1527 if(row == clickedRow)
1529 clickedRow = row.GetNextRow();
1531 clickedRow = row.GetPrevRow();
1534 if(row == currentRow)
1536 DataRow newCurrentRow = row.GetNextRow();
1538 newCurrentRow = row.GetPrevRow();
1539 SetCurrentRow(newCurrentRow, true);
1542 if(row == firstRowShown)
1544 firstRowShown = row.GetPrevRow();
1546 firstRowShown = row.GetNextRow();
1549 (row.parent ? row.parent.subRows: rows).Remove(row);
1552 //HideEditBox(false, false, true);
1556 (this.rowCount * rowHeight) +
1557 ((style.header) ? rowHeight : 0) -
1558 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1560 modifiedDocument = true;
1569 DataRow FindRow(int64 tag)
1574 for(row = rows.first; row; row = row.next)
1576 if(!row.noneRow && row.tag == tag)
1584 DataRow FindString(const char * searchedString)
1587 bool checkNextField = true;
1589 for(field = fields.first; field; field = field.next)
1591 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1594 for(row = rows.first; row; row = row.GetNextRow())
1598 void * data = row.GetData(field);
1599 char tempString[1024] = "";
1600 bool needClass = false;
1601 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1603 if(string && string[0])
1604 checkNextField = false;
1605 if(string && string[0] && !strcmp(string, searchedString))
1610 if(!checkNextField) break;
1615 DataRow FindSubString(const char * subString)
1618 bool checkNextField = true;
1619 int len = subString ? strlen(subString) : 0;
1623 for(field = fields.first; field; field = field.next)
1625 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1628 for(row = rows.first; row; row = row.GetNextRow())
1632 void * data = row.GetData(field);
1633 char tempString[1024] = "";
1634 bool needClass = false;
1635 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1637 if(string && string[0])
1638 checkNextField = false;
1639 if(string && string[0] && !strncmp(string, subString, len))
1644 if(!checkNextField) break;
1650 DataRow FindSubStringi(const char * subString)
1653 bool checkNextField = true;
1654 int len = subString ? strlen(subString) : 0;
1655 DataRow result = null;
1656 const char * bestResult = null;
1661 for(field = fields.first; field; field = field.next)
1663 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1666 for(row = rows.first; row; row = row.GetNextRow())
1670 void * data = row.GetData(field);
1671 char tempString[1024] = "";
1672 bool needClass = false;
1673 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1675 if(string && string[0])
1676 checkNextField = false;
1677 if(string && string[0])
1679 int stringLen = strlen(string);
1681 if(!strnicmp(string, subString, Min(len, stringLen)))
1683 if(bestLen < Min(len, stringLen))
1685 if(!bestResult || strcmpi(string, bestResult) < 0)
1687 bestLen = Min(len, stringLen);
1688 bestResult = string;
1696 if(!checkNextField) break;
1702 DataRow FindSubStringAfter(DataRow after, const char * subString)
1705 bool checkNextField = true;
1706 int len = subString ? strlen(subString) : 0;
1710 for(field = fields.first; field; field = field.next)
1712 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1715 for(row = after.GetNextRow(); row && row != after; row = row.GetNextRow(), (!row) ? (row = rows.first) : null)
1719 void * data = row.GetData(field);
1720 char tempString[1024] = "";
1721 bool needClass = false;
1722 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1724 if(string && string[0])
1725 checkNextField = false;
1726 if(string && string[0] && !strncmp(string, subString, len))
1731 if(!checkNextField) break;
1737 DataRow FindSubRow(int64 tag)
1743 for(row = rows.first; row; row = row.next)
1745 if(!row.noneRow && row.tag == tag)
1747 if(!row.noneRow && row.subRows.first)
1749 DataRow subRow = row.FindSubRow(tag);
1763 Window master = this.master;
1765 HideEditBox(false, true, false);
1766 editData.Destroy(0);
1768 firstRowShown = currentRow = null;
1773 if(style.freeSelect)
1774 NotifyHighlight(master, this, currentRow ? currentRow : null, 0);
1776 NotifySelect(master, this, currentRow ? currentRow : null, 0);
1779 if(style.alwaysEdit && currentRow)
1780 currentRow.Edit(currentField);
1787 (this.rowCount * rowHeight) +
1788 ((style.header) ? rowHeight : 0) -
1789 ((rowHeight && !((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1794 void Sort(DataField field, int order)
1799 int headerSize = ((style.header) ? rowHeight : 0);
1800 int height = clientSize.h + 1 - headerSize;
1802 if(!field) field = fields.first;
1804 field.sortOrder = order ? order : 1;
1805 rows.Sort(DataRow::Compare, field);
1807 for(search = rows.first; search; search = search.next)
1808 search._SortSubRows(field, order);
1812 for(search = rows.first; search; search = search.GetNextRow())
1813 search.index = index++;
1816 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
1817 SetScrollPosition(scroll.x, currentRow.index * rowHeight - height + rowHeight);
1818 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
1819 SetScrollPosition(scroll.x, currentRow ? currentRow.index * rowHeight : 0);
1821 OnVScroll(0, scroll.y, 0);
1823 // SetScrollPosition(0, scroll.y);
1828 void StopEditing(bool save)
1830 HideEditBox(save, false, true);
1833 void GetMultiSelection(OldList list)
1836 if(this && style.multiSelect)
1840 for(row = rows.first; row; row = row.GetNextRow())
1842 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
1844 list.Add(OldLink { data = row });
1850 // Convenience Current Row Methods
1851 void * SetData(DataField field, any_object data)
1853 return currentRow.SetData(field, data);
1856 any_object GetData(DataField field)
1858 return (void *)currentRow.GetData(field);
1863 return currentRow ? currentRow.tag : 0;
1869 DataField defaultField { };
1870 rows.offset = (uint)(uintptr)&((DataRow)0).prev;
1871 fields.offset = (uint)(uintptr)&((DataField)0).prev;
1872 style.fullRowSelect = true;
1873 style.fillLastField = true;
1874 style.expandOnAdd = true;
1875 typingTimeOut = 0.5;
1876 rowHeight = 16; // Stuff depending on creation and default property checking
1879 defaultField.defaultField = true;
1881 AddField(defaultField);
1883 typedString = new char[1];
1884 typedString[0] = '\0';
1899 while((field = fields.first))
1901 // fields.Remove(field);
1911 while((row = rows.first))
1918 ListBoxCell GetCell(DataRow * row, DataField * field)
1920 ListBoxCell cell = null;
1921 if(!*row) *row = currentRow;
1924 if(!*field) *field = this ? currentField : null;
1927 for(*field = fields.first; (*field).index != 0; *field = (*field).next);
1932 if(field->listBox == this)
1934 for(index = 0, cell = (*row).cells.first; cell && index != (*field).index; index++, cell = cell.next);
1941 void HideEditBox(bool save, bool alwaysStopEdit, bool repositionOnly)
1943 if(editData && editData.visible)
1946 editData.SaveData();
1948 editData.visible = false;
1949 NotifyEditDone(master, this, currentRow);
1951 // ENSURE DATA BOX IS NOT VISIBLE
1952 editData.visible = false;
1954 if(style.alwaysEdit && !alwaysStopEdit)
1957 int height = rowHeight - (style.alwaysEdit ? 1 : 0);
1958 int y = currentRow.index * rowHeight + (style.header ? rowHeight : 0);
1959 int x = currentField.x;
1960 int width = (!currentField.next && style.fillLastField && (!hasHorzScroll || clientSize.w - currentField.x > currentField.width + EXTRA_SPACE)) ?
1961 clientSize.w - currentField.x : (currentField.width + EXTRA_SPACE);
1963 if(!style.alwaysEdit)
1965 editData.position = { x, y };
1966 editData.size = { width, height };
1970 editData.position = { x, y - editData.clientStart.y };
1971 editData.size = { width, height + editData.clientStart.y * 2 };
1973 editData.visible = true;
1974 if(style.alwaysEdit)
1975 editData.Deactivate();
1977 PopupEditBox(currentField, repositionOnly);
1981 currentField = null;*/
1985 void SetCurrentRow(DataRow row, bool notify)
1987 if(this && (currentRow != row || (currentRow && currentRow.selectedFlag == unselected)))
1989 int headerSize = ((style.header) ? rowHeight : 0);
1990 int height = clientSize.h + 1 - headerSize;
1992 // true: destroy edit box
1993 HideEditBox(true, true, false);
1995 if(!(style.multiSelect) && currentRow)
1996 currentRow.selectedFlag = unselected;
2000 if(style.multiSelect)
2004 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
2005 selRow.selectedFlag = unselected;
2007 currentRow.selectedFlag = selected;
2012 currentRow.selectedFlag = selected;
2014 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
2015 SetScrollPosition(scroll.x,
2016 currentRow.index * rowHeight - height + rowHeight);
2017 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
2019 int line = currentRow ? currentRow.index * rowHeight : 0;
2020 //SNAPUP(line, rowHeight);
2021 SetScrollPosition(scroll.x, line);
2026 Window master = this.master;
2029 if(style.freeSelect && visible)
2030 NotifyHighlight(master, this, currentRow ? currentRow : null, 0);
2032 NotifySelect(master, this, currentRow ? currentRow : null, 0);
2033 if(style.alwaysEdit && currentRow)
2034 currentRow.Edit(currentField);
2042 void RepositionFieldEditor()
2044 if(editData && editData.visible)
2046 int height = rowHeight - (style.alwaysEdit ? 1 : 0);
2048 int y = currentRow.index * rowHeight + (style.header ? rowHeight : 0);
2052 if(style.collapse && !(style.treeBranch))
2054 for(field = fields.first; field; field = field.next)
2056 width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2057 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2058 if(field == currentField) break;
2061 if(!style.alwaysEdit)
2063 editData.position = { x, y - editData.clientStart.y };
2064 editData.size = { width, height + editData.clientStart.y * 2 };
2068 editData.position = { x, y };
2069 editData.size = { width, height };
2074 void PopupEditBox(DataField whichField, bool repositionOnly)
2076 if((!editData || !editData.visible || currentField != whichField) && currentRow)
2078 // true: destroy edit box
2079 HideEditBox(true, true, false);
2082 int height = rowHeight - (style.alwaysEdit ? 1 : 0);
2084 int y = currentRow.index * rowHeight + (style.header ? rowHeight : 0);
2086 //void * data = currentRow.GetData(whichField);
2091 if(style.collapse && !(style.treeBranch))
2094 for(field = fields.first; field; field = field.next)
2096 width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2097 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2098 if(field == whichField) break;
2102 currentField = whichField;
2103 cell = GetCell(&row, ¤tField);
2110 background = dataBoxBackground;
2111 foreground = dataBoxForeground;
2113 bool NotifyChanged(DataBox dataBox, bool closingDropDown)
2116 DataField field = null;
2117 ListBoxCell cell = GetCell(&row, &field);
2121 modifiedDocument = true;
2123 NotifyChanged(master, this, currentRow);
2128 bool NotifyModified()
2130 //DataRow row = null;
2131 //DataField field = null;
2132 //ListBoxCell cell = GetCell(&row, &field);
2133 //cell.isSet = true;
2134 modifiedDocument = true;
2136 NotifyModified(master, this, currentRow);
2140 bool OnKeyDown(Key key, unichar ch)
2142 bool result = DataBox::OnKeyDown(key, ch);
2143 if(visible && active) // Added this check here, because we will not use enter/escape otherwise, and lose DataBox's result
2145 if((SmartKey)key == enter || (SmartKey)key == escape)
2154 editData.Destroy(0);
2155 editData.type = whichField.dataType;
2156 editData.fieldData = whichField.userData;
2157 editData.borderStyle = style.alwaysEdit ? 0 : deep;
2158 editData.data = cell ? cell.data : null;
2161 // Might not really need this anymore...
2162 NotifyEditing(master, this, currentRow);
2165 if(!style.alwaysEdit)
2167 editData.position = { x, y - editData.clientStart.y };
2168 editData.size = { width, height + editData.clientStart.y * 2 };
2172 editData.position = { x, y };
2173 editData.size = { width, height };
2177 editData.visible = true;
2179 if(style.alwaysEdit)
2180 editData.Deactivate();
2182 // MOVED THIS HIGHER FOR DATALIST EDITOR
2184 // Might not really need this anymore...
2185 NotifyEdited(master, this, currentRow);
2190 void OnRedraw(Surface surface)
2193 int y = (style.header) ? rowHeight : 0;
2194 bool isActive = active;
2195 Font font = fontObject;
2196 Font boldFont = this.boldFont.font;
2200 if(style.alwaysEdit && style.fullRowSelect)
2203 int y = (style.header) ? rowHeight : 0;
2204 int x = -scroll.x - 1;// + EXTRA_SPACE;// / 2 - 1;
2205 int w = clientSize.w;
2206 int h = clientSize.h;
2210 // Fill out indent column
2211 if(style.collapse && !(style.treeBranch) && (style.header || rows.first))
2214 surface.SetBackground(formColor);
2215 surface.Area(-scroll.x, 0, x, clientSize.h);
2218 surface.SetForeground(formColor);
2219 for(row = firstRowShown; row; row = row.GetNextRow())
2222 surface.HLine(x + 1, w-1, y-1);
2228 for(field = fields.first; field; field = field.next)
2230 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2231 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2232 if(field.prev && y > 0)
2233 surface.VLine(0, y-1, x);
2238 surface.foreground = this.foreground;
2239 surface.TextOpacity(false);
2241 // Draw the tree branches
2242 if(style.treeBranch)
2244 int y = -scroll.y + ((style.header) ? rowHeight : 0);
2245 surface.LineStipple(0x5555);
2246 surface.SetForeground(branchesColor);
2247 for(row = rows.first; row; row = row.GetNextRow() )
2249 int x = -scroll.x + EXTRA_SPACE / 2-1;
2250 int rowStart = -scroll.x;
2255 for(parent = row.parent; parent; parent = parent.parent)
2256 if(!parent.header) indent += 20;
2257 if(style.rootCollapse) indent += 20;
2259 plusIndent = (style.treeBranch) ? (indent - 20 + 4) : indent;
2264 if(row.subRows.first)
2267 int y1 = y + PLUSY + 4;
2271 for(child = row.collapsed ? null : row.subRows.first; child && child != row; )
2274 if(child.subRows.first && !child.collapsed && child != row.subRows.last)
2275 child = child.subRows.first;
2280 for(; child && child != row; child = child.parent)
2290 y2 = y + numRows * rowHeight + PLUSY + 4;
2291 surface.VLine(y1, y2, rowStart + plusIndent + 7 + 20);
2293 surface.HLine(rowStart + plusIndent + 7, rowStart + indent, y + PLUSY + 4);
2296 if(y >= clientSize.h)
2299 // Root Vertical Lines
2300 if(style.rootCollapse && rows.first)
2305 y = -scroll.y + ((style.header) ? rowHeight : 0);
2307 for(child = rows.first; child && child != rows.last; )
2310 if(child.subRows.first && !child.collapsed && child != rows.last)
2311 child = child.subRows.first;
2316 for(; child; child = child.parent)
2326 y2 = y + numRows * rowHeight + PLUSY + 4;
2327 surface.VLine(y1, y2, -scroll.x + 11);
2329 surface.LineStipple(0);
2332 for(row = firstRowShown; row; row = row.GetNextRow() )
2334 int x = -scroll.x + EXTRA_SPACE / 2-1;
2337 Color foreground = this.foreground /*black*/, background = this.background /*white*/;
2338 DataDisplayFlags dataDisplayFlags = 0;
2339 int rowStart = -scroll.x;
2342 Bitmap icon = row.icon ? row.icon.bitmap : null;
2343 int collapseRowStart = 0;
2344 bool lastWasHeader = row.header;
2346 for(parent = row.parent; parent; parent = parent.parent)
2348 if(!parent.header || lastWasHeader)
2350 if(style.treeBranch)
2356 if(style.rootCollapse) indent += 20;
2359 dataDisplayFlags.fullRow = style.fullRowSelect;
2360 dataDisplayFlags.active = isActive;
2361 dataDisplayFlags.header = row.header;
2366 collapseRowStart = rowStart;
2368 if(!(style.treeBranch))
2375 if(style.multiSelect)
2377 dataDisplayFlags.selected = row.selectedFlag == selected || row.selectedFlag == tempSelected;
2378 dataDisplayFlags.current = row == currentRow || (!currentRow && row == firstRowShown);
2382 dataDisplayFlags.selected = row.selectedFlag == selected || row.selectedFlag == tempSelected;
2383 dataDisplayFlags.current = row == currentRow || (!currentRow && row == firstRowShown);
2385 if(row == currentRow)
2387 dataDisplayFlags.current = true;
2388 dataDisplayFlags.selectedFlag = true;
2390 else if(!currentRow && row == firstRowShown)
2392 dataDisplayFlags.current = true;
2396 surface.TextOpacity(true);
2398 background = this.background;
2399 foreground = this.foreground;
2401 // Draw the current row background
2404 Color colors[] = { formColor, azure, mistyRose, linen, floralWhite, lavender, lavenderBlush, lemonChiffon };
2407 while((p = p.parent)) level++;
2408 background = colors[level % (sizeof(colors)/sizeof(colors[0]))];
2409 surface.SetBackground(background);
2410 surface.Area(rowStart, y, clientSize.w, (y + rowHeight) - 1);
2411 foreground = branchesColor;
2413 else if(dataDisplayFlags.selected)
2415 if(dataDisplayFlags.selected && (isActive || style.alwaysHL || (style.alwaysEdit && style.fullRowSelect)))
2417 if(!isActive && style.alwaysEdit)
2418 background = formColor;
2420 background = selectionColor ? selectionColor : SELECTION_COLOR;
2421 if(style.fullRowSelect)
2423 int offset = (style.alwaysEdit) ? 2 : 1;
2424 surface.SetBackground(background);
2425 surface.Area(rowStart, y, clientSize.w, (y + rowHeight) - offset);
2427 if(isActive || !(style.alwaysEdit))
2428 foreground = selectionText ? selectionText : SELECTION_TEXT;
2430 foreground = branchesColor;
2436 surface.Blit(icon, x + (20 - icon.width) /2,y + 2,0,0, icon.width, icon.height);
2442 int width = clientSize.w;
2444 dataDisplayFlags.firstField = true;
2445 clip.left = x - EXTRA_SPACE / 2+1;
2447 clip.right = x + width - EXTRA_SPACE/2 - 0;
2448 clip.bottom = y + rowHeight - 1;
2449 surface.Clip(&clip);
2451 surface.TextFont(font);
2453 surface.SetForeground(foreground);
2454 surface.SetBackground(background);
2456 ((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);
2460 if(opacity < 1) surface.TextOpacity(false);
2462 for(field = fields.first; field; field = field.next)
2465 int width = ((!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) || row.header) ?
2466 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2468 // Box clip = { x, y+1, x + field.width - EXTRA_SPACE - 1, y + rowHeight - 2 };
2471 //width -= EXTRA_SPACE;
2473 if(!field.prev) width -= indent;
2476 dataDisplayFlags.firstField = field.prev ? false : true;
2478 if(!dataDisplayFlags.firstField && !dataDisplayFlags.fullRow)
2480 background = this.background;
2481 foreground = this.foreground;
2484 if(!isActive && dataDisplayFlags.selected && style.alwaysEdit && field.editable && opacity)
2487 surface.SetBackground(background);
2488 surface.Area(x-3, y, x+width-1, y + rowHeight-2);
2491 clip.left = x - EXTRA_SPACE / 2+1;
2493 clip.right = x + width - EXTRA_SPACE/2 - 0;
2494 clip.bottom = y + rowHeight - 1;
2495 surface.Clip(&clip);
2497 for(index = 0, cell = row.cells.first; cell && index != field.index; index++, cell = cell.next);
2498 // Should always be as many cells in the row as fields in the listbox
2499 if(cell && cell.isSet && field.dataType)
2502 surface.TextFont(boldFont);
2504 surface.TextFont(font);
2506 surface.SetForeground(foreground);
2507 surface.SetBackground(background);
2509 if(field.dataType.type == noHeadClass || field.dataType.type == normalClass)
2510 ((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);
2512 ((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);
2515 if(!isActive && dataDisplayFlags.selected && style.alwaysEdit && field.editable)
2516 background = formColor;
2518 if(!dataDisplayFlags.firstField && !dataDisplayFlags.fullRow)
2520 background = formColor;
2521 foreground = this.background;
2525 // surface.WriteTextf(x + 100, y, "ix: %d", row.index);
2528 x += width;// + EXTRA_SPACE;
2530 if(row.header) break;
2536 int plusIndent = (style.treeBranch) ? (indent - 20 + 4) : indent;
2538 if(row.subRows.first && (row.parent || !(style.treeBranch) || (style.rootCollapse)))
2540 surface.SetForeground(row.header ? headerCollapseForeground : this.foreground);
2541 surface.Rectangle(collapseRowStart + 3 + plusIndent, y + PLUSY, collapseRowStart + 11 + plusIndent, y + PLUSY + 8);
2543 surface.SetBackground(row.header ? (formColor) : (this.background)); //white
2544 surface.Area(collapseRowStart + 4 + plusIndent, y + PLUSY + 1, collapseRowStart + 10 + plusIndent, y + PLUSY + 7);
2546 surface.HLine(collapseRowStart + 5 + plusIndent, collapseRowStart + 9 + plusIndent, y+PLUSY+4);
2548 surface.VLine(y + PLUSY + 2, y + PLUSY + 6, collapseRowStart + 7 + plusIndent);
2553 // Draw the current row stipple
2554 if(style.fullRowSelect && !(style.alwaysEdit) && (dataDisplayFlags.current) && isActive)
2559 surface.LineStipple(0x5555);
2560 if(dataDisplayFlags.selected)
2561 surface.SetForeground(stippleColor);
2563 surface.SetForeground(this.foreground);
2566 surface.SetForeground(selectionColor ? selectionColor : SELECTION_COLOR);
2567 surface.Rectangle(0, y, clientSize.w-1, (y + rowHeight) - 1);
2568 surface.LineStipple(0);
2572 if(y >= clientSize.h)
2575 if(firstRowShown) surface.Clip(null);
2576 if(this.dragRow && this.dropIndex != -1)
2578 int dropIndex = this.dropIndex;
2581 if(!style.multiSelect && currentRow.index < this.dropIndex)
2583 surface.DrawingChar(223);
2585 y = style.header ? rowHeight : 0;
2586 y += dropIndex * rowHeight - scroll.y;
2588 surface.SetForeground(Color { 85, 85, 255 });
2589 surface.HLine(0, clientSize.w-1, y);
2590 surface.HLine(0, clientSize.w-1, y + 1);
2594 void OnDrawOverChildren(Surface surface)
2596 if(draggingField && this.dropField)
2598 int position = this.dropField.x;
2599 if(draggingField.x < position)
2600 position += this.dropField.width + EXTRA_SPACE;
2602 surface.SetForeground(Color { 85, 85, 255 });
2603 surface.VLine(0, rowHeight - 1, position - scroll.x - 2);
2604 surface.VLine(0, rowHeight - 1, position - scroll.x);
2606 if(sortField && !style.clearHeader && style.header)
2608 DataField field = sortField;
2609 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2610 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2613 surface.TextExtent(field.header, strlen(field.header), &tw, &th);
2614 if(tw < width - EXTRA_SPACE)
2616 bool up = field.sortOrder == 1;
2620 field.x + 2 - scroll.x, 0,
2621 field.x + width + EXTRA_SPACE - 1 - scroll.x, rowHeight
2623 surface.Clip(&clip);
2624 if(field.alignment == left || field.alignment == center)
2626 if(field.alignment == center)
2627 x = field.x + (width + EXTRA_SPACE - tw) / 2 + tw + EXTRA_SPACE + 4;
2629 x = field.x + tw + EXTRA_SPACE + 4;
2631 x = Min(x, field.x + width - 4);
2633 else if(field.alignment == right)
2635 x = field.x + width - tw - 2*EXTRA_SPACE - 4;
2636 x = Max(x, field.x + 2);
2642 // surface.SetForeground((wmenu.selectedFlag == item) ? white : black);
2643 // surface.WriteText(clientSize.w-8, y+(wmenu.rh - 8)/2, "\020", 1);
2649 surface.SetForeground(Color { 128,128,128 } );
2650 surface.DrawLine(x + 3, y, x, y + 5);
2651 surface.PutPixel(x + 1, y + 5);
2652 surface.PutPixel(x + 1, y + 3);
2653 surface.PutPixel(x + 2, y + 1);
2655 surface.SetForeground(white);
2656 surface.DrawLine(x + 4, y, x + 7, y + 5);
2657 surface.PutPixel(x + 6, y + 5);
2658 surface.PutPixel(x + 6, y + 3);
2659 surface.PutPixel(x + 5, y + 1);
2661 surface.DrawLine(x, y + 6, x + 7, y + 6);
2665 surface.SetForeground(Color { 128,128,128 });
2666 surface.DrawLine(x + 3, y+6, x, y+1);
2667 surface.PutPixel(x + 1, y+1);
2668 surface.PutPixel(x + 1, y+3);
2669 surface.PutPixel(x + 2, y+5);
2671 surface.SetForeground(white);
2672 surface.DrawLine(x + 4, y+6, x + 7, y+1);
2673 surface.PutPixel(x + 6, y+1);
2674 surface.PutPixel(x + 6, y+3);
2675 surface.PutPixel(x + 5, y+5);
2677 surface.DrawLine(x, y, x + 7, y);
2686 void OnResize(int w, int h)
2689 bool showEndBevel = false;
2691 if(style.collapse && !style.treeBranch)
2693 for(field = fields.first; field; field = field.next)
2695 int width = field.width + EXTRA_SPACE;
2703 (rowCount * rowHeight) +
2704 ((style.header) ? rowHeight : 0) -
2705 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
2707 for(field = fields.first; field; field = field.next)
2709 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2710 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2711 if(style.header && field.headButton)
2713 showEndBevel = true;
2716 field.headButton.position = { field.x, 0 };
2717 field.headButton.size = { width, rowHeight };
2718 field.headButton.visible = true;
2721 field.headButton.visible = false;
2725 if(!style.fillLastField && showEndBevel && endBevel)
2727 endBevel.position = { x, 0 };
2728 endBevel.size = { clientSize.w + 2 - x, rowHeight };
2729 endBevel.visible = true;
2732 endBevel.visible = false;
2734 if(style.alwaysEdit && editData && editData.visible)
2736 HideEditBox(true, false, true);
2738 else if(editData && editData.visible)
2739 RepositionFieldEditor();
2742 void AdaptToFieldWidth(DataField field, bool doScroll)
2744 OnResize(clientSize.w, clientSize.h);
2746 // Scroll appropriately
2749 if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x &&
2750 field.x >= field.x + field.width + EXTRA_SPACE - clientSize.w)
2752 SetScrollPosition(field.x + field.width + EXTRA_SPACE - clientSize.w, scroll.y);
2754 else if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x ||
2756 SetScrollPosition(field.x, scroll.y);
2761 bool HeaderPushed(Button control, int x, int y, Modifiers mods)
2763 DataField field = (DataField)(intptr)control.id;
2764 // false: dont destroy edit box
2765 HideEditBox(true, false, true);
2766 if(style.resizable && ((!field && x < RESIZE_BORDER && fields.last) ||
2767 (field && x < RESIZE_BORDER && field.prev) ||
2768 (field && x >= control.clientSize.w - RESIZE_BORDER)))
2771 field = fields.last;
2772 else if(x < RESIZE_BORDER && field.prev)
2775 if(field.fixed) return false;
2776 resizingField = field;
2777 this.resizeX = x + control.position.x;
2778 this.startWidth = field.width;
2779 this.oldX = x - scroll.x;
2784 if(field.fixed) return false;
2785 draggingField = field;
2786 if(style.moveFields)
2787 field.headButton.stayDown = true;
2788 else if(!style.sortable)
2796 bool HeaderMouseMove(Button control, int x, int y, Modifiers mods)
2801 DataField field = resizingField;
2803 x += control.position.x;
2805 // Tweak to prevent shrinking field if we're actually moving right
2806 if(x - scroll.x > this.oldX &&
2807 this.startWidth + x - this.resizeX < field.width)
2809 this.oldX = x - scroll.x;
2812 this.oldX = x - scroll.x;
2814 field.width = this.startWidth + x - this.resizeX;
2815 field.width = Max(field.width, - EXTRA_SPACE);
2817 AdaptToFieldWidth(field, true);
2819 else if(draggingField)
2821 x += control.position.x;
2822 if(style.moveFields)
2824 DataField field = fields.last;
2826 for(field = fields.first; field; field = field.next)
2828 fieldX += ((field.width || style.resizable) ?
2829 field.width : clientSize.w) + EXTRA_SPACE;
2833 if(draggingField == field)
2835 // Reset scroll position
2836 if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x &&
2837 field.x >= field.x + field.width + EXTRA_SPACE - clientSize.w)
2840 field.x + field.width + EXTRA_SPACE - clientSize.w,
2843 else if(field.x + field.width + EXTRA_SPACE - clientSize.w > scroll.x ||
2845 SetScrollPosition(field.x, scroll.y);
2848 if(this.dropField != field)
2850 this.dropField = field;
2853 int position = field.x;
2855 if(draggingField.x < position)
2857 position += field.width + EXTRA_SPACE - clientSize.w;
2858 if(position > scroll.x)
2859 SetScrollPosition(position, scroll.y);
2864 if(position < scroll.x)
2865 SetScrollPosition(position, scroll.y);
2868 this.movingFields = true;
2874 else if(style.resizable)
2876 DataField field = (DataField)(intptr)control.id;
2879 if(x < RESIZE_BORDER && field.prev)
2881 if(!field.prev.fixed)
2882 control.cursor = guiApp.GetCursor(sizeWE);
2884 else if(x >= control.clientSize.w - RESIZE_BORDER)
2885 control.cursor = guiApp.GetCursor(sizeWE);
2887 control.cursor = null;
2891 if(x < RESIZE_BORDER && fields.last)
2892 control.cursor = guiApp.GetCursor(sizeWE);
2894 control.cursor = null;
2900 bool HeaderReleased(Button control, int x, int y, Modifiers mods)
2904 NotifyResized(master, this, resizingField, mods);
2905 resizingField = null;
2912 if(style.moveFields)
2917 DataField switchField = fields.last;
2921 x += draggingField.x;
2922 for(field = fields.first; field; field = field.next)
2924 fieldX += ((field.width || style.resizable) ?
2925 field.width : clientSize.w) + EXTRA_SPACE;
2928 switchField = field;
2932 if(switchField && draggingField != switchField && this.dropField)
2934 for(field = fields.first; field; field = field.next)
2936 if(field == switchField || field == draggingField)
2940 // Switch field first: move before
2941 if(field == switchField)
2942 draggingField.Move(switchField.prev);
2943 // Dragged field first: move after
2945 draggingField.Move(switchField);
2947 NotifyMovedField(master, this, draggingField, mods);
2949 draggingField.headButton.stayDown = false;
2954 movingFields = false;
2956 draggingField = null;
2962 bool HeaderClicked(Button control, int x, int y, Modifiers mods)
2964 if(style.header && !this.dropField && style.sortable)
2966 DataField field = (DataField)(intptr)control.id;
2967 if(sortField == field)
2968 field.sortOrder *= -1;
2973 Sort(sortField, field.sortOrder);
2974 NotifySort(master, this, field, mods);
2980 bool HeaderDoubleClicked(Button control, int x, int y, Modifiers mods)
2984 DataField field = (DataField)(intptr)control.id;
2987 if(x < RESIZE_BORDER && field.prev)
2989 else if(x >= control.clientSize.w - RESIZE_BORDER);
2995 if(x < RESIZE_BORDER && fields.last)
2996 field = fields.last;
3008 if(style.freeSelect)
3013 this.rolledOver = this.dragging = false;
3020 bool OnLoadGraphics()
3022 display.FontExtent(fontObject, "W", 1, null, &fontH);
3023 if(!style.heightSet)
3025 rowHeight = Max(fontH + 2, 16) + (style.alwaysEdit ? 1 : 0);
3026 SetScrollLineStep(8, rowHeight);
3031 void OnApplyGraphics()
3033 SetScrollLineStep(8, rowHeight);
3037 for(field = fields.first; field; field = field.next)
3039 if(field.headButton)
3041 field.headButton.bevel = (!guiApp.textMode && !style.clearHeader);
3043 field.headButton.background = Color { 0, 170, 0 };
3047 OnResize(clientSize.w, clientSize.h);
3050 bool OnResizing(int *w, int *h)
3054 if(!initSize.w && (!anchor.left.type || !anchor.right.type) && !*w)
3059 Font font = fontObject;
3060 Font boldFont = this.boldFont.font;
3061 Display display = this.display;
3063 for(row = rows.first; row; row = row.GetNextRow())
3065 Bitmap icon = row.icon ? row.icon.bitmap : null;
3066 int x = -scroll.x + EXTRA_SPACE / 2-1;
3070 for(parent = row.parent; parent; parent = parent.parent)
3074 if(style.treeBranch)
3080 if(style.rootCollapse) indent += 20;
3082 if(style.collapse && !(style.treeBranch)) x += 15;
3086 // Compute the rows size
3087 for(field = fields.first; field; field = field.next)
3089 if(((style.resizable && (!(style.alwaysEdit) || field.next)) || field.width) && !row.header)
3090 x += field.width - (field.prev ? 0 : indent);
3095 for(index = 0, cell = row.cells.first; index != field.index; index++, cell = cell.next);
3097 // Should always be as many cells in the row as fields in the listbox
3098 if(cell && cell.isSet && field.dataType)
3100 static char tempString[4096];
3101 const char * string;
3103 if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
3104 string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, cell.data[0], tempString, field.userData, null);
3106 string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, cell.data, tempString, field.userData, null);
3108 if(!string) string = "";
3109 display.FontExtent(row.header ? boldFont : font, string, strlen(string), &tw, &th);
3112 display.FontExtent(row.header ? boldFont : font, string, strlen(string), &tw, &th);
3114 display.FontExtent(row.header ? boldFont : font, "", 0, &tw, &th);
3117 if(row.header) break;
3121 maxWidth = Max(maxWidth, x);
3127 *h = Min(this.maxShown, this.rowCount) * rowHeight;
3132 if(!*w) *w = rowHeight * 5;
3133 if(!*h) *h = rowHeight * 5;
3140 FontResource font = this.font;
3141 FontResource boldFont
3143 faceName = font.faceName, size = font.size, bold = true
3145 AddResource(boldFont);
3146 RemoveResource(this.boldFont);
3147 this.boldFont = boldFont;
3151 SetInitSize(initSize);
3154 bool OnMouseMove(int x, int y, Modifiers mods)
3156 bool isTimer = false;
3157 int realX = x, realY = y;
3159 if(insideNotifySelect) return true;
3161 if(style.alwaysEdit && style.resizable &&
3162 resizingField && !(mods.isSideEffect))
3165 DataField field = resizingField;
3166 field.width = this.startWidth + x - this.resizeX;
3167 field.width = Max(field.width, - EXTRA_SPACE);
3169 AdaptToFieldWidth(field, true);
3173 if(style.alwaysEdit && style.resizable)
3175 int vx = -scroll.x - 1;
3178 if(style.collapse && !(style.treeBranch))
3181 for(field = fields.first; field; field = field.next)
3183 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3184 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3190 cursor = guiApp.GetCursor(sizeWE);
3194 vx += width + EXTRA_SPACE;
3198 if((editData && editData.visible) || (style.alwaysEdit))
3201 if(x == MAXINT && y == MAXINT)
3208 // ADDED THIS CHECK FOR FieldDropBox LEAKS
3209 if(/*!mods.isSideEffect && */(this.rolledOver || !this.dragging))
3211 int rowY = (style.header) ? rowHeight : 0;
3219 ((vertScroll && vertScroll.visible &&
3220 (y < 0 || y >= clientSize.h)) ||
3221 (horzScroll && horzScroll.visible &&
3222 (x < 0 || x >= clientSize.w))))
3227 if(vertScroll && vertScroll.visible &&
3228 (y < 0 || y >= clientSize.h))
3229 vertScroll.Action((y<0)?up:down, 0, 0);
3230 if(horzScroll && horzScroll.visible &&
3231 (x < 0 || x >= clientSize.w))
3232 horzScroll.Action((x<0)?up:down, 0, 0);
3238 // This must be done after the scrolling took place
3239 rowIndex = firstRowShown ? firstRowShown.index : -1;
3241 y = Min(y, clientSize.h-1);
3242 for(row = firstRowShown; row; row = row.GetNextRow(), rowIndex ++)
3251 if(row && currentRow != row)
3253 if(this.dragRow && style.moveRows)
3255 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
3257 else if(style.multiSelect)
3260 for(thisRow = rows.first; thisRow; thisRow = thisRow.GetNextRow())
3261 if((thisRow.selectedFlag == selected || thisRow.selectedFlag == tempSelected) ||
3267 if(this.dropIndex != rowIndex)
3269 this.dropIndex = rowIndex;
3270 this.editRow = null;
3272 this.movedRow = true;
3275 else if((style.freeSelect || this.dragging) && ((realX>= 0 && realY >= 0 && realX< clientSize.w && realY < clientSize.h) || this.rolledOver))
3277 if(!(style.multiSelect))
3279 if(currentRow)currentRow.selectedFlag = unselected;
3280 if(row)row.selectedFlag = selected;
3284 if(style.multiSelect)
3288 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3290 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3291 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3294 if(rowIndex >= clickedRow.index)
3296 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
3298 selRow.selectedFlag = (selRow.selectedFlag == selected) ? tempUnselected : tempSelected;
3305 for(selRow = row; selRow; selRow = selRow.GetNextRow())
3307 selRow.selectedFlag = (selRow.selectedFlag == selected) ? tempUnselected : tempSelected;
3308 if(selRow == clickedRow)
3314 if(style.freeSelect)
3315 NotifyHighlight(master, this, currentRow, mods);
3318 insideNotifySelect = true;
3319 NotifySelect(master, this, currentRow, mods);
3320 insideNotifySelect = false;
3323 if(style.alwaysEdit && currentRow)
3324 currentRow.Edit(currentField);
3331 bool OnMouseOver(int x, int y, Modifiers mods)
3334 this.rolledOver = true;
3338 bool OnActivate(bool active, Window swap, bool * goOnWithActivation, bool direct)
3340 // TOCHECK: WAS THIS MISSING ? CHECK FOR SLOWDOWN
3341 if(!active) Update(null);
3343 if(!active && (!swap || !swap.isModal))
3345 // true: destroy edit box
3346 HideEditBox(true, true, false);
3348 else if(!swap || !swap.isModal)
3350 // Bring back edit box
3351 if(currentRow && style.alwaysEdit)
3353 currentRow.Edit(currentField ? currentField : null);
3357 return true; //NotifyActivate(master, this, active, swap, 0);
3361 bool OnButtonDown(int x, int y, Modifiers mods, bool right)
3364 // Check to see if we're dragging the vertical divider
3365 if(style.alwaysEdit && style.resizable && !right)
3367 int vx = -scroll.x - 1;// + EXTRA_SPACE;// / 2 - 1;
3370 if(style.collapse && !(style.treeBranch))
3373 for(field = fields.first; field; field = field.next)
3375 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3376 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3382 resizingField = field.prev;
3384 this.startWidth = resizingField.width;
3386 SetMouseRangeToClient();
3390 vx += width + EXTRA_SPACE;
3394 if(!(style.freeSelect))
3396 int rowY = (style.header) ? rowHeight : 0;
3398 int rowIndex = firstRowShown ? firstRowShown.index : -1;
3399 DataRow previousRow = currentRow;
3400 DataRow newCurrentRow = null;
3401 bool moveMultiple = false;
3402 int numSelected = 0;
3403 int rowStart = -scroll.x;
3405 if(style.multiSelect)
3412 for(row = rows.first; row; row = row.GetNextRow())
3414 if(row.selectedFlag == tempSelected)
3415 row.selectedFlag = selected;
3416 else if(row.selectedFlag == tempUnselected)
3417 row.selectedFlag = unselected;
3418 if(row.selectedFlag == selected)
3425 for(row = firstRowShown; row; row = row.GetNextRow(), rowIndex ++)
3428 if(rowY > y || (style.multiSelect && !row.GetNextRow()))
3431 if(style.treeBranch)
3434 for(parent = (style.rootCollapse) ? row.parent : (row.parent ? row.parent.parent : null); parent; parent = parent.parent)
3440 /* THIS WAS TOO STRICT:
3441 if(style.collapse && row.subRows.first && (row.parent || !(style.treeBranch) || (style.rootCollapse)) &&
3442 (x >= rowStart + 3 + plusIndent && y >= rowY - rowHeight + PLUSY && x <= rowStart + 11 + plusIndent && y <= rowY - rowHeight + PLUSY + 8))
3444 if(style.collapse &&
3445 (x >= rowStart && y >= rowY - rowHeight && x <= rowStart + 18 + plusIndent && y <= rowY + rowHeight-1))
3447 if(row.subRows.first && (row.parent || !(style.treeBranch) || (style.rootCollapse)) && x >= plusIndent)
3448 row.collapsed = !row.collapsed;
3455 newCurrentRow = row;
3457 if(style.multiSelect)
3459 // Deselect everything if user didn't clicked on a row
3463 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3464 selRow.selectedFlag = unselected;
3466 //this.clickedRowIndex = rowIndex;
3468 else if(style.moveRows && !(mods.shift) &&
3469 (row.selectedFlag == selected || row.selectedFlag == tempSelected) &&
3470 !right && !(mods.isActivate))
3471 moveMultiple = true;
3477 if(row.selectedFlag == tempUnselected || row.selectedFlag == unselected)
3479 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3480 selRow.selectedFlag = unselected;
3481 row.selectedFlag = selected;
3484 //this.clickedRowIndex = rowIndex;
3490 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3491 selRow.selectedFlag = unselected;
3495 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3497 if(selRow != clickedRow)
3499 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3500 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3507 if(rowIndex >= clickedRow.index)
3509 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
3513 if(selRow != clickedRow)
3515 if(selRow.selectedFlag)
3516 selRow.selectedFlag = tempUnselected;
3518 selRow.selectedFlag = tempSelected;
3522 selRow.selectedFlag = selected;
3529 for(selRow = row; selRow; selRow = selRow.GetNextRow())
3533 if(selRow != clickedRow)
3535 if(selRow.selectedFlag)
3536 selRow.selectedFlag = tempUnselected;
3538 selRow.selectedFlag = tempSelected;
3542 selRow.selectedFlag = selected;
3543 if(selRow == clickedRow)
3552 if(row.selectedFlag)
3553 row.selectedFlag = tempUnselected;
3554 else row.selectedFlag = tempSelected;
3557 row.selectedFlag = tempSelected;
3559 //this.clickedRowIndex = rowIndex;
3569 // true: destroy edit box
3572 incref newCurrentRow;
3575 if(currentRow != newCurrentRow)
3576 HideEditBox(true, true, false);
3580 if(newCurrentRow._refCount <= 1)
3581 delete newCurrentRow;
3583 newCurrentRow._refCount--;
3588 if(!(style.multiSelect))
3590 if(currentRow) currentRow.selectedFlag = unselected;
3591 if(newCurrentRow) newCurrentRow.selectedFlag = selected;
3595 if(currentRow != newCurrentRow)
3598 // true: destroy edit box
3601 //incref newCurrentRow;
3602 incref newCurrentRow;
3605 HideEditBox(true, true, false);
3610 int headerSize = ((style.header) ? rowHeight : 0);
3611 int height = clientSize.h + 1 - headerSize;
3613 /*if(newCurrentRow._refCount <= 1)
3614 delete newCurrentRow;
3617 newCurrentRow._refCount--;
3618 //newCurrentRow._refCount--;
3621 currentRow = newCurrentRow;
3623 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
3624 SetScrollPosition(scroll.x,
3625 currentRow.index * rowHeight - height + rowHeight);
3626 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
3628 int line = currentRow ? currentRow.index * rowHeight : 0;
3629 //SNAPUP(line, rowHeight);
3630 SetScrollPosition(scroll.x, line);
3633 // GO THROUGH SetCurrentRow eventually?
3634 // SetCurrentRow(newCurrentRow, true);
3638 if(style.freeSelect)
3639 NotifyHighlight(master, this, currentRow, mods);
3640 else if((moveMultiple || (!(style.multiSelect) && previousRow == currentRow)) &&
3641 newCurrentRow && !(mods.shift))
3645 if(!(mods.isActivate))
3649 this.dragRow = currentRow;
3650 this.dropIndex = -1;
3651 this.movedRow = false;
3653 if(editData && editData.visible && style.alwaysEdit)
3660 if(style.collapse && !style.treeBranch)
3663 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3665 indent += (style.treeBranch) ? 20 : 15;
3668 for(field = fields.first; field; field = field.next)
3670 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3671 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3673 if(!field.prev) width -= indent;
3674 if(x >= sx && x < sx + width)
3678 if(field == currentField)
3679 editData.Deactivate();
3682 currentRow.Edit(field);
3683 editData.Activate();
3686 else if(!(mods.ctrl) && numSelected <= 1)
3687 this.editRow = currentRow;
3689 if(style.noDragging && newCurrentRow)
3690 NotifyReclick(master, this, newCurrentRow, mods);
3694 // If the user clicked exactly on the edited field,
3696 if(editData && editData.visible && newCurrentRow)
3702 if(style.collapse && !(style.treeBranch))
3707 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3709 indent += (style.treeBranch) ? 20 : 15;
3713 for(field = fields.first; field; field = field.next)
3715 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3716 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3717 if(!field.prev) width -= indent;
3718 if(x >= sx && x < sx + width && newCurrentRow)
3723 if(field) //x >= sx && x < sx + width && newCurrentRow)
3725 if(field == currentField)
3726 editData.Activate();
3728 newCurrentRow.Edit(currentField);*/
3730 else if(style.noDragging && newCurrentRow)
3731 NotifyReclick(master, this, newCurrentRow, mods);
3733 else if(style.noDragging && newCurrentRow)
3734 NotifyReclick(master, this, newCurrentRow, mods);
3741 if(result && style.alwaysEdit && currentRow)
3745 DataField field = null;
3750 if(style.collapse && !style.treeBranch)
3753 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3755 indent += (style.treeBranch) ? 20 : 15;
3758 for(field = fields.first; field; field = field.next)
3760 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3761 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3763 if(!field.prev) width -= indent;
3764 if(x >= sx && x < sx + width)
3766 f = currentField = field;
3773 // Moved NotifySelect after setting currentField for the NotifySelect implementation to be aware of which field is now selected (e.g. WatchesView)
3774 result = NotifySelect(master, this, currentRow, mods);
3775 if(result && style.alwaysEdit && currentRow)
3777 // In case the user specifically clicked on a field (f is set), override any change to currentField that NotifySelect could have done
3778 currentRow.Edit(f ? f : currentField);
3780 // If the user clicked exactly on the edited field,
3782 if(editData && editData.visible && newCurrentRow)
3786 editData.Activate();
3788 else if(style.noDragging && newCurrentRow)
3789 NotifyReclick(master, this, newCurrentRow, mods);
3792 else if(style.noDragging && newCurrentRow)
3793 NotifyReclick(master, this, newCurrentRow, mods);
3797 For drop box to capture...
3800 if(x < 0 || y < 0 || x >= clientSize.w || y >= clientSize.h)
3803 master.parent.Activate();
3812 if(!style.noDragging)
3814 this.dragging = true;
3817 if(x >= 0 && y >= 0 && x < clientSize.w && y < clientSize.h)
3818 this.rolledOver = true;
3823 this.dragging = false;
3824 OnLeftButtonUp(x, y, mods);
3829 bool OnLeftButtonDown(int x, int y, Modifiers mods)
3831 return OnButtonDown(x,y, mods, false);
3834 bool OnLeftButtonUp(int x, int y, Modifiers mods)
3836 if(resizingField && style.alwaysEdit)
3838 Window::FreeMouseRange();
3840 resizingField = null;
3843 if(dragRow || editRow)
3845 DataRow row, switchRow = rows.last;
3846 int rowY = (style.header) ? rowHeight : 0;
3847 for(row = firstRowShown; row; row = row.GetNextRow())
3856 if(this.editRow == switchRow && y >= 0)
3861 for(field = fields.first; field; field = field.next)
3863 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3864 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3867 if(fieldX > x + scroll.x)
3871 if(field && field.editable)
3873 // true: destroy edit box
3874 HideEditBox(true, true, false);
3875 PopupEditBox(field, false);
3877 else if(!style.noDragging)
3878 NotifyReclick(master, this, currentRow, mods);
3880 else if(style.moveRows && switchRow)
3882 if(this.dragRow == switchRow && this.movedRow == false)
3884 DataRow row = this.dragRow;
3888 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3889 selRow.selectedFlag = unselected;
3893 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3895 if(selRow != clickedRow)
3897 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3898 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3904 if(row.selectedFlag)
3905 row.selectedFlag = tempUnselected;
3906 else row.selectedFlag = tempSelected;
3909 row.selectedFlag = tempSelected;
3914 if(style.multiSelect)
3916 if(!switchRow.selectedFlag)
3918 bool foundSwitch = false;
3921 DataRow afterRow = switchRow.prev;
3922 for(row = rows.first; row; row = next)
3924 next = row.GetNextRow();
3925 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
3927 if(!foundSwitch && !after)
3930 afterRow = switchRow;
3932 if(!after || !(row.selectedFlag == selected || row.selectedFlag == tempSelected) ||
3939 else if(row == switchRow)
3946 for(row = rows.first; row; row = row.GetNextRow())
3948 if(row == switchRow || row == this.dragRow)
3952 // Switch row first: move before
3953 if(row == switchRow)
3955 DataRow actualMoveRow;
3957 if(!switchRow.prev && switchRow.parent == dragRow.parent)
3958 actualMoveRow = null;
3961 actualMoveRow = switchRow.prev ? switchRow.prev : switchRow;
3962 while(actualMoveRow && actualMoveRow.parent != dragRow.parent && actualMoveRow.parent)
3963 actualMoveRow = actualMoveRow.parent;
3966 if(!actualMoveRow || (actualMoveRow && actualMoveRow.parent == dragRow.parent))
3967 if(NotifyMove(master, this, actualMoveRow, mods))
3969 dragRow.Move(actualMoveRow);
3972 // Dragged row first: move after
3975 DataRow actualMoveRow = switchRow;
3976 DataRow nextRow = switchRow.GetNextRow();
3978 while(nextRow && nextRow.parent != dragRow.parent)
3979 nextRow = nextRow.parent ? nextRow.parent.next : null;
3981 actualMoveRow = nextRow.prev;
3984 actualMoveRow = dragRow.parent ? dragRow.parent.subRows.last : rows.last;
3986 if(!actualMoveRow || (actualMoveRow != dragRow && actualMoveRow.parent == dragRow.parent))
3987 if(NotifyMove(master, this, actualMoveRow, mods))
3989 dragRow.Move(actualMoveRow);
4003 if(this.dragging || style.freeSelect)
4007 this.rolledOver = this.dragging = false;
4009 if(x >= 0 && y >= 0 && x < clientSize.w && y < clientSize.h && currentRow && style.freeSelect)
4013 result = NotifySelect(master, this, currentRow, mods);
4014 if(style.alwaysEdit)
4015 currentRow.Edit(currentField);
4019 // if(!(style.freeSelect))
4025 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
4027 int rowStart = -scroll.x;
4029 int rowY = (style.header) ? rowHeight : 0;
4032 OnLeftButtonUp(x,y,mods);
4033 if(style.alwaysEdit)
4035 if(!(style.collapse) || x > 15)
4036 if(editData && editData.visible)
4038 editData.Activate();
4039 NotifyDoubleClick(master, this, x, y, mods);
4043 for(row = firstRowShown; row; row = row.GetNextRow())
4046 if(rowY > y || (style.multiSelect && !row.GetNextRow()))
4048 if(style.treeBranch)
4051 for(parent = (style.rootCollapse) ? row.parent : (row.parent ? row.parent.parent : null); parent; parent = parent.parent)
4060 if((row && style.collapse && (x >= rowStart && x <= rowStart + 18 + plusIndent)) ||
4061 NotifyDoubleClick(master, this, x, y, mods))
4065 if(row && row.subRows.first)
4067 row.collapsed = !row.collapsed;
4071 // We need to return true here so that OnLeftButtonDown can popup the DataBox Editors
4077 bool OnRightButtonDown(int x, int y, Modifiers mods)
4079 return OnButtonDown(x,y, mods, true);
4082 bool OnRightButtonUp(int x, int y, Modifiers mods)
4084 OnLeftButtonUp(x,y,mods);
4085 return NotifyRightClick(master, this, x, y, mods);
4088 bool GoToLetter(unichar ch, bool keyHit)
4090 bool result = false;
4092 bool checkNextField = true;
4093 int len = keyHit ? 0 : strlen(typedString);
4095 typedString = renew typedString char[len + 2];
4096 typedString[len++] = (char)tolower(ch); // TODO: FIX UNICODE
4097 typedString[len] = '\0';
4099 for(field = fields.first; field; field = field.next)
4101 DataRow startRow = currentRow ? currentRow : rows.first;
4103 if(startRow && field.dataType && field.dataType._vTbl[__ecereVMethodID_class_OnGetString] && ch)
4106 bool looped = false;
4107 if(len == 1 && currentRow)
4108 startRow = (next = startRow.GetNextRow(), (next ? next : rows.first));
4110 for(row = startRow; row != startRow || !looped; next = row.GetNextRow(), row = next ? next : rows.first)
4112 void * data = row.GetData(field);
4113 char tempString[1024] = "";
4114 bool needClass = false;
4115 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;
4117 if(string && string[0])
4118 checkNextField = false;
4119 if(string && string[0] && !strnicmp(string, typedString, len))
4121 if(style.multiSelect)
4126 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
4127 selRow.selectedFlag = unselected;
4128 row.selectedFlag = selected;
4130 SetCurrentRow(row, true);
4137 if(this.typingTimeOut && !keyHit)
4138 typingTimer.Start();
4139 if(!result || !this.typingTimeOut || keyHit)
4140 typedString[len-1] = '\0';
4142 if(!checkNextField || result) break;
4147 bool OnKeyDown(Key key, unichar ch)
4151 if(key == enter || key == keyPadEnter)
4153 if(editData && editData.visible && editData.active)
4155 HideEditBox(true, false, false);
4159 else if(key == escape)
4161 if(resizingField || this.movingFields || (editData && editData.visible) || this.dragRow)
4163 if(editData && editData.visible && style.alwaysEdit && !editData.active)
4165 // false: dont destroy edit box
4166 HideEditBox(false, false, false);
4169 resizingField.width = this.startWidth;
4170 AdaptToFieldWidth(resizingField, true);
4171 resizingField = null;
4174 this.dragRow = null;
4177 this.dragging = false;
4181 this.movingFields = false;
4182 draggingField = null;
4188 if(!currentField || !currentField.editable)
4189 for(field = fields.first; field; field = field.next)
4193 currentField = field;
4197 if((key == f2 || (style.alwaysEdit && (key == ctrlV || key == ctrlC || key == ctrlX || key == shiftInsert || key == ctrlInsert || key == shiftDel))) &&
4198 currentField && currentField.editable)
4200 PopupEditBox(currentField, false);
4201 if(editData && editData.visible)
4203 if(style.alwaysEdit)
4205 editData.Activate();
4206 if(key == ctrlV || key == ctrlC || key == ctrlX || key == shiftInsert || key == ctrlInsert || key == shiftDel)
4208 editData.OnKeyHit(key, ch);
4212 // For Installer to pop up file dialog
4213 NotifyKeyDown(master, this, currentRow, key, ch);
4219 if(!NotifyKeyDown(master, this, currentRow, key, ch))
4222 // Editable fields...
4225 if(style.alwaysEdit && editData && editData.visible)
4226 return editData.OnKeyDown(key, ch);
4227 return true; // We want to pick up the OnKeyHit to replace contents, but skip GoToLetter
4230 if(ch >=32 && ch != 128 && !key.alt && !key.ctrl && GoToLetter(ch, false))
4232 /*if(inactive && window.state != Hidden)
4233 NotifyHighlight(master, this, currentRow, 0);
4236 NotifySelect(master, this, currentRow, 0);
4243 bool OnKeyHit(Key key, unichar ch)
4245 if(!ch && !key.alt && !key.ctrl)
4247 key.code = (SmartKey)key.code;
4249 if(ch >= 32 && !key.alt && !key.ctrl && ch != 128)
4252 if(!currentField || !currentField.editable)
4253 for(field = fields.first; field; field = field.next)
4257 currentField = field;
4261 if(currentField && currentField.editable)
4263 if((!editData || !editData.visible) || !editData.active)
4265 PopupEditBox(currentField, false);
4266 if(editData && editData.visible)
4268 editData.Activate();
4269 editData.OnKeyHit(key, ch);
4276 if(editData && editData.visible && ch && !key.alt && !key.ctrl && editData.active && (key.code != tab || (editData._class == class(EditBox) && ((EditBox)editData).tabKey)))
4279 if(!key.alt && (style.multiSelect || !key.ctrl))
4284 if(style.alwaysEdit)
4289 for(field = currentField.prev; field; field = field.prev)
4293 currentField = field;
4294 HideEditBox(true, true, false);
4295 PopupEditBox(currentField, false);
4301 if(style.collapse && currentRow /*&& !currentField*/) // THIS PREVENTED COLLAPSING THE PROPERTY SHEET
4303 if(currentRow.subRows.first && !currentRow.collapsed)
4305 currentRow.collapsed = true;
4307 else if(currentRow.parent)
4308 SetCurrentRow(currentRow.parent, true);
4313 if(style.collapse && currentRow && currentRow.subRows.first)
4315 if(currentRow.collapsed)
4316 currentRow.collapsed = false;
4318 SetCurrentRow(currentRow.subRows.first, true);
4321 else if(style.alwaysEdit)
4326 for(field = currentField.next; field; field = field.next)
4330 currentField = field;
4331 HideEditBox(true, true, false);
4332 PopupEditBox(currentField, false);
4340 case pageDown: case pageUp:
4341 case end: case home:
4343 int headerSize = ((style.header) ? rowHeight : 0);
4344 int height = clientSize.h + 1 - headerSize;
4347 // true: destroy edit box
4348 // !!! TESTING true HERE !!!
4349 HideEditBox(true, true, false);
4350 // HideEditBox(false, true, false);
4352 oldRow = currentRow;
4354 SNAPDOWN(height, rowHeight);
4355 if((!currentRow || key.code == home) && key.code != end)
4357 currentRow = rows.first;
4365 if(!(style.multiSelect) && currentRow && !currentRow.selectedFlag)
4368 next = currentRow.GetNextRow();
4375 if(!(style.multiSelect) && currentRow && !currentRow.selectedFlag)
4378 next = currentRow.GetPrevRow();
4386 currentRow = lastRow.GetLastRow();
4392 currentRow && (next = currentRow.GetPrevRow()) && c < height / rowHeight;
4393 c++, currentRow = next);
4400 currentRow && (next = currentRow.GetNextRow()) && c < height / rowHeight;
4401 c++, currentRow = next);
4406 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
4407 SetScrollPosition(scroll.x, currentRow.index * rowHeight - height + rowHeight);
4408 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
4409 SetScrollPosition(scroll.x, currentRow ? currentRow.index * rowHeight : 0);
4411 if(style.multiSelect)
4415 if(!(key.shift) && (key.ctrl))
4418 for(row = rows.first; row; row = row.GetNextRow())
4420 if(row.selectedFlag == tempSelected)
4421 row.selectedFlag = selected;
4422 else if(row.selectedFlag == tempUnselected)
4423 row.selectedFlag = unselected;
4429 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
4430 selRow.selectedFlag = unselected;
4434 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
4436 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
4437 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
4443 if(currentRow.index >= clickedRow.index)
4445 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
4449 if(selRow.selectedFlag) selRow.selectedFlag = tempUnselected; else selRow.selectedFlag = tempSelected;
4452 selRow.selectedFlag = selected;
4453 if(selRow == currentRow)
4459 for(selRow = currentRow; selRow; selRow = selRow.GetNextRow())
4463 if(selRow.selectedFlag) selRow.selectedFlag = tempUnselected; else selRow.selectedFlag = tempSelected;
4466 selRow.selectedFlag = selected;
4467 if(selRow == clickedRow)
4474 if(!(key.ctrl) && currentRow)
4476 currentRow.selectedFlag = selected;
4479 clickedRow = currentRow;
4484 if(oldRow) oldRow.selectedFlag = unselected;
4485 if(currentRow) currentRow.selectedFlag = selected;
4490 if(style.freeSelect)
4491 NotifyHighlight(master, this, currentRow, 0);
4493 NotifySelect(master, this, currentRow, 0);
4495 if(style.alwaysEdit && currentRow)
4496 currentRow.Edit(currentField /*null*/);
4503 if(style.multiSelect && currentRow)
4505 if(currentRow.selectedFlag)
4508 currentRow.selectedFlag = unselected;
4511 currentRow.selectedFlag = selected;
4514 if(style.freeSelect)
4515 NotifyHighlight(master, this, currentRow, 0);
4517 NotifySelect(master, this, currentRow, 0);
4524 if(!NotifyKeyHit(master, this, currentRow, key, ch))
4527 if(ch >=32 && ch != 128 && !key.alt && !key.ctrl && GoToLetter(ch, true))
4529 /*if(inactive && window.state != Hidden)
4530 return NotifyHighlight(master, this, currentRow, 0);
4533 return NotifySelect(master, this, currentRow, 0);
4540 void OnHScroll(ScrollBarAction action, int position, Key key)
4545 void OnVScroll(ScrollBarAction action, int position, Key key)
4550 for(firstRowShown = rows.first; firstRowShown; firstRowShown = next)
4552 next = firstRowShown.GetNextRow();
4553 if(y >= position || !next) break;
4563 DataRow firstRowShown;
4567 DataField sortField;
4571 double typingTimeOut;
4584 if(guiApp.GetKeyState(shift)) mods.shift = true;
4585 if(guiApp.GetKeyState(alt)) mods.alt = true;
4586 if(guiApp.GetKeyState(control)) mods.ctrl = true;
4587 OnMouseMove(MAXINT, MAXINT, mods);
4595 delay = 0.5; // typingTimeOut
4600 typedString[0] = '\0';
4602 // The next line was commented... Why? When commented typing words stops working ( only first character jumps )
4608 bool dragging, rolledOver;
4617 // For editing fields
4619 DataField currentField;
4622 // For moving fields
4623 DataField draggingField, dropField;
4626 // For resizing fields
4627 DataField resizingField;
4628 int resizeX, oldX, startWidth;
4631 FontResource boldFont;
4634 // Only used for OnMouseMove so far, for avoiding problems with consequential mouse moves
4635 bool insideNotifySelect;
4636 ColorAlpha selectionColor, selectionText, stippleColor;
4637 stippleColor = 0xFFFFFF80;