]> git.saurik.com Git - wxWidgets.git/blame - src/aui/floatpane.cpp
ensure all topic overviews have an horizontal rule with the list of the sections...
[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...
8949ba7d 76 if(m_owner_mgr)
4dc79cfb 77 {
8949ba7d
VZ
78 if(m_owner_mgr->m_action_window == this)
79 m_owner_mgr->m_action_window = NULL;
80 m_owner_mgr->UnregisterFloatingFrame(this);
20d64475 81 }
601398b9 82
50acee04
JS
83 m_mgr.UnInit();
84}
85
00c1c94c 86void wxAuiFloatingFrame::SetPaneWindow(const wxAuiPaneInfo& pane)
50acee04
JS
87{
88 m_pane_window = pane.window;
89 m_pane_window->Reparent(this);
be66f18e 90
a3a5df9d 91 wxAuiPaneInfo contained_pane = pane;
50acee04
JS
92 contained_pane.Dock().Center().Show().
93 CaptionVisible(false).
94 PaneBorder(false).
95 Layer(0).Row(0).Position(0);
be66f18e 96
5c62cb6c 97 // Carry over the minimum size
bc07ab17 98 wxSize pane_min_size = pane.window->GetMinSize();
cedd7b22 99
bc07ab17
RD
100 // if the frame window's max size is greater than the min size
101 // then set the max size to the min size as well
102 wxSize cur_max_size = GetMaxSize();
1dc6ec2c
BW
103 if (cur_max_size.IsFullySpecified() &&
104 (cur_max_size.x < pane.min_size.x ||
105 cur_max_size.y < pane.min_size.y)
106 )
bc07ab17
RD
107 {
108 SetMaxSize(pane_min_size);
109 }
cedd7b22 110
5c62cb6c
AB
111 SetMinSize(pane.window->GetMinSize());
112
50acee04 113 m_mgr.AddPane(m_pane_window, contained_pane);
be66f18e 114 m_mgr.Update();
50acee04
JS
115
116 if (pane.min_size.IsFullySpecified())
117 {
118 // because SetSizeHints() calls Fit() too (which sets the window
119 // size to its minimum allowed), we keep the size before calling
120 // SetSizeHints() and reset it afterwards...
121 wxSize tmp = GetSize();
122 GetSizer()->SetSizeHints(this);
123 SetSize(tmp);
124 }
be66f18e 125
50acee04
JS
126 SetTitle(pane.caption);
127
50acee04
JS
128 if (pane.floating_size != wxDefaultSize)
129 {
130 SetSize(pane.floating_size);
131 }
cedd7b22 132 else
50acee04
JS
133 {
134 wxSize size = pane.best_size;
135 if (size == wxDefaultSize)
136 size = pane.min_size;
137 if (size == wxDefaultSize)
138 size = m_pane_window->GetSize();
601398b9 139 if (m_owner_mgr && pane.HasGripper())
50acee04
JS
140 {
141 if (pane.HasGripperTop())
254a3429 142 size.y += m_owner_mgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE);
50acee04 143 else
254a3429 144 size.x += m_owner_mgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE);
50acee04 145 }
be66f18e 146
50acee04
JS
147 SetClientSize(size);
148 }
149}
150
4dc79cfb
BW
151wxAuiManager* wxAuiFloatingFrame::GetOwnerManager() const
152{
153 return m_owner_mgr;
154}
155
8949ba7d
VZ
156void wxAuiFloatingFrame::SetOwnerManager(wxAuiManager* owner_mgr)
157{
158 // we want to allow for NULL here to avoid crashing in dtor
159 m_owner_mgr = owner_mgr;
160}
4dc79cfb 161
00c1c94c 162void wxAuiFloatingFrame::OnSize(wxSizeEvent& event)
50acee04 163{
601398b9
BP
164 if (m_owner_mgr)
165 {
166 m_owner_mgr->OnFloatingPaneResized(m_pane_window, event.GetSize());
167 }
50acee04
JS
168}
169
00c1c94c 170void wxAuiFloatingFrame::OnClose(wxCloseEvent& evt)
50acee04 171{
601398b9
BP
172 if (m_owner_mgr)
173 {
174 m_owner_mgr->OnFloatingPaneClosed(m_pane_window, evt);
175 }
176 if (!evt.GetVeto())
177 {
cedd7b22 178 m_mgr.DetachPane(m_pane_window);
c68038f3 179 Destroy();
a23717e5 180 }
50acee04
JS
181}
182
00c1c94c 183void wxAuiFloatingFrame::OnMoveEvent(wxMoveEvent& event)
50acee04 184{
22fec94a
BW
185 if (!m_solid_drag)
186 {
187 // systems without solid window dragging need to be
188 // handled slightly differently, due to the lack of
189 // the constant stream of EVT_MOVING events
190 if (!isMouseDown())
191 return;
192 OnMoveStart();
193 OnMoving(event.GetRect(), wxNORTH);
194 m_moving = true;
195 return;
196 }
cedd7b22
PC
197
198
50acee04
JS
199 wxRect win_rect = GetRect();
200
322c5ec4
RR
201 if (win_rect == m_last_rect)
202 return;
203
50acee04
JS
204 // skip the first move event
205 if (m_last_rect.IsEmpty())
206 {
207 m_last_rect = win_rect;
208 return;
209 }
210
cedd7b22 211 // skip if moving too fast to avoid massive redraws and
322c5ec4
RR
212 // jumping hint windows
213 if ((abs(win_rect.x - m_last_rect.x) > 3) ||
214 (abs(win_rect.y - m_last_rect.y) > 3))
0ae3bace 215 {
322c5ec4
RR
216 m_last3_rect = m_last2_rect;
217 m_last2_rect = m_last_rect;
0ae3bace
RR
218 m_last_rect = win_rect;
219 return;
220 }
221
50acee04
JS
222 // prevent frame redocking during resize
223 if (m_last_rect.GetSize() != win_rect.GetSize())
224 {
322c5ec4
RR
225 m_last3_rect = m_last2_rect;
226 m_last2_rect = m_last_rect;
50acee04
JS
227 m_last_rect = win_rect;
228 return;
229 }
230
322c5ec4 231 wxDirection dir = wxALL;
cedd7b22 232
322c5ec4
RR
233 int horiz_dist = abs(win_rect.x - m_last3_rect.x);
234 int vert_dist = abs(win_rect.y - m_last3_rect.y);
cedd7b22 235
322c5ec4
RR
236 if (vert_dist >= horiz_dist)
237 {
238 if (win_rect.y < m_last3_rect.y)
239 dir = wxNORTH;
240 else
241 dir = wxSOUTH;
242 }
243 else
244 {
245 if (win_rect.x < m_last3_rect.x)
246 dir = wxWEST;
247 else
248 dir = wxEAST;
249 }
cedd7b22 250
322c5ec4
RR
251 m_last3_rect = m_last2_rect;
252 m_last2_rect = m_last_rect;
50acee04 253 m_last_rect = win_rect;
be66f18e 254
50acee04
JS
255 if (!isMouseDown())
256 return;
257
258 if (!m_moving)
259 {
260 OnMoveStart();
261 m_moving = true;
262 }
263
322c5ec4
RR
264 if (m_last3_rect.IsEmpty())
265 return;
cedd7b22 266
22fec94a 267 OnMoving(event.GetRect(), dir);
50acee04
JS
268}
269
00c1c94c 270void wxAuiFloatingFrame::OnIdle(wxIdleEvent& event)
50acee04
JS
271{
272 if (m_moving)
273 {
274 if (!isMouseDown())
275 {
276 m_moving = false;
277 OnMoveFinished();
278 }
cedd7b22 279 else
50acee04
JS
280 {
281 event.RequestMore();
282 }
283 }
284}
285
00c1c94c 286void wxAuiFloatingFrame::OnMoveStart()
50acee04
JS
287{
288 // notify the owner manager that the pane has started to move
601398b9
BP
289 if (m_owner_mgr)
290 {
291 m_owner_mgr->OnFloatingPaneMoveStart(m_pane_window);
292 }
50acee04
JS
293}
294
00c1c94c 295void wxAuiFloatingFrame::OnMoving(const wxRect& WXUNUSED(window_rect), wxDirection dir)
50acee04
JS
296{
297 // notify the owner manager that the pane is moving
601398b9
BP
298 if (m_owner_mgr)
299 {
300 m_owner_mgr->OnFloatingPaneMoving(m_pane_window, dir);
301 }
322c5ec4 302 m_lastDirection = dir;
50acee04
JS
303}
304
00c1c94c 305void wxAuiFloatingFrame::OnMoveFinished()
50acee04
JS
306{
307 // notify the owner manager that the pane has finished moving
601398b9
BP
308 if (m_owner_mgr)
309 {
310 m_owner_mgr->OnFloatingPaneMoved(m_pane_window, m_lastDirection);
311 }
50acee04
JS
312}
313
00c1c94c 314void wxAuiFloatingFrame::OnActivate(wxActivateEvent& event)
50acee04 315{
601398b9 316 if (m_owner_mgr && event.GetActive())
50acee04
JS
317 {
318 m_owner_mgr->OnFloatingPaneActivated(m_pane_window);
319 }
320}
321
322// utility function which determines the state of the mouse button
323// (independant of having a wxMouseEvent handy) - utimately a better
324// mechanism for this should be found (possibly by adding the
325// functionality to wxWidgets itself)
00c1c94c 326bool wxAuiFloatingFrame::isMouseDown()
50acee04
JS
327{
328 return wxGetMouseState().LeftDown();
329}
330
331
00c1c94c
BW
332BEGIN_EVENT_TABLE(wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass)
333 EVT_SIZE(wxAuiFloatingFrame::OnSize)
334 EVT_MOVE(wxAuiFloatingFrame::OnMoveEvent)
335 EVT_MOVING(wxAuiFloatingFrame::OnMoveEvent)
336 EVT_CLOSE(wxAuiFloatingFrame::OnClose)
337 EVT_IDLE(wxAuiFloatingFrame::OnIdle)
338 EVT_ACTIVATE(wxAuiFloatingFrame::OnActivate)
50acee04
JS
339END_EVENT_TABLE()
340
341
342#endif // wxUSE_AUI