]> git.decadent.org.uk Git - ion3.git/blob - mod_query/query.c
9418af5e11d5b8518fa93795a5c46b02a3c2b6b4
[ion3.git] / mod_query / query.c
1 /*
2  * ion/mod_query/query.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2007. 
5  *
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.
10  */
11
12 #include <libextl/extl.h>
13
14 #include <ioncore/common.h>
15 #include <ioncore/global.h>
16 #include <ioncore/binding.h>
17 #include <ioncore/regbind.h>
18 #include <ioncore/bindmaps.h>
19 #include <ioncore/key.h>
20 #include "query.h"
21 #include "wedln.h"
22
23
24 /*--lowlevel routine not to be called by the user--EXTL_DOC
25  * Show a query window in \var{mplex} with prompt \var{prompt}, initial
26  * contents \var{dflt}. The function \var{handler} is called with
27  * the entered string as the sole argument when \fnref{WEdln.finish}
28  * is called. The function \var{completor} is called with the created
29  * \type{WEdln} is first argument and the string to complete is the
30  * second argument when \fnref{WEdln.complete} is called.
31  */
32 EXTL_EXPORT
33 WEdln *mod_query_do_query(WMPlex *mplex, const char *prompt, const char *dflt,
34                           ExtlFn handler, ExtlFn completor, 
35                           ExtlFn cycle, ExtlFn bcycle)
36 {
37     WRectangle geom;
38     WEdlnCreateParams fnp;
39     WMPlexAttachParams par;
40     WEdln *wedln;
41
42     fnp.prompt=prompt;
43     fnp.dflt=dflt;
44     fnp.handler=handler;
45     fnp.completor=completor;
46     
47     par.flags=(MPLEX_ATTACH_SWITCHTO|
48                MPLEX_ATTACH_MODAL|
49                MPLEX_ATTACH_UNNUMBERED|
50                MPLEX_ATTACH_SIZEPOLICY);
51     par.szplcy=SIZEPOLICY_FULL_BOUNDS;
52
53     wedln=(WEdln*)mplex_do_attach_new(mplex, &par,
54                                       (WRegionCreateFn*)create_wedln,
55                                       (void*)&fnp); 
56                                       
57     if(wedln!=NULL && cycle!=extl_fn_none()){
58         uint kcb, state; 
59         bool sub;
60         
61         if(ioncore_current_key(&kcb, &state, &sub) && !sub){
62             wedln->cycle_bindmap=region_add_cycle_bindmap((WRegion*)wedln,
63                                                           kcb, state, cycle,
64                                                           bcycle);
65         }
66     }
67     
68     return wedln;
69 }
70