3 * Combox: A combination of two objects (a button and a browser) is
4 * encapsulated to get a combobox-like object. All XForms
5 * functions are hidden.
7 * GNU Copyleft 1996 Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
10 * Dependencies: Only XForms, but created to be used with LyX.
16 * 2/06/1996, Alejandro Aguilar Sierra
19 * 4/06/1996, Alejandro Aguilar Sierra
20 * Added droplist mode (a button with a black down arrow at right)
21 * and support for middle and right buttons, as XForms choice object.
31 #include FORMS_H_LOCATION
47 /// callback prototype
48 typedef void (*FL_COMBO_CB) (int, void *, Combox *);
49 /// pre post prototype
50 typedef void (*FL_COMBO_PRE_POST) ();
57 explicit Combox(combox_type t = FL_COMBOX_NORMAL);
61 /** To add this object to a form. Note that there are two heights
62 for normal (button) and expanded (browser) mode each.
64 void add(int x, int y, int w, int hmin, int hmax);
66 /// Add lines. Same as for fl_browser object
67 void addline(string const &);
68 /// Add lines. Same as for fl_browser object
69 void addto(string const &);
71 /// Returns the selected item
74 /// Returns a pointer to the selected line of text
75 string const getline();
77 /// Select an arbitrary item
80 bool select_text(string const &);
82 /// Clear all the list
85 /// Is the combox cleared (empty)
86 bool empty() { return is_empty; }
88 /// Remove the objects from the form they are in.
91 /** Assign a callback to this object. The callback should be a void
92 function with a int and a void pointer as parameters.
94 void setcallback(FL_COMBO_CB, void *);
97 void setpre(FL_COMBO_PRE_POST);
99 void setpost(FL_COMBO_PRE_POST);
101 /// XForms attributes
102 void resize(unsigned);
104 void gravity(unsigned, unsigned);
110 void shortcut(string const &, int);
116 static void combo_cb(FL_OBJECT *, long);
118 static void input_cb(FL_OBJECT *, long);
120 static int peek_event(FL_FORM *, void *);
122 /// At least Hide should not be public
123 void Hide(int who = 0);
136 FL_COMBO_CB callback;
140 FL_COMBO_PRE_POST _pre;
142 FL_COMBO_PRE_POST _post;
153 //----------------- Inline methods ---------------------------
156 void Combox::addto(string const & text)
159 fl_addto_browser(browser, text.c_str());
166 void Combox::resize(unsigned r)
168 fl_set_object_resize(button, r);
169 if (label!= button) fl_set_object_resize(label, r);
174 void Combox::gravity(unsigned g1, unsigned g2)
176 fl_set_object_gravity(button, g1, g2);
177 if (label!= button) fl_set_object_gravity(label, g1, g2);
182 void Combox::shortcut(string const & s, int i)
185 fl_set_object_shortcut(button, s.c_str(), i);
190 void Combox::setcallback(FL_COMBO_CB cb, void * a = 0)
198 void Combox::setpre(FL_COMBO_PRE_POST cb)
205 void Combox::setpost(FL_COMBO_PRE_POST cb)
219 string const Combox::getline()
221 if (type == FL_COMBOX_INPUT)
222 return fl_get_input(label);
224 return (browser && sel > 0) ?
225 fl_get_browser_line(browser, sel) : string();