Ticket 419: (search broken in editor/viewer on glib <2.14)
[midnight-commander.git] / src / widget.h
blobd986f9fed999cad39354186ec5b20c70a48e03e8
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 char *show_hist (GList *history, int widget_y, int widget_x);
97 typedef struct {
98 Widget widget;
99 int point; /* cursor position in the input line in characters */
100 int mark; /* The mark position in characters */
101 int term_first_shown; /* column of the first shown character */
102 size_t current_max_size; /* Maximum length of input line (bytes) */
103 int field_width; /* width of the editing field */
104 int color; /* color used */
105 int first; /* Is first keystroke? */
106 int disable_update; /* Do we want to skip updates? */
107 int is_password; /* Is this a password input line? */
108 char *buffer; /* pointer to editing buffer */
109 GList *history; /* The history */
110 int need_push; /* need to push the current Input on hist? */
111 char **completions; /* Possible completions array */
112 INPUT_COMPLETE_FLAGS completion_flags; /* INPUT_COMPLETE* bitwise flags(complete.h) */
113 char *history_name; /* name of history for loading and saving */
114 char charbuf[MB_LEN_MAX]; /* buffer for multibytes characters */
115 size_t charpoint; /* point to end of mulibyte sequence in charbuf */
116 } WInput;
118 /* For history load-save functions */
119 #define INPUT_LAST_TEXT ((char *) 2)
121 typedef struct {
122 Widget widget;
123 int auto_adjust_cols; /* compute widget.cols from strlen(text)? */
124 char *text;
125 int transparent; /* Paint in the default color fg/bg */
126 } WLabel;
128 typedef struct WLEntry {
129 char *text; /* Text to display */
130 int hotkey;
131 void *data; /* Client information */
132 struct WLEntry *next;
133 struct WLEntry *prev;
134 } WLEntry;
136 struct WListbox;
137 typedef struct WListbox WListbox;
138 typedef int (*lcback) (WListbox *);
140 /* Callback should return one of the following values */
141 enum {
142 LISTBOX_CONT, /* continue */
143 LISTBOX_DONE /* finish dialog */
146 struct WListbox {
147 Widget widget;
148 WLEntry *list; /* Pointer to the circular double linked list. */
149 WLEntry *top; /* The first element displayed */
150 WLEntry *current; /* The current element displayed */
151 int pos; /* Cur. pos, must be kept in sync with current */
152 int count; /* Number of items in the listbox */
153 int width;
154 int height; /* Size of the widget */
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 typedef struct WGroupbox {
162 Widget widget;
163 char *title;
164 } WGroupbox;
167 /* Constructors */
168 WButton *button_new (int y, int x, int action, int flags, const char *text,
169 bcback callback);
170 WRadio *radio_new (int y, int x, int count, const char **text);
171 WCheck *check_new (int y, int x, int state, const char *text);
172 WInput *input_new (int y, int x, int color, int len, const char *text, const char *histname, INPUT_COMPLETE_FLAGS completion_flags);
173 WLabel *label_new (int y, int x, const char *text);
174 WGauge *gauge_new (int y, int x, int shown, int max, int current);
175 WListbox *listbox_new (int y, int x, int height, int width, lcback callback);
176 WGroupbox *groupbox_new (int y, int x, int height, int width, const char *title);
178 /* Input lines */
179 void winput_set_origin (WInput *i, int x, int field_width);
180 cb_ret_t handle_char (WInput *in, int c_code);
181 int is_in_input_map (WInput *in, int c_code);
182 void update_input (WInput *in, int clear_first);
183 void new_input (WInput *in);
184 int push_history (WInput *in, const char *text);
185 void stuff (WInput *in, const char *text, int insert_extra_space);
186 void input_disable_update (WInput *in);
187 void input_set_prompt (WInput *in, int field_len, const char *prompt);
188 void input_enable_update (WInput *in);
189 void input_set_point (WInput *in, int pos);
190 void input_show_cursor (WInput *in);
191 void assign_text (WInput *in, const char *text);
192 cb_ret_t input_callback (Widget *, widget_msg_t msg, int parm);
194 /* Labels */
195 void label_set_text (WLabel *label, const char *text);
197 /* Gauges */
198 void gauge_set_value (WGauge *g, int max, int current);
199 void gauge_show (WGauge *g, int shown);
201 /* Buttons */
202 /* return copy of button text */
203 const char *button_get_text (WButton *b);
204 void button_set_text (WButton *b, const char *text);
206 /* Listbox manager */
207 WLEntry *listbox_get_data (WListbox *l, int pos);
209 /* search text int listbox entries */
210 WLEntry *listbox_search_text (WListbox *l, const char *text);
211 void listbox_select_entry (WListbox *l, WLEntry *dest);
212 void listbox_select_by_number (WListbox *l, int n);
213 void listbox_select_last (WListbox *l, int set_top);
214 void listbox_remove_current (WListbox *l, int force);
215 void listbox_remove_list (WListbox *l);
216 void listbox_get_current (WListbox *l, char **string, char **extra);
218 enum append_pos {
219 LISTBOX_APPEND_AT_END, /* append at the end */
220 LISTBOX_APPEND_BEFORE, /* insert before current */
221 LISTBOX_APPEND_AFTER, /* insert after current */
222 LISTBOX_APPEND_SORTED /* insert alphabetically */
225 char *listbox_add_item (WListbox *l, enum append_pos pos, int
226 hotkey, const char *text, void *data);
228 /* Hintbar routines */
230 /* Buttonbar */
232 typedef void (*voidfn)(void);
233 typedef void (*buttonbarfn)(void *);
235 typedef struct WButtonBar WButtonBar;
237 WButtonBar *buttonbar_new (int visible);
238 WButtonBar *find_buttonbar (Dlg_head *h);
239 void buttonbar_clear_label (Dlg_head *, int idx);
240 void buttonbar_set_label (Dlg_head *, int index, const char *text, voidfn);
241 void buttonbar_set_label_data (Dlg_head *h, int idx, const char *text,
242 buttonbarfn cback, void *data);
243 void buttonbar_set_visible (WButtonBar *, gboolean);
244 void buttonbar_redraw (Dlg_head *h);
246 void free_completions (WInput *);
247 void complete (WInput *);
249 #endif