diff mde/gui/widget/ParentContent.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 0dd49f333189
children 3d58adc17d20
line wrap: on
line diff
--- a/mde/gui/widget/ParentContent.d	Wed Jul 29 20:28:22 2009 +0200
+++ b/mde/gui/widget/ParentContent.d	Sat Aug 08 15:53:10 2009 +0200
@@ -196,14 +196,22 @@
     }
     
     override void minWChange (IChildWidget widget, wdim nmw) {
-        if (widget !is currentW) return;
-        mw = nmw;
-        parent.minWChange (this, nmw);
+        if (widget is currentW) {
+	    mw = nmw;
+	    parent.minWChange (this, nmw);
+	} else {	// changes won't be seen, but we must follow function spec
+	    if (widget.width < nmw)
+		widget.setWidth (nmw, -1);
+	}
     }
     override void minHChange (IChildWidget widget, wdim nmh) {
-        if (widget !is currentW) return;
-        mh = nmh;
-        parent.minHChange (this, nmh);
+        if (widget is currentW) {
+	    mh = nmh;
+	    parent.minHChange (this, nmh);
+	} else {
+	    if (widget.height < nmh)
+		widget.setHeight (nmh, -1);
+	}
     }
     
     override bool isWSizable () {
@@ -273,14 +281,14 @@
         
         subWidgets = [mgr.makeWidget (this, data.strings[0], c)];
         
-        content_.addCallback (&collapse);
+        content_.addCallback (&cbDisplay);
     }
     
     override bool setup (uint n, uint flags) {
         bool r = super.setup (n, flags);
         if (r) {
-            collapsed = content_();
-            if (!collapsed) {
+            display = content_();
+            if (display) {
             	mw = subWidgets[0].minWidth;
             	mh = subWidgets[0].minHeight;
             	w = subWidgets[0].width;
@@ -306,7 +314,7 @@
 	    return;
 	}
 	content_ = cont;
-	collapse (content_);
+	cbDisplay (content_);
     }
     
     override void minWChange (IChildWidget widget, wdim nmw) {
@@ -330,50 +338,51 @@
     
     override void setWidth (wdim nw, int dir) {
 	w = (nw >= mw ? nw : mw);
-        if (!collapsed) subWidgets[0].setWidth (w, dir);
+        subWidgets[0].setWidth (w, dir);
     }
     override void setHeight (wdim nh, int dir) {
         h = (nh >= mh ? nh : mh);
-        if (!collapsed) subWidgets[0].setHeight (h, dir);
+        subWidgets[0].setHeight (h, dir);
     }
     
     override void setPosition (wdim nx, wdim ny) {
         x = nx;
         y = ny;
-        if (!collapsed) subWidgets[0].setPosition (nx,ny);
+	if (display) subWidgets[0].setPosition (nx,ny);
     }
     
     override IChildWidget getWidget (wdim cx, wdim cy) {
-        if (!collapsed)
+        if (display)
             return subWidgets[0].getWidget (cx, cy);
         else return this;
     }
     
     override void draw () {
-        if (!collapsed) subWidgets[0].draw;
+        if (display) subWidgets[0].draw;
     }
     
 protected:
     // callback on content_
-    void collapse (IContent) {
-	if (collapsed == content_()) return;
-        collapsed = content_();
-        if (collapsed) {
-            mw = mh = 0;
-        } else {
+    void cbDisplay (IContent) {
+	if (display == content_()) return;
+        display = content_();
+	logger.trace ("{}.cbDisplay ({})", id, display);
+        if (display) {
             mw = subWidgets[0].minWidth;
             mh = subWidgets[0].minHeight;
+        } else {
+            mw = mh = 0;
         }
         parent.minWChange (this, mw);
         parent.minHChange (this, mh);
-        if (collapsed) return;
+        if (!display) return;
     	// set incase parent didn't:
         subWidgets[0].setWidth (w, -1);
         subWidgets[0].setHeight (h, -1);
         subWidgets[0].setPosition (x,y);
     }
     
-    bool collapsed = false;
+    bool display = false;
     IBoolContent content_;
 }
 
@@ -435,12 +444,12 @@
     override void minWChange (IChildWidget widget, wdim nmw) {
         debug assert (widget is subWidgets[0]);
         mw = nmw + border.x1 + border.x2;
-        parent.minWChange (this, nmw);
+        parent.minWChange (this, mw);
     }
     override void minHChange (IChildWidget widget, wdim nmh) {
         debug assert (widget is subWidgets[0]);
         mh = nmh + border.y1 + border.y2;
-        parent.minHChange (this, nmh);
+        parent.minHChange (this, mh);
     }
     
     override void draw () {
@@ -458,6 +467,15 @@
     }
     
 protected:
+    invariant {
+	// this() calls makeWidget() which calls recursionCheck(); invariant is called at this point before this() finishes
+	if (subWidgets.length) {
+	    assert (subWidgets.length == 1);
+	    assert (mw == subWidgets[0].minWidth + border.x1 + border.x2);
+	    assert (mh == subWidgets[0].minHeight + border.y1 + border.y2);
+	}
+    }
+    
     alias IRenderer.Border.BTYPE BTYPE;
     alias IRenderer.Border.RESIZE RESIZE;
     BTYPE borderType;       // what type of border to put around the widget