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
{
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 */
138 typedef struct WListbox WListbox
;
139 typedef int (*lcback
) (WListbox
*);
141 /* Callback should return one of the following values */
143 LISTBOX_CONT
, /* continue */
144 LISTBOX_DONE
/* finish dialog */
149 GList
*list
; /* Pointer to the double linked list */
150 int pos
; /* The current element displayed */
151 int top
; /* The first element displayed */
152 int count
; /* Number of items in the listbox */
153 gboolean allow_duplicates
; /* Do we allow duplicates on the list? */
154 gboolean scrollbar
; /* Draw a scrollbar? */
155 gboolean deletable
; /* Can list entries be deleted? */
156 lcback cback
; /* The callback function */
157 int cursor_x
, cursor_y
; /* Cache the values */
160 /* number of bttons in buttonbar */
161 #define BUTTONBAR_LABELS_NUM 10
163 typedef struct WButtonBar
{
165 gboolean visible
; /* Is it visible? */
166 int btn_width
; /* width of one button */
169 unsigned long command
;
171 } labels
[BUTTONBAR_LABELS_NUM
];
174 typedef struct WGroupbox
{
180 /* Default callback for widgets */
181 cb_ret_t
default_proc (widget_msg_t msg
, int parm
);
184 WButton
*button_new (int y
, int x
, int action
, int flags
, const char *text
,
186 WRadio
*radio_new (int y
, int x
, int count
, const char **text
);
187 WCheck
*check_new (int y
, int x
, int state
, const char *text
);
188 WInput
*input_new (int y
, int x
, int color
, int len
, const char *text
, const char *histname
, INPUT_COMPLETE_FLAGS completion_flags
);
189 WLabel
*label_new (int y
, int x
, const char *text
);
190 WGauge
*gauge_new (int y
, int x
, int shown
, int max
, int current
);
191 WListbox
*listbox_new (int y
, int x
, int height
, int width
, gboolean deletable
, lcback callback
);
192 WButtonBar
*buttonbar_new (gboolean visible
);
193 WGroupbox
*groupbox_new (int y
, int x
, int height
, int width
, const char *title
);
196 void winput_set_origin (WInput
*i
, int x
, int field_width
);
197 cb_ret_t
handle_char (WInput
*in
, int c_code
);
198 int is_in_input_map (WInput
*in
, int c_code
);
199 void update_input (WInput
*in
, int clear_first
);
200 void new_input (WInput
*in
);
201 void stuff (WInput
*in
, const char *text
, int insert_extra_space
);
202 void input_disable_update (WInput
*in
);
203 void input_set_prompt (WInput
*in
, int field_len
, const char *prompt
);
204 void input_enable_update (WInput
*in
);
205 void input_set_point (WInput
*in
, int pos
);
206 void input_show_cursor (WInput
*in
);
207 void assign_text (WInput
*in
, const char *text
);
208 cb_ret_t
input_callback (Widget
*, widget_msg_t msg
, int parm
);
211 void label_set_text (WLabel
*label
, const char *text
);
214 void gauge_set_value (WGauge
*g
, int max
, int current
);
215 void gauge_show (WGauge
*g
, int shown
);
218 /* return copy of button text */
219 const char *button_get_text (const WButton
*b
);
220 void button_set_text (WButton
*b
, const char *text
);
221 int button_get_len (const WButton
*b
);
223 /* Listbox manager */
224 WLEntry
*listbox_get_data (WListbox
*l
, int pos
);
226 /* search text int listbox entries */
227 int listbox_search_text (WListbox
*l
, const char *text
);
228 void listbox_select_entry (WListbox
*l
, int dest
);
229 void listbox_select_first (WListbox
*l
);
230 void listbox_select_last (WListbox
*l
);
231 void listbox_remove_current (WListbox
*l
);
232 void listbox_set_list (WListbox
*l
, GList
*list
);
233 void listbox_remove_list (WListbox
*l
);
234 void listbox_get_current (WListbox
*l
, char **string
, void **extra
);
237 LISTBOX_APPEND_AT_END
= 0, /* append at the end */
238 LISTBOX_APPEND_BEFORE
, /* insert before current */
239 LISTBOX_APPEND_AFTER
, /* insert after current */
240 LISTBOX_APPEND_SORTED
/* insert alphabetically */
243 char *listbox_add_item (WListbox
*l
, listbox_append_t pos
,
244 int hotkey
, const char *text
, void *data
);
246 struct global_keymap_t
;
248 WButtonBar
*find_buttonbar (const Dlg_head
*h
);
249 void buttonbar_set_label (WButtonBar
*bb
, int idx
, const char *text
,
250 const struct global_keymap_t
*keymap
, const Widget
*receiver
);
251 #define buttonbar_clear_label(bb, idx, recv) buttonbar_set_label (bb, idx, "", NULL, recv)
252 void buttonbar_set_visible (WButtonBar
*bb
, gboolean visible
);
253 void buttonbar_redraw (WButtonBar
*bb
);
255 void free_completions (WInput
*in
);
256 void complete (WInput
*in
);
258 #endif /* MC_WIDGET_H */