Refactored IPV4/IPV6 FTP connection setup code
[midnight-commander.git] / src / widget.h
blob8403fc5617310cf6175a38bec2e1fc96c46dbc41
2 /** \file widget.h
3 * \brief Header: widgets
4 */
6 #ifndef MC_WIDGET_H
7 #define MC_WIDGET_H
9 #include "lib/global.h"
10 #include "dialog.h" /* Widget */
12 /* Completion stuff */
14 typedef enum {
15 INPUT_COMPLETE_FILENAMES = 1<<0,
16 INPUT_COMPLETE_HOSTNAMES = 1<<1,
17 INPUT_COMPLETE_COMMANDS = 1<<2,
18 INPUT_COMPLETE_VARIABLES = 1<<3,
19 INPUT_COMPLETE_USERNAMES = 1<<4,
20 INPUT_COMPLETE_CD = 1<<5,
21 INPUT_COMPLETE_SHELL_ESC = 1<<6,
23 INPUT_COMPLETE_DEFAULT = INPUT_COMPLETE_FILENAMES
24 | INPUT_COMPLETE_HOSTNAMES
25 | INPUT_COMPLETE_VARIABLES
26 | INPUT_COMPLETE_USERNAMES
27 } INPUT_COMPLETE_FLAGS;
29 /* Please note that the first element in all the widgets is a */
30 /* widget variable of type Widget. We abuse this fact everywhere */
32 /* button callback */
33 struct WButton;
34 typedef int (*bcback) (struct WButton *button, int action);
36 /* structure for label (caption) with hotkey, if original text does not contain
37 * hotkey, only start is valid and is equal to original text
38 * hotkey is defined as char*, but mc support only singlebyte hotkey
40 struct hotkey_t {
41 char *start;
42 char *hotkey;
43 char *end;
46 /* used in static definition of menu entries */
47 #define NULL_HOTKEY {NULL, NULL, NULL}
49 /* create hotkey from text */
50 struct hotkey_t parse_hotkey (const char *text);
51 /* release hotkey, free all mebers of hotkey_t */
52 void release_hotkey (const struct hotkey_t hotkey);
53 /* return width on terminal of hotkey */
54 int hotkey_width (const struct hotkey_t hotkey);
56 typedef struct WButton {
57 Widget widget;
58 int action; /* what to do when pressed */
59 int selected; /* button state */
61 #define HIDDEN_BUTTON 0
62 #define NARROW_BUTTON 1
63 #define NORMAL_BUTTON 2
64 #define DEFPUSH_BUTTON 3
65 unsigned int flags; /* button flags */
66 struct hotkey_t text; /* text of button, contain hotkey too */
67 int hotpos; /* offset hot KEY char in text */
68 bcback callback; /* Callback function */
69 } WButton;
71 typedef struct WRadio {
72 Widget widget;
73 unsigned int state; /* radio button state */
74 int pos, sel;
75 int count; /* number of members */
76 struct hotkey_t *texts; /* texts of labels */
77 } WRadio;
79 typedef struct WCheck {
80 Widget widget;
82 #define C_BOOL 0x0001
83 #define C_CHANGE 0x0002
84 unsigned int state; /* check button state */
85 struct hotkey_t text; /* text of check button */
86 } WCheck;
88 typedef struct WGauge {
89 Widget widget;
90 int shown;
91 int max;
92 int current;
93 gboolean from_left_to_right;
94 } WGauge;
96 GList *history_get (const char *input_name);
97 void history_put (const char *input_name, GList *h);
98 /* for repositioning of history dialog we should pass widget to this
99 * function, as position of history dialog depends on widget's position */
100 char *show_hist (GList **history, Widget *widget);
102 typedef struct {
103 Widget widget;
104 int point; /* cursor position in the input line in characters */
105 int mark; /* The mark position in characters */
106 gboolean highlight; /* There is a selected block */
107 int term_first_shown; /* column of the first shown character */
108 size_t current_max_size; /* Maximum length of input line (bytes) */
109 int field_width; /* width of the editing field */
110 int color; /* color used */
111 int mark_color; /* color for marked text */
112 int unchanged_color; /* color for inactive text (Is first keystroke) */
113 gboolean first; /* Is first keystroke? */
114 int disable_update; /* Do we want to skip updates? */
115 int is_password; /* Is this a password input line? */
116 char *buffer; /* pointer to editing buffer */
117 GList *history; /* The history */
118 int need_push; /* need to push the current Input on hist? */
119 char **completions; /* Possible completions array */
120 INPUT_COMPLETE_FLAGS completion_flags; /* INPUT_COMPLETE* bitwise flags(complete.h) */
121 char *history_name; /* name of history for loading and saving */
122 char charbuf[MB_LEN_MAX]; /* buffer for multibytes characters */
123 size_t charpoint; /* point to end of mulibyte sequence in charbuf */
124 } WInput;
126 /* For history load-save functions */
127 #define INPUT_LAST_TEXT ((char *) 2)
129 typedef struct {
130 Widget widget;
131 int auto_adjust_cols; /* compute widget.cols from strlen(text)? */
132 char *text;
133 int transparent; /* Paint in the default color fg/bg */
134 } WLabel;
136 typedef struct {
137 Widget widget;
138 gboolean auto_adjust_cols; /* Compute widget.cols from parent width? */
139 gboolean transparent; /* Paint in the default color fg/bg */
140 } WHLine;
142 typedef struct WLEntry {
143 char *text; /* Text to display */
144 int hotkey;
145 void *data; /* Client information */
146 } WLEntry;
148 struct WListbox;
149 typedef struct WListbox WListbox;
150 typedef int (*lcback) (WListbox *);
152 /* Callback should return one of the following values */
153 enum {
154 LISTBOX_CONT, /* continue */
155 LISTBOX_DONE /* finish dialog */
158 struct WListbox {
159 Widget widget;
160 GList *list; /* Pointer to the double linked list */
161 int pos; /* The current element displayed */
162 int top; /* The first element displayed */
163 int count; /* Number of items in the listbox */
164 gboolean allow_duplicates; /* Do we allow duplicates on the list? */
165 gboolean scrollbar; /* Draw a scrollbar? */
166 gboolean deletable; /* Can list entries be deleted? */
167 lcback cback; /* The callback function */
168 int cursor_x, cursor_y; /* Cache the values */
171 /* number of bttons in buttonbar */
172 #define BUTTONBAR_LABELS_NUM 10
174 typedef struct WButtonBar {
175 Widget widget;
176 gboolean visible; /* Is it visible? */
177 struct {
178 char *text;
179 unsigned long command;
180 Widget *receiver;
181 int end_coord; /* cumulative width of buttons so far */
182 } labels [BUTTONBAR_LABELS_NUM];
183 } WButtonBar;
185 typedef struct WGroupbox {
186 Widget widget;
187 char *title;
188 } WGroupbox;
191 /* Default callback for widgets */
192 cb_ret_t default_proc (widget_msg_t msg, int parm);
194 /* Constructors */
195 WButton *button_new (int y, int x, int action, int flags, const char *text,
196 bcback callback);
197 WRadio *radio_new (int y, int x, int count, const char **text);
198 WCheck *check_new (int y, int x, int state, const char *text);
199 WInput *input_new (int y, int x, int *input_colors,
200 int len, const char *text, const char *histname,
201 INPUT_COMPLETE_FLAGS completion_flags);
202 WLabel *label_new (int y, int x, const char *text);
203 WHLine *hline_new (int y, int x, int width);
205 WGauge *gauge_new (int y, int x, int shown, int max, int current);
206 WListbox *listbox_new (int y, int x, int height, int width, gboolean deletable, lcback callback);
207 WButtonBar *buttonbar_new (gboolean visible);
208 WGroupbox *groupbox_new (int y, int x, int height, int width, const char *title);
210 /* Input lines */
211 void winput_set_origin (WInput *i, int x, int field_width);
212 cb_ret_t handle_char (WInput *in, int c_code);
213 int is_in_input_map (WInput *in, int c_code);
214 void update_input (WInput *in, int clear_first);
215 void new_input (WInput *in);
216 void stuff (WInput *in, const char *text, int insert_extra_space);
217 void input_disable_update (WInput *in);
218 void input_set_prompt (WInput *in, int field_len, const char *prompt);
219 void input_enable_update (WInput *in);
220 void input_set_point (WInput *in, int pos);
221 void input_show_cursor (WInput *in);
222 void assign_text (WInput *in, const char *text);
223 cb_ret_t input_callback (Widget *, widget_msg_t msg, int parm);
225 /* Labels */
226 void label_set_text (WLabel *label, const char *text);
228 /* Gauges */
229 void gauge_set_value (WGauge *g, int max, int current);
230 void gauge_show (WGauge *g, int shown);
232 /* Buttons */
233 /* return copy of button text */
234 const char *button_get_text (const WButton *b);
235 void button_set_text (WButton *b, const char *text);
236 int button_get_len (const WButton *b);
238 /* Listbox manager */
239 WLEntry *listbox_get_data (WListbox *l, int pos);
241 /* search text int listbox entries */
242 int listbox_search_text (WListbox *l, const char *text);
243 void listbox_select_entry (WListbox *l, int dest);
244 void listbox_select_first (WListbox *l);
245 void listbox_select_last (WListbox *l);
246 void listbox_remove_current (WListbox *l);
247 void listbox_set_list (WListbox *l, GList *list);
248 void listbox_remove_list (WListbox *l);
249 void listbox_get_current (WListbox *l, char **string, void **extra);
251 typedef enum {
252 LISTBOX_APPEND_AT_END = 0, /* append at the end */
253 LISTBOX_APPEND_BEFORE, /* insert before current */
254 LISTBOX_APPEND_AFTER, /* insert after current */
255 LISTBOX_APPEND_SORTED /* insert alphabetically */
256 } listbox_append_t;
258 char *listbox_add_item (WListbox *l, listbox_append_t pos,
259 int hotkey, const char *text, void *data);
261 struct global_keymap_t;
263 WButtonBar *find_buttonbar (const Dlg_head *h);
264 void buttonbar_set_label (WButtonBar *bb, int idx, const char *text,
265 const struct global_keymap_t *keymap, const Widget *receiver);
266 #define buttonbar_clear_label(bb, idx, recv) buttonbar_set_label (bb, idx, "", NULL, recv)
267 void buttonbar_set_visible (WButtonBar *bb, gboolean visible);
268 void buttonbar_redraw (WButtonBar *bb);
270 void free_completions (WInput *in);
271 void complete (WInput *in);
273 #endif /* MC_WIDGET_H */