comparison mde/gui/WidgetManager.d @ 173:a1ba9157510e

Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 08 Aug 2009 15:53:10 +0200
parents 7f7b2011b759
children
comparison
equal deleted inserted replaced
172:0dd49f333189 173:a1ba9157510e
44 import mde.gui.widget.ParentContent; 44 import mde.gui.widget.ParentContent;
45 import mde.gui.widget.AParentWidget; 45 import mde.gui.widget.AParentWidget;
46 46
47 public import tango.core.sync.Mutex; 47 public import tango.core.sync.Mutex;
48 import tango.util.log.Log : Log, Logger; 48 import tango.util.log.Log : Log, Logger;
49 import tango.io.Console; // to print exception stack-trace
49 import tango.util.container.SortedMap; 50 import tango.util.container.SortedMap;
50 51
51 private Logger logger; 52 private Logger logger;
52 static this () { 53 static this () {
53 logger = Log.getLogger ("mde.gui.WidgetManager"); 54 logger = Log.getLogger ("mde.gui.WidgetManager");
91 // If call reaches the widget manager there isn't any recursion. 92 // If call reaches the widget manager there isn't any recursion.
92 //NOTE: should be override 93 //NOTE: should be override
93 final void recursionCheck (widgetID, IContent) {} 94 final void recursionCheck (widgetID, IContent) {}
94 95
95 override void minWChange (IChildWidget widget, wdim nmw) { 96 override void minWChange (IChildWidget widget, wdim nmw) {
96 if (widget !is childRoot) // Probably because widget is a popup widget 97 if (widget !is childRoot) { // Probably because widget is a popup widget
97 // This may get called from a CTOR, hence we can't check widget is one of childContext, etc. 98 // This may get called from a CTOR, hence we can't check widget is one of childContext, etc.
99 if (widget.width < nmw)
100 widget.setWidth (nmw, -1);
98 return; 101 return;
102 }
99 mw = nmw; 103 mw = nmw;
100 if (w < nmw) { 104 if (w < nmw) {
101 childRoot.setWidth (nmw, -1); 105 childRoot.setWidth (nmw, -1);
102 w = nmw; 106 w = nmw;
103 } 107 }
104 childRoot.setPosition (0,0); 108 childRoot.setPosition (0,0);
105 requestRedraw; 109 requestRedraw;
106 } 110 }
107 override void minHChange (IChildWidget widget, wdim nmh) { 111 override void minHChange (IChildWidget widget, wdim nmh) {
108 if (widget !is childRoot) 112 if (widget !is childRoot) {
113 if (widget.height < nmh)
114 widget.setHeight (nmh, -1);
109 return; 115 return;
116 }
110 mh = nmh; 117 mh = nmh;
111 if (h < nmh) { 118 if (h < nmh) {
112 childRoot.setHeight (nmh, -1); 119 childRoot.setHeight (nmh, -1);
113 h = nmh; 120 h = nmh;
114 } 121 }
116 requestRedraw; 123 requestRedraw;
117 } 124 }
118 //END IParentWidget methods 125 //END IParentWidget methods
119 126
120 //BEGIN IWidget methods 127 //BEGIN IWidget methods
121 override bool saveChanges () { 128 public override bool saveChanges () {
122 bool ret = childRoot.saveChanges; 129 bool ret = childRoot.saveChanges;
123 ret |= childContext.saveChanges; 130 ret |= childContext.saveChanges;
124 if (childDragged !is null) 131 if (childDragged !is null)
125 ret |= childDragged.saveChanges; 132 ret |= childDragged.saveChanges;
126 return ret; 133 return ret;
145 if (childIPPW) 152 if (childIPPW)
146 childIPPW.removedIPPW; 153 childIPPW.removedIPPW;
147 childIPPW = ippw; 154 childIPPW = ippw;
148 } 155 }
149 override bool removeChildIPPW (IPopupParentWidget ippw) { 156 override bool removeChildIPPW (IPopupParentWidget ippw) {
157 if (ippw is childContext && contextActive) {
158 childContext.removedIPPW;
159 contextActive = false;
160 return true;
161 }
150 if (childIPPW !is ippw) return false; 162 if (childIPPW !is ippw) return false;
151 childIPPW.removedIPPW; 163 childIPPW.removedIPPW;
152 childIPPW = null; 164 childIPPW = null;
153 mAIPPW = MenuPosition.INACTIVE; 165 mAIPPW = MenuPosition.INACTIVE;
154 requestRedraw; 166 requestRedraw;
155 return false; 167 return true;
156 } 168 }
157 169
158 override void menuActive (MenuPosition mA) { 170 override void menuActive (MenuPosition mA) {
159 mAIPPW = mA; 171 mAIPPW = mA;
160 if (childIPPW) 172 if (childIPPW)
178 if (contextActive) { 190 if (contextActive) {
179 ret = childContext.getPopupWidget (cx, cy, closePopup); 191 ret = childContext.getPopupWidget (cx, cy, closePopup);
180 if (ret) return ret; 192 if (ret) return ret;
181 if (closePopup) { 193 if (closePopup) {
182 childContext.removedIPPW; 194 childContext.removedIPPW;
195 contextActive = false;
183 requestRedraw; 196 requestRedraw;
184 } 197 }
185 } 198 }
186 if (childIPPW) { 199 if (childIPPW) {
187 ret = childIPPW.getPopupWidget (cx, cy, closePopup); 200 ret = childIPPW.getPopupWidget (cx, cy, closePopup);
192 } 205 }
193 return null; 206 return null;
194 } 207 }
195 208
196 override void drawPopup () { 209 override void drawPopup () {
210 if (childIPPW)
211 childIPPW.drawPopup;
197 if (contextActive) 212 if (contextActive)
198 childContext.draw(); 213 childContext.drawPopup();
199 if (childDragged) 214 if (childDragged)
200 childDragged.draw(); 215 childDragged.draw();
201 } 216 }
202 217
203 debug protected override bool isChild (IPopupParentWidget ippw) { 218 debug protected override bool isChild (IPopupParentWidget ippw) {
229 //pragma (msg, binarySearch ("type", WIDGETS)); 244 //pragma (msg, binarySearch ("type", WIDGETS));
230 mixin (binarySearch ("type", WIDGETS)); 245 mixin (binarySearch ("type", WIDGETS));
231 // Not returned a new widget: 246 // Not returned a new widget:
232 logger.error ("Bad widget type: {}; creating a debug widget instead",type); 247 logger.error ("Bad widget type: {}; creating a debug widget instead",type);
233 } catch (Exception e) { 248 } catch (Exception e) {
234 logger.error ("Error creating widget: {}; creating a debug widget instead.", e.msg); 249 logger.error ("Error creating widget; creating a debug widget instead. Exception printed to stderr.");
250 //TODO: find a standard way to output exceptions, and implement everywhere:
251 e.writeOut(delegate void(char[]s){ Cerr(s); });
235 } 252 }
236 253
237 return new DebugWidget (this, parent, id, data, content); 254 return new DebugWidget (this, parent, id, data, content);
238 } 255 }
239 256
292 } 309 }
293 if (x < 0) x = 0; // may be placed partially off-screen 310 if (x < 0) x = 0; // may be placed partially off-screen
294 if (y < 0) y = 0; 311 if (y < 0) y = 0;
295 popup.setPosition (x, y); 312 popup.setPosition (x, y);
296 debug if (Debug.logPopupPositioning()) 313 debug if (Debug.logPopupPositioning())
297 logger.trace ("Placed popup {}; output position: {}", popup, position); 314 logger.trace ("Placed popup {} of size ({},{}) at ({},{}); output position: {}", popup, w,h, x,y, position);
298 return position; 315 return position;
299 } 316 }
300 317
301 void requestRedraw () { 318 void requestRedraw () {
302 imde.mainSchedule.request(imde.SCHEDULE.DRAW); 319 imde.mainSchedule.request(imde.SCHEDULE.DRAW);
350 367
351 /** Draw all widgets */ 368 /** Draw all widgets */
352 final void wmDrawWidgets() { 369 final void wmDrawWidgets() {
353 if (childRoot) 370 if (childRoot)
354 childRoot.draw; 371 childRoot.draw;
355 if (childIPPW)
356 childIPPW.drawPopup;
357 drawPopup; 372 drawPopup;
358 } 373 }
359 374
360 /** For mouse click events. 375 /** For mouse click events.
361 * 376 *