]> git.lyx.org Git - lyx.git/blob - src/combox.h
Dekels tabular/textinset patches
[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, bh;
137         ///
138         int sel;
139         ///
140         bool is_empty;
141         ///
142         FL_COMBO_CB callback;
143         ///
144         void * cb_arg;
145         ///
146         FL_COMBO_PRE_POST _pre;
147         ///
148         FL_COMBO_PRE_POST _post;
149         ///
150         FL_OBJECT * button;
151         ///
152         FL_OBJECT * label;
153         ///
154         FL_FORM* form;
155         ///
156         FL_OBJECT * tabfolder1;
157         ///
158         FL_OBJECT * tabfolder2;
159 };
160
161
162
163 //-----------------  Inline methods  --------------------------- 
164
165 inline
166 void Combox::addto(string const & text)
167 {
168         if (browser) {
169                 fl_addto_browser(browser, text.c_str());
170                 is_empty = false;
171         }
172 }
173
174
175 inline
176 void Combox::resize(unsigned r)
177 {
178    fl_set_object_resize(button, r);
179    if (label!= button) fl_set_object_resize(label, r); 
180 }
181
182
183 inline
184 void Combox::gravity(unsigned g1, unsigned g2)
185 {
186    fl_set_object_gravity(button, g1, g2);
187    if (label!= button) fl_set_object_gravity(label, g1, g2); 
188 }
189
190
191 inline
192 void Combox::shortcut(string const & s, int i)
193 {
194    if (button)
195       fl_set_object_shortcut(button, s.c_str(), i);
196 }
197
198
199 inline
200 void Combox::setcallback(FL_COMBO_CB cb, void * a = 0)
201 {
202    callback = cb;
203    cb_arg = a;
204 }
205
206
207 inline
208 void Combox::setpre(FL_COMBO_PRE_POST cb)
209 {
210         _pre = cb;
211 }
212
213
214 inline
215 void Combox::setpost(FL_COMBO_PRE_POST cb)
216 {
217         _post = cb;
218 }
219
220
221 inline
222 int Combox::get() const
223 {
224    return sel;
225 }
226
227
228 inline
229 string const Combox::getline() const
230 {
231     if (type == FL_COMBOX_INPUT) 
232       return fl_get_input(label);
233     else
234       return (browser && sel > 0) ?
235               fl_get_browser_line(browser, sel) : string();
236 }
237
238 #endif