Mercurial > projects > dynamin
comparison dynamin/gui/container.d @ 62:60832e1eef04
Implement default buttons.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Sat, 08 Aug 2009 20:35:20 -0500 |
parents | 712ea1ea845a |
children | 6580fabb7dce |
comparison
equal
deleted
inserted
replaced
61:f8f5d6244795 | 62:60832e1eef04 |
---|---|
28 import dynamin.all_core; | 28 import dynamin.all_core; |
29 import dynamin.all_painting; | 29 import dynamin.all_painting; |
30 import dynamin.all_gui; | 30 import dynamin.all_gui; |
31 import dynamin.gui.control; | 31 import dynamin.gui.control; |
32 import dynamin.gui.events; | 32 import dynamin.gui.events; |
33 import dynamin.gui.button; | |
33 import tango.io.Stdout; | 34 import tango.io.Stdout; |
34 | 35 |
35 alias List!(Control, true) ControlList; | 36 alias List!(Control, true) ControlList; |
36 | 37 |
37 /// | 38 /// |
38 class Container : Control { | 39 class Container : Control { |
39 protected: | 40 protected: |
40 ControlList _children; | 41 ControlList _children; |
41 Size _minSize; | 42 Size _minSize; |
42 Size _maxSize; | 43 Size _maxSize; |
44 Button _defaultButton; | |
43 | 45 |
44 override void whenResized(EventArgs e) { | 46 override void whenResized(EventArgs e) { |
45 layout(); | 47 layout(); |
46 } | 48 } |
47 // If the specified array is large enough to hold the results, no heap | 49 // If the specified array is large enough to hold the results, no heap |
123 scope e = new HierarchyEventArgs(child); | 125 scope e = new HierarchyEventArgs(child); |
124 descendantRemoved(e); | 126 descendantRemoved(e); |
125 } | 127 } |
126 | 128 |
127 void dispatchDescendantAdded(HierarchyEventArgs e) { | 129 void dispatchDescendantAdded(HierarchyEventArgs e) { |
130 if(e.descendant is defaultButton) | |
131 (cast(Button)e.descendant)._isDefault = true; | |
132 | |
128 descendantAdded.callHandlers(e); | 133 descendantAdded.callHandlers(e); |
129 descendantAdded.callMainHandler(e); | 134 descendantAdded.callMainHandler(e); |
130 e.levels = e.levels + 1; | 135 e.levels = e.levels + 1; |
131 if(_parent) | 136 if(_parent) |
132 _parent.descendantAdded(e); | 137 _parent.descendantAdded(e); |
136 descendantRemoved.callMainHandler(e); | 141 descendantRemoved.callMainHandler(e); |
137 e.levels = e.levels + 1; | 142 e.levels = e.levels + 1; |
138 if(_parent) | 143 if(_parent) |
139 _parent.descendantRemoved(e); | 144 _parent.descendantRemoved(e); |
140 } | 145 } |
146 | |
147 override void whenKeyDown(KeyEventArgs e) { | |
148 if(e.key == Key.Enter && defaultButton) { | |
149 scope e2 = new EventArgs; | |
150 defaultButton.clicked(e2); | |
151 e.stopped = true; | |
152 } | |
153 } | |
154 | |
141 public: | 155 public: |
142 /// Override this method in a subclass to handle the minSizeChanged event. | 156 /// Override this method in a subclass to handle the minSizeChanged event. |
143 protected void whenMinSizeChanged(EventArgs e) { } | 157 protected void whenMinSizeChanged(EventArgs e) { } |
144 /// This event occurs after the control's minimum size has been changed. | 158 /// This event occurs after the control's minimum size has been changed. |
145 Event!(whenMinSizeChanged) minSizeChanged; | 159 Event!(whenMinSizeChanged) minSizeChanged; |
170 _children = new ControlList(&whenChildAdded, &whenChildRemoved); | 184 _children = new ControlList(&whenChildAdded, &whenChildRemoved); |
171 | 185 |
172 elasticX = true; | 186 elasticX = true; |
173 elasticY = true; | 187 elasticY = true; |
174 } | 188 } |
189 | |
190 /** | |
191 * Gets or sets the default button in this container. | |
192 */ | |
193 Button defaultButton() { return _defaultButton; } | |
194 /// ditto | |
195 void defaultButton(Button b) { | |
196 _defaultButton = b; | |
197 foreach(d; &descendants) { | |
198 if(b == d) | |
199 b._isDefault = true; | |
200 } | |
201 } | |
202 | |
175 override void dispatchPainting(PaintingEventArgs e) { | 203 override void dispatchPainting(PaintingEventArgs e) { |
176 super.dispatchPainting(e); | 204 super.dispatchPainting(e); |
177 foreach(c; _children) { | 205 foreach(c; _children) { |
178 e.graphics.save(); | 206 e.graphics.save(); |
179 e.graphics.translate(c.x, c.y); | 207 e.graphics.translate(c.x, c.y); |