comparison mde/gui/WidgetManager.d @ 166:55667d048c31

Made content displayable while being dragged.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sun, 21 Jun 2009 12:19:18 +0200
parents bb2f1a76346d
children 620d4ea30228
comparison
equal deleted inserted replaced
165:bb2f1a76346d 166:55667d048c31
83 // If call reaches the widget manager there isn't any recursion. 83 // If call reaches the widget manager there isn't any recursion.
84 //NOTE: should be override 84 //NOTE: should be override
85 final void recursionCheck (widgetID, IContent) {} 85 final void recursionCheck (widgetID, IContent) {}
86 86
87 override void minWChange (IChildWidget widget, wdim nmw) { 87 override void minWChange (IChildWidget widget, wdim nmw) {
88 debug assert (widget is child, "WM.mSC (code error)"); 88 if (widget !is child) // Usually because widget is a floating widget
89 // This may get called from a CTOR, hence we can't check widget is one of popupContext, etc.
90 return;
89 mw = nmw; 91 mw = nmw;
90 if (w < nmw) { 92 if (w < nmw) {
91 child.setWidth (nmw, -1); 93 child.setWidth (nmw, -1);
92 w = nmw; 94 w = nmw;
93 } 95 }
94 child.setPosition (0,0); 96 child.setPosition (0,0);
95 requestRedraw; 97 requestRedraw;
96 } 98 }
97 override void minHChange (IChildWidget widget, wdim nmh) { 99 override void minHChange (IChildWidget widget, wdim nmh) {
98 debug assert (widget is child, "WM.mSC (code error)"); 100 if (widget !is child)
101 return;
99 mh = nmh; 102 mh = nmh;
100 if (h < nmh) { 103 if (h < nmh) {
101 child.setHeight (nmh, -1); 104 child.setHeight (nmh, -1);
102 h = nmh; 105 h = nmh;
103 } 106 }
169 } 172 }
170 173
171 override void drawPopup () { 174 override void drawPopup () {
172 if (popupContext) 175 if (popupContext)
173 popupContext.draw(); 176 popupContext.draw();
177 if (dragContentDisplay)
178 dragContentDisplay.draw();
174 } 179 }
175 180
176 debug protected override bool isChild (IPopupParentWidget ippw) { 181 debug protected override bool isChild (IPopupParentWidget ippw) {
177 return ippw is childIPPW; 182 return ippw is childIPPW;
178 } 183 }
203 logger.error ("Bad widget type: {}; creating a debug widget instead",type); 208 logger.error ("Bad widget type: {}; creating a debug widget instead",type);
204 } catch (Exception e) { 209 } catch (Exception e) {
205 logger.error ("Error creating widget: {}; creating a debug widget instead.", e.msg); 210 logger.error ("Error creating widget: {}; creating a debug widget instead.", e.msg);
206 } 211 }
207 212
208 return new DebugWidget (this, this, id, data, content); 213 return new DebugWidget (this, parent, id, data, content);
209 } 214 }
210 215
211 override WidgetData widgetData (widgetID id) { 216 override WidgetData widgetData (widgetID id) {
212 return curData[id]; 217 return curData[id];
213 } 218 }
297 // Update underMouse to get the widget clicked on 302 // Update underMouse to get the widget clicked on
298 updateUnderMouse (cx, cy, state); 303 updateUnderMouse (cx, cy, state);
299 304
300 // end of a drag? 305 // end of a drag?
301 if (dragStart !is null && b == dragButton && state == false) { 306 if (dragStart !is null && b == dragButton && state == false) {
302 if (dragStart.dragRelease (cx, cy, underMouse)) { 307 IChildWidget dS = dragStart;
303 dragStart = null; 308 dragStart = null;
309 dragContentDisplay = null;
310 requestRedraw;
311 if (dS.dragRelease (cx, cy, underMouse))
304 return; 312 return;
305 }
306 dragStart = null;
307 } 313 }
308 314
309 // Disable keyboard input if on another widget: 315 // Disable keyboard input if on another widget:
310 if (keyFocus && keyFocus !is underMouse) { 316 if (keyFocus && keyFocus !is underMouse) {
311 keyFocus.keyFocusLost; 317 keyFocus.keyFocusLost;
329 setLetterCallback (&underMouse.keyEvent); 335 setLetterCallback (&underMouse.keyEvent);
330 } 336 }
331 if (ret & 2 && dragStart is null) { // drag events requested 337 if (ret & 2 && dragStart is null) { // drag events requested
332 dragStart = underMouse; 338 dragStart = underMouse;
333 dragButton = b; // currently we allow any button to be used for a drag, but.. ? 339 dragButton = b; // currently we allow any button to be used for a drag, but.. ?
340 if (ret & 4) {
341 IContent c = underMouse.content();
342 if (c) { // NOTE: creates a new widget, not optimal
343 dragContentDisplay = new DisplayContentWidget (this, this, "dragContentDisplay", WidgetData ([0], []), c);
344 dragContentDisplay.setup (0, 3);
345 dragX = underMouse.xPos - cx;
346 dragY = underMouse.yPos - cy;
347 dragContentDisplay.setPosition (cx + dragX, cy + dragY);
348 }
349 }
334 } 350 }
335 } 351 }
336 } 352 }
337 353
338 /** For mouse motion events. 354 /** For mouse motion events.
339 * 355 *
340 * Lock on mutex before calling. Pass new mouse coordinates. */ 356 * Lock on mutex before calling. Pass new mouse coordinates. */
341 void wmMouseMotion (wdabs cx, wdabs cy) { 357 void wmMouseMotion (wdabs cx, wdabs cy) {
342 updateUnderMouse (cx, cy, false); 358 updateUnderMouse (cx, cy, false);
343 359
344 if (dragStart !is null) 360 if (dragStart !is null) {
345 dragStart.dragMotion (cx, cy, underMouse); 361 dragStart.dragMotion (cx, cy, underMouse);
362 if (dragContentDisplay !is null) {
363 dragContentDisplay.setPosition (cx + dragX, cy + dragY);
364 requestRedraw;
365 }
366 }
346 } 367 }
347 368
348 369
349 /** A change callback on MiscOptions.l10n content to update widgets. 370 /** A change callback on MiscOptions.l10n content to update widgets.
350 * 371 *
501 MenuPosition mAIPPW; // IPPW variable 522 MenuPosition mAIPPW; // IPPW variable
502 IPopupParentWidget childIPPW; // child IPPW, if any active 523 IPopupParentWidget childIPPW; // child IPPW, if any active
503 524
504 // Popup(s) handled directly by AWidgetManager: 525 // Popup(s) handled directly by AWidgetManager:
505 IChildWidget popupContext; // context menu (active if not null) 526 IChildWidget popupContext; // context menu (active if not null)
527 IChildWidget dragContentDisplay; // displays dragged content; no interaction
506 528
507 IChildWidget dragStart; // if non-null, this widget should receive motion and click-release events 529 IChildWidget dragStart; // if non-null, this widget should receive motion and click-release events
508 int dragButton; // index of button in use for drag 530 int dragButton; // index of button in use for drag
531 wdrel dragX, dragY; // coordinates of dragged content relative to mouse
532
509 IChildWidget keyFocus; // widget receiving keyboard input 533 IChildWidget keyFocus; // widget receiving keyboard input
510 IChildWidget underMouse; // widget under the mouse pointer 534 IChildWidget underMouse; // widget under the mouse pointer
511 535
512 Mutex mutex; // lock on methods for use outside the package. 536 Mutex mutex; // lock on methods for use outside the package.
513 } 537 }