listbox.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. void listbox_get_current (WListbox * l, char **string, void **extra);
  56. WLEntry *listbox_get_nth_item (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, GList * list);
  61. void listbox_remove_list (WListbox * l);
  62. char *listbox_add_item (WListbox * l, listbox_append_t pos, int hotkey, const char *text,
  63. void *data, gboolean free_data);
  64. /*** inline functions ****************************************************************************/
  65. #endif /* MC__WIDGET_LISTBOX_H */