menu.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef __RTGUI_MENU_H__
  2. #define __RTGUI_MENU_H__
  3. #include <rtgui/image.h>
  4. #include <rtgui/widgets/window.h>
  5. #include <rtgui/widgets/listctrl.h>
  6. /* rtgui menu item */
  7. enum rtgui_menu_item_type
  8. {
  9. RTGUI_ITEM_NORMAL,
  10. RTGUI_ITEM_CHECK,
  11. RTGUI_ITEM_SUBMENU,
  12. RTGUI_ITEM_SEPARATOR
  13. };
  14. typedef enum rtgui_menu_item_type rtgui_menu_item_type_t;
  15. struct rtgui_menu_item
  16. {
  17. rtgui_menu_item_type_t type;
  18. /* menu text label */
  19. const char* label;
  20. /* menu image */
  21. rtgui_image_t *image;
  22. /* sub-menu item */
  23. const struct rtgui_menu_item_t *submenu;
  24. rt_uint16_t submenu_count;
  25. /* menu action */
  26. rt_bool_t (*on_menuaction)(rtgui_widget_t* widget, rtgui_event_t* event);
  27. };
  28. typedef struct rtgui_menu_item rtgui_menu_item_t;
  29. /** Gets the type of a menu */
  30. #define RTGUI_MENU_TYPE (rtgui_menu_type_get())
  31. /** Casts the object to an rtgui_menu */
  32. #define RTGUI_MENU(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_MENU_TYPE, rtgui_menu_t))
  33. /** Checks if the object is an rtgui_menu */
  34. #define RTGUI_IS_MENU(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_MENU_TYPE))
  35. #define RTGUI_MENU_DEFAULT_WIDTH 100
  36. struct rtgui_menu
  37. {
  38. /* inherited from window */
  39. struct rtgui_win parent;
  40. /* menu items */
  41. const struct rtgui_menu_item *items;
  42. rt_uint16_t items_count;
  43. /* parent menu */
  44. struct rtgui_menu *parent_menu;
  45. struct rtgui_menu *sub_menu;
  46. /* menu item list control */
  47. struct rtgui_listctrl *items_list;
  48. /* pop event handle */
  49. rt_bool_t (*on_menupop)(rtgui_widget_t* widget, rtgui_event_t* event);
  50. rt_bool_t (*on_menuhide)(rtgui_widget_t* widget, rtgui_event_t* event);
  51. };
  52. typedef struct rtgui_menu rtgui_menu_t;
  53. rtgui_type_t *rtgui_menu_type_get(void);
  54. struct rtgui_menu* rtgui_menu_create(const char* title, struct rtgui_menu* parent_menu,
  55. const struct rtgui_menu_item* items, rt_uint16_t count);
  56. void rtgui_menu_destroy(struct rtgui_menu* menu);
  57. void rtgui_menu_set_onmenupop(struct rtgui_menu* menu, rtgui_event_handler_ptr handler);
  58. void rtgui_menu_set_onmenuhide(struct rtgui_menu* menu, rtgui_event_handler_ptr handler);
  59. void rtgui_menu_pop(struct rtgui_menu* menu, int x, int y);
  60. #endif