88#include " event_emitter.h"
99#include " geometry.h"
1010#include " menu_event.h"
11+ #include " foundation/native_object_provider.h"
1112
1213namespace nativeapi {
1314
@@ -156,20 +157,22 @@ class Menu;
156157 * auto item = MenuItem::Create("Open File", MenuItemType::Normal);
157158 * item->SetIcon("data:image/png;base64,...");
158159 * item->SetAccelerator(KeyboardAccelerator("O", KeyboardAccelerator::Ctrl));
159- * item->AddListener<MenuItemClickedEvent>([](const MenuItemClickedEvent& event) {
160+ * item->AddListener<MenuItemClickedEvent>([](const MenuItemClickedEvent& event)
161+ * {
160162 * // Handle menu item click
161163 * std::cout << "Opening file..." << std::endl;
162164 * });
163165 *
164166 * // Create a checkbox item
165167 * auto checkbox = MenuItem::Create("Show Toolbar", MenuItemType::Checkbox);
166168 * checkbox->SetChecked(true);
167- * checkbox->AddListener<MenuItemClickedEvent>([](const MenuItemClickedEvent& event) {
168- * std::cout << "Toolbar clicked, handle state change manually" << std::endl;
169+ * checkbox->AddListener<MenuItemClickedEvent>([](const MenuItemClickedEvent&
170+ * event) { std::cout << "Toolbar clicked, handle state change manually" <<
171+ * std::endl;
169172 * });
170173 * ```
171174 */
172- class MenuItem : public EventEmitter {
175+ class MenuItem : public EventEmitter , public NativeObjectProvider {
173176 public:
174177 /* *
175178 * @brief Factory method to create a new menu item.
@@ -435,7 +438,6 @@ class MenuItem : public EventEmitter {
435438 */
436439 void RemoveSubmenu ();
437440
438-
439441 /* *
440442 * @brief Programmatically trigger this menu item.
441443 *
@@ -446,17 +448,6 @@ class MenuItem : public EventEmitter {
446448 */
447449 bool Trigger ();
448450
449- /* *
450- * @brief Get the native platform-specific menu item object.
451- *
452- * This method provides access to the underlying platform-specific
453- * menu item for advanced use cases. Use with caution as this breaks
454- * the abstraction layer.
455- *
456- * @return Pointer to the native menu item object
457- */
458- void * GetNativeObject () const ;
459-
460451 /* *
461452 * @brief Emit a menu item selected event.
462453 *
@@ -477,6 +468,17 @@ class MenuItem : public EventEmitter {
477468 */
478469 void EmitStateChangedEvent (bool checked);
479470
471+ protected:
472+ /* *
473+ * @brief Internal method to get the platform-specific native menu item object.
474+ *
475+ * This method must be implemented by platform-specific code to return
476+ * the underlying native menu item object.
477+ *
478+ * @return Pointer to the native menu item object
479+ */
480+ void * GetNativeObjectInternal () const override ;
481+
480482 private:
481483 friend class Menu ;
482484
@@ -546,7 +548,7 @@ class MenuItem : public EventEmitter {
546548 * fileMenu->ShowAsContextMenu(100, 100);
547549 * ```
548550 */
549- class Menu : public EventEmitter {
551+ class Menu : public EventEmitter , public NativeObjectProvider {
550552 public:
551553 /* *
552554 * @brief Factory method to create a new menu.
@@ -770,7 +772,6 @@ class Menu : public EventEmitter {
770772 */
771773 bool IsEnabled () const ;
772774
773-
774775 /* *
775776 * @brief Create a standard menu item and add it to the menu.
776777 *
@@ -807,17 +808,6 @@ class Menu : public EventEmitter {
807808 std::shared_ptr<MenuItem> CreateAndAddSubmenu (const std::string& text,
808809 std::shared_ptr<Menu> submenu);
809810
810- /* *
811- * @brief Get the native platform-specific menu object.
812- *
813- * This method provides access to the underlying platform-specific
814- * menu for advanced use cases. Use with caution as this breaks
815- * the abstraction layer.
816- *
817- * @return Pointer to the native menu object
818- */
819- void * GetNativeObject () const ;
820-
821811 /* *
822812 * @brief Emit a menu opened event.
823813 *
@@ -834,6 +824,17 @@ class Menu : public EventEmitter {
834824 */
835825 void EmitClosedEvent ();
836826
827+ protected:
828+ /* *
829+ * @brief Internal method to get the platform-specific native menu object.
830+ *
831+ * This method must be implemented by platform-specific code to return
832+ * the underlying native menu object.
833+ *
834+ * @return Pointer to the native menu object
835+ */
836+ void * GetNativeObjectInternal () const override ;
837+
837838 private:
838839 /* *
839840 * @brief Private constructor for factory methods.
0 commit comments