Last fuzzy updated...
[midnight-commander.git] / src / widget.h
blobcc94ab6e7919a1eb8c51c87026046a899c291271
1 #ifndef __WIDGET_H
2 #define __WIDGET_H
4 #include "dlg.h" /* Widget */
6 #define C_BOOL 1
7 #define C_CHANGE 2
9 /* Please note that the first element in all the widgets is a */
10 /* widget variable of type Widget. We abuse this fact everywhere */
12 #define HIDDEN_BUTTON 0
13 #define NARROW_BUTTON 1
14 #define NORMAL_BUTTON 2
15 #define DEFPUSH_BUTTON 3
17 typedef struct WButton {
18 Widget widget;
19 int action; /* what to do when pressed */
20 int selected; /* button state */
21 unsigned int flags; /* button flags */
22 char *text; /* text of button */
23 int hotkey; /* hot KEY */
24 int hotpos; /* offset hot KEY char in text */
25 int (*callback)(int, void*); /* Callback function */
26 void *callback_data;
27 } WButton;
29 typedef struct WRadio {
30 Widget widget;
31 unsigned int state; /* radio button state */
32 int pos, sel;
33 int count; /* number of members */
34 char **texts; /* texts of labels */
35 int upper_letter_is_hotkey; /* If true, then the capital letter is a hk */
36 } WRadio;
38 typedef struct WCheck {
39 Widget widget;
40 unsigned int state; /* check button state */
41 char *text; /* text of check button */
42 int hotkey; /* hot KEY */
43 int hotpos; /* offset hot KEY char in text */
44 } WCheck;
46 typedef struct WGauge {
47 Widget widget;
48 int shown;
49 int max;
50 int current;
51 } WGauge;
53 typedef struct hist_entry {
54 struct hist_entry *prev;
55 struct hist_entry *next;
56 char *text;
57 } Hist;
59 Hist *history_get (char *input_name);
60 void history_put (char *input_name, Hist *h);
61 char *show_hist (Hist *history, int widget_y, int widget_x);
63 typedef struct {
64 Widget widget;
65 int point; /* cursor position in the input line */
66 int mark; /* The mark position */
67 int first_shown; /* Index of the first shown character */
68 int current_max_len; /* Maximum length of input line */
69 int field_len; /* Length of the editing field */
70 int color; /* color used */
71 int first; /* Is first keystroke? */
72 int disable_update; /* Do we want to skip updates? */
73 int is_password; /* Is this a password input line? */
74 unsigned char *buffer; /* pointer to editing buffer */
75 Hist *history; /* The history */
76 int need_push; /* need to push the current Input on hist? */
77 char **completions; /* Possible completions array */
78 int completion_flags; /* INPUT_COMPLETE* bitwise flags(complete.h) */
79 char *history_name; /* name of history for loading and saving */
80 } WInput;
82 /* For history load-save functions */
83 #define INPUT_LAST_TEXT ((char *) 2)
84 #define HISTORY_FILE_NAME ".mc/history"
86 typedef struct {
87 Widget widget;
88 int auto_adjust_cols; /* compute widget.cols from strlen(text)? */
89 char *text;
90 int transparent; /* Paint in the default color fg/bg */
91 } WLabel;
93 typedef struct WLEntry {
94 char *text; /* Text to display */
95 int hotkey;
96 void *data; /* Client information */
97 struct WLEntry *next;
98 struct WLEntry *prev;
99 } WLEntry;
101 enum {
102 listbox_begin, listbox_end
103 } /* listbox_insert */;
105 /* Listbox actions when selecting an option: */
106 enum {
107 listbox_nothing,
108 listbox_finish, /* finish dialog */
109 listbox_cback /* call the callback routine */
110 } /* listbox_action */;
112 typedef int (*lcback) (void *);
114 typedef struct WListbox {
115 Widget widget;
116 WLEntry *list; /* Pointer to the circular double linked list. */
117 WLEntry *top; /* The first element displayed */
118 WLEntry *current; /* The current element displayed */
119 int pos; /* Cur. pos, must be kept in sync with current */
120 int count; /* Number of items in the listbox */
121 int width;
122 int height; /* Size of the widget */
123 int action; /* Action type */
124 int allow_duplicates; /* Do we allow duplicates on the list? */
125 int scrollbar; /* Draw a scrollbar? */
126 lcback cback; /* The callback function */
127 int cursor_x, cursor_y; /* Cache the values */
128 } WListbox;
130 typedef void (*buttonbarfn)(void *);
132 typedef struct {
133 Widget widget;
134 int visible; /* Is it visible? */
135 struct {
136 char *text;
137 buttonbarfn function;
138 void *data;
139 } labels [10];
140 } WButtonBar;
142 /* Constructors */
143 WButton *button_new (int y, int x, int action, int flags, char *text,
144 int (*callback)(int, void *), void *extra, char *tkname);
145 WRadio *radio_new (int y, int x, int count, char **text, int use_hotkey, char *tkname);
146 WCheck *check_new (int y, int x, int state, char *text, char *tkname);
147 WInput *input_new (int y, int x, int color, int len, const char *text, char *tkname);
148 WLabel *label_new (int y, int x, const char *text, char *tkname);
149 WGauge *gauge_new (int y, int x, int shown, int max, int current, char *tkname);
150 WListbox *listbox_new (int x, int y, int width, int height, int action,
151 lcback, char *tkname);
153 /* Input lines */
154 void winput_set_origin (WInput *i, int x, int field_len);
155 int handle_char (WInput *in, int c_code);
156 int is_in_input_map (WInput *in, int c_code);
157 void update_input (WInput *in, int clear_first);
158 void new_input (WInput *in);
159 int push_history (WInput *in, char *text);
160 void stuff (WInput *in, char *text, int insert_extra_space);
161 void input_disable_update (WInput *in);
162 void input_set_prompt (WInput *in, int field_len, char *prompt);
163 void input_enable_update (WInput *in);
164 void input_set_point (WInput *in, int pos);
165 void input_show_cursor (WInput *in);
166 void assign_text (WInput *in, char *text);
167 int input_callback (WInput *in, int Msg, int Par);
169 /* Labels */
170 void label_set_text (WLabel *label, char *text);
172 /* Gauges */
173 void gauge_set_value (WGauge *g, int max, int current);
174 void gauge_show (WGauge *g, int shown);
176 /* Buttons */
177 void button_set_text (WButton *b, char *text);
179 /* Listbox manager */
180 WLEntry *listbox_get_data (WListbox *l, int pos);
182 /* search text int listbox entries */
183 WLEntry *listbox_search_text (WListbox *l, char *text);
184 void listbox_select_entry (WListbox *l, WLEntry *dest);
185 void listbox_select_by_number (WListbox *l, int n);
186 void listbox_select_last (WListbox *l, int set_top);
187 void listbox_remove_current (WListbox *l, int force);
188 void listbox_remove_list (WListbox *l);
189 void listbox_get_current (WListbox *l, char **string, char **extra);
191 enum append_pos {
192 LISTBOX_APPEND_AT_END, /* append at the end */
193 LISTBOX_APPEND_BEFORE, /* insert before current */
194 LISTBOX_APPEND_AFTER /* insert after current */
197 char *listbox_add_item (WListbox *l, enum append_pos pos, int
198 hotkey, char *text, void *data);
200 /* Hintbar routines */
202 /* Buttonbar routines */
203 WButtonBar *buttonbar_new (int visible);
204 WButtonBar *find_buttonbar (Dlg_head *h);
205 typedef void (*voidfn)(void);
206 void define_label (Dlg_head *, int index, char *text, voidfn);
207 void define_label_data (Dlg_head *h, int idx, char *text,
208 buttonbarfn cback, void *data);
209 void redraw_labels (Dlg_head *h);
210 void buttonbar_hint (WButtonBar *bb, char *s);
212 #endif /* __WIDGET_H */