]> git.lyx.org Git - lyx.git/blobdiff - src/combox.h
More fixes to insettabular/text (and some missing features added).
[lyx.git] / src / combox.h
index 981f51ddb08789d37a8ac9c3c8ce423c13b6c4d7..c948c1895f84a423681b4a31c2383e97d47b41fa 100644 (file)
@@ -30,6 +30,7 @@
 
 #include FORMS_H_LOCATION
 #include <cstdlib>
+#include "LString.h"
 
 ///
 enum combox_type {
@@ -41,8 +42,10 @@ enum combox_type {
        FL_COMBOX_INPUT
 };
 
+class Combox;
+
 /// callback prototype
-typedef void (*FL_COMBO_CB) (int, void *);
+typedef void (*FL_COMBO_CB) (int, void *, Combox *);
 /// pre post prototype
 typedef void (*FL_COMBO_PRE_POST) ();
 
@@ -51,41 +54,49 @@ typedef void (*FL_COMBO_PRE_POST) ();
 class Combox {
 public:
        ///
-       Combox(combox_type t = FL_COMBOX_NORMAL);
+       explicit Combox(combox_type t = FL_COMBOX_NORMAL);
        ///
        ~Combox();
 
        /** To add this object to a form. Note that there are two heights
-        for normal (button) and expanded (browser) mode each. */
-       void add(int x, int y, int w, int hmin, int hmax);
+           for normal (button) and expanded (browser) mode each.
+           The optional tabfolder arguments are needed to overcome an
+           xforms bug when repositioning a combox in a tab folder.
+           tabfolder1_ is the folder holding the combox.
+           If using nested tabfolders, tabfolder2_ is the "base" folder
+           holding tabfolder1_.
+       */
+       void add(int x, int y, int w, int hmin, int hmax,
+                FL_OBJECT * tabfolder1_ = 0, FL_OBJECT * tabfolder2_ = 0);
        
        /// Add lines. Same as for fl_browser object
-       void addline(char const *);
+       void addline(string const &);
        /// Add lines. Same as for fl_browser object
-       void addto(char const *);
+       void addto(string const &);
        
        /// Returns the selected item
-       int get();
+       int get() const;
    
        /// Returns a pointer to the selected line of text
-       char const * getline();
+       string const getline() const;
    
        ///  Select an arbitrary item
        void select(int);
        ///
-        bool select_text(char const *);
+        bool select_text(string const &);
    
        ///  Clear all the list
        void clear();
 
        /// Is the combox cleared (empty)
-       bool empty() { return is_empty; }
+       bool empty() const { return is_empty; }
        
        /// Remove the objects from the form they are in. 
        void remove();
 
        /**  Assign a callback to this object. The callback should be a void
-        function with a int and a void pointer as parameters. */
+        function with a int and a void pointer as parameters.
+       */
        void setcallback(FL_COMBO_CB, void *);
    
         ///  Pre handler
@@ -102,7 +113,7 @@ public:
        ///
        void deactivate();
        ///
-        void shortcut(char const *, int);
+        void shortcut(string const &, int);
        ///
        void Redraw();
        ///
@@ -141,6 +152,10 @@ public:
        FL_OBJECT * label;
        ///
         FL_FORM* form;
+       ///
+       FL_OBJECT * tabfolder1;
+       ///
+       FL_OBJECT * tabfolder2;
 };
 
 
@@ -148,10 +163,10 @@ public:
 //-----------------  Inline methods  --------------------------- 
 
 inline
-void Combox::addto(char const * text)
+void Combox::addto(string const & text)
 {
        if (browser) {
-               fl_addto_browser(browser, text);
+               fl_addto_browser(browser, text.c_str());
                is_empty = false;
        }
 }
@@ -174,10 +189,10 @@ void Combox::gravity(unsigned g1, unsigned g2)
 
 
 inline
-void Combox::shortcut(char const * s, int i)
+void Combox::shortcut(string const & s, int i)
 {
    if (button)
-      fl_set_object_shortcut(button, s, i);
+      fl_set_object_shortcut(button, s.c_str(), i);
 }
 
 
@@ -204,19 +219,20 @@ void Combox::setpost(FL_COMBO_PRE_POST cb)
 
 
 inline
-int Combox::get()
+int Combox::get() const
 {
    return sel;
 }
 
 
 inline
-char const * Combox::getline()
+string const Combox::getline() const
 {
     if (type == FL_COMBOX_INPUT) 
       return fl_get_input(label);
     else
-      return browser ? fl_get_browser_line(browser, sel) : 0;
+      return (browser && sel > 0) ?
+             fl_get_browser_line(browser, sel) : string();
 }
 
 #endif