3 * \brief Header: widgets
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
{
94 GList
*history_get (const char *input_name
);
95 void history_put (const char *input_name
, GList
*h
);
96 /* for repositioning of history dialog we should pass widget to this
97 * function, as position of history dialog depends on widget's position */
98 char *show_hist (GList
*history
, Widget
*widget
);
102 int point
; /* cursor position in the input line in characters */
103 int mark
; /* The mark position in characters */
104 int term_first_shown
; /* column of the first shown character */
105 size_t current_max_size
; /* Maximum length of input line (bytes) */
106 int field_width
; /* width of the editing field */
107 int color
; /* color used */
108 int first
; /* Is first keystroke? */
109 int disable_update
; /* Do we want to skip updates? */
110 int is_password
; /* Is this a password input line? */
111 char *buffer
; /* pointer to editing buffer */
112 GList
*history
; /* The history */
113 int need_push
; /* need to push the current Input on hist? */
114 char **completions
; /* Possible completions array */
115 INPUT_COMPLETE_FLAGS completion_flags
; /* INPUT_COMPLETE* bitwise flags(complete.h) */
116 char *history_name
; /* name of history for loading and saving */
117 char charbuf
[MB_LEN_MAX
]; /* buffer for multibytes characters */
118 size_t charpoint
; /* point to end of mulibyte sequence in charbuf */
121 /* For history load-save functions */
122 #define INPUT_LAST_TEXT ((char *) 2)
126 int auto_adjust_cols
; /* compute widget.cols from strlen(text)? */
128 int transparent
; /* Paint in the default color fg/bg */
131 typedef struct WLEntry
{
132 char *text
; /* Text to display */
134 void *data
; /* Client information */
135 struct WLEntry
*next
;
136 struct WLEntry
*prev
;
140 typedef struct WListbox WListbox
;
141 typedef int (*lcback
) (WListbox
*);
143 /* Callback should return one of the following values */
145 LISTBOX_CONT
, /* continue */
146 LISTBOX_DONE
/* finish dialog */
151 WLEntry
*list
; /* Pointer to the circular double linked list. */
152 WLEntry
*top
; /* The first element displayed */
153 WLEntry
*current
; /* The current element displayed */
154 int pos
; /* Cur. pos, must be kept in sync with current */
155 int count
; /* Number of items in the listbox */
156 int allow_duplicates
; /* Do we allow duplicates on the list? */
157 int scrollbar
; /* Draw a scrollbar? */
158 lcback cback
; /* The callback function */
159 int cursor_x
, cursor_y
; /* Cache the values */
162 /* number of bttons in buttonbar */
163 #define BUTTONBAR_LABELS_NUM 10
165 typedef struct WButtonBar
{
167 gboolean visible
; /* Is it visible? */
168 int btn_width
; /* width of one button */
171 unsigned long command
;
173 } labels
[BUTTONBAR_LABELS_NUM
];
176 typedef struct WGroupbox
{
182 /* Default callback for widgets */
183 cb_ret_t
default_proc (widget_msg_t msg
, int parm
);
186 WButton
*button_new (int y
, int x
, int action
, int flags
, const char *text
,
188 WRadio
*radio_new (int y
, int x
, int count
, const char **text
);
189 WCheck
*check_new (int y
, int x
, int state
, const char *text
);
190 WInput
*input_new (int y
, int x
, int color
, int len
, const char *text
, const char *histname
, INPUT_COMPLETE_FLAGS completion_flags
);
191 WLabel
*label_new (int y
, int x
, const char *text
);
192 WGauge
*gauge_new (int y
, int x
, int shown
, int max
, int current
);
193 WListbox
*listbox_new (int y
, int x
, int height
, int width
, lcback callback
);
194 WButtonBar
*buttonbar_new (gboolean visible
);
195 WGroupbox
*groupbox_new (int y
, int x
, int height
, int width
, const char *title
);
198 void winput_set_origin (WInput
*i
, int x
, int field_width
);
199 cb_ret_t
handle_char (WInput
*in
, int c_code
);
200 int is_in_input_map (WInput
*in
, int c_code
);
201 void update_input (WInput
*in
, int clear_first
);
202 void new_input (WInput
*in
);
203 void stuff (WInput
*in
, const char *text
, int insert_extra_space
);
204 void input_disable_update (WInput
*in
);
205 void input_set_prompt (WInput
*in
, int field_len
, const char *prompt
);
206 void input_enable_update (WInput
*in
);
207 void input_set_point (WInput
*in
, int pos
);
208 void input_show_cursor (WInput
*in
);
209 void assign_text (WInput
*in
, const char *text
);
210 cb_ret_t
input_callback (Widget
*, widget_msg_t msg
, int parm
);
213 void label_set_text (WLabel
*label
, const char *text
);
216 void gauge_set_value (WGauge
*g
, int max
, int current
);
217 void gauge_show (WGauge
*g
, int shown
);
220 /* return copy of button text */
221 const char *button_get_text (const WButton
*b
);
222 void button_set_text (WButton
*b
, const char *text
);
223 int button_get_len (const WButton
*b
);
225 /* Listbox manager */
226 WLEntry
*listbox_get_data (WListbox
*l
, int pos
);
228 /* search text int listbox entries */
229 WLEntry
*listbox_search_text (WListbox
*l
, const char *text
);
230 void listbox_select_entry (WListbox
*l
, WLEntry
*dest
);
231 void listbox_select_by_number (WListbox
*l
, int n
);
232 void listbox_select_last (WListbox
*l
);
233 void listbox_select_first (WListbox
*l
);
234 void listbox_remove_current (WListbox
*l
, int force
);
235 void listbox_remove_list (WListbox
*l
);
236 void listbox_get_current (WListbox
*l
, char **string
, char **extra
);
239 LISTBOX_APPEND_AT_END
= 0, /* append at the end */
240 LISTBOX_APPEND_BEFORE
, /* insert before current */
241 LISTBOX_APPEND_AFTER
, /* insert after current */
242 LISTBOX_APPEND_SORTED
/* insert alphabetically */
245 char *listbox_add_item (WListbox
*l
, enum append_pos pos
, int
246 hotkey
, const char *text
, void *data
);
248 struct global_keymap_t
;
250 WButtonBar
*find_buttonbar (const Dlg_head
*h
);
251 void buttonbar_set_label (WButtonBar
*bb
, int index
, const char *text
,
252 const struct global_keymap_t
*keymap
, const Widget
*receiver
);
253 #define buttonbar_clear_label(bb, idx, recv) buttonbar_set_label (bb, idx, "", NULL, recv)
254 void buttonbar_set_visible (WButtonBar
*bb
, gboolean visible
);
255 void buttonbar_redraw (WButtonBar
*bb
);
257 void free_completions (WInput
*in
);
258 void complete (WInput
*in
);
260 #endif /* MC_WIDGET_H */