listbox.h 2.7 KB

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