diff mde/gui/widget/Widget.d @ 121:5b37d0400732

Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed. WidgetManager code redistributed between classes; WMScreen class moved to WMScreen.d. addContent function now calls makeWidget with another id.
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 02 Jan 2009 18:07:10 +0000
parents aba2dd815a1f
children d3b2cefd46c9
line wrap: on
line diff
--- a/mde/gui/widget/Widget.d	Thu Jan 01 15:16:00 2009 +0000
+++ b/mde/gui/widget/Widget.d	Fri Jan 02 18:07:10 2009 +0000
@@ -47,11 +47,23 @@
  *************************************************************************************************/
 abstract class AWidget : IChildWidget
 {
+//BEGIN IParentWidget methods
+    // Don't override; use the WIDGET_TYPE.SAFE_RECURSION flag for safe widgets.
+    //NOTE: should be override (compiler bug)
+    final void recursionCheck (widgetID a) {
+        debug assert (id !is null && parent !is null, "recursionCheck called before parent and id set");
+        if (a is id)
+            throw new GuiException ("Infite recursion of "~a);
+        parent.recursionCheck (a);
+    }
+//END IParentWidget methods
+    
 //BEGIN Load and save
     // Base this() for child Widgets.
-    protected this (IWidgetManager mgr, widgetID id, WidgetData) {
-        this.mgr = mgr;
-        this.id = id;
+    protected this (IWidgetManager mgr, IParentWidget parent, widgetID id) {
+        this.mgr	= mgr;
+        this.parent	= parent;
+        this.id		= id;
     }
     
     // Widgets need to do their initialization either in this() or setup().
@@ -183,9 +195,10 @@
 	    throw new ContentException (this);
     }
     
+    IWidgetManager mgr;		// the enclosing window
+    IParentWidget parent;	// the parent widget
+    wdim x, y;			// position
     widgetID id;                // The widget's ID, used for saving data
-    IWidgetManager mgr;		// the enclosing window
-    wdim x, y;			// position
     wdim w, h;			// size
     wdim mw = 0, mh = 0;	// minimal or fixed size, depending on whether the widget is
     				// resizible; both types of widgets should actually be expandable.
@@ -199,12 +212,13 @@
  *************************************************************************************************/
 abstract class AParentWidget : AWidget
 {
-    this (IWidgetManager mgr, widgetID id, WidgetData data) {
-        super (mgr, id, data);
+    this (IWidgetManager mgr, IParentWidget parent, widgetID id) {
+        super (mgr, parent, id);
     }
     
     override bool setup (uint n, uint flags) {
-	bool c = false;
+        debug (mdeWidgets) logger.trace ("AParentWidget.setup");
+        bool c = false;
 	foreach (w; subWidgets) {
 	    debug assert (w);
 	    c |= w.setup (n,flags);
@@ -225,12 +239,13 @@
 /** ditto */
 abstract class AParentSingleWidget : AWidget
 {
-    this (IWidgetManager mgr, widgetID id, WidgetData data) {
-	super (mgr, id, data);
+    this (IWidgetManager mgr, IParentWidget parent, widgetID id) {
+        super (mgr, parent, id);
     }
     
     override bool setup (uint n, uint flags) {
-	debug assert (subWidget);
+        debug (mdeWidgets) logger.trace ("AParentSingleWidget.setup");
+        debug assert (subWidget);
 	return subWidget.setup (n,flags);
     }
     
@@ -250,8 +265,8 @@
      * Widget uses the initialisation data:
      * [widgetID, w, h]
      * where w, h is the fixed size. */
-    this (IWidgetManager mgr, widgetID id, WidgetData data) {
-        super (mgr, id, data);
+    this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data) {
+        super (mgr, parent, id);
         w = mw = cast(wdim) data.ints[1];
         h = mh = cast(wdim) data.ints[2];
     }
@@ -261,8 +276,8 @@
 class SizableWidget : AWidget {
     // Check data.length is at least 1 before calling!
     /// Constructor for a completely resizable [blank] widget.
-    this (IWidgetManager mgr, widgetID id, WidgetData data) {
-        super (mgr, id, data);
+    this (IWidgetManager mgr, IParentWidget parent, widgetID id) {
+        super (mgr, parent, id);
     }
     
     override bool isWSizable () {    return true;    }
@@ -274,8 +289,8 @@
  * Overriding classes should implement this() (setting the size), draw() and activated(). */
 abstract class AButtonWidget : AWidget
 {
-    protected this (IWidgetManager mgr, widgetID id, WidgetData data) {
-        super (mgr, id, data);
+    protected this (IWidgetManager mgr, IParentWidget parent, widgetID id) {
+        super (mgr, parent, id);
     }
     
     /// May be over-ridden. Pushed is true if the button has been pushed and not released.