]> git.saurik.com Git - wxWidgets.git/blame - src/aui/floatpane.cpp
small cleanup
[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
e5ab82d3
AB
35IMPLEMENT_CLASS( wxFloatingPane, wxFloatingPaneBaseClass )
36
50acee04
JS
37wxFloatingPane::wxFloatingPane(wxWindow* parent,
38 wxFrameManager* owner_mgr,
e5ab82d3
AB
39 const wxPaneInfo& pane,
40 wxWindowID id /*= wxID_ANY*/)
41 : wxFloatingPaneBaseClass(parent, id, wxEmptyString,
42 pane.floating_pos, pane.floating_size,
50acee04 43 wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION |
96743140
BW
44 (pane.HasCloseButton()?wxCLOSE_BOX:0) |
45 wxFRAME_NO_TASKBAR |
e5ab82d3
AB
46 wxFRAME_FLOAT_ON_PARENT | wxCLIP_CHILDREN |
47 (pane.IsFixed()?0:wxRESIZE_BORDER)
48 )
50acee04
JS
49{
50 m_owner_mgr = owner_mgr;
51 m_moving = false;
461125ea 52 m_mgr.SetManagedWindow(this);
322c5ec4 53 SetExtraStyle(wxWS_EX_PROCESS_IDLE);
50acee04
JS
54}
55
56wxFloatingPane::~wxFloatingPane()
57{
58 m_mgr.UnInit();
59}
60
61void wxFloatingPane::SetPaneWindow(const wxPaneInfo& pane)
62{
63 m_pane_window = pane.window;
64 m_pane_window->Reparent(this);
be66f18e 65
50acee04
JS
66 wxPaneInfo contained_pane = pane;
67 contained_pane.Dock().Center().Show().
68 CaptionVisible(false).
69 PaneBorder(false).
70 Layer(0).Row(0).Position(0);
be66f18e 71
5c62cb6c
AB
72 // Carry over the minimum size
73 SetMinSize(pane.window->GetMinSize());
74
50acee04 75 m_mgr.AddPane(m_pane_window, contained_pane);
be66f18e 76 m_mgr.Update();
50acee04
JS
77
78 if (pane.min_size.IsFullySpecified())
79 {
80 // because SetSizeHints() calls Fit() too (which sets the window
81 // size to its minimum allowed), we keep the size before calling
82 // SetSizeHints() and reset it afterwards...
83 wxSize tmp = GetSize();
84 GetSizer()->SetSizeHints(this);
85 SetSize(tmp);
86 }
be66f18e 87
50acee04
JS
88 SetTitle(pane.caption);
89
50acee04
JS
90 if (pane.floating_size != wxDefaultSize)
91 {
92 SetSize(pane.floating_size);
93 }
94 else
95 {
96 wxSize size = pane.best_size;
97 if (size == wxDefaultSize)
98 size = pane.min_size;
99 if (size == wxDefaultSize)
100 size = m_pane_window->GetSize();
101 if (pane.HasGripper())
102 {
103 if (pane.HasGripperTop())
104 size.y += m_owner_mgr->m_art->GetMetric(wxAUI_ART_GRIPPER_SIZE);
105 else
106 size.x += m_owner_mgr->m_art->GetMetric(wxAUI_ART_GRIPPER_SIZE);
107 }
be66f18e 108
50acee04
JS
109 SetClientSize(size);
110 }
111}
112
113void wxFloatingPane::OnSize(wxSizeEvent& event)
114{
115 m_owner_mgr->OnFloatingPaneResized(m_pane_window, event.GetSize());
116}
117
58754643 118void wxFloatingPane::OnClose(wxCloseEvent& evt)
50acee04 119{
58754643
BW
120 m_owner_mgr->OnFloatingPaneClosed(m_pane_window, evt);
121 if (!evt.GetVeto())
c68038f3 122 Destroy();
50acee04
JS
123}
124
125void wxFloatingPane::OnMoveEvent(wxMoveEvent& event)
126{
127 wxRect win_rect = GetRect();
128
322c5ec4
RR
129 if (win_rect == m_last_rect)
130 return;
131
50acee04
JS
132 // skip the first move event
133 if (m_last_rect.IsEmpty())
134 {
135 m_last_rect = win_rect;
136 return;
137 }
138
322c5ec4
RR
139 // skip if moving too fast to avoid massive redraws and
140 // jumping hint windows
141 if ((abs(win_rect.x - m_last_rect.x) > 3) ||
142 (abs(win_rect.y - m_last_rect.y) > 3))
0ae3bace 143 {
322c5ec4
RR
144 m_last3_rect = m_last2_rect;
145 m_last2_rect = m_last_rect;
0ae3bace
RR
146 m_last_rect = win_rect;
147 return;
148 }
149
50acee04
JS
150 // prevent frame redocking during resize
151 if (m_last_rect.GetSize() != win_rect.GetSize())
152 {
322c5ec4
RR
153 m_last3_rect = m_last2_rect;
154 m_last2_rect = m_last_rect;
50acee04
JS
155 m_last_rect = win_rect;
156 return;
157 }
158
322c5ec4
RR
159 wxDirection dir = wxALL;
160
161 int horiz_dist = abs(win_rect.x - m_last3_rect.x);
162 int vert_dist = abs(win_rect.y - m_last3_rect.y);
163
164 if (vert_dist >= horiz_dist)
165 {
166 if (win_rect.y < m_last3_rect.y)
167 dir = wxNORTH;
168 else
169 dir = wxSOUTH;
170 }
171 else
172 {
173 if (win_rect.x < m_last3_rect.x)
174 dir = wxWEST;
175 else
176 dir = wxEAST;
177 }
178
179 m_last3_rect = m_last2_rect;
180 m_last2_rect = m_last_rect;
50acee04 181 m_last_rect = win_rect;
be66f18e 182
50acee04
JS
183 if (!isMouseDown())
184 return;
185
186 if (!m_moving)
187 {
188 OnMoveStart();
189 m_moving = true;
190 }
191
322c5ec4
RR
192 if (m_last3_rect.IsEmpty())
193 return;
194
195 OnMoving(event.GetRect(), dir );
50acee04
JS
196}
197
198void wxFloatingPane::OnIdle(wxIdleEvent& event)
199{
200 if (m_moving)
201 {
202 if (!isMouseDown())
203 {
204 m_moving = false;
205 OnMoveFinished();
206 }
207 else
208 {
209 event.RequestMore();
210 }
211 }
212}
213
214void wxFloatingPane::OnMoveStart()
215{
216 // notify the owner manager that the pane has started to move
217 m_owner_mgr->OnFloatingPaneMoveStart(m_pane_window);
218}
219
322c5ec4 220void wxFloatingPane::OnMoving(const wxRect& WXUNUSED(window_rect), wxDirection dir)
50acee04
JS
221{
222 // notify the owner manager that the pane is moving
322c5ec4
RR
223 m_owner_mgr->OnFloatingPaneMoving(m_pane_window, dir);
224 m_lastDirection = dir;
50acee04
JS
225}
226
227void wxFloatingPane::OnMoveFinished()
228{
229 // notify the owner manager that the pane has finished moving
322c5ec4 230 m_owner_mgr->OnFloatingPaneMoved(m_pane_window, m_lastDirection);
50acee04
JS
231}
232
233void wxFloatingPane::OnActivate(wxActivateEvent& event)
234{
235 if (event.GetActive())
236 {
237 m_owner_mgr->OnFloatingPaneActivated(m_pane_window);
238 }
239}
240
241// utility function which determines the state of the mouse button
242// (independant of having a wxMouseEvent handy) - utimately a better
243// mechanism for this should be found (possibly by adding the
244// functionality to wxWidgets itself)
245bool wxFloatingPane::isMouseDown()
246{
247 return wxGetMouseState().LeftDown();
248}
249
250
251BEGIN_EVENT_TABLE(wxFloatingPane, wxFloatingPaneBaseClass)
252 EVT_SIZE(wxFloatingPane::OnSize)
253 EVT_MOVE(wxFloatingPane::OnMoveEvent)
254 EVT_MOVING(wxFloatingPane::OnMoveEvent)
255 EVT_CLOSE(wxFloatingPane::OnClose)
256 EVT_IDLE(wxFloatingPane::OnIdle)
257 EVT_ACTIVATE(wxFloatingPane::OnActivate)
258END_EVENT_TABLE()
259
260
261#endif // wxUSE_AUI