Ticket #2097: ChangeLog in its current form does not strictly make any sense
[midnight-commander.git] / src / wtools.h
blobba6b4c06e98bffcc9364a30b5c9fb21de4540a84
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_t;
37 /* The widget is placed on relative_?/divisions_? of the parent widget */
38 typedef struct {
39 quick_t widget_type;
41 int relative_x;
42 int x_divisions;
43 int relative_y;
44 int y_divisions;
46 Widget *widget;
48 /* widget parameters */
49 union {
50 struct {
51 const char *text;
52 int *state; /* in/out */
53 } checkbox;
55 struct {
56 const char *text;
57 int action;
58 bcback callback;
59 } button;
61 struct {
62 const char *text;
63 int len;
64 int flags; /* 1 -- is_password, 2 -- INPUT_COMPLETE_CD */
65 const char *histname;
66 char **result;
67 } input;
69 struct {
70 const char *text;
71 } label;
73 struct {
74 int count;
75 const char **items;
76 int *value; /* in/out */
77 } radio;
78 } u;
79 } QuickWidget;
81 #define QUICK_CHECKBOX(x, xdiv, y, ydiv, txt, st) \
82 { \
83 .widget_type = quick_checkbox, \
84 .relative_x = x, \
85 .x_divisions = xdiv, \
86 .relative_y = y, \
87 .y_divisions = ydiv, \
88 .widget = NULL, \
89 .u = { \
90 .checkbox = { \
91 .text = txt, \
92 .state = st \
93 } \
94 } \
97 #define QUICK_BUTTON(x, xdiv, y, ydiv, txt, act, cb) \
98 { \
99 .widget_type = quick_button, \
100 .relative_x = x, \
101 .x_divisions = xdiv, \
102 .relative_y = y, \
103 .y_divisions = ydiv, \
104 .widget = NULL, \
105 .u = { \
106 .button = { \
107 .text = txt, \
108 .action = act, \
109 .callback = cb \
114 #define QUICK_INPUT(x, xdiv, y, ydiv, txt, len_, flags_, hname, res) \
116 .widget_type = quick_input, \
117 .relative_x = x, \
118 .x_divisions = xdiv, \
119 .relative_y = y, \
120 .y_divisions = ydiv, \
121 .widget = NULL, \
122 .u = { \
123 .input = { \
124 .text = txt, \
125 .len = len_, \
126 .flags = flags_, \
127 .histname = hname, \
128 .result = res \
133 #define QUICK_LABEL(x, xdiv, y, ydiv, txt) \
135 .widget_type = quick_label, \
136 .relative_x = x, \
137 .x_divisions = xdiv, \
138 .relative_y = y, \
139 .y_divisions = ydiv, \
140 .widget = NULL, \
141 .u = { \
142 .label = { \
143 .text = txt \
148 #define QUICK_RADIO(x, xdiv, y, ydiv, cnt, items_, val) \
150 .widget_type = quick_radio, \
151 .relative_x = x, \
152 .x_divisions = xdiv, \
153 .relative_y = y, \
154 .y_divisions = ydiv, \
155 .widget = NULL, \
156 .u = { \
157 .radio = { \
158 .count = cnt, \
159 .items = items_, \
160 .value = val \
165 #define QUICK_END \
167 .widget_type = quick_end, \
168 .relative_x = 0, \
169 .x_divisions = 0, \
170 .relative_y = 0, \
171 .y_divisions = 0, \
172 .widget = NULL, \
173 .u = { \
174 .input = { \
175 .text = NULL, \
176 .len = 0, \
177 .flags = 0, \
178 .histname = NULL, \
179 .result = NULL \
184 typedef struct {
185 int xlen, ylen;
186 int xpos, ypos; /* if -1, then center the dialog */
187 const char *title;
188 const char *help;
189 QuickWidget *widgets;
190 gboolean i18n; /* If true, internationalization has happened */
191 } QuickDialog;
193 int quick_dialog (QuickDialog *qd);
194 int quick_dialog_skip (QuickDialog *qd, int nskip);
196 /* The input dialogs */
198 /* Pass this as def_text to request a password */
199 #define INPUT_PASSWORD ((char *) -1)
201 char *input_dialog (const char *header, const char *text,
202 const char *history_name, const char *def_text);
203 char *input_dialog_help (const char *header, const char *text, const char *help,
204 const char *history_name, const char *def_text);
205 char *input_expand_dialog (const char *header, const char *text,
206 const char *history_name, const char *def_text);
208 void query_set_sel (int new_sel);
210 /* Create message box but don't dismiss it yet, not background safe */
211 struct Dlg_head *create_message (int flags, const char *title,
212 const char *text, ...)
213 __attribute__ ((format (__printf__, 3, 4)));
215 /* Show message box, background safe */
216 void message (int flags, const char *title, const char *text, ...)
217 __attribute__ ((format (__printf__, 3, 4)));
220 /* Use this as header for message() - it expands to "Error" */
221 #define MSG_ERROR ((char *) -1)
223 int query_dialog (const char *header, const char *text, int flags, int count, ...);
225 /* flags for message() and query_dialog() */
226 enum {
227 D_NORMAL = 0,
228 D_ERROR = 1
229 } /* dialog options */;
231 #endif