Fix bug when the focused window deinitialized
[notion.git] / mod_query / query.c
blobfbb3fa6f7d40351729410eab4aa5c20e2c5c063a
1 /*
2 * ion/mod_query/query.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
9 #include <libextl/extl.h>
11 #include <ioncore/common.h>
12 #include <ioncore/global.h>
13 #include <ioncore/binding.h>
14 #include <ioncore/regbind.h>
15 #include <ioncore/bindmaps.h>
16 #include <ioncore/stacking.h>
17 #include <ioncore/key.h>
18 #include "query.h"
19 #include "wedln.h"
22 /*--lowlevel routine not to be called by the user--EXTL_DOC
23 * Show a query window in \var{mplex} with prompt \var{prompt}, initial
24 * contents \var{dflt}. The function \var{handler} is called with
25 * the entered string as the sole argument when \fnref{WEdln.finish}
26 * is called. The function \var{completor} is called with the created
27 * \type{WEdln} is first argument and the string to complete is the
28 * second argument when \fnref{WEdln.complete} is called.
30 EXTL_EXPORT
31 WEdln *mod_query_do_query(WMPlex *mplex, const char *prompt, const char *dflt,
32 ExtlFn handler, ExtlFn completor,
33 ExtlFn cycle, ExtlFn bcycle)
35 WRectangle geom;
36 WEdlnCreateParams fnp;
37 WMPlexAttachParams par;
38 WEdln *wedln;
40 fnp.prompt=prompt;
41 fnp.dflt=dflt;
42 fnp.handler=handler;
43 fnp.completor=completor;
45 par.flags=(MPLEX_ATTACH_SWITCHTO|
46 MPLEX_ATTACH_LEVEL|
47 MPLEX_ATTACH_UNNUMBERED|
48 MPLEX_ATTACH_SIZEPOLICY);
49 par.szplcy=SIZEPOLICY_FULL_BOUNDS;
50 par.level=STACKING_LEVEL_MODAL1+2;
52 wedln=(WEdln*)mplex_do_attach_new(mplex, &par,
53 (WRegionCreateFn*)create_wedln,
54 (void*)&fnp);
56 if(wedln!=NULL && cycle!=extl_fn_none()){
57 uint kcb, state;
58 bool sub;
60 if(ioncore_current_key(&kcb, &state, &sub) && !sub){
61 wedln->cycle_bindmap=region_add_cycle_bindmap((WRegion*)wedln,
62 kcb, state, cycle,
63 bcycle);
67 return wedln;