listbox.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. gboolean free_data; /* Whether to free the data on entry's removal */
  33. } WLEntry;
  34. typedef struct WListbox
  35. {
  36. Widget widget;
  37. GQueue *list; /* Pointer to the list of WLEntry */
  38. int pos; /* The current element displayed */
  39. int top; /* The first element displayed */
  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. int listbox_search_data (WListbox * l, const void *data);
  52. void listbox_select_first (WListbox * l);
  53. void listbox_select_last (WListbox * l);
  54. void listbox_select_entry (WListbox * l, int dest);
  55. int listbox_get_length (const WListbox * l);
  56. void listbox_get_current (WListbox * l, char **string, void **extra);
  57. WLEntry *listbox_get_nth_item (const WListbox * l, int pos);
  58. GList *listbox_get_first_link (const WListbox * l);
  59. void listbox_remove_current (WListbox * l);
  60. gboolean listbox_is_empty (const WListbox * l);
  61. void listbox_set_list (WListbox * l, GQueue * list);
  62. void listbox_remove_list (WListbox * l);
  63. char *listbox_add_item (WListbox * l, listbox_append_t pos, int hotkey, const char *text,
  64. void *data, gboolean free_data);
  65. /*** inline functions ****************************************************************************/
  66. #endif /* MC__WIDGET_LISTBOX_H */