]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/combox.h
dont use pragma impementation and interface anymore
[lyx.git] / src / frontends / xforms / combox.h
1 // -*- C++ -*-
2 /**
3  * \file combox.h
4  * Copyright 1996 Alejandro Aguilar Sierra
5  * This file is part of LyX, the document processor.
6  * Licence details can be found in the file COPYING.
7  *
8  * \author Alejandro Aguilar Sierra
9  *
10  * Full author contact details are available in file CREDITS
11  */
12
13 /* A combination of two objects (a button and a browser) is encapsulated to
14  * get a combobox-like object. All XForms functions are hidden.
15  *
16  * Change log:
17  *
18  *  2/06/1996,   Alejandro Aguilar Sierra
19  *    Created and tested.
20  *
21  *  4/06/1996,   Alejandro Aguilar Sierra
22  *    Added droplist mode (a button with a black down arrow at right)
23  *    and support for middle and right buttons, as XForms choice object.
24  */
25
26 #ifndef COMBOX_H
27 #define COMBOX_H
28
29
30 #include FORMS_H_LOCATION
31 #include <cstdlib>
32 #include "LString.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 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(string const &);
67         /// Add lines. Same as for fl_browser object
68         void addto(string const &);
69
70         /// Returns the selected item
71         int get() const;
72
73         /// Returns a pointer to the selected line of text
74         string const getline() const;
75
76         ///  Select an arbitrary item
77         void select(int);
78         ///
79         bool select(string const &);
80
81         ///  Clear all the list
82         void clear();
83
84         /// Is the combox cleared (empty)
85         bool empty() const { return is_empty; }
86
87         /// Remove the objects from the form they are in.
88         void remove();
89
90         /**
91          * Assign a callback to this object. The callback should be a void
92          * function with a int, a void pointer, and a Combox pointer as
93          * parameters.
94         */
95         void setcallback(FL_COMBO_CB, void *);
96
97         ///  Pre handler
98         void setpre(FL_COMBO_PRE_POST);
99         /// Post handler
100         void setpost(FL_COMBO_PRE_POST);
101
102         ///  XForms attributes
103         void resize(unsigned);
104         ///
105         void gravity(unsigned, unsigned);
106         ///
107         void activate();
108         ///
109         void deactivate();
110         ///
111         void shortcut(string const &, int);
112         ///
113         void redraw();
114         ///
115         void show();
116         ///
117         static void combo_cb(FL_OBJECT *, long);
118         ///
119         static void input_cb(FL_OBJECT *, long);
120         ///
121         static int  peek_event(FL_FORM *, void *);
122  protected:
123         /// At least Hide should not be public
124         void hide(int who = 0);
125         ///
126         FL_OBJECT * browser;
127  private:
128         ///
129         combox_type type;
130         ///
131         int bw;
132         ///
133         int bh;
134         ///
135         int sel;
136         ///
137         bool is_empty;
138         ///
139         FL_COMBO_CB callback;
140         ///
141         void * cb_arg;
142         ///
143         FL_COMBO_PRE_POST _pre;
144         ///
145         FL_COMBO_PRE_POST _post;
146         ///
147         FL_OBJECT * button;
148         ///
149         FL_OBJECT * label;
150         ///
151         FL_FORM* form;
152 };
153
154
155
156 //-----------------  Inline methods  ---------------------------
157
158 inline
159 void Combox::addto(string const & text)
160 {
161         if (browser) {
162                 fl_addto_browser(browser, text.c_str());
163                 is_empty = false;
164         }
165 }
166
167
168 inline
169 void Combox::resize(unsigned r)
170 {
171    fl_set_object_resize(button, r);
172    if (label!= button) fl_set_object_resize(label, r);
173 }
174
175
176 inline
177 void Combox::gravity(unsigned g1, unsigned g2)
178 {
179    fl_set_object_gravity(button, g1, g2);
180    if (label!= button) fl_set_object_gravity(label, g1, g2);
181 }
182
183
184 inline
185 void Combox::shortcut(string const & s, int i)
186 {
187    if (button)
188       fl_set_object_shortcut(button, s.c_str(), i);
189 }
190
191
192 inline
193 void Combox::setcallback(FL_COMBO_CB cb, void * a = 0)
194 {
195    callback = cb;
196    cb_arg = a;
197 }
198
199
200 inline
201 void Combox::setpre(FL_COMBO_PRE_POST cb)
202 {
203         _pre = cb;
204 }
205
206
207 inline
208 void Combox::setpost(FL_COMBO_PRE_POST cb)
209 {
210         _post = cb;
211 }
212
213
214 inline
215 int Combox::get() const
216 {
217    return sel;
218 }
219
220
221 inline
222 string const Combox::getline() const
223 {
224     if (type == FL_COMBOX_INPUT)
225       return fl_get_input(label);
226     else
227       return (browser && sel > 0) ?
228               string(fl_get_browser_line(browser, sel)) : string();
229 }
230
231 #endif