Skip to content

Commit e94700f

Browse files
committed
Fix type conversions for menu and positioning APIs
Corrects type casting for menu item and menu IDs in C++ and Objective-C code, ensuring proper interoperability between native and C API layers. Also updates struct namespace usage in positioning strategy functions and clarifies a parameter name in menu.h documentation.
1 parent 7b3b72d commit e94700f

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/capi/menu_c.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ bool native_menu_remove_item_by_id(native_menu_t menu, native_menu_item_id_t ite
710710

711711
try {
712712
auto menu_ptr = static_cast<Menu*>(menu);
713-
return menu_ptr->RemoveItemById(item_id);
713+
return menu_ptr->RemoveItemById(static_cast<MenuItemId>(item_id));
714714
} catch (...) {
715715
return false;
716716
}
@@ -795,7 +795,7 @@ native_menu_item_t native_menu_get_item_by_id(native_menu_t menu, native_menu_it
795795

796796
try {
797797
auto menu_ptr = static_cast<Menu*>(menu);
798-
auto item = menu_ptr->GetItemById(item_id);
798+
auto item = menu_ptr->GetItemById(static_cast<MenuItemId>(item_id));
799799
return item ? static_cast<native_menu_item_t>(item.get()) : nullptr;
800800
} catch (...) {
801801
return nullptr;

src/capi/positioning_strategy_c.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ native_positioning_strategy_t native_positioning_strategy_absolute(const native_
1010
return nullptr;
1111
}
1212

13-
Point cpp_point{point->x, point->y};
13+
nativeapi::Point cpp_point{point->x, point->y};
1414
PositioningStrategy* strategy = new PositioningStrategy(PositioningStrategy::Absolute(cpp_point));
1515
return static_cast<native_positioning_strategy_t>(strategy);
1616
}
@@ -26,10 +26,10 @@ native_positioning_strategy_t native_positioning_strategy_relative(const native_
2626
return nullptr;
2727
}
2828

29-
Rectangle cpp_rect{rect->x, rect->y, rect->width, rect->height};
30-
Point cpp_offset{0, 0};
29+
nativeapi::Rectangle cpp_rect{rect->x, rect->y, rect->width, rect->height};
30+
nativeapi::Point cpp_offset{0, 0};
3131
if (offset) {
32-
cpp_offset = Point{offset->x, offset->y};
32+
cpp_offset = nativeapi::Point{offset->x, offset->y};
3333
}
3434

3535
PositioningStrategy* strategy =

src/menu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class MenuItem : public EventEmitter<MenuEvent>, public NativeObjectProvider {
184184
*
185185
* Creates a menu item of the specified type with the given text.
186186
*
187-
* @param text The display text for the menu item
187+
* @param label The display text for the menu item
188188
* @param type The type of menu item to create
189189
*
190190
* @example

src/platform/macos/application_macos.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ bool SetMenuBar(std::shared_ptr<Menu> menu) {
139139
}
140140

141141
// Get the native menu handle
142-
NSMenu* ns_menu = static_cast<NSMenu*>(menu->GetNativeObject());
142+
NSMenu* ns_menu = (__bridge NSMenu*)(menu->GetNativeObject());
143143
if (!ns_menu) {
144144
return false;
145145
}

src/platform/macos/menu_macos.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ - (void)menuItemClicked:(id)sender {
128128
// Get the MenuItemId from the menu item's associated object
129129
NSNumber* item_id_obj = objc_getAssociatedObject(menu_item, kMenuItemIdKey);
130130
if (item_id_obj) {
131-
nativeapi::MenuItemId item_id = [item_id_obj longValue];
131+
nativeapi::MenuItemId item_id = static_cast<nativeapi::MenuItemId>([item_id_obj longValue]);
132132
_clickedBlock(item_id);
133133
}
134134
}
@@ -151,7 +151,7 @@ - (void)menuWillOpen:(NSMenu*)menu {
151151
// Get the MenuId from the menu's associated object
152152
NSNumber* menu_id_obj = objc_getAssociatedObject(menu, kMenuIdKey);
153153
if (menu_id_obj) {
154-
nativeapi::MenuId menu_id = [menu_id_obj longValue];
154+
nativeapi::MenuId menu_id = static_cast<nativeapi::MenuId>([menu_id_obj longValue]);
155155
_openedBlock(menu_id);
156156
}
157157
}
@@ -170,7 +170,7 @@ - (void)menuDidClose:(NSMenu*)menu {
170170
// Get the MenuId from the menu's associated object
171171
NSNumber* menu_id_obj = objc_getAssociatedObject(menu, kMenuIdKey);
172172
if (menu_id_obj) {
173-
nativeapi::MenuId menu_id = [menu_id_obj longValue];
173+
nativeapi::MenuId menu_id = static_cast<nativeapi::MenuId>([menu_id_obj longValue]);
174174
_closedBlock(menu_id);
175175
}
176176
}

0 commit comments

Comments
 (0)