listbox.h 2.8 KB

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