]> git.decadent.org.uk Git - ion3.git/blobdiff - mod_query/query.c
Imported Upstream version 20090110
[ion3.git] / mod_query / query.c
index b56c087a4b24bc5d8e108af305927c71bbca053b..fbb3fa6f7d40351729410eab4aa5c20e2c5c063a 100644 (file)
@@ -1,12 +1,9 @@
 /*
  * ion/mod_query/query.c
  *
- * Copyright (c) Tuomo Valkonen 1999-2006
+ * Copyright (c) Tuomo Valkonen 1999-2009
  *
- * Ion is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
+ * See the included file LICENSE for details.
  */
 
 #include <libextl/extl.h>
 #include <ioncore/global.h>
 #include <ioncore/binding.h>
 #include <ioncore/regbind.h>
+#include <ioncore/bindmaps.h>
+#include <ioncore/stacking.h>
 #include <ioncore/key.h>
 #include "query.h"
 #include "wedln.h"
 
 
-static void create_cycle_binding(WEdln *wedln, XKeyEvent *ev, ExtlFn cycle)
-{
-    WBindmap *bindmap=create_bindmap();
-    WBinding b;
-    
-    if(bindmap==NULL)
-        return;
-        
-    b.ksb=XKeycodeToKeysym(ioncore_g.dpy, ev->keycode, 0);
-    b.kcb=ev->keycode;
-    b.state=ev->state;
-    b.act=BINDING_KEYPRESS;
-    b.area=0;
-    b.wait=FALSE;
-    b.submap=NULL;
-    b.func=extl_ref_fn(cycle);
-    
-    if(!bindmap_add_binding(bindmap, &b)){
-        extl_unref_fn(b.func);
-        bindmap_destroy(bindmap);
-        return;
-    }
-    
-    if(!region_add_bindmap((WRegion*)wedln, bindmap)){
-        bindmap_destroy(bindmap);
-        return;
-    }
-    
-    wedln->cycle_bindmap=bindmap;
-}
-    
-
 /*--lowlevel routine not to be called by the user--EXTL_DOC
  * Show a query window in \var{mplex} with prompt \var{prompt}, initial
  * contents \var{dflt}. The function \var{handler} is called with
@@ -62,12 +29,12 @@ static void create_cycle_binding(WEdln *wedln, XKeyEvent *ev, ExtlFn cycle)
  */
 EXTL_EXPORT
 WEdln *mod_query_do_query(WMPlex *mplex, const char *prompt, const char *dflt,
-                          ExtlFn handler, ExtlFn completor, ExtlFn cycle)
+                          ExtlFn handler, ExtlFn completor, 
+                          ExtlFn cycle, ExtlFn bcycle)
 {
     WRectangle geom;
     WEdlnCreateParams fnp;
     WMPlexAttachParams par;
-    XKeyEvent *ev=ioncore_current_key_event();
     WEdln *wedln;
 
     fnp.prompt=prompt;
@@ -76,18 +43,26 @@ WEdln *mod_query_do_query(WMPlex *mplex, const char *prompt, const char *dflt,
     fnp.completor=completor;
     
     par.flags=(MPLEX_ATTACH_SWITCHTO|
-               MPLEX_ATTACH_MODAL|
+               MPLEX_ATTACH_LEVEL|
                MPLEX_ATTACH_UNNUMBERED|
                MPLEX_ATTACH_SIZEPOLICY);
     par.szplcy=SIZEPOLICY_FULL_BOUNDS;
+    par.level=STACKING_LEVEL_MODAL1+2;
 
     wedln=(WEdln*)mplex_do_attach_new(mplex, &par,
                                       (WRegionCreateFn*)create_wedln,
                                       (void*)&fnp); 
                                       
-    if(wedln!=NULL && ev!=NULL && cycle!=extl_fn_none())
-        create_cycle_binding(wedln, ev, cycle);
+    if(wedln!=NULL && cycle!=extl_fn_none()){
+        uint kcb, state; 
+        bool sub;
         
+        if(ioncore_current_key(&kcb, &state, &sub) && !sub){
+            wedln->cycle_bindmap=region_add_cycle_bindmap((WRegion*)wedln,
+                                                          kcb, state, cycle,
+                                                          bcycle);
+        }
+    }
     
     return wedln;
 }