]> git.saurik.com Git - wxWidgets.git/blob - src/aui/floatpane.cpp
Only give capture to wxPopupTransientWindow child if it's the only one.
[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 // 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
32 #endif
33
34 #ifdef __WXMSW__
35 #include "wx/msw/private.h"
36 #endif
37
38 IMPLEMENT_CLASS(wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass)
39
40 wxAuiFloatingFrame::wxAuiFloatingFrame(wxWindow* parent,
41 wxAuiManager* owner_mgr,
42 const wxAuiPaneInfo& pane,
43 wxWindowID id /*= wxID_ANY*/,
44 long style /*=wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION |
45 wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT |
46 wxCLIP_CHILDREN
47 */)
48 : wxAuiFloatingFrameBaseClass(parent, id, wxEmptyString,
49 pane.floating_pos, pane.floating_size,
50 style |
51 (pane.HasCloseButton()?wxCLOSE_BOX:0) |
52 (pane.HasMaximizeButton()?wxMAXIMIZE_BOX:0) |
53 (pane.IsFixed()?0:wxRESIZE_BORDER)
54 )
55 {
56 m_ownerMgr = owner_mgr;
57 m_moving = false;
58 m_mgr.SetManagedWindow(this);
59 m_solidDrag = true;
60
61 // find out if the system supports solid window drag.
62 // on non-msw systems, this is assumed to be the case
63 #ifdef __WXMSW__
64 BOOL b = TRUE;
65 SystemParametersInfo(38 /*SPI_GETDRAGFULLWINDOWS*/, 0, &b, 0);
66 m_solidDrag = b ? true : false;
67 #endif
68
69 SetExtraStyle(wxWS_EX_PROCESS_IDLE);
70 }
71
72 wxAuiFloatingFrame::~wxAuiFloatingFrame()
73 {
74 // if we do not do this, then we can crash...
75 if (m_ownerMgr && m_ownerMgr->m_actionWindow == this)
76 {
77 m_ownerMgr->m_actionWindow = NULL;
78 }
79
80 m_mgr.UnInit();
81 }
82
83 void wxAuiFloatingFrame::SetPaneWindow(const wxAuiPaneInfo& pane)
84 {
85 m_paneWindow = pane.window;
86 m_paneWindow->Reparent(this);
87
88 wxAuiPaneInfo contained_pane = pane;
89 contained_pane.Dock().Center().Show().
90 CaptionVisible(false).
91 PaneBorder(false).
92 Layer(0).Row(0).Position(0);
93
94 // Carry over the minimum size
95 wxSize pane_min_size = pane.window->GetMinSize();
96
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();
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 )
104 {
105 SetMaxSize(pane_min_size);
106 }
107
108 SetMinSize(pane.window->GetMinSize());
109
110 m_mgr.AddPane(m_paneWindow, contained_pane);
111 m_mgr.Update();
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 }
122
123 SetTitle(pane.caption);
124
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 )
141 {
142 SetSize(pane.floating_size);
143 }
144 else
145 {
146 wxSize size = pane.best_size;
147 if (size == wxDefaultSize)
148 size = pane.min_size;
149 if (size == wxDefaultSize)
150 size = m_paneWindow->GetSize();
151 if (m_ownerMgr && pane.HasGripper())
152 {
153 if (pane.HasGripperTop())
154 size.y += m_ownerMgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE);
155 else
156 size.x += m_ownerMgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE);
157 }
158
159 SetClientSize(size);
160 }
161 }
162
163 wxAuiManager* wxAuiFloatingFrame::GetOwnerManager() const
164 {
165 return m_ownerMgr;
166 }
167
168
169 void wxAuiFloatingFrame::OnSize(wxSizeEvent& WXUNUSED(event))
170 {
171 if (m_ownerMgr)
172 {
173 m_ownerMgr->OnFloatingPaneResized(m_paneWindow, GetRect());
174 }
175 }
176
177 void wxAuiFloatingFrame::OnClose(wxCloseEvent& evt)
178 {
179 if (m_ownerMgr)
180 {
181 m_ownerMgr->OnFloatingPaneClosed(m_paneWindow, evt);
182 }
183 if (!evt.GetVeto())
184 {
185 m_mgr.DetachPane(m_paneWindow);
186 Destroy();
187 }
188 }
189
190 void wxAuiFloatingFrame::OnMoveEvent(wxMoveEvent& event)
191 {
192 if (!m_solidDrag)
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 }
204
205
206 wxRect winRect = GetRect();
207
208 if (winRect == m_lastRect)
209 return;
210
211 // skip the first move event
212 if (m_lastRect.IsEmpty())
213 {
214 m_lastRect = winRect;
215 return;
216 }
217
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__
221 // skip if moving too fast to avoid massive redraws and
222 // jumping hint windows
223 if ((abs(winRect.x - m_lastRect.x) > 3) ||
224 (abs(winRect.y - m_lastRect.y) > 3))
225 {
226 m_last3Rect = m_last2Rect;
227 m_last2Rect = m_lastRect;
228 m_lastRect = winRect;
229
230 // However still update the internally stored position to avoid
231 // snapping back to the old one later.
232 if (m_ownerMgr)
233 {
234 m_ownerMgr->GetPane(m_paneWindow).
235 floating_pos = winRect.GetPosition();
236 }
237
238 return;
239 }
240 #endif
241
242 // prevent frame redocking during resize
243 if (m_lastRect.GetSize() != winRect.GetSize())
244 {
245 m_last3Rect = m_last2Rect;
246 m_last2Rect = m_lastRect;
247 m_lastRect = winRect;
248 return;
249 }
250
251 wxDirection dir = wxALL;
252
253 int horiz_dist = abs(winRect.x - m_last3Rect.x);
254 int vert_dist = abs(winRect.y - m_last3Rect.y);
255
256 if (vert_dist >= horiz_dist)
257 {
258 if (winRect.y < m_last3Rect.y)
259 dir = wxNORTH;
260 else
261 dir = wxSOUTH;
262 }
263 else
264 {
265 if (winRect.x < m_last3Rect.x)
266 dir = wxWEST;
267 else
268 dir = wxEAST;
269 }
270
271 m_last3Rect = m_last2Rect;
272 m_last2Rect = m_lastRect;
273 m_lastRect = winRect;
274
275 if (!isMouseDown())
276 return;
277
278 if (!m_moving)
279 {
280 OnMoveStart();
281 m_moving = true;
282 }
283
284 if (m_last3Rect.IsEmpty())
285 return;
286
287 if ( event.GetEventType() == wxEVT_MOVING )
288 OnMoving(event.GetRect(), dir);
289 else
290 OnMoving(wxRect(event.GetPosition(),GetSize()), dir);
291 }
292
293 void wxAuiFloatingFrame::OnIdle(wxIdleEvent& event)
294 {
295 if (m_moving)
296 {
297 if (!isMouseDown())
298 {
299 m_moving = false;
300 OnMoveFinished();
301 }
302 else
303 {
304 event.RequestMore();
305 }
306 }
307 }
308
309 void wxAuiFloatingFrame::OnMoveStart()
310 {
311 // notify the owner manager that the pane has started to move
312 if (m_ownerMgr)
313 {
314 m_ownerMgr->OnFloatingPaneMoveStart(m_paneWindow);
315 }
316 }
317
318 void wxAuiFloatingFrame::OnMoving(const wxRect& WXUNUSED(window_rect), wxDirection dir)
319 {
320 // notify the owner manager that the pane is moving
321 if (m_ownerMgr)
322 {
323 m_ownerMgr->OnFloatingPaneMoving(m_paneWindow, dir);
324 }
325 m_lastDirection = dir;
326 }
327
328 void wxAuiFloatingFrame::OnMoveFinished()
329 {
330 // notify the owner manager that the pane has finished moving
331 if (m_ownerMgr)
332 {
333 m_ownerMgr->OnFloatingPaneMoved(m_paneWindow, m_lastDirection);
334 }
335 }
336
337 void wxAuiFloatingFrame::OnActivate(wxActivateEvent& event)
338 {
339 if (m_ownerMgr && event.GetActive())
340 {
341 m_ownerMgr->OnFloatingPaneActivated(m_paneWindow);
342 }
343 }
344
345 // utility function which determines the state of the mouse button
346 // (independent of having a wxMouseEvent handy) - utimately a better
347 // mechanism for this should be found (possibly by adding the
348 // functionality to wxWidgets itself)
349 bool wxAuiFloatingFrame::isMouseDown()
350 {
351 return wxGetMouseState().LeftIsDown();
352 }
353
354
355 BEGIN_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)
362 END_EVENT_TABLE()
363
364
365 #endif // wxUSE_AUI