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