]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/aui/floatpane.cpp
missing commit
[wxWidgets.git] / src / aui / floatpane.cpp
... / ...
CommitLineData
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/aui/floatpane.cpp
3// Purpose: wxaui: wx advanced user interface - docking window manager
4// Author: Benjamin I. Williams
5// Modified by:
6// Created: 2005-05-17
7// RCS-ID: $Id$
8// Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
9// Licence: wxWindows Library Licence, Version 3.1
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#if wxUSE_AUI
27
28#include "wx/aui/framemanager.h"
29#include "wx/aui/floatpane.h"
30#include "wx/aui/dockart.h"
31
32#ifndef WX_PRECOMP
33#endif
34
35#ifdef __WXMSW__
36#include "wx/msw/private.h"
37#endif
38
39IMPLEMENT_CLASS(wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass)
40
41wxAuiFloatingFrame::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 |
47 wxCLIP_CHILDREN
48 */)
49 : wxAuiFloatingFrameBaseClass(parent, id, wxEmptyString,
50 pane.floating_pos, pane.floating_size,
51 style |
52 (pane.HasCloseButton()?wxCLOSE_BOX:0) |
53 (pane.HasMaximizeButton()?wxMAXIMIZE_BOX:0) |
54 (pane.IsFixed()?0:wxRESIZE_BORDER)
55 )
56{
57 m_ownerMgr = owner_mgr;
58 m_moving = false;
59 m_mgr.SetManagedWindow(this);
60 m_solidDrag = true;
61
62 // find out if the system supports solid window drag.
63 // on non-msw systems, this is assumed to be the case
64#ifdef __WXMSW__
65 BOOL b = TRUE;
66 SystemParametersInfo(38 /*SPI_GETDRAGFULLWINDOWS*/, 0, &b, 0);
67 m_solidDrag = b ? true : false;
68#endif
69
70 SetExtraStyle(wxWS_EX_PROCESS_IDLE);
71}
72
73wxAuiFloatingFrame::~wxAuiFloatingFrame()
74{
75 // if we do not do this, then we can crash...
76 if (m_ownerMgr && m_ownerMgr->m_actionWindow == this)
77 {
78 m_ownerMgr->m_actionWindow = NULL;
79 }
80
81 m_mgr.UnInit();
82}
83
84void wxAuiFloatingFrame::SetPaneWindow(const wxAuiPaneInfo& pane)
85{
86 m_paneWindow = pane.window;
87 m_paneWindow->Reparent(this);
88
89 wxAuiPaneInfo contained_pane = pane;
90 contained_pane.Dock().Center().Show().
91 CaptionVisible(false).
92 PaneBorder(false).
93 Layer(0).Row(0).Position(0);
94
95 // Carry over the minimum size
96 wxSize pane_min_size = pane.window->GetMinSize();
97
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)
104 )
105 {
106 SetMaxSize(pane_min_size);
107 }
108
109 SetMinSize(pane.window->GetMinSize());
110
111 m_mgr.AddPane(m_paneWindow, contained_pane);
112 m_mgr.Update();
113
114 if (pane.min_size.IsFullySpecified())
115 {
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);
121 SetSize(tmp);
122 }
123
124 SetTitle(pane.caption);
125
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.
131 //
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;
136 if (pane.IsFixed())
137 {
138 SetWindowStyleFlag(GetWindowStyleFlag() & ~wxRESIZE_BORDER);
139 }
140
141 if ( hasFloatingSize )
142 {
143 SetSize(pane.floating_size);
144 }
145 else
146 {
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())
153 {
154 if (pane.HasGripperTop())
155 size.y += m_ownerMgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE);
156 else
157 size.x += m_ownerMgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE);
158 }
159
160 SetClientSize(size);
161 }
162}
163
164wxAuiManager* wxAuiFloatingFrame::GetOwnerManager() const
165{
166 return m_ownerMgr;
167}
168
169
170void wxAuiFloatingFrame::OnSize(wxSizeEvent& WXUNUSED(event))
171{
172 if (m_ownerMgr)
173 {
174 m_ownerMgr->OnFloatingPaneResized(m_paneWindow, GetRect());
175 }
176}
177
178void wxAuiFloatingFrame::OnClose(wxCloseEvent& evt)
179{
180 if (m_ownerMgr)
181 {
182 m_ownerMgr->OnFloatingPaneClosed(m_paneWindow, evt);
183 }
184 if (!evt.GetVeto())
185 {
186 m_mgr.DetachPane(m_paneWindow);
187 Destroy();
188 }
189}
190
191void wxAuiFloatingFrame::OnMoveEvent(wxMoveEvent& event)
192{
193 if (!m_solidDrag)
194 {
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
198 if (!isMouseDown())
199 return;
200 OnMoveStart();
201 OnMoving(event.GetRect(), wxNORTH);
202 m_moving = true;
203 return;
204 }
205
206
207 wxRect winRect = GetRect();
208
209 if (winRect == m_lastRect)
210 return;
211
212 // skip the first move event
213 if (m_lastRect.IsEmpty())
214 {
215 m_lastRect = winRect;
216 return;
217 }
218
219 // as on OSX moving windows are not getting all move events, only sporadically, this difference
220 // is almost always big on OSX, so avoid this early exit opportunity
221#ifndef __WXOSX__
222 // skip if moving too fast to avoid massive redraws and
223 // jumping hint windows
224 if ((abs(winRect.x - m_lastRect.x) > 3) ||
225 (abs(winRect.y - m_lastRect.y) > 3))
226 {
227 m_last3Rect = m_last2Rect;
228 m_last2Rect = m_lastRect;
229 m_lastRect = winRect;
230
231 // However still update the internally stored position to avoid
232 // snapping back to the old one later.
233 if (m_ownerMgr)
234 {
235 m_ownerMgr->GetPane(m_paneWindow).
236 floating_pos = winRect.GetPosition();
237 }
238
239 return;
240 }
241#endif
242
243 // prevent frame redocking during resize
244 if (m_lastRect.GetSize() != winRect.GetSize())
245 {
246 m_last3Rect = m_last2Rect;
247 m_last2Rect = m_lastRect;
248 m_lastRect = winRect;
249 return;
250 }
251
252 wxDirection dir = wxALL;
253
254 int horiz_dist = abs(winRect.x - m_last3Rect.x);
255 int vert_dist = abs(winRect.y - m_last3Rect.y);
256
257 if (vert_dist >= horiz_dist)
258 {
259 if (winRect.y < m_last3Rect.y)
260 dir = wxNORTH;
261 else
262 dir = wxSOUTH;
263 }
264 else
265 {
266 if (winRect.x < m_last3Rect.x)
267 dir = wxWEST;
268 else
269 dir = wxEAST;
270 }
271
272 m_last3Rect = m_last2Rect;
273 m_last2Rect = m_lastRect;
274 m_lastRect = winRect;
275
276 if (!isMouseDown())
277 return;
278
279 if (!m_moving)
280 {
281 OnMoveStart();
282 m_moving = true;
283 }
284
285 if (m_last3Rect.IsEmpty())
286 return;
287
288 if ( event.GetEventType() == wxEVT_MOVING )
289 OnMoving(event.GetRect(), dir);
290 else
291 OnMoving(wxRect(event.GetPosition(),GetSize()), dir);
292}
293
294void wxAuiFloatingFrame::OnIdle(wxIdleEvent& event)
295{
296 if (m_moving)
297 {
298 if (!isMouseDown())
299 {
300 m_moving = false;
301 OnMoveFinished();
302 }
303 else
304 {
305 event.RequestMore();
306 }
307 }
308}
309
310void wxAuiFloatingFrame::OnMoveStart()
311{
312 // notify the owner manager that the pane has started to move
313 if (m_ownerMgr)
314 {
315 m_ownerMgr->OnFloatingPaneMoveStart(m_paneWindow);
316 }
317}
318
319void wxAuiFloatingFrame::OnMoving(const wxRect& WXUNUSED(window_rect), wxDirection dir)
320{
321 // notify the owner manager that the pane is moving
322 if (m_ownerMgr)
323 {
324 m_ownerMgr->OnFloatingPaneMoving(m_paneWindow, dir);
325 }
326 m_lastDirection = dir;
327}
328
329void wxAuiFloatingFrame::OnMoveFinished()
330{
331 // notify the owner manager that the pane has finished moving
332 if (m_ownerMgr)
333 {
334 m_ownerMgr->OnFloatingPaneMoved(m_paneWindow, m_lastDirection);
335 }
336}
337
338void wxAuiFloatingFrame::OnActivate(wxActivateEvent& event)
339{
340 if (m_ownerMgr && event.GetActive())
341 {
342 m_ownerMgr->OnFloatingPaneActivated(m_paneWindow);
343 }
344}
345
346// utility function which determines the state of the mouse button
347// (independent of having a wxMouseEvent handy) - utimately a better
348// mechanism for this should be found (possibly by adding the
349// functionality to wxWidgets itself)
350bool wxAuiFloatingFrame::isMouseDown()
351{
352 return wxGetMouseState().LeftIsDown();
353}
354
355
356BEGIN_EVENT_TABLE(wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass)
357 EVT_SIZE(wxAuiFloatingFrame::OnSize)
358 EVT_MOVE(wxAuiFloatingFrame::OnMoveEvent)
359 EVT_MOVING(wxAuiFloatingFrame::OnMoveEvent)
360 EVT_CLOSE(wxAuiFloatingFrame::OnClose)
361 EVT_IDLE(wxAuiFloatingFrame::OnIdle)
362 EVT_ACTIVATE(wxAuiFloatingFrame::OnActivate)
363END_EVENT_TABLE()
364
365
366#endif // wxUSE_AUI