]> git.lyx.org Git - lyx.git/blobdiff - src/combox.C
More fixes to insettabular/text (and some missing features added).
[lyx.git] / src / combox.C
index 400e3da44d6051e719d3e2cc95e65515358185d9..02e31059b1391f3f27d4f624c76fda942c2587ca 100644 (file)
@@ -48,7 +48,8 @@ extern "C" void C_Combox_input_cb(FL_OBJECT *ob, long);
 extern "C" void C_Combox_combo_cb(FL_OBJECT *ob, long data) ;
 extern "C" int C_Combox_peek_event(FL_FORM * form, void *xev);
 
-Combox::Combox(combox_type t): type(t)
+Combox::Combox(combox_type t)
+       : type(t), tabfolder1(0), tabfolder2(0)
 {
    browser = button = 0;
    callback = 0;
@@ -109,28 +110,30 @@ void Combox::remove()
 }
 
 
-void Combox::addline(char const* text)
+void Combox::addline(string const & text)
 {
        if (!browser) return;
-       fl_add_browser_line(browser, text);
+       fl_add_browser_line(browser, text.c_str());
        
        // By default the first item is selected
        if (!sel) {
                sel = 1;
                if (type == FL_COMBOX_INPUT)
-                       fl_set_input(label, text);
+                       fl_set_input(label, text.c_str());
                else
-                       fl_set_object_label(label, text); 
+                       fl_set_object_label(label, text.c_str()); 
        }
        is_empty = false;
 }
 
 
