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"
36 #include "wx/msw/private.h"
39 IMPLEMENT_CLASS(wxAuiFloatingFrame
, wxAuiFloatingFrameBaseClass
)
41 wxAuiFloatingFrame::wxAuiFloatingFrame(wxWindow
* parent
,
42 wxAuiManager
* owner_mgr
,
43 const wxAuiPaneInfo
& pane
,
44 wxWindowID id
/*= wxID_ANY*/,
45 long style
/*=wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION |
46 wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT |
49 : wxAuiFloatingFrameBaseClass(parent
, id
, wxEmptyString
,
50 pane
.floating_pos
, pane
.floating_size
,
52 (pane
.HasCloseButton()?wxCLOSE_BOX
:0) |
53 (pane
.HasMaximizeButton()?wxMAXIMIZE_BOX
:0) |
54 (pane
.IsFixed()?0:wxRESIZE_BORDER
)
57 m_ownerMgr
= owner_mgr
;
59 m_mgr
.SetManagedWindow(this);
62 // find out if the system supports solid window drag.
63 // on non-msw systems, this is assumed to be the case
66 SystemParametersInfo(38 /*SPI_GETDRAGFULLWINDOWS*/, 0, &b
, 0);
67 m_solidDrag
= b
? true : false;
70 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
73 wxAuiFloatingFrame::~wxAuiFloatingFrame()
75 // if we do not do this, then we can crash...
76 if (m_ownerMgr
&& m_ownerMgr
->m_actionWindow
== this)
78 m_ownerMgr
->m_actionWindow
= NULL
;
84 void wxAuiFloatingFrame::SetPaneWindow(const wxAuiPaneInfo
& pane
)
86 m_paneWindow
= pane
.window
;
87 m_paneWindow
->Reparent(this);
89 wxAuiPaneInfo contained_pane
= pane
;
90 contained_pane
.Dock().Center().Show().
91 CaptionVisible(false).
93 Layer(0).Row(0).Position(0);
95 // Carry over the minimum size
96 wxSize pane_min_size
= pane
.window
->GetMinSize();
98 // if the frame window's max size is greater than the min size
99 // then set the max size to the min size as well
100 wxSize cur_max_size
= GetMaxSize();
101 if (cur_max_size
.IsFullySpecified() &&
102 (cur_max_size
.x
< pane
.min_size
.x
||
103 cur_max_size
.y
< pane
.min_size
.y
)
106 SetMaxSize(pane_min_size
);
109 SetMinSize(pane
.window
->GetMinSize());
111 m_mgr
.AddPane(m_paneWindow
, contained_pane
);
114 if (pane
.min_size
.IsFullySpecified())
116 // because SetSizeHints() calls Fit() too (which sets the window
117 // size to its minimum allowed), we keep the size before calling
118 // SetSizeHints() and reset it afterwards...
119 wxSize tmp
= GetSize();
120 GetSizer()->SetSizeHints(this);
124 SetTitle(pane
.caption
);
126 // This code is slightly awkward because we need to reset wxRESIZE_BORDER
127 // before calling SetClientSize() below as doing it after setting the
128 // client size would actually change it, at least under MSW, where the
129 // total window size doesn't change and hence, as the borders size changes,
130 // the client size does change.
132 // So we must call it first but doing it generates a size event and updates
133 // pane.floating_size from inside it so we must also record its original
134 // value before doing it.
135 const bool hasFloatingSize
= pane
.floating_size
!= wxDefaultSize
;
138 SetWindowStyleFlag(GetWindowStyleFlag() & ~wxRESIZE_BORDER
);
141 if ( hasFloatingSize
)
143 SetSize(pane
.floating_size
);
147 wxSize size
= pane
.best_size
;
148 if (size
== wxDefaultSize
)
149 size
= pane
.min_size
;
150 if (size
== wxDefaultSize
)
151 size
= m_paneWindow
->GetSize();
152 if (m_ownerMgr
&& pane
.HasGripper())
154 if (pane
.HasGripperTop())
155 size
.y
+= m_ownerMgr
->m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
157 size
.x
+= m_ownerMgr
->m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
164 wxAuiManager
* wxAuiFloatingFrame::GetOwnerManager() const
170 void wxAuiFloatingFrame::OnSize(wxSizeEvent
& WXUNUSED(event
))
174 m_ownerMgr
->OnFloatingPaneResized(m_paneWindow
, GetRect());
178 void wxAuiFloatingFrame::OnClose(wxCloseEvent
& evt
)
182 m_ownerMgr
->OnFloatingPaneClosed(m_paneWindow
, evt
);
186 m_mgr
.DetachPane(m_paneWindow
);
191 void wxAuiFloatingFrame::OnMoveEvent(wxMoveEvent
& event
)
195 // systems without solid window dragging need to be
196 // handled slightly differently, due to the lack of
197 // the constant stream of EVT_MOVING events
201 OnMoving(event
.GetRect(), wxNORTH
);
207 wxRect winRect
= GetRect();
209 if (winRect
== m_lastRect
)
212 // skip the first move event
213 if (m_lastRect
.IsEmpty())
215 m_lastRect
= winRect
;
219 // skip if moving too fast to avoid massive redraws and
220 // jumping hint windows
221 if ((abs(winRect
.x
- m_lastRect
.x
) > 3) ||
222 (abs(winRect
.y
- m_lastRect
.y
) > 3))
224 m_last3Rect
= m_last2Rect
;
225 m_last2Rect
= m_lastRect
;
226 m_lastRect
= winRect
;
228 // However still update the internally stored position to avoid
229 // snapping back to the old one later.
232 m_ownerMgr
->GetPane(m_paneWindow
).
233 floating_pos
= winRect
.GetPosition();
239 // prevent frame redocking during resize
240 if (m_lastRect
.GetSize() != winRect
.GetSize())
242 m_last3Rect
= m_last2Rect
;
243 m_last2Rect
= m_lastRect
;
244 m_lastRect
= winRect
;
248 wxDirection dir
= wxALL
;
250 int horiz_dist
= abs(winRect
.x
- m_last3Rect
.x
);
251 int vert_dist
= abs(winRect
.y
- m_last3Rect
.y
);
253 if (vert_dist
>= horiz_dist
)
255 if (winRect
.y
< m_last3Rect
.y
)
262 if (winRect
.x
< m_last3Rect
.x
)
268 m_last3Rect
= m_last2Rect
;
269 m_last2Rect
= m_lastRect
;
270 m_lastRect
= winRect
;
281 if (m_last3Rect
.IsEmpty())
284 OnMoving(event
.GetRect(), dir
);
287 void wxAuiFloatingFrame::OnIdle(wxIdleEvent
& event
)
303 void wxAuiFloatingFrame::OnMoveStart()
305 // notify the owner manager that the pane has started to move
308 m_ownerMgr
->OnFloatingPaneMoveStart(m_paneWindow
);
312 void wxAuiFloatingFrame::OnMoving(const wxRect
& WXUNUSED(window_rect
), wxDirection dir
)
314 // notify the owner manager that the pane is moving
317 m_ownerMgr
->OnFloatingPaneMoving(m_paneWindow
, dir
);
319 m_lastDirection
= dir
;
322 void wxAuiFloatingFrame::OnMoveFinished()
324 // notify the owner manager that the pane has finished moving
327 m_ownerMgr
->OnFloatingPaneMoved(m_paneWindow
, m_lastDirection
);
331 void wxAuiFloatingFrame::OnActivate(wxActivateEvent
& event
)
333 if (m_ownerMgr
&& event
.GetActive())
335 m_ownerMgr
->OnFloatingPaneActivated(m_paneWindow
);
339 // utility function which determines the state of the mouse button
340 // (independant of having a wxMouseEvent handy) - utimately a better
341 // mechanism for this should be found (possibly by adding the
342 // functionality to wxWidgets itself)
343 bool wxAuiFloatingFrame::isMouseDown()
345 return wxGetMouseState().LeftIsDown();
349 BEGIN_EVENT_TABLE(wxAuiFloatingFrame
, wxAuiFloatingFrameBaseClass
)
350 EVT_SIZE(wxAuiFloatingFrame::OnSize
)
351 EVT_MOVE(wxAuiFloatingFrame::OnMoveEvent
)
352 EVT_MOVING(wxAuiFloatingFrame::OnMoveEvent
)
353 EVT_CLOSE(wxAuiFloatingFrame::OnClose
)
354 EVT_IDLE(wxAuiFloatingFrame::OnIdle
)
355 EVT_ACTIVATE(wxAuiFloatingFrame::OnActivate
)