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