4 * Copyright 1996 Alejandro Aguilar Sierra
5 * This file is part of LyX, the document processor.
6 * Licence details can be found in the file COPYING.
8 * \author Alejandro Aguilar Sierra
10 * Full author contact details are available in file CREDITS
13 /* A combination of two objects (a button and a browser) is encapsulated to
14 * get a combobox-like object. All XForms functions are hidden.
18 * 2/06/1996, Alejandro Aguilar Sierra
21 * 4/06/1996, Alejandro Aguilar Sierra
22 * Added droplist mode (a button with a black down arrow at right)
23 * and support for middle and right buttons, as XForms choice object.
33 #include FORMS_H_LOCATION
49 /// callback prototype
50 typedef void (*FL_COMBO_CB) (int, void *, Combox *);
51 /// pre post prototype
52 typedef void (*FL_COMBO_PRE_POST) ();
59 explicit Combox(combox_type t = FL_COMBOX_NORMAL);
63 /** To add this object to a form. Note that there are two heights
64 * for normal (button) and expanded (browser) mode each.
66 void add(int x, int y, int w, int hmin, int hmax);
68 /// Add lines. Same as for fl_browser object
69 void addline(string const &);
70 /// Add lines. Same as for fl_browser object
71 void addto(string const &);
73 /// Returns the selected item
76 /// Returns a pointer to the selected line of text
77 string const getline() const;
79 /// Select an arbitrary item
82 bool select(string const &);
84 /// Clear all the list
87 /// Is the combox cleared (empty)
88 bool empty() const { return is_empty; }
90 /// Remove the objects from the form they are in.
94 * Assign a callback to this object. The callback should be a void
95 * function with a int, a void pointer, and a Combox pointer as
98 void setcallback(FL_COMBO_CB, void *);
101 void setpre(FL_COMBO_PRE_POST);
103 void setpost(FL_COMBO_PRE_POST);
105 /// XForms attributes
106 void resize(unsigned);
108 void gravity(unsigned, unsigned);
114 void shortcut(string const &, int);
120 static void combo_cb(FL_OBJECT *, long);
122 static void input_cb(FL_OBJECT *, long);
124 static int peek_event(FL_FORM *, void *);
126 /// At least Hide should not be public
127 void hide(int who = 0);
142 FL_COMBO_CB callback;
146 FL_COMBO_PRE_POST _pre;
148 FL_COMBO_PRE_POST _post;
159 //----------------- Inline methods ---------------------------
162 void Combox::addto(string const & text)
165 fl_addto_browser(browser, text.c_str());
172 void Combox::resize(unsigned r)
174 fl_set_object_resize(button, r);
175 if (label!= button) fl_set_object_resize(label, r);
180 void Combox::gravity(unsigned g1, unsigned g2)
182 fl_set_object_gravity(button, g1, g2);
183 if (label!= button) fl_set_object_gravity(label, g1, g2);
188 void Combox::shortcut(string const & s, int i)
191 fl_set_object_shortcut(button, s.c_str(), i);
196 void Combox::setcallback(FL_COMBO_CB cb, void * a = 0)
204 void Combox::setpre(FL_COMBO_PRE_POST cb)
211 void Combox::setpost(FL_COMBO_PRE_POST cb)
218 int Combox::get() const
225 string const Combox::getline() const
227 if (type == FL_COMBOX_INPUT)
228 return fl_get_input(label);
230 return (browser && sel > 0) ?
231 string(fl_get_browser_line(browser, sel)) : string();