]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/combox.h
Really dull and boring header shit
[lyx.git] / src / frontends / xforms / combox.h
1 // -*- C++ -*-
2 /**
3  * \file combox.h
4  * Copyright 1996 Alejandro Aguilar Sierra
5  * Read the file COPYING
6  *
7  * \author Alejandro Aguilar Sierra
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 /* A combination of two objects (a button and a browser) is encapsulated to
13  * get a combobox-like object. All XForms functions are hidden.
14  *
15  * Change log:
16  *
17  *  2/06/1996,   Alejandro Aguilar Sierra
18  *    Created and tested.
19  *
20  *  4/06/1996,   Alejandro Aguilar Sierra
21  *    Added droplist mode (a button with a black down arrow at right)
22  *    and support for middle and right buttons, as XForms choice object.
23  */
24
25 #ifndef COMBOX_H
26 #define COMBOX_H
27
28 #ifdef __GNUG__
29 #pragma interface
30 #endif
31
32 #include FORMS_H_LOCATION
33 #include <cstdlib>
34 #include "LString.h"
35
36 ///
37 enum combox_type {
38         ///
39         FL_COMBOX_NORMAL,
40         ///
41         FL_COMBOX_DROPLIST,
42         ///
43         FL_COMBOX_INPUT
44 };
45
46 class Combox;
47
48 /// callback prototype
49 typedef void (*FL_COMBO_CB) (int, void *, Combox *);
50 /// pre post prototype
51 typedef void (*FL_COMBO_PRE_POST) ();
52
53
54 ///
55 class Combox {
56 public:
57         ///
58         explicit Combox(combox_type t = FL_COMBOX_NORMAL);
59         ///
60         ~Combox();
61
62         /** To add this object to a form. Note that there are two heights
63             for normal (button) and expanded (browser) mode each.
64             The optional tabfolder arguments are needed to overcome an
65             xforms bug when repositioning a combox in a tab folder.
66             tabfolder1_ is the folder holding the combox.
67             If using nested tabfolders, tabfolder2_ is the "base" folder
68             holding tabfolder1_.
69         */
70         void add(int x, int y, int w, int hmin, int hmax,
71                  FL_OBJECT * tabfolder1_ = 0, FL_OBJECT * tabfolder2_ = 0);
72
73         /// Add lines. Same as for fl_browser object
74         void addline(string const &);
75         /// Add lines. Same as for fl_browser object
76         void addto(string const &);
77
78         /// Returns the selected item
79         int get() const;
80
81         /// Returns a pointer to the selected line of text
82         string const getline() const;
83
84         ///  Select an arbitrary item
85         void select(int);
86         ///
87         bool select(string const &);
88
89         ///  Clear all the list
90         void clear();
91
92         /// Is the combox cleared (empty)
93         bool empty() const { return is_empty; }
94
95         /// Remove the objects from the form they are in.
96         void remove();
97
98         /**
99          * Assign a callback to this object. The callback should be a void
100          * function with a int, a void pointer, and a Combox pointer as
101          * parameters.
102         */
103         void setcallback(FL_COMBO_CB, void *);
104
105         ///  Pre handler
106         void setpre(FL_COMBO_PRE_POST);
107         /// Post handler
108         void setpost(FL_COMBO_PRE_POST);
109
110         ///  XForms attributes
111         void resize(unsigned);
112         ///
113         void gravity(unsigned, unsigned);
114         ///
115         void activate();
116         ///
117         void deactivate();
118         ///
119         void shortcut(string const &, int);
120         ///
121         void redraw();
122         ///
123         void show();
124         ///
125         static void combo_cb(FL_OBJECT *, long);
126         ///
127         static void input_cb(FL_OBJECT *, long);
128         ///
129         static int  peek_event(FL_FORM *, void *);
130  protected:
131         /// At least Hide should not be public
132         void hide(int who = 0);
133         ///
134         FL_OBJECT * browser;
135  private:
136         ///
137         combox_type type;
138         ///
139         int bw;
140         ///
141         int bh;
142         ///
143         int sel;
144         ///
145         bool is_empty;
146         ///
147         FL_COMBO_CB callback;
148         ///
149         void * cb_arg;
150         ///
151         FL_COMBO_PRE_POST _pre;
152         ///
153         FL_COMBO_PRE_POST _post;
154         ///
155         FL_OBJECT * button;
156         ///
157         FL_OBJECT * label;
158         ///
159         FL_FORM* form;
160         ///
161         FL_OBJECT * tabfolder1;
162         ///
163         FL_OBJECT * tabfolder2;
164 };
165
166
167
168 //-----------------  Inline methods  ---------------------------
169
170 inline
171 void Combox::addto(string const & text)
172 {
173         if (browser) {
174                 fl_addto_browser(browser, text.c_str());
175                 is_empty = false;
176         }
177 }
178
179
180 inline
181 void Combox::resize(unsigned r)
182 {
183    fl_set_object_resize(button, r);
184    if (label!= button) fl_set_object_resize(label, r);
185 }
186
187
188 inline
189 void Combox::gravity(unsigned g1, unsigned g2)
190 {
191    fl_set_object_gravity(button, g1, g2);
192    if (label!= button) fl_set_object_gravity(label, g1, g2);
193 }
194
195
196 inline
197 void Combox::shortcut(string const & s, int i)
198 {
199    if (button)
200       fl_set_object_shortcut(button, s.c_str(), i);
201 }
202
203
204 inline
205 void Combox::setcallback(FL_COMBO_CB cb, void * a = 0)
206 {
207    callback = cb;
208    cb_arg = a;
209 }
210
211
212 inline
213 void Combox::setpre(FL_COMBO_PRE_POST cb)
214 {
215         _pre = cb;
216 }
217
218
219 inline
220 void Combox::setpost(FL_COMBO_PRE_POST cb)
221 {
222         _post = cb;
223 }
224
225
226 inline
227 int Combox::get() const
228 {
229    return sel;
230 }
231
232
233 inline
234 string const Combox::getline() const
235 {
236     if (type == FL_COMBOX_INPUT)
237       return fl_get_input(label);
238     else
239       return (browser && sel > 0) ?
240               string(fl_get_browser_line(browser, sel)) : string();
241 }
242
243 #endif