Add useful macros for widget type cast.
[midnight-commander.git] / lib / widget / listbox.h
blobeee50b7c92031771478a7bd602db1e357c6133ce
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 #define LISTBOX(x) ((WListbox *)(x))
14 #define LENTRY(x) ((WLEntry *)(x))
16 /*** enums ***************************************************************************************/
18 /* callback should return one of the following values */
19 typedef enum
21 LISTBOX_CONT, /* continue */
22 LISTBOX_DONE /* finish dialog */
23 } lcback_ret_t;
25 typedef enum
27 LISTBOX_APPEND_AT_END = 0, /* append at the end */
28 LISTBOX_APPEND_BEFORE, /* insert before current */
29 LISTBOX_APPEND_AFTER, /* insert after current */
30 LISTBOX_APPEND_SORTED /* insert alphabetically */
31 } listbox_append_t;
33 /*** structures declarations (and typedefs of structures)*****************************************/
35 struct WListbox;
36 typedef lcback_ret_t (*lcback_fn) (struct WListbox * l);
38 typedef struct WLEntry
40 char *text; /* Text to display */
41 int hotkey;
42 void *data; /* Client information */
43 } WLEntry;
45 typedef struct WListbox
47 Widget widget;
48 GList *list; /* Pointer to the double linked list */
49 int pos; /* The current element displayed */
50 int top; /* The first element displayed */
51 int count; /* Number of items in the listbox */
52 gboolean allow_duplicates; /* Do we allow duplicates on the list? */
53 gboolean scrollbar; /* Draw a scrollbar? */
54 gboolean deletable; /* Can list entries be deleted? */
55 lcback_fn callback; /* The callback function */
56 int cursor_x, cursor_y; /* Cache the values */
57 } WListbox;
59 /*** global variables defined in .c file *********************************************************/
61 extern const global_keymap_t *listbox_map;
63 /*** declarations of public functions ************************************************************/
65 WListbox *listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn callback);
66 int listbox_search_text (WListbox * l, const char *text);
67 void listbox_select_first (WListbox * l);
68 void listbox_select_last (WListbox * l);
69 void listbox_select_entry (WListbox * l, int dest);
70 void listbox_get_current (WListbox * l, char **string, void **extra);
71 void listbox_remove_current (WListbox * l);
72 void listbox_set_list (WListbox * l, GList * list);
73 void listbox_remove_list (WListbox * l);
74 char *listbox_add_item (WListbox * l, listbox_append_t pos,
75 int hotkey, const char *text, void *data);
77 /*** inline functions ****************************************************************************/
79 #endif /* MC__WIDGET_LISTBOX_H */