Support of multiple editors and viewers.
[midnight-commander.git] / src / wtools.h
blob8205d3a59e05b1b50a325db758331e840016f76f
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 {
14 struct Dlg_head *dlg;
15 struct WListbox *list;
16 } Listbox;
18 /* Listbox utility functions */
19 Listbox *create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
20 const char *title, const char *help);
21 Listbox *create_listbox_window (int lines, int cols, const char *title, const char *help);
22 #define LISTBOX_APPEND_TEXT(l,h,t,d) \
23 listbox_add_item (l->list, LISTBOX_APPEND_AT_END, h, t, d)
25 int run_listbox (Listbox *l);
27 /* Quick Widgets */
28 typedef enum {
29 quick_end = 0,
30 quick_checkbox = 1,
31 quick_button = 2,
32 quick_input = 3,
33 quick_label = 4,
34 quick_radio = 5,
35 quick_groupbox = 6
36 } quick_t;
38 /* The widget is placed on relative_?/divisions_? of the parent widget */
39 typedef struct {
40 quick_t widget_type;
42 int relative_x;
43 int x_divisions;
44 int relative_y;
45 int y_divisions;
47 Widget *widget;
49 /* widget parameters */
50 union {
51 struct {
52 const char *text;
53 int *state; /* in/out */
54 } checkbox;
56 struct {
57 const char *text;
58 int action;
59 bcback callback;
60 } button;
62 struct {
63 const char *text;
64 int len;
65 int flags; /* 1 -- is_password, 2 -- INPUT_COMPLETE_CD */
66 const char *histname;
67 char **result;
68 } input;
70 struct {
71 const char *text;
72 } label;
74 struct {
75 int count;
76 const char **items;
77 int *value; /* in/out */
78 } radio;
80 struct {
81 int width;
82 int height;
83 const char *title;
84 } groupbox;
85 } u;
86 } QuickWidget;
88 #define QUICK_CHECKBOX(x, xdiv, y, ydiv, txt, st) \
89 { \
90 .widget_type = quick_checkbox, \
91 .relative_x = x, \
92 .x_divisions = xdiv, \
93 .relative_y = y, \
94 .y_divisions = ydiv, \
95 .widget = NULL, \
96 .u = { \
97 .checkbox = { \
98 .text = txt, \
99 .state = st \
104 #define QUICK_BUTTON(x, xdiv, y, ydiv, txt, act, cb) \
106 .widget_type = quick_button, \
107 .relative_x = x, \
108 .x_divisions = xdiv, \
109 .relative_y = y, \
110 .y_divisions = ydiv, \
111 .widget = NULL, \
112 .u = { \
113 .button = { \
114 .text = txt, \
115 .action = act, \
116 .callback = cb \
121 #define QUICK_INPUT(x, xdiv, y, ydiv, txt, len_, flags_, hname, res) \
123 .widget_type = quick_input, \
124 .relative_x = x, \
125 .x_divisions = xdiv, \
126 .relative_y = y, \
127 .y_divisions = ydiv, \
128 .widget = NULL, \
129 .u = { \
130 .input = { \
131 .text = txt, \
132 .len = len_, \
133 .flags = flags_, \
134 .histname = hname, \
135 .result = res \
140 #define QUICK_LABEL(x, xdiv, y, ydiv, txt) \
142 .widget_type = quick_label, \
143 .relative_x = x, \
144 .x_divisions = xdiv, \
145 .relative_y = y, \
146 .y_divisions = ydiv, \
147 .widget = NULL, \
148 .u = { \
149 .label = { \
150 .text = txt \
155 #define QUICK_RADIO(x, xdiv, y, ydiv, cnt, items_, val) \
157 .widget_type = quick_radio, \
158 .relative_x = x, \
159 .x_divisions = xdiv, \
160 .relative_y = y, \
161 .y_divisions = ydiv, \
162 .widget = NULL, \
163 .u = { \
164 .radio = { \
165 .count = cnt, \
166 .items = items_, \
167 .value = val \
172 #define QUICK_GROUPBOX(x, xdiv, y, ydiv, w, h, t) \
174 .widget_type = quick_groupbox, \
175 .relative_x = x, \
176 .x_divisions = xdiv, \
177 .relative_y = y, \
178 .y_divisions = ydiv, \
179 .widget = NULL, \
180 .u = { \
181 .groupbox = { \
182 .width = w, \
183 .height = h, \
184 .title = t \
189 #define QUICK_END \
191 .widget_type = quick_end, \
192 .relative_x = 0, \
193 .x_divisions = 0, \
194 .relative_y = 0, \
195 .y_divisions = 0, \
196 .widget = NULL, \
197 .u = { \
198 .input = { \
199 .text = NULL, \
200 .len = 0, \
201 .flags = 0, \
202 .histname = NULL, \
203 .result = NULL \
208 typedef struct {
209 int xlen, ylen;
210 int xpos, ypos; /* if -1, then center the dialog */
211 const char *title;
212 const char *help;
213 QuickWidget *widgets;
214 gboolean i18n; /* If true, internationalization has happened */
215 } QuickDialog;
217 int quick_dialog (QuickDialog *qd);
218 int quick_dialog_skip (QuickDialog *qd, int nskip);
220 /* The input dialogs */
222 /* Pass this as def_text to request a password */
223 #define INPUT_PASSWORD ((char *) -1)
225 char *input_dialog (const char *header, const char *text,
226 const char *history_name, const char *def_text);
227 char *input_dialog_help (const char *header, const char *text, const char *help,
228 const char *history_name, const char *def_text);
229 char *input_expand_dialog (const char *header, const char *text,
230 const char *history_name, const char *def_text);
232 void query_set_sel (int new_sel);
234 /* Create message box but don't dismiss it yet, not background safe */
235 struct Dlg_head *create_message (int flags, const char *title,
236 const char *text, ...)
237 __attribute__ ((format (__printf__, 3, 4)));
239 /* Show message box, background safe */
240 void message (int flags, const char *title, const char *text, ...)
241 __attribute__ ((format (__printf__, 3, 4)));
244 /* Use this as header for message() - it expands to "Error" */
245 #define MSG_ERROR ((char *) -1)
247 int query_dialog (const char *header, const char *text, int flags, int count, ...);
249 /* flags for message() and query_dialog() */
250 enum {
251 D_NORMAL = 0,
252 D_ERROR = 1
253 } /* dialog options */;
255 #endif