1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-26 20:28:49 -05:00

Cocoa: Add support for MainMenu.nib loading

This commit is contained in:
Camilla Löwy 2017-03-01 04:09:51 +01:00
parent 6d9a58bfef
commit c50aba1335
4 changed files with 31 additions and 9 deletions

View File

@ -169,6 +169,7 @@ information on what to include when reporting a bug.
- [Linux] Bugfix: Event processing did not detect joystick disconnection (#932) - [Linux] Bugfix: Event processing did not detect joystick disconnection (#932)
- [Cocoa] Added support for Vulkan window surface creation via - [Cocoa] Added support for Vulkan window surface creation via
[MoltenVK](https://moltengl.com/moltenvk/) (#870) [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: Disabling window aspect ratio would assert (#852)
- [Cocoa] Bugfix: Window creation failed to set first responder (#876,#883) - [Cocoa] Bugfix: Window creation failed to set first responder (#876,#883)
- [Cocoa] Bugfix: Removed use of deprecated `CGDisplayIOServicePort` function - [Cocoa] Bugfix: Removed use of deprecated `CGDisplayIOServicePort` function

View File

@ -86,8 +86,9 @@ the application to the `Contents/Resources` subdirectory of the application's
bundle, if present. bundle, if present.
@anchor GLFW_COCOA_MENUBAR @anchor GLFW_COCOA_MENUBAR
__GLFW_COCOA_MENUBAR__ specifies whether to create a basic menu bar when the __GLFW_COCOA_MENUBAR__ specifies whether to create a basic menu bar, either from
first window is created, which is when AppKit is initialized. a nib or manually, when the first window is created, which is when AppKit is
initialized.
@subsubsection init_hints_values Supported and default values @subsubsection init_hints_values Supported and default values

View File

@ -2085,10 +2085,12 @@ GLFWAPI void glfwWindowHint(int hint, int value);
* [Bundle Programming Guide](https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/) * [Bundle Programming Guide](https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/)
* in the Mac Developer Library. * in the Mac Developer Library.
* *
* @remark @macos The first time a window is created the menu bar is populated * @remark @macos The first time a window is created the menu bar is created.
* with common commands like Hide, Quit and About. The About entry opens * If GLFW finds a `MainMenu.nib` it is loaded and assumed to contain a menu
* a minimal about dialog with information from the application's bundle. The * bar. Otherwise a minimal menu bar is created manually with common commands
* menu bar can be disabled with the @ref GLFW_COCOA_MENUBAR init hint. * 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 * @remark @macos On OS X 10.10 and later the window frame will not be rendered
* at full resolution on Retina displays unless the * at full resolution on Retina displays unless the

View File

@ -785,6 +785,10 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
//------------------------------------------------------------------------ //------------------------------------------------------------------------
@interface GLFWApplication : NSApplication @interface GLFWApplication : NSApplication
{
NSArray* nibObjects;
}
@end @end
@implementation GLFWApplication @implementation GLFWApplication
@ -809,6 +813,17 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
- (void)doNothing:(id)object - (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 @end
// Try to figure out what the calling application is called // Try to figure out what the calling application is called
@ -848,8 +863,7 @@ static NSString* findAppName(void)
// Set up the menu bar (manually) // Set up the menu bar (manually)
// This is nasty, nasty stuff -- calls to undocumented semi-private APIs that // 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 // 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 // localize(d|able), etc. Add a nib to save us this horror.
// doesn't seem like a good thing to require of GLFW users.
// //
static void createMenuBar(void) static void createMenuBar(void)
{ {
@ -943,6 +957,10 @@ static GLFWbool initializeAppKit(void)
// Menu bar setup must go between sharedApplication above and // Menu bar setup must go between sharedApplication above and
// finishLaunching below, in order to properly emulate the behavior // finishLaunching below, in order to properly emulate the behavior
// of NSApplicationMain // of NSApplicationMain
if ([[NSBundle mainBundle] pathForResource:@"MainMenu" ofType:@"nib"])
[NSApp loadMainMenu];
else
createMenuBar(); createMenuBar();
} }