Improvements of QuickDialog engine.
[free-mc.git] / src / wtools.h
blob047532f95eb2b56da762771ba868acac9c7b2e1d
2 /** \file wtools.h
3 * \brief Header: widget based utility functions
4 */
6 #ifndef MC_WTOOLS_H
7 #define MC_WTOOLS_H
9 #include "lib/global.h"
10 #include "dialog.h"
11 #include "widget.h"
13 typedef struct
15 struct Dlg_head *dlg;
16 struct WListbox *list;
17 } Listbox;
19 /* Listbox utility functions */
20 Listbox *create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
21 const char *title, const char *help);
22 Listbox *create_listbox_window (int lines, int cols, const char *title, const char *help);
23 #define LISTBOX_APPEND_TEXT(l,h,t,d) \
24 listbox_add_item (l->list, LISTBOX_APPEND_AT_END, h, t, d)
26 int run_listbox (Listbox * l);
28 /* Quick Widgets */
29 typedef enum
31 quick_end = 0,
32 quick_checkbox = 1,
33 quick_button = 2,
34 quick_input = 3,
35 quick_label = 4,
36 quick_radio = 5,
37 quick_groupbox = 6
38 } quick_t;
40 /* The widget is placed on relative_?/divisions_? of the parent widget */
41 typedef struct
43 quick_t widget_type;
45 int relative_x;
46 int x_divisions;
47 int relative_y;
48 int y_divisions;
50 Widget *widget;
51 widget_options_t options;
53 /* widget parameters */
54 union
56 struct
58 const char *text;
59 int *state; /* in/out */
60 } checkbox;
62 struct
64 const char *text;
65 int action;
66 bcback callback;
67 } button;
69 struct
71 const char *text;
72 int len;
73 int flags; /* 1 -- is_password, 2 -- INPUT_COMPLETE_CD */
74 const char *histname;
75 char **result;
76 } input;
78 struct
80 const char *text;
81 } label;
83 struct
85 int count;
86 const char **items;
87 int *value; /* in/out */
88 } radio;
90 struct
92 int width;
93 int height;
94 const char *title;
95 } groupbox;
96 } u;
97 } QuickWidget;
99 #define QUICK_CHECKBOX(x, xdiv, y, ydiv, txt, st) \
101 .widget_type = quick_checkbox, \
102 .relative_x = x, \
103 .x_divisions = xdiv, \
104 .relative_y = y, \
105 .y_divisions = ydiv, \
106 .widget = NULL, \
107 .options = 0, \
108 .u = { \
109 .checkbox = { \
110 .text = txt, \
111 .state = st \
116 #define QUICK_BUTTON(x, xdiv, y, ydiv, txt, act, cb) \
118 .widget_type = quick_button, \
119 .relative_x = x, \
120 .x_divisions = xdiv, \
121 .relative_y = y, \
122 .y_divisions = ydiv, \
123 .widget = NULL, \
124 .options = 0, \
125 .u = { \
126 .button = { \
127 .text = txt, \
128 .action = act, \
129 .callback = cb \
134 #define QUICK_INPUT(x, xdiv, y, ydiv, txt, len_, flags_, hname, res) \
136 .widget_type = quick_input, \
137 .relative_x = x, \
138 .x_divisions = xdiv, \
139 .relative_y = y, \
140 .y_divisions = ydiv, \
141 .widget = NULL, \
142 .options = 0, \
143 .u = { \
144 .input = { \
145 .text = txt, \
146 .len = len_, \
147 .flags = flags_, \
148 .histname = hname, \
149 .result = res \
154 #define QUICK_LABEL(x, xdiv, y, ydiv, txt) \
156 .widget_type = quick_label, \
157 .relative_x = x, \
158 .x_divisions = xdiv, \
159 .relative_y = y, \
160 .y_divisions = ydiv, \
161 .widget = NULL, \
162 .options = 0, \
163 .u = { \
164 .label = { \
165 .text = txt \
170 #define QUICK_RADIO(x, xdiv, y, ydiv, cnt, items_, val) \
172 .widget_type = quick_radio, \
173 .relative_x = x, \
174 .x_divisions = xdiv, \
175 .relative_y = y, \
176 .y_divisions = ydiv, \
177 .widget = NULL, \
178 .options = 0, \
179 .u = { \
180 .radio = { \
181 .count = cnt, \
182 .items = items_, \
183 .value = val \
188 #define QUICK_GROUPBOX(x, xdiv, y, ydiv, w, h, t) \
190 .widget_type = quick_groupbox, \
191 .relative_x = x, \
192 .x_divisions = xdiv, \
193 .relative_y = y, \
194 .y_divisions = ydiv, \
195 .widget = NULL, \
196 .options = 0, \
197 .u = { \
198 .groupbox = { \
199 .width = w, \
200 .height = h, \
201 .title = t \
206 #define QUICK_END \
208 .widget_type = quick_end, \
209 .relative_x = 0, \
210 .x_divisions = 0, \
211 .relative_y = 0, \
212 .y_divisions = 0, \
213 .widget = NULL, \
214 .options = 0, \
215 .u = { \
216 .input = { \
217 .text = NULL, \
218 .len = 0, \
219 .flags = 0, \
220 .histname = NULL, \
221 .result = NULL \
226 typedef struct
228 int xlen, ylen;
229 int xpos, ypos; /* if -1, then center the dialog */
230 const char *title;
231 const char *help;
232 QuickWidget *widgets;
233 dlg_cb_fn callback;
234 gboolean i18n; /* If true, internationalization has happened */
235 } QuickDialog;
237 int quick_dialog (QuickDialog * qd);
238 int quick_dialog_skip (QuickDialog * qd, int nskip);
240 /* The input dialogs */
242 /* Pass this as def_text to request a password */
243 #define INPUT_PASSWORD ((char *) -1)
245 char *input_dialog (const char *header, const char *text,
246 const char *history_name, const char *def_text);
247 char *input_dialog_help (const char *header, const char *text, const char *help,
248 const char *history_name, const char *def_text);
249 char *input_expand_dialog (const char *header, const char *text,
250 const char *history_name, const char *def_text);
252 void query_set_sel (int new_sel);
254 /* Create message box but don't dismiss it yet, not background safe */
255 struct Dlg_head *create_message (int flags, const char *title,
256 const char *text, ...) __attribute__ ((format (__printf__, 3, 4)));
258 /* Show message box, background safe */
259 void message (int flags, const char *title, const char *text, ...)
260 __attribute__ ((format (__printf__, 3, 4)));
263 /* Use this as header for message() - it expands to "Error" */
264 #define MSG_ERROR ((char *) -1)
266 int query_dialog (const char *header, const char *text, int flags, int count, ...);
268 /* flags for message() and query_dialog() */
269 enum
271 D_NORMAL = 0,
272 D_ERROR = 1
273 } /* dialog options */ ;
275 #endif