]> git.lyx.org Git - lyx.git/blob - src/combox.h
several small and larger changes, read the Changelog
[lyx.git] / src / combox.h
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.
11  * 
12  */ 
13
14 /* Change log:
15  *  
16  *  2/06/1996,   Alejandro Aguilar Sierra 
17  *    Created and tested.
18  *  
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  */ 
23
24 #ifndef COMBOX_H
25 #define COMBOX_H
26
27 #ifdef __GNUG__
28 #pragma interface
29 #endif
30
31 #include FORMS_H_LOCATION
32 #include <cstdlib>
33
34 ///
35 enum combox_type {
36         ///
37         FL_COMBOX_NORMAL,
38         ///
39         FL_COMBOX_DROPLIST,
40         ///
41         FL_COMBOX_INPUT
42 };
43
44 /// callback prototype
45 typedef void (*FL_COMBO_CB) (int, void *);
46 /// pre post prototype
47 typedef void (*FL_COMBO_PRE_POST) ();
48
49
50 ///
51 class Combox {
52 public:
53         ///
54         Combox(combox_type t = FL_COMBOX_NORMAL);
55         ///
56         ~Combox();
57
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);
61         
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 *);
66         
67         /// Returns the selected item
68         int get();
69    
70         /// Returns a pointer to the selected line of text
71         char const * getline();
72    
73         ///  Select an arbitrary item
74         void select(int);
75         ///
76         bool select_text(char const *);
77    
78         ///  Clear all the list
79         void clear();
80
81         /// Is the combox cleared (empty)
82         bool empty() { return is_empty; }
83         
84         /// Remove the objects from the form they are in. 
85         void remove();
86
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 *);
90    
91         ///  Pre handler
92         void setpre(FL_COMBO_PRE_POST);
93         /// Post handler
94         void setpost(FL_COMBO_PRE_POST);
95         
96         ///  XForms attributes
97         void resize(unsigned);
98         ///
99         void gravity(unsigned, unsigned);
100         ///
101         void activate();
102         ///
103         void deactivate();
104         ///
105         void shortcut(char const *, int);
106         ///
107         void Redraw();
108         ///
109         void Show();
110         ///
111         static void combo_cb(FL_OBJECT *, long);
112         ///
113         static void input_cb(FL_OBJECT *, long);
114         ///
115         static int  peek_event(FL_FORM *, void *);
116  protected:
117         /// At least Hide should not be public
118         void Hide(int who = 0);
119         ///
120         FL_OBJECT * browser;
121  private:
122         ///
123         combox_type type;
124         ///
125         int bw, bh;
126         ///
127         int sel;
128         ///
129         bool is_empty;
130         ///
131         FL_COMBO_CB callback;
132         ///
133         void * cb_arg;
134         ///
135         FL_COMBO_PRE_POST _pre;
136         ///
137         FL_COMBO_PRE_POST _post;
138         ///
139         FL_OBJECT * button;
140         ///
141         FL_OBJECT * label;
142         ///
143         FL_FORM* form;
144 };
145
146
147
148 //-----------------  Inline methods  --------------------------- 
149
150 inline
151 void Combox::addto(char const * text)
152 {
153         if (browser) {
154                 fl_addto_browser(browser, text);
155                 is_empty = false;
156         }
157 }
158
159
160 inline
161 void Combox::resize(unsigned r)
162 {
163    fl_set_object_resize(button, r);
164    if (label!= button) fl_set_object_resize(label, r); 
165 }
166
167
168 inline
169 void Combox::gravity(unsigned g1, unsigned g2)
170 {
171    fl_set_object_gravity(button, g1, g2);
172    if (label!= button) fl_set_object_gravity(label, g1, g2); 
173 }
174
175
176 inline
177 void Combox::shortcut(char const * s, int i)
178 {
179    if (button)
180       fl_set_object_shortcut(button, s, i);
181 }
182
183
184 inline
185 void Combox::setcallback(FL_COMBO_CB cb, void * a = 0)
186 {
187    callback = cb;
188    cb_arg = a;
189 }
190
191
192 inline
193 void Combox::setpre(FL_COMBO_PRE_POST cb)
194 {
195         _pre = cb;
196 }
197
198
199 inline
200 void Combox::setpost(FL_COMBO_PRE_POST cb)
201 {
202         _post = cb;
203 }
204
205
206 inline
207 int Combox::get()
208 {
209    return sel;
210 }
211
212
213 inline
214 char const * Combox::getline()
215 {
216     if (type == FL_COMBOX_INPUT) 
217       return fl_get_input(label);
218     else
219       return browser ? fl_get_browser_line(browser, sel) : 0;
220 }
221
222 #endif