42dc5bf1ea3c9a912d2a0904f44cd062a5988905
[midnight-commander.git] / lib / widget / input.h
blob42dc5bf1ea3c9a912d2a0904f44cd062a5988905
2 /** \file input.h
3 * \brief Header: WInput widget
4 */
6 #ifndef MC__WIDGET_INPUT_H
7 #define MC__WIDGET_INPUT_H
9 #include "lib/keybind.h" /* global_keymap_t */
11 /*** typedefs(not structures) and defined constants **********************************************/
13 /* For history load-save functions */
14 #define INPUT_LAST_TEXT ((char *) 2)
16 /*** enums ***************************************************************************************/
18 typedef enum
20 WINPUTC_MAIN, /* color used */
21 WINPUTC_MARK, /* color for marked text */
22 WINPUTC_UNCHANGED, /* color for inactive text (Is first keystroke) */
23 WINPUTC_HISTORY, /* color for history list */
24 WINPUTC_COUNT_COLORS /* count of used colors */
25 } input_colors_enum_t;
27 /* completion flags */
28 typedef enum
30 INPUT_COMPLETE_FILENAMES = 1 << 0,
31 INPUT_COMPLETE_HOSTNAMES = 1 << 1,
32 INPUT_COMPLETE_COMMANDS = 1 << 2,
33 INPUT_COMPLETE_VARIABLES = 1 << 3,
34 INPUT_COMPLETE_USERNAMES = 1 << 4,
35 INPUT_COMPLETE_CD = 1 << 5,
36 INPUT_COMPLETE_SHELL_ESC = 1 << 6,
38 INPUT_COMPLETE_DEFAULT = INPUT_COMPLETE_FILENAMES
39 | INPUT_COMPLETE_HOSTNAMES | INPUT_COMPLETE_VARIABLES | INPUT_COMPLETE_USERNAMES
40 } input_complete_t;
42 /*** structures declarations (and typedefs of structures)*****************************************/
44 typedef int input_colors_t[WINPUTC_COUNT_COLORS];
46 typedef struct
48 Widget widget;
49 input_colors_t color;
50 int point; /* cursor position in the input line in characters */
51 int mark; /* the mark position in characters */
52 gboolean highlight; /* there is a selected block */
53 int term_first_shown; /* column of the first shown character */
54 size_t current_max_size; /* maximum length of input line (bytes) */
55 int field_width; /* width of the editing field */
56 gboolean first; /* is first keystroke? */
57 int disable_update; /* do we want to skip updates? */
58 gboolean is_password; /* is this a password input line? */
59 char *init_text; /* initial text of input line */
60 char *buffer; /* pointer to editing buffer */
61 char *history_name; /* name of history for loading and saving */
62 GList *history; /* the history */
63 GList *history_current; /* current history item */
64 gboolean history_changed; /* the history has changed */
65 gboolean need_push; /* need to push the current Input on hist? */
66 gboolean strip_password; /* need to strip password before placing string to history */
67 char **completions; /* possible completions array */
68 input_complete_t completion_flags;
69 char charbuf[MB_LEN_MAX]; /* buffer for multibytes characters */
70 size_t charpoint; /* point to end of mulibyte sequence in charbuf */
71 WLabel *label; /* label associated with this input line*/
72 } WInput;
74 /*** global variables defined in .c file *********************************************************/
76 extern int quote;
78 extern const global_keymap_t *input_map;
80 /*** declarations of public functions ************************************************************/
82 WInput *input_new (int y, int x, const int *input_colors,
83 int len, const char *text, const char *histname,
84 input_complete_t completion_flags);
85 /* callbac is public; needed for command line */
86 cb_ret_t input_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
87 const int *input_get_default_colors (void);
88 void input_set_origin (WInput * i, int x, int field_width);
89 cb_ret_t input_handle_char (WInput * in, int key);
90 int input_key_is_in_map (WInput * in, int key);
91 void input_assign_text (WInput * in, const char *text);
92 void input_insert (WInput * in, const char *text, gboolean insert_extra_space);
93 void input_set_point (WInput * in, int pos);
94 void input_update (WInput * in, gboolean clear_first);
95 void input_enable_update (WInput * in);
96 void input_disable_update (WInput * in);
97 void input_clean (WInput * in);
98 void input_free_completions (WInput * in);
100 /*** inline functions ****************************************************************************/
102 #endif /* MC__WIDGET_INPUT_H */