1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/aui/floatpane.cpp
3 // Purpose: wxaui: wx advanced user interface - docking window manager
4 // Author: Benjamin I. Williams
7 // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
8 // Licence: wxWindows Library Licence, Version 3.1
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 #include "wx/wxprec.h"
27 #include "wx/aui/framemanager.h"
28 #include "wx/aui/floatpane.h"
29 #include "wx/aui/dockart.h"
35 #include "wx/msw/private.h"
38 IMPLEMENT_CLASS(wxAuiFloatingFrame
, wxAuiFloatingFrameBaseClass
)
40 wxAuiFloatingFrame::wxAuiFloatingFrame(wxWindow
* parent
,
41 wxAuiManager
* owner_mgr
,
42 const wxAuiPaneInfo
& pane
,
43 wxWindowID id
/*= wxID_ANY*/,
44 long style
/*=wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION |
45 wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT |
48 : wxAuiFloatingFrameBaseClass(parent
, id
, wxEmptyString
,
49 pane
.floating_pos
, pane
.floating_size
,
51 (pane
.HasCloseButton()?wxCLOSE_BOX
:0) |
52 (pane
.HasMaximizeButton()?wxMAXIMIZE_BOX
:0) |
53 (pane
.IsFixed()?0:wxRESIZE_BORDER
)
56 m_ownerMgr
= owner_mgr
;
58 m_mgr
.SetManagedWindow(this);
61 // find out if the system supports solid window drag.
62 // on non-msw systems, this is assumed to be the case
65 SystemParametersInfo(38 /*SPI_GETDRAGFULLWINDOWS*/, 0, &b
, 0);
66 m_solidDrag
= b
? true : false;
69 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
72 wxAuiFloatingFrame::~wxAuiFloatingFrame()
74 // if we do not do this, then we can crash...
75 if (m_ownerMgr
&& m_ownerMgr
->m_actionWindow
== this)
77 m_ownerMgr
->m_actionWindow
= NULL
;
83 void wxAuiFloatingFrame::SetPaneWindow(const wxAuiPaneInfo
& pane
)
85 m_paneWindow
= pane
.window
;
86 m_paneWindow
->Reparent(this);
88 wxAuiPaneInfo contained_pane
= pane
;
89 contained_pane
.Dock().Center().Show().
90 CaptionVisible(false).
92 Layer(0).Row(0).Position(0);
94 // Carry over the minimum size
95 wxSize pane_min_size
= pane
.window
->GetMinSize();
97 // if the frame window's max size is greater than the min size
98 // then set the max size to the min size as well
99 wxSize cur_max_size
= GetMaxSize();
100 if (cur_max_size
.IsFullySpecified() &&
101 (cur_max_size
.x
< pane
.min_size
.x
||
102 cur_max_size
.y
< pane
.min_size
.y
)
105 SetMaxSize(pane_min_size
);
108 SetMinSize(pane
.window
->GetMinSize());
110 m_mgr
.AddPane(m_paneWindow
, contained_pane
);
113 if (pane
.min_size
.IsFullySpecified())
115 // because SetSizeHints() calls Fit() too (which sets the window
116 // size to its minimum allowed), we keep the size before calling
117 // SetSizeHints() and reset it afterwards...
118 wxSize tmp
= GetSize();
119 GetSizer()->SetSizeHints(this);
123 SetTitle(pane
.caption
);
125 // This code is slightly awkward because we need to reset wxRESIZE_BORDER
126 // before calling SetClientSize() below as doing it after setting the
127 // client size would actually change it, at least under MSW, where the
128 // total window size doesn't change and hence, as the borders size changes,
129 // the client size does change.
131 // So we must call it first but doing it generates a size event and updates
132 // pane.floating_size from inside it so we must also record its original
133 // value before doing it.
134 const bool hasFloatingSize
= pane
.floating_size
!= wxDefaultSize
;
137 SetWindowStyleFlag(GetWindowStyleFlag() & ~wxRESIZE_BORDER
);
140 if ( hasFloatingSize
)
142 SetSize(pane
.floating_size
);
146 wxSize size
= pane
.best_size
;
147 if (size
== wxDefaultSize
)
148 size
= pane
.min_size
;
149 if (size
== wxDefaultSize
)
150 size
= m_paneWindow
->GetSize();
151 if (m_ownerMgr
&& pane
.HasGripper())
153 if (pane
.HasGripperTop())
154 size
.y
+= m_ownerMgr
->m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
156 size
.x
+= m_ownerMgr
->m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
163 wxAuiManager
* wxAuiFloatingFrame::GetOwnerManager() const
169 void wxAuiFloatingFrame::OnSize(wxSizeEvent
& WXUNUSED(event
))
173 m_ownerMgr
->OnFloatingPaneResized(m_paneWindow
, GetRect());
177 void wxAuiFloatingFrame::OnClose(wxCloseEvent
& evt
)
181 m_ownerMgr
->OnFloatingPaneClosed(m_paneWindow
, evt
);
185 m_mgr
.DetachPane(m_paneWindow
);
190 void wxAuiFloatingFrame::OnMoveEvent(wxMoveEvent
& event
)
194 // systems without solid window dragging need to be
195 // handled slightly differently, due to the lack of
196 // the constant stream of EVT_MOVING events
200 OnMoving(event
.GetRect(), wxNORTH
);
206 wxRect winRect
= GetRect();
208 if (winRect
== m_lastRect
)
211 // skip the first move event
212 if (m_lastRect
.IsEmpty())
214 m_lastRect
= winRect
;
218 // as on OSX moving windows are not getting all move events, only sporadically, this difference
219 // is almost always big on OSX, so avoid this early exit opportunity
221 // skip if moving too fast to avoid massive redraws and
222 // jumping hint windows
223 if ((abs(winRect
.x
- m_lastRect
.x
) > 3) ||
224 (abs(winRect
.y
- m_lastRect
.y
) > 3))
226 m_last3Rect
= m_last2Rect
;
227 m_last2Rect
= m_lastRect
;
228 m_lastRect
= winRect
;
230 // However still update the internally stored position to avoid
231 // snapping back to the old one later.
234 m_ownerMgr
->GetPane(m_paneWindow
).
235 floating_pos
= winRect
.GetPosition();
242 // prevent frame redocking during resize
243 if (m_lastRect
.GetSize() != winRect
.GetSize())
245 m_last3Rect
= m_last2Rect
;
246 m_last2Rect
= m_lastRect
;
247 m_lastRect
= winRect
;
251 wxDirection dir
= wxALL
;
253 int horiz_dist
= abs(winRect
.x
- m_last3Rect
.x
);
254 int vert_dist
= abs(winRect
.y
- m_last3Rect
.y
);
256 if (vert_dist
>= horiz_dist
)
258 if (winRect
.y
< m_last3Rect
.y
)
265 if (winRect
.x
< m_last3Rect
.x
)
271 m_last3Rect
= m_last2Rect
;
272 m_last2Rect
= m_lastRect
;
273 m_lastRect
= winRect
;
284 if (m_last3Rect
.IsEmpty())
287 if ( event
.GetEventType() == wxEVT_MOVING
)
288 OnMoving(event
.GetRect(), dir
);
290 OnMoving(wxRect(event
.GetPosition(),GetSize()), dir
);
293 void wxAuiFloatingFrame::OnIdle(wxIdleEvent
& event
)
309 void wxAuiFloatingFrame::OnMoveStart()
311 // notify the owner manager that the pane has started to move
314 m_ownerMgr
->OnFloatingPaneMoveStart(m_paneWindow
);
318 void wxAuiFloatingFrame::OnMoving(const wxRect
& WXUNUSED(window_rect
), wxDirection dir
)
320 // notify the owner manager that the pane is moving
323 m_ownerMgr
->OnFloatingPaneMoving(m_paneWindow
, dir
);
325 m_lastDirection
= dir
;
328 void wxAuiFloatingFrame::OnMoveFinished()
330 // notify the owner manager that the pane has finished moving
333 m_ownerMgr
->OnFloatingPaneMoved(m_paneWindow
, m_lastDirection
);
337 void wxAuiFloatingFrame::OnActivate(wxActivateEvent
& event
)
339 if (m_ownerMgr
&& event
.GetActive())
341 m_ownerMgr
->OnFloatingPaneActivated(m_paneWindow
);
345 // utility function which determines the state of the mouse button
346 // (independent of having a wxMouseEvent handy) - utimately a better
347 // mechanism for this should be found (possibly by adding the
348 // functionality to wxWidgets itself)
349 bool wxAuiFloatingFrame::isMouseDown()
351 return wxGetMouseState().LeftIsDown();
355 BEGIN_EVENT_TABLE(wxAuiFloatingFrame
, wxAuiFloatingFrameBaseClass
)
356 EVT_SIZE(wxAuiFloatingFrame::OnSize
)
357 EVT_MOVE(wxAuiFloatingFrame::OnMoveEvent
)
358 EVT_MOVING(wxAuiFloatingFrame::OnMoveEvent
)
359 EVT_CLOSE(wxAuiFloatingFrame::OnClose
)
360 EVT_IDLE(wxAuiFloatingFrame::OnIdle
)
361 EVT_ACTIVATE(wxAuiFloatingFrame::OnActivate
)