]> git.decadent.org.uk Git - ion3.git/blob - mod_query/query.c
Imported Upstream version 20090110
[ion3.git] / mod_query / query.c
1 /*
2  * ion/mod_query/query.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2009. 
5  *
6  * See the included file LICENSE for details.
7  */
8
9 #include <libextl/extl.h>
10
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"
20
21
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.
29  */
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)
34 {
35     WRectangle geom;
36     WEdlnCreateParams fnp;
37     WMPlexAttachParams par;
38     WEdln *wedln;
39
40     fnp.prompt=prompt;
41     fnp.dflt=dflt;
42     fnp.handler=handler;
43     fnp.completor=completor;
44     
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;
51
52     wedln=(WEdln*)mplex_do_attach_new(mplex, &par,
53                                       (WRegionCreateFn*)create_wedln,
54                                       (void*)&fnp); 
55                                       
56     if(wedln!=NULL && cycle!=extl_fn_none()){
57         uint kcb, state; 
58         bool sub;
59         
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);
64         }
65     }
66     
67     return wedln;
68 }
69