Fix umpnpmgr build
[reactos.git] / rosapps / mc / src / widget.h
1 #ifndef __WIDGET_H
2 #define __WIDGET_H
3
4 #define C_BOOL 1
5 #define C_CHANGE 2
6
7 /* Please note that the first element in all the widgets is a */
8 /* widget variable of type Widget. We abuse this fact everywhere */
9 /* Widget_Items */
10
11 #define HIDDEN_BUTTON 0
12 #define NARROW_BUTTON 1
13 #define NORMAL_BUTTON 2
14 #define DEFPUSH_BUTTON 3
15
16 typedef struct WButton {
17 Widget widget;
18 int action; /* what to do when pressed */
19 int selected; /* button state */
20 unsigned int flags; /* button flags */
21 char *text; /* text of button */
22 int hotkey; /* hot KEY */
23 int hotpos; /* offset hot KEY char in text */
24 int (*callback)(int, void*); /* Callback function */
25 void *callback_data;
26 } WButton;
27
28 typedef struct WRadio {
29 Widget widget;
30 unsigned int state; /* radio button state */
31 int pos, sel;
32 int count; /* number of members */
33 char **texts; /* texts of labels */
34 int upper_letter_is_hotkey; /* If true, then the capital letter is a hk */
35 #ifdef HAVE_GNOME
36 void *first_gtk_radio;
37 #endif
38 } WRadio;
39
40 typedef struct WCheck {
41 Widget widget;
42 unsigned int state; /* check button state */
43 char *text; /* text of check button */
44 int hotkey; /* hot KEY */
45 int hotpos; /* offset hot KEY char in text */
46 } WCheck;
47
48 typedef struct WGauge {
49 Widget widget;
50 int shown;
51 int max;
52 int current;
53 int pixels; /* Only used for Tk:
54 * We keep the pixel size in the C code
55 * so that we can compute quickly compute
56 * the size of the rectangle in the Tk
57 * canvas. Using Tcl would be too slow.
58 */
59 } WGauge;
60
61 typedef struct hist_entry {
62 struct hist_entry *prev;
63 struct hist_entry *next;
64 char *text;
65 } Hist;
66
67 Hist *history_get (char *input_name);
68 void history_put (char *input_name, Hist *h);
69 char *show_hist (Hist *history, int widget_y, int widget_x);
70
71 typedef struct {
72 Widget widget;
73 int point; /* cursor position in the input line */
74 int mark; /* The mark position */
75 int first_shown; /* Index of the first shown character */
76 int current_max_len; /* Maximum length of input line */
77 int field_len; /* Length of the editing field */
78 int color; /* color used */
79 int first; /* Is first keystroke? */
80 int disable_update; /* Do we want to skip updates? */
81 int is_password; /* Is this a password input line? */
82 char *buffer; /* pointer to editing buffer */
83 Hist *history; /* The history */
84 int need_push; /* need to push the current Input on hist? */
85 char **completions; /* Possible completions array */
86 int completion_flags; /* INPUT_COMPLETE* bitwise flags(complete.h) */
87 int inserted_one; /* TK: just one char inserted, nothing fancy */
88 char *history_name; /* name of history for loading and saving */
89 } WInput;
90
91 /* For history load-save functions */
92 #define INPUT_LAST_TEXT ((char *) 2)
93 #define HISTORY_FILE_NAME ".mc/history"
94
95 typedef struct {
96 Widget widget;
97 int auto_adjust_cols; /* compute widget.cols from strlen(text)? */
98 char *text;
99 int transparent; /* Paint in the default color fg/bg */
100 } WLabel;
101
102 typedef struct WLEntry {
103 char *text; /* Text to display */
104 int hotkey;
105 void *data; /* Client information */
106 struct WLEntry *next;
107 struct WLEntry *prev;
108 } WLEntry;
109
110 enum {
111 listbox_begin, listbox_end
112 } /* listbox_insert */;
113
114 /* Listbox actions when selecting an option: */
115 enum {
116 listbox_nothing,
117 listbox_finish, /* finish dialog */
118 listbox_cback /* call the callback routine */
119 } /* listbox_action */;
120
121 typedef int (*lcback) (void *);
122
123 typedef struct {
124 Widget widget;
125 WLEntry *list; /* Pointer to the circular double linked list. */
126 WLEntry *top; /* The first element displayed */
127 WLEntry *current; /* The current element displayed */
128 int pos; /* Cur. pos, must be kept in sync with current */
129 int count; /* Number of items in the listbox */
130 int width;
131 int height; /* Size of the widget */
132 int action; /* Action type */
133 int allow_duplicates; /* Do we allow duplicates on the list? */
134 int scrollbar; /* Draw a scrollbar? */
135 lcback cback; /* The callback function */
136 int cursor_x, cursor_y; /* Cache the values */
137 } WListbox;
138
139 typedef struct {
140 Widget widget;
141 int visible; /* Is it visible? */
142 struct {
143 char *text;
144 void (*function)(void *data);
145 void *data;
146 } labels [10];
147 } WButtonBar;
148
149 /* Constructors */
150 WButton *button_new (int y, int x, int action, int flags, char *text,
151 int (*callback)(int, void *), void *extra, char *tkname);
152 WRadio *radio_new (int y, int x, int count, char **text, int use_hotkey, char *tkname);
153 WCheck *check_new (int y, int x, int state, char *text, char *tkname);
154 WInput *input_new (int y, int x, int color, int len, char *text, char *tkname);
155 WLabel *label_new (int y, int x, char *text, char *tkname);
156 WGauge *gauge_new (int y, int x, int shown, int max, int current, char *tkname);
157 WListbox *listbox_new (int x, int y, int width, int height, int action,
158 lcback, char *tkname);
159
160 /* Input lines */
161 void winput_set_origin (WInput *i, int x, int field_len);
162 int handle_char (WInput *in, int c_code);
163 int is_in_input_map (WInput *in, int c_code);
164 void update_input (WInput *in, int clear_first);
165 void new_input (WInput *in);
166 int push_history (WInput *in, char *text);
167 void stuff (WInput *in, char *text, int insert_extra_space);
168 void input_disable_update (WInput *in);
169 void input_set_prompt (WInput *in, int field_len, char *prompt);
170 void input_enable_update (WInput *in);
171 void input_set_point (WInput *in, int pos);
172 void input_show_cursor (WInput *in);
173 void assign_text (WInput *in, char *text);
174
175 /* Labels */
176 void label_set_text (WLabel *label, char *text);
177
178 /* Gauges */
179 void gauge_set_value (WGauge *g, int max, int current);
180 void gauge_show (WGauge *g, int shown);
181
182 /* Buttons */
183 void button_set_text (WButton *b, char *text);
184
185 /* Listbox manager */
186 WLEntry *listbox_get_data (WListbox *l, int pos);
187
188 /* search text int listbox entries */
189 WLEntry *listbox_search_text (WListbox *l, char *text);
190 void listbox_select_entry (WListbox *l, WLEntry *dest);
191 void listbox_select_by_number (WListbox *l, int n);
192 void listbox_select_last (WListbox *l, int set_top);
193 void listbox_remove_current (WListbox *l, int force);
194 void listbox_remove_list (WListbox *l);
195 void listbox_get_current (WListbox *l, char **string, char **extra);
196
197 enum append_pos {
198 LISTBOX_APPEND_AT_END, /* append at the end */
199 LISTBOX_APPEND_BEFORE, /* insert before current */
200 LISTBOX_APPEND_AFTER /* insert after current */
201 };
202
203 char *listbox_add_item (WListbox *l, enum append_pos pos, int
204 hotkey, char *text, void *data);
205
206 /* Hintbar routines */
207
208 /* Buttonbar routines */
209 WButtonBar *buttonbar_new (int visible);
210 typedef void (*buttonbarfn )(void *);
211 typedef void (*voidfn)(void);
212 void define_label (Dlg_head *, Widget *paneletc, int index, char *text, voidfn);
213 void define_label_data (Dlg_head *h, Widget *paneletc, int idx, char *text,
214 buttonbarfn cback, void *data);
215 void set_label_text (WButtonBar *, int, char *);
216 void redraw_labels (Dlg_head *h, Widget *paneletc);
217 WButtonBar *find_buttonbar (Dlg_head *h, Widget *paneletc);
218 void buttonbar_hint (WButtonBar *bb, char *s);
219
220 #ifdef HAVE_X
221 int x_create_radio (Dlg_head *h, widget_data parent, WRadio *r);
222 int x_create_button (Dlg_head *h, widget_data parent, WButton *b);
223 int x_create_check (Dlg_head *h, widget_data parent, WCheck *c);
224 int x_create_label (Dlg_head *h, widget_data parent, WLabel *l);
225 int x_create_input (Dlg_head *h, widget_data parent, WInput *in);
226 int x_create_listbox (Dlg_head *h, widget_data parent, WListbox *l);
227 int x_create_buttonbar (Dlg_head *h, widget_data parent, WButtonBar *bb);
228
229 void x_button_set (WButton *b, char *text);
230 void x_label_set_text (WLabel *label, char *text);
231 void x_listbox_select_nth (WListbox *l, int nth);
232 void x_listbox_delete_nth (WListbox *l, int nth);
233 void x_label_set_text (WLabel *label, char *text);
234 int x_create_gauge (Dlg_head *h, widget_data parent, WGauge *g);
235 void x_gauge_show (WGauge *g);
236 void x_gauge_set_value (WGauge *g, int max, int current);
237 void x_radio_toggle (WRadio *);
238 void x_radio_focus_item (WRadio *radio);
239 void x_listbox_select_nth (WListbox *, int);
240 void x_list_insert (WListbox *, WLEntry *, WLEntry *);
241 void x_redefine_label (WButtonBar *, int);
242 void x_update_input (WInput *in);
243 #endif
244
245 #endif /* __WIDGET_H */