diff mde/gui/widget/PopupMenu.d @ 117:aba2dd815a1f

Some tweaks to popup events and widgets. Moved gui.mtt to guiDemo.mtt Changed handling of clicks with popups. Made some of the popup widgets use usual from widget data construction.
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 26 Dec 2008 12:07:38 +0000
parents 1b1e2297e2fc
children d28aea50c6da
line wrap: on
line diff
--- a/mde/gui/widget/PopupMenu.d	Sun Dec 21 12:03:50 2008 +0000
+++ b/mde/gui/widget/PopupMenu.d	Fri Dec 26 12:07:38 2008 +0000
@@ -41,8 +41,8 @@
 {
     this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
 	content = c;
-	WDCMinCheck (data, 1,0, content);
-	subWidget = menuContent (mgr, id, data, content);
+	WDCMinCheck (data, 1,1, content);
+	subWidget = mgr.makeWidget (data.strings[0], content);
 	
 	adapter = mgr.renderer.getAdapter;
 	adapter.text = content.toString (1);
@@ -64,9 +64,13 @@
 	return 0;
     }
     
-    override void popupRemoved () {
+    override void popupClose () {
 	pushed = false;
     }
+    override bool popupParentClick () {
+        pushed = false;
+        return true;
+    }
     
     override void draw () {
 	mgr.renderer.drawButton (x,y, w,h, pushed);
@@ -88,19 +92,55 @@
 }
 
 /*************************************************************************************************
- * A function which returns the most appropriate content menu widget.
+ * Widget which pops up a sub-menu based on a content on mouse-over.
  *************************************************************************************************/
-IChildWidget menuContent (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { if (c is null) throw new ContentException;
+class SubMenuWidget : PopupMenuWidget
+{
+    this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
+        super (mgr, id, data, c);
+    }
+    
+    override int clickEvent (wdabs, wdabs, ubyte b, bool state) {
+        return 0;
+    }
+    
+    override void highlight (bool state) {
+        if (state && !pushed) {
+            pushed = true;
+            mgr.addPopup (this, subWidget, 1);	// causes redraw
+        }
+    }
+}
+
+/*************************************************************************************************
+ * A function which returns a ContentListWidget or MenuButtonContentWidget.
+ *************************************************************************************************/
+IChildWidget flatMenuContent (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
+    if (c is null) throw new ContentException;
     if (cast(IContentList) c)
-	return new MenuContentListWidget(mgr,id,data,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);
 }
 
-/** A menu content-button, like ButtonContentWidget, but which can be activated with the up-click.
- */
+/*************************************************************************************************
+ * A function which returns a SubMenuWidget or MenuButtonContentWidget.
+ *************************************************************************************************/
+IChildWidget subMenuContent (IWidgetManager mgr, 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);
+}
+
+/*************************************************************************************************
+ * A menu content-button, like ButtonContentWidget, but which can be activated with the up-click.
+ *************************************************************************************************/
 class MenuButtonContentWidget : ATextWidget
 {
     this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
@@ -138,31 +178,3 @@
     EventContent content;
     bool pushed;
 }
-
-/// Similar to layout.ContentListWidget but creates sub-widgets with menuContent.
-class MenuContentListWidget : GridWidget
-{
-    this (IWidgetManager mgr, widgetID id, WidgetData data, IContent content) {
-	cList = cast(IContentList) content;
-	WDCMinCheck (data, 2, 0, cList);
-	
-	cols = 1;
-	if ((rows = cList.list.length) > 0) {
-	    subWidgets.length = rows;
-	    foreach (i, c; cList.list) {
-		subWidgets[i] = menuContent (mgr,id,data,c);
-	    }
-	} else {
-	    rows = 1;
-	    subWidgets = [mgr.makeWidget (id, new ErrorContent ("<empty list>"))];
-	}
-	super (mgr, id, data);
-    }
-    
-    override bool saveChanges () {
-	return false;	// sub-widgets don't have an id
-    }
-    
-private:
-    IContentList cList;
-}