-bool Combox::select_text(char const* t)
+bool Combox::select_text(string const & t)
 {
-       if (!browser || !t) return false;
-       for (int i = 1; i <= fl_get_browser_maxline(browser); ++i) {
-               if (!strcmp(t, fl_get_browser_line(browser, i))) {
+       if (!browser || t.empty()) return false;
+       int const maxline = fl_get_browser_maxline(browser);
+       
+       for (int i = 1; i <= maxline; ++i) {
+               if (t == fl_get_browser_line(browser, i)) {
                        select(i);
                        return true;
                }
@@ -142,7 +145,7 @@ bool Combox::select_text(char const* t)
 void Combox::select(int i)
 {
        if (!browser || !button) return;
-       if (i>0 && i<= fl_get_browser_maxline(browser)) sel = i; 
+       if (i > 0 && i <= fl_get_browser_maxline(browser)) sel = i; 
        fl_deactivate_object(button);
        
        if (type == FL_COMBOX_INPUT)
@@ -153,11 +156,16 @@ void Combox::select(int i)
 }
 
 
-void Combox::add(int x, int y, int w, int hmin, int hmax)
-{  
-       FL_OBJECT *obj;
+void Combox::add(int x, int y, int w, int hmin, int hmax,
+                FL_OBJECT * tabfolder1_, FL_OBJECT * tabfolder2_)
+{
+       // Store these for later use in working round an xforms bug in Show()
+       tabfolder1 = tabfolder1_;
+       tabfolder2 = tabfolder2_;
+
+       FL_OBJECT * obj;
        
-       switch(type) {
+       switch (type) {
        case FL_COMBOX_DROPLIST:
        {
                button = obj = fl_add_button(FL_NORMAL_BUTTON,
@@ -244,24 +252,54 @@ void Combox::Show()
        if (_pre) _pre();
        
        int tmp;
-       XGetInputFocus(fl_display, &save_window, &tmp); //BUG-Fix Dietmar
-       XFlush(fl_display);
+       XGetInputFocus(fl_get_display(), &save_window, &tmp); //BUG-Fix Dietmar
+       XFlush(fl_get_display());
        if (button && type != FL_COMBOX_NORMAL) {
                fl_set_object_label(button, "@2<-");          
                fl_redraw_object(button);
        }
-       int x = label->form->x + label->x, y = label->form->y + label->y;
-       fl_set_form_position(form, x, y + label->h);
+
+       int x = label->x;
+       int y = label->y + label->h;
+       if (tabfolder1) {
+               // This is a bug work around suggested by Steve Lamont on the
+               // xforms mailing list. It correctly positions the browser form
+               // after the main window has been moved.
+               // The bug only occurs in tabbed folders.
+               int folder_x, folder_y, folder_w, folder_h;
+               fl_get_folder_area( tabfolder1,
+                                   &folder_x, &folder_y,
+                                   &folder_w, &folder_h );
+               x += folder_x;
+               y += folder_y;
+
+               if (tabfolder2) {
+                       fl_get_folder_area( tabfolder2,
+                                           &folder_x, &folder_y,
+                                           &folder_w, &folder_h );
+                       x += tabfolder2->form->x + folder_x;
+                       y += tabfolder2->form->y + folder_y;
+               } else {
+                       x += tabfolder1->form->x;
+                       y += tabfolder1->form->y;
+               }
+               
+       } else {
+               x += label->form->x;
+               y += label->form->y;
+       }
+
+       fl_set_form_position(form, x, y);
        fl_show_form(form, FL_PLACE_POSITION, FL_NOBORDER, "");
         if (sel>0) {
                fl_set_browser_topline(browser, sel);
                fl_select_browser_line(browser, sel);
        }
-       XGrabPointer(fl_display, form->window, false,
+       XGrabPointer(fl_get_display(), form->window, false,
                     ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
                     GrabModeAsync, GrabModeAsync,
                     0, 0, 0);
-       XFlush(fl_display);
+       XFlush(fl_get_display());
 }
 
 void Combox::Hide(int who)
@@ -274,15 +312,17 @@ void Combox::Hide(int who)
                else
                        fl_set_object_label(label,
                                            fl_get_browser_line(browser, sel));         
-               if (callback) callback(sel, cb_arg);
+//             if (callback) callback(sel, cb_arg);
        }
-        XUngrabPointer(fl_display, 0);
-       XFlush(fl_display);
+        XUngrabPointer(fl_get_display(), 0);
+       XFlush(fl_get_display());
+       if (!who && browser && label && callback)
+           callback(sel, cb_arg, this);
         if (form) {
                fl_hide_form(form);
-               XSetInputFocus(fl_display, save_window,
+               XSetInputFocus(fl_get_display(), save_window,
                               RevertToParent, CurrentTime); // BUG-FIX-Dietmar
-               XFlush(fl_display);
+               XFlush(fl_get_display());
         }
        if (button) {
                if (type != FL_COMBOX_NORMAL){
@@ -309,16 +349,18 @@ void Combox::deactivate()
        if (label) fl_deactivate_object(label);
 }
 
-void Combox::input_cb(FL_OBJECT *ob, long)
+
+void Combox::input_cb(FL_OBJECT * ob, long)
 {
        Combox * combo = static_cast<Combox*>(ob->u_vdata);
 
        char const * text = fl_get_input(ob);
 
-       combo->addto(text);
+       combo->addto(text ? text : string());
        combo->is_empty = false;
 }
 
+
 extern "C" void C_Combox_input_cb(FL_OBJECT * ob, long data)
 {
   Combox::input_cb(ob, data);
@@ -331,22 +373,22 @@ void Combox::combo_cb(FL_OBJECT * ob, long data)
        switch (data) {
        case 0:
        {  
-               int i = combo->get();
+               int const i = combo->get();
                switch (fl_get_button_numb(ob)) {
                case 2: 
                {
-                       combo->select(--i); 
+                       combo->select(i - 1); 
                        if (combo->callback)
                                combo->callback(combo->sel,
-                                               combo->cb_arg);
+                                               combo->cb_arg, combo);
                        break;
                }
                case 3: 
                {
-                       combo->select(++i);  
+                       combo->select(i + 1);  
                        if (combo->callback)
                                combo->callback(combo->sel,
-                                               combo->cb_arg);
+                                               combo->cb_arg, combo);
                        break;
                }
                default: combo->Show(); break;
@@ -384,11 +426,10 @@ int Combox::peek_event(FL_FORM * form, void * xev)
        if (static_cast<XEvent*>(xev)->type != KeyPress) return 0;
        
        char s_r[10]; s_r[9] = '\0';
-       static int num_bytes;
        KeySym keysym_return;
-       num_bytes = XLookupString(&static_cast<XEvent*>(xev)->xkey, s_r, 10, 
-                                 &keysym_return, 0);
-       XFlush(fl_display);
+       XLookupString(&static_cast<XEvent*>(xev)->xkey, s_r, 10, 
+                             &keysym_return, 0);
+       XFlush(fl_get_display());
        switch (keysym_return) {
        case XK_Down:
                if (fl_get_browser(combo->browser) <