2 * ion/mod_menu/mkmenu.c
4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * See the included file LICENSE for details.
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>
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
27 * Do not use this function directly. Use \fnref{mod_menu.menu} and
28 * \fnref{mod_menu.bigmenu}.
31 WMenu *mod_menu_do_menu(WMPlex *mplex, ExtlFn handler, ExtlTab tab,
34 WMenuCreateParams fnp;
35 WMPlexAttachParams par;
40 fnp.submenu_mode=FALSE;
41 fnp.big_mode=extl_table_is_bool_set(param, "big");
43 extl_table_gets_i(param, "initial", &(fnp.initial));
49 par.flags=(MPLEX_ATTACH_SWITCHTO|
51 MPLEX_ATTACH_UNNUMBERED|
52 MPLEX_ATTACH_SIZEPOLICY);
53 par.szplcy=SIZEPOLICY_FULL_BOUNDS;
54 par.level=STACKING_LEVEL_MODAL1+1;
56 return (WMenu*)mplex_do_attach_new(mplex, &par,
57 (WRegionCreateFn*)create_menu,
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
69 * Do not use this function directly. Use \fnref{mod_menu.pmenu}.
72 WMenu *mod_menu_do_pmenu(WWindow *where, ExtlFn handler, ExtlTab tab)
75 WMenuCreateParams fnp;
76 XEvent *ev=ioncore_current_pointer_event();
80 if(ev==NULL || ev->type!=ButtonPress)
83 scr=region_screen_of((WRegion*)where);
92 fnp.submenu_mode=FALSE;
94 fnp.refg.x=ev->xbutton.x_root-REGION_GEOM(scr).x;
95 fnp.refg.y=ev->xbutton.y_root-REGION_GEOM(scr).y;
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);
110 region_restack((WRegion*)menu, None, Above);
112 if(!ioncore_set_drag_handlers((WRegion*)menu,
114 (WMotionHandler*)menu_motion,
115 (WButtonHandler*)menu_release,
117 (GrabKilledHandler*)menu_cancel)){
118 destroy_obj((Obj*)menu);
122 region_map((WRegion*)menu);