comparison mde/gui/widget/ParentContent.d @ 170:e45226d3deae

Context menu services not applicable to the current type can now be hidden. Added files missing from previous commits.
author Diggory Hardy <diggory.hardy@gmail.com>
date Mon, 29 Jun 2009 21:20:16 +0200
parents da8d3091fdaf
children 0dd49f333189
comparison
equal deleted inserted replaced
169:bc1cf73dc835 170:e45226d3deae
122 mgr.renderer.drawButton (x,y, w,h, pushed); 122 mgr.renderer.drawButton (x,y, w,h, pushed);
123 adapter.draw (x,y); 123 adapter.draw (x,y);
124 } 124 }
125 125
126 protected: 126 protected:
127 void updateVal (Content) { // callback 127 void updateVal (IContent) { // callback
128 adapter.text = content_.toString(cIndex); 128 adapter.text = content_.toString(cIndex);
129 wdim omw = mw, omh = mh; 129 wdim omw = mw, omh = mh;
130 adapter.getDimensions (mw, mh); 130 adapter.getDimensions (mw, mh);
131 if (omw != mw) 131 if (omw != mw)
132 parent.minWChange (this, mw); 132 parent.minWChange (this, mw);
184 } 184 }
185 } 185 }
186 return r; 186 return r;
187 } 187 }
188 188
189 override void recursionCheck (widgetID wID, IContent c) {
190 if (wID is id && c is content_)
191 throw new WidgetRecursionException (wID);
192 parent.recursionCheck (wID, c);
193 }
194
189 override void minWChange (IChildWidget widget, wdim nmw) { 195 override void minWChange (IChildWidget widget, wdim nmw) {
190 if (widget !is currentW) return; 196 if (widget !is currentW) return;
191 mw = nmw; 197 mw = nmw;
192 parent.minWChange (this, nmw); 198 parent.minWChange (this, nmw);
193 } 199 }
227 currentW.draw; 233 currentW.draw;
228 } 234 }
229 235
230 protected: 236 protected:
231 // callback on content_ 237 // callback on content_
232 void switchWidget (Content) { 238 void switchWidget (IContent) {
233 currentW = subWidgets[content_()]; 239 currentW = subWidgets[content_()];
234 mw = currentW.minWidth; 240 mw = currentW.minWidth;
235 mh = currentW.minHeight; 241 mh = currentW.minHeight;
236 parent.minWChange (this, mw); 242 parent.minWChange (this, mw);
237 parent.minHChange (this, mh); 243 parent.minHChange (this, mh);
247 EnumContent content_; 253 EnumContent content_;
248 254
249 bool isWS, isHS; // no infrastructure for changing sizability, so need to fix it. 255 bool isWS, isHS; // no infrastructure for changing sizability, so need to fix it.
250 } 256 }
251 257
252 /** A collapsible widget: shows/hides a child dependant on a BoolContent. 258 /** A collapsible widget: shows/hides a child dependant on an IBoolContent.
253 * 259 *
254 * Sizability is set once. Min-size is changed (but cannot force size to 0). 260 * Sizability is set once. Min-size is changed (but cannot force size to 0).
255 * 261 *
256 * Uses its content as a switch, which means content cannot be passed through. 262 * Uses its content as a switch, which means content cannot be passed through.
257 * A builtin button would improve this. */ 263 * A builtin button would improve this. */
258 class CollapsibleWidget : AParentWidget 264 class CollapsibleWidget : AParentWidget
259 { 265 {
260 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) { 266 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
261 super (mgr, parent, id); 267 super (mgr, parent, id);
262 content_ = cast(BoolContent) c; 268 content_ = cast(IBoolContent) c;
263 WDCCheck (data, 1, 1, content_); 269 WDCCheck (data, 1, 1, content_);
264 270
265 subWidgets = [mgr.makeWidget (this, data.strings[0], c)]; 271 subWidgets = [mgr.makeWidget (this, data.strings[0], c)];
266 272
267 content_.addCallback (&collapse); 273 content_.addCallback (&collapse);
279 } 285 }
280 } 286 }
281 return r; 287 return r;
282 } 288 }
283 289
290 override void recursionCheck (widgetID wID, IContent c) {
291 if (wID is id && c is content_)
292 throw new WidgetRecursionException (wID);
293 parent.recursionCheck (wID, c);
294 }
295
284 override IContent content () { 296 override IContent content () {
285 return content_; 297 return content_;
286 } 298 }
287 299
288 override void minWChange (IChildWidget widget, wdim nmw) { 300 override void minWChange (IChildWidget widget, wdim nmw) {
329 if (!collapsed) subWidgets[0].draw; 341 if (!collapsed) subWidgets[0].draw;
330 } 342 }
331 343
332 protected: 344 protected:
333 // callback on content_ 345 // callback on content_
334 void collapse (Content) { 346 void collapse (IContent) {
335 collapsed = content_(); 347 collapsed = content_();
336 if (collapsed) { 348 if (collapsed) {
337 mw = mh = 0; 349 mw = mh = 0;
338 } else { 350 } else {
339 mw = subWidgets[0].minWidth; 351 mw = subWidgets[0].minWidth;
347 subWidgets[0].setHeight (h, -1); 359 subWidgets[0].setHeight (h, -1);
348 subWidgets[0].setPosition (x,y); 360 subWidgets[0].setPosition (x,y);
349 } 361 }
350 362
351 bool collapsed = false; 363 bool collapsed = false;
352 BoolContent content_; 364 IBoolContent content_;
353 } 365 }
354 366
355 /** Puts a border around its child widget. 367 /** Puts a border around its child widget.
356 * 368 *
357 * This doesn't allow dragging like widgets in a floating area. 369 * This doesn't allow dragging like widgets in a floating area.