88424848b75c35ef904eab06065897cd203536e4
[midnight-commander.git] / lib / widget / listbox.h
blob88424848b75c35ef904eab06065897cd203536e4
2 /** \file listbox.h
3 * \brief Header: WListbox widget
4 */
6 #ifndef MC__WIDGET_LISTBOX_H
7 #define MC__WIDGET_LISTBOX_H
9 #include "lib/keybind.h" /* global_keymap_t */
11 /*** typedefs(not structures) and defined constants **********************************************/
13 /*** enums ***************************************************************************************/
15 /* callback should return one of the following values */
16 typedef enum
18 LISTBOX_CONT, /* continue */
19 LISTBOX_DONE /* finish dialog */
20 } lcback_ret_t;
22 typedef enum
24 LISTBOX_APPEND_AT_END = 0, /* append at the end */
25 LISTBOX_APPEND_BEFORE, /* insert before current */
26 LISTBOX_APPEND_AFTER, /* insert after current */
27 LISTBOX_APPEND_SORTED /* insert alphabetically */
28 } listbox_append_t;
30 /*** structures declarations (and typedefs of structures)*****************************************/
32 struct WListbox;
33 typedef lcback_ret_t (*lcback_fn) (struct WListbox * l);
35 typedef struct WLEntry
37 char *text; /* Text to display */
38 int hotkey;
39 void *data; /* Client information */
40 } WLEntry;
42 typedef struct WListbox
44 Widget widget;
45 GList *list; /* Pointer to the double linked list */
46 int pos; /* The current element displayed */
47 int top; /* The first element displayed */
48 int count; /* Number of items in the listbox */
49 gboolean allow_duplicates; /* Do we allow duplicates on the list? */
50 gboolean scrollbar; /* Draw a scrollbar? */
51 gboolean deletable; /* Can list entries be deleted? */
52 lcback_fn callback; /* The callback function */
53 int cursor_x, cursor_y; /* Cache the values */
54 } WListbox;
56 /*** global variables defined in .c file *********************************************************/
58 extern const global_keymap_t *listbox_map;
60 /*** declarations of public functions ************************************************************/
62 WListbox *listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn callback);
63 int listbox_search_text (WListbox * l, const char *text);
64 void listbox_select_first (WListbox * l);
65 void listbox_select_last (WListbox * l);
66 void listbox_select_entry (WListbox * l, int dest);
67 void listbox_get_current (WListbox * l, char **string, void **extra);
68 void listbox_remove_current (WListbox * l);
69 void listbox_set_list (WListbox * l, GList * list);
70 void listbox_remove_list (WListbox * l);
71 char *listbox_add_item (WListbox * l, listbox_append_t pos,
72 int hotkey, const char *text, void *data);
74 /*** inline functions ****************************************************************************/
76 #endif /* MC__WIDGET_LISTBOX_H */