mcfilemanager: use new quick dialog engine.
[midnight-commander.git] / lib / widget / quick2.h
blob21a74702bbcbf8a11129f3de5d9880f7945b11f9
1 /** \file quick2.h
2 * \brief Header: quick dialog engine
3 */
5 #ifndef MC__QUICK2_H
6 #define MC__QUICK2_H
8 #include "lib/tty/mouse.h"
10 /*** typedefs(not structures) and defined constants **********************************************/
12 #define QUICK2_CHECKBOX(txt, st, id_) \
13 { \
14 .widget_type = quick2_checkbox, \
15 .options = 0, \
16 .id = id_, \
17 .u = { \
18 .checkbox = { \
19 .text = txt, \
20 .state = st \
21 } \
22 } \
25 #define QUICK2_BUTTON(txt, act, cb, id_) \
26 { \
27 .widget_type = quick2_button, \
28 .options = 0, \
29 .id = id_, \
30 .u = { \
31 .button = { \
32 .text = txt, \
33 .action = act, \
34 .callback = cb \
35 } \
36 } \
39 #define QUICK2_INPUT(txt, flags_, hname, res, id_) \
40 { \
41 .widget_type = quick2_input, \
42 .options = 0, \
43 .id = id_, \
44 .u = { \
45 .input = { \
46 .label_text = NULL, \
47 .label_location = input_label_none, \
48 .label = NULL, \
49 .text = txt, \
50 .flags = flags_, \
51 .histname = hname, \
52 .result = res \
53 } \
54 } \
57 #define QUICK2_LABELED_INPUT(label_, label_loc, txt, flags_, hname, res, id_) \
58 { \
59 .widget_type = quick2_input, \
60 .options = 0, \
61 .id = id_, \
62 .u = { \
63 .input = { \
64 .label_text = label_, \
65 .label_location = label_loc, \
66 .label = NULL, \
67 .text = txt, \
68 .flags = flags_, \
69 .histname = hname, \
70 .result = res \
71 } \
72 } \
75 #define QUICK2_LABEL(txt, id_) \
76 { \
77 .widget_type = quick2_label, \
78 .options = 0, \
79 .id = id_, \
80 .u = { \
81 .label = { \
82 .text = txt, \
83 .input = NULL \
84 } \
85 } \
88 #define QUICK2_RADIO(cnt, items_, val, id_) \
89 { \
90 .widget_type = quick2_radio, \
91 .options = 0, \
92 .id = id_, \
93 .u = { \
94 .radio = { \
95 .count = cnt, \
96 .items = items_, \
97 .value = val \
98 } \
99 } \
102 #define QUICK2_START_GROUPBOX(t) \
104 .widget_type = quick2_start_groupbox, \
105 .options = 0, \
106 .id = NULL, \
107 .u = { \
108 .groupbox = { \
109 .title = t \
114 #define QUICK2_STOP_GROUPBOX \
116 .widget_type = quick2_stop_groupbox, \
117 .options = 0, \
118 .id = NULL, \
119 .u = { \
120 .input = { \
121 .text = NULL, \
122 .flags = 0, \
123 .histname = NULL, \
124 .result = NULL \
129 #define QUICK2_SEPARATOR(line_) \
131 .widget_type = quick2_separator, \
132 .options = 0, \
133 .id = NULL, \
134 .u = { \
135 .separator = { \
136 .space = TRUE, \
137 .line = line_ \
142 #define QUICK2_START_COLUMNS \
144 .widget_type = quick2_start_columns, \
145 .options = 0, \
146 .id = NULL, \
147 .u = { \
148 .input = { \
149 .text = NULL, \
150 .flags = 0, \
151 .histname = NULL, \
152 .result = NULL \
157 #define QUICK2_NEXT_COLUMN \
159 .widget_type = quick2_next_column, \
160 .options = 0, \
161 .id = NULL, \
162 .u = { \
163 .input = { \
164 .text = NULL, \
165 .flags = 0, \
166 .histname = NULL, \
167 .result = NULL \
172 #define QUICK2_STOP_COLUMNS \
174 .widget_type = quick2_stop_columns, \
175 .options = 0, \
176 .id = NULL, \
177 .u = { \
178 .input = { \
179 .text = NULL, \
180 .flags = 0, \
181 .histname = NULL, \
182 .result = NULL \
187 #define QUICK2_START_BUTTONS(space_, line_) \
189 .widget_type = quick2_buttons, \
190 .options = 0, \
191 .id = NULL, \
192 .u = { \
193 .separator = { \
194 .space = space_, \
195 .line = line_ \
200 #define QUICK2_END \
202 .widget_type = quick2_end, \
203 .options = 0, \
204 .id = NULL, \
205 .u = { \
206 .input = { \
207 .text = NULL, \
208 .flags = 0, \
209 .histname = NULL, \
210 .result = NULL \
215 /*** enums ***************************************************************************************/
217 /* Quick Widgets */
218 typedef enum
220 quick2_end = 0,
221 quick2_checkbox = 1,
222 quick2_button = 2,
223 quick2_input = 3,
224 quick2_label = 4,
225 quick2_radio = 5,
226 quick2_start_groupbox = 6,
227 quick2_stop_groupbox = 7,
228 quick2_separator = 8,
229 quick2_start_columns = 9,
230 quick2_next_column = 10,
231 quick2_stop_columns = 11,
232 quick2_buttons = 12
233 } quick2_t;
235 typedef enum
237 input_label_none = 0,
238 input_label_above = 1,
239 input_label_left = 2,
240 input_label_right = 3,
241 input_label_below = 4
242 } quick_input_label_location_t;
244 /*** structures declarations (and typedefs of structures)*****************************************/
246 /* The widget is placed on relative_?/divisions_? of the parent widget */
247 typedef struct quick_widget_t quick_widget_t;
249 struct quick_widget_t
251 quick2_t widget_type;
253 widget_options_t options;
254 unsigned long *id;
256 /* widget parameters */
257 union
259 struct
261 const char *text;
262 int *state; /* in/out */
263 } checkbox;
265 struct
267 const char *text;
268 int action;
269 bcback_fn callback;
270 } button;
272 struct
274 const char *label_text;
275 quick_input_label_location_t label_location;
276 quick_widget_t *label;
277 const char *text;
278 int flags; /* 1 -- is_password, 2 -- INPUT_COMPLETE_CD */
279 const char *histname;
280 char **result;
281 gboolean strip_password;
282 } input;
284 struct
286 const char *text;
287 quick_widget_t *input;
288 } label;
290 struct
292 int count;
293 const char **items;
294 int *value; /* in/out */
295 } radio;
297 struct
299 const char *title;
300 } groupbox;
302 struct
304 gboolean space;
305 gboolean line;
306 } separator;
307 } u;
310 typedef struct
312 int y, x; /* if -1, then center the dialog */
313 int cols; /* heigth is calculated automatically */
314 const char *title;
315 const char *help;
316 quick_widget_t *widgets;
317 dlg_cb_fn callback;
318 mouse_h mouse;
319 } quick_dialog_t;
321 /*** global variables defined in .c file *********************************************************/
323 /*** declarations of public functions ************************************************************/
325 int quick2_dialog_skip (quick_dialog_t * quick_dlg, int nskip);
327 /*** inline functions ****************************************************************************/
329 static inline int
330 quick2_dialog (quick_dialog_t * quick_dlg)
332 return quick2_dialog_skip (quick_dlg, 1);
335 #endif /* MC__QUICK2_H */