Rework strutils for usage GString instread of self-made buffers.
[midnight-commander.git] / src / widget.h
blob5252d0b323547baf2fd0433bcecd677ff1a7db2b
1 #ifndef MC_WIDGET_H
2 #define MC_WIDGET_H
4 #include "dialog.h" /* Widget */
6 /* Completion stuff */
8 typedef enum {
9 INPUT_COMPLETE_FILENAMES = 1<<0,
10 INPUT_COMPLETE_HOSTNAMES = 1<<1,
11 INPUT_COMPLETE_COMMANDS = 1<<2,
12 INPUT_COMPLETE_VARIABLES = 1<<3,
13 INPUT_COMPLETE_USERNAMES = 1<<4,
14 INPUT_COMPLETE_CD = 1<<5,
15 INPUT_COMPLETE_SHELL_ESC = 1<<6,
17 INPUT_COMPLETE_DEFAULT = INPUT_COMPLETE_FILENAMES
18 | INPUT_COMPLETE_HOSTNAMES
19 | INPUT_COMPLETE_VARIABLES
20 | INPUT_COMPLETE_USERNAMES
21 } INPUT_COMPLETE_FLAGS;
23 /* Please note that the first element in all the widgets is a */
24 /* widget variable of type Widget. We abuse this fact everywhere */
26 /* button callback */
27 typedef int (*bcback) (int);
29 /* structure for label (caption) with hotkey, if original text does not contain
30 * hotkey, only start is valid and is equal to original text
31 * hotkey is defined as char*, but mc support only singlebyte hotkey
33 struct hotkey_t {
34 char *start;
35 char *hotkey;
36 char *end;
39 /* used in static definition of menu entries */
40 #define NULL_HOTKEY {NULL, NULL, NULL}
42 /* create hotkey from text */
43 struct hotkey_t parse_hotkey (const char *text);
44 /* release hotkey, free all mebers of hotkey_t */
45 void release_hotkey (const struct hotkey_t hotkey);
46 /* return width on terminal of hotkey */
47 int hotkey_width (const struct hotkey_t hotkey);
49 typedef struct WButton {
50 Widget widget;
51 int action; /* what to do when pressed */
52 int selected; /* button state */
54 #define HIDDEN_BUTTON 0
55 #define NARROW_BUTTON 1
56 #define NORMAL_BUTTON 2
57 #define DEFPUSH_BUTTON 3
58 unsigned int flags; /* button flags */
59 struct hotkey_t text; /* text of button, contain hotkey too */
60 int hotpos; /* offset hot KEY char in text */
61 bcback callback; /* Callback function */
62 } WButton;
64 typedef struct WRadio {
65 Widget widget;
66 unsigned int state; /* radio button state */
67 int pos, sel;
68 int count; /* number of members */
69 struct hotkey_t *texts; /* texts of labels */
70 } WRadio;
72 typedef struct WCheck {
73 Widget widget;
75 #define C_BOOL 0x0001
76 #define C_CHANGE 0x0002
77 unsigned int state; /* check button state */
78 struct hotkey_t text; /* text of check button */
79 } WCheck;
81 typedef struct WGauge {
82 Widget widget;
83 int shown;
84 int max;
85 int current;
86 } WGauge;
88 GList *history_get (const char *input_name);
89 void history_put (const char *input_name, GList *h);
90 char *show_hist (GList *history, int widget_y, int widget_x);
92 typedef struct {
93 Widget widget;
94 int point; /* cursor position in the input line in characters */
95 int mark; /* The mark position in characters */
96 int term_first_shown; /* column of the first shown character */
97 size_t current_max_size; /* Maximum length of input line (bytes) */
98 int field_width; /* width of the editing field */
99 int color; /* color used */
100 int first; /* Is first keystroke? */
101 int disable_update; /* Do we want to skip updates? */
102 int is_password; /* Is this a password input line? */
103 char *buffer; /* pointer to editing buffer */
104 GList *history; /* The history */
105 int need_push; /* need to push the current Input on hist? */
106 char **completions; /* Possible completions array */
107 INPUT_COMPLETE_FLAGS completion_flags; /* INPUT_COMPLETE* bitwise flags(complete.h) */
108 char *history_name; /* name of history for loading and saving */
109 char charbuf[MB_LEN_MAX]; /* buffer for multibytes characters */
110 size_t charpoint; /* point to end of mulibyte sequence in charbuf */
111 } WInput;
113 /* For history load-save functions */
114 #define INPUT_LAST_TEXT ((char *) 2)
116 typedef struct {
117 Widget widget;
118 int auto_adjust_cols; /* compute widget.cols from strlen(text)? */
119 char *text;
120 int transparent; /* Paint in the default color fg/bg */
121 } WLabel;
123 typedef struct WLEntry {
124 char *text; /* Text to display */
125 int hotkey;
126 void *data; /* Client information */
127 struct WLEntry *next;
128 struct WLEntry *prev;
129 } WLEntry;
131 struct WListbox;
132 typedef struct WListbox WListbox;
133 typedef int (*lcback) (WListbox *);
135 /* Callback should return one of the following values */
136 enum {
137 LISTBOX_CONT, /* continue */
138 LISTBOX_DONE /* finish dialog */
141 struct WListbox {
142 Widget widget;
143 WLEntry *list; /* Pointer to the circular double linked list. */
144 WLEntry *top; /* The first element displayed */
145 WLEntry *current; /* The current element displayed */
146 int pos; /* Cur. pos, must be kept in sync with current */
147 int count; /* Number of items in the listbox */
148 int width;
149 int height; /* Size of the widget */
150 int allow_duplicates; /* Do we allow duplicates on the list? */
151 int scrollbar; /* Draw a scrollbar? */
152 lcback cback; /* The callback function */
153 int cursor_x, cursor_y; /* Cache the values */
156 typedef struct WGroupbox {
157 Widget widget;
158 char *title;
159 } WGroupbox;
162 /* Constructors */
163 WButton *button_new (int y, int x, int action, int flags, const char *text,
164 bcback callback);
165 WRadio *radio_new (int y, int x, int count, const char **text);
166 WCheck *check_new (int y, int x, int state, const char *text);
167 WInput *input_new (int y, int x, int color, int len, const char *text, const char *histname, INPUT_COMPLETE_FLAGS completion_flags);
168 WLabel *label_new (int y, int x, const char *text);
169 WGauge *gauge_new (int y, int x, int shown, int max, int current);
170 WListbox *listbox_new (int x, int y, int width, int height, lcback callback);
171 WGroupbox *groupbox_new (int x, int y, int width, int height, const char *title);
173 /* Input lines */
174 void winput_set_origin (WInput *i, int x, int field_width);
175 cb_ret_t handle_char (WInput *in, int c_code);
176 int is_in_input_map (WInput *in, int c_code);
177 void update_input (WInput *in, int clear_first);
178 void new_input (WInput *in);
179 int push_history (WInput *in, const char *text);
180 void stuff (WInput *in, const char *text, int insert_extra_space);
181 void input_disable_update (WInput *in);
182 void input_set_prompt (WInput *in, int field_len, const char *prompt);
183 void input_enable_update (WInput *in);
184 void input_set_point (WInput *in, int pos);
185 void input_show_cursor (WInput *in);
186 void assign_text (WInput *in, const char *text);
187 cb_ret_t input_callback (Widget *, widget_msg_t msg, int parm);
189 /* Labels */
190 void label_set_text (WLabel *label, const char *text);
192 /* Gauges */
193 void gauge_set_value (WGauge *g, int max, int current);
194 void gauge_show (WGauge *g, int shown);
196 /* Buttons */
197 /* return copy of button text */
198 const char *button_get_text (WButton *b);
199 void button_set_text (WButton *b, const char *text);
201 /* Listbox manager */
202 WLEntry *listbox_get_data (WListbox *l, int pos);
204 /* search text int listbox entries */
205 WLEntry *listbox_search_text (WListbox *l, const char *text);
206 void listbox_select_entry (WListbox *l, WLEntry *dest);
207 void listbox_select_by_number (WListbox *l, int n);
208 void listbox_select_last (WListbox *l, int set_top);
209 void listbox_remove_current (WListbox *l, int force);
210 void listbox_remove_list (WListbox *l);
211 void listbox_get_current (WListbox *l, char **string, char **extra);
213 enum append_pos {
214 LISTBOX_APPEND_AT_END, /* append at the end */
215 LISTBOX_APPEND_BEFORE, /* insert before current */
216 LISTBOX_APPEND_AFTER, /* insert after current */
217 LISTBOX_APPEND_SORTED /* insert alphabetically */
220 char *listbox_add_item (WListbox *l, enum append_pos pos, int
221 hotkey, const char *text, void *data);
223 /* Hintbar routines */
225 /* Buttonbar */
227 typedef void (*voidfn)(void);
228 typedef void (*buttonbarfn)(void *);
230 typedef struct WButtonBar WButtonBar;
232 WButtonBar *buttonbar_new (int visible);
233 WButtonBar *find_buttonbar (Dlg_head *h);
234 void buttonbar_clear_label (Dlg_head *, int idx);
235 void buttonbar_set_label (Dlg_head *, int index, const char *text, voidfn);
236 void buttonbar_set_label_data (Dlg_head *h, int idx, const char *text,
237 buttonbarfn cback, void *data);
238 void buttonbar_set_visible (WButtonBar *, gboolean);
239 void buttonbar_redraw (Dlg_head *h);
241 void free_completions (WInput *);
242 void complete (WInput *);
244 #endif