Newer versions of libextl and libtu
[notion/jeffpc.git] / mod_menu / mkmenu.c
blobd9775b66bf95728f7a0cc5087382f4e1dec6716d
1 /*
2 * ion/mod_menu/mkmenu.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
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"
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.
27 * Do not use this function directly. Use \fnref{mod_menu.menu} and
28 * \fnref{mod_menu.bigmenu}.
30 EXTL_EXPORT
31 WMenu *mod_menu_do_menu(WMPlex *mplex, ExtlFn handler, ExtlTab tab,
32 ExtlTab param)
34 WMenuCreateParams fnp;
35 WMPlexAttachParams par;
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;
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;
56 return (WMenu*)mplex_do_attach_new(mplex, &par,
57 (WRegionCreateFn*)create_menu,
58 (void*)&fnp);
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}.
69 * Do not use this function directly. Use \fnref{mod_menu.pmenu}.
71 EXTL_EXPORT
72 WMenu *mod_menu_do_pmenu(WWindow *where, ExtlFn handler, ExtlTab tab)
74 WScreen *scr;
75 WMenuCreateParams fnp;
76 XEvent *ev=ioncore_current_pointer_event();
77 WMenu *menu;
78 WFitParams fp;
80 if(ev==NULL || ev->type!=ButtonPress)
81 return NULL;
83 scr=region_screen_of((WRegion*)where);
85 if(scr==NULL)
86 return NULL;
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;
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;
105 menu=create_menu((WWindow*)scr, &fp, &fnp);
107 if(menu==NULL)
108 return NULL;
110 region_restack((WRegion*)menu, None, Above);
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;
122 region_map((WRegion*)menu);
124 return menu;