]> git.decadent.org.uk Git - ion3.git/blob - mod_menu/mkmenu.c
d20882f7c2d775d313b1ddb82aae48a2cf4466b6
[ion3.git] / mod_menu / mkmenu.c
1 /*
2  * ion/mod_menu/mkmenu.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2008. 
5  *
6  * See the included file LICENSE for details.
7  */
8
9 #include <limits.h>
10 #include <ioncore/common.h>
11 #include <ioncore/pointer.h>
12 #include <ioncore/stacking.h>
13 #include <ioncore/grab.h>
14 #include <libextl/extl.h>
15 #include "menu.h"
16 #include "mkmenu.h"
17
18
19 /*--lowlevel routine not to be called by the user--EXTL_DOC
20  * Display a menu inside multiplexer. The \var{handler} parameter
21  * is a function that gets the selected menu entry as argument and
22  * should call it with proper parameters. The table \var{tab} is a
23  * list of menu entries of the form \code{\{name = ???, [ submenu_fn = ??? ]\}}.
24  * The function \var{submenu_fn} return a similar submenu definition 
25  * when called.
26  * 
27  * Do not use this function directly. Use  \fnref{mod_menu.menu} and
28  * \fnref{mod_menu.bigmenu}.
29  */
30 EXTL_EXPORT
31 WMenu *mod_menu_do_menu(WMPlex *mplex, ExtlFn handler, ExtlTab tab, 
32                         ExtlTab param)
33 {
34     WMenuCreateParams fnp;
35     WMPlexAttachParams par;
36
37     fnp.handler=handler;
38     fnp.tab=tab;
39     fnp.pmenu_mode=FALSE;
40     fnp.submenu_mode=FALSE;
41     fnp.big_mode=extl_table_is_bool_set(param, "big");
42     fnp.initial=0;
43     extl_table_gets_i(param, "initial", &(fnp.initial));
44     fnp.refg.x=0;
45     fnp.refg.y=0;
46     fnp.refg.w=0;
47     fnp.refg.h=0;
48     
49     par.flags=(MPLEX_ATTACH_SWITCHTO|
50                MPLEX_ATTACH_LEVEL|
51                MPLEX_ATTACH_UNNUMBERED|
52                MPLEX_ATTACH_SIZEPOLICY);
53     par.szplcy=SIZEPOLICY_FULL_BOUNDS;
54     par.level=STACKING_LEVEL_MODAL1+2;
55     
56     return (WMenu*)mplex_do_attach_new(mplex, &par,
57                                        (WRegionCreateFn*)create_menu,
58                                        (void*)&fnp); 
59 }
60
61
62 /*--lowlevel routine not to be called by the user--EXTL_DOC
63  * Display a pop-up menu inside window \var{where}. This function
64  * can only be called from a mouse/pointing device button press handler
65  * and the menu will be placed below the point where the press occured.
66  * The \var{handler} and \var{tab} parameters are similar to those of
67  * \fnref{menu_menu}.
68  * 
69  * Do not use this function directly. Use \fnref{mod_menu.pmenu}.
70  */
71 EXTL_EXPORT
72 WMenu *mod_menu_do_pmenu(WWindow *where, ExtlFn handler, ExtlTab tab)
73 {
74     WScreen *scr;
75     WMenuCreateParams fnp;
76     XEvent *ev=ioncore_current_pointer_event();
77     WMenu *menu;
78     WFitParams fp;
79     
80     if(ev==NULL || ev->type!=ButtonPress)
81         return NULL;
82
83     scr=region_screen_of((WRegion*)where);
84
85     if(scr==NULL)
86         return NULL;
87     
88     fnp.handler=handler;
89     fnp.tab=tab;
90     fnp.pmenu_mode=TRUE;
91     fnp.big_mode=FALSE;
92     fnp.submenu_mode=FALSE;
93     fnp.initial=0;
94     fnp.refg.x=ev->xbutton.x_root-REGION_GEOM(scr).x;
95     fnp.refg.y=ev->xbutton.y_root-REGION_GEOM(scr).y;
96     fnp.refg.w=0;
97     fnp.refg.h=0;
98     
99     fp.mode=REGION_FIT_BOUNDS;
100     fp.g.x=REGION_GEOM(where).x;
101     fp.g.y=REGION_GEOM(where).y;
102     fp.g.w=REGION_GEOM(where).w;
103     fp.g.h=REGION_GEOM(where).h;
104     
105     menu=create_menu((WWindow*)scr, &fp, &fnp);
106     
107     if(menu==NULL)
108         return NULL;
109
110     region_restack((WRegion*)menu, None, Above);
111     
112     if(!ioncore_set_drag_handlers((WRegion*)menu,
113                             NULL,
114                             (WMotionHandler*)menu_motion,
115                             (WButtonHandler*)menu_release,
116                             NULL, 
117                             (GrabKilledHandler*)menu_cancel)){
118         destroy_obj((Obj*)menu);
119         return NULL;
120     }
121     
122     region_map((WRegion*)menu);
123     
124     return menu;
125 }
126