]> git.lyx.org Git - lyx.git/blobdiff - src/combox.C
small changes to ButtonController usage
[lyx.git] / src / combox.C
index 58efa6534e8524b7608c82ff3bfddd46a7b5ed55..400e3da44d6051e719d3e2cc95e65515358185d9 100644 (file)
@@ -4,7 +4,7 @@
  *          encapsulated to get a combobox-like object. All XForms 
  *          functions are hidden.         
  * 
- *  GNU Copyleft (C) 1996 Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
+ *  GNU Copyleft 1996 Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
  *                        and the LyX Team.
  * 
  *  Dependencies:  Only XForms, but created to be used with LyX.
@@ -40,6 +40,8 @@
 
 #include "debug.h"
 
+using std::endl;
+
 // These are C wrappers around static members of Combox, used as
 // callbacks for xforms.
 extern "C" void C_Combox_input_cb(FL_OBJECT *ob, long);
@@ -127,7 +129,7 @@ void Combox::addline(char const* text)
 bool Combox::select_text(char const* t)
 {
        if (!browser || !t) return false;
-       for (int i= 1; i<= fl_get_browser_maxline(browser); i++) {
+       for (int i = 1; i <= fl_get_browser_maxline(browser); ++i) {
                if (!strcmp(t, fl_get_browser_line(browser, i))) {
                        select(i);
                        return true;
@@ -197,8 +199,8 @@ void Combox::add(int x, int y, int w, int hmin, int hmax)
        }
        } // end of switch
 
-       label->u_vdata = (void*)this;
-       button->u_vdata = (void*)this;
+       label->u_vdata = this;
+       button->u_vdata = this;
 
        // Hmm, it seems fl_create_browser is broken in xforms 0.86.
        // We have to work around that by creating the dropped browser form
@@ -207,7 +209,7 @@ void Combox::add(int x, int y, int w, int hmin, int hmax)
        FL_FORM * current_form = fl_current_form;
        fl_end_form();
 
-       bw = w+20; bh = hmax-hmin-12;
+       bw = w + 20; bh = hmax - hmin - 12;
 
        form = fl_bgn_form(FL_NO_BOX, bw, bh);
        browser = obj = fl_add_browser(FL_HOLD_BROWSER, 0, 0, bw, bh, "");
@@ -216,7 +218,7 @@ void Combox::add(int x, int y, int w, int hmin, int hmax)
        fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity);
        fl_set_object_callback(obj, C_Combox_combo_cb, 2);
        fl_end_form();
-       browser->u_vdata = (void*)this;
+       browser->u_vdata = this;
        form->u_vdata = browser;
        fl_register_raw_callback(form, 
                                 ButtonPressMask|KeyPressMask,
@@ -309,23 +311,23 @@ void Combox::deactivate()
 
 void Combox::input_cb(FL_OBJECT *ob, long)
 {
-       Combox *combo = (Combox*)ob->u_vdata;
+       Combox * combo = static_cast<Combox*>(ob->u_vdata);
 
-       char const *text = fl_get_input(ob);
+       char const * text = fl_get_input(ob);
 
        combo->addto(text);
        combo->is_empty = false;
 }
 
-extern "C" void C_Combox_input_cb(FL_OBJECT *ob, long data)
+extern "C" void C_Combox_input_cb(FL_OBJECT * ob, long data)
 {
   Combox::input_cb(ob, data);
 }
 
 
-void Combox::combo_cb(FL_OBJECT *ob, long data)
+void Combox::combo_cb(FL_OBJECT * ob, long data)
 {
-       Combox *combo = (Combox*)ob->u_vdata;
+       Combox * combo = static_cast<Combox*>(ob->u_vdata);
        switch (data) {
        case 0:
        {  
@@ -357,39 +359,34 @@ void Combox::combo_cb(FL_OBJECT *ob, long data)
        }
 }
 
-extern "C" void C_Combox_combo_cb(FL_OBJECT *ob, long data) 
+extern "C" void C_Combox_combo_cb(FL_OBJECT * ob, long data) 
 {
        Combox::combo_cb(ob, data);
 }
 
 
-int Combox::peek_event(FL_FORM * form, void *xev)
+int Combox::peek_event(FL_FORM * form, void * xev)
 {
-       FL_OBJECT *ob = (FL_OBJECT *)form->u_vdata;
-       Combox *combo = (Combox*)ob->u_vdata;
+       FL_OBJECT * ob = static_cast<FL_OBJECT *>(form->u_vdata);
+       Combox * combo = static_cast<Combox*>(ob->u_vdata);
        
-#if FL_REVISION < 86
-       if(((XEvent *)xev)->type == ButtonPress && !ob->belowmouse)
-#endif
-#if FL_REVISION > 85
-// I don't know why belowmouse does not work, but it doesn't. (Asger)
-               if (((XEvent *) xev)->type == ButtonPress && (
-                       ((XEvent *)xev)->xbutton.x - ob->x < 0 ||
-                       ((XEvent *)xev)->xbutton.x - ob->x > ob->w ||
-                       ((XEvent *)xev)->xbutton.y - ob->y < 0 ||
-                       ((XEvent *)xev)->xbutton.y - ob->y > ob->h))
-#endif
-       {
+       // I don't know why belowmouse does not work, but it doesn't. (Asger)
+       // Are we sure? Please verify. (Lgb)
+       if (static_cast<XEvent *>(xev)->type == ButtonPress && (
+               static_cast<XEvent *>(xev)->xbutton.x - ob->x < 0 ||
+               static_cast<XEvent *>(xev)->xbutton.x - ob->x > ob->w ||
+               static_cast<XEvent *>(xev)->xbutton.y - ob->y < 0 ||
+               static_cast<XEvent *>(xev)->xbutton.y - ob->y > ob->h)) {
                combo->Hide(1); 
                return 1;
        }
                
-       if (((XEvent*)xev)->type != KeyPress) return 0;
+       if (static_cast<XEvent*>(xev)->type != KeyPress) return 0;
        
-       char s_r[10];
+       char s_r[10]; s_r[9] = '\0';
        static int num_bytes;
        KeySym keysym_return;
-       num_bytes = XLookupString(&((XEvent*)xev)->xkey, s_r, 10, 
+       num_bytes = XLookupString(&static_cast<XEvent*>(xev)->xkey, s_r, 10, 
                                  &keysym_return, 0);
        XFlush(fl_display);
        switch (keysym_return) {