Merge branch '4549_subshell_execl_argv0'
[midnight-commander.git] / lib / widget / quick.h
blob4f8abccb5ca21ced34a4e649f85aee0b187e5a67
1 /** \file quick.h
2 * \brief Header: quick dialog engine
3 */
5 #ifndef MC__QUICK_H
6 #define MC__QUICK_H
8 /*** typedefs(not structures) and defined constants **********************************************/
10 #define QUICK_CHECKBOX(txt, st, id_) \
11 { \
12 .widget_type = quick_checkbox, \
13 .options = WOP_DEFAULT, \
14 .pos_flags = WPOS_KEEP_DEFAULT, \
15 .id = id_, \
16 .u = { \
17 .checkbox = { \
18 .text = txt, \
19 .state = st \
20 } \
21 } \
24 #define QUICK_BUTTON(txt, act, cb, id_) \
25 { \
26 .widget_type = quick_button, \
27 .options = WOP_DEFAULT, \
28 .pos_flags = WPOS_KEEP_DEFAULT, \
29 .id = id_, \
30 .u = { \
31 .button = { \
32 .text = txt, \
33 .action = act, \
34 .callback = cb \
35 } \
36 } \
39 #define QUICK_INPUT(txt, hname, res, id_, is_passwd_, strip_passwd_, completion_flags_) \
40 { \
41 .widget_type = quick_input, \
42 .options = WOP_DEFAULT, \
43 .pos_flags = WPOS_KEEP_DEFAULT, \
44 .id = id_, \
45 .u = { \
46 .input = { \
47 .label_text = NULL, \
48 .label_location = input_label_none, \
49 .label = NULL, \
50 .text = txt, \
51 .completion_flags = completion_flags_, \
52 .is_passwd = is_passwd_, \
53 .strip_passwd = strip_passwd_, \
54 .histname = hname, \
55 .result = res \
56 } \
57 } \
60 #define QUICK_LABELED_INPUT(label_, label_loc, txt, hname, res, id_, is_passwd_, strip_passwd_, completion_flags_) \
61 { \
62 .widget_type = quick_input, \
63 .options = WOP_DEFAULT, \
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 .completion_flags = completion_flags_, \
73 .is_passwd = is_passwd_, \
74 .strip_passwd = strip_passwd_, \
75 .histname = hname, \
76 .result = res \
77 } \
78 } \
81 #define QUICK_LABEL(txt, id_) \
82 { \
83 .widget_type = quick_label, \
84 .options = WOP_DEFAULT, \
85 .pos_flags = WPOS_KEEP_DEFAULT, \
86 .id = id_, \
87 .u = { \
88 .label = { \
89 .text = txt, \
90 .input = NULL \
91 } \
92 } \
95 #define QUICK_RADIO(cnt, items_, val, id_) \
96 { \
97 .widget_type = quick_radio, \
98 .options = WOP_DEFAULT, \
99 .pos_flags = WPOS_KEEP_DEFAULT, \
100 .id = id_, \
101 .u = { \
102 .radio = { \
103 .count = cnt, \
104 .items = items_, \
105 .value = val \
110 #define QUICK_START_GROUPBOX(t) \
112 .widget_type = quick_start_groupbox, \
113 .options = WOP_DEFAULT, \
114 .pos_flags = WPOS_KEEP_DEFAULT, \
115 .id = NULL, \
116 .u = { \
117 .groupbox = { \
118 .title = t \
123 #define QUICK_STOP_GROUPBOX \
125 .widget_type = quick_stop_groupbox, \
126 .options = WOP_DEFAULT, \
127 .pos_flags = WPOS_KEEP_DEFAULT, \
128 .id = NULL, \
129 .u = { \
130 .input = { \
131 .text = NULL, \
132 .histname = NULL, \
133 .result = NULL \
138 #define QUICK_SEPARATOR(line_) \
140 .widget_type = quick_separator, \
141 .options = WOP_DEFAULT, \
142 .pos_flags = WPOS_KEEP_DEFAULT, \
143 .id = NULL, \
144 .u = { \
145 .separator = { \
146 .space = TRUE, \
147 .line = line_ \
152 #define QUICK_START_COLUMNS \
154 .widget_type = quick_start_columns, \
155 .options = WOP_DEFAULT, \
156 .pos_flags = WPOS_KEEP_DEFAULT, \
157 .id = NULL, \
158 .u = { \
159 .input = { \
160 .text = NULL, \
161 .histname = NULL, \
162 .result = NULL \
167 #define QUICK_NEXT_COLUMN \
169 .widget_type = quick_next_column, \
170 .options = WOP_DEFAULT, \
171 .pos_flags = WPOS_KEEP_DEFAULT, \
172 .id = NULL, \
173 .u = { \
174 .input = { \
175 .text = NULL, \
176 .histname = NULL, \
177 .result = NULL \
182 #define QUICK_STOP_COLUMNS \
184 .widget_type = quick_stop_columns, \
185 .options = WOP_DEFAULT, \
186 .pos_flags = WPOS_KEEP_DEFAULT, \
187 .id = NULL, \
188 .u = { \
189 .input = { \
190 .text = NULL, \
191 .histname = NULL, \
192 .result = NULL \
197 #define QUICK_START_BUTTONS(space_, line_) \
199 .widget_type = quick_buttons, \
200 .options = WOP_DEFAULT, \
201 .pos_flags = WPOS_KEEP_DEFAULT, \
202 .id = NULL, \
203 .u = { \
204 .separator = { \
205 .space = space_, \
206 .line = line_ \
211 #define QUICK_BUTTONS_OK_CANCEL \
212 QUICK_START_BUTTONS (TRUE, TRUE), \
213 QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL), \
214 QUICK_BUTTON (N_("&Cancel"), B_CANCEL, NULL, NULL)
216 #define QUICK_END \
218 .widget_type = quick_end, \
219 .options = WOP_DEFAULT, \
220 .pos_flags = WPOS_KEEP_DEFAULT, \
221 .id = NULL, \
222 .u = { \
223 .input = { \
224 .text = NULL, \
225 .histname = NULL, \
226 .result = NULL \
231 /*** enums ***************************************************************************************/
233 /* Quick Widgets */
234 typedef enum
236 quick_end = 0,
237 quick_checkbox = 1,
238 quick_button = 2,
239 quick_input = 3,
240 quick_label = 4,
241 quick_radio = 5,
242 quick_start_groupbox = 6,
243 quick_stop_groupbox = 7,
244 quick_separator = 8,
245 quick_start_columns = 9,
246 quick_next_column = 10,
247 quick_stop_columns = 11,
248 quick_buttons = 12
249 } quick_t;
251 typedef enum
253 input_label_none = 0,
254 input_label_above = 1,
255 input_label_left = 2,
256 input_label_right = 3,
257 input_label_below = 4
258 } quick_input_label_location_t;
260 /*** structures declarations (and typedefs of structures)*****************************************/
262 /* The widget is placed on relative_?/divisions_? of the parent widget */
263 typedef struct quick_widget_t quick_widget_t;
265 struct quick_widget_t
267 quick_t widget_type;
269 widget_options_t options;
270 widget_state_t state;
271 widget_pos_flags_t pos_flags;
272 unsigned long *id;
274 /* widget parameters */
275 union
277 struct
279 const char *text;
280 gboolean *state; /* in/out */
281 } checkbox;
283 struct
285 const char *text;
286 int action;
287 bcback_fn callback;
288 } button;
290 struct
292 const char *label_text;
293 quick_input_label_location_t label_location;
294 quick_widget_t *label;
295 const char *text;
296 input_complete_t completion_flags;
297 gboolean is_passwd; /* TRUE -- is password */
298 gboolean strip_passwd;
299 const char *histname;
300 char **result;
301 } input;
303 struct
305 const char *text;
306 quick_widget_t *input;
307 } label;
309 struct
311 int count;
312 const char **items;
313 int *value; /* in/out */
314 } radio;
316 struct
318 const char *title;
319 } groupbox;
321 struct
323 gboolean space;
324 gboolean line;
325 } separator;
326 } u;
329 typedef struct
331 WRect rect; /* if rect.x == -1 or rect.y == -1, then dialog is ceneterd;
332 * rect.lines is unused and ignored */
333 const char *title;
334 const char *help;
335 quick_widget_t *widgets;
336 widget_cb_fn callback;
337 widget_mouse_cb_fn mouse_callback;
338 } quick_dialog_t;
340 /*** global variables defined in .c file *********************************************************/
342 /*** declarations of public functions ************************************************************/
344 int quick_dialog_skip (quick_dialog_t * quick_dlg, int nskip);
346 /*** inline functions ****************************************************************************/
348 static inline int
349 quick_dialog (quick_dialog_t *quick_dlg)
351 return quick_dialog_skip (quick_dlg, 1);
354 #endif /* MC__QUICK_H */