Widget library: added new widget WHLine.
[midnight-commander.git] / src / widget.h
blob28691892f4842d64b91ca54c837e82b4078afff9
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 typedef int (*bcback) (int);
35 /* structure for label (caption) with hotkey, if original text does not contain
36 * hotkey, only start is valid and is equal to original text
37 * hotkey is defined as char*, but mc support only singlebyte hotkey
39 struct hotkey_t {
40 char *start;
41 char *hotkey;
42 char *end;
45 /* used in static definition of menu entries */
46 #define NULL_HOTKEY {NULL, NULL, NULL}
48 /* create hotkey from text */
49 struct hotkey_t parse_hotkey (const char *text);
50 /* release hotkey, free all mebers of hotkey_t */
51 void release_hotkey (const struct hotkey_t hotkey);
52 /* return width on terminal of hotkey */
53 int hotkey_width (const struct hotkey_t hotkey);
55 typedef struct WButton {
56 Widget widget;
57 int action; /* what to do when pressed */
58 int selected; /* button state */
60 #define HIDDEN_BUTTON 0
61 #define NARROW_BUTTON 1
62 #define NORMAL_BUTTON 2
63 #define DEFPUSH_BUTTON 3
64 unsigned int flags; /* button flags */
65 struct hotkey_t text; /* text of button, contain hotkey too */
66 int hotpos; /* offset hot KEY char in text */
67 bcback callback; /* Callback function */
68 } WButton;
70 typedef struct WRadio {
71 Widget widget;
72 unsigned int state; /* radio button state */
73 int pos, sel;
74 int count; /* number of members */
75 struct hotkey_t *texts; /* texts of labels */
76 } WRadio;
78 typedef struct WCheck {
79 Widget widget;
81 #define C_BOOL 0x0001
82 #define C_CHANGE 0x0002
83 unsigned int state; /* check button state */
84 struct hotkey_t text; /* text of check button */
85 } WCheck;
87 typedef struct WGauge {
88 Widget widget;
89 int shown;
90 int max;
91 int current;
92 } WGauge;
94 GList *history_get (const char *input_name);
95 void history_put (const char *input_name, GList *h);
96 /* for repositioning of history dialog we should pass widget to this
97 * function, as position of history dialog depends on widget's position */
98 char *show_hist (GList **history, Widget *widget);
100 typedef struct {
101 Widget widget;
102 int point; /* cursor position in the input line in characters */
103 int mark; /* The mark position in characters */
104 int term_first_shown; /* column of the first shown character */
105 size_t current_max_size; /* Maximum length of input line (bytes) */
106 int field_width; /* width of the editing field */
107 int color; /* color used */
108 int first; /* Is first keystroke? */
109 int disable_update; /* Do we want to skip updates? */
110 int is_password; /* Is this a password input line? */
111 char *buffer; /* pointer to editing buffer */
112 GList *history; /* The history */
113 int need_push; /* need to push the current Input on hist? */
114 char **completions; /* Possible completions array */
115 INPUT_COMPLETE_FLAGS completion_flags; /* INPUT_COMPLETE* bitwise flags(complete.h) */
116 char *history_name; /* name of history for loading and saving */
117 char charbuf[MB_LEN_MAX]; /* buffer for multibytes characters */
118 size_t charpoint; /* point to end of mulibyte sequence in charbuf */
119 } WInput;
121 /* For history load-save functions */
122 #define INPUT_LAST_TEXT ((char *) 2)
124 typedef struct {
125 Widget widget;
126 int auto_adjust_cols; /* compute widget.cols from strlen(text)? */
127 char *text;
128 int transparent; /* Paint in the default color fg/bg */
129 } WLabel;
131 typedef struct {
132 Widget widget;
133 gboolean auto_adjust_cols; /* Compute widget.cols from parent width? */
134 gboolean transparent; /* Paint in the default color fg/bg */
135 } WHLine;
137 typedef struct WLEntry {
138 char *text; /* Text to display */
139 int hotkey;
140 void *data; /* Client information */
141 } WLEntry;
143 struct WListbox;
144 typedef struct WListbox WListbox;
145 typedef int (*lcback) (WListbox *);
147 /* Callback should return one of the following values */
148 enum {
149 LISTBOX_CONT, /* continue */
150 LISTBOX_DONE /* finish dialog */
153 struct WListbox {
154 Widget widget;
155 GList *list; /* Pointer to the double linked list */
156 int pos; /* The current element displayed */
157 int top; /* The first element displayed */
158 int count; /* Number of items in the listbox */
159 gboolean allow_duplicates; /* Do we allow duplicates on the list? */
160 gboolean scrollbar; /* Draw a scrollbar? */
161 gboolean deletable; /* Can list entries be deleted? */
162 lcback cback; /* The callback function */
163 int cursor_x, cursor_y; /* Cache the values */
166 /* number of bttons in buttonbar */
167 #define BUTTONBAR_LABELS_NUM 10
169 typedef struct WButtonBar {
170 Widget widget;
171 gboolean visible; /* Is it visible? */
172 int btn_width; /* width of one button */
173 struct {
174 char *text;
175 unsigned long command;
176 Widget *receiver;
177 } labels [BUTTONBAR_LABELS_NUM];
178 } WButtonBar;
180 typedef struct WGroupbox {
181 Widget widget;
182 char *title;
183 } WGroupbox;
186 /* Default callback for widgets */
187 cb_ret_t default_proc (widget_msg_t msg, int parm);
189 /* Constructors */
190 WButton *button_new (int y, int x, int action, int flags, const char *text,
191 bcback callback);
192 WRadio *radio_new (int y, int x, int count, const char **text);
193 WCheck *check_new (int y, int x, int state, const char *text);
194 WInput *input_new (int y, int x, int color, int len, const char *text, const char *histname, INPUT_COMPLETE_FLAGS completion_flags);
195 WLabel *label_new (int y, int x, const char *text);
196 WHLine *hline_new (int y, int x, int width);
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, gboolean deletable, lcback callback);
200 WButtonBar *buttonbar_new (gboolean 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 void stuff (WInput *in, const char *text, int insert_extra_space);
210 void input_disable_update (WInput *in);
211 void input_set_prompt (WInput *in, int field_len, const char *prompt);
212 void input_enable_update (WInput *in);
213 void input_set_point (WInput *in, int pos);
214 void input_show_cursor (WInput *in);
215 void assign_text (WInput *in, const char *text);
216 cb_ret_t input_callback (Widget *, widget_msg_t msg, int parm);
218 /* Labels */
219 void label_set_text (WLabel *label, const char *text);
221 /* Gauges */
222 void gauge_set_value (WGauge *g, int max, int current);
223 void gauge_show (WGauge *g, int shown);
225 /* Buttons */
226 /* return copy of button text */
227 const char *button_get_text (const WButton *b);
228 void button_set_text (WButton *b, const char *text);
229 int button_get_len (const WButton *b);
231 /* Listbox manager */
232 WLEntry *listbox_get_data (WListbox *l, int pos);
234 /* search text int listbox entries */
235 int listbox_search_text (WListbox *l, const char *text);
236 void listbox_select_entry (WListbox *l, int dest);
237 void listbox_select_first (WListbox *l);
238 void listbox_select_last (WListbox *l);
239 void listbox_remove_current (WListbox *l);
240 void listbox_set_list (WListbox *l, GList *list);
241 void listbox_remove_list (WListbox *l);
242 void listbox_get_current (WListbox *l, char **string, void **extra);
244 typedef enum {
245 LISTBOX_APPEND_AT_END = 0, /* append at the end */
246 LISTBOX_APPEND_BEFORE, /* insert before current */
247 LISTBOX_APPEND_AFTER, /* insert after current */
248 LISTBOX_APPEND_SORTED /* insert alphabetically */
249 } listbox_append_t;
251 char *listbox_add_item (WListbox *l, listbox_append_t pos,
252 int hotkey, const char *text, void *data);
254 struct global_keymap_t;
256 WButtonBar *find_buttonbar (const Dlg_head *h);
257 void buttonbar_set_label (WButtonBar *bb, int idx, const char *text,
258 const struct global_keymap_t *keymap, const Widget *receiver);
259 #define buttonbar_clear_label(bb, idx, recv) buttonbar_set_label (bb, idx, "", NULL, recv)
260 void buttonbar_set_visible (WButtonBar *bb, gboolean visible);
261 void buttonbar_redraw (WButtonBar *bb);
263 void free_completions (WInput *in);
264 void complete (WInput *in);
266 #endif /* MC_WIDGET_H */