2 * ion/mod_query/query.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.
12 #include <libextl/extl.h>
14 #include <ioncore/common.h>
15 #include <ioncore/global.h>
16 #include <ioncore/binding.h>
17 #include <ioncore/regbind.h>
18 #include <ioncore/key.h>
23 static void create_cycle_binding(WEdln *wedln, uint kcb, uint state, ExtlFn cycle)
25 WBindmap *bindmap=create_bindmap();
31 b.ksb=XKeycodeToKeysym(ioncore_g.dpy, kcb, 0);
34 b.act=BINDING_KEYPRESS;
38 b.func=extl_ref_fn(cycle);
40 if(!bindmap_add_binding(bindmap, &b)){
41 extl_unref_fn(b.func);
42 bindmap_destroy(bindmap);
46 if(!region_add_bindmap((WRegion*)wedln, bindmap)){
47 bindmap_destroy(bindmap);
51 wedln->cycle_bindmap=bindmap;
55 /*--lowlevel routine not to be called by the user--EXTL_DOC
56 * Show a query window in \var{mplex} with prompt \var{prompt}, initial
57 * contents \var{dflt}. The function \var{handler} is called with
58 * the entered string as the sole argument when \fnref{WEdln.finish}
59 * is called. The function \var{completor} is called with the created
60 * \type{WEdln} is first argument and the string to complete is the
61 * second argument when \fnref{WEdln.complete} is called.
64 WEdln *mod_query_do_query(WMPlex *mplex, const char *prompt, const char *dflt,
65 ExtlFn handler, ExtlFn completor, ExtlFn cycle)
68 WEdlnCreateParams fnp;
69 WMPlexAttachParams par;
75 fnp.completor=completor;
77 par.flags=(MPLEX_ATTACH_SWITCHTO|
79 MPLEX_ATTACH_UNNUMBERED|
80 MPLEX_ATTACH_SIZEPOLICY);
81 par.szplcy=SIZEPOLICY_FULL_BOUNDS;
83 wedln=(WEdln*)mplex_do_attach_new(mplex, &par,
84 (WRegionCreateFn*)create_wedln,
87 if(wedln!=NULL && cycle!=extl_fn_none()){
91 if(ioncore_current_key(&kcb, &state, &sub) && !sub)
92 create_cycle_binding(wedln, kcb, state, cycle);