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
This commit is contained in:
@@ -75,10 +75,6 @@ public:
|
|||||||
{ return m_useNativeStatusBar; }
|
{ return m_useNativeStatusBar; }
|
||||||
#endif // wxUSE_STATUSBAR
|
#endif // wxUSE_STATUSBAR
|
||||||
|
|
||||||
#if wxUSE_MENUS
|
|
||||||
WXHMENU GetWinMenu() const { return m_hMenu; }
|
|
||||||
#endif // wxUSE_MENUS
|
|
||||||
|
|
||||||
// event handlers
|
// event handlers
|
||||||
bool HandleSize(int x, int y, WXUINT flag);
|
bool HandleSize(int x, int y, WXUINT flag);
|
||||||
bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
|
bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
|
||||||
@@ -107,6 +103,12 @@ public:
|
|||||||
WXWPARAM wParam,
|
WXWPARAM wParam,
|
||||||
WXLPARAM lParam);
|
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:
|
protected:
|
||||||
// common part of all ctors
|
// common part of all ctors
|
||||||
void Init();
|
void Init();
|
||||||
|
|||||||
@@ -63,8 +63,12 @@ public:
|
|||||||
virtual void SetWindowMenu(wxMenu* menu);
|
virtual void SetWindowMenu(wxMenu* menu);
|
||||||
|
|
||||||
virtual void DoMenuUpdates(wxMenu* menu = NULL);
|
virtual void DoMenuUpdates(wxMenu* menu = NULL);
|
||||||
|
|
||||||
|
// return the active child menu, if any
|
||||||
|
virtual WXHMENU MSWGetActiveMenu() const;
|
||||||
#endif // wxUSE_MENUS
|
#endif // wxUSE_MENUS
|
||||||
|
|
||||||
|
|
||||||
// implementation only from now on
|
// implementation only from now on
|
||||||
|
|
||||||
// MDI helpers
|
// MDI helpers
|
||||||
@@ -94,8 +98,10 @@ public:
|
|||||||
virtual WXLRESULT MSWDefWindowProc(WXUINT, WXWPARAM, WXLPARAM);
|
virtual WXLRESULT MSWDefWindowProc(WXUINT, WXWPARAM, WXLPARAM);
|
||||||
virtual bool MSWTranslateMessage(WXMSG* msg);
|
virtual bool MSWTranslateMessage(WXMSG* msg);
|
||||||
|
|
||||||
|
#if wxUSE_MENUS
|
||||||
// override wxFrameBase function to also look in the active child menu bar
|
// override wxFrameBase function to also look in the active child menu bar
|
||||||
virtual const wxMenuItem *FindItemInMenuBar(int menuId) const;
|
virtual const wxMenuItem *FindItemInMenuBar(int menuId) const;
|
||||||
|
#endif // wxUSE_MENUS
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#if wxUSE_MENUS_NATIVE
|
#if wxUSE_MENUS_NATIVE
|
||||||
@@ -112,13 +118,20 @@ protected:
|
|||||||
bool m_parentFrameActive;
|
bool m_parentFrameActive;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#if wxUSE_MENUS
|
||||||
// add/remove window menu if we have it (i.e. m_windowMenu != NULL)
|
// add/remove window menu if we have it (i.e. m_windowMenu != NULL)
|
||||||
void AddWindowMenu();
|
void AddWindowMenu();
|
||||||
void RemoveWindowMenu();
|
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)
|
// return the number of child frames we currently have (maybe 0)
|
||||||
int GetChildFramesCount() const;
|
int GetChildFramesCount() const;
|
||||||
|
|
||||||
|
|
||||||
friend class WXDLLIMPEXP_FWD_CORE wxMDIChildFrame;
|
friend class WXDLLIMPEXP_FWD_CORE wxMDIChildFrame;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
|
|||||||
@@ -580,24 +580,9 @@ bool wxFrame::ShowFullScreen(bool show, long style)
|
|||||||
#if wxUSE_MENUS
|
#if wxUSE_MENUS
|
||||||
if (m_fsStyle & wxFULLSCREEN_NOMENUBAR)
|
if (m_fsStyle & wxFULLSCREEN_NOMENUBAR)
|
||||||
{
|
{
|
||||||
WXHMENU menu = m_hMenu;
|
const WXHMENU hmenu = MSWGetActiveMenu();
|
||||||
|
if ( hmenu )
|
||||||
#if wxUSE_MDI_ARCHITECTURE
|
::SetMenu(GetHwnd(), (HMENU)hmenu);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif // wxUSE_MENUS
|
#endif // wxUSE_MENUS
|
||||||
|
|
||||||
|
|||||||
@@ -234,6 +234,16 @@ wxMDIParentFrame::~wxMDIParentFrame()
|
|||||||
// wxMDIParentFrame child management
|
// 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 wxMDIParentFrame::GetChildFramesCount() const
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@@ -291,6 +301,8 @@ void wxMDIParentFrame::RemoveMDIChild(wxMDIChildFrame * WXUNUSED(child))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if wxUSE_MENUS
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxMDIParentFrame window menu handling
|
// wxMDIParentFrame window menu handling
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -349,6 +361,10 @@ void wxMDIParentFrame::SetWindowMenu(wxMenu* menu)
|
|||||||
AddWindowMenu();
|
AddWindowMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxMDIParentFrame other menu-related stuff
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxMDIParentFrame::DoMenuUpdates(wxMenu* menu)
|
void wxMDIParentFrame::DoMenuUpdates(wxMenu* menu)
|
||||||
{
|
{
|
||||||
wxMDIChildFrame *child = GetActiveChild();
|
wxMDIChildFrame *child = GetActiveChild();
|
||||||
@@ -388,6 +404,25 @@ const wxMenuItem *wxMDIParentFrame::FindItemInMenuBar(int menuId) const
|
|||||||
return item;
|
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()
|
void wxMDIParentFrame::UpdateClientSize()
|
||||||
{
|
{
|
||||||
if ( GetClientWindow() )
|
if ( GetClientWindow() )
|
||||||
@@ -414,17 +449,6 @@ void wxMDIParentFrame::OnIconized(wxIconizeEvent& event)
|
|||||||
UpdateClientSize();
|
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.
|
// Responds to colour changes, and passes event on to children.
|
||||||
void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
|
void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
|
||||||
{
|
{
|
||||||
@@ -1118,7 +1142,7 @@ bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate),
|
|||||||
{
|
{
|
||||||
wxMDIParentFrame * const parent = GetMDIParent();
|
wxMDIParentFrame * const parent = GetMDIParent();
|
||||||
|
|
||||||
HMENU menuToSet = 0;
|
WXHMENU hMenuToSet = 0;
|
||||||
|
|
||||||
bool activated;
|
bool activated;
|
||||||
|
|
||||||
@@ -1127,12 +1151,12 @@ bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate),
|
|||||||
activated = true;
|
activated = true;
|
||||||
parent->m_currentChild = this;
|
parent->m_currentChild = this;
|
||||||
|
|
||||||
HMENU child_menu = (HMENU)GetWinMenu();
|
WXHMENU hMenuChild = m_hMenu;
|
||||||
if ( child_menu )
|
if ( hMenuChild )
|
||||||
{
|
{
|
||||||
parent->m_parentFrameActive = false;
|
parent->m_parentFrameActive = false;
|
||||||
|
|
||||||
menuToSet = child_menu;
|
hMenuToSet = hMenuChild;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( m_hWnd == hwndDeact )
|
else if ( m_hWnd == hwndDeact )
|
||||||
@@ -1143,15 +1167,15 @@ bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate),
|
|||||||
activated = false;
|
activated = false;
|
||||||
parent->m_currentChild = NULL;
|
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
|
// activate the the parent menu only when there is no other child
|
||||||
// that has been activated
|
// that has been activated
|
||||||
if ( parent_menu && !hwndAct )
|
if ( hMenuParent && !hwndAct )
|
||||||
{
|
{
|
||||||
parent->m_parentFrameActive = true;
|
parent->m_parentFrameActive = true;
|
||||||
|
|
||||||
menuToSet = parent_menu;
|
hMenuToSet = hMenuParent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1160,10 +1184,10 @@ bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate),
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( menuToSet )
|
if ( hMenuToSet )
|
||||||
{
|
{
|
||||||
MDISetMenu(parent->GetClientWindow(),
|
MDISetMenu(parent->GetClientWindow(),
|
||||||
menuToSet, GetMDIWindowMenu(parent));
|
(HMENU)hMenuToSet, GetMDIWindowMenu(parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
wxActivateEvent event(wxEVT_ACTIVATE, activated, m_windowId);
|
wxActivateEvent event(wxEVT_ACTIVATE, activated, m_windowId);
|
||||||
|
|||||||
Reference in New Issue
Block a user