X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/48580976469f7c46b730f96effacfa680e55e3cd..b3adca1e989f5520461c1e63ee6fcafcd0c7cd8e:/src/cocoa/mbarman.mm?ds=sidebyside diff --git a/src/cocoa/mbarman.mm b/src/cocoa/mbarman.mm index 77fea84ec6..74694bffdc 100644 --- a/src/cocoa/mbarman.mm +++ b/src/cocoa/mbarman.mm @@ -6,7 +6,7 @@ // Created: 2003/09/04 // RCS-ID: $Id$ // Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence +// Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// #include "wx/wxprec.h" @@ -20,6 +20,7 @@ #include "wx/cocoa/mbarman.h" #include "wx/cocoa/autorelease.h" +#include "wx/cocoa/objc/objc_uniquifying.h" #import #import @@ -27,6 +28,12 @@ #import #import +// Declare setAppleMenu: in an NSApplication category since Tiger and later +// releases support it but don't declare it as it's considered deprecated. +@interface NSApplication(wxDeprecatedMethodsWeWantToUse) +- (void)setAppleMenu:(NSMenu *)menu; +@end + // ============================================================================ // wxMenuBarManagerObserver // ============================================================================ @@ -45,6 +52,7 @@ - (void)windowWillClose: (NSNotification *)notification; #endif // 0 @end // interface wxMenuBarManagerObserver : NSObject +WX_DECLARE_GET_OBJC_CLASS(wxMenuBarManagerObserver,NSObject) @implementation wxMenuBarManagerObserver : NSObject - (id)init @@ -94,6 +102,7 @@ #endif // 0 @end // implementation wxMenuBarManagerObserver : NSObject +WX_IMPLEMENT_GET_OBJC_CLASS(wxMenuBarManagerObserver,NSObject) // ============================================================================ // wxMenuBarManager @@ -102,7 +111,7 @@ wxMenuBarManager *wxMenuBarManager::sm_mbarmanInstance = NULL; wxMenuBarManager::wxMenuBarManager() { - m_observer = [[wxMenuBarManagerObserver alloc] + m_observer = [[WX_GET_OBJC_CLASS(wxMenuBarManagerObserver) alloc] initWithWxMenuBarManager:this]; [[NSNotificationCenter defaultCenter] addObserver:m_observer selector:@selector(windowDidBecomeKey:) @@ -127,7 +136,7 @@ wxMenuBarManager::wxMenuBarManager() m_menuMain = nil; m_mainMenuBarInstalled = true; m_mainMenuBar = NULL; - m_windowCurrent = NULL; + m_currentNSWindow = nil; NSApplication *theNSApplication = wxTheApp->GetNSApplication(); // Create the services menu. @@ -243,7 +252,10 @@ void wxMenuBarManager::InstallMainMenu() void wxMenuBarManager::WindowDidBecomeKey(NSNotification *notification) { - wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]); + /* NOTE: m_currentNSWindow might be destroyed but we only ever use it + to look it up in the hash table. Do not send messages to it. */ + m_currentNSWindow = [notification object]; + wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa(m_currentNSWindow); if(win) InstallMenuBarForWindow(win); else @@ -271,7 +283,6 @@ void wxMenuBarManager::WindowWillClose(NSNotification *notification) void wxMenuBarManager::InstallMenuBarForWindow(wxCocoaNSWindow *win) { wxASSERT(win); - m_windowCurrent = win; wxMenuBar *menubar = win->GetAppMenuBar(win); wxLogTrace(wxTRACE_COCOA,wxT("Found menubar=%p for window=%p."),menubar,win); SetMenuBar(menubar); @@ -279,8 +290,12 @@ void wxMenuBarManager::InstallMenuBarForWindow(wxCocoaNSWindow *win) void wxMenuBarManager::UpdateMenuBar() { - if(m_windowCurrent) - InstallMenuBarForWindow(m_windowCurrent); + if(m_currentNSWindow) + { + wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa(m_currentNSWindow); + if(win) + InstallMenuBarForWindow(win); + } } #endif // wxUSE_MENUS