3 * \brief Header: widgets
9 #include "lib/global.h"
10 #include "dialog.h" /* Widget */
12 /* Completion stuff */
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 */
34 typedef int (*bcback
) (struct WButton
*button
, int action
);
36 /* structure for label (caption) with hotkey, if original text does not contain
37 * hotkey, only start is valid and is equal to original text
38 * hotkey is defined as char*, but mc support only singlebyte hotkey
46 /* used in static definition of menu entries */
47 #define NULL_HOTKEY {NULL, NULL, NULL}
49 /* create hotkey from text */
50 struct hotkey_t
parse_hotkey (const char *text
);
51 /* release hotkey, free all mebers of hotkey_t */
52 void release_hotkey (const struct hotkey_t hotkey
);
53 /* return width on terminal of hotkey */
54 int hotkey_width (const struct hotkey_t hotkey
);
56 typedef struct WButton
{
58 int action
; /* what to do when pressed */
59 int selected
; /* button state */
61 #define HIDDEN_BUTTON 0
62 #define NARROW_BUTTON 1
63 #define NORMAL_BUTTON 2
64 #define DEFPUSH_BUTTON 3
65 unsigned int flags
; /* button flags */
66 struct hotkey_t text
; /* text of button, contain hotkey too */
67 int hotpos
; /* offset hot KEY char in text */
68 bcback callback
; /* Callback function */
71 typedef struct WRadio
{
73 unsigned int state
; /* radio button state */
75 int count
; /* number of members */
76 struct hotkey_t
*texts
; /* texts of labels */
79 typedef struct WCheck
{
83 #define C_CHANGE 0x0002
84 unsigned int state
; /* check button state */
85 struct hotkey_t text
; /* text of check button */
88 typedef struct WGauge
{
93 gboolean from_left_to_right
;
96 GList
*history_get (const char *input_name
);
97 void history_put (const char *input_name
, GList
*h
);
98 /* for repositioning of history dialog we should pass widget to this
99 * function, as position of history dialog depends on widget's position */
100 char *show_hist (GList
**history
, Widget
*widget
);
103 WINPUTC_MAIN
, /* color used */
104 WINPUTC_MARK
, /* color for marked text */
105 WINPUTC_UNCHANGED
, /* color for inactive text (Is first keystroke) */
106 WINPUTC_HISTORY
, /* color for history list */
107 WINPUTC_COUNT_COLORS
/* count of used colors */
108 } input_colors_enum_t
;
110 typedef int input_colors_t
[WINPUTC_COUNT_COLORS
];
114 int point
; /* cursor position in the input line in characters */
115 int mark
; /* The mark position in characters */
116 gboolean highlight
; /* There is a selected block */
117 int term_first_shown
; /* column of the first shown character */
118 size_t current_max_size
; /* Maximum length of input line (bytes) */
119 int field_width
; /* width of the editing field */
120 input_colors_t color
;
121 gboolean first
; /* Is first keystroke? */
122 int disable_update
; /* Do we want to skip updates? */
123 int is_password
; /* Is this a password input line? */
124 char *buffer
; /* pointer to editing buffer */
125 GList
*history
; /* The history */
126 int need_push
; /* need to push the current Input on hist? */
127 char **completions
; /* Possible completions array */
128 INPUT_COMPLETE_FLAGS completion_flags
; /* INPUT_COMPLETE* bitwise flags(complete.h) */
129 char *history_name
; /* name of history for loading and saving */
130 char charbuf
[MB_LEN_MAX
]; /* buffer for multibytes characters */
131 size_t charpoint
; /* point to end of mulibyte sequence in charbuf */
134 /* For history load-save functions */
135 #define INPUT_LAST_TEXT ((char *) 2)
139 int auto_adjust_cols
; /* compute widget.cols from strlen(text)? */
141 int transparent
; /* Paint in the default color fg/bg */
146 gboolean auto_adjust_cols
; /* Compute widget.cols from parent width? */
147 gboolean transparent
; /* Paint in the default color fg/bg */
150 typedef struct WLEntry
{
151 char *text
; /* Text to display */
153 void *data
; /* Client information */
157 typedef struct WListbox WListbox
;
158 typedef int (*lcback
) (WListbox
*);
160 /* Callback should return one of the following values */
162 LISTBOX_CONT
, /* continue */
163 LISTBOX_DONE
/* finish dialog */
168 GList
*list
; /* Pointer to the double linked list */
169 int pos
; /* The current element displayed */
170 int top
; /* The first element displayed */
171 int count
; /* Number of items in the listbox */
172 gboolean allow_duplicates
; /* Do we allow duplicates on the list? */
173 gboolean scrollbar
; /* Draw a scrollbar? */
174 gboolean deletable
; /* Can list entries be deleted? */
175 lcback cback
; /* The callback function */
176 int cursor_x
, cursor_y
; /* Cache the values */
179 /* number of bttons in buttonbar */
180 #define BUTTONBAR_LABELS_NUM 10
182 typedef struct WButtonBar
{
184 gboolean visible
; /* Is it visible? */
187 unsigned long command
;
189 int end_coord
; /* cumulative width of buttons so far */
190 } labels
[BUTTONBAR_LABELS_NUM
];
193 typedef struct WGroupbox
{
199 /* Default callback for widgets */
200 cb_ret_t
default_proc (widget_msg_t msg
, int parm
);
203 WButton
*button_new (int y
, int x
, int action
, int flags
, const char *text
,
205 WRadio
*radio_new (int y
, int x
, int count
, const char **text
);
206 WCheck
*check_new (int y
, int x
, int state
, const char *text
);
207 WInput
*input_new (int y
, int x
, int *input_colors
,
208 int len
, const char *text
, const char *histname
,
209 INPUT_COMPLETE_FLAGS completion_flags
);
210 WLabel
*label_new (int y
, int x
, const char *text
);
211 WHLine
*hline_new (int y
, int x
, int width
);
213 WGauge
*gauge_new (int y
, int x
, int shown
, int max
, int current
);
214 WListbox
*listbox_new (int y
, int x
, int height
, int width
, gboolean deletable
, lcback callback
);
215 WButtonBar
*buttonbar_new (gboolean visible
);
216 WGroupbox
*groupbox_new (int y
, int x
, int height
, int width
, const char *title
);
219 int *input_get_default_colors (void);
220 void winput_set_origin (WInput
*i
, int x
, int field_width
);
221 cb_ret_t
handle_char (WInput
*in
, int c_code
);
222 int is_in_input_map (WInput
*in
, int c_code
);
223 void update_input (WInput
*in
, int clear_first
);
224 void new_input (WInput
*in
);
225 void stuff (WInput
*in
, const char *text
, int insert_extra_space
);
226 void input_disable_update (WInput
*in
);
227 void input_set_prompt (WInput
*in
, int field_len
, const char *prompt
);
228 void input_enable_update (WInput
*in
);
229 void input_set_point (WInput
*in
, int pos
);
230 void input_show_cursor (WInput
*in
);
231 void assign_text (WInput
*in
, const char *text
);
232 cb_ret_t
input_callback (Widget
*, widget_msg_t msg
, int parm
);
235 void label_set_text (WLabel
*label
, const char *text
);
238 void gauge_set_value (WGauge
*g
, int max
, int current
);
239 void gauge_show (WGauge
*g
, int shown
);
242 /* return copy of button text */
243 const char *button_get_text (const WButton
*b
);
244 void button_set_text (WButton
*b
, const char *text
);
245 int button_get_len (const WButton
*b
);
247 /* Listbox manager */
248 WLEntry
*listbox_get_data (WListbox
*l
, int pos
);
250 /* search text int listbox entries */
251 int listbox_search_text (WListbox
*l
, const char *text
);
252 void listbox_select_entry (WListbox
*l
, int dest
);
253 void listbox_select_first (WListbox
*l
);
254 void listbox_select_last (WListbox
*l
);
255 void listbox_remove_current (WListbox
*l
);
256 void listbox_set_list (WListbox
*l
, GList
*list
);
257 void listbox_remove_list (WListbox
*l
);
258 void listbox_get_current (WListbox
*l
, char **string
, void **extra
);
261 LISTBOX_APPEND_AT_END
= 0, /* append at the end */
262 LISTBOX_APPEND_BEFORE
, /* insert before current */
263 LISTBOX_APPEND_AFTER
, /* insert after current */
264 LISTBOX_APPEND_SORTED
/* insert alphabetically */
267 char *listbox_add_item (WListbox
*l
, listbox_append_t pos
,
268 int hotkey
, const char *text
, void *data
);
270 struct global_keymap_t
;
272 WButtonBar
*find_buttonbar (const Dlg_head
*h
);
273 void buttonbar_set_label (WButtonBar
*bb
, int idx
, const char *text
,
274 const struct global_keymap_t
*keymap
, const Widget
*receiver
);
275 #define buttonbar_clear_label(bb, idx, recv) buttonbar_set_label (bb, idx, "", NULL, recv)
276 void buttonbar_set_visible (WButtonBar
*bb
, gboolean visible
);
277 void buttonbar_redraw (WButtonBar
*bb
);
279 void free_completions (WInput
*in
);
280 void complete (WInput
*in
);
282 #endif /* MC_WIDGET_H */