X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f1d04a42d5a19b18856a41571488fe7006f3d00a..d37b709c4b94d8690f9fe6adbdc1246e9f51bf4e:/src/cocoa/mbarman.mm diff --git a/src/cocoa/mbarman.mm b/src/cocoa/mbarman.mm index f6c52d21be..35e158a1bd 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,17 @@ #import #import +#define wxUSE_FSCRIPT 0 +#if wxUSE_FSCRIPT + #import +#endif + +// 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,11 +57,12 @@ - (void)windowWillClose: (NSNotification *)notification; #endif // 0 @end // interface wxMenuBarManagerObserver : NSObject +WX_DECLARE_GET_OBJC_CLASS(wxMenuBarManagerObserver,NSObject) @implementation wxMenuBarManagerObserver : NSObject - (id)init { - wxFAIL_MSG("[wxMenuBarManagerObserver -init] should never be called!"); + wxFAIL_MSG(wxT("[wxMenuBarManagerObserver -init] should never be called!")); m_mbarman = NULL; return self; } @@ -94,15 +107,27 @@ #endif // 0 @end // implementation wxMenuBarManagerObserver : NSObject +WX_IMPLEMENT_GET_OBJC_CLASS(wxMenuBarManagerObserver,NSObject) // ============================================================================ // wxMenuBarManager // ============================================================================ wxMenuBarManager *wxMenuBarManager::sm_mbarmanInstance = NULL; +static void AddFScriptItem(NSMenu *menu) +#if wxUSE_FSCRIPT +{ + NSMenuItem *item = [[FScriptMenuItem alloc] init]; + [menu addItem: item]; + [item release]; +} +#else +{} +#endif + 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 +152,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. @@ -140,6 +165,7 @@ wxMenuBarManager::wxMenuBarManager() /**/[m_menuApp addItemWithTitle:@"Preferences..." action:nil keyEquivalent:@""]; /**/[m_menuApp addItem: [NSMenuItem separatorItem]]; +/**/AddFScriptItem(m_menuApp); /**/menuitem = [[NSMenuItem alloc] initWithTitle: @"Services" action:nil keyEquivalent:@""]; [menuitem setSubmenu:m_menuServices]; [m_menuApp addItem: menuitem]; @@ -243,7 +269,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,16 +300,19 @@ void wxMenuBarManager::WindowWillClose(NSNotification *notification) void wxMenuBarManager::InstallMenuBarForWindow(wxCocoaNSWindow *win) { wxASSERT(win); - m_windowCurrent = win; - wxMenuBar *menubar = win->GetAppMenuBar(); - wxLogDebug("Found menubar=%p for window=%p.",menubar,win); + wxMenuBar *menubar = win->GetAppMenuBar(win); + wxLogTrace(wxTRACE_COCOA,wxT("Found menubar=%p for window=%p."),menubar,win); SetMenuBar(menubar); } -void wxMenuBarManager::UpdateWindowMenuBar(wxTopLevelWindowNative *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