4 * Copyright 1996 Alejandro Aguilar Sierra
5 * Read the file COPYING
7 * \author Alejandro Aguilar Sierra
9 * Full author contact details are available in file CREDITS
12 /* A combination of two objects (a button and a browser) is encapsulated to
13 * get a combobox-like object. All XForms functions are hidden.
17 * 2/06/1996, Alejandro Aguilar Sierra
20 * 4/06/1996, Alejandro Aguilar Sierra
21 * Added droplist mode (a button with a black down arrow at right)
22 * and support for middle and right buttons, as XForms choice object.
32 #include FORMS_H_LOCATION
48 /// callback prototype
49 typedef void (*FL_COMBO_CB) (int, void *, Combox *);
50 /// pre post prototype
51 typedef void (*FL_COMBO_PRE_POST) ();
58 explicit Combox(combox_type t = FL_COMBOX_NORMAL);
62 /** To add this object to a form. Note that there are two heights
63 for normal (button) and expanded (browser) mode each.
64 The optional tabfolder arguments are needed to overcome an
65 xforms bug when repositioning a combox in a tab folder.
66 tabfolder1_ is the folder holding the combox.
67 If using nested tabfolders, tabfolder2_ is the "base" folder
70 void add(int x, int y, int w, int hmin, int hmax,
71 FL_OBJECT * tabfolder1_ = 0, FL_OBJECT * tabfolder2_ = 0);
73 /// Add lines. Same as for fl_browser object
74 void addline(string const &);
75 /// Add lines. Same as for fl_browser object
76 void addto(string const &);
78 /// Returns the selected item
81 /// Returns a pointer to the selected line of text
82 string const getline() const;
84 /// Select an arbitrary item
87 bool select(string const &);
89 /// Clear all the list
92 /// Is the combox cleared (empty)
93 bool empty() const { return is_empty; }
95 /// Remove the objects from the form they are in.
99 * Assign a callback to this object. The callback should be a void
100 * function with a int, a void pointer, and a Combox pointer as
103 void setcallback(FL_COMBO_CB, void *);
106 void setpre(FL_COMBO_PRE_POST);
108 void setpost(FL_COMBO_PRE_POST);
110 /// XForms attributes
111 void resize(unsigned);
113 void gravity(unsigned, unsigned);
119 void shortcut(string const &, int);
125 static void combo_cb(FL_OBJECT *, long);
127 static void input_cb(FL_OBJECT *, long);
129 static int peek_event(FL_FORM *, void *);
131 /// At least Hide should not be public
132 void hide(int who = 0);
147 FL_COMBO_CB callback;
151 FL_COMBO_PRE_POST _pre;
153 FL_COMBO_PRE_POST _post;
161 FL_OBJECT * tabfolder1;
163 FL_OBJECT * tabfolder2;
168 //----------------- Inline methods ---------------------------
171 void Combox::addto(string const & text)
174 fl_addto_browser(browser, text.c_str());
181 void Combox::resize(unsigned r)
183 fl_set_object_resize(button, r);
184 if (label!= button) fl_set_object_resize(label, r);
189 void Combox::gravity(unsigned g1, unsigned g2)
191 fl_set_object_gravity(button, g1, g2);
192 if (label!= button) fl_set_object_gravity(label, g1, g2);
197 void Combox::shortcut(string const & s, int i)
200 fl_set_object_shortcut(button, s.c_str(), i);
205 void Combox::setcallback(FL_COMBO_CB cb, void * a = 0)
213 void Combox::setpre(FL_COMBO_PRE_POST cb)
220 void Combox::setpost(FL_COMBO_PRE_POST cb)
227 int Combox::get() const
234 string const Combox::getline() const
236 if (type == FL_COMBOX_INPUT)
237 return fl_get_input(label);
239 return (browser && sel > 0) ?
240 string(fl_get_browser_line(browser, sel)) : string();