never used directly but only to look up the associated wxCocoaNSWindow.
If the wxCocoaNSWindow cannot be found later in UpdateMenuBar then it's
likely been destroyed but no crash will result as before.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26720
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// Main menu (if app provides one)
wxMenuBar *m_mainMenuBar;
wxMenuBarManagerObserver *m_observer;
// Main menu (if app provides one)
wxMenuBar *m_mainMenuBar;
wxMenuBarManagerObserver *m_observer;
- wxCocoaNSWindow *m_windowCurrent;
+ WX_NSWindow m_currentNSWindow;
m_menuMain = nil;
m_mainMenuBarInstalled = true;
m_mainMenuBar = NULL;
m_menuMain = nil;
m_mainMenuBarInstalled = true;
m_mainMenuBar = NULL;
- m_windowCurrent = NULL;
+ m_currentNSWindow = nil;
NSApplication *theNSApplication = wxTheApp->GetNSApplication();
// Create the services menu.
NSApplication *theNSApplication = wxTheApp->GetNSApplication();
// Create the services menu.
void wxMenuBarManager::WindowDidBecomeKey(NSNotification *notification)
{
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
if(win)
InstallMenuBarForWindow(win);
else
void wxMenuBarManager::InstallMenuBarForWindow(wxCocoaNSWindow *win)
{
wxASSERT(win);
void wxMenuBarManager::InstallMenuBarForWindow(wxCocoaNSWindow *win)
{
wxASSERT(win);
wxMenuBar *menubar = win->GetAppMenuBar(win);
wxLogTrace(wxTRACE_COCOA,wxT("Found menubar=%p for window=%p."),menubar,win);
SetMenuBar(menubar);
wxMenuBar *menubar = win->GetAppMenuBar(win);
wxLogTrace(wxTRACE_COCOA,wxT("Found menubar=%p for window=%p."),menubar,win);
SetMenuBar(menubar);
void wxMenuBarManager::UpdateMenuBar()
{
void wxMenuBarManager::UpdateMenuBar()
{
- if(m_windowCurrent)
- InstallMenuBarForWindow(m_windowCurrent);
+ if(m_currentNSWindow)
+ {
+ wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa(m_currentNSWindow);
+ if(win)
+ InstallMenuBarForWindow(win);
+ }