native_menu_windows.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**************************************************************************/
  2. /* native_menu_windows.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef NATIVE_MENU_WINDOWS_H
  31. #define NATIVE_MENU_WINDOWS_H
  32. #include "core/io/image.h"
  33. #include "core/templates/hash_map.h"
  34. #include "core/templates/rid_owner.h"
  35. #include "servers/display/native_menu.h"
  36. #define WIN32_LEAN_AND_MEAN
  37. #include <windows.h>
  38. class NativeMenuWindows : public NativeMenu {
  39. GDCLASS(NativeMenuWindows, NativeMenu)
  40. enum GlobalMenuCheckType {
  41. CHECKABLE_TYPE_NONE,
  42. CHECKABLE_TYPE_CHECK_BOX,
  43. CHECKABLE_TYPE_RADIO_BUTTON,
  44. };
  45. struct MenuItemData {
  46. Callable callback;
  47. Variant meta;
  48. GlobalMenuCheckType checkable_type;
  49. bool checked = false;
  50. int max_states = 0;
  51. int state = 0;
  52. Ref<Image> img;
  53. HBITMAP bmp = 0;
  54. };
  55. struct MenuData {
  56. HMENU menu = 0;
  57. bool is_rtl = false;
  58. };
  59. mutable RID_PtrOwner<MenuData> menus;
  60. HashMap<HMENU, RID> menu_lookup;
  61. HBITMAP _make_bitmap(const Ref<Image> &p_img) const;
  62. public:
  63. void _menu_activate(HMENU p_menu, int p_index) const;
  64. virtual bool has_feature(Feature p_feature) const override;
  65. virtual bool has_system_menu(SystemMenus p_menu_id) const override;
  66. virtual RID get_system_menu(SystemMenus p_menu_id) const override;
  67. virtual RID create_menu() override;
  68. virtual bool has_menu(const RID &p_rid) const override;
  69. virtual void free_menu(const RID &p_rid) override;
  70. virtual Size2 get_size(const RID &p_rid) const override;
  71. virtual void popup(const RID &p_rid, const Vector2i &p_position) override;
  72. virtual void set_interface_direction(const RID &p_rid, bool p_is_rtl) override;
  73. virtual void set_popup_open_callback(const RID &p_rid, const Callable &p_callback) override;
  74. virtual Callable get_popup_open_callback(const RID &p_rid) const override;
  75. virtual void set_popup_close_callback(const RID &p_rid, const Callable &p_callback) override;
  76. virtual Callable get_popup_close_callback(const RID &p_rid) const override;
  77. virtual void set_minimum_width(const RID &p_rid, float p_width) override;
  78. virtual float get_minimum_width(const RID &p_rid) const override;
  79. virtual bool is_opened(const RID &p_rid) const override;
  80. virtual int add_submenu_item(const RID &p_rid, const String &p_label, const RID &p_submenu_rid, const Variant &p_tag = Variant(), int p_index = -1) override;
  81. virtual int add_item(const RID &p_rid, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1) override;
  82. virtual int add_check_item(const RID &p_rid, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1) override;
  83. virtual int add_icon_item(const RID &p_rid, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1) override;
  84. virtual int add_icon_check_item(const RID &p_rid, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1) override;
  85. virtual int add_radio_check_item(const RID &p_rid, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1) override;
  86. virtual int add_icon_radio_check_item(const RID &p_rid, const Ref<Texture2D> &p_icon, const String &p_label, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1) override;
  87. virtual int add_multistate_item(const RID &p_rid, const String &p_label, int p_max_states, int p_default_state, const Callable &p_callback = Callable(), const Callable &p_key_callback = Callable(), const Variant &p_tag = Variant(), Key p_accel = Key::NONE, int p_index = -1) override;
  88. virtual int add_separator(const RID &p_rid, int p_index = -1) override;
  89. virtual int find_item_index_with_text(const RID &p_rid, const String &p_text) const override;
  90. virtual int find_item_index_with_tag(const RID &p_rid, const Variant &p_tag) const override;
  91. virtual bool is_item_checked(const RID &p_rid, int p_idx) const override;
  92. virtual bool is_item_checkable(const RID &p_rid, int p_idx) const override;
  93. virtual bool is_item_radio_checkable(const RID &p_rid, int p_idx) const override;
  94. virtual Callable get_item_callback(const RID &p_rid, int p_idx) const override;
  95. virtual Callable get_item_key_callback(const RID &p_rid, int p_idx) const override;
  96. virtual Variant get_item_tag(const RID &p_rid, int p_idx) const override;
  97. virtual String get_item_text(const RID &p_rid, int p_idx) const override;
  98. virtual RID get_item_submenu(const RID &p_rid, int p_idx) const override;
  99. virtual Key get_item_accelerator(const RID &p_rid, int p_idx) const override;
  100. virtual bool is_item_disabled(const RID &p_rid, int p_idx) const override;
  101. virtual bool is_item_hidden(const RID &p_rid, int p_idx) const override;
  102. virtual String get_item_tooltip(const RID &p_rid, int p_idx) const override;
  103. virtual int get_item_state(const RID &p_rid, int p_idx) const override;
  104. virtual int get_item_max_states(const RID &p_rid, int p_idx) const override;
  105. virtual Ref<Texture2D> get_item_icon(const RID &p_rid, int p_idx) const override;
  106. virtual int get_item_indentation_level(const RID &p_rid, int p_idx) const override;
  107. virtual void set_item_checked(const RID &p_rid, int p_idx, bool p_checked) override;
  108. virtual void set_item_checkable(const RID &p_rid, int p_idx, bool p_checkable) override;
  109. virtual void set_item_radio_checkable(const RID &p_rid, int p_idx, bool p_checkable) override;
  110. virtual void set_item_callback(const RID &p_rid, int p_idx, const Callable &p_callback) override;
  111. virtual void set_item_key_callback(const RID &p_rid, int p_idx, const Callable &p_key_callback) override;
  112. virtual void set_item_hover_callbacks(const RID &p_rid, int p_idx, const Callable &p_callback) override;
  113. virtual void set_item_tag(const RID &p_rid, int p_idx, const Variant &p_tag) override;
  114. virtual void set_item_text(const RID &p_rid, int p_idx, const String &p_text) override;
  115. virtual void set_item_submenu(const RID &p_rid, int p_idx, const RID &p_submenu_rid) override;
  116. virtual void set_item_accelerator(const RID &p_rid, int p_idx, Key p_keycode) override;
  117. virtual void set_item_disabled(const RID &p_rid, int p_idx, bool p_disabled) override;
  118. virtual void set_item_hidden(const RID &p_rid, int p_idx, bool p_hidden) override;
  119. virtual void set_item_tooltip(const RID &p_rid, int p_idx, const String &p_tooltip) override;
  120. virtual void set_item_state(const RID &p_rid, int p_idx, int p_state) override;
  121. virtual void set_item_max_states(const RID &p_rid, int p_idx, int p_max_states) override;
  122. virtual void set_item_icon(const RID &p_rid, int p_idx, const Ref<Texture2D> &p_icon) override;
  123. virtual void set_item_indentation_level(const RID &p_rid, int p_idx, int p_level) override;
  124. virtual int get_item_count(const RID &p_rid) const override;
  125. virtual bool is_system_menu(const RID &p_rid) const override;
  126. virtual void remove_item(const RID &p_rid, int p_idx) override;
  127. virtual void clear(const RID &p_rid) override;
  128. NativeMenuWindows();
  129. ~NativeMenuWindows();
  130. };
  131. #endif // NATIVE_MENU_WINDOWS_H