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