comparison dynamin/gui/list_box.d @ 55:c138461bf845

Add focusing and other changes that are related like descendantAdded/Removed events, Window.activated event, and updating List. Window.state was also added, even though focusing does not depend on it.
author Jordan Miner <jminer7@gmail.com>
date Sat, 08 Aug 2009 15:42:27 -0500
parents ccc108b25a0a
children 651082a9b364
comparison
equal deleted inserted replaced
54:3738a2d0bac3 55:c138461bf845
36 * 36 *
37 * $(IMAGE ../web/example_list_box.png) 37 * $(IMAGE ../web/example_list_box.png)
38 */ 38 */
39 class ListBox : Scrollable { 39 class ListBox : Scrollable {
40 protected: 40 protected:
41 List!(string) _items; 41 List!(string, true) _items;
42 int _selectedIndex = -1; 42 int _selectedIndex = -1;
43 43
44 override void whenKeyDown(KeyEventArgs e) { 44 override void whenKeyDown(KeyEventArgs e) {
45 if(e.key == Key.Down) { 45 if(e.key == Key.Down) {
46 if(selectedIndex + 1 < _items.count) 46 if(selectedIndex + 1 < _items.count)
81 /// Override this method in a subclass to handle the selectionChanged event. 81 /// Override this method in a subclass to handle the selectionChanged event.
82 protected void whenSelectionChanged(EventArgs e) { } 82 protected void whenSelectionChanged(EventArgs e) { }
83 /// This event occurs after the selection has changed. 83 /// This event occurs after the selection has changed.
84 Event!(whenSelectionChanged) selectionChanged; 84 Event!(whenSelectionChanged) selectionChanged;
85 85
86 void listItemsChanged() { 86 void whenListItemsChanged(string, int) {
87 super.layout(); 87 super.layout();
88 repaint(); 88 repaint();
89 } 89 }
90 90
91 /// 91 ///
92 this() { 92 this() {
93 selectionChanged.mainHandler = &whenSelectionChanged; 93 selectionChanged.mainHandler = &whenSelectionChanged;
94 _items = new List!(string)(&listItemsChanged); 94 _items = new List!(string, true)(&whenListItemsChanged, &whenListItemsChanged);
95 95
96 super(); 96 super();
97 _focusable = true; 97 _focusable = true;
98 // TODO: hack 98 // TODO: hack
99 backColor = WindowsTheme.getColor(5); 99 backColor = WindowsTheme.getColor(5);
100 } 100 }
101 /// 101 ///
102 List!(string) items() { 102 List!(string, true) items() {
103 return _items; 103 return _items;
104 } 104 }
105 /// 105 ///
106 int selectedIndex() { return _selectedIndex; } 106 int selectedIndex() { return _selectedIndex; }
107 /// ditto 107 /// ditto