]> git.saurik.com Git - wxWidgets.git/blobdiff - src/aui/framemanager.cpp
Workaround for #15404: wxRichTextCtrl: caret does not disappear when focus is lost...
[wxWidgets.git] / src / aui / framemanager.cpp
index 24e718d3d34dd1d69f606f292f31f494c7a893bc..20e654791a10566761219ce1a9c129d8bb0a4eda 100644 (file)
@@ -4,7 +4,6 @@
 // Author:      Benjamin I. Williams
 // Modified by:
 // Created:     2005-05-17
-// RCS-ID:      $Id$
 // Copyright:   (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
 // Licence:     wxWindows Library Licence, Version 3.1
 ///////////////////////////////////////////////////////////////////////////////
@@ -59,6 +58,7 @@ wxDEFINE_EVENT( wxEVT_AUI_PANE_BUTTON, wxAuiManagerEvent );
 wxDEFINE_EVENT( wxEVT_AUI_PANE_CLOSE, wxAuiManagerEvent );
 wxDEFINE_EVENT( wxEVT_AUI_PANE_MAXIMIZE, wxAuiManagerEvent );
 wxDEFINE_EVENT( wxEVT_AUI_PANE_RESTORE, wxAuiManagerEvent );
+wxDEFINE_EVENT( wxEVT_AUI_PANE_ACTIVATED, wxAuiManagerEvent );
 wxDEFINE_EVENT( wxEVT_AUI_RENDER, wxAuiManagerEvent );
 wxDEFINE_EVENT( wxEVT_AUI_FIND_MANAGER, wxAuiManagerEvent );
 
@@ -550,15 +550,28 @@ static void RenumberDockRows(wxAuiDockInfoPtrArray& docks)
 // SetActivePane() sets the active pane, as well as cycles through
 // every other pane and makes sure that all others' active flags
 // are turned off
-static void SetActivePane(wxAuiPaneInfoArray& panes, wxWindow* active_pane)
+void wxAuiManager::SetActivePane(wxWindow* active_pane)
 {
     int i, pane_count;
-    for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
+    wxAuiPaneInfo* active_paneinfo = NULL;
+    for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
     {
-        wxAuiPaneInfo& pane = panes.Item(i);
+        wxAuiPaneInfo& pane = m_panes.Item(i);
         pane.state &= ~wxAuiPaneInfo::optionActive;
         if (pane.window == active_pane)
+        {
             pane.state |= wxAuiPaneInfo::optionActive;
+            active_paneinfo = &pane;
+        }
+    }
+
+    // send the 'activated' event after all panes have been updated
+    if ( active_paneinfo )
+    {
+        wxAuiManagerEvent evt(wxEVT_AUI_PANE_ACTIVATED);
+        evt.SetManager(this);
+        evt.SetPane(active_paneinfo);
+        ProcessMgrEvent(evt);
     }
 }
 
