Skip to content

Commit

Permalink
Allow themes to override [NSMenu _isVisible]
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
qmfrederik committed Oct 27, 2024
1 parent 9901bbc commit a98d314
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Headers/Additions/GNUstepGUI/GSTheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions Source/GSThemeMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -418,5 +418,11 @@ - (void) organizeMenu: (NSMenu *)menu
[[menu menuRepresentation] update];
[menu sizeToFit];
}

- (BOOL) proposedVisibility: (BOOL)visible
forMenu: (NSMenu *) menu
{
return visible;
}
@end

3 changes: 2 additions & 1 deletion Source/NSMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a98d314

Please sign in to comment.