updated the .TP cleanup for coherency in the key description pages.
[midnight-commander.git] / src / widget.h
bloba08f9107322b43bce9bd9b53b6fef62ba4f59c43
1 #ifndef __WIDGET_H
2 #define __WIDGET_H
4 #define C_BOOL 1
5 #define C_CHANGE 2
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 */
11 #define HIDDEN_BUTTON 0
12 #define NARROW_BUTTON 1
13 #define NORMAL_BUTTON 2
14 #define DEFPUSH_BUTTON 3
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;
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 } WRadio;
37 typedef struct WCheck {
38 Widget widget;
39 unsigned int state; /* check button state */
40 char *text; /* text of check button */
41 int hotkey; /* hot KEY */
42 int hotpos; /* offset hot KEY char in text */
43 } WCheck;
45 typedef struct WGauge {
46 Widget widget;
47 int shown;
48 int max;
49 int current;
50 int pixels; /* Only used for Tk:
51 * We keep the pixel size in the C code
52 * so that we can compute quickly compute
53 * the size of the rectangle in the Tk
54 * canvas. Using Tcl would be too slow.
56 } WGauge;
58 typedef struct hist_entry {
59 struct hist_entry *prev;
60 struct hist_entry *next;
61 char *text;
62 } Hist;
64 Hist *history_get (char *input_name);
65 void history_put (char *input_name, Hist *h);
66 char *show_hist (Hist *history, int widget_y, int widget_x);
68 typedef struct {
69 Widget widget;
70 int point; /* cursor position in the input line */
71 int mark; /* The mark position */
72 int first_shown; /* Index of the first shown character */
73 int current_max_len; /* Maximum length of input line */
74 int field_len; /* Length of the editing field */
75 int color; /* color used */
76 int first; /* Is first keystroke? */
77 int disable_update; /* Do we want to skip updates? */
78 int is_password; /* Is this a password input line? */
79 unsigned char *buffer; /* pointer to editing buffer */
80 Hist *history; /* The history */
81 int need_push; /* need to push the current Input on hist? */
82 char **completions; /* Possible completions array */
83 int completion_flags; /* INPUT_COMPLETE* bitwise flags(complete.h) */
84 int inserted_one; /* TK: just one char inserted, nothing fancy */
85 char *history_name; /* name of history for loading and saving */
86 } WInput;
88 /* For history load-save functions */
89 #define INPUT_LAST_TEXT ((char *) 2)
90 #define HISTORY_FILE_NAME ".mc/history"
92 typedef struct {
93 Widget widget;
94 int auto_adjust_cols; /* compute widget.cols from strlen(text)? */
95 char *text;
96 int transparent; /* Paint in the default color fg/bg */
97 } WLabel;
99 typedef struct WLEntry {
100 char *text; /* Text to display */
101 int hotkey;
102 void *data; /* Client information */
103 struct WLEntry *next;
104 struct WLEntry *prev;
105 } WLEntry;
107 enum {
108 listbox_begin, listbox_end
109 } /* listbox_insert */;
111 /* Listbox actions when selecting an option: */
112 enum {
113 listbox_nothing,
114 listbox_finish, /* finish dialog */
115 listbox_cback /* call the callback routine */
116 } /* listbox_action */;
118 typedef int (*lcback) (void *);
120 typedef struct {
121 Widget widget;
122 WLEntry *list; /* Pointer to the circular double linked list. */
123 WLEntry *top; /* The first element displayed */
124 WLEntry *current; /* The current element displayed */
125 int pos; /* Cur. pos, must be kept in sync with current */
126 int count; /* Number of items in the listbox */
127 int width;
128 int height; /* Size of the widget */
129 int action; /* Action type */
130 int allow_duplicates; /* Do we allow duplicates on the list? */
131 int scrollbar; /* Draw a scrollbar? */
132 lcback cback; /* The callback function */
133 int cursor_x, cursor_y; /* Cache the values */
134 } WListbox;
136 typedef void (*buttonbarfn)(void *);
138 typedef struct {
139 Widget widget;
140 int visible; /* Is it visible? */
141 struct {
142 char *text;
143 buttonbarfn function;
144 void *data;
145 } labels [10];
146 } WButtonBar;
148 /* Constructors */
149 WButton *button_new (int y, int x, int action, int flags, char *text,
150 int (*callback)(int, void *), void *extra, char *tkname);
151 WRadio *radio_new (int y, int x, int count, char **text, int use_hotkey, char *tkname);
152 WCheck *check_new (int y, int x, int state, char *text, char *tkname);
153 WInput *input_new (int y, int x, int color, int len, const char *text, char *tkname);
154 WLabel *label_new (int y, int x, const char *text, char *tkname);
155 WGauge *gauge_new (int y, int x, int shown, int max, int current, char *tkname);
156 WListbox *listbox_new (int x, int y, int width, int height, int action,
157 lcback, char *tkname);
159 /* Input lines */
160 void winput_set_origin (WInput *i, int x, int field_len);
161 int handle_char (WInput *in, int c_code);
162 int is_in_input_map (WInput *in, int c_code);
163 void update_input (WInput *in, int clear_first);
164 void new_input (WInput *in);
165 int push_history (WInput *in, char *text);
166 void stuff (WInput *in, char *text, int insert_extra_space);
167 void input_disable_update (WInput *in);
168 void input_set_prompt (WInput *in, int field_len, char *prompt);
169 void input_enable_update (WInput *in);
170 void input_set_point (WInput *in, int pos);
171 void input_show_cursor (WInput *in);
172 void assign_text (WInput *in, char *text);
173 int input_callback (Dlg_head *h, WInput *in, int Msg, int Par);
175 /* Labels */
176 void label_set_text (WLabel *label, char *text);
178 /* Gauges */
179 void gauge_set_value (WGauge *g, int max, int current);
180 void gauge_show (WGauge *g, int shown);
182 /* Buttons */
183 void button_set_text (WButton *b, char *text);
185 /* Listbox manager */
186 WLEntry *listbox_get_data (WListbox *l, int pos);
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);
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 */
203 char *listbox_add_item (WListbox *l, enum append_pos pos, int
204 hotkey, char *text, void *data);
206 /* Hintbar routines */
208 /* Buttonbar routines */
209 WButtonBar *buttonbar_new (int visible);
210 typedef void (*voidfn)(void);
211 void define_label (Dlg_head *, Widget *paneletc, int index, char *text, voidfn);
212 void define_label_data (Dlg_head *h, Widget *paneletc, int idx, char *text,
213 buttonbarfn cback, void *data);
214 void redraw_labels (Dlg_head *h, Widget *paneletc);
215 void buttonbar_hint (WButtonBar *bb, char *s);
217 #endif /* __WIDGET_H */