changeset 172:0dd49f333189

Implemented "void setContent (IContent)".
author Diggory Hardy <diggory.hardy@gmail.com>
date Wed, 29 Jul 2009 20:28:22 +0200
parents 7f7b2011b759
children a1ba9157510e
files codeDoc/ideas.txt codeDoc/jobs.txt mde/gui/widget/AChildWidget.d mde/gui/widget/AParentWidget.d mde/gui/widget/Floating.d mde/gui/widget/Ifaces.d mde/gui/widget/ParentContent.d mde/gui/widget/TextWidget.d mde/gui/widget/layout.d mde/gui/widget/miscContent.d mde/gui/widget/miscWidgets.d
diffstat 11 files changed, 112 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/codeDoc/ideas.txt	Sun Jul 26 11:04:17 2009 +0200
+++ b/codeDoc/ideas.txt	Wed Jul 29 20:28:22 2009 +0200
@@ -138,3 +138,7 @@
 > for easy access to editor (power GUI dev mode)
   > include a theme selection box on the GUI
   > include a button to turn the editor on/off
+
+
+Uses:
+> A universal XML generator/editor from XSD files?
--- a/codeDoc/jobs.txt	Sun Jul 26 11:04:17 2009 +0200
+++ b/codeDoc/jobs.txt	Wed Jul 29 20:28:22 2009 +0200
@@ -3,19 +3,18 @@
 
 
 In progress:
-
+Having setContent recusively call on subWidgets is not quite right: where the addContent function was used to pass a different content, the content should not be reset by a content() call propegated from a parent.
 
 
 To do (importance 0-5: 0 pointless, 1 no obvious impact now, 2 todo sometime, 3 useful, 4 important, 5 urgent):
 Also search for FIXME/NOTE/BUG/WARNING comment marks.
-4   Should only have one instance of context menu widgets. Service menu callbacks don't get removed!
+4   GUI: up-clicks get passed as events and activate objects
 3   Closing menus when release-click is not on menu or parent (ordinary & context).
 3   Dragging and dropping of editable data: should content immediately appear as being dragged?
 3   Dragging from anything other than AStringContentWidget.
 3   Single-line edit: pressing return should lose keyboard focus and change value
 3   Enable dragging from more widgets: bool content, enum
 3   Content: setContent specialisations, opAssign should reject more values (particularly for BoolContent).
-3   GUI: up-clicks get passed as events and activate objects
 3   Widget saving: how to deal with modifier functions, esp. when they discard parameters? Remove feature except for dimdata and handle gui editing separately?
 3   Windows compatibility - no registry support (useful to find path).
 2   Optimise: memory/reuse of popupContext and dragContentDisplay (in WidgetManager).
--- a/mde/gui/widget/AChildWidget.d	Sun Jul 26 11:04:17 2009 +0200
+++ b/mde/gui/widget/AChildWidget.d	Wed Jul 29 20:28:22 2009 +0200
@@ -59,10 +59,11 @@
         return false;
     }
     
-    // Widgets with content need to override this
+    // Widgets with content need to override these
     override IContent content () {
         return null;
     }
+    override void setContent (IContent) {}
 //END Load and save
     
 //BEGIN Size and position
--- a/mde/gui/widget/AParentWidget.d	Sun Jul 26 11:04:17 2009 +0200
+++ b/mde/gui/widget/AParentWidget.d	Wed Jul 29 20:28:22 2009 +0200
@@ -217,10 +217,14 @@
  * 
  * Intended to manage a context menu for WidgetManager, and not to work quite
  * like a regular IPPW.
+ * 
+ * Doesn't implement all the IChildWidget methods that would be relevent,
+ * because it's not used like a regular widget.
  *****************************************************************************/
 class PopupHandlerWidget : APopupParentWidget
 {
     this (IWidgetManager mgr, IParentWidget parent, widgetID id, char[] subWidg, IContent c) {
+	assert (parent is mgr);	// we're not meant to be used like a normal widget
         super (mgr, parent, id);
         
 	popup = mgr.makeWidget (this, subWidg, c);
@@ -233,8 +237,7 @@
     /// Open a context menu
     void openMenu (IChildWidget underMouse, Content contextContent) {
 	if (mAIPPW != MenuPosition.INACTIVE) return;	// already in use
-	//TODO:
-	//subWidgets[0].setContent (contextContent);
+	subWidgets[0].setContent = contextContent;
 	parentIPPW.addChildIPPW (this);
 	// For context menus, don't set parentIPPW.menuActive like for clicked menus:
 	menuActive = mgr.positionPopup (underMouse, popup);
--- a/mde/gui/widget/Floating.d	Sun Jul 26 11:04:17 2009 +0200
+++ b/mde/gui/widget/Floating.d	Wed Jul 29 20:28:22 2009 +0200
@@ -93,6 +93,12 @@
         return true;
     }
     
+    override void setContent (IContent c) {
+	// Pass the content on to sub-widgets, in case they want it
+	foreach (widg; subWidgets)
+	    widg.setContent = c;
+    }
+    
     override void setWidth (wdim nw, int) {
         w = nw;
         // check all floating widgets are visible
--- a/mde/gui/widget/Ifaces.d	Sun Jul 26 11:04:17 2009 +0200
+++ b/mde/gui/widget/Ifaces.d	Wed Jul 29 20:28:22 2009 +0200
@@ -359,9 +359,6 @@
      * Should be propegated up to parents. */
     void childChanged ();
     +/
-    
-    /** Return the widget's content, or null. */
-    IContent content ();
 //END Load and save
     
 //BEGIN Size and position
@@ -410,6 +407,16 @@
     void setPosition (wdim x, wdim y);
 //END Size and position
     
+//BEGIN Content
+    /** Return the widget's content, or null. */
+    IContent content ();
+    
+    /** Set the widget's content, if the widget takes content and changing it
+     * at this stage is feasible. (Also pass to sub-widgets, where the
+     * constructor normally does so.) */
+    void setContent (IContent);
+//END Content
+    
 //BEGIN Events
     /** Recursively scan the widget tree to find the widget under (cx,cy).
      *
--- a/mde/gui/widget/ParentContent.d	Sun Jul 26 11:04:17 2009 +0200
+++ b/mde/gui/widget/ParentContent.d	Wed Jul 29 20:28:22 2009 +0200
@@ -163,6 +163,9 @@
     override IContent content () {
         return content_;
     }
+    override void setContent (IContent) {
+	logger.warn ("SwitchWidget: resetting content is not yet supported");
+    }
     
     override bool setup (uint n, uint flags) {
         bool r = super.setup (n, flags);
@@ -296,6 +299,15 @@
     override IContent content () {
         return content_;
     }
+    override void setContent (IContent c) {
+	auto cont = cast(IBoolContent) c;
+	if (!cont) {
+	    logger.warn ("CollapsibleWidget: invalid content set: {}; ignoring", c);
+	    return;
+	}
+	content_ = cont;
+	collapse (content_);
+    }
     
     override void minWChange (IChildWidget widget, wdim nmw) {
         debug assert (widget is subWidgets[0]);
@@ -344,6 +356,7 @@
 protected:
     // callback on content_
     void collapse (IContent) {
+	if (collapsed == content_()) return;
         collapsed = content_();
         if (collapsed) {
             mw = mh = 0;
@@ -391,6 +404,10 @@
         return true;
     }
     
+    override void setContent (IContent c) {
+	subWidgets[0].setContent = c;
+    }
+    
     override void setWidth (wdim nw, int) {
         debug assert (nw >= mw);
         w = nw;
--- a/mde/gui/widget/TextWidget.d	Sun Jul 26 11:04:17 2009 +0200
+++ b/mde/gui/widget/TextWidget.d	Wed Jul 29 20:28:22 2009 +0200
@@ -109,6 +109,15 @@
     override IContent content () {
         return content_;
     }
+    override void setContent (IContent c) {
+	auto cont = cast(Content) c;
+	if (!cont) {
+	    logger.warn ("DisplayContentWidget: invalid content set: {}; ignoring", c);
+	    return;
+	}
+	content_ = cont;
+	updateVal (content_);
+    }
     
 protected:
     void updateVal (IContent) {	// callback
@@ -140,6 +149,16 @@
     override IContent content () {
         return content_;
     }
+    override void setContent (IContent c) {
+	content_.endEdit;	// save in case we were editing (FIXME: this has other side effects?)
+	auto cont = cast(AStringContent) c;
+	if (!cont) {
+	    logger.warn ("AStringContentWidget: invalid content set: {}; ignoring", c);
+	    return;
+	}
+	content_ = cont;
+	update (content_);
+    }
     
     override bool isWSizable () {
         return true;
--- a/mde/gui/widget/layout.d	Sun Jul 26 11:04:17 2009 +0200
+++ b/mde/gui/widget/layout.d	Wed Jul 29 20:28:22 2009 +0200
@@ -81,6 +81,12 @@
         mgr.dimData (id, col.width ~ row.width);
         return true;
     }
+    
+    override void setContent (IContent c) {
+	// Pass the content on to sub-widgets, in case they want it
+	foreach (widg; subWidgets)
+	    widg.setContent = c;
+    }
 protected:
 }
 
@@ -119,6 +125,9 @@
     override IContent content () {
         return cList;
     }
+    override void setContent (IContent) {
+	logger.warn ("ContentListWidget: resetting content is not yet supported");
+    }
     
     override bool dropContent (IContent content) {
 	if (cList.set (content))
--- a/mde/gui/widget/miscContent.d	Sun Jul 26 11:04:17 2009 +0200
+++ b/mde/gui/widget/miscContent.d	Wed Jul 29 20:28:22 2009 +0200
@@ -49,6 +49,15 @@
     override IContent content () {
         return content_;
     }
+    override void setContent (IContent c) {
+	auto cont = cast(IBoolContent) c;
+	if (!cont) {
+	    logger.warn ("BoolContentWidget: invalid content set: {}; ignoring", c);
+	    return;
+	}
+	content_ = cont;
+	mgr.requestRedraw;
+    }
     
     override bool dropContent (IContent content) {
 	if (content_.set (content))
@@ -92,6 +101,22 @@
     override IContent content () {
         return content_;
     }
+    override void setContent (IContent c) {
+	auto cont = cast(Content) c;
+	if (!cont) {
+	    logger.warn ("ButtonContentWidget: invalid content set: {}; ignoring", c);
+	    return;
+	}
+	content_ = cont;
+	adapter.text = content_.toString(1);
+	wdim omw = mw, omh = mh;
+	adapter.getDimensions (mw, mh);
+	if (omw != mw)
+	    parent.minWChange (this, mw);
+	if (omh != mh)
+	    parent.minHChange (this, mh);
+	mgr.requestRedraw;
+    }
     
     override int clickEvent (wdabs cx, wdabs cy, ubyte b, bool state) {
 	// Also display if dragging
@@ -137,6 +162,15 @@
     override IContent content () {
         return content_;
     }
+    override void setContent (IContent c) {
+	auto cont = cast(DoubleContent) c;
+	if (!cont) {
+	    logger.warn ("SliderContentWidget: invalid content set: {}; ignoring", c);
+	    return;
+	}
+	content_ = cont;
+	mgr.requestRedraw;
+    }
     
     override bool isWSizable () {
         return true;
--- a/mde/gui/widget/miscWidgets.d	Sun Jul 26 11:04:17 2009 +0200
+++ b/mde/gui/widget/miscWidgets.d	Wed Jul 29 20:28:22 2009 +0200
@@ -66,6 +66,10 @@
         logger.warn ("Debug widget ({}); parameters: ints = {}, strings = {}; content: {}", id, data.ints, data.strings, c);
     }
     
+    override void setContent (IContent c) {
+	logger.info ("Debug widget ({}); new content set: {}", c);
+    }
+    
     override void draw () {
         super.draw;