Merge branch '1617_history_fix'
[midnight-commander.git] / src / wtools.h
blob5d06391c2f6c359f5f3deb1b9cc14d03d93490a3
2 /** \file wtools.h
3 * \brief Header: widget based utility functions
4 */
6 #ifndef MC_WTOOLS_H
7 #define MC_WTOOLS_H
9 #include "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.checkbox.text = txt, \
90 .u.checkbox.state = st \
93 #define QUICK_BUTTON(x, xdiv, y, ydiv, txt, act, cb) \
94 { \
95 .widget_type = quick_button, \
96 .relative_x = x, \
97 .x_divisions = xdiv, \
98 .relative_y = y, \
99 .y_divisions = ydiv, \
100 .widget = NULL, \
101 .u.button.text = txt, \
102 .u.button.action = act, \
103 .u.button.callback = cb \
106 #define QUICK_INPUT(x, xdiv, y, ydiv, txt, len_, flags_, hname, res) \
108 .widget_type = quick_input, \
109 .relative_x = x, \
110 .x_divisions = xdiv, \
111 .relative_y = y, \
112 .y_divisions = ydiv, \
113 .widget = NULL, \
114 .u.input.text = txt, \
115 .u.input.len = len_, \
116 .u.input.flags = flags_, \
117 .u.input.histname = hname, \
118 .u.input.result = res \
121 #define QUICK_LABEL(x, xdiv, y, ydiv, txt) \
123 .widget_type = quick_label, \
124 .relative_x = x, \
125 .x_divisions = xdiv, \
126 .relative_y = y, \
127 .y_divisions = ydiv, \
128 .widget = NULL, \
129 .u.label.text = txt \
132 #define QUICK_RADIO(x, xdiv, y, ydiv, cnt, items_, val) \
134 .widget_type = quick_radio, \
135 .relative_x = x, \
136 .x_divisions = xdiv, \
137 .relative_y = y, \
138 .y_divisions = ydiv, \
139 .widget = NULL, \
140 .u.radio.count = cnt, \
141 .u.radio.items = items_, \
142 .u.radio.value = val, \
145 #define QUICK_END \
147 .widget_type = quick_end, \
148 .relative_x = 0, \
149 .x_divisions = 0, \
150 .relative_y = 0, \
151 .y_divisions = 0, \
152 .widget = NULL, \
153 .u.input.text = NULL, \
154 .u.input.len = 0, \
155 .u.input.flags = 0, \
156 .u.input.histname = NULL, \
157 .u.input.result = NULL \
160 typedef struct {
161 int xlen, ylen;
162 int xpos, ypos; /* if -1, then center the dialog */
163 const char *title;
164 const char *help;
165 QuickWidget *widgets;
166 gboolean i18n; /* If true, internationalization has happened */
167 } QuickDialog;
169 int quick_dialog (QuickDialog *qd);
170 int quick_dialog_skip (QuickDialog *qd, int nskip);
172 /* The input dialogs */
174 /* Pass this as def_text to request a password */
175 #define INPUT_PASSWORD ((char *) -1)
177 char *input_dialog (const char *header, const char *text,
178 const char *history_name, const char *def_text);
179 char *input_dialog_help (const char *header, const char *text, const char *help,
180 const char *history_name, const char *def_text);
181 char *input_expand_dialog (const char *header, const char *text,
182 const char *history_name, const char *def_text);
184 void query_set_sel (int new_sel);
186 /* Create message box but don't dismiss it yet, not background safe */
187 struct Dlg_head *create_message (int flags, const char *title,
188 const char *text, ...)
189 __attribute__ ((format (__printf__, 3, 4)));
191 /* Show message box, background safe */
192 void message (int flags, const char *title, const char *text, ...)
193 __attribute__ ((format (__printf__, 3, 4)));
196 /* Use this as header for message() - it expands to "Error" */
197 #define MSG_ERROR ((char *) -1)
199 int query_dialog (const char *header, const char *text, int flags, int count, ...);
201 /* flags for message() and query_dialog() */
202 enum {
203 D_NORMAL = 0,
204 D_ERROR = 1
205 } /* dialog options */;
207 #endif