]> git.lyx.org Git - lyx.git/blob - src/combox.h
0dfc461a27ae6710a77f9036c81e291440e1c88c
[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 <stdlib.h>
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 inline
160 void Combox::resize(unsigned r)
161 {
162    fl_set_object_resize(button, r);
163    if (label!=button) fl_set_object_resize(label, r); 
164 }
165
166 inline
167 void Combox::gravity(unsigned g1, unsigned g2)
168 {
169    fl_set_object_gravity(button, g1, g2);
170    if (label!=button) fl_set_object_gravity(label, g1, g2); 
171 }
172
173 inline
174 void Combox::shortcut(char const* s, int i)
175 {
176    if (button)
177       fl_set_object_shortcut(button,s,i);
178 }
179
180 inline
181 void Combox::setcallback(FL_COMBO_CB cb, void *a = 0)
182 {
183    callback = cb;
184    cb_arg = a;
185 }
186
187 inline
188 void Combox::setpre(FL_COMBO_PRE_POST cb)
189 {
190         _pre = cb;
191 }
192
193 inline
194 void Combox::setpost(FL_COMBO_PRE_POST cb)
195 {
196         _post = cb;
197 }
198
199 inline
200 int Combox::get()
201 {
202    return sel;
203 }
204
205 inline
206 char const*Combox::getline()
207 {
208     if (type==FL_COMBOX_INPUT) 
209       return fl_get_input(label);
210     else
211       return ((browser) ? fl_get_browser_line(browser, sel): (char const*)0);
212 }
213
214 #endif
215
216