1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/aui/floatpane.cpp
3 // Purpose: wxaui: wx advanced user interface - docking window manager
4 // Author: Benjamin I. Williams
8 // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
9 // Licence: wxWindows Library Licence, Version 3.1
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/aui/framemanager.h"
29 #include "wx/aui/floatpane.h"
30 #include "wx/aui/dockart.h"
35 IMPLEMENT_CLASS( wxFloatingPane
, wxFloatingPaneBaseClass
)
37 wxFloatingPane::wxFloatingPane(wxWindow
* parent
,
38 wxFrameManager
* owner_mgr
,
39 const wxPaneInfo
& pane
,
40 wxWindowID id
/*= wxID_ANY*/)
41 : wxFloatingPaneBaseClass(parent
, id
, wxEmptyString
,
42 pane
.floating_pos
, pane
.floating_size
,
43 wxRESIZE_BORDER
| wxSYSTEM_MENU
| wxCAPTION
|
44 (pane
.HasCloseButton()?wxCLOSE_BOX
:0) |
46 wxFRAME_FLOAT_ON_PARENT
| wxCLIP_CHILDREN
|
47 (pane
.IsFixed()?0:wxRESIZE_BORDER
)
50 m_owner_mgr
= owner_mgr
;
52 m_mgr
.SetManagedWindow(this);
53 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
56 wxFloatingPane::~wxFloatingPane()
61 void wxFloatingPane::SetPaneWindow(const wxPaneInfo
& pane
)
63 m_pane_window
= pane
.window
;
64 m_pane_window
->Reparent(this);
66 wxPaneInfo contained_pane
= pane
;
67 contained_pane
.Dock().Center().Show().
68 CaptionVisible(false).
70 Layer(0).Row(0).Position(0);
72 // Carry over the minimum size
73 SetMinSize(pane
.window
->GetMinSize());
75 m_mgr
.AddPane(m_pane_window
, contained_pane
);
78 if (pane
.min_size
.IsFullySpecified())
80 // because SetSizeHints() calls Fit() too (which sets the window
81 // size to its minimum allowed), we keep the size before calling
82 // SetSizeHints() and reset it afterwards...
83 wxSize tmp
= GetSize();
84 GetSizer()->SetSizeHints(this);
88 SetTitle(pane
.caption
);
90 if (pane
.floating_size
!= wxDefaultSize
)
92 SetSize(pane
.floating_size
);
96 wxSize size
= pane
.best_size
;
97 if (size
== wxDefaultSize
)
99 if (size
== wxDefaultSize
)
100 size
= m_pane_window
->GetSize();
101 if (pane
.HasGripper())
103 if (pane
.HasGripperTop())
104 size
.y
+= m_owner_mgr
->m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
106 size
.x
+= m_owner_mgr
->m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
113 void wxFloatingPane::OnSize(wxSizeEvent
& event
)
115 m_owner_mgr
->OnFloatingPaneResized(m_pane_window
, event
.GetSize());
118 void wxFloatingPane::OnClose(wxCloseEvent
& evt
)
120 m_owner_mgr
->OnFloatingPaneClosed(m_pane_window
, evt
);
125 void wxFloatingPane::OnMoveEvent(wxMoveEvent
& event
)
127 wxRect win_rect
= GetRect();
129 if (win_rect
== m_last_rect
)
132 // skip the first move event
133 if (m_last_rect
.IsEmpty())
135 m_last_rect
= win_rect
;
139 // skip if moving too fast to avoid massive redraws and
140 // jumping hint windows
141 if ((abs(win_rect
.x
- m_last_rect
.x
) > 3) ||
142 (abs(win_rect
.y
- m_last_rect
.y
) > 3))
144 m_last3_rect
= m_last2_rect
;
145 m_last2_rect
= m_last_rect
;
146 m_last_rect
= win_rect
;
150 // prevent frame redocking during resize
151 if (m_last_rect
.GetSize() != win_rect
.GetSize())
153 m_last3_rect
= m_last2_rect
;
154 m_last2_rect
= m_last_rect
;
155 m_last_rect
= win_rect
;
159 wxDirection dir
= wxALL
;
161 int horiz_dist
= abs(win_rect
.x
- m_last3_rect
.x
);
162 int vert_dist
= abs(win_rect
.y
- m_last3_rect
.y
);
164 if (vert_dist
>= horiz_dist
)
166 if (win_rect
.y
< m_last3_rect
.y
)
173 if (win_rect
.x
< m_last3_rect
.x
)
179 m_last3_rect
= m_last2_rect
;
180 m_last2_rect
= m_last_rect
;
181 m_last_rect
= win_rect
;
192 if (m_last3_rect
.IsEmpty())
195 OnMoving(event
.GetRect(), dir
);
198 void wxFloatingPane::OnIdle(wxIdleEvent
& event
)
214 void wxFloatingPane::OnMoveStart()
216 // notify the owner manager that the pane has started to move
217 m_owner_mgr
->OnFloatingPaneMoveStart(m_pane_window
);
220 void wxFloatingPane::OnMoving(const wxRect
& WXUNUSED(window_rect
), wxDirection dir
)
222 // notify the owner manager that the pane is moving
223 m_owner_mgr
->OnFloatingPaneMoving(m_pane_window
, dir
);
224 m_lastDirection
= dir
;
227 void wxFloatingPane::OnMoveFinished()
229 // notify the owner manager that the pane has finished moving
230 m_owner_mgr
->OnFloatingPaneMoved(m_pane_window
, m_lastDirection
);
233 void wxFloatingPane::OnActivate(wxActivateEvent
& event
)
235 if (event
.GetActive())
237 m_owner_mgr
->OnFloatingPaneActivated(m_pane_window
);
241 // utility function which determines the state of the mouse button
242 // (independant of having a wxMouseEvent handy) - utimately a better
243 // mechanism for this should be found (possibly by adding the
244 // functionality to wxWidgets itself)
245 bool wxFloatingPane::isMouseDown()
247 return wxGetMouseState().LeftDown();
251 BEGIN_EVENT_TABLE(wxFloatingPane
, wxFloatingPaneBaseClass
)
252 EVT_SIZE(wxFloatingPane::OnSize
)
253 EVT_MOVE(wxFloatingPane::OnMoveEvent
)
254 EVT_MOVING(wxFloatingPane::OnMoveEvent
)
255 EVT_CLOSE(wxFloatingPane::OnClose
)
256 EVT_IDLE(wxFloatingPane::OnIdle
)
257 EVT_ACTIVATE(wxFloatingPane::OnActivate
)