4 * Copyright 2002 the LyX Team
5 * Copyright 1996 Alejandro Aguilar Sierra
6 * Read the file COPYING
8 * \author Alejandro Aguilar Sierra, asierra@servidor.unam.mx
11 /* A combination of two objects (a button and a browser) is encapsulated to
12 * get a combobox-like object. All XForms functions are hidden.
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.
63 The optional tabfolder arguments are needed to overcome an
64 xforms bug when repositioning a combox in a tab folder.
65 tabfolder1_ is the folder holding the combox.
66 If using nested tabfolders, tabfolder2_ is the "base" folder
69 void add(int x, int y, int w, int hmin, int hmax,
70 FL_OBJECT * tabfolder1_ = 0, FL_OBJECT * tabfolder2_ = 0);
72 /// Add lines. Same as for fl_browser object
73 void addline(string const &);
74 /// Add lines. Same as for fl_browser object
75 void addto(string const &);
77 /// Returns the selected item
80 /// Returns a pointer to the selected line of text
81 string const getline() const;
83 /// Select an arbitrary item
86 bool select(string const &);
88 /// Clear all the list
91 /// Is the combox cleared (empty)
92 bool empty() const { return is_empty; }
94 /// Remove the objects from the form they are in.
98 * Assign a callback to this object. The callback should be a void
99 * function with a int, a void pointer, and a Combox pointer as
102 void setcallback(FL_COMBO_CB, void *);
105 void setpre(FL_COMBO_PRE_POST);
107 void setpost(FL_COMBO_PRE_POST);
109 /// XForms attributes
110 void resize(unsigned);
112 void gravity(unsigned, unsigned);
118 void shortcut(string const &, int);
124 static void combo_cb(FL_OBJECT *, long);
126 static void input_cb(FL_OBJECT *, long);
128 static int peek_event(FL_FORM *, void *);
130 /// At least Hide should not be public
131 void hide(int who = 0);
146 FL_COMBO_CB callback;
150 FL_COMBO_PRE_POST _pre;
152 FL_COMBO_PRE_POST _post;
160 FL_OBJECT * tabfolder1;
162 FL_OBJECT * tabfolder2;
167 //----------------- Inline methods ---------------------------
170 void Combox::addto(string const & text)
173 fl_addto_browser(browser, text.c_str());
180 void Combox::resize(unsigned r)
182 fl_set_object_resize(button, r);
183 if (label!= button) fl_set_object_resize(label, r);
188 void Combox::gravity(unsigned g1, unsigned g2)
190 fl_set_object_gravity(button, g1, g2);
191 if (label!= button) fl_set_object_gravity(label, g1, g2);
196 void Combox::shortcut(string const & s, int i)
199 fl_set_object_shortcut(button, s.c_str(), i);
204 void Combox::setcallback(FL_COMBO_CB cb, void * a = 0)
212 void Combox::setpre(FL_COMBO_PRE_POST cb)
219 void Combox::setpost(FL_COMBO_PRE_POST cb)
226 int Combox::get() const
233 string const Combox::getline() const
235 if (type == FL_COMBOX_INPUT)
236 return fl_get_input(label);
238 return (browser && sel > 0) ?
239 string(fl_get_browser_line(browser, sel)) : string();