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