From a98d314ea42c5fe9b87e974b2bced3fbd88338d6 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Sun, 27 Oct 2024 20:57:36 +0100 Subject: [PATCH] Allow themes to override `[NSMenu _isVisible]` The default implementation of `[NSMenu]` uses `_aWindow` and `_bWindow` to determine the visibility of the menu. Not all themes use these windows to build a menu. For example, the WinUXTheme will use Win32 APIs to build a menu. Allow themes to override the value of `[NSMenu _isVisible]` by introducing a `[GSTheme proposedVisibility: (BOOL)visible forMenu: (NSMenu *) menu]` method. The default implementation simply eturns the proposed visibility. --- Headers/Additions/GNUstepGUI/GSTheme.h | 6 ++++++ Source/GSThemeMenu.m | 6 ++++++ Source/NSMenu.m | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Headers/Additions/GNUstepGUI/GSTheme.h b/Headers/Additions/GNUstepGUI/GSTheme.h index a37b6a4f69..54e6d45874 100644 --- a/Headers/Additions/GNUstepGUI/GSTheme.h +++ b/Headers/Additions/GNUstepGUI/GSTheme.h @@ -1569,6 +1569,12 @@ withRepeatedImage: (NSImage*)image - (void) organizeMenu: (NSMenu *)menu isHorizontal: (BOOL)horizontal; +/** + * Used by the theme to override the proposed menu visibility. The default + * implementation simply returns the proposed visibility unmodified. + */ +- (BOOL) proposedVisibility: (BOOL)visible + forMenu: (NSMenu *) menu; @end @interface GSTheme (OpenSavePanels) diff --git a/Source/GSThemeMenu.m b/Source/GSThemeMenu.m index 023d5aaeb3..0480b6dab6 100644 --- a/Source/GSThemeMenu.m +++ b/Source/GSThemeMenu.m @@ -418,5 +418,11 @@ - (void) organizeMenu: (NSMenu *)menu [[menu menuRepresentation] update]; [menu sizeToFit]; } + +- (BOOL) proposedVisibility: (BOOL)visible + forMenu: (NSMenu *) menu +{ + return visible; +} @end diff --git a/Source/NSMenu.m b/Source/NSMenu.m index 61915e42d7..33e1e9c876 100644 --- a/Source/NSMenu.m +++ b/Source/NSMenu.m @@ -383,7 +383,8 @@ - (void) _rightMouseDisplay: (NSEvent*)theEvent - (BOOL) _isVisible { - return [_aWindow isVisible] || [_bWindow isVisible]; + BOOL isVisible = [_aWindow isVisible] || [_bWindow isVisible]; + return [[GSTheme theme] proposedVisibility: isVisible forMenu: self]; } - (BOOL) _isMain