listbox.h 2.8 KB

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