2 * ion/mod_menu/mkmenu.c
4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
13 #include <ioncore/common.h>
14 #include <ioncore/pointer.h>
15 #include <ioncore/grab.h>
16 #include <libextl/extl.h>
21 /*--lowlevel routine not to be called by the user--EXTL_DOC
22 * Display a menu inside multiplexer. The \var{handler} parameter
23 * is a function that gets the selected menu entry as argument and
24 * should call it with proper parameters. The table \var{tab} is a
25 * list of menu entries of the form \code{\{name = ???, [ submenu_fn = ??? ]\}}.
26 * The function \var{submenu_fn} return a similar submenu definition
29 * Do not use this function directly. Use \fnref{mod_menu.menu} and
30 * \fnref{mod_menu.bigmenu}.
33 WMenu *mod_menu_do_menu(WMPlex *mplex, ExtlFn handler, ExtlTab tab,
36 WMenuCreateParams fnp;
37 WMPlexAttachParams par;
42 fnp.submenu_mode=FALSE;
43 fnp.big_mode=extl_table_is_bool_set(param, "big");
45 extl_table_gets_i(param, "initial", &(fnp.initial));
51 par.flags=(MPLEX_ATTACH_SWITCHTO|
53 MPLEX_ATTACH_UNNUMBERED|
54 MPLEX_ATTACH_SIZEPOLICY);
55 par.szplcy=SIZEPOLICY_FULL_BOUNDS;
57 return (WMenu*)mplex_do_attach_new(mplex, &par,
58 (WRegionCreateFn*)create_menu,
63 /*--lowlevel routine not to be called by the user--EXTL_DOC
64 * Display a pop-up menu inside window \var{where}. This function
65 * can only be called from a mouse/pointing device button press handler
66 * and the menu will be placed below the point where the press occured.
67 * The \var{handler} and \var{tab} parameters are similar to those of
70 * Do not use this function directly. Use \fnref{mod_menu.pmenu}.
73 WMenu *mod_menu_do_pmenu(WWindow *where, ExtlFn handler, ExtlTab tab)
76 WMenuCreateParams fnp;
77 XEvent *ev=ioncore_current_pointer_event();
81 if(ev==NULL || ev->type!=ButtonPress)
84 scr=region_screen_of((WRegion*)where);
93 fnp.submenu_mode=FALSE;
95 fnp.refg.x=ev->xbutton.x_root-REGION_GEOM(scr).x;
96 fnp.refg.y=ev->xbutton.y_root-REGION_GEOM(scr).y;
100 fp.mode=REGION_FIT_BOUNDS;
101 fp.g.x=REGION_GEOM(where).x;
102 fp.g.y=REGION_GEOM(where).y;
103 fp.g.w=REGION_GEOM(where).w;
104 fp.g.h=REGION_GEOM(where).h;
106 menu=create_menu((WWindow*)scr, &fp, &fnp);
111 region_restack((WRegion*)menu, None, Above);
113 if(!ioncore_set_drag_handlers((WRegion*)menu,
115 (WMotionHandler*)menu_motion,
116 (WButtonHandler*)menu_release,
118 (GrabKilledHandler*)menu_cancel)){
119 destroy_obj((Obj*)menu);
123 region_map((WRegion*)menu);