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 */
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
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
{
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 */
70 typedef struct WRadio
{
72 unsigned int state
; /* radio button state */
74 int count
; /* number of members */
75 struct hotkey_t
*texts
; /* texts of labels */
78 typedef struct WCheck
{
82 #define C_CHANGE 0x0002
83 unsigned int state
; /* check button state */
84 struct hotkey_t text
; /* text of check button */
87 typedef struct WGauge
{
92 gboolean from_left_to_right
;
95 GList
*history_get (const char *input_name
);
96 void history_put (const char *input_name
, GList
*h
);
97 /* for repositioning of history dialog we should pass widget to this
98 * function, as position of history dialog depends on widget's position */
99 char *show_hist (GList
**history
, Widget
*widget
);
103 int point
; /* cursor position in the input line in characters */
104 int mark
; /* The mark position in characters */
105 gboolean highlight
; /* There is a selected block */
106 int term_first_shown
; /* column of the first shown character */
107 size_t current_max_size
; /* Maximum length of input line (bytes) */
108 int field_width
; /* width of the editing field */
109 int color
; /* color used */
110 int mark_color
; /* color for marked text */
111 int unchanged_color
; /* color for inactive text (Is first keystroke) */
112 gboolean first
; /* Is first keystroke? */
113 int disable_update
; /* Do we want to skip updates? */
114 int is_password
; /* Is this a password input line? */
115 char *buffer
; /* pointer to editing buffer */
116 GList
*history
; /* The history */
117 int need_push
; /* need to push the current Input on hist? */
118 char **completions
; /* Possible completions array */
119 INPUT_COMPLETE_FLAGS completion_flags
; /* INPUT_COMPLETE* bitwise flags(complete.h) */
120 char *history_name
; /* name of history for loading and saving */
121 char charbuf
[MB_LEN_MAX
]; /* buffer for multibytes characters */
122 size_t charpoint
; /* point to end of mulibyte sequence in charbuf */
125 /* For history load-save functions */
126 #define INPUT_LAST_TEXT ((char *) 2)
130 int auto_adjust_cols
; /* compute widget.cols from strlen(text)? */
132 int transparent
; /* Paint in the default color fg/bg */
137 gboolean auto_adjust_cols
; /* Compute widget.cols from parent width? */
138 gboolean transparent
; /* Paint in the default color fg/bg */
141 typedef struct WLEntry
{
142 char *text
; /* Text to display */
144 void *data
; /* Client information */
148 typedef struct WListbox WListbox
;
149 typedef int (*lcback
) (WListbox
*);
151 /* Callback should return one of the following values */
153 LISTBOX_CONT
, /* continue */
154 LISTBOX_DONE
/* finish dialog */
159 GList
*list
; /* Pointer to the double linked list */
160 int pos
; /* The current element displayed */
161 int top
; /* The first element displayed */
162 int count
; /* Number of items in the listbox */
163 gboolean allow_duplicates
; /* Do we allow duplicates on the list? */
164 gboolean scrollbar
; /* Draw a scrollbar? */
165 gboolean deletable
; /* Can list entries be deleted? */
166 lcback cback
; /* The callback function */
167 int cursor_x
, cursor_y
; /* Cache the values */
170 /* number of bttons in buttonbar */
171 #define BUTTONBAR_LABELS_NUM 10
173 typedef struct WButtonBar
{
175 gboolean visible
; /* Is it visible? */
176 int btn_width
; /* width of one button */
179 unsigned long command
;
181 } labels
[BUTTONBAR_LABELS_NUM
];
184 typedef struct WGroupbox
{
190 /* Default callback for widgets */
191 cb_ret_t
default_proc (widget_msg_t msg
, int parm
);
194 WButton
*button_new (int y
, int x
, int action
, int flags
, const char *text
,
196 WRadio
*radio_new (int y
, int x
, int count
, const char **text
);
197 WCheck
*check_new (int y
, int x
, int state
, const char *text
);
198 WInput
*input_new (int y
, int x
, int *input_colors
,
199 int len
, const char *text
, const char *histname
,
200 INPUT_COMPLETE_FLAGS completion_flags
);
201 WLabel
*label_new (int y
, int x
, const char *text
);
202 WHLine
*hline_new (int y
, int x
, int width
);
204 WGauge
*gauge_new (int y
, int x
, int shown
, int max
, int current
);
205 WListbox
*listbox_new (int y
, int x
, int height
, int width
, gboolean deletable
, lcback callback
);
206 WButtonBar
*buttonbar_new (gboolean visible
);
207 WGroupbox
*groupbox_new (int y
, int x
, int height
, int width
, const char *title
);
210 void winput_set_origin (WInput
*i
, int x
, int field_width
);
211 cb_ret_t
handle_char (WInput
*in
, int c_code
);
212 int is_in_input_map (WInput
*in
, int c_code
);
213 void update_input (WInput
*in
, int clear_first
);
214 void new_input (WInput
*in
);
215 void stuff (WInput
*in
, const char *text
, int insert_extra_space
);
216 void input_disable_update (WInput
*in
);
217 void input_set_prompt (WInput
*in
, int field_len
, const char *prompt
);
218 void input_enable_update (WInput
*in
);
219 void input_set_point (WInput
*in
, int pos
);
220 void input_show_cursor (WInput
*in
);
221 void assign_text (WInput
*in
, const char *text
);
222 cb_ret_t
input_callback (Widget
*, widget_msg_t msg
, int parm
);
225 void label_set_text (WLabel
*label
, const char *text
);
228 void gauge_set_value (WGauge
*g
, int max
, int current
);
229 void gauge_show (WGauge
*g
, int shown
);
232 /* return copy of button text */
233 const char *button_get_text (const WButton
*b
);
234 void button_set_text (WButton
*b
, const char *text
);
235 int button_get_len (const WButton
*b
);
237 /* Listbox manager */
238 WLEntry
*listbox_get_data (WListbox
*l
, int pos
);
240 /* search text int listbox entries */
241 int listbox_search_text (WListbox
*l
, const char *text
);
242 void listbox_select_entry (WListbox
*l
, int dest
);
243 void listbox_select_first (WListbox
*l
);
244 void listbox_select_last (WListbox
*l
);
245 void listbox_remove_current (WListbox
*l
);
246 void listbox_set_list (WListbox
*l
, GList
*list
);
247 void listbox_remove_list (WListbox
*l
);
248 void listbox_get_current (WListbox
*l
, char **string
, void **extra
);
251 LISTBOX_APPEND_AT_END
= 0, /* append at the end */
252 LISTBOX_APPEND_BEFORE
, /* insert before current */
253 LISTBOX_APPEND_AFTER
, /* insert after current */
254 LISTBOX_APPEND_SORTED
/* insert alphabetically */
257 char *listbox_add_item (WListbox
*l
, listbox_append_t pos
,
258 int hotkey
, const char *text
, void *data
);
260 struct global_keymap_t
;
262 WButtonBar
*find_buttonbar (const Dlg_head
*h
);
263 void buttonbar_set_label (WButtonBar
*bb
, int idx
, const char *text
,
264 const struct global_keymap_t
*keymap
, const Widget
*receiver
);
265 #define buttonbar_clear_label(bb, idx, recv) buttonbar_set_label (bb, idx, "", NULL, recv)
266 void buttonbar_set_visible (WButtonBar
*bb
, gboolean visible
);
267 void buttonbar_redraw (WButtonBar
*bb
);
269 void free_completions (WInput
*in
);
270 void complete (WInput
*in
);
272 #endif /* MC_WIDGET_H */