]> git.saurik.com Git - wxWidgets.git/commitdiff
use a virtual function instead of wxDynamicCast(wxMDIParentFrame) in wxFrame code...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 26 Jan 2009 23:18:47 +0000 (23:18 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 26 Jan 2009 23:18:47 +0000 (23:18 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58443 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/frame.h
include/wx/msw/mdi.h
src/msw/frame.cpp
src/msw/mdi.cpp

index 0677d943e95d35080705163c3c34f81dc48fb7c6..348853262afa6d1e77e50492601fe583cb4ce8bd 100644 (file)
@@ -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();
index 3aa1a566f09c73b9bffc94f1bf99ddd21bf084cc..5115b619dd5703ca4e7217115173ba2ec10ffd7c 100644 (file)
@@ -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()
index bf2b9dbac88a98330cdbed82c205faca4e662ae4..15c9e2bb59bf6f010d7cfa5c7379608abe1923e0 100644 (file)
@@ -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
 
index 3ecb51ef778a5849f76c38c15be71924edc250db..36f0a451ba11b475936ff8deb972aeb4dbf7facb 100644 (file)
@@ -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);