]> 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 a4ff82a76e42f339b9c2373d1e13468b1a095c59..c948c1895f84a423681b4a31c2383e97d47b41fa 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.
  *    and support for middle and right buttons, as XForms choice object.
  */ 
 
-#ifndef _COMBOX_H_
-#define _COMBOX_H_
+#ifndef COMBOX_H
+#define COMBOX_H
 
 #ifdef __GNUG__
 #pragma interface
 #endif
 
 #include FORMS_H_LOCATION
-#include <stdlib.h>
+#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,16 +113,22 @@ public:
        ///
        void deactivate();
        ///
-        void shortcut(char const*, int);
+        void shortcut(string const &, int);
        ///
        void Redraw();
        ///
        void Show();
+       ///
+       static void combo_cb(FL_OBJECT *, long);
+       ///
+       static void input_cb(FL_OBJECT *, long);
+       ///
+        static int  peek_event(FL_FORM *, void *);
  protected:
         /// At least Hide should not be public
        void Hide(int who = 0);
        ///
-       FL_OBJECT *browser;
+       FL_OBJECT * browser;
  private:
        ///
        combox_type type;
@@ -122,25 +139,23 @@ public:
        ///
        bool is_empty;
        ///
-       static void combo_cb(FL_OBJECT *, long);
-       ///
-       static void input_cb(FL_OBJECT *, long);
-       ///
-        static int  peek_event(FL_FORM *, void *);
-       ///
        FL_COMBO_CB callback;
        ///
-       void *cb_arg;
+       void * cb_arg;
        ///
        FL_COMBO_PRE_POST _pre;
        ///
        FL_COMBO_PRE_POST _post;
        ///
-       FL_OBJECT *button;
+       FL_OBJECT * button;
        ///
-       FL_OBJECT *label;
+       FL_OBJECT * label;
        ///
         FL_FORM* form;
+       ///
+       FL_OBJECT * tabfolder1;
+       ///
+       FL_OBJECT * tabfolder2;
 };
 
 
@@ -148,69 +163,76 @@ 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;
        }
 }
 
+
 inline
 void Combox::resize(unsigned r)
 {
    fl_set_object_resize(button, r);
-   if (label!=button) fl_set_object_resize(label, r); 
+   if (label!= button) fl_set_object_resize(label, r); 
 }
 
+
 inline
 void Combox::gravity(unsigned g1, unsigned g2)
 {
    fl_set_object_gravity(button, g1, g2);
-   if (label!=button) fl_set_object_gravity(label, g1, g2); 
+   if (label!= button) fl_set_object_gravity(label, g1, 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);
 }
 
+
 inline
-void Combox::setcallback(FL_COMBO_CB cb, void *a = 0)
+void Combox::setcallback(FL_COMBO_CB cb, void * a = 0)
 {
    callback = cb;
    cb_arg = a;
 }
 
+
 inline
 void Combox::setpre(FL_COMBO_PRE_POST cb)
 {
        _pre = cb;
 }
 
+
 inline
 void Combox::setpost(FL_COMBO_PRE_POST cb)
 {
        _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) 
+    if (type == FL_COMBOX_INPUT) 
       return fl_get_input(label);
     else
-      return ((browser) ? fl_get_browser_line(browser, sel): (char const*)0);
+      return (browser && sel > 0) ?
+             fl_get_browser_line(browser, sel) : string();
 }
 
 #endif
-
-