floatpane.cpp

Go to the documentation of this file.
00001 
00002 // Name:        src/aui/floatpane.cpp
00003 // Purpose:     wxaui: wx advanced user interface - docking window manager
00004 // Author:      Benjamin I. Williams
00005 // Modified by:
00006 // Created:     2005-05-17
00007 // RCS-ID:      $Id: floatpane.cpp,v 1.5 2006/07/05 16:38:01 BIW Exp $
00008 // Copyright:   (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
00009 // Licence:     wxWindows Library Licence, Version 3.1
00011 
00012 // ============================================================================
00013 // declarations
00014 // ============================================================================
00015 
00016 // ----------------------------------------------------------------------------
00017 // headers
00018 // ----------------------------------------------------------------------------
00019 
00020 #include "framemanager.h"
00021 #include "floatpane.h"
00022 #include "dockart.h"
00023 
00024 #if wxXTRA_AUI
00025 
00026 IMPLEMENT_CLASS( wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass )
00027 
00028 wxAuiFloatingFrame::wxAuiFloatingFrame(wxWindow* parent,
00029                 wxAuiManager* owner_mgr,
00030                 const wxAuiPaneInfo& pane,
00031                 wxWindowID id /*= wxID_ANY*/)
00032                 : wxAuiFloatingFrameBaseClass(parent, id, wxEmptyString,
00033                         pane.floating_pos, pane.floating_size,
00034                         wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION |
00035                         (pane.HasCloseButton()?wxCLOSE_BOX:0) |
00036                         wxFRAME_NO_TASKBAR |
00037                         wxFRAME_FLOAT_ON_PARENT | wxCLIP_CHILDREN |
00038                         (pane.IsFixed()?0:wxRESIZE_BORDER)
00039                         )
00040 {
00041     m_owner_mgr = owner_mgr;
00042     m_moving = false;
00043     m_last_rect = wxRect();
00044     m_mgr.SetManagedWindow(this);
00045     SetExtraStyle(wxWS_EX_PROCESS_IDLE);
00046 }
00047 
00048 wxAuiFloatingFrame::~wxAuiFloatingFrame()
00049 {
00050     m_mgr.UnInit();
00051 }
00052 
00053 void wxAuiFloatingFrame::SetPaneWindow(const wxAuiPaneInfo& pane)
00054 {
00055     m_pane_window = pane.window;
00056     m_pane_window->Reparent(this);
00057 
00058     wxAuiPaneInfo contained_pane = pane;
00059     contained_pane.Dock().Center().Show().
00060                     CaptionVisible(false).
00061                     PaneBorder(false).
00062                     Layer(0).Row(0).Position(0);
00063 
00064     // Carry over the minimum size
00065     SetMinSize(pane.window->GetMinSize());
00066 
00067     m_mgr.AddPane(m_pane_window, contained_pane);
00068     m_mgr.Update();
00069 
00070     if (pane.min_size.IsFullySpecified())
00071     {
00072         // because SetSizeHints() calls Fit() too (which sets the window
00073         // size to its minimum allowed), we keep the size before calling
00074         // SetSizeHints() and reset it afterwards...
00075         wxSize tmp = GetSize();
00076         GetSizer()->SetSizeHints(this);
00077         SetSize(tmp);
00078     }
00079 
00080     SetTitle(pane.caption);
00081 
00082     if (pane.floating_size != wxDefaultSize)
00083     {
00084         SetSize(pane.floating_size);
00085     }
00086         else
00087     {
00088         wxSize size = pane.best_size;
00089         if (size == wxDefaultSize)
00090             size = pane.min_size;
00091         if (size == wxDefaultSize)
00092             size = m_pane_window->GetSize();
00093         if (pane.HasGripper())
00094         {
00095             if (pane.HasGripperTop())
00096                 size.y += m_owner_mgr->m_art->GetMetric(wxAUI_ART_GRIPPER_SIZE);
00097             else
00098                 size.x += m_owner_mgr->m_art->GetMetric(wxAUI_ART_GRIPPER_SIZE);
00099         }
00100 
00101         SetClientSize(size);
00102     }
00103 }
00104 
00105 void wxAuiFloatingFrame::OnSize(wxSizeEvent& event)
00106 {
00107     m_owner_mgr->OnFloatingPaneResized(m_pane_window, event.GetSize());
00108 }
00109 
00110 void wxAuiFloatingFrame::OnClose(wxCloseEvent& evt)
00111 {
00112     m_owner_mgr->OnFloatingPaneClosed(m_pane_window, evt);
00113     if (!evt.GetVeto())
00114         Destroy();
00115 }
00116 
00117 void wxAuiFloatingFrame::OnMoveEvent(wxMoveEvent& event)
00118 {
00119 #ifdef __WXGTK__
00120     // On wxGTK 2.6 and 2.7 for some unknown reason, wxSizeEvents are not
00121     // emitted for wxAuiFloatingFrames when they are manually resized.
00122     // See Bug #1528554.
00123     // However, it does (fortunately) wrongly emit wxMoveEvent in this scenario.
00124     // So we having on that to update the floating pane size - let's hope noone
00125     // fixes this useful bug, without fixing the above.
00126     m_owner_mgr->OnFloatingPaneResized(m_pane_window, GetSize());
00127 #endif
00128 
00129     wxRect win_rect = GetRect();
00130 
00131     // skip the first move event
00132     if (m_last_rect.IsEmpty())
00133     {
00134         m_last_rect = win_rect;
00135         return;
00136     }
00137 
00138     // prevent frame redocking during resize
00139     if (m_last_rect.GetSize() != win_rect.GetSize())
00140     {
00141         m_last_rect = win_rect;
00142         return;
00143     }
00144 
00145     m_last_rect = win_rect;
00146 
00147     if (!isMouseDown())
00148         return;
00149 
00150     if (!m_moving)
00151     {
00152         OnMoveStart();
00153         m_moving = true;
00154     }
00155 
00156     OnMoving(event.GetRect());
00157 }
00158 
00159 void wxAuiFloatingFrame::OnIdle(wxIdleEvent& event)
00160 {
00161     if (m_moving)
00162     {
00163         if (!isMouseDown())
00164         {
00165             m_moving = false;
00166             OnMoveFinished();
00167         }
00168             else
00169         {
00170             event.RequestMore();
00171         }
00172     }
00173 }
00174 
00175 void wxAuiFloatingFrame::OnMoveStart()
00176 {
00177     // notify the owner manager that the pane has started to move
00178     m_owner_mgr->OnFloatingPaneMoveStart(m_pane_window);
00179 }
00180 
00181 void wxAuiFloatingFrame::OnMoving(const wxRect& WXUNUSED(window_rect))
00182 {
00183     // notify the owner manager that the pane is moving
00184     m_owner_mgr->OnFloatingPaneMoving(m_pane_window);
00185 }
00186 
00187 void wxAuiFloatingFrame::OnMoveFinished()
00188 {
00189     // notify the owner manager that the pane has finished moving
00190     m_owner_mgr->OnFloatingPaneMoved(m_pane_window);
00191 }
00192 
00193 void wxAuiFloatingFrame::OnActivate(wxActivateEvent& event)
00194 {
00195     if (event.GetActive())
00196     {
00197         m_owner_mgr->OnFloatingPaneActivated(m_pane_window);
00198     }
00199 }
00200 
00201 // utility function which determines the state of the mouse button
00202 // (independant of having a wxMouseEvent handy) - utimately a better
00203 // mechanism for this should be found (possibly by adding the
00204 // functionality to wxWidgets itself)
00205 bool wxAuiFloatingFrame::isMouseDown()
00206 {
00207     return wxGetMouseState().LeftDown();
00208 }
00209 
00210 
00211 BEGIN_EVENT_TABLE(wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass)
00212     EVT_SIZE(wxAuiFloatingFrame::OnSize)
00213     EVT_MOVE(wxAuiFloatingFrame::OnMoveEvent)
00214     EVT_MOVING(wxAuiFloatingFrame::OnMoveEvent)
00215     EVT_CLOSE(wxAuiFloatingFrame::OnClose)
00216     EVT_IDLE(wxAuiFloatingFrame::OnIdle)
00217     EVT_ACTIVATE(wxAuiFloatingFrame::OnActivate)
00218 END_EVENT_TABLE()
00219 
00220 #endif // wxUSE_AUI

Generated on Sat Nov 10 03:49:00 2007 for Camelot by  doxygen 1.4.4