3 class CheckListBoxButton : Button
5 isCheckbox = true, inactive = true, size = { 12, 12 };
7 bool CheckListBox::NotifyPushed(Button button, int x, int y, Modifiers mods)
9 currentRow = (DataRow)button.id;
10 ToggleCheck(currentRow);
14 bool CheckListBox::NotifyReleased(Button button, int x, int y, Modifiers mods)
19 bool OnMouseOver(int x, int y, Modifiers mods)
25 bool OnMouseLeave(Modifiers mods)
32 class CheckListBox : ListBox
34 Map<int, CheckListBoxButton> buttonMaps { };
35 AVLTree<DataRow> rowChecks { };
40 fullRowSelect = false, collapseControl = true, treeBranches = true, rootCollapseButton = true,
46 buttonMaps.RemoveAll();
49 bool NotifyCollapse(CheckListBox listBox, DataRow row, bool collapsed)
52 for(r = row.firstRow; r && r != row; )
56 MapIterator<int, Button> it { map = listBox.buttonMaps };
57 if(it.Index((int)r, false))
59 Button checkBox = it.data;
69 listBox.SetupButtons(r, false);
71 if(r.firstRow && !r.collapsed)
74 for(; r != row; r = r.parent)
75 if(r.next) { r = r.next; break; }
77 for(r = row.GetNextRow(); r; r = r.GetNextRow())
79 Button checkBox = listBox.buttonMaps[(int)r];
80 checkBox.position.y = 1 + (r.index + listBox.hasHeader) * listBox.rowHeight;
85 bool CheckPartialChecks(DataRow row)
88 for(r = row.firstRow; r; r = r.next)
90 if(rowChecks.Find(r) || CheckPartialChecks(r))
96 void SetupButtons(DataRow row, bool recurse)
99 CheckListBoxButton button;
100 int indent = checkIndent;
102 for(parent = row.parent; parent; parent = parent.parent) indent += 20;
103 button = buttonMaps[(int)row];
104 if(!button) button = CheckListBoxButton { this };
105 button.position = { 2 + indent, 1+(row.index + hasHeader) * rowHeight };
106 button.id = (int)row;
108 for(parent = row; parent; parent = parent.parent) if(rowChecks.Find(parent)) break;
111 button.checked = true;
112 button.buttonState = up;
116 button.checked = CheckPartialChecks(row);
117 button.buttonState = button.checked ? down : up;
120 buttonMaps[(int)row] = button;
121 if(recurse && !row.collapsed)
124 for(r = row.firstRow; r; r = r.next)
125 SetupButtons(r, recurse);
132 for(row = firstRow; row; row = row.next)
133 SetupButtons(row, true);
138 if(ListBox::OnCreate())
142 buttonMaps.RemoveAll();
144 for(row = firstRow; row; row = row.next)
145 SetupButtons(row, true);
151 void ToggleCheck(DataRow row)
153 CheckListBoxButton checkBox = buttonMaps[(int)row];
156 bool checked = false;
158 for(r = row; r; r = r.parent)
159 if(rowChecks.Find(r))
164 SetCheck(row, !checked);
168 void UncheckBoxes(DataRow row)
170 CheckListBoxButton button = buttonMaps[(int)row];
171 if(button) { button.checked = false; button.buttonState = up; }
175 for(r = row.firstRow; r; r = r.next)
180 void UnsetChildren(DataRow row)
183 CheckListBoxButton button = buttonMaps[(int)row];
184 if(button) { button.checked = true; button.buttonState = up; }
186 for(r = row.firstRow; r; r = r.next)
188 Iterator<DataRow> it { rowChecks };
195 void SetCheck(DataRow row, bool checked)
198 bool wasChecked = false;
200 for(parent = row; parent; parent = parent.parent)
202 if(rowChecks.Find(parent)) { wasChecked = true; break; }
204 if(checked != wasChecked)
206 modifiedDocument = true;
207 // NotifyChanged(master, this, row);
210 // Check if all siblings are checked, if so go up until we reach a row not fully checked
214 for(r = row.parent.firstRow; r; r = r.next)
216 if(r != row && !rowChecks.Find(r))
219 if(r || !row.parent) break;
223 // Take out all children from rowChecks, checking them all
228 for(parent = row.parent; parent; parent = parent.parent)
231 CheckListBoxButton button = buttonMaps[(int)parent];
234 button.checked = true;
235 button.buttonState = down;
247 Iterator<DataRow> it { rowChecks };
256 for(r = row.parent.firstRow; r; r = r.next)
265 for(; parent; parent = parent.parent)
267 CheckListBoxButton button = buttonMaps[(int)parent];
270 if(CheckPartialChecks(parent))
272 button.checked = true;
273 button.buttonState = down;
277 button.checked = false;
278 button.buttonState = up;
284 NotifyChanged(master, this, row);
288 bool NotifyKeyDown(CheckListBox listBox, DataRow row, Key key, unichar ch)
292 listBox.ToggleCheck(row);
298 bool OnKeyHit(Key key, unichar ch)
302 return ListBox::OnKeyHit(key, ch);
305 bool NotifyDoubleClick(CheckListBox listBox, int x, int y, Modifiers mods)
307 listBox.OnLeftButtonDown(x, y, mods);
311 bool NotifyReclick(CheckListBox listBox, DataRow row, Modifiers mods)
313 if(row == listBox.currentRow)
314 listBox.ToggleCheck(row);
318 // virtual void Window::NotifyChecked(CheckListBox listBox, DataRow row);