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. /*** typedefs(not structures) and defined constants **********************************************/
  7. #define LISTBOX(x) ((WListbox *) (x))
  8. #define LENTRY(x) ((WLEntry *) (x))
  9. /*** enums ***************************************************************************************/
  10. /* callback should return one of the following values */
  11. typedef enum
  12. {
  13. LISTBOX_CONT, /* continue */
  14. LISTBOX_DONE /* finish dialog */
  15. } lcback_ret_t;
  16. typedef enum
  17. {
  18. LISTBOX_APPEND_AT_END = 0, /* append at the end */
  19. LISTBOX_APPEND_BEFORE, /* insert before current */
  20. LISTBOX_APPEND_AFTER, /* insert after current */
  21. LISTBOX_APPEND_SORTED /* insert alphabetically */
  22. } listbox_append_t;
  23. /*** structures declarations (and typedefs of structures)*****************************************/
  24. struct WListbox;
  25. typedef lcback_ret_t (*lcback_fn) (struct WListbox *l);
  26. typedef struct WLEntry
  27. {
  28. char *text; /* Text to display */
  29. int hotkey;
  30. void *data; /* Client information */
  31. gboolean free_data; /* Whether to free the data on entry's removal */
  32. } WLEntry;
  33. typedef struct WListbox
  34. {
  35. Widget widget;
  36. GQueue *list; /* Pointer to the list of WLEntry */
  37. int top; /* The first element displayed */
  38. int current; /* The current 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. int listbox_search_data (WListbox *l, const void *data);
  51. void listbox_select_first (WListbox *l);
  52. void listbox_select_last (WListbox *l);
  53. void listbox_set_current (WListbox *l, int dest);
  54. int listbox_get_length (const WListbox *l);
  55. void listbox_get_current (WListbox *l, char **string, void **extra);
  56. WLEntry *listbox_get_nth_entry (const WListbox *l, int pos);
  57. GList *listbox_get_first_link (const WListbox *l);
  58. void listbox_remove_current (WListbox *l);
  59. gboolean listbox_is_empty (const WListbox *l);
  60. void listbox_set_list (WListbox *l, GQueue *list);
  61. void listbox_remove_list (WListbox *l);
  62. char *listbox_add_item (WListbox *l, listbox_append_t pos, int hotkey, const char *text, void *data,
  63. gboolean free_data);
  64. char *listbox_add_item_take (WListbox *l, listbox_append_t pos, int hotkey, char *text, void *data,
  65. gboolean free_data);
  66. /*** inline functions ****************************************************************************/
  67. #endif /* MC__WIDGET_LISTBOX_H */