From 51181d291194b7ae616cfb17c984fd8927e4a977 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 26 Jan 2009 23:18:47 +0000 Subject: [PATCH] use a virtual function instead of wxDynamicCast(wxMDIParentFrame) in wxFrame code: this not only makes the code cleaner but should also remove the last dependency on MDI code when linking wx applications not using MDI git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58443 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/frame.h | 10 ++++--- include/wx/msw/mdi.h | 13 +++++++++ src/msw/frame.cpp | 21 ++------------ src/msw/mdi.cpp | 64 +++++++++++++++++++++++++++++------------- 4 files changed, 66 insertions(+), 42 deletions(-) diff --git a/include/wx/msw/frame.h b/include/wx/msw/frame.h index 0677d943e9..348853262a 100644 --- a/include/wx/msw/frame.h +++ b/include/wx/msw/frame.h @@ -75,10 +75,6 @@ public: { return m_useNativeStatusBar; } #endif // wxUSE_STATUSBAR -#if wxUSE_MENUS - WXHMENU GetWinMenu() const { return m_hMenu; } -#endif // wxUSE_MENUS - // event handlers bool HandleSize(int x, int y, WXUINT flag); bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control); @@ -107,6 +103,12 @@ public: WXWPARAM wParam, WXLPARAM lParam); +#if wxUSE_MENUS + // get the currently active menu: this is the same as the frame menu for + // normal frames but is overridden by wxMDIParentFrame + virtual WXHMENU MSWGetActiveMenu() const { return m_hMenu; } +#endif // wxUSE_MENUS + protected: // common part of all ctors void Init(); diff --git a/include/wx/msw/mdi.h b/include/wx/msw/mdi.h index 3aa1a566f0..5115b619dd 100644 --- a/include/wx/msw/mdi.h +++ b/include/wx/msw/mdi.h @@ -63,8 +63,12 @@ public: virtual void SetWindowMenu(wxMenu* menu); virtual void DoMenuUpdates(wxMenu* menu = NULL); + + // return the active child menu, if any + virtual WXHMENU MSWGetActiveMenu() const; #endif // wxUSE_MENUS + // implementation only from now on // MDI helpers @@ -94,8 +98,10 @@ public: virtual WXLRESULT MSWDefWindowProc(WXUINT, WXWPARAM, WXLPARAM); virtual bool MSWTranslateMessage(WXMSG* msg); +#if wxUSE_MENUS // override wxFrameBase function to also look in the active child menu bar virtual const wxMenuItem *FindItemInMenuBar(int menuId) const; +#endif // wxUSE_MENUS protected: #if wxUSE_MENUS_NATIVE @@ -112,13 +118,20 @@ protected: bool m_parentFrameActive; private: +#if wxUSE_MENUS // add/remove window menu if we have it (i.e. m_windowMenu != NULL) void AddWindowMenu(); void RemoveWindowMenu(); + // update the window menu (if we have it) to enable or disable the commands + // which only make sense when we have more than one child + void UpdateWindowMenu(bool enable); +#endif // wxUSE_MENUS + // return the number of child frames we currently have (maybe 0) int GetChildFramesCount() const; + friend class WXDLLIMPEXP_FWD_CORE wxMDIChildFrame; DECLARE_EVENT_TABLE() diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index bf2b9dbac8..15c9e2bb59 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -580,24 +580,9 @@ bool wxFrame::ShowFullScreen(bool show, long style) #if wxUSE_MENUS if (m_fsStyle & wxFULLSCREEN_NOMENUBAR) { - WXHMENU menu = m_hMenu; - -#if wxUSE_MDI_ARCHITECTURE - wxMDIParentFrame *frame = wxDynamicCast(this, wxMDIParentFrame); - if (frame) - { - wxMDIChildFrame *child = frame->GetActiveChild(); - if (child) - { - menu = child->GetWinMenu(); - } - } -#endif // wxUSE_MDI_ARCHITECTURE - - if (menu) - { - ::SetMenu(GetHwnd(), (HMENU)menu); - } + const WXHMENU hmenu = MSWGetActiveMenu(); + if ( hmenu ) + ::SetMenu(GetHwnd(), (HMENU)hmenu); } #endif // wxUSE_MENUS diff --git a/src/msw/mdi.cpp b/src/msw/mdi.cpp index 3ecb51ef77..36f0a451ba 100644 --- a/src/msw/mdi.cpp +++ b/src/msw/mdi.cpp @@ -234,6 +234,16 @@ wxMDIParentFrame::~wxMDIParentFrame() // wxMDIParentFrame child management // ---------------------------------------------------------------------------- +wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const +{ + HWND hWnd = (HWND)::SendMessage(GetWinHwnd(GetClientWindow()), + WM_MDIGETACTIVE, 0, 0L); + if ( hWnd == 0 ) + return NULL; + + return (wxMDIChildFrame *)wxFindWinFromHandle(hWnd); +} + int wxMDIParentFrame::GetChildFramesCount() const { int count = 0; @@ -291,6 +301,8 @@ void wxMDIParentFrame::RemoveMDIChild(wxMDIChildFrame * WXUNUSED(child)) } } +#if wxUSE_MENUS + // ---------------------------------------------------------------------------- // wxMDIParentFrame window menu handling // ---------------------------------------------------------------------------- @@ -349,6 +361,10 @@ void wxMDIParentFrame::SetWindowMenu(wxMenu* menu) AddWindowMenu(); } +// ---------------------------------------------------------------------------- +// wxMDIParentFrame other menu-related stuff +// ---------------------------------------------------------------------------- + void wxMDIParentFrame::DoMenuUpdates(wxMenu* menu) { wxMDIChildFrame *child = GetActiveChild(); @@ -388,6 +404,25 @@ const wxMenuItem *wxMDIParentFrame::FindItemInMenuBar(int menuId) const return item; } +WXHMENU wxMDIParentFrame::MSWGetActiveMenu() const +{ + wxMDIChildFrame * const child = GetActiveChild(); + if ( child ) + { + const WXHMENU hmenu = child->MSWGetActiveMenu(); + if ( hmenu ) + return hmenu; + } + + return wxFrame::MSWGetActiveMenu(); +} + +#endif // wxUSE_MENUS + +// ---------------------------------------------------------------------------- +// wxMDIParentFrame event handling +// ---------------------------------------------------------------------------- + void wxMDIParentFrame::UpdateClientSize() { if ( GetClientWindow() ) @@ -414,17 +449,6 @@ void wxMDIParentFrame::OnIconized(wxIconizeEvent& event) UpdateClientSize(); } -// Returns the active MDI child window -wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const -{ - HWND hWnd = (HWND)::SendMessage(GetWinHwnd(GetClientWindow()), - WM_MDIGETACTIVE, 0, 0L); - if ( hWnd == 0 ) - return NULL; - - return (wxMDIChildFrame *)wxFindWinFromHandle(hWnd); -} - // Responds to colour changes, and passes event on to children. void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event) { @@ -1118,7 +1142,7 @@ bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate), { wxMDIParentFrame * const parent = GetMDIParent(); - HMENU menuToSet = 0; + WXHMENU hMenuToSet = 0; bool activated; @@ -1127,12 +1151,12 @@ bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate), activated = true; parent->m_currentChild = this; - HMENU child_menu = (HMENU)GetWinMenu(); - if ( child_menu ) + WXHMENU hMenuChild = m_hMenu; + if ( hMenuChild ) { parent->m_parentFrameActive = false; - menuToSet = child_menu; + hMenuToSet = hMenuChild; } } else if ( m_hWnd == hwndDeact ) @@ -1143,15 +1167,15 @@ bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate), activated = false; parent->m_currentChild = NULL; - HMENU parent_menu = (HMENU)parent->GetWinMenu(); + WXHMENU hMenuParent = parent->m_hMenu; // activate the the parent menu only when there is no other child // that has been activated - if ( parent_menu && !hwndAct ) + if ( hMenuParent && !hwndAct ) { parent->m_parentFrameActive = true; - menuToSet = parent_menu; + hMenuToSet = hMenuParent; } } else @@ -1160,10 +1184,10 @@ bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate), return false; } - if ( menuToSet ) + if ( hMenuToSet ) { MDISetMenu(parent->GetClientWindow(), - menuToSet, GetMDIWindowMenu(parent)); + (HMENU)hMenuToSet, GetMDIWindowMenu(parent)); } wxActivateEvent event(wxEVT_ACTIVATE, activated, m_windowId); -- 2.49.0