comparison mde/gui/widget/PopupMenu.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 9cff74f68b84
comparison
equal deleted inserted replaced
120:46c63cb1c74f 121:5b37d0400732
36 /************************************************************************************************* 36 /*************************************************************************************************
37 * Widget which pops up a menu based on a content. 37 * Widget which pops up a menu based on a content.
38 *************************************************************************************************/ 38 *************************************************************************************************/
39 class PopupMenuWidget : AParentSingleWidget 39 class PopupMenuWidget : AParentSingleWidget
40 { 40 {
41 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { 41 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
42 content = c; 42 content = c;
43 WDCMinCheck (data, 1,1, content); 43 WDCMinCheck (data, 1,1, content);
44 subWidget = mgr.makeWidget (data.strings[0], content); 44 super (mgr, parent, id);
45
46 subWidget = mgr.makeWidget (this, data.strings[0], content);
45 47
46 adapter = mgr.renderer.getAdapter; 48 adapter = mgr.renderer.getAdapter;
47 adapter.text = content.toString (1); 49 adapter.text = content.toString (1);
48 adapter.getDimensions (mw, mh); 50 adapter.getDimensions (mw, mh);
49 w = mw; 51 w = mw;
50 h = mh; 52 h = mh;
51 super (mgr, id, data);
52 } 53 }
53 54
54 override int clickEvent (wdabs, wdabs, ubyte b, bool state) { 55 override int clickEvent (wdabs, wdabs, ubyte b, bool state) {
55 if (b == 1 && state == true) { 56 if (b == 1 && state == true) {
56 // If active, the popup is closed by WidgetManager since the click isn't on the popup. 57 // If active, the popup is closed by WidgetManager since the click isn't on the popup.
93 /************************************************************************************************* 94 /*************************************************************************************************
94 * Widget which pops up a sub-menu based on a content on mouse-over. 95 * Widget which pops up a sub-menu based on a content on mouse-over.
95 *************************************************************************************************/ 96 *************************************************************************************************/
96 class SubMenuWidget : PopupMenuWidget 97 class SubMenuWidget : PopupMenuWidget
97 { 98 {
98 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { 99 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
99 super (mgr, id, data, c); 100 super (mgr, parent, id, data, c);
100 } 101 }
101 102
102 override int clickEvent (wdabs, wdabs, ubyte b, bool state) { 103 override int clickEvent (wdabs, wdabs, ubyte b, bool state) {
103 return 0; 104 return 0;
104 } 105 }
112 } 113 }
113 114
114 /************************************************************************************************* 115 /*************************************************************************************************
115 * A function which returns a ContentListWidget or MenuButtonContentWidget. 116 * A function which returns a ContentListWidget or MenuButtonContentWidget.
116 *************************************************************************************************/ 117 *************************************************************************************************/
117 IChildWidget flatMenuContent (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { 118 IChildWidget flatMenuContent (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
118 if (c is null) throw new ContentException; 119 if (c is null) throw new ContentException;
119 if (cast(IContentList) c) 120 if (cast(IContentList) c)
120 return new ContentListWidget(mgr,id,data,c); 121 return new ContentListWidget(mgr,parent,id,data,c);
121 else if (cast(EventContent) c) 122 if (cast(EventContent) c)
122 return new MenuButtonContentWidget(mgr,id,data,c); 123 return new MenuButtonContentWidget(mgr,parent,id,data,c);
123 else // generic uneditable option 124 // generic uneditable option
124 return new DisplayContentWidget(mgr,id,data,c); 125 return new DisplayContentWidget(mgr,parent,id,data,c);
125 } 126 }
126 127
127 /************************************************************************************************* 128 /*************************************************************************************************
128 * A function which returns a SubMenuWidget or MenuButtonContentWidget. 129 * A function which returns a SubMenuWidget or MenuButtonContentWidget.
129 *************************************************************************************************/ 130 *************************************************************************************************/
130 IChildWidget subMenuContent (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { 131 IChildWidget subMenuContent (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
131 if (c is null) throw new ContentException; 132 if (c is null) throw new ContentException;
132 if (cast(IContentList) c) 133 if (cast(IContentList) c)
133 return new SubMenuWidget(mgr,id,data,c); 134 return new SubMenuWidget(mgr,parent,id,data,c);
134 else if (cast(EventContent) c) 135 if (cast(EventContent) c)
135 return new MenuButtonContentWidget(mgr,id,data,c); 136 return new MenuButtonContentWidget(mgr,parent,id,data,c);
136 else // generic uneditable option 137 // generic uneditable option
137 return new DisplayContentWidget(mgr,id,data,c); 138 return new DisplayContentWidget(mgr,parent,id,data,c);
138 } 139 }
139 140
140 /************************************************************************************************* 141 /*************************************************************************************************
141 * A menu content-button, like ButtonContentWidget, but which can be activated with the up-click. 142 * A menu content-button, like ButtonContentWidget, but which can be activated with the up-click.
142 *************************************************************************************************/ 143 *************************************************************************************************/
143 class MenuButtonContentWidget : ATextWidget 144 class MenuButtonContentWidget : ATextWidget
144 { 145 {
145 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { 146 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) {
146 content = cast(EventContent) c; 147 content = cast(EventContent) c;
147 WDCMinCheck (data, 1,0, content); 148 if (content is null) throw new ContentException (this);
148 adapter = mgr.renderer.getAdapter (); 149 adapter = mgr.renderer.getAdapter ();
149 super (mgr, id, data); 150 super (mgr, parent, id);
150 } 151 }
151 152
152 override bool setup (uint n, uint flags) { 153 override bool setup (uint n, uint flags) {
153 if (!(flags & 3)) return false; // string or renderer (and possibly font) changed 154 if (!(flags & 3)) return false; // string or renderer (and possibly font) changed
154 adapter.text = content.toString(1); 155 adapter.text = content.toString(1);