diff 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
line wrap: on
line diff
--- a/mde/gui/widget/PopupMenu.d	Thu Jan 01 15:16:00 2009 +0000
+++ b/mde/gui/widget/PopupMenu.d	Fri Jan 02 18:07:10 2009 +0000
@@ -38,17 +38,18 @@
  *************************************************************************************************/
 class PopupMenuWidget : AParentSingleWidget
 {
-    this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
+    this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
 	content = c;
 	WDCMinCheck (data, 1,1, content);
-	subWidget = mgr.makeWidget (data.strings[0], content);
+        super (mgr, parent, id);
+        
+        subWidget = mgr.makeWidget (this, data.strings[0], content);
 	
 	adapter = mgr.renderer.getAdapter;
 	adapter.text = content.toString (1);
 	adapter.getDimensions (mw, mh);
 	w = mw;
 	h = mh;
-	super (mgr, id, data);
     }
     
     override int clickEvent (wdabs, wdabs, ubyte b, bool state) {
@@ -95,8 +96,8 @@
  *************************************************************************************************/
 class SubMenuWidget : PopupMenuWidget
 {
-    this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
-        super (mgr, id, data, c);
+    this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
+        super (mgr, parent, id, data, c);
     }
     
     override int clickEvent (wdabs, wdabs, ubyte b, bool state) {
@@ -114,27 +115,27 @@
 /*************************************************************************************************
  * A function which returns a ContentListWidget or MenuButtonContentWidget.
  *************************************************************************************************/
-IChildWidget flatMenuContent (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
+IChildWidget flatMenuContent (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
     if (c is null) throw new ContentException;
     if (cast(IContentList) c)
-	return new ContentListWidget(mgr,id,data,c);
-    else if (cast(EventContent) c)
-	return new MenuButtonContentWidget(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(EventContent) c)
+        return new MenuButtonContentWidget(mgr,parent,id,data,c);
+    // generic uneditable option
+    return new DisplayContentWidget(mgr,parent,id,data,c);
 }
 
 /*************************************************************************************************
  * A function which returns a SubMenuWidget or MenuButtonContentWidget.
  *************************************************************************************************/
-IChildWidget subMenuContent (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
+IChildWidget subMenuContent (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
     if (c is null) throw new ContentException;
     if (cast(IContentList) c)
-	return new SubMenuWidget(mgr,id,data,c);
-    else if (cast(EventContent) c)
-	return new MenuButtonContentWidget(mgr,id,data,c);
-    else // generic uneditable option
-        return new DisplayContentWidget(mgr,id,data,c);
+        return new SubMenuWidget(mgr,parent,id,data,c);
+    if (cast(EventContent) c)
+        return new MenuButtonContentWidget(mgr,parent,id,data,c);
+    // generic uneditable option
+    return new DisplayContentWidget(mgr,parent,id,data,c);
 }
 
 /*************************************************************************************************
@@ -142,11 +143,11 @@
  *************************************************************************************************/
 class MenuButtonContentWidget : ATextWidget
 {
-    this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
-	content = cast(EventContent) c;
-	WDCMinCheck (data, 1,0, content);
-	adapter = mgr.renderer.getAdapter ();
-	super (mgr, id, data);
+    this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) {
+        content = cast(EventContent) c;
+        if (content is null) throw new ContentException (this);
+        adapter = mgr.renderer.getAdapter ();
+        super (mgr, parent, id);
     }
     
     override bool setup (uint n, uint flags) {