Ticket #1790: mc crashes on start
[midnight-commander.git] / src / widget.h
blob99a72b66fc5b969c106a8706ddc943caa2fe872d
2 /** \file widget.h
3 * \brief Header: widgets
4 */
6 #ifndef MC_WIDGET_H
7 #define MC_WIDGET_H
9 #include "dialog.h" /* Widget */
11 /* Completion stuff */
13 typedef enum {
14 INPUT_COMPLETE_FILENAMES = 1<<0,
15 INPUT_COMPLETE_HOSTNAMES = 1<<1,
16 INPUT_COMPLETE_COMMANDS = 1<<2,
17 INPUT_COMPLETE_VARIABLES = 1<<3,
18 INPUT_COMPLETE_USERNAMES = 1<<4,
19 INPUT_COMPLETE_CD = 1<<5,
20 INPUT_COMPLETE_SHELL_ESC = 1<<6,
22 INPUT_COMPLETE_DEFAULT = INPUT_COMPLETE_FILENAMES
23 | INPUT_COMPLETE_HOSTNAMES
24 | INPUT_COMPLETE_VARIABLES
25 | INPUT_COMPLETE_USERNAMES
26 } INPUT_COMPLETE_FLAGS;
28 /* Please note that the first element in all the widgets is a */
29 /* widget variable of type Widget. We abuse this fact everywhere */
31 /* button callback */
32 typedef int (*bcback) (int);
34 /* structure for label (caption) with hotkey, if original text does not contain
35 * hotkey, only start is valid and is equal to original text
36 * hotkey is defined as char*, but mc support only singlebyte hotkey
38 struct hotkey_t {
39 char *start;
40 char *hotkey;
41 char *end;
44 /* used in static definition of menu entries */
45 #define NULL_HOTKEY {NULL, NULL, NULL}
47 /* create hotkey from text */
48 struct hotkey_t parse_hotkey (const char *text);
49 /* release hotkey, free all mebers of hotkey_t */
50 void release_hotkey (const struct hotkey_t hotkey);
51 /* return width on terminal of hotkey */
52 int hotkey_width (const struct hotkey_t hotkey);
54 typedef struct WButton {
55 Widget widget;
56 int action; /* what to do when pressed */
57 int selected; /* button state */
59 #define HIDDEN_BUTTON 0
60 #define NARROW_BUTTON 1
61 #define NORMAL_BUTTON 2
62 #define DEFPUSH_BUTTON 3
63 unsigned int flags; /* button flags */
64 struct hotkey_t text; /* text of button, contain hotkey too */
65 int hotpos; /* offset hot KEY char in text */
66 bcback callback; /* Callback function */
67 } WButton;
69 typedef struct WRadio {
70 Widget widget;
71 unsigned int state; /* radio button state */
72 int pos, sel;
73 int count; /* number of members */
74 struct hotkey_t *texts; /* texts of labels */
75 } WRadio;
77 typedef struct WCheck {
78 Widget widget;
80 #define C_BOOL 0x0001
81 #define C_CHANGE 0x0002
82 unsigned int state; /* check button state */
83 struct hotkey_t text; /* text of check button */
84 } WCheck;
86 typedef struct WGauge {
87 Widget widget;
88 int shown;
89 int max;
90 int current;
91 } WGauge;
93 GList *history_get (const char *input_name);
94 void history_put (const char *input_name, GList *h);
95 /* for repositioning of history dialog we should pass widget to this
96 * function, as position of history dialog depends on widget's position */
97 char *show_hist (GList *history, Widget *widget);
99 typedef struct {
100 Widget widget;
101 int point; /* cursor position in the input line in characters */
102 int mark; /* The mark position in characters */
103 int term_first_shown; /* column of the first shown character */
104 size_t current_max_size; /* Maximum length of input line (bytes) */
105 int field_width; /* width of the editing field */
106 int color; /* color used */
107 int first; /* Is first keystroke? */
108 int disable_update; /* Do we want to skip updates? */
109 int is_password; /* Is this a password input line? */
110 char *buffer; /* pointer to editing buffer */
111 GList *history; /* The history */
112 int need_push; /* need to push the current Input on hist? */
113 char **completions; /* Possible completions array */
114 INPUT_COMPLETE_FLAGS completion_flags; /* INPUT_COMPLETE* bitwise flags(complete.h) */
115 char *history_name; /* name of history for loading and saving */
116 char charbuf[MB_LEN_MAX]; /* buffer for multibytes characters */
117 size_t charpoint; /* point to end of mulibyte sequence in charbuf */
118 } WInput;
120 /* For history load-save functions */
121 #define INPUT_LAST_TEXT ((char *) 2)
123 typedef struct {
124 Widget widget;
125 int auto_adjust_cols; /* compute widget.cols from strlen(text)? */
126 char *text;
127 int transparent; /* Paint in the default color fg/bg */
128 } WLabel;
130 typedef struct WLEntry {
131 char *text; /* Text to display */
132 int hotkey;
133 void *data; /* Client information */
134 struct WLEntry *next;
135 struct WLEntry *prev;
136 } WLEntry;
138 struct WListbox;
139 typedef struct WListbox WListbox;
140 typedef int (*lcback) (WListbox *);
142 /* Callback should return one of the following values */
143 enum {
144 LISTBOX_CONT, /* continue */
145 LISTBOX_DONE /* finish dialog */
148 struct WListbox {
149 Widget widget;
150 WLEntry *list; /* Pointer to the circular double linked list. */
151 WLEntry *top; /* The first element displayed */
152 WLEntry *current; /* The current element displayed */
153 int pos; /* Cur. pos, must be kept in sync with current */
154 int count; /* Number of items in the listbox */
155 int allow_duplicates; /* Do we allow duplicates on the list? */
156 int scrollbar; /* Draw a scrollbar? */
157 lcback cback; /* The callback function */
158 int cursor_x, cursor_y; /* Cache the values */
161 /* number of bttons in buttonbar */
162 #define BUTTONBAR_LABELS_NUM 10
164 typedef void (*voidfn)(void);
165 typedef void (*buttonbarfn)(void *);
167 typedef struct WButtonBar {
168 Widget widget;
169 int visible; /* Is it visible? */
170 int btn_width; /* width of one button */
171 struct {
172 char *text;
173 enum { BBFUNC_NONE, BBFUNC_VOID, BBFUNC_PTR } tag;
174 union {
175 voidfn fn_void;
176 buttonbarfn fn_ptr;
177 } u;
178 void *data;
179 } labels [BUTTONBAR_LABELS_NUM];
180 } WButtonBar;
182 typedef struct WGroupbox {
183 Widget widget;
184 char *title;
185 } WGroupbox;
188 /* Default callback for widgets */
189 cb_ret_t default_proc (widget_msg_t msg, int parm);
191 /* Constructors */
192 WButton *button_new (int y, int x, int action, int flags, const char *text,
193 bcback callback);
194 WRadio *radio_new (int y, int x, int count, const char **text);
195 WCheck *check_new (int y, int x, int state, const char *text);
196 WInput *input_new (int y, int x, int color, int len, const char *text, const char *histname, INPUT_COMPLETE_FLAGS completion_flags);
197 WLabel *label_new (int y, int x, const char *text);
198 WGauge *gauge_new (int y, int x, int shown, int max, int current);
199 WListbox *listbox_new (int y, int x, int height, int width, lcback callback);
200 WButtonBar *buttonbar_new (int visible);
201 WGroupbox *groupbox_new (int y, int x, int height, int width, const char *title);
203 /* Input lines */
204 void winput_set_origin (WInput *i, int x, int field_width);
205 cb_ret_t handle_char (WInput *in, int c_code);
206 int is_in_input_map (WInput *in, int c_code);
207 void update_input (WInput *in, int clear_first);
208 void new_input (WInput *in);
209 int push_history (WInput *in, const char *text);
210 void stuff (WInput *in, const char *text, int insert_extra_space);
211 void input_disable_update (WInput *in);
212 void input_set_prompt (WInput *in, int field_len, const char *prompt);
213 void input_enable_update (WInput *in);
214 void input_set_point (WInput *in, int pos);
215 void input_show_cursor (WInput *in);
216 void assign_text (WInput *in, const char *text);
217 cb_ret_t input_callback (Widget *, widget_msg_t msg, int parm);
219 /* Labels */
220 void label_set_text (WLabel *label, const char *text);
222 /* Gauges */
223 void gauge_set_value (WGauge *g, int max, int current);
224 void gauge_show (WGauge *g, int shown);
226 /* Buttons */
227 /* return copy of button text */
228 const char *button_get_text (const WButton *b);
229 void button_set_text (WButton *b, const char *text);
230 int button_get_len (const WButton *b);
232 /* Listbox manager */
233 WLEntry *listbox_get_data (WListbox *l, int pos);
235 /* search text int listbox entries */
236 WLEntry *listbox_search_text (WListbox *l, const char *text);
237 void listbox_select_entry (WListbox *l, WLEntry *dest);
238 void listbox_select_by_number (WListbox *l, int n);
239 void listbox_select_last (WListbox *l);
240 void listbox_select_first (WListbox *l);
241 void listbox_remove_current (WListbox *l, int force);
242 void listbox_remove_list (WListbox *l);
243 void listbox_get_current (WListbox *l, char **string, char **extra);
245 enum append_pos {
246 LISTBOX_APPEND_AT_END = 0, /* append at the end */
247 LISTBOX_APPEND_BEFORE, /* insert before current */
248 LISTBOX_APPEND_AFTER, /* insert after current */
249 LISTBOX_APPEND_SORTED /* insert alphabetically */
252 char *listbox_add_item (WListbox *l, enum append_pos pos, int
253 hotkey, const char *text, void *data);
256 WButtonBar *find_buttonbar (Dlg_head *h);
257 void buttonbar_clear_label (Dlg_head *, int idx);
258 void buttonbar_set_label (Dlg_head *, int index, const char *text, voidfn);
259 void buttonbar_set_label_data (Dlg_head *h, int idx, const char *text,
260 buttonbarfn cback, void *data);
261 void buttonbar_set_visible (WButtonBar *, gboolean);
262 void buttonbar_redraw (Dlg_head *h);
264 void free_completions (WInput *);
265 void complete (WInput *);
267 #endif