mirror of
https://github.com/glfw/glfw.git
synced 2024-11-25 22:14:34 +00:00
Cocoa: Add support for MainMenu.nib loading
This commit is contained in:
parent
6d9a58bfef
commit
c50aba1335
@ -169,6 +169,7 @@ information on what to include when reporting a bug.
|
||||
- [Linux] Bugfix: Event processing did not detect joystick disconnection (#932)
|
||||
- [Cocoa] Added support for Vulkan window surface creation via
|
||||
[MoltenVK](https://moltengl.com/moltenvk/) (#870)
|
||||
- [Cocoa] Added support for loading a `MainMenu.nib` when available
|
||||
- [Cocoa] Bugfix: Disabling window aspect ratio would assert (#852)
|
||||
- [Cocoa] Bugfix: Window creation failed to set first responder (#876,#883)
|
||||
- [Cocoa] Bugfix: Removed use of deprecated `CGDisplayIOServicePort` function
|
||||
|
@ -86,8 +86,9 @@ the application to the `Contents/Resources` subdirectory of the application's
|
||||
bundle, if present.
|
||||
|
||||
@anchor GLFW_COCOA_MENUBAR
|
||||
__GLFW_COCOA_MENUBAR__ specifies whether to create a basic menu bar when the
|
||||
first window is created, which is when AppKit is initialized.
|
||||
__GLFW_COCOA_MENUBAR__ specifies whether to create a basic menu bar, either from
|
||||
a nib or manually, when the first window is created, which is when AppKit is
|
||||
initialized.
|
||||
|
||||
|
||||
@subsubsection init_hints_values Supported and default values
|
||||
|
@ -2085,10 +2085,12 @@ GLFWAPI void glfwWindowHint(int hint, int value);
|
||||
* [Bundle Programming Guide](https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/)
|
||||
* in the Mac Developer Library.
|
||||
*
|
||||
* @remark @macos The first time a window is created the menu bar is populated
|
||||
* with common commands like Hide, Quit and About. The About entry opens
|
||||
* a minimal about dialog with information from the application's bundle. The
|
||||
* menu bar can be disabled with the @ref GLFW_COCOA_MENUBAR init hint.
|
||||
* @remark @macos The first time a window is created the menu bar is created.
|
||||
* If GLFW finds a `MainMenu.nib` it is loaded and assumed to contain a menu
|
||||
* bar. Otherwise a minimal menu bar is created manually with common commands
|
||||
* like Hide, Quit and About. The About entry opens a minimal about dialog
|
||||
* with information from the application's bundle. Menu bar creation can be
|
||||
* disabled entirely with the @ref GLFW_COCOA_MENUBAR init hint.
|
||||
*
|
||||
* @remark @macos On OS X 10.10 and later the window frame will not be rendered
|
||||
* at full resolution on Retina displays unless the
|
||||
|
@ -785,6 +785,10 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
@interface GLFWApplication : NSApplication
|
||||
{
|
||||
NSArray* nibObjects;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation GLFWApplication
|
||||
@ -809,6 +813,17 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
|
||||
- (void)doNothing:(id)object
|
||||
{
|
||||
}
|
||||
|
||||
- (void)loadMainMenu
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 100800
|
||||
[[NSBundle mainBundle] loadNibNamed:@"MainMenu"
|
||||
owner:NSApp
|
||||
topLevelObjects:&nibObjects];
|
||||
#else
|
||||
[[NSBundle mainBundle] loadNibNamed:@"MainMenu" owner:NSApp];
|
||||
#endif
|
||||
}
|
||||
@end
|
||||
|
||||
// Try to figure out what the calling application is called
|
||||
@ -848,8 +863,7 @@ static NSString* findAppName(void)
|
||||
// Set up the menu bar (manually)
|
||||
// This is nasty, nasty stuff -- calls to undocumented semi-private APIs that
|
||||
// could go away at any moment, lots of stuff that really should be
|
||||
// localize(d|able), etc. Loading a nib would save us this horror, but that
|
||||
// doesn't seem like a good thing to require of GLFW users.
|
||||
// localize(d|able), etc. Add a nib to save us this horror.
|
||||
//
|
||||
static void createMenuBar(void)
|
||||
{
|
||||
@ -943,6 +957,10 @@ static GLFWbool initializeAppKit(void)
|
||||
// Menu bar setup must go between sharedApplication above and
|
||||
// finishLaunching below, in order to properly emulate the behavior
|
||||
// of NSApplicationMain
|
||||
|
||||
if ([[NSBundle mainBundle] pathForResource:@"MainMenu" ofType:@"nib"])
|
||||
[NSApp loadMainMenu];
|
||||
else
|
||||
createMenuBar();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user