]> git.saurik.com Git - wxWidgets.git/blame - src/aui/floatpane.cpp
supporting -1 as 'to' parameter for selections
[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
be66f18e 7// RCS-ID: $Id$
50acee04
JS
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
50acee04
JS
33#endif
34
20d64475
RR
35#ifdef __WXMSW__
36#include "wx/msw/private.h"
37#endif
38
4dc79cfb 39IMPLEMENT_CLASS(wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass)
e5ab82d3 40
00c1c94c 41wxAuiFloatingFrame::wxAuiFloatingFrame(wxWindow* parent,
a3a5df9d
BW
42 wxAuiManager* owner_mgr,
43 const wxAuiPaneInfo& pane,
bc429ce0
RR
44 wxWindowID id /*= wxID_ANY*/,
45 long style /*=wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION |
cedd7b22 46 wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT |
bc429ce0
RR
47 wxCLIP_CHILDREN
48 */)
00c1c94c 49 : wxAuiFloatingFrameBaseClass(parent, id, wxEmptyString,
e5ab82d3 50 pane.floating_pos, pane.floating_size,
cedd7b22 51 style |
96743140 52 (pane.HasCloseButton()?wxCLOSE_BOX:0) |
74a94478 53 (pane.HasMaximizeButton()?wxMAXIMIZE_BOX:0) |
e5ab82d3
AB
54 (pane.IsFixed()?0:wxRESIZE_BORDER)
55 )
50acee04
JS
56{
57 m_owner_mgr = owner_mgr;
58 m_moving = false;
461125ea 59 m_mgr.SetManagedWindow(this);
22fec94a 60 m_solid_drag = true;
cedd7b22 61
22fec94a
BW
62 // find out if the system supports solid window drag.
63 // on non-msw systems, this is assumed to be the case
20d64475 64#ifdef __WXMSW__
bc119dd5 65 BOOL b = TRUE;
22fec94a
BW
66 SystemParametersInfo(38 /*SPI_GETDRAGFULLWINDOWS*/, 0, &b, 0);
67 m_solid_drag = b ? true : false;
20d64475 68#endif
cedd7b22 69
322c5ec4 70 SetExtraStyle(wxWS_EX_PROCESS_IDLE);
50acee04
JS
71}
72
00c1c94c 73wxAuiFloatingFrame::~wxAuiFloatingFrame()
50acee04 74{
20d64475 75 // if we do not do this, then we can crash...
4dc79cfb
BW
76 if(m_owner_mgr && m_owner_mgr->m_action_window == this)
77 {
20d64475
RR
78 m_owner_mgr->m_action_window = NULL;
79 }
50acee04
JS
80 m_mgr.UnInit();
81}
82
00c1c94c 83void wxAuiFloatingFrame::SetPaneWindow(const wxAuiPaneInfo& pane)
50acee04
JS
84{
85 m_pane_window = pane.window;
86 m_pane_window->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
50acee04 110 m_mgr.AddPane(m_pane_window, 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
50acee04
JS
125 if (pane.floating_size != wxDefaultSize)
126 {
127 SetSize(pane.floating_size);
128 }
cedd7b22 129 else
50acee04
JS
130 {
131 wxSize size = pane.best_size;
132 if (size == wxDefaultSize)
133 size = pane.min_size;
134 if (size == wxDefaultSize)
135 size = m_pane_window->GetSize();
136 if (pane.HasGripper())
137 {
138 if (pane.HasGripperTop())
254a3429 139 size.y += m_owner_mgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE);
50acee04 140 else
254a3429 141 size.x += m_owner_mgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE);
50acee04 142 }
be66f18e 143
50acee04
JS
144 SetClientSize(size);
145 }
146}
147
4dc79cfb
BW
148wxAuiManager* wxAuiFloatingFrame::GetOwnerManager() const
149{
150 return m_owner_mgr;
151}
152
153
00c1c94c 154void wxAuiFloatingFrame::OnSize(wxSizeEvent& event)
50acee04
JS
155{
156 m_owner_mgr->OnFloatingPaneResized(m_pane_window, event.GetSize());
157}
158
00c1c94c 159void wxAuiFloatingFrame::OnClose(wxCloseEvent& evt)
50acee04 160{
58754643 161 m_owner_mgr->OnFloatingPaneClosed(m_pane_window, evt);
a23717e5 162 if (!evt.GetVeto()) {
cedd7b22 163 m_mgr.DetachPane(m_pane_window);
c68038f3 164 Destroy();
a23717e5 165 }
50acee04
JS
166}
167
00c1c94c 168void wxAuiFloatingFrame::OnMoveEvent(wxMoveEvent& event)
50acee04 169{
22fec94a
BW
170 if (!m_solid_drag)
171 {
172 // systems without solid window dragging need to be
173 // handled slightly differently, due to the lack of
174 // the constant stream of EVT_MOVING events
175 if (!isMouseDown())
176 return;
177 OnMoveStart();
178 OnMoving(event.GetRect(), wxNORTH);
179 m_moving = true;
180 return;
181 }
cedd7b22
PC
182
183
50acee04
JS
184 wxRect win_rect = GetRect();
185
322c5ec4
RR
186 if (win_rect == m_last_rect)
187 return;
188
50acee04
JS
189 // skip the first move event
190 if (m_last_rect.IsEmpty())
191 {
192 m_last_rect = win_rect;
193 return;
194 }
195
cedd7b22 196 // skip if moving too fast to avoid massive redraws and
322c5ec4
RR
197 // jumping hint windows
198 if ((abs(win_rect.x - m_last_rect.x) > 3) ||
199 (abs(win_rect.y - m_last_rect.y) > 3))
0ae3bace 200 {
322c5ec4
RR
201 m_last3_rect = m_last2_rect;
202 m_last2_rect = m_last_rect;
0ae3bace
RR
203 m_last_rect = win_rect;
204 return;
205 }
206
50acee04
JS
207 // prevent frame redocking during resize
208 if (m_last_rect.GetSize() != win_rect.GetSize())
209 {
322c5ec4
RR
210 m_last3_rect = m_last2_rect;
211 m_last2_rect = m_last_rect;
50acee04
JS
212 m_last_rect = win_rect;
213 return;
214 }
215
322c5ec4 216 wxDirection dir = wxALL;
cedd7b22 217
322c5ec4
RR
218 int horiz_dist = abs(win_rect.x - m_last3_rect.x);
219 int vert_dist = abs(win_rect.y - m_last3_rect.y);
cedd7b22 220
322c5ec4
RR
221 if (vert_dist >= horiz_dist)
222 {
223 if (win_rect.y < m_last3_rect.y)
224 dir = wxNORTH;
225 else
226 dir = wxSOUTH;
227 }
228 else
229 {
230 if (win_rect.x < m_last3_rect.x)
231 dir = wxWEST;
232 else
233 dir = wxEAST;
234 }
cedd7b22 235
322c5ec4
RR
236 m_last3_rect = m_last2_rect;
237 m_last2_rect = m_last_rect;
50acee04 238 m_last_rect = win_rect;
be66f18e 239
50acee04
JS
240 if (!isMouseDown())
241 return;
242
243 if (!m_moving)
244 {
245 OnMoveStart();
246 m_moving = true;
247 }
248
322c5ec4
RR
249 if (m_last3_rect.IsEmpty())
250 return;
cedd7b22 251
22fec94a 252 OnMoving(event.GetRect(), dir);
50acee04
JS
253}
254
00c1c94c 255void wxAuiFloatingFrame::OnIdle(wxIdleEvent& event)
50acee04
JS
256{
257 if (m_moving)
258 {
259 if (!isMouseDown())
260 {
261 m_moving = false;
262 OnMoveFinished();
263 }
cedd7b22 264 else
50acee04
JS
265 {
266 event.RequestMore();
267 }
268 }
269}
270
00c1c94c 271void wxAuiFloatingFrame::OnMoveStart()
50acee04
JS
272{
273 // notify the owner manager that the pane has started to move
274 m_owner_mgr->OnFloatingPaneMoveStart(m_pane_window);
275}
276
00c1c94c 277void wxAuiFloatingFrame::OnMoving(const wxRect& WXUNUSED(window_rect), wxDirection dir)
50acee04
JS
278{
279 // notify the owner manager that the pane is moving
322c5ec4
RR
280 m_owner_mgr->OnFloatingPaneMoving(m_pane_window, dir);
281 m_lastDirection = dir;
50acee04
JS
282}
283
00c1c94c 284void wxAuiFloatingFrame::OnMoveFinished()
50acee04
JS
285{
286 // notify the owner manager that the pane has finished moving
322c5ec4 287 m_owner_mgr->OnFloatingPaneMoved(m_pane_window, m_lastDirection);
50acee04
JS
288}
289
00c1c94c 290void wxAuiFloatingFrame::OnActivate(wxActivateEvent& event)
50acee04
JS
291{
292 if (event.GetActive())
293 {
294 m_owner_mgr->OnFloatingPaneActivated(m_pane_window);
295 }
296}
297
298// utility function which determines the state of the mouse button
299// (independant of having a wxMouseEvent handy) - utimately a better
300// mechanism for this should be found (possibly by adding the
301// functionality to wxWidgets itself)
00c1c94c 302bool wxAuiFloatingFrame::isMouseDown()
50acee04
JS
303{
304 return wxGetMouseState().LeftDown();
305}
306
307
00c1c94c
BW
308BEGIN_EVENT_TABLE(wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass)
309 EVT_SIZE(wxAuiFloatingFrame::OnSize)
310 EVT_MOVE(wxAuiFloatingFrame::OnMoveEvent)
311 EVT_MOVING(wxAuiFloatingFrame::OnMoveEvent)
312 EVT_CLOSE(wxAuiFloatingFrame::OnClose)
313 EVT_IDLE(wxAuiFloatingFrame::OnIdle)
314 EVT_ACTIVATE(wxAuiFloatingFrame::OnActivate)
50acee04
JS
315END_EVENT_TABLE()
316
317
318#endif // wxUSE_AUI