]> git.saurik.com Git - wxWidgets.git/blobdiff - src/cocoa/mbarman.mm
Applied Kevin Hock's combobox patch for text update events
[wxWidgets.git] / src / cocoa / mbarman.mm
index 0935ec6e97a7a7df004439dbbbbc8c0a042b73f6..2eda41c0d4f0cd9da31b4b8c2c701207f79ea111 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     2003/09/04
 // RCS-ID:      $Id$
 // Copyright:   (c) 2003 David Elliott
 // Created:     2003/09/04
 // RCS-ID:      $Id$
 // Copyright:   (c) 2003 David Elliott
-// Licence:     wxWindows licence
+// Licence:     wxWidgets licence
 /////////////////////////////////////////////////////////////////////////////
 
 #include "wx/wxprec.h"
 /////////////////////////////////////////////////////////////////////////////
 
 #include "wx/wxprec.h"
@@ -127,7 +127,7 @@ wxMenuBarManager::wxMenuBarManager()
     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.
@@ -243,7 +243,10 @@ void wxMenuBarManager::InstallMainMenu()
 
 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
@@ -271,16 +274,19 @@ void wxMenuBarManager::WindowWillClose(NSNotification *notification)
 void wxMenuBarManager::InstallMenuBarForWindow(wxCocoaNSWindow *win)
 {
     wxASSERT(win);
 void wxMenuBarManager::InstallMenuBarForWindow(wxCocoaNSWindow *win)
 {
     wxASSERT(win);
-    m_windowCurrent = win;
     wxMenuBar *menubar = win->GetAppMenuBar(win);
     wxMenuBar *menubar = win->GetAppMenuBar(win);
-    wxLogDebug(wxT("Found menubar=%p for window=%p."),menubar,win);
+    wxLogTrace(wxTRACE_COCOA,wxT("Found menubar=%p for window=%p."),menubar,win);
     SetMenuBar(menubar);
 }
 
 void wxMenuBarManager::UpdateMenuBar()
 {
     SetMenuBar(menubar);
 }
 
 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
 }
 
 #endif // wxUSE_MENUS