]> git.decadent.org.uk Git - ion3.git/blobdiff - mod_menu/menu.c
Imported Upstream version 20090110
[ion3.git] / mod_menu / menu.c
index d891c230b6690a014b3cf1ec5810af78c450031b..6c1287fdb79bcb96a7b57e65be78273ca380df90 100644 (file)
@@ -1,12 +1,9 @@
 /*
  * ion/mod_menu/menu.c
  *
- * Copyright (c) Tuomo Valkonen 1999-2007
+ * Copyright (c) Tuomo Valkonen 1999-2009
  *
- * Ion is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
+ * See the included file LICENSE for details.
  */
 
 #include <string.h>
@@ -30,6 +27,8 @@
 #include <ioncore/names.h>
 #include <ioncore/gr.h>
 #include <ioncore/gr-util.h>
+#include <ioncore/sizehint.h>
+#include <ioncore/resize.h>
 #include "menu.h"
 #include "main.h"
 
@@ -391,6 +390,26 @@ bool menu_fitrep(WMenu *menu, WWindow *par, const WFitParams *fp)
 }
 
 
+void menu_size_hints(WMenu *menu, WSizeHints *hints_ret)
+{
+    int n=menu->n_entries;
+    int w=menu->max_entry_w;
+    int h=menu->entry_h*n + menu->entry_spacing*maxof(0, n-1);
+
+    if(menu->brush!=NULL){
+        GrBorderWidths bdw;
+        grbrush_get_border_widths(menu->brush, &bdw);
+        
+        w+=bdw.left+bdw.right;
+        h+=bdw.top+bdw.bottom;
+    }
+    
+    hints_ret->min_set=TRUE;
+    hints_ret->min_width=w;
+    hints_ret->min_height=h;
+}
+
+
 /*}}}*/
 
 
@@ -584,7 +603,8 @@ bool menu_init(WMenu *menu, WWindow *par, const WFitParams *fp,
     menu->handler=extl_ref_fn(params->handler);
     menu->pmenu_mode=params->pmenu_mode;
     menu->big_mode=params->big_mode;
-
+    /*menu->cycle_bindmap=NULL;*/
+    
     menu->last_fp=*fp;
     
     if(params->pmenu_mode){
@@ -668,6 +688,9 @@ void menu_deinit(WMenu *menu)
     if(menu->submenu!=NULL)
         destroy_obj((Obj*)menu->submenu);
     
+    /*if(menu->cycle_bindmap!=NULL)
+        bindmap_destroy(menu->cycle_bindmap);*/
+
     extl_unref_table(menu->tab);
     extl_unref_fn(menu->handler);
     
@@ -945,10 +968,10 @@ static void menu_do_finish(WMenu *menu)
     
     ok=extl_table_geti_t(menu->tab, menu->selected_entry+1, &tab);
     
-    if(region_manager_allows_destroying((WRegion*)head))
-        destroy_obj((Obj*)head);
-    else if(head->submenu!=NULL)
-        destroy_obj((Obj*)head->submenu);
+    if(!region_rqdispose((WRegion*)head)){
+        if(head->submenu!=NULL)
+            destroy_obj((Obj*)head->submenu);
+    }
     
     if(ok)
         extl_call(handler, "t", NULL, tab);
@@ -984,8 +1007,7 @@ void menu_finish(WMenu *menu)
 EXTL_EXPORT_MEMBER
 void menu_cancel(WMenu *menu)
 {
-    if(region_manager_allows_destroying((WRegion*)menu))
-        region_dispose_((WRegion*)menu);
+    region_defer_rqdispose((WRegion*)menu);
 }
 
 
@@ -1014,7 +1036,7 @@ static void reset_scroll_timer()
  * 
  * \begin{tabularx}{\linewidth}{lX}
  *  \tabhead{Field & Description}
- *  \var{scroll_amount} & Number of pixels to scroll at a time 
+ *  \var{scroll_amount} & Number of pixels to scroll at a time in
  *                        pointer-controlled menus when one extends
  *                        beyond a border of the screen and the pointer
  *                        touches that border. \\
@@ -1416,6 +1438,7 @@ static DynFunTab menu_dynfuntab[]={
     {window_insstr, menu_insstr},
     {region_restack, menu_restack},
     {region_stacking, menu_stacking},
+    {region_size_hints, menu_size_hints},
     END_DYNFUNTAB
 };