@@ -808,7 +821,7 @@ void wxAuiManager::UpdateHintWindowConfig()
     wxWindow* w = m_frame;
     while (w)
     {
-        if (w->IsKindOf(CLASSINFO(wxFrame)))
+        if (wxDynamicCast(w, wxFrame))
         {
             wxFrame* f = static_cast<wxFrame*>(w);
             can_do_transparent = f->CanSetTransparent();
@@ -899,7 +912,7 @@ void wxAuiManager::SetManagedWindow(wxWindow* wnd)
     // we need to add the MDI client window as the default
     // center pane
 
-    if (m_frame->IsKindOf(CLASSINFO(wxMDIParentFrame)))
+    if (wxDynamicCast(m_frame, wxMDIParentFrame))
     {
         wxMDIParentFrame* mdi_frame = (wxMDIParentFrame*)m_frame;
         wxWindow* client_window = mdi_frame->GetClientWindow();
@@ -910,7 +923,7 @@ void wxAuiManager::SetManagedWindow(wxWindow* wnd)
                 wxAuiPaneInfo().Name(wxT("mdiclient")).
                 CenterPane().PaneBorder(false));
     }
-    else if (m_frame->IsKindOf(CLASSINFO(wxAuiMDIParentFrame)))
+    else if (wxDynamicCast(m_frame, wxAuiMDIParentFrame))
     {
         wxAuiMDIParentFrame* mdi_frame = (wxAuiMDIParentFrame*)m_frame;
         wxAuiMDIClientWindow* client_window = mdi_frame->GetClientWindow();
@@ -1083,7 +1096,7 @@ bool wxAuiManager::AddPane(wxWindow* window, const wxAuiPaneInfo& paneInfo)
 
     if (pinfo.HasGripper())
     {
-        if (pinfo.window->IsKindOf(CLASSINFO(wxAuiToolBar)))
+        if (wxDynamicCast(pinfo.window, wxAuiToolBar))
         {
             // prevent duplicate gripper -- both wxAuiManager and wxAuiToolBar
             // have a gripper control.  The toolbar's built-in gripper
@@ -1103,7 +1116,7 @@ bool wxAuiManager::AddPane(wxWindow* window, const wxAuiPaneInfo& paneInfo)
         pinfo.best_size = pinfo.window->GetClientSize();
 
 #if wxUSE_TOOLBAR
-        if (pinfo.window->IsKindOf(CLASSINFO(wxToolBar)))
+        if (wxDynamicCast(pinfo.window, wxToolBar))
         {
             // GetClientSize() doesn't get the best size for
             // a toolbar under some newer versions of wxWidgets,
@@ -3222,16 +3235,16 @@ bool wxAuiManager::DoDrop(wxAuiDockInfoArray& docks,
         // determine the mouse offset and the pane size, both in the
         // direction of the dock itself, and perpendicular to the dock
 
-        int offset, size;
+        int mouseOffset, size;
 
         if (part->orientation == wxVERTICAL)
         {
-            offset = pt.y - part->rect.y;
+            mouseOffset = pt.y - part->rect.y;
             size = part->rect.GetHeight();
         }
         else
         {
-            offset = pt.x - part->rect.x;
+            mouseOffset = pt.x - part->rect.x;
             size = part->rect.GetWidth();
         }
 
@@ -3239,7 +3252,7 @@ bool wxAuiManager::DoDrop(wxAuiDockInfoArray& docks,
 
         // if we are in the top/left part of the pane,
         // insert the pane before the pane being hovered over
-        if (offset <= size/2)
+        if (mouseOffset <= size/2)
         {
             drop_position = part->pane->dock_pos;
             DoInsertPane(panes,
@@ -3251,7 +3264,7 @@ bool wxAuiManager::DoDrop(wxAuiDockInfoArray& docks,
 
         // if we are in the bottom/right part of the pane,
         // insert the pane before the pane being hovered over
-        if (offset > size/2)
+        if (mouseOffset > size/2)
         {
             drop_position = part->pane->dock_pos+1;
             DoInsertPane(panes,
@@ -3299,7 +3312,7 @@ void wxAuiManager::ShowHint(const wxRect& rect)
         m_hintFadeAmt = m_hintFadeMax;
 
         if ((m_flags & wxAUI_MGR_HINT_FADE)
-            && !((m_hintWnd->IsKindOf(CLASSINFO(wxPseudoTransparentFrame))) &&
+            && !((wxDynamicCast(m_hintWnd, wxPseudoTransparentFrame)) &&
                  (m_flags & wxAUI_MGR_NO_VENETIAN_BLINDS_FADE))
             )
             m_hintFadeAmt = 0;
@@ -3353,15 +3366,15 @@ void wxAuiManager::ShowHint(const wxRect& rect)
                     pane.frame &&
                         pane.frame->IsShown())
             {
-                wxRect rect = pane.frame->GetRect();
+                wxRect r = pane.frame->GetRect();
 #ifdef __WXGTK__
                 // wxGTK returns the client size, not the whole frame size
-                rect.width += 15;
-                rect.height += 35;
-                rect.Inflate(5);
+                r.width += 15;
+                r.height += 35;
+                r.Inflate(5);
 #endif
 
-                clip.Subtract(rect);
+                clip.Subtract(r);
             }
         }
 
@@ -3814,7 +3827,7 @@ void wxAuiManager::OnFloatingPaneActivated(wxWindow* wnd)
 {
     if ((GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE) && GetPane(wnd).IsOk())
     {
-        SetActivePane(m_panes, wnd);
+        SetActivePane(wnd);
         Repaint();
     }
 }
@@ -3945,7 +3958,7 @@ void wxAuiManager::OnSize(wxSizeEvent& event)
         Repaint();
 
 #if wxUSE_MDI
-        if (m_frame->IsKindOf(CLASSINFO(wxMDIParentFrame)))
+        if (wxDynamicCast(m_frame, wxMDIParentFrame))
         {
             // for MDI parent frames, this event must not
             // be "skipped".  In other words, the parent frame
@@ -3969,7 +3982,7 @@ void wxAuiManager::OnFindManager(wxAuiManagerEvent& evt)
     }
 
     // if we are managing a child frame, get the 'real' manager
-    if (window->IsKindOf(CLASSINFO(wxAuiFloatingFrame)))
+    if (wxDynamicCast(window, wxAuiFloatingFrame))
     {
         wxAuiFloatingFrame* float_frame = static_cast<wxAuiFloatingFrame*>(window);
         evt.SetManager(float_frame->GetOwnerManager());
@@ -4112,7 +4125,7 @@ void wxAuiManager::OnLeftDown(wxMouseEvent& event)
             if (part->pane &&
                 part->pane->window &&
                 managed_wnd &&
-                managed_wnd->IsKindOf(CLASSINFO(wxAuiFloatingFrame)))
+                wxDynamicCast(managed_wnd, wxAuiFloatingFrame))
             {
                 wxAuiFloatingFrame* floating_frame = (wxAuiFloatingFrame*)managed_wnd;
                 wxAuiManager* owner_mgr = floating_frame->GetOwnerManager();
@@ -4127,7 +4140,7 @@ void wxAuiManager::OnLeftDown(wxMouseEvent& event)
             if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
             {
                 // set the caption as active
-                SetActivePane(m_panes, part->pane->window);
+                SetActivePane(part->pane->window);
                 Repaint();
             }
 
@@ -4197,7 +4210,7 @@ bool wxAuiManager::DoEndResizeAction(wxMouseEvent& event)
 #if wxUSE_STATUSBAR
         // if there's a status control, the available
         // height decreases accordingly
-        if (m_frame && m_frame->IsKindOf(CLASSINFO(wxFrame)))
+        if (wxDynamicCast(m_frame, wxFrame))
         {
             wxFrame* frame = static_cast<wxFrame*>(m_frame);
             wxStatusBar* status = frame->GetStatusBar();
@@ -4626,7 +4639,7 @@ void wxAuiManager::OnMotion(wxMouseEvent& event)
             // We can't move the child window so we need to get the frame that
             // we want to be really moving. This is probably not the best place
             // to do this but at least it fixes the bug (#13177) for now.
-            if (!m_actionWindow->IsKindOf(CLASSINFO(wxAuiFloatingFrame)))
+            if (!wxDynamicCast(m_actionWindow, wxAuiFloatingFrame))
             {
                 wxAuiPaneInfo& pane = GetPane(m_actionWindow);
                 m_actionWindow = pane.frame;
@@ -4644,8 +4657,8 @@ void wxAuiManager::OnMotion(wxMouseEvent& event)
 
         pane.SetFlag(wxAuiPaneInfo::actionPane, true);
 
-        wxPoint pt = event.GetPosition();
-        DoDrop(m_docks, m_panes, pane, pt, m_actionOffset);
+        wxPoint point = event.GetPosition();
+        DoDrop(m_docks, m_panes, pane, point, m_actionOffset);
 
         // if DoDrop() decided to float the pane, set up
         // the floating pane's initial position
@@ -4737,7 +4750,7 @@ void wxAuiManager::OnChildFocus(wxChildFocusEvent& event)
         wxAuiPaneInfo& pane = GetPane(event.GetWindow());
         if (pane.IsOk() && (pane.state & wxAuiPaneInfo::optionActive) == 0)
         {
-            SetActivePane(m_panes, event.GetWindow());
+            SetActivePane(event.GetWindow());
             m_frame->Refresh();
         }
     }
@@ -4779,7 +4792,7 @@ void wxAuiManager::OnPaneButton(wxAuiManagerEvent& evt)
     }
     else if (evt.button == wxAUI_BUTTON_MAXIMIZE_RESTORE && !pane.IsMaximized())
     {
-        // fire pane close event
+        // fire pane maximize event
         wxAuiManagerEvent e(wxEVT_AUI_PANE_MAXIMIZE);
         e.SetManager(this);
         e.SetPane(evt.pane);
@@ -4793,7 +4806,7 @@ void wxAuiManager::OnPaneButton(wxAuiManagerEvent& evt)
     }
     else if (evt.button == wxAUI_BUTTON_MAXIMIZE_RESTORE && pane.IsMaximized())
     {
-        // fire pane close event
+        // fire pane restore event
         wxAuiManagerEvent e(wxEVT_AUI_PANE_RESTORE);
         e.SetManager(this);
         e.SetPane(evt.pane);
@@ -4805,11 +4818,29 @@ void wxAuiManager::OnPaneButton(wxAuiManagerEvent& evt)
             Update();
         }
     }
-    else if (evt.button == wxAUI_BUTTON_PIN)
+    else if (evt.button == wxAUI_BUTTON_PIN &&
+                (m_flags & wxAUI_MGR_ALLOW_FLOATING) && pane.IsFloatable())
     {
-        if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
-            pane.IsFloatable())
-                pane.Float();
+        if (pane.IsMaximized())
+        {
+            // If the pane is maximized, the original state must be restored
+            // before trying to float the pane, otherwise the other panels
+            // wouldn't appear correctly when it becomes floating.
+            wxAuiManagerEvent e(wxEVT_AUI_PANE_RESTORE);
+            e.SetManager(this);
+            e.SetPane(evt.pane);
+            ProcessMgrEvent(e);
+
+            if (e.GetVeto())
+            {
+                // If it can't be restored, it can't be floated neither.
+                return;
+            }
+
+            RestorePane(pane);
+        }
+
+        pane.Float();
         Update();
     }
 }