Mercurial > projects > mde
diff mde/gui/widget/miscContent.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 | d28aea50c6da |
children | 3e648bc53bde |
line wrap: on
line diff
--- a/mde/gui/widget/miscContent.d Thu Jan 01 15:16:00 2009 +0000 +++ b/mde/gui/widget/miscContent.d Fri Jan 02 18:07:10 2009 +0000 @@ -27,6 +27,7 @@ import mde.gui.renderer.IRenderer; import mde.content.AStringContent; import mde.content.miscContent; +import Items = mde.content.Items; debug { import tango.util.log.Log : Log, Logger; @@ -37,39 +38,51 @@ } /************************************************************************************************* + * A function which uses Items.get (data.strings[0]) to get a content and creates a widget from + * data.ints[1]. The first item in each ints and strings is removed before passing data to the new + * widget. + * + * The function only takes an IContent parameter to satisfy createWidget; it's value is ignored. + ************************************************************************************************/ +IChildWidget addContent (IWidgetManager mgr, IParentWidget parent, widgetID, WidgetData data, IContent) { + if (data.strings.length != 2) throw new WidgetDataException; + return mgr.makeWidget (parent, data.strings[1], Items.get (data.strings[0])); +} + +/************************************************************************************************* * A function which returns the most appropriate content editing widget. * * Widgets which can be returned: BoolContentWidget (toggle button), ValueContentWidget (generic * text-box editor), DisplayContentWidget (generic text label). *************************************************************************************************/ -IChildWidget editContent (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { +IChildWidget editContent (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) { // Note: SAFE_RECURSION enabled if (c is null) throw new ContentException; - else if (cast(AStringContent) c) { + if (cast(AStringContent) c) { if (cast(EnumContent) c) // can be PopupMenuWidget or ContentListWidget - return new ContentListWidget(mgr,id,data,c); - else if (cast(BoolContent) c) - return new BoolContentWidget(mgr,id,data,c); - else - return new AStringContentWidget(mgr,id,data,c); - } else if (cast(IContentList) c) - return new ContentListWidget(mgr,id,data,c); - else if (cast(EventContent) c) - return new ButtonContentWidget(mgr,id,data,c); - else // generic uneditable option - return new DisplayContentWidget(mgr,id,data,c); + return new ContentListWidget(mgr,parent,id,data,c); + if (cast(BoolContent) c) + return new BoolContentWidget(mgr,parent,id,data,c); + return new AStringContentWidget(mgr,parent,id,data,c); + } + if (cast(IContentList) c) + return new ContentListWidget(mgr,parent,id,data,c); + if (cast(EventContent) c) + return new ButtonContentWidget(mgr,parent,id,data,c); + // generic uneditable option + return new DisplayContentWidget(mgr,parent,id,data,c); } /// Editable boolean widget class BoolContentWidget : AButtonWidget { - this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { + this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) { content = cast(BoolContent) c; - WDCMinCheck(data, 1,0, content); + if (content is null) throw new ContentException (this); + super (mgr, parent, id); wdimPair s = mgr.renderer.getToggleSize; w = mw = s.x; h = mh = s.y; - super (mgr, id, data); } override void draw () { @@ -87,11 +100,11 @@ /// A button connected to an EventContent class ButtonContentWidget : AButtonWidget { - this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { + this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) { content = cast(EventContent) c; - WDCMinCheck (data, 1,0, content); - adapter = mgr.renderer.getAdapter (); - super (mgr, id, data); + if (content is null) throw new ContentException (this); + adapter = mgr.renderer.getAdapter (); + super (mgr, parent, id); } override bool setup (uint n, uint flags) {