1 namespace gui::controls;
5 static define branchesColor = Color { 85, 85, 85 };
6 static define headerCollapseForeground = Color { 135, 135, 135 };
7 static define dataBoxBackground = Color { 67, 134, 198 };
8 static define dataBoxForeground = lightYellow;
10 #define SNAPDOWN(x, d) \
13 if(x < 0) x -= ((d) - Abs(x) % (d)); else x -= x % (d); \
18 static class ListBoxCell : struct
20 ListBoxCell prev, next;
26 #define RESIZE_BORDER 5
32 bool header:1, freeSelect:1 /*Exclusive to ELS_MULTISELECT*/, fullRowSelect:1, multiSelect:1, autoScroll:1, alwaysHL : 1, moveRows:1, resizable:1;
33 bool moveFields:1, clearHeader:1, alwaysEdit:1, collapse:1, treeBranch:1, rootCollapse:1, heightSet:1;
34 bool sortable:1, noDragging:1, fillLastField:1, expandOnAdd:1;
37 public class DataDisplayFlags
39 public bool selected:1, fullRow:1, current:1, active:1, dropBox:1, header:1, firstField:1;
42 enum SelectedFlag { unselected, selected, tempSelected, tempUnselected };
45 extern int __ecereVMethodID_class_OnEdit;
46 extern int __ecereVMethodID_class_OnDisplay;
47 extern int __ecereVMethodID_class_OnGetString;
48 extern int __ecereVMethodID_class_OnFree;
49 extern int __ecereVMethodID_class_OnCompare;
50 extern int __ecereVMethodID_class_OnCopy;
51 extern int __ecereVMethodID_class_OnSaveEdit;
55 public class DataField
59 property Class dataType
61 set { dataType = value; if(value) { alignment = (Alignment)value.defaultAlignment; } } // NOTE: Class::defaultAlignment does not seem to be used anywhere
62 get { return dataType; }
64 property bool editable { set { editable = value; } };
65 property bool fixed { set { fixed = value; } get { return fixed; } };
66 property Alignment alignment
71 if(headButton) headButton.alignment = value;
72 if(listBox) listBox.Update(null);
74 get { return alignment; }
80 width = Max(value, -EXTRA_SPACE);
82 listBox.AdaptToFieldWidth(this, false);
86 property int index { get { return this ? index : 0; } };
95 for(field = listBox.fields.first; field; field = field.next)
97 if(index == value - 2)
110 for(field = listBox.fields.first; field; field = field.next)
122 property int sortOrder { get { return this ? sortOrder : 0; } };
123 property const char * header
129 headButton.text = header;
132 property void * userData
140 return this ? userData : null;
143 property bool freeData
145 set { freeData = value; } get { return freeData; }
147 property DataField prev { get { return prev; } };
148 property DataField next { get { return next; } };
150 void Move(DataField after)
154 listBox.fields.Move(this, after);
157 listBox.OnResize(listBox.clientSize.w, listBox.clientSize.h);
158 listBox.Update(null);
164 if(listBox && dataType)
166 Display display = listBox.display;
167 Font boldFont = listBox.boldFont.font;
168 Font font = listBox.fontObject;
172 display.FontExtent(boldFont, header, strlen(header), &width, null);
173 width += EXTRA_SPACE;
174 for(row = listBox.firstRow; row; row = row.GetNextRow())
178 for(i = 0, cell = row.cells.first; i != index; i++, cell = cell.next);
179 if(cell && cell.isSet && dataType)
181 static char tempString[4096];
184 if(dataType.type == normalClass || dataType.type == noHeadClass)
185 string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, cell.data[0], tempString, userData, null);
187 string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, cell.data, tempString, userData, null);
189 display.FontExtent(row.header ? boldFont : font, string, strlen(string), &tw, null);
191 display.FontExtent(row.header ? boldFont : font, "", 0, &tw, null);
192 if(tw > width) width = tw;
196 property::width = width;
203 // property::dataType = "String";
204 property::dataType = "char *";
216 headButton.Destroy(0);
221 listBox.fields.Remove(this);
222 for(field = listBox.fields.first; field; field = field.next)
224 if(field.index >= index)
227 if(listBox.currentField == this)
228 listBox.currentField = null;
230 listBox.OnResize(listBox.clientSize.w, listBox.clientSize.h);
235 DataField prev, next;
259 property int64 tag { set { if(this) tag = value; } get { return this ? tag : 0; } };
260 property DataRow previous { get { return prev; } };
261 property DataRow next { get { return next; } };
262 property int index { get { return (this && (!parent || parent.IsExpanded())) ? index : -1; } };
263 property const char * string
265 set { SetData(listBox.fields.first, value); }
266 get { return GetData(listBox.fields.first); }
268 property bool isHeader { set { header = value; } get { return this ? header : false; } };
269 property BitmapResource icon { set { if(this) icon = value; } get { return this ? icon : null; } };
270 property bool collapsed
274 if(this && collapsed != value)
277 if(parent.IsExpanded())
284 for(search = subRows.first; search; search = search.next)
285 search.selectedFlag = 0;
287 if(listBox.clickedRow && !listBox.clickedRow.parent.IsExpanded())
289 listBox.clickedRow = GetNextRow();
290 if(!listBox.clickedRow)
291 listBox.clickedRow = this;
293 if(listBox.currentRow && !listBox.currentRow.parent.IsExpanded())
295 listBox.SetCurrentRow(this, true);
297 if(listBox.firstRowShown && !listBox.firstRowShown.parent.IsExpanded())
299 listBox.firstRowShown = GetPrevRow();
300 if(!listBox.firstRowShown)
301 listBox.firstRowShown = this;
306 for(search = GetNextRow(); search; search = search.GetNextRow())
308 listBox.rowCount = ix;
310 listBox.HideEditBox(false, false, true);
312 listBox.SetScrollArea(
314 (listBox.rowCount * listBox.rowHeight) +
315 ((listBox.style.header) ? listBox.rowHeight : 0) -
316 ((!((listBox.clientSize.h+1) % listBox.rowHeight)) ? listBox.rowHeight : 0), true);
317 listBox.Update(null);
318 listBox.NotifyCollapse(listBox.master, listBox, this, value);
322 if(this && !skipCheck)
323 listBox.CheckConsistency();
326 get { return this ? collapsed : false; }
328 property bool selected
334 selectedFlag = value ? selected : unselected;
335 listBox.Update(null);
338 get { return selectedFlag == selected || selectedFlag == tempSelected; }
340 property DataRow parent
344 if(this && (value != this))
347 DataRow after = value ? value.subRows.last : listBox.rows.last;
348 int ixCount = (!collapsed && subRows.count) ? GetLastRow().index - index + 1 : 1;
349 if(parent.IsExpanded())
351 for(search = GetNextRow(); search; search = search.GetNextRow())
352 search.index -= ixCount;
353 listBox.rowCount -= ixCount;
356 listBox.HideEditBox(false, false, true);
359 if(this == listBox.clickedRow)
361 listBox.clickedRow = GetNextRow();
362 if(!listBox.clickedRow)
363 listBox.clickedRow = GetPrevRow();
366 if(this == listBox.currentRow)
368 DataRow newCurrentRow = GetNextRow();
369 if(!listBox.newCurrentRow)
370 listBox.newCurrentRow = GetPrevRow();
371 listBox.SetCurrentRow(newCurrentRow, true);
374 if(this == listBox.firstRowShown)
376 listBox.firstRowShown = GetPrevRow();
377 if(!listBox.firstRowShown)
378 listBox.firstRowShown = GetNextRow();
382 (parent ? parent.subRows : listBox.rows).Remove(this);
385 value.subRows.Insert(after, this);
387 listBox.rows.Insert(after, this);
391 if(value && listBox.style.expandOnAdd)
394 value.skipCheck = true;
396 value.collapsed = false;
398 value.skipCheck = false;
402 if(value.IsExpanded())
406 if(after && after.subRows.first && !after.collapsed)
408 search = after.GetLastRow();
409 index = search.index + 1;
412 index = after ? (after.index + 1) : (index + 1);
414 listBox.rowCount += ixCount;
418 for(search = GetNextRow(); search; search = search.GetNextRow())
422 listBox.SetScrollArea(
424 (listBox.rowCount * listBox.rowHeight) +
425 ((listBox.style.header) ? listBox.rowHeight : 0) -
426 ((!((listBox.clientSize.h+1) % listBox.rowHeight)) ? listBox.rowHeight : 0), true);
427 if(listBox.style.autoScroll)
428 listBox.SetScrollPosition(0, MAXINT - listBox.rowHeight);
430 // TESTING THIS HERE...
432 listBox.Sort(listBox.sortField, listBox.sortField.sortOrder);
435 int headerSize = ((listBox.style.header) ? listBox.rowHeight : 0);
436 int height = listBox.clientSize.h + 1 - headerSize;
437 if(listBox.currentRow && listBox.currentRow.index * listBox.rowHeight > listBox.scroll.y + height - listBox.rowHeight)
438 listBox.SetScrollPosition(listBox.scroll.x, listBox.currentRow.index * listBox.rowHeight - height + listBox.rowHeight);
439 else if(!listBox.currentRow || listBox.currentRow.index * listBox.rowHeight < listBox.scroll.y)
441 int line = listBox.currentRow ? listBox.currentRow.index * listBox.rowHeight : 0;
442 listBox.SetScrollPosition(listBox.scroll.x, line);
445 listBox.OnVScroll(0, listBox.scroll.y, 0);
447 listBox.Update(null);
455 property DataRow lastRow { get { return this ? subRows.last : null; } };
456 property DataRow firstRow { get { return this ? subRows.first : null; } };
458 void Edit(DataField field)
464 if(!field || !field.editable)
466 for(field = listBox.fields.first; field; field = field.next)
467 if(field.editable) break;
469 if(field && field.editable)
471 listBox.SetCurrentRow(this, true);
472 listBox.PopupEditBox(field, false);
478 // NOTE: This does not support reparenting (Use row.parent = first)
479 void Move(DataRow after)
484 if(listBox && prev != after)
487 int headerSize = ((listBox.style.header) ? listBox.rowHeight : 0);
488 int height = listBox.clientSize.h + 1 - headerSize;
489 int ixCount = (!collapsed && subRows.count) ? GetLastRow().index - index + 1 : 1;
491 if(!after || after.index < index)
493 if((after && after == listBox.firstRowShown.prev) || (!after && !parent /*&& listBox.firstRowShown.prev*/))
494 listBox.firstRowShown = this;
496 // All rows between AFTER (exclusive) and ROW (exclusive) are incremented by one
497 // ROW is equal to AFTER's index + 1
499 for(search = after ? after.next : (parent ? parent.subRows.first : listBox.rows.first); search && search != this; search = search.GetNextRow())
500 search.index += ixCount;
502 if(after && after.subRows.first && !after.collapsed)
504 search = after.GetLastRow();
505 index = search.index + 1;
508 index = after ? (after.index + 1) : parent ? parent.index + 1 : 0;
510 // Fix indices of sub rows
514 for(c = 1, search = GetNextRow(); search && c < ixCount; c++, search = search.GetNextRow())
521 int afterIXCount = 1;
523 nextRow = GetNextRow();
524 if(this == listBox.firstRowShown)
525 listBox.firstRowShown = nextRow;
527 // All rows between ROW (exclusive) and AFTER (inclusive) are decremented by one
528 // ROW is equal to AFTER's index
530 for(search = nextRow; search; search = search.GetNextRow())
532 search.index -= ixCount;
533 if(search == after) break;
536 // Fix up's after's sub rows
537 if(after && !after.collapsed)
539 DataRow last = after.GetLastRow();
542 int ix = after.index+1;
543 for(search = after.GetNextRow(); search; search = search.GetNextRow())
547 if(search == last) break;
551 index = after.index + afterIXCount;
553 // Fix indices of sub rows
557 for(c = 1, search = GetNextRow(); search && c < ixCount; c++, search = search.GetNextRow())
561 (parent ? parent.subRows : listBox.rows).Move(this, after);
564 listBox.CheckConsistency();
567 listBox.HideEditBox(true, false, true);
570 if(listBox.currentRow && listBox.currentRow.index * listBox.rowHeight > listBox.scroll.y + height - listBox.rowHeight)
571 listBox.SetScrollPosition(listBox.scroll.x, listBox.currentRow.index * listBox.rowHeight - height + listBox.rowHeight);
572 else if(!listBox.currentRow || listBox.currentRow.index * listBox.rowHeight < listBox.scroll.y)
574 int line = listBox.currentRow ? listBox.currentRow.index * listBox.rowHeight : 0;
575 //SNAPUP(line, listBox.rowHeight);
576 listBox.SetScrollPosition(listBox.scroll.x, line);
579 listBox.OnVScroll(0, listBox.scroll.y, 0);
581 listBox.modifiedDocument = true;
583 listBox.Update(null);
590 any_object GetData(DataField field)
594 ListBoxCell cell = listBox.GetCell(&this, &field);
595 if(cell && cell.isSet && cell.data)
597 if((field.dataType.type == normalClass || field.dataType.type == noHeadClass))
606 void * SetData(DataField field, any_object newData)
610 ListBoxCell cell = listBox.GetCell(&this, &field);
613 Class dataType = field.dataType;
617 if(dataType.type == normalClass || dataType.type == noHeadClass)
619 if(cell.data[0] && field.freeData)
620 ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, cell.data[0]);
622 if(eClass_IsDerived(dataType, class(char *)) && field.freeData)
623 ((void (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCopy])(dataType, cell.data, newData);
625 cell.data[0] = (void *)newData;
629 // Free old data first
630 ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, cell.data);
631 ((void (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCopy])(dataType, cell.data, newData);
635 listBox.modifiedDocument = true;
636 listBox.Update(null);
637 if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
646 void UnsetData(DataField field)
650 ListBoxCell cell = listBox.GetCell(&this, &field);
653 Class dataType = field.dataType;
657 if(dataType.type == normalClass || dataType.type == noHeadClass)
659 if(cell.data[0] && field.freeData)
660 ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, cell.data[0]);
665 // 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);
912 for(search = this; search; search = search.GetNextRow())
917 int headerSize = ((listBox.style.header) ? listBox.rowHeight : 0);
918 int height = listBox.clientSize.h + 1 - headerSize;
919 if(listBox.currentRow && listBox.currentRow.index * listBox.rowHeight > listBox.scroll.y + height - listBox.rowHeight)
920 listBox.SetScrollPosition(listBox.scroll.x, listBox.currentRow.index * listBox.rowHeight - height + listBox.rowHeight);
921 else if(!listBox.currentRow || listBox.currentRow.index * listBox.rowHeight < listBox.scroll.y)
922 listBox.SetScrollPosition(listBox.scroll.x, listBox.currentRow ? listBox.currentRow.index * listBox.rowHeight : 0);
923 listBox.OnVScroll(0, listBox.scroll.y, 0);
928 public DataRow GetPrevRow()
934 for(row = prev; row && !row.collapsed && row.subRows.last; row = row.subRows.last);
941 public DataRow GetNextRow()
945 if(subRows.first && !collapsed)
949 for(row = this; row; row = row.parent)
951 if(row.next) { row = row.next; break; }
957 private DataRow GetLastRow()
960 while(row && !row.collapsed && row.subRows.last)
961 row = row.subRows.last;
968 SelectedFlag selectedFlag;
979 public class ListBox : CommonControl
981 hasVertScroll = true;
982 // background = white;
984 snapVertScroll = true;
986 class_property(icon) = "<:ecere>controls/listBox.png";
990 property bool freeSelect { property_category $"Behavior" set { style.freeSelect = value; } get { return style.freeSelect; } };
991 property DataRow currentRow { property_category $"Private" /*"Behavior"*/ set { if(this) SetCurrentRow(value, false); } get { return this ? currentRow : null; } };
992 property DataField currentField
994 get { return currentField; }
995 // TODO: Document what this does
998 currentField = value;
999 HideEditBox(true, true, false);
1000 if(value && value.editable)
1001 PopupEditBox(currentField, false);
1005 property int rowHeight
1007 property_category $"Appearance"
1008 isset { return style.heightSet; }
1013 style.heightSet = true;
1015 SetScrollLineStep(8, value);
1019 style.heightSet = false;
1024 get { return this ? rowHeight : 0; }
1026 property Seconds typingTimeout
1028 property_category $"Behavior"
1031 typedString[0] = '\0';
1032 typingTimer.delay = value;
1033 typingTimeOut = value;
1035 get { return typingTimeOut; }
1037 property bool moveRows { property_category $"Behavior" set { style.moveRows = value; } get { return style.moveRows; } };
1038 property bool moveFields { property_category $"Behavior" set { style.moveFields = value; } get { return style.moveFields; } };
1039 property bool resizable { property_category $"Behavior" set { style.resizable = value; } get { return style.resizable; } };
1040 property bool autoScroll { property_category $"Behavior" set { style.autoScroll = value; } get { return style.autoScroll; } };
1041 property bool alwaysHighLight { property_category $"Appearance" set { style.alwaysHL = value; } get { return style.alwaysHL; } };
1042 property bool hasClearHeader { property_category $"Appearance" set { style.clearHeader = value; if(value) property::hasHeader = true; } get { return style.clearHeader; } };
1043 property bool hasHeader
1045 property_category $"Appearance"
1048 if(value && !style.header)
1054 bevel = !guiApp.textMode && !style.clearHeader;
1055 dontScrollVert = true;
1058 NotifyPushed = HeaderPushed;
1059 NotifyClicked = HeaderClicked;
1060 NotifyDoubleClick = HeaderDoubleClicked;
1061 NotifyReleased = HeaderReleased;
1062 NotifyMouseMove = HeaderMouseMove;
1066 endBevel.visible = false;
1068 style.header = value;
1070 get { return style.header; }
1072 property bool multiSelect { property_category $"Behavior" set { style.multiSelect = value; } get { return style.multiSelect; } };
1073 property bool alwaysEdit { property_category $"Behavior" set { style.alwaysEdit = value; } get { return style.alwaysEdit; } };
1074 property bool fullRowSelect { property_category $"Appearance" set { style.fullRowSelect = value; } get { return style.fullRowSelect; } };
1075 property bool collapseControl { property_category $"Appearance" set { style.collapse = value; } get { return style.collapse; } };
1076 property bool treeBranches { property_category $"Appearance" set { style.treeBranch = value; } get { return style.treeBranch; } };
1077 property bool rootCollapseButton { property_category $"Appearance" set { style.rootCollapse = value; } get { return style.rootCollapse; } };
1078 property bool sortable { property_category $"Behavior" set { style.sortable = value; } get { return style.sortable; } };
1079 property bool noDragging { property_category $"Behavior" set { style.noDragging = value; } get { return style.noDragging; } };
1080 property bool fillLastField
1082 property_category $"Behavior"
1085 style.fillLastField = value;
1087 get { return style.fillLastField; }
1089 property int numSelections
1093 int numSelections = 0;
1094 if(this && style.multiSelect)
1097 for(row = rows.first; row; row = row.GetNextRow())
1098 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
1101 return numSelections;
1104 property int currentIndex
1106 get { return currentRow ? currentRow.index : -1; }
1108 property DataRow lastRow { get { return this ? rows.last : null; } };
1109 property DataRow firstRow { get { return this ? rows.first : null; } };
1110 property int rowCount { get { return rowCount; } };
1111 property DataField firstField { get { return this ? fields.first : null; } };
1112 property Color selectionColor { set { selectionColor = value; } get { return selectionColor; } isset { return selectionColor ? true : false; } };
1113 property Color selectionText { set { selectionText = value; } get { return selectionText; } isset { return selectionText ? true : false; } };
1114 property Color stippleColor { set { stippleColor = value; } get { return stippleColor; } };
1115 property bool expandOnAdd { set { style.expandOnAdd = value; } get { return style.expandOnAdd; } };
1118 virtual bool Window::NotifySelect(ListBox listBox, DataRow row, Modifiers mods);
1119 virtual bool Window::NotifyHighlight(ListBox listBox, DataRow row, Modifiers mods);
1120 virtual bool Window::NotifyReclick(ListBox listBox, DataRow row, Modifiers mods);
1121 virtual bool Window::NotifySort(ListBox listBox, DataField field, Modifiers mods);
1122 virtual bool Window::NotifyChanged(ListBox listBox, DataRow row);
1123 virtual bool Window::NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch);
1124 virtual bool Window::NotifyEdited(ListBox listBox, DataRow row);
1125 virtual bool Window::NotifyEditDone(ListBox listBox, DataRow row);
1126 virtual bool Window::NotifyMovedField(ListBox listBox, DataField field, Modifiers mods);
1127 virtual bool Window::NotifyMove(ListBox listBox, DataRow row, Modifiers mods);
1128 virtual bool Window::NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods);
1129 virtual bool Window::NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods);
1130 virtual bool Window::NotifyResized(ListBox listBox, DataField field, Modifiers mods);
1131 virtual bool Window::NotifyCollapse(ListBox listBox, DataRow row, bool collapsed);
1132 virtual bool Window::NotifyKeyHit(ListBox listBox, DataRow row, Key key, unichar ch);
1133 virtual bool Window::NotifyModified(ListBox listBox, DataRow row);
1134 virtual bool Window::NotifyEditing(ListBox listBox, DataRow row);
1135 virtual void Window::NotifyMoved(ListBox listBox, DataRow row, Modifiers mods);
1138 private void CheckConsistency()
1143 for(r = rows.first; r; r = r.GetNextRow())
1145 if(r.index != index++)
1153 void AddField(DataField addedField)
1158 if(fields.first && ((DataField)fields.first).defaultField)
1160 DataField defaultField = fields.first;
1161 defaultField.Free();
1162 delete defaultField;
1166 addedField = DataField { };
1170 addedField.listBox = this;
1171 fields.Add(addedField);
1173 addedField.sortOrder = 1;
1174 addedField.index = numFields;
1178 addedField.headButton.Destroy(0);
1179 delete addedField.headButton;
1180 addedField.headButton = Button
1185 dontScrollVert = true;
1186 id = (int64)(intptr)addedField;
1187 text = addedField.header;
1188 bevel = (!guiApp.textMode && !style.clearHeader);
1190 alignment = addedField.alignment;
1191 NotifyPushed = HeaderPushed;
1192 NotifyClicked = HeaderClicked;
1193 NotifyDoubleClick = HeaderDoubleClicked;
1194 NotifyReleased = HeaderReleased;
1195 NotifyMouseMove = HeaderMouseMove;
1197 incref addedField.headButton;
1198 addedField.headButton.Create();
1201 addedField.headButton.background = Color { 0, 170, 0 };
1207 for(row = rows.first; row; )
1209 int size = (field.dataType && field.dataType.typeSize) ?
1210 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1211 ListBoxCell cell = (ListBoxCell)new0 byte[size];
1212 row.cells.Add(cell);
1213 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
1216 if(row.subRows.first)
1217 row = row.subRows.first;
1220 for(; row; row = row.parent)
1222 if(row.next) { row = row.next; break; }
1227 OnResize(clientSize.w, clientSize.h);
1236 Clear(); // Ensure data is cleared first
1237 while((field = fields.first))
1242 endBevel.visible = false;
1247 void RemoveField(DataField field)
1253 int index = field.index;
1256 if(sortField == field)
1259 for(row = rows.first; row; )
1264 for(cell = row.cells.first, c = 0; c < index && cell; c++, cell = cell.next);
1265 if(cell && index == c)
1269 // TOCHECK: Is this check good? Will need incref/decref sometime?
1270 if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
1272 if(cell.data[0] && field.freeData)
1273 ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data[0]);
1276 ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data);
1279 row.cells.Remove(cell);
1283 if(row.subRows.first)
1284 row = row.subRows.first;
1287 for(; row; row = row.parent)
1289 if(row.next) { row = row.next; break; }
1298 endBevel.visible = false;
1302 DataRow AddRowNone()
1304 DataRow row { noneRow = true };
1311 rows.Insert(null, row);
1314 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1320 firstRowShown = row;
1324 (rowCount * rowHeight) +
1325 ((style.header) ? rowHeight : 0) -
1326 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1327 if(style.autoScroll)
1328 SetScrollPosition(0, MAXINT - rowHeight);
1329 modifiedDocument = true;
1348 // Find very last row
1351 for(lastRow = rows.last; lastRow && !lastRow.collapsed && lastRow.subRows.last; lastRow = lastRow.subRows.last);
1352 row.index = lastRow ? (lastRow.index + 1) : 0;
1360 for(c = 0; c<fields.count; c++)
1362 for(field = fields.first; field; field = field.next)
1363 if((int)field.index == c)
1367 int size = (field.dataType && field.dataType.typeSize) ?
1368 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1369 ListBoxCell cell = (ListBoxCell) new0 byte[size];
1370 row.cells.Add(cell);
1371 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
1378 firstRowShown = row;
1384 (rowCount * rowHeight) +
1385 ((style.header) ? rowHeight : 0) -
1386 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1387 if(style.autoScroll)
1388 SetScrollPosition(0, MAXINT - rowHeight);
1389 modifiedDocument = true;
1400 DataRow AddRowAfter(DataRow after)
1412 if(after && after.subRows.first && !after.collapsed)
1414 for(search = after.subRows.last; !search.collapsed && search.subRows.last; )
1415 search = search.subRows.last;
1416 row.index = search.index + 1;
1419 row.index = after ? (after.index + 1) : 0;
1420 rows.Insert(after, row);
1423 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1428 for(c = 0; c<fields.count; c++)
1430 for(field = fields.first; field; field = field.next)
1431 if((int)field.index == c)
1435 int size = (field.dataType && field.dataType.typeSize) ?
1436 (sizeof(class ListBoxCell) + field.dataType.typeSize - sizeof(void *)) : sizeof(class ListBoxCell);
1437 ListBoxCell cell = (ListBoxCell) new0 byte[size];
1438 row.cells.Add(cell);
1439 FillBytes(cell.data, 0, size - (uint)(uintptr)&((ListBoxCell)0).data);
1443 if(!firstRowShown || !after)
1445 firstRowShown = row;
1450 (rowCount * rowHeight) +
1451 ((style.header) ? rowHeight : 0) -
1452 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1453 if(style.autoScroll)
1454 SetScrollPosition(0, MAXINT - rowHeight);
1455 modifiedDocument = true;
1465 DataRow AddStringf(const char * format, ...)
1471 char string[MAX_F_STRING];
1474 va_start(args, format);
1475 vsnprintf(string, sizeof(string), format ? format : "", args);
1476 string[sizeof(string)-1] = 0;
1480 row.SetData(fields.first, string);
1486 DataRow AddString(const char * string)
1492 row.SetData(fields.first, string);
1498 void SelectRow(DataRow row)
1500 SetCurrentRow(row, true);
1503 void DeleteRow(DataRow row)
1505 if(!row) row = currentRow;
1508 DataRow sub, next, search;
1509 // Trying to move this here (Messed up deleting watches)
1510 //HideEditBox(false, false, true);
1513 for(sub = row.subRows.first; sub; sub = next)
1519 if(row.parent.IsExpanded())
1521 for(search = row.GetNextRow(); search; search = search.GetNextRow())
1526 HideEditBox(false, false, true);
1528 if(row == clickedRow)
1530 clickedRow = row.GetNextRow();
1532 clickedRow = row.GetPrevRow();
1535 if(row == currentRow)
1537 DataRow newCurrentRow = row.GetNextRow();
1539 newCurrentRow = row.GetPrevRow();
1540 SetCurrentRow(newCurrentRow, true);
1543 if(row == firstRowShown)
1545 firstRowShown = row.GetPrevRow();
1547 firstRowShown = row.GetNextRow();
1550 (row.parent ? row.parent.subRows: rows).Remove(row);
1553 //HideEditBox(false, false, true);
1557 (rowCount * rowHeight) +
1558 ((style.header) ? rowHeight : 0) -
1559 ((!((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1561 modifiedDocument = true;
1570 DataRow FindRow(int64 tag)
1575 for(row = rows.first; row; row = row.next)
1577 if(!row.noneRow && row.tag == tag)
1585 DataRow FindString(const char * searchedString)
1588 bool checkNextField = true;
1590 for(field = fields.first; field; field = field.next)
1592 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1595 for(row = rows.first; row; row = row.GetNextRow())
1599 void * data = row.GetData(field);
1600 char tempString[1024] = "";
1601 bool needClass = false;
1602 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1604 if(string && string[0])
1605 checkNextField = false;
1606 if(string && string[0] && !strcmp(string, searchedString))
1611 if(!checkNextField) break;
1616 DataRow FindSubString(const char * subString)
1619 bool checkNextField = true;
1620 int len = subString ? strlen(subString) : 0;
1624 for(field = fields.first; field; field = field.next)
1626 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1629 for(row = rows.first; row; row = row.GetNextRow())
1633 void * data = row.GetData(field);
1634 char tempString[1024] = "";
1635 bool needClass = false;
1636 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1638 if(string && string[0])
1639 checkNextField = false;
1640 if(string && string[0] && !strncmp(string, subString, len))
1645 if(!checkNextField) break;
1651 DataRow FindSubStringi(const char * subString)
1654 bool checkNextField = true;
1655 int len = subString ? strlen(subString) : 0;
1656 DataRow result = null;
1657 const char * bestResult = null;
1662 for(field = fields.first; field; field = field.next)
1664 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1667 for(row = rows.first; row; row = row.GetNextRow())
1671 void * data = row.GetData(field);
1672 char tempString[1024] = "";
1673 bool needClass = false;
1674 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1676 if(string && string[0])
1677 checkNextField = false;
1678 if(string && string[0])
1680 int stringLen = strlen(string);
1682 if(!strnicmp(string, subString, Min(len, stringLen)))
1684 if(bestLen < Min(len, stringLen))
1686 if(!bestResult || strcmpi(string, bestResult) < 0)
1688 bestLen = Min(len, stringLen);
1689 bestResult = string;
1697 if(!checkNextField) break;
1703 DataRow FindSubStringAfter(DataRow after, const char * subString)
1706 bool checkNextField = true;
1707 int len = subString ? strlen(subString) : 0;
1711 for(field = fields.first; field; field = field.next)
1713 if(field.dataType._vTbl[__ecereVMethodID_class_OnGetString])
1716 for(row = after.GetNextRow(); row && row != after; row = row.GetNextRow(), (!row) ? (row = rows.first) : null)
1720 void * data = row.GetData(field);
1721 char tempString[1024] = "";
1722 bool needClass = false;
1723 const char * string = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
1725 if(string && string[0])
1726 checkNextField = false;
1727 if(string && string[0] && !strncmp(string, subString, len))
1732 if(!checkNextField) break;
1738 DataRow FindSubRow(int64 tag)
1744 for(row = rows.first; row; row = row.next)
1746 if(!row.noneRow && row.tag == tag)
1748 if(!row.noneRow && row.subRows.first)
1750 DataRow subRow = row.FindSubRow(tag);
1764 Window master = this.master;
1766 HideEditBox(false, true, false);
1767 editData.Destroy(0);
1769 firstRowShown = currentRow = null;
1774 if(style.freeSelect)
1775 NotifyHighlight(master, this, currentRow ? currentRow : null, 0);
1777 NotifySelect(master, this, currentRow ? currentRow : null, 0);
1780 if(style.alwaysEdit && currentRow)
1781 currentRow.Edit(currentField);
1788 (rowCount * rowHeight) +
1789 ((style.header) ? rowHeight : 0) -
1790 ((rowHeight && !((clientSize.h+1) % rowHeight)) ? rowHeight : 0), true);
1795 void Sort(DataField field, int order)
1800 int headerSize = ((style.header) ? rowHeight : 0);
1801 int height = clientSize.h + 1 - headerSize;
1803 if(!field) field = fields.first;
1805 field.sortOrder = order ? order : 1;
1806 rows.Sort(DataRow::Compare, field);
1808 for(search = rows.first; search; search = search.next)
1809 search._SortSubRows(field, order);
1813 for(search = rows.first; search; search = search.GetNextRow())
1814 search.index = index++;
1817 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
1818 SetScrollPosition(scroll.x, currentRow.index * rowHeight - height + rowHeight);
1819 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
1820 SetScrollPosition(scroll.x, currentRow ? currentRow.index * rowHeight : 0);
1822 OnVScroll(0, scroll.y, 0);
1824 // SetScrollPosition(0, scroll.y);
1829 void StopEditing(bool save)
1831 HideEditBox(save, false, true);
1834 void GetMultiSelection(OldList list)
1837 if(this && style.multiSelect)
1841 for(row = rows.first; row; row = row.GetNextRow())
1843 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
1845 list.Add(OldLink { data = row });
1851 // Convenience Current Row Methods
1852 void * SetData(DataField field, any_object data)
1854 return currentRow.SetData(field, data);
1857 any_object GetData(DataField field)
1859 return (void *)currentRow.GetData(field);
1864 return currentRow ? currentRow.tag : 0;
1870 DataField defaultField { };
1871 rows.offset = (uint)(uintptr)&((DataRow)0).prev;
1872 fields.offset = (uint)(uintptr)&((DataField)0).prev;
1873 style.fullRowSelect = true;
1874 style.fillLastField = true;
1875 style.expandOnAdd = true;
1876 typingTimeOut = 0.5;
1877 rowHeight = 16; // Stuff depending on creation and default property checking
1880 defaultField.defaultField = true;
1882 AddField(defaultField);
1884 typedString = new char[1];
1885 typedString[0] = '\0';
1900 while((field = fields.first))
1902 // fields.Remove(field);
1912 while((row = rows.first))
1919 ListBoxCell GetCell(DataRow * row, DataField * field)
1921 ListBoxCell cell = null;
1922 if(!*row) *row = currentRow;
1925 if(!*field) *field = this ? currentField : null;
1928 for(*field = fields.first; (*field).index != 0; *field = (*field).next);
1933 if(field->listBox == this)
1935 for(index = 0, cell = (*row).cells.first; cell && index != (*field).index; index++, cell = cell.next);
1942 void HideEditBox(bool save, bool alwaysStopEdit, bool repositionOnly)
1944 if(editData && editData.visible)
1947 editData.SaveData();
1949 editData.visible = false;
1950 NotifyEditDone(master, this, currentRow);
1952 // ENSURE DATA BOX IS NOT VISIBLE
1953 editData.visible = false;
1955 if(style.alwaysEdit && !alwaysStopEdit)
1958 int height = rowHeight - (style.alwaysEdit ? 1 : 0);
1959 int y = currentRow.index * rowHeight + (style.header ? rowHeight : 0);
1960 int x = currentField.x;
1961 int width = (!currentField.next && style.fillLastField && (!hasHorzScroll || clientSize.w - currentField.x > currentField.width + EXTRA_SPACE)) ?
1962 clientSize.w - currentField.x : (currentField.width + EXTRA_SPACE);
1964 if(!style.alwaysEdit)
1966 editData.position = { x, y };
1967 editData.size = { width, height };
1971 editData.position = { x, y - editData.clientStart.y };
1972 editData.size = { width, height + editData.clientStart.y * 2 };
1974 editData.visible = true;
1975 if(style.alwaysEdit)
1976 editData.Deactivate();
1978 PopupEditBox(currentField, repositionOnly);
1982 currentField = null;*/
1986 void SetCurrentRow(DataRow row, bool notify)
1988 if(this && (currentRow != row || (currentRow && currentRow.selectedFlag == unselected)))
1990 int headerSize = ((style.header) ? rowHeight : 0);
1991 int height = clientSize.h + 1 - headerSize;
1993 // true: destroy edit box
1994 HideEditBox(true, true, false);
1996 if(!(style.multiSelect) && currentRow)
1997 currentRow.selectedFlag = unselected;
2001 if(style.multiSelect)
2005 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
2006 selRow.selectedFlag = unselected;
2008 currentRow.selectedFlag = selected;
2013 currentRow.selectedFlag = selected;
2015 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
2016 SetScrollPosition(scroll.x,
2017 currentRow.index * rowHeight - height + rowHeight);
2018 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
2020 int line = currentRow ? currentRow.index * rowHeight : 0;
2021 //SNAPUP(line, rowHeight);
2022 SetScrollPosition(scroll.x, line);
2027 Window master = this.master;
2030 if(style.freeSelect && visible)
2031 NotifyHighlight(master, this, currentRow ? currentRow : null, 0);
2033 NotifySelect(master, this, currentRow ? currentRow : null, 0);
2034 if(style.alwaysEdit && currentRow)
2035 currentRow.Edit(currentField);
2043 void RepositionFieldEditor()
2045 if(editData && editData.visible)
2047 int height = rowHeight - (style.alwaysEdit ? 1 : 0);
2049 int y = currentRow.index * rowHeight + (style.header ? rowHeight : 0);
2053 if(style.collapse && !(style.treeBranch))
2055 for(field = fields.first; field; field = field.next)
2057 width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2058 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2059 if(field == currentField) break;
2062 if(!style.alwaysEdit)
2064 editData.position = { x, y - editData.clientStart.y };
2065 editData.size = { width, height + editData.clientStart.y * 2 };
2069 editData.position = { x, y };
2070 editData.size = { width, height };
2075 void PopupEditBox(DataField whichField, bool repositionOnly)
2077 if((!editData || !editData.visible || currentField != whichField) && currentRow)
2079 // true: destroy edit box
2080 HideEditBox(true, true, false);
2083 int height = rowHeight - (style.alwaysEdit ? 1 : 0);
2085 int y = currentRow.index * rowHeight + (style.header ? rowHeight : 0);
2087 //void * data = currentRow.GetData(whichField);
2092 if(style.collapse && !(style.treeBranch))
2095 for(field = fields.first; field; field = field.next)
2097 width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
2098 clientSize.w - field.x : (field.width + EXTRA_SPACE);
2099 if(field == whichField) break;
2103 currentField = whichField;
2104 cell = GetCell(&row, ¤tField);
2111 background = dataBoxBackground;
2112 foreground = dataBoxForeground;
2114 bool NotifyChanged(DataBox dataBox, bool closingDropDown)
2117 DataField field = null;
2118 ListBoxCell cell = GetCell(&row, &field);
2122 modifiedDocument = true;
2124 NotifyChanged(master, this, currentRow);
2129 bool NotifyModified()
2131 //DataRow row = null;
2132 //DataField field = null;
2133 //ListBoxCell cell = GetCell(&row, &field);
2134 //cell.isSet = true;
2135 modifiedDocument = true;
2137 NotifyModified(master, this, currentRow);
2141 bool OnKeyDown(Key key, unichar ch)
2143 bool result = DataBox::OnKeyDown(key, ch);
2144 if(visible && active) // Added this check here, because we will not use enter/escape otherwise, and lose DataBox's result
2146 if((SmartKey)key == enter || (SmartKey)key == escape)
2155 editData.Destroy(0);
2156 editData.type = whichField.dataType;
2157 editData.fieldData = whichField.userData;
2158 editData.borderStyle = style.alwaysEdit ? 0 : deep;
2159 editData.data = cell ? cell.data : null;
2162 // Might not really need this anymore...
2163 NotifyEditing(master, this, currentRow);
2166 if(!style.alwaysEdit)
2168 editData.position = { x, y - editData.clientStart.y };
2169 editData.size = { width, height + editData.clientStart.y * 2 };
2173 editData.position = { x, y };
2174 editData.size = { width, height };
2178 editData.visible = true;
2180 if(style.alwaysEdit)
2181 editData.Deactivate();
2183 // MOVED THIS HIGHER FOR DATALIST EDITOR
2185 // Might not really need this anymore...
2186 NotifyEdited(master, this, currentRow);
2191 void OnRedraw(Surface surface)
2194 int y = (style.header) ? rowHeight : 0;
2195 bool isActive = active;
2196 Font font = fontObject;
2197 Font boldFont = this.boldFont.font;
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(dragRow && dropIndex != -1)
2581 if(!style.multiSelect && currentRow.index < dropIndex)
2583 surface.DrawingChar(223);
2585 y = style.header ? rowHeight : 0;
2586 y += ix * 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 && dropField)
2598 int position = dropField.x;
2599 if(draggingField.x < position)
2600 position += 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 resizeX = x + control.position.x;
2778 startWidth = field.width;
2779 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 > oldX &&
2807 startWidth + x - resizeX < field.width)
2809 oldX = x - scroll.x;
2812 oldX = x - scroll.x;
2814 field.width = startWidth + x - 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(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 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 && 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 && !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 rolledOver = 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(maxShown, 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 = startWidth + x - 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 && */(rolledOver || !dragging))
3211 int rowY = (style.header) ? rowHeight : 0;
3212 DataRow row = null, nextRow;
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 - ((dragRow && style.moveRows) ? rowHeight : 0)-1);
3242 for(row = firstRowShown; row; row = nextRow, rowIndex ++)
3244 nextRow = row.GetNextRow();
3246 if(rowY > y || !nextRow)
3252 if(dragRow && style.moveRows)
3254 if(row && row == currentRow)
3255 row = row.GetNextRow();
3257 if(row && row.parent == currentRow)
3258 row = row.GetNextRow();
3261 if(row && currentRow != row)
3263 if(dragRow && style.moveRows)
3265 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
3267 else if(style.multiSelect)
3270 for(thisRow = rows.first; thisRow; thisRow = thisRow.GetNextRow())
3271 if((thisRow.selectedFlag == selected || thisRow.selectedFlag == tempSelected) ||
3277 if(dropIndex != rowIndex)
3279 dropIndex = rowIndex;
3285 else if((style.freeSelect || dragging) && ((realX>= 0 && realY >= 0 && realX< clientSize.w && realY < clientSize.h) || rolledOver))
3287 if(!(style.multiSelect))
3289 if(currentRow)currentRow.selectedFlag = unselected;
3290 if(row)row.selectedFlag = selected;
3294 if(style.multiSelect)
3298 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3300 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3301 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3304 if(rowIndex >= clickedRow.index)
3306 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
3308 selRow.selectedFlag = (selRow.selectedFlag == selected) ? tempUnselected : tempSelected;
3315 for(selRow = row; selRow; selRow = selRow.GetNextRow())
3317 selRow.selectedFlag = (selRow.selectedFlag == selected) ? tempUnselected : tempSelected;
3318 if(selRow == clickedRow)
3324 if(style.freeSelect)
3325 NotifyHighlight(master, this, currentRow, mods);
3328 insideNotifySelect = true;
3329 NotifySelect(master, this, currentRow, mods);
3330 insideNotifySelect = false;
3333 if(style.alwaysEdit && currentRow)
3334 currentRow.Edit(currentField);
3341 bool OnMouseOver(int x, int y, Modifiers mods)
3348 bool OnActivate(bool active, Window swap, bool * goOnWithActivation, bool direct)
3350 // TOCHECK: WAS THIS MISSING ? CHECK FOR SLOWDOWN
3351 if(!active) Update(null);
3353 if(!active && (!swap || !swap.isModal))
3355 // true: destroy edit box
3356 HideEditBox(true, true, false);
3358 else if(!swap || !swap.isModal)
3360 // Bring back edit box
3361 if(currentRow && style.alwaysEdit)
3363 currentRow.Edit(currentField ? currentField : null);
3367 return true; //NotifyActivate(master, this, active, swap, 0);
3371 bool OnButtonDown(int x, int y, Modifiers mods, bool right)
3374 // Check to see if we're dragging the vertical divider
3375 if(style.alwaysEdit && style.resizable && !right)
3377 int vx = -scroll.x - 1;// + EXTRA_SPACE;// / 2 - 1;
3380 if(style.collapse && !(style.treeBranch))
3383 for(field = fields.first; field; field = field.next)
3385 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3386 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3392 resizingField = field.prev;
3394 startWidth = resizingField.width;
3396 SetMouseRangeToClient();
3400 vx += width + EXTRA_SPACE;
3404 if(!(style.freeSelect))
3406 int rowY = (style.header) ? rowHeight : 0;
3408 int rowIndex = firstRowShown ? firstRowShown.index : -1;
3409 DataRow previousRow = currentRow;
3410 DataRow newCurrentRow = null;
3411 bool moveMultiple = false;
3412 int numSelected = 0;
3413 int rowStart = -scroll.x;
3415 if(style.multiSelect)
3422 for(row = rows.first; row; row = row.GetNextRow())
3424 if(row.selectedFlag == tempSelected)
3425 row.selectedFlag = selected;
3426 else if(row.selectedFlag == tempUnselected)
3427 row.selectedFlag = unselected;
3428 if(row.selectedFlag == selected)
3435 for(row = firstRowShown; row; row = row.GetNextRow(), rowIndex ++)
3438 if(rowY > y || (style.multiSelect && !row.GetNextRow()))
3441 if(style.treeBranch)
3444 for(parent = (style.rootCollapse) ? row.parent : (row.parent ? row.parent.parent : null); parent; parent = parent.parent)
3450 /* THIS WAS TOO STRICT:
3451 if(style.collapse && row.subRows.first && (row.parent || !(style.treeBranch) || (style.rootCollapse)) &&
3452 (x >= rowStart + 3 + plusIndent && y >= rowY - rowHeight + PLUSY && x <= rowStart + 11 + plusIndent && y <= rowY - rowHeight + PLUSY + 8))
3454 if(style.collapse &&
3455 (x >= rowStart && y >= rowY - rowHeight && x <= rowStart + 18 + plusIndent && y <= rowY + rowHeight-1))
3457 if(row.subRows.first && (row.parent || !(style.treeBranch) || (style.rootCollapse)) && x >= plusIndent)
3458 row.collapsed = !row.collapsed;
3465 newCurrentRow = row;
3467 if(style.multiSelect)
3469 // Deselect everything if user didn't clicked on a row
3473 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3474 selRow.selectedFlag = unselected;
3476 //clickedRowIndex = rowIndex;
3478 else if(style.moveRows && !(mods.shift) &&
3479 (row.selectedFlag == selected || row.selectedFlag == tempSelected) &&
3480 !right && !(mods.isActivate))
3481 moveMultiple = true;
3487 if(row.selectedFlag == tempUnselected || row.selectedFlag == unselected)
3489 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3490 selRow.selectedFlag = unselected;
3491 row.selectedFlag = selected;
3494 //clickedRowIndex = rowIndex;
3500 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3501 selRow.selectedFlag = unselected;
3505 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3507 if(selRow != clickedRow)
3509 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3510 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3517 if(rowIndex >= clickedRow.index)
3519 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
3523 if(selRow != clickedRow)
3525 if(selRow.selectedFlag)
3526 selRow.selectedFlag = tempUnselected;
3528 selRow.selectedFlag = tempSelected;
3532 selRow.selectedFlag = selected;
3539 for(selRow = row; selRow; selRow = selRow.GetNextRow())
3543 if(selRow != clickedRow)
3545 if(selRow.selectedFlag)
3546 selRow.selectedFlag = tempUnselected;
3548 selRow.selectedFlag = tempSelected;
3552 selRow.selectedFlag = selected;
3553 if(selRow == clickedRow)
3562 if(row.selectedFlag)
3563 row.selectedFlag = tempUnselected;
3564 else row.selectedFlag = tempSelected;
3567 row.selectedFlag = tempSelected;
3569 //clickedRowIndex = rowIndex;
3579 // true: destroy edit box
3582 incref newCurrentRow;
3585 if(currentRow != newCurrentRow)
3586 HideEditBox(true, true, false);
3590 if(newCurrentRow._refCount <= 1)
3591 delete newCurrentRow;
3593 newCurrentRow._refCount--;
3598 if(!(style.multiSelect))
3600 if(currentRow) currentRow.selectedFlag = unselected;
3601 if(newCurrentRow) newCurrentRow.selectedFlag = selected;
3605 if(currentRow != newCurrentRow)
3608 // true: destroy edit box
3611 //incref newCurrentRow;
3612 incref newCurrentRow;
3615 HideEditBox(true, true, false);
3620 int headerSize = ((style.header) ? rowHeight : 0);
3621 int height = clientSize.h + 1 - headerSize;
3623 /*if(newCurrentRow._refCount <= 1)
3624 delete newCurrentRow;
3627 newCurrentRow._refCount--;
3628 //newCurrentRow._refCount--;
3631 currentRow = newCurrentRow;
3633 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
3634 SetScrollPosition(scroll.x,
3635 currentRow.index * rowHeight - height + rowHeight);
3636 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
3638 int line = currentRow ? currentRow.index * rowHeight : 0;
3639 //SNAPUP(line, rowHeight);
3640 SetScrollPosition(scroll.x, line);
3643 // GO THROUGH SetCurrentRow eventually?
3644 // SetCurrentRow(newCurrentRow, true);
3648 if(style.freeSelect)
3649 NotifyHighlight(master, this, currentRow, mods);
3650 else if((moveMultiple || (!(style.multiSelect) && previousRow == currentRow)) &&
3651 newCurrentRow && !(mods.shift))
3655 if(!(mods.isActivate))
3659 dragRow = currentRow;
3665 if(editData && editData.visible && style.alwaysEdit)
3672 if(style.collapse && !style.treeBranch)
3675 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3677 indent += (style.treeBranch) ? 20 : 15;
3680 for(field = fields.first; field; field = field.next)
3682 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3683 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3685 if(!field.prev) width -= indent;
3686 if(x >= sx && x < sx + width)
3690 if(field == currentField)
3691 editData.Deactivate();
3694 currentRow.Edit(field);
3695 editData.Activate();
3698 else if(!(mods.ctrl) && numSelected <= 1)
3699 editRow = currentRow;
3701 if(style.noDragging && newCurrentRow)
3702 NotifyReclick(master, this, newCurrentRow, mods);
3706 // If the user clicked exactly on the edited field,
3708 if(editData && editData.visible && newCurrentRow)
3714 if(style.collapse && !(style.treeBranch))
3719 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3721 indent += (style.treeBranch) ? 20 : 15;
3725 for(field = fields.first; field; field = field.next)
3727 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3728 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3729 if(!field.prev) width -= indent;
3730 if(x >= sx && x < sx + width && newCurrentRow)
3735 if(field) //x >= sx && x < sx + width && newCurrentRow)
3737 if(field == currentField)
3738 editData.Activate();
3740 newCurrentRow.Edit(currentField);*/
3742 else if(style.noDragging && newCurrentRow)
3743 NotifyReclick(master, this, newCurrentRow, mods);
3745 else if(style.noDragging && newCurrentRow)
3746 NotifyReclick(master, this, newCurrentRow, mods);
3753 if(result && style.alwaysEdit && currentRow)
3757 DataField field = null;
3762 if(style.collapse && !style.treeBranch)
3765 for(parent = newCurrentRow.parent; parent; parent = parent.parent)
3767 indent += (style.treeBranch) ? 20 : 15;
3770 for(field = fields.first; field; field = field.next)
3772 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3773 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3775 if(!field.prev) width -= indent;
3776 if(x >= sx && x < sx + width)
3778 f = currentField = field;
3785 // Moved NotifySelect after setting currentField for the NotifySelect implementation to be aware of which field is now selected (e.g. WatchesView)
3786 result = NotifySelect(master, this, currentRow, mods);
3787 if(result && style.alwaysEdit && currentRow)
3789 // In case the user specifically clicked on a field (f is set), override any change to currentField that NotifySelect could have done
3790 currentRow.Edit(f ? f : currentField);
3792 // If the user clicked exactly on the edited field,
3794 if(editData && editData.visible && newCurrentRow)
3798 editData.Activate();
3800 else if(style.noDragging && newCurrentRow)
3801 NotifyReclick(master, this, newCurrentRow, mods);
3804 else if(style.noDragging && newCurrentRow)
3805 NotifyReclick(master, this, newCurrentRow, mods);
3809 For drop box to capture...
3812 if(x < 0 || y < 0 || x >= clientSize.w || y >= clientSize.h)
3815 master.parent.Activate();
3824 if(!style.noDragging)
3829 if(x >= 0 && y >= 0 && x < clientSize.w && y < clientSize.h)
3836 OnLeftButtonUp(x, y, mods);
3841 bool OnLeftButtonDown(int x, int y, Modifiers mods)
3843 return OnButtonDown(x,y, mods, false);
3846 bool OnLeftButtonUp(int x, int y, Modifiers mods)
3848 if(resizingField && style.alwaysEdit)
3850 Window::FreeMouseRange();
3852 resizingField = null;
3855 if(dragRow || editRow)
3857 DataRow row, switchRow = rows.last;
3858 int rowY = (style.header) ? rowHeight : 0;
3859 while(switchRow.lastRow) switchRow = switchRow.lastRow;
3860 for(row = firstRowShown; row; row = row.GetNextRow())
3869 if(editRow == switchRow && y >= 0)
3874 for(field = fields.first; field; field = field.next)
3876 int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ?
3877 clientSize.w - field.x : (field.width + EXTRA_SPACE);
3880 if(fieldX > x + scroll.x)
3884 if(field && field.editable)
3886 // true: destroy edit box
3887 HideEditBox(true, true, false);
3888 PopupEditBox(field, false);
3890 else if(!style.noDragging)
3891 NotifyReclick(master, this, currentRow, mods);
3893 else if(style.moveRows && switchRow)
3895 if(dragRow == switchRow && movedRow == false)
3897 DataRow row = dragRow;
3901 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3902 selRow.selectedFlag = unselected;
3906 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
3908 if(selRow != clickedRow)
3910 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
3911 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
3917 if(row.selectedFlag)
3918 row.selectedFlag = tempUnselected;
3919 else row.selectedFlag = tempSelected;
3922 row.selectedFlag = tempSelected;
3927 if(style.multiSelect)
3929 if(!switchRow.selectedFlag)
3931 bool foundSwitch = false;
3934 DataRow afterRow = switchRow.prev;
3935 for(row = rows.first; row; row = next)
3937 next = row.GetNextRow();
3938 if(row.selectedFlag == selected || row.selectedFlag == tempSelected)
3940 if(!foundSwitch && !after)
3943 afterRow = switchRow;
3945 if(!after || !(row.selectedFlag == selected || row.selectedFlag == tempSelected) ||
3952 else if(row == switchRow)
3959 for(row = rows.first; row; row = row.GetNextRow())
3961 if(row == switchRow || row == dragRow)
3965 // Switch row first: move before
3966 if(row == switchRow)
3968 DataRow actualMoveRow;
3970 if(!switchRow.prev && switchRow.parent == dragRow.parent)
3971 actualMoveRow = null;
3974 actualMoveRow = switchRow.prev ? switchRow.prev : switchRow;
3975 while(actualMoveRow && actualMoveRow.parent != dragRow.parent && actualMoveRow.parent)
3976 actualMoveRow = actualMoveRow.parent;
3979 if(!actualMoveRow || (actualMoveRow && actualMoveRow.parent == dragRow.parent))
3980 if(NotifyMove(master, this, actualMoveRow, mods))
3982 dragRow.Move(actualMoveRow);
3983 NotifyMoved(master, this, actualMoveRow, mods);
3986 // Dragged row first: move after
3989 DataRow actualMoveRow = switchRow;
3990 DataRow nextRow = switchRow.GetNextRow();
3992 while(nextRow && nextRow.parent != dragRow.parent)
3993 nextRow = nextRow.parent ? nextRow.parent.next : null;
3995 actualMoveRow = nextRow.prev;
3998 actualMoveRow = dragRow.parent ? dragRow.parent.subRows.last : rows.last;
4000 if(!actualMoveRow || (actualMoveRow != dragRow && actualMoveRow.parent == dragRow.parent))
4001 if(NotifyMove(master, this, actualMoveRow, mods))
4003 dragRow.Move(actualMoveRow);
4004 NotifyMoved(master, this, actualMoveRow, mods);
4020 if(dragging || style.freeSelect)
4024 rolledOver = dragging = false;
4026 if(x >= 0 && y >= 0 && x < clientSize.w && y < clientSize.h && currentRow && style.freeSelect)
4030 result = NotifySelect(master, this, currentRow, mods);
4031 if(style.alwaysEdit)
4032 currentRow.Edit(currentField);
4036 // if(!(style.freeSelect))
4042 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
4044 int rowStart = -scroll.x;
4046 int rowY = (style.header) ? rowHeight : 0;
4049 OnLeftButtonUp(x,y,mods);
4050 if(style.alwaysEdit)
4052 if(!(style.collapse) || x > 15)
4053 if(editData && editData.visible)
4055 editData.Activate();
4056 NotifyDoubleClick(master, this, x, y, mods);
4060 for(row = firstRowShown; row; row = row.GetNextRow())
4063 if(rowY > y || (style.multiSelect && !row.GetNextRow()))
4065 if(style.treeBranch)
4068 for(parent = (style.rootCollapse) ? row.parent : (row.parent ? row.parent.parent : null); parent; parent = parent.parent)
4077 if((row && style.collapse && (x >= rowStart && x <= rowStart + 18 + plusIndent)) ||
4078 NotifyDoubleClick(master, this, x, y, mods))
4082 if(row && row.subRows.first)
4084 row.collapsed = !row.collapsed;
4088 // We need to return true here so that OnLeftButtonDown can popup the DataBox Editors
4094 bool OnRightButtonDown(int x, int y, Modifiers mods)
4096 return OnButtonDown(x,y, mods, true);
4099 bool OnRightButtonUp(int x, int y, Modifiers mods)
4101 OnLeftButtonUp(x,y,mods);
4102 return NotifyRightClick(master, this, x, y, mods);
4105 bool GoToLetter(unichar ch, bool keyHit)
4107 bool result = false;
4109 bool checkNextField = true;
4110 int len = keyHit ? 0 : strlen(typedString);
4112 typedString = renew typedString char[len + 2];
4113 typedString[len++] = (char)tolower(ch); // TODO: FIX UNICODE
4114 typedString[len] = '\0';
4116 for(field = fields.first; field; field = field.next)
4118 DataRow startRow = currentRow ? currentRow : rows.first;
4120 if(startRow && field.dataType && field.dataType._vTbl[__ecereVMethodID_class_OnGetString] && ch)
4123 bool looped = false;
4124 if(len == 1 && currentRow)
4125 startRow = (next = startRow.GetNextRow(), (next ? next : rows.first));
4127 for(row = startRow; row != startRow || !looped; next = row.GetNextRow(), row = next ? next : rows.first)
4129 void * data = row.GetData(field);
4130 char tempString[1024] = "";
4131 bool needClass = false;
4132 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;
4134 if(string && string[0])
4135 checkNextField = false;
4136 if(string && string[0] && !strnicmp(string, typedString, len))
4138 if(style.multiSelect)
4143 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
4144 selRow.selectedFlag = unselected;
4145 row.selectedFlag = selected;
4147 SetCurrentRow(row, true);
4154 if(typingTimeOut && !keyHit)
4155 typingTimer.Start();
4156 if(!result || !typingTimeOut || keyHit)
4157 typedString[len-1] = '\0';
4159 if(!checkNextField || result) break;
4164 bool OnKeyDown(Key key, unichar ch)
4168 if(key == enter || key == keyPadEnter)
4170 if(editData && editData.visible && editData.active)
4172 HideEditBox(true, false, false);
4176 else if(key == escape)
4178 if(resizingField || movingFields || (editData && editData.visible) || dragRow)
4180 if(editData && editData.visible && style.alwaysEdit && !editData.active)
4182 // false: dont destroy edit box
4183 HideEditBox(false, false, false);
4186 resizingField.width = startWidth;
4187 AdaptToFieldWidth(resizingField, true);
4188 resizingField = null;
4201 movingFields = false;
4202 draggingField = null;
4208 if(!currentField || !currentField.editable)
4209 for(field = fields.first; field; field = field.next)
4213 currentField = field;
4217 if((key == f2 || (style.alwaysEdit && (key == ctrlV || key == ctrlC || key == ctrlX || key == shiftInsert || key == ctrlInsert || key == shiftDel))) &&
4218 currentField && currentField.editable)
4220 PopupEditBox(currentField, false);
4221 if(editData && editData.visible)
4223 if(style.alwaysEdit)
4225 editData.Activate();
4226 if(key == ctrlV || key == ctrlC || key == ctrlX || key == shiftInsert || key == ctrlInsert || key == shiftDel)
4228 editData.OnKeyHit(key, ch);
4232 // For Installer to pop up file dialog
4233 NotifyKeyDown(master, this, currentRow, key, ch);
4239 if(!NotifyKeyDown(master, this, currentRow, key, ch))
4242 // Editable fields...
4245 if(style.alwaysEdit && editData && editData.visible)
4246 return editData.OnKeyDown(key, ch);
4247 return true; // We want to pick up the OnKeyHit to replace contents, but skip GoToLetter
4250 if(ch >=32 && ch != 128 && !key.alt && !key.ctrl && GoToLetter(ch, false))
4252 /*if(inactive && window.state != Hidden)
4253 NotifyHighlight(master, this, currentRow, 0);
4256 NotifySelect(master, this, currentRow, 0);
4263 bool OnKeyHit(Key key, unichar ch)
4265 if(!ch && !key.alt && !key.ctrl)
4267 key.code = (SmartKey)key.code;
4269 if(ch >= 32 && !key.alt && !key.ctrl && ch != 128)
4272 if(!currentField || !currentField.editable)
4273 for(field = fields.first; field; field = field.next)
4277 currentField = field;
4281 if(currentField && currentField.editable)
4283 if((!editData || !editData.visible) || !editData.active)
4285 PopupEditBox(currentField, false);
4286 if(editData && editData.visible)
4288 editData.Activate();
4289 editData.OnKeyHit(key, ch);
4296 if(editData && editData.visible && ch && !key.alt && !key.ctrl && editData.active && (key.code != tab || (editData._class == class(EditBox) && ((EditBox)editData).tabKey)))
4299 if(!key.alt && (style.multiSelect || !key.ctrl))
4304 if(style.alwaysEdit)
4309 for(field = currentField.prev; field; field = field.prev)
4313 currentField = field;
4314 HideEditBox(true, true, false);
4315 PopupEditBox(currentField, false);
4321 if(style.collapse && currentRow /*&& !currentField*/) // THIS PREVENTED COLLAPSING THE PROPERTY SHEET
4323 if(currentRow.subRows.first && !currentRow.collapsed)
4325 currentRow.collapsed = true;
4327 else if(currentRow.parent)
4328 SetCurrentRow(currentRow.parent, true);
4333 if(style.collapse && currentRow && currentRow.subRows.first)
4335 if(currentRow.collapsed)
4336 currentRow.collapsed = false;
4338 SetCurrentRow(currentRow.subRows.first, true);
4341 else if(style.alwaysEdit)
4346 for(field = currentField.next; field; field = field.next)
4350 currentField = field;
4351 HideEditBox(true, true, false);
4352 PopupEditBox(currentField, false);
4360 case pageDown: case pageUp:
4361 case end: case home:
4363 int headerSize = ((style.header) ? rowHeight : 0);
4364 int height = clientSize.h + 1 - headerSize;
4367 // true: destroy edit box
4368 // !!! TESTING true HERE !!!
4369 HideEditBox(true, true, false);
4370 // HideEditBox(false, true, false);
4372 oldRow = currentRow;
4374 SNAPDOWN(height, rowHeight);
4375 if((!currentRow || key.code == home) && key.code != end)
4377 currentRow = rows.first;
4385 if(!(style.multiSelect) && currentRow && !currentRow.selectedFlag)
4388 next = currentRow.GetNextRow();
4395 if(!(style.multiSelect) && currentRow && !currentRow.selectedFlag)
4398 next = currentRow.GetPrevRow();
4406 currentRow = lastRow.GetLastRow();
4412 currentRow && (next = currentRow.GetPrevRow()) && c < height / rowHeight;
4413 c++, currentRow = next);
4420 currentRow && (next = currentRow.GetNextRow()) && c < height / rowHeight;
4421 c++, currentRow = next);
4426 if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
4427 SetScrollPosition(scroll.x, currentRow.index * rowHeight - height + rowHeight);
4428 else if(!currentRow || currentRow.index * rowHeight < scroll.y)
4429 SetScrollPosition(scroll.x, currentRow ? currentRow.index * rowHeight : 0);
4431 if(style.multiSelect)
4435 if(!(key.shift) && (key.ctrl))
4438 for(row = rows.first; row; row = row.GetNextRow())
4440 if(row.selectedFlag == tempSelected)
4441 row.selectedFlag = selected;
4442 else if(row.selectedFlag == tempUnselected)
4443 row.selectedFlag = unselected;
4449 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
4450 selRow.selectedFlag = unselected;
4454 for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
4456 if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
4457 else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
4463 if(currentRow.index >= clickedRow.index)
4465 for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
4469 if(selRow.selectedFlag) selRow.selectedFlag = tempUnselected; else selRow.selectedFlag = tempSelected;
4472 selRow.selectedFlag = selected;
4473 if(selRow == currentRow)
4479 for(selRow = currentRow; selRow; selRow = selRow.GetNextRow())
4483 if(selRow.selectedFlag) selRow.selectedFlag = tempUnselected; else selRow.selectedFlag = tempSelected;
4486 selRow.selectedFlag = selected;
4487 if(selRow == clickedRow)
4494 if(!(key.ctrl) && currentRow)
4496 currentRow.selectedFlag = selected;
4499 clickedRow = currentRow;
4504 if(oldRow) oldRow.selectedFlag = unselected;
4505 if(currentRow) currentRow.selectedFlag = selected;
4510 if(style.freeSelect)
4511 NotifyHighlight(master, this, currentRow, 0);
4513 NotifySelect(master, this, currentRow, 0);
4515 if(style.alwaysEdit && currentRow)
4516 currentRow.Edit(currentField /*null*/);
4523 if(style.multiSelect && currentRow)
4525 if(currentRow.selectedFlag)
4528 currentRow.selectedFlag = unselected;
4531 currentRow.selectedFlag = selected;
4534 if(style.freeSelect)
4535 NotifyHighlight(master, this, currentRow, 0);
4537 NotifySelect(master, this, currentRow, 0);
4544 if(!NotifyKeyHit(master, this, currentRow, key, ch))
4547 if(ch >=32 && ch != 128 && !key.alt && !key.ctrl && GoToLetter(ch, true))
4549 /*if(inactive && window.state != Hidden)
4550 return NotifyHighlight(master, this, currentRow, 0);
4553 return NotifySelect(master, this, currentRow, 0);
4560 void OnHScroll(ScrollBarAction action, int position, Key key)
4565 void OnVScroll(ScrollBarAction action, int position, Key key)
4570 for(firstRowShown = rows.first; firstRowShown; firstRowShown = next)
4572 next = firstRowShown.GetNextRow();
4573 if(y >= position || !next) break;
4583 DataRow firstRowShown;
4587 DataField sortField;
4591 double typingTimeOut;
4604 if(guiApp.GetKeyState(shift)) mods.shift = true;
4605 if(guiApp.GetKeyState(alt)) mods.alt = true;
4606 if(guiApp.GetKeyState(control)) mods.ctrl = true;
4607 OnMouseMove(MAXINT, MAXINT, mods);
4615 delay = 0.5; // typingTimeOut
4620 typedString[0] = '\0';
4622 // The next line was commented... Why? When commented typing words stops working ( only first character jumps )
4628 bool dragging, rolledOver;
4637 // For editing fields
4639 DataField currentField;
4642 // For moving fields
4643 DataField draggingField, dropField;
4646 // For resizing fields
4647 DataField resizingField;
4648 int resizeX, oldX, startWidth;
4651 FontResource boldFont;
4654 // Only used for OnMouseMove so far, for avoiding problems with consequential mouse moves
4655 bool insideNotifySelect;
4656 ColorAlpha selectionColor, selectionText, stippleColor;
4657 stippleColor = 0xFFFFFF80;