listbox.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. GQueue *list; /* Pointer to the list of WLEntry */
  37. int pos; /* The current element displayed */
  38. int top; /* The first element displayed */
  39. gboolean allow_duplicates; /* Do we allow duplicates on the list? */
  40. gboolean scrollbar; /* Draw a scrollbar? */
  41. gboolean deletable; /* Can list entries be deleted? */
  42. lcback_fn callback; /* The callback function */
  43. int cursor_x, cursor_y; /* Cache the values */
  44. } WListbox;
  45. /*** global variables defined in .c file *********************************************************/
  46. extern const global_keymap_t *listbox_map;
  47. /*** declarations of public functions ************************************************************/
  48. WListbox *listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn callback);
  49. int listbox_search_text (WListbox * l, const char *text);
  50. void listbox_select_first (WListbox * l);
  51. void listbox_select_last (WListbox * l);
  52. void listbox_select_entry (WListbox * l, int dest);
  53. void listbox_get_current (WListbox * l, char **string, void **extra);
  54. WLEntry *listbox_get_nth_item (const WListbox * l, int pos);
  55. GList *listbox_get_first_link (const WListbox * l);
  56. void listbox_remove_current (WListbox * l);
  57. gboolean listbox_is_empty (const WListbox * l);
  58. void listbox_set_list (WListbox * l, GList * list);
  59. void listbox_remove_list (WListbox * l);
  60. char *listbox_add_item (WListbox * l, listbox_append_t pos,
  61. int hotkey, const char *text, void *data);
  62. /*** inline functions ****************************************************************************/
  63. #endif /* MC__WIDGET_LISTBOX_H */