menu.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * File : view.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-16 Bernard first version
  13. */
  14. #ifndef __RTGUI_MENU_H__
  15. #define __RTGUI_MENU_H__
  16. #include <rtgui/rtgui.h>
  17. #include <rtgui/image.h>
  18. #include <rtgui/widgets/widget.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. typedef int HMENU;
  23. #define RTGUI_MENU_HEIGHT 43 /*菜单项高度*/
  24. #define RTGUI_MENU_BORDER 2
  25. #define RTGUI_MENU_IMAGE_W 24
  26. #define RTGUI_MENU_IMAGE_H 24
  27. #define ITEM (System,Name,ID) \
  28. rtgui_menu_append(hPopupMenu_##System, MF_ENABLED, ID, Name);
  29. /*菜单项标志*/
  30. #define RTGUI_MENU_POPUP 0x00000080L
  31. typedef struct rtgui_menu_item rtgui_menu_item_t; //普通菜单
  32. typedef struct rtgui_menu rtgui_menu_t;//菜单
  33. /** Gets the type of a view */
  34. #define RTGUI_MENU_TYPE (rtgui_menu_type_get())
  35. /** Casts the object to an rtgui_view_t */
  36. #define RTGUI_MENU(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_MENU_TYPE, rtgui_menu_t))
  37. /** Checks if the object is an rtgui_view_t */
  38. #define RTGUI_IS_MENU(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_MENU_TYPE))
  39. struct rtgui_menu
  40. {
  41. rtgui_widget_t parent;
  42. char* name;
  43. /* 用于辅助绘图的参数,如果无需绘图,去掉这些参数没有影响 */
  44. rt_uint32_t orient; /* 排列方向 */
  45. rt_uint32_t item_size; /* 菜单项尺寸 */
  46. rt_uint16_t item_count; /* 菜单项数 */
  47. rtgui_menu_item_t* current_item; /* 当前的菜单项 */
  48. rtgui_menu_item_t* forego_item; /* 上一个菜单项 */
  49. /*下级菜单项 */
  50. rtgui_menu_item_t* head; /*头*/
  51. rtgui_menu_item_t* tail; /*尾*/
  52. /*上级菜单项 */
  53. rtgui_menu_item_t* farther;
  54. };
  55. struct rtgui_menu_item
  56. {
  57. char* caption; //菜单名
  58. rt_uint32_t item_id;
  59. rt_uint32_t type; //菜单的创建类型
  60. rt_uint32_t shortcut;
  61. rt_bool_t bexit; //调用该菜单后,是否退出菜单
  62. rtgui_menu_item_t* next;
  63. rtgui_menu_item_t* prev;
  64. rtgui_image_t* image; //绑定的图标
  65. rtgui_menu_t* sub_menu; //子菜单
  66. void(*func_updown)(rtgui_menu_t *menu); //在UP/DOWN动作之后运行的函数
  67. void(*func_enter)(void); //在确认后执行的函数
  68. };
  69. rtgui_type_t *rtgui_menu_type_get(void);
  70. rtgui_menu_t* rtgui_menu_create(PVOID parent, const char* name);
  71. void rtgui_menu_destroy(rtgui_menu_t* menu);
  72. HMENU rtgui_menu_popup_create (void);
  73. rt_bool_t rtgui_menu_append(rtgui_menu_t *menu,rt_uint32_t flags,rt_uint32_t ID,char * caption);
  74. void rtgui_menu_popup_delete(rtgui_menu_t* menu);
  75. rtgui_menu_t* rtgui_menu_item_delete(rtgui_menu_t* menu,rtgui_menu_item_t* pItem);
  76. void rtgui_menu_on_down(rtgui_menu_t* menu);
  77. void rtgui_menu_on_up(rtgui_menu_t* menu);
  78. void rtgui_menu_on_exit(rtgui_menu_t* menu);
  79. void rtgui_menu_set_selected(rtgui_menu_t* menu, int selected);
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #endif