Extend QUICK_INPUT and QUICK_LABELED_INPUT macros for getting completion flags via...
[midnight-commander.git] / lib / widget / quick.h
blob73482d627ca60b497cd0529249e9bdc425509d3c
1 /** \file quick.h
2 * \brief Header: quick dialog engine
3 */
5 #ifndef MC__QUICK_H
6 #define MC__QUICK_H
8 #include "lib/tty/mouse.h"
10 /*** typedefs(not structures) and defined constants **********************************************/
12 #define QUICK_CHECKBOX(txt, st, id_) \
13 { \
14 .widget_type = quick_checkbox, \
15 .options = 0, \
16 .pos_flags = WPOS_KEEP_DEFAULT, \
17 .id = id_, \
18 .u = { \
19 .checkbox = { \
20 .text = txt, \
21 .state = st \
22 } \
23 } \
26 #define QUICK_BUTTON(txt, act, cb, id_) \
27 { \
28 .widget_type = quick_button, \
29 .options = 0, \
30 .pos_flags = WPOS_KEEP_DEFAULT, \
31 .id = id_, \
32 .u = { \
33 .button = { \
34 .text = txt, \
35 .action = act, \
36 .callback = cb \
37 } \
38 } \
41 #define QUICK_INPUT(txt, hname, res, id_, is_passwd_, strip_passwd_, completion_flags_) \
42 { \
43 .widget_type = quick_input, \
44 .options = 0, \
45 .pos_flags = WPOS_KEEP_DEFAULT, \
46 .id = id_, \
47 .u = { \
48 .input = { \
49 .label_text = NULL, \
50 .label_location = input_label_none, \
51 .label = NULL, \
52 .text = txt, \
53 .completion_flags = completion_flags_, \
54 .is_passwd = is_passwd_, \
55 .strip_passwd = strip_passwd_, \
56 .histname = hname, \
57 .result = res \
58 } \
59 } \
62 #define QUICK_LABELED_INPUT(label_, label_loc, txt, hname, res, id_, is_passwd_, strip_passwd_, completion_flags_) \
63 { \
64 .widget_type = quick_input, \
65 .options = 0, \
66 .pos_flags = WPOS_KEEP_DEFAULT, \
67 .id = id_, \
68 .u = { \
69 .input = { \
70 .label_text = label_, \
71 .label_location = label_loc, \
72 .label = NULL, \
73 .text = txt, \
74 .completion_flags = completion_flags_, \
75 .is_passwd = is_passwd_, \
76 .strip_passwd = strip_passwd_, \
77 .histname = hname, \
78 .result = res \
79 } \
80 } \
83 #define QUICK_LABEL(txt, id_) \
84 { \
85 .widget_type = quick_label, \
86 .options = 0, \
87 .pos_flags = WPOS_KEEP_DEFAULT, \
88 .id = id_, \
89 .u = { \
90 .label = { \
91 .text = txt, \
92 .input = NULL \
93 } \
94 } \
97 #define QUICK_RADIO(cnt, items_, val, id_) \
98 { \
99 .widget_type = quick_radio, \
100 .options = 0, \
101 .pos_flags = WPOS_KEEP_DEFAULT, \
102 .id = id_, \
103 .u = { \
104 .radio = { \
105 .count = cnt, \
106 .items = items_, \
107 .value = val \
112 #define QUICK_START_GROUPBOX(t) \
114 .widget_type = quick_start_groupbox, \
115 .options = 0, \
116 .pos_flags = WPOS_KEEP_DEFAULT, \
117 .id = NULL, \
118 .u = { \
119 .groupbox = { \
120 .title = t \
125 #define QUICK_STOP_GROUPBOX \
127 .widget_type = quick_stop_groupbox, \
128 .options = 0, \
129 .pos_flags = WPOS_KEEP_DEFAULT, \
130 .id = NULL, \
131 .u = { \
132 .input = { \
133 .text = NULL, \
134 .histname = NULL, \
135 .result = NULL \
140 #define QUICK_SEPARATOR(line_) \
142 .widget_type = quick_separator, \
143 .options = 0, \
144 .pos_flags = WPOS_KEEP_DEFAULT, \
145 .id = NULL, \
146 .u = { \
147 .separator = { \
148 .space = TRUE, \
149 .line = line_ \
154 #define QUICK_START_COLUMNS \
156 .widget_type = quick_start_columns, \
157 .options = 0, \
158 .pos_flags = WPOS_KEEP_DEFAULT, \
159 .id = NULL, \
160 .u = { \
161 .input = { \
162 .text = NULL, \
163 .histname = NULL, \
164 .result = NULL \
169 #define QUICK_NEXT_COLUMN \
171 .widget_type = quick_next_column, \
172 .options = 0, \
173 .pos_flags = WPOS_KEEP_DEFAULT, \
174 .id = NULL, \
175 .u = { \
176 .input = { \
177 .text = NULL, \
178 .histname = NULL, \
179 .result = NULL \
184 #define QUICK_STOP_COLUMNS \
186 .widget_type = quick_stop_columns, \
187 .options = 0, \
188 .pos_flags = WPOS_KEEP_DEFAULT, \
189 .id = NULL, \
190 .u = { \
191 .input = { \
192 .text = NULL, \
193 .histname = NULL, \
194 .result = NULL \
199 #define QUICK_START_BUTTONS(space_, line_) \
201 .widget_type = quick_buttons, \
202 .options = 0, \
203 .pos_flags = WPOS_KEEP_DEFAULT, \
204 .id = NULL, \
205 .u = { \
206 .separator = { \
207 .space = space_, \
208 .line = line_ \
213 #define QUICK_BUTTONS_OK_CANCEL \
214 QUICK_START_BUTTONS (TRUE, TRUE), \
215 QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL), \
216 QUICK_BUTTON (N_("&Cancel"), B_CANCEL, NULL, NULL)
218 #define QUICK_END \
220 .widget_type = quick_end, \
221 .options = 0, \
222 .pos_flags = WPOS_KEEP_DEFAULT, \
223 .id = NULL, \
224 .u = { \
225 .input = { \
226 .text = NULL, \
227 .histname = NULL, \
228 .result = NULL \
233 /*** enums ***************************************************************************************/
235 /* Quick Widgets */
236 typedef enum
238 quick_end = 0,
239 quick_checkbox = 1,
240 quick_button = 2,
241 quick_input = 3,
242 quick_label = 4,
243 quick_radio = 5,
244 quick_start_groupbox = 6,
245 quick_stop_groupbox = 7,
246 quick_separator = 8,
247 quick_start_columns = 9,
248 quick_next_column = 10,
249 quick_stop_columns = 11,
250 quick_buttons = 12
251 } quick_t;
253 typedef enum
255 input_label_none = 0,
256 input_label_above = 1,
257 input_label_left = 2,
258 input_label_right = 3,
259 input_label_below = 4
260 } quick_input_label_location_t;
262 /*** structures declarations (and typedefs of structures)*****************************************/
264 /* The widget is placed on relative_?/divisions_? of the parent widget */
265 typedef struct quick_widget_t quick_widget_t;
267 struct quick_widget_t
269 quick_t widget_type;
271 widget_options_t options;
272 widget_pos_flags_t pos_flags;
273 unsigned long *id;
275 /* widget parameters */
276 union
278 struct
280 const char *text;
281 int *state; /* in/out */
282 } checkbox;
284 struct
286 const char *text;
287 int action;
288 bcback_fn callback;
289 } button;
291 struct
293 const char *label_text;
294 quick_input_label_location_t label_location;
295 quick_widget_t *label;
296 const char *text;
297 input_complete_t completion_flags;
298 gboolean is_passwd; /* TRUE -- is password */
299 gboolean strip_passwd;
300 const char *histname;
301 char **result;
302 } input;
304 struct
306 const char *text;
307 quick_widget_t *input;
308 } label;
310 struct
312 int count;
313 const char **items;
314 int *value; /* in/out */
315 } radio;
317 struct
319 const char *title;
320 } groupbox;
322 struct
324 gboolean space;
325 gboolean line;
326 } separator;
327 } u;
330 typedef struct
332 int y, x; /* if -1, then center the dialog */
333 int cols; /* heigth is calculated automatically */
334 const char *title;
335 const char *help;
336 quick_widget_t *widgets;
337 widget_cb_fn callback;
338 mouse_h mouse;
339 } quick_dialog_t;
341 /*** global variables defined in .c file *********************************************************/
343 /*** declarations of public functions ************************************************************/
345 int quick_dialog_skip (quick_dialog_t * quick_dlg, int nskip);
347 /*** inline functions ****************************************************************************/
349 static inline int
350 quick_dialog (quick_dialog_t * quick_dlg)
352 return quick_dialog_skip (quick_dlg, 1);
355 #endif /* MC__QUICK_H */