Updated doc/NEWS file
[midnight-commander.git] / lib / widget / quick.h
bloba88763aa3f72369549b0fb332ae00d72a8b62fd6
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, flags_, hname, res, id_) \
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 .flags = flags_, \
54 .histname = hname, \
55 .result = res \
56 } \
57 } \
60 #define QUICK_LABELED_INPUT(label_, label_loc, txt, flags_, hname, res, id_) \
61 { \
62 .widget_type = quick_input, \
63 .options = 0, \
64 .pos_flags = WPOS_KEEP_DEFAULT, \
65 .id = id_, \
66 .u = { \
67 .input = { \
68 .label_text = label_, \
69 .label_location = label_loc, \
70 .label = NULL, \
71 .text = txt, \
72 .flags = flags_, \
73 .histname = hname, \
74 .result = res \
75 } \
76 } \
79 #define QUICK_LABEL(txt, id_) \
80 { \
81 .widget_type = quick_label, \
82 .options = 0, \
83 .pos_flags = WPOS_KEEP_DEFAULT, \
84 .id = id_, \
85 .u = { \
86 .label = { \
87 .text = txt, \
88 .input = NULL \
89 } \
90 } \
93 #define QUICK_RADIO(cnt, items_, val, id_) \
94 { \
95 .widget_type = quick_radio, \
96 .options = 0, \
97 .pos_flags = WPOS_KEEP_DEFAULT, \
98 .id = id_, \
99 .u = { \
100 .radio = { \
101 .count = cnt, \
102 .items = items_, \
103 .value = val \
108 #define QUICK_START_GROUPBOX(t) \
110 .widget_type = quick_start_groupbox, \
111 .options = 0, \
112 .pos_flags = WPOS_KEEP_DEFAULT, \
113 .id = NULL, \
114 .u = { \
115 .groupbox = { \
116 .title = t \
121 #define QUICK_STOP_GROUPBOX \
123 .widget_type = quick_stop_groupbox, \
124 .options = 0, \
125 .pos_flags = WPOS_KEEP_DEFAULT, \
126 .id = NULL, \
127 .u = { \
128 .input = { \
129 .text = NULL, \
130 .flags = 0, \
131 .histname = NULL, \
132 .result = NULL \
137 #define QUICK_SEPARATOR(line_) \
139 .widget_type = quick_separator, \
140 .options = 0, \
141 .pos_flags = WPOS_KEEP_DEFAULT, \
142 .id = NULL, \
143 .u = { \
144 .separator = { \
145 .space = TRUE, \
146 .line = line_ \
151 #define QUICK_START_COLUMNS \
153 .widget_type = quick_start_columns, \
154 .options = 0, \
155 .pos_flags = WPOS_KEEP_DEFAULT, \
156 .id = NULL, \
157 .u = { \
158 .input = { \
159 .text = NULL, \
160 .flags = 0, \
161 .histname = NULL, \
162 .result = NULL \
167 #define QUICK_NEXT_COLUMN \
169 .widget_type = quick_next_column, \
170 .options = 0, \
171 .pos_flags = WPOS_KEEP_DEFAULT, \
172 .id = NULL, \
173 .u = { \
174 .input = { \
175 .text = NULL, \
176 .flags = 0, \
177 .histname = NULL, \
178 .result = NULL \
183 #define QUICK_STOP_COLUMNS \
185 .widget_type = quick_stop_columns, \
186 .options = 0, \
187 .pos_flags = WPOS_KEEP_DEFAULT, \
188 .id = NULL, \
189 .u = { \
190 .input = { \
191 .text = NULL, \
192 .flags = 0, \
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 .flags = 0, \
228 .histname = NULL, \
229 .result = NULL \
234 /*** enums ***************************************************************************************/
236 /* Quick Widgets */
237 typedef enum
239 quick_end = 0,
240 quick_checkbox = 1,
241 quick_button = 2,
242 quick_input = 3,
243 quick_label = 4,
244 quick_radio = 5,
245 quick_start_groupbox = 6,
246 quick_stop_groupbox = 7,
247 quick_separator = 8,
248 quick_start_columns = 9,
249 quick_next_column = 10,
250 quick_stop_columns = 11,
251 quick_buttons = 12
252 } quick_t;
254 typedef enum
256 input_label_none = 0,
257 input_label_above = 1,
258 input_label_left = 2,
259 input_label_right = 3,
260 input_label_below = 4
261 } quick_input_label_location_t;
263 /*** structures declarations (and typedefs of structures)*****************************************/
265 /* The widget is placed on relative_?/divisions_? of the parent widget */
266 typedef struct quick_widget_t quick_widget_t;
268 struct quick_widget_t
270 quick_t widget_type;
272 widget_options_t options;
273 widget_pos_flags_t pos_flags;
274 unsigned long *id;
276 /* widget parameters */
277 union
279 struct
281 const char *text;
282 int *state; /* in/out */
283 } checkbox;
285 struct
287 const char *text;
288 int action;
289 bcback_fn callback;
290 } button;
292 struct
294 const char *label_text;
295 quick_input_label_location_t label_location;
296 quick_widget_t *label;
297 const char *text;
298 int flags; /* 1 -- is_password, 2 -- INPUT_COMPLETE_CD */
299 const char *histname;
300 char **result;
301 gboolean strip_password;
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 */