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 int term_first_shown
; /* column of the first shown character */
106 size_t current_max_size
; /* Maximum length of input line (bytes) */
107 int field_width
; /* width of the editing field */
108 int color
; /* color used */
109 int first
; /* Is first keystroke? */
110 int disable_update
; /* Do we want to skip updates? */
111 int is_password
; /* Is this a password input line? */
112 char *buffer
; /* pointer to editing buffer */
113 GList
*history
; /* The history */
114 int need_push
; /* need to push the current Input on hist? */
115 char **completions
; /* Possible completions array */
116 INPUT_COMPLETE_FLAGS completion_flags
; /* INPUT_COMPLETE* bitwise flags(complete.h) */
117 char *history_name
; /* name of history for loading and saving */
118 char charbuf
[MB_LEN_MAX
]; /* buffer for multibytes characters */
119 size_t charpoint
; /* point to end of mulibyte sequence in charbuf */
122 /* For history load-save functions */
123 #define INPUT_LAST_TEXT ((char *) 2)
127 int auto_adjust_cols
; /* compute widget.cols from strlen(text)? */
129 int transparent
; /* Paint in the default color fg/bg */
134 gboolean auto_adjust_cols
; /* Compute widget.cols from parent width? */
135 gboolean transparent
; /* Paint in the default color fg/bg */
138 typedef struct WLEntry
{
139 char *text
; /* Text to display */
141 void *data
; /* Client information */
145 typedef struct WListbox WListbox
;
146 typedef int (*lcback
) (WListbox
*);
148 /* Callback should return one of the following values */
150 LISTBOX_CONT
, /* continue */
151 LISTBOX_DONE
/* finish dialog */
156 GList
*list
; /* Pointer to the double linked list */
157 int pos
; /* The current element displayed */
158 int top
; /* The first element displayed */
159 int count
; /* Number of items in the listbox */
160 gboolean allow_duplicates
; /* Do we allow duplicates on the list? */
161 gboolean scrollbar
; /* Draw a scrollbar? */
162 gboolean deletable
; /* Can list entries be deleted? */
163 lcback cback
; /* The callback function */
164 int cursor_x
, cursor_y
; /* Cache the values */
167 /* number of bttons in buttonbar */
168 #define BUTTONBAR_LABELS_NUM 10
170 typedef struct WButtonBar
{
172 gboolean visible
; /* Is it visible? */
173 int btn_width
; /* width of one button */
176 unsigned long command
;
178 } labels
[BUTTONBAR_LABELS_NUM
];
181 typedef struct WGroupbox
{
187 /* Default callback for widgets */
188 cb_ret_t
default_proc (widget_msg_t msg
, int parm
);
191 WButton
*button_new (int y
, int x
, int action
, int flags
, const char *text
,
193 WRadio
*radio_new (int y
, int x
, int count
, const char **text
);
194 WCheck
*check_new (int y
, int x
, int state
, const char *text
);
195 WInput
*input_new (int y
, int x
, int color
, int len
, const char *text
, const char *histname
, INPUT_COMPLETE_FLAGS completion_flags
);
196 WLabel
*label_new (int y
, int x
, const char *text
);
197 WHLine
*hline_new (int y
, int x
, int width
);
199 WGauge
*gauge_new (int y
, int x
, int shown
, int max
, int current
);
200 WListbox
*listbox_new (int y
, int x
, int height
, int width
, gboolean deletable
, lcback callback
);
201 WButtonBar
*buttonbar_new (gboolean visible
);
202 WGroupbox
*groupbox_new (int y
, int x
, int height
, int width
, const char *title
);
205 void winput_set_origin (WInput
*i
, int x
, int field_width
);
206 cb_ret_t
handle_char (WInput
*in
, int c_code
);
207 int is_in_input_map (WInput
*in
, int c_code
);
208 void update_input (WInput
*in
, int clear_first
);
209 void new_input (WInput
*in
);
210 void stuff (WInput
*in
, const char *text
, int insert_extra_space
);
211 void input_disable_update (WInput
*in
);
212 void input_set_prompt (WInput
*in
, int field_len
, const char *prompt
);
213 void input_enable_update (WInput
*in
);
214 void input_set_point (WInput
*in
, int pos
);
215 void input_show_cursor (WInput
*in
);
216 void assign_text (WInput
*in
, const char *text
);
217 cb_ret_t
input_callback (Widget
*, widget_msg_t msg
, int parm
);
220 void label_set_text (WLabel
*label
, const char *text
);
223 void gauge_set_value (WGauge
*g
, int max
, int current
);
224 void gauge_show (WGauge
*g
, int shown
);
227 /* return copy of button text */
228 const char *button_get_text (const WButton
*b
);
229 void button_set_text (WButton
*b
, const char *text
);
230 int button_get_len (const WButton
*b
);
232 /* Listbox manager */
233 WLEntry
*listbox_get_data (WListbox
*l
, int pos
);
235 /* search text int listbox entries */
236 int listbox_search_text (WListbox
*l
, const char *text
);
237 void listbox_select_entry (WListbox
*l
, int dest
);
238 void listbox_select_first (WListbox
*l
);
239 void listbox_select_last (WListbox
*l
);
240 void listbox_remove_current (WListbox
*l
);
241 void listbox_set_list (WListbox
*l
, GList
*list
);
242 void listbox_remove_list (WListbox
*l
);
243 void listbox_get_current (WListbox
*l
, char **string
, void **extra
);
246 LISTBOX_APPEND_AT_END
= 0, /* append at the end */
247 LISTBOX_APPEND_BEFORE
, /* insert before current */
248 LISTBOX_APPEND_AFTER
, /* insert after current */
249 LISTBOX_APPEND_SORTED
/* insert alphabetically */
252 char *listbox_add_item (WListbox
*l
, listbox_append_t pos
,
253 int hotkey
, const char *text
, void *data
);
255 struct global_keymap_t
;
257 WButtonBar
*find_buttonbar (const Dlg_head
*h
);
258 void buttonbar_set_label (WButtonBar
*bb
, int idx
, const char *text
,
259 const struct global_keymap_t
*keymap
, const Widget
*receiver
);
260 #define buttonbar_clear_label(bb, idx, recv) buttonbar_set_label (bb, idx, "", NULL, recv)
261 void buttonbar_set_visible (WButtonBar
*bb
, gboolean visible
);
262 void buttonbar_redraw (WButtonBar
*bb
);
264 void free_completions (WInput
*in
);
265 void complete (WInput
*in
);
267 #endif /* MC_WIDGET_H */