]> git.lyx.org Git - lyx.git/blob - src/combox.h
mathed31.diff
[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 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 #include "LString.h"
34
35 ///
36 enum combox_type {
37         ///
38         FL_COMBOX_NORMAL,
39         ///
40         FL_COMBOX_DROPLIST,
41         ///
42         FL_COMBOX_INPUT
43 };
44
45 class Combox;
46
47 /// callback prototype
48 typedef void (*FL_COMBO_CB) (int, void *, Combox *);
49 /// pre post prototype
50 typedef void (*FL_COMBO_PRE_POST) ();
51
52
53 ///
54 class Combox {
55 public:
56         ///
57         explicit Combox(combox_type t = FL_COMBOX_NORMAL);
58         ///
59         ~Combox();
60
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
67             holding tabfolder1_.
68         */
69         void add(int x, int y, int w, int hmin, int hmax,
70                  FL_OBJECT * tabfolder1_ = 0, FL_OBJECT * tabfolder2_ = 0);
71         
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 &);
76         
77         /// Returns the selected item
78         int get() const;
79    
80         /// Returns a pointer to the selected line of text
81         string const getline() const;
82    
83         ///  Select an arbitrary item
84         void select(int);
85         ///
86         bool select_text(string const &);
87    
88         ///  Clear all the list
89         void clear();
90
91         /// Is the combox cleared (empty)
92         bool empty() const { return is_empty; }
93         
94         /// Remove the objects from the form they are in. 
95         void remove();
96
97         /**  Assign a callback to this object. The callback should be a void
98          function with a int and a void pointer as parameters.
99         */
100         void setcallback(FL_COMBO_CB, void *);
101    
102         ///  Pre handler
103         void setpre(FL_COMBO_PRE_POST);
104         /// Post handler
105         void setpost(FL_COMBO_PRE_POST);
106         
107         ///  XForms attributes
108         void resize(unsigned);
109         ///
110         void gravity(unsigned, unsigned);
111         ///
112         void activate();
113         ///
114         void deactivate();
115         ///
116         void shortcut(string const &, int);
117         ///
118         void Redraw();
119         ///
120         void Show();
121         ///
122         static void combo_cb(FL_OBJECT *, long);
123         ///
124         static void input_cb(FL_OBJECT *, long);
125         ///
126         static int  peek_event(FL_FORM *, void *);
127  protected:
128         /// At least Hide should not be public
129         void Hide(int who = 0);
130         ///
131         FL_OBJECT * browser;
132  private:
133         ///
134         combox_type type;
135         ///
136         int bw;
137         ///
138         int bh;
139         ///
140         int sel;
141         ///
142         bool is_empty;
143         ///
144         FL_COMBO_CB callback;
145         ///
146         void * cb_arg;
147         ///
148         FL_COMBO_PRE_POST _pre;
149         ///
150         FL_COMBO_PRE_POST _post;
151         ///
152         FL_OBJECT * button;
153         ///
154         FL_OBJECT * label;
155         ///
156         FL_FORM* form;
157         ///
158         FL_OBJECT * tabfolder1;
159         ///
160         FL_OBJECT * tabfolder2;
161 };
162
163
164
165 //-----------------  Inline methods  --------------------------- 
166
167 inline
168 void Combox::addto(string const & text)
169 {
170         if (browser) {
171                 fl_addto_browser(browser, text.c_str());
172                 is_empty = false;
173         }
174 }
175
176
177 inline
178 void Combox::resize(unsigned r)
179 {
180    fl_set_object_resize(button, r);
181    if (label!= button) fl_set_object_resize(label, r); 
182 }
183
184
185 inline
186 void Combox::gravity(unsigned g1, unsigned g2)
187 {
188    fl_set_object_gravity(button, g1, g2);
189    if (label!= button) fl_set_object_gravity(label, g1, g2); 
190 }
191
192
193 inline
194 void Combox::shortcut(string const & s, int i)
195 {
196    if (button)
197       fl_set_object_shortcut(button, s.c_str(), i);
198 }
199
200
201 inline
202 void Combox::setcallback(FL_COMBO_CB cb, void * a = 0)
203 {
204    callback = cb;
205    cb_arg = a;
206 }
207
208
209 inline
210 void Combox::setpre(FL_COMBO_PRE_POST cb)
211 {
212         _pre = cb;
213 }
214
215
216 inline
217 void Combox::setpost(FL_COMBO_PRE_POST cb)
218 {
219         _post = cb;
220 }
221
222
223 inline
224 int Combox::get() const
225 {
226    return sel;
227 }
228
229
230 inline
231 string const Combox::getline() const
232 {
233     if (type == FL_COMBOX_INPUT) 
234       return fl_get_input(label);
235     else
236       return (browser && sel > 0) ?
237               string(fl_get_browser_line(browser, sel)) : string();
238 }
239
240 #endif