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