This commit was manufactured by cvs2svn to create tag
[lyx.git] / src / combox.h
blob0dfc461a27ae6710a77f9036c81e291440e1c88c
1 // -*- C++ -*-
2 /*
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.
6 *
7 * GNU Copyleft (C) 1996 Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
8 * and the LyX Team.
9 *
10 * Dependencies: Only XForms, but created to be used with LyX.
12 */
14 /* Change log:
16 * 2/06/1996, Alejandro Aguilar Sierra
17 * Created and tested.
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.
22 */
24 #ifndef _COMBOX_H_
25 #define _COMBOX_H_
27 #ifdef __GNUG__
28 #pragma interface
29 #endif
31 #include FORMS_H_LOCATION
32 #include <stdlib.h>
34 ///
35 enum combox_type {
36 ///
37 FL_COMBOX_NORMAL,
38 ///
39 FL_COMBOX_DROPLIST,
40 ///
41 FL_COMBOX_INPUT
44 /// callback prototype
45 typedef void (*FL_COMBO_CB) (int, void*);
46 /// pre post prototype
47 typedef void (*FL_COMBO_PRE_POST) ();
50 ///
51 class Combox {
52 public:
53 ///
54 Combox(combox_type t=FL_COMBOX_NORMAL);
55 ///
56 ~Combox();
58 /** To add this object to a form. Note that there are two heights
59 for normal (button) and expanded (browser) mode each. */
60 void add(int x, int y, int w, int hmin, int hmax);
62 /// Add lines. Same as for fl_browser object
63 void addline(char const*);
64 /// Add lines. Same as for fl_browser object
65 void addto(char const*);
67 /// Returns the selected item
68 int get();
70 /// Returns a pointer to the selected line of text
71 char const*getline();
73 /// Select an arbitrary item
74 void select(int);
75 ///
76 bool select_text(char const*);
78 /// Clear all the list
79 void clear();
81 /// Is the combox cleared (empty)
82 bool empty() { return is_empty; }
84 /// Remove the objects from the form they are in.
85 void remove();
87 /** Assign a callback to this object. The callback should be a void
88 function with a int and a void pointer as parameters. */
89 void setcallback(FL_COMBO_CB, void *);
91 /// Pre handler
92 void setpre(FL_COMBO_PRE_POST);
93 /// Post handler
94 void setpost(FL_COMBO_PRE_POST);
96 /// XForms attributes
97 void resize(unsigned);
98 ///
99 void gravity(unsigned, unsigned);
101 void activate();
103 void deactivate();
105 void shortcut(char const*, int);
107 void Redraw();
109 void Show();
111 static void combo_cb(FL_OBJECT *, long);
113 static void input_cb(FL_OBJECT *, long);
115 static int peek_event(FL_FORM *, void *);
116 protected:
117 /// At least Hide should not be public
118 void Hide(int who = 0);
120 FL_OBJECT *browser;
121 private:
123 combox_type type;
125 int bw, bh;
127 int sel;
129 bool is_empty;
131 FL_COMBO_CB callback;
133 void *cb_arg;
135 FL_COMBO_PRE_POST _pre;
137 FL_COMBO_PRE_POST _post;
139 FL_OBJECT *button;
141 FL_OBJECT *label;
143 FL_FORM* form;
148 //----------------- Inline methods ---------------------------
150 inline
151 void Combox::addto(char const* text)
153 if (browser) {
154 fl_addto_browser(browser, text);
155 is_empty = false;
159 inline
160 void Combox::resize(unsigned r)
162 fl_set_object_resize(button, r);
163 if (label!=button) fl_set_object_resize(label, r);
166 inline
167 void Combox::gravity(unsigned g1, unsigned g2)
169 fl_set_object_gravity(button, g1, g2);
170 if (label!=button) fl_set_object_gravity(label, g1, g2);
173 inline
174 void Combox::shortcut(char const* s, int i)
176 if (button)
177 fl_set_object_shortcut(button,s,i);
180 inline
181 void Combox::setcallback(FL_COMBO_CB cb, void *a = 0)
183 callback = cb;
184 cb_arg = a;
187 inline
188 void Combox::setpre(FL_COMBO_PRE_POST cb)
190 _pre = cb;
193 inline
194 void Combox::setpost(FL_COMBO_PRE_POST cb)
196 _post = cb;
199 inline
200 int Combox::get()
202 return sel;
205 inline
206 char const*Combox::getline()
208 if (type==FL_COMBOX_INPUT)
209 return fl_get_input(label);
210 else
211 return ((browser) ? fl_get_browser_line(browser, sel): (char const*)0);
214 #endif