From 3e84f98ffaf7f813fad8cf4260ebe7896adc4d18 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Thu, 6 Nov 2003 19:25:06 +0000 Subject: [PATCH] wxMenuBarManager::InstallMenuBarForWindow no longer looks for a menubar attached to the parent of a window without one. Instead, it is now up to the GetAppMenuBar() function to do so. The new implementation in wxTopLevelWindow does just that. The wxFrame implementation now calls the base class version if it does not have a menubar. Also, it is now invalid to call the function with a NULL window (it is internal anyway). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24424 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/frame.h | 2 +- include/wx/cocoa/toplevel.h | 2 +- src/cocoa/frame.mm | 7 +++++++ src/cocoa/mbarman.mm | 12 ++++-------- src/cocoa/toplevel.mm | 8 ++++++++ 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/include/wx/cocoa/frame.h b/include/wx/cocoa/frame.h index 0cea7dbac3..9d0fcc3a41 100644 --- a/include/wx/cocoa/frame.h +++ b/include/wx/cocoa/frame.h @@ -51,7 +51,7 @@ protected: // Cocoa specifics // ------------------------------------------------------------------------ public: - virtual wxMenuBar* GetAppMenuBar() { return GetMenuBar(); } + virtual wxMenuBar* GetAppMenuBar(); // Returns the NSView for non-client drawing virtual WX_NSView GetNonClientNSView(); protected: diff --git a/include/wx/cocoa/toplevel.h b/include/wx/cocoa/toplevel.h index e09873628d..8e5f44bd97 100644 --- a/include/wx/cocoa/toplevel.h +++ b/include/wx/cocoa/toplevel.h @@ -67,7 +67,7 @@ public: virtual void CocoaDelegate_windowDidResignKey(void); virtual void CocoaDelegate_windowDidBecomeMain(void); virtual void CocoaDelegate_windowDidResignMain(void); - virtual wxMenuBar* GetAppMenuBar() { return NULL; } + virtual wxMenuBar* GetAppMenuBar(); protected: void SetNSWindow(WX_NSWindow cocoaNSWindow); WX_NSWindow m_cocoaNSWindow; diff --git a/src/cocoa/frame.mm b/src/cocoa/frame.mm index f74bbf4a0a..e7ed47ceef 100644 --- a/src/cocoa/frame.mm +++ b/src/cocoa/frame.mm @@ -81,6 +81,13 @@ void wxFrame::SetMenuBar(wxMenuBar *menubar) wxMenuBarManager::GetInstance()->UpdateWindowMenuBar(this); } +wxMenuBar* wxFrame::GetAppMenuBar() +{ + if(GetMenuBar()) + return GetMenuBar(); + return wxFrameBase::GetAppMenuBar(); +} + wxPoint wxFrame::GetClientAreaOrigin() const { return wxPoint(0,0); diff --git a/src/cocoa/mbarman.mm b/src/cocoa/mbarman.mm index 829bdffebb..63bbdd4e91 100644 --- a/src/cocoa/mbarman.mm +++ b/src/cocoa/mbarman.mm @@ -188,19 +188,15 @@ void wxMenuBarManager::WindowDidResignMain(wxTopLevelWindowNative *win) void wxMenuBarManager::InstallMenuBarForWindow(wxTopLevelWindowNative *win) { - wxMenuBar *menubar = NULL; - for(wxTopLevelWindowNative *destwin = win; - !menubar && destwin; - destwin = wxDynamicCast(destwin->GetParent(), wxTopLevelWindow)) - { - menubar = destwin->GetAppMenuBar(); - } + wxASSERT(win); + wxMenuBar *menubar = win->GetAppMenuBar(); SetMenuBar(menubar); } void wxMenuBarManager::UpdateWindowMenuBar(wxTopLevelWindowNative *win) { - InstallMenuBarForWindow(m_windowKey); + if(m_windowKey) + InstallMenuBarForWindow(m_windowKey); } #endif // wxUSE_MENUS diff --git a/src/cocoa/toplevel.mm b/src/cocoa/toplevel.mm index 453ad124a3..5bcd9a84d8 100644 --- a/src/cocoa/toplevel.mm +++ b/src/cocoa/toplevel.mm @@ -134,6 +134,14 @@ wxTopLevelWindowCocoa::~wxTopLevelWindowCocoa() // wxTopLevelWindowCocoa Cocoa Specifics // ---------------------------------------------------------------------------- +wxMenuBar* wxTopLevelWindowCocoa::GetAppMenuBar() +{ + wxTopLevelWindowCocoa *parent = wxDynamicCast(GetParent(),wxTopLevelWindow); + if(parent) + return parent->GetAppMenuBar(); + return NULL; +} + void wxTopLevelWindowCocoa::SetNSWindow(WX_NSWindow cocoaNSWindow) { bool need_debug = cocoaNSWindow || m_cocoaNSWindow; -- 2.45.2