From 482d1315104091a88d616d584718d39ce50a1b64 Mon Sep 17 00:00:00 2001 From: williameveretteggplant <44709277+williameveretteggplant@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:19:16 -0600 Subject: [PATCH 1/3] Remove GSFakeNSMenuItem class This class doesn't appear to do anything but serve as a pass-through for the original object, so why not just use that? --- WinNSMenu.m | 87 +---------------------------------------------------- 1 file changed, 1 insertion(+), 86 deletions(-) diff --git a/WinNSMenu.m b/WinNSMenu.m index 748a231..8ddd750 100644 --- a/WinNSMenu.m +++ b/WinNSMenu.m @@ -38,86 +38,6 @@ static NSLock *menuLock = nil; -@interface GSFakeNSMenuItem : NSObject -{ - id _originalItem; -} - -- (id) initWithItem: (id)item; -- (id) originalItem; -- (id) target; -- (SEL)action; -- (void) action: (id)sender; -@end - -@implementation GSFakeNSMenuItem -- (id) initWithItem: (id)item -{ - self = [super init]; - if (self) - { - _originalItem = item; - } - return self; -} - -- (id) originalItem -{ - return _originalItem; -} - -- (id)target -{ - return self; -} - -- (SEL)action -{ - return @selector(action:); -} - -- (void) action: (id)sender -{ - NSMenu *theMenu = [_originalItem menu]; - [theMenu performActionForItemAtIndex:[theMenu indexOfItem:_originalItem]]; -} - -#ifndef GNUSTEP -#pragma mark - -#pragma mark Act as proxy for actual NSMenuItem methods... -#endif -- (id)forwardingTargetForSelector:(SEL)selector -{ - if ([_originalItem respondsToSelector:selector]) - return _originalItem; - return nil; -} - -- (void)forwardInvocation:(NSInvocation *)invocation -{ - SEL selector = [invocation selector]; - - // Forward any invocation to the original item if it supports it... - if ([_originalItem respondsToSelector:selector]) - [invocation invokeWithTarget:_originalItem]; -} - --(NSMethodSignature*)methodSignatureForSelector:(SEL)selector -{ - NSMethodSignature *signature = [[_originalItem class] instanceMethodSignatureForSelector:selector]; - if(signature == nil) - { - signature = [NSMethodSignature signatureWithObjCTypes:"@^v^c"]; - } - return(signature); -} - -- (void)doesNotRecognizeSelector:(SEL)selector -{ - NSLog(@"%s:selector not recognized: %@", __PRETTY_FUNCTION__, NSStringFromSelector(selector)); -} -@end - @interface NSWindow (WinMenuPrivate) - (GSWindowDecorationView *) windowView; - (void) _setMenu: (NSMenu *) menu; @@ -271,11 +191,6 @@ HMENU r_build_menu_for_itemmap(NSMenu *menu, BOOL asPopUp, BOOL fakeItem, NSMapT { flags = MF_STRING; s = menu_tag++; - if(fakeItem) - { - item = [[GSFakeNSMenuItem alloc] initWithItem: item]; - AUTORELEASE(item); - } NSMapInsert(itemMap, (const void *)s, item); } @@ -348,7 +263,7 @@ HMENU r_build_menu_for_itemmap(NSMenu *menu, BOOL asPopUp, BOOL fakeItem, NSMapT // For PopUpButtons we don't set the flag on the state but on selection if (fakeItem && asPopUp) { - if ([(GSFakeNSMenuItem *)item originalItem] == [[menu _owningPopUp] selectedItem]) + if (item == [[menu _owningPopUp] selectedItem]) { flags |= MF_CHECKED; } From 090a130a524654af0fb1a44b094d47735856b971 Mon Sep 17 00:00:00 2001 From: williameveretteggplant <44709277+williameveretteggplant@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:46:10 -0600 Subject: [PATCH 2/3] Set default action for Menu items in popup --- WinNSMenu.m | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/WinNSMenu.m b/WinNSMenu.m index 8ddd750..e2da02a 100644 --- a/WinNSMenu.m +++ b/WinNSMenu.m @@ -71,7 +71,7 @@ void initialize_lock() } // find all subitems for the given items... -HMENU r_build_menu_for_itemmap(NSMenu *menu, BOOL asPopUp, BOOL fakeItem, NSMapTable *itemMap) +HMENU r_build_menu_for_itemmap(NSMenu *menu, BOOL asPopUp, BOOL notPullDown, NSMapTable *itemMap) { NSArray *array = [menu itemArray]; NSEnumerator *en = [array objectEnumerator]; @@ -181,7 +181,7 @@ HMENU r_build_menu_for_itemmap(NSMenu *menu, BOOL asPopUp, BOOL fakeItem, NSMapT { NSMenu *smenu = [item submenu]; flags = MF_STRING | MF_POPUP; - s = (UINT)r_build_menu_for_itemmap(smenu, asPopUp, fakeItem, itemMap); + s = (UINT)r_build_menu_for_itemmap(smenu, asPopUp, notPullDown, itemMap); } else if([item isSeparatorItem]) { @@ -191,6 +191,15 @@ HMENU r_build_menu_for_itemmap(NSMenu *menu, BOOL asPopUp, BOOL fakeItem, NSMapT { flags = MF_STRING; s = menu_tag++; + if (([item action] == NULL || [item target] == nil) && notPullDown && asPopUp) + { + NSPopUpButtonCell *popup = [menu _owningPopUp]; + if (popup != nil) + { + [item setAction: @selector(_popUpItemAction:)]; + [item setTarget: popup]; + } + } NSMapInsert(itemMap, (const void *)s, item); } @@ -261,7 +270,7 @@ HMENU r_build_menu_for_itemmap(NSMenu *menu, BOOL asPopUp, BOOL fakeItem, NSMapT { flags |= MF_ENABLED; // ([item isEnabled]?MF_ENABLED:MF_GRAYED); // shouldn't this be :MF_GRAYED|MF_DISABLED ? // For PopUpButtons we don't set the flag on the state but on selection - if (fakeItem && asPopUp) + if (notPullDown && asPopUp) { if (item == [[menu _owningPopUp] selectedItem]) { @@ -279,9 +288,9 @@ HMENU r_build_menu_for_itemmap(NSMenu *menu, BOOL asPopUp, BOOL fakeItem, NSMapT return result; } -HMENU r_build_menu(NSMenu *menu, BOOL asPopup, BOOL fakeItem) +HMENU r_build_menu(NSMenu *menu, BOOL asPopup, BOOL notPullDown) { - return r_build_menu_for_itemmap(menu, asPopup, fakeItem, itemMap); + return r_build_menu_for_itemmap(menu, asPopup, notPullDown, itemMap); } void build_menu(HWND win) From 0201ed3280858f7bc2da60493d8f6db17cd7e27a Mon Sep 17 00:00:00 2001 From: williameveretteggplant <44709277+williameveretteggplant@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:59:39 -0600 Subject: [PATCH 3/3] rename fake variable --- WinNSMenu.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WinNSMenu.m b/WinNSMenu.m index e2da02a..cdd27f2 100644 --- a/WinNSMenu.m +++ b/WinNSMenu.m @@ -466,7 +466,7 @@ - (void) displayPopUpMenu: (NSMenuView *)mr preferredEdge: (NSRectEdge)edge selectedItem: (int)selectedItem { - BOOL fake = NO; + BOOL notPullDown = NO; NSMenu *menu = [mr menu]; // Need menu for display... @@ -475,7 +475,7 @@ - (void) displayPopUpMenu: (NSMenuView *)mr NSPopUpButtonCell *cell = [menu _owningPopUp]; if (cell) - fake = ![cell pullsDown]; + notPullDown = ![cell pullsDown]; // Create a temporary item map for this popup sequence... NSMapTable *itemMap = NSCreateMapTable(NSIntMapKeyCallBacks, @@ -483,7 +483,7 @@ - (void) displayPopUpMenu: (NSMenuView *)mr [menu update]; - HMENU hmenu = r_build_menu_for_itemmap(menu, YES, fake, itemMap); + HMENU hmenu = r_build_menu_for_itemmap(menu, YES, notPullDown, itemMap); NSWindow *theWin = ((cvWin == nil) ? [NSApp mainWindow] : cvWin); HWND win = (HWND)[theWin windowNumber]; NSPoint point = cellFrame.origin;