]>
Commit | Line | Data |
---|---|---|
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 | 39 | IMPLEMENT_CLASS(wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass) |
e5ab82d3 | 40 | |
00c1c94c | 41 | wxAuiFloatingFrame::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 | 56 | { |
9a29fe70 | 57 | m_ownerMgr = owner_mgr; |
50acee04 | 58 | m_moving = false; |
461125ea | 59 | m_mgr.SetManagedWindow(this); |
9a29fe70 | 60 | m_solidDrag = 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 | 66 | SystemParametersInfo(38 /*SPI_GETDRAGFULLWINDOWS*/, 0, &b, 0); |
9a29fe70 | 67 | m_solidDrag = b ? true : false; |
20d64475 | 68 | #endif |
cedd7b22 | 69 | |
322c5ec4 | 70 | SetExtraStyle(wxWS_EX_PROCESS_IDLE); |
50acee04 JS |
71 | } |
72 | ||
00c1c94c | 73 | wxAuiFloatingFrame::~wxAuiFloatingFrame() |
50acee04 | 74 | { |
20d64475 | 75 | // if we do not do this, then we can crash... |
9a29fe70 | 76 | if (m_ownerMgr && m_ownerMgr->m_actionWindow == this) |
4dc79cfb | 77 | { |
9a29fe70 | 78 | m_ownerMgr->m_actionWindow = NULL; |
20d64475 | 79 | } |
601398b9 | 80 | |
50acee04 JS |
81 | m_mgr.UnInit(); |
82 | } | |
83 | ||
00c1c94c | 84 | void wxAuiFloatingFrame::SetPaneWindow(const wxAuiPaneInfo& pane) |
50acee04 | 85 | { |
9a29fe70 VZ |
86 | m_paneWindow = pane.window; |
87 | m_paneWindow->Reparent(this); | |
be66f18e | 88 | |
a3a5df9d | 89 | wxAuiPaneInfo contained_pane = pane; |
50acee04 JS |
90 | contained_pane.Dock().Center().Show(). |
91 | CaptionVisible(false). | |
92 | PaneBorder(false). | |
93 | Layer(0).Row(0).Position(0); | |
be66f18e | 94 | |
5c62cb6c | 95 | // Carry over the minimum size |
bc07ab17 | 96 | wxSize pane_min_size = pane.window->GetMinSize(); |
cedd7b22 | 97 | |
bc07ab17 RD |
98 | // if the frame window's max size is greater than the min size |
99 | // then set the max size to the min size as well | |
100 | wxSize cur_max_size = GetMaxSize(); | |
1dc6ec2c BW |
101 | if (cur_max_size.IsFullySpecified() && |
102 | (cur_max_size.x < pane.min_size.x || | |
103 | cur_max_size.y < pane.min_size.y) | |
104 | ) | |
bc07ab17 RD |
105 | { |
106 | SetMaxSize(pane_min_size); | |
107 | } | |
cedd7b22 | 108 | |
5c62cb6c AB |
109 | SetMinSize(pane.window->GetMinSize()); |
110 | ||
9a29fe70 | 111 | m_mgr.AddPane(m_paneWindow, contained_pane); |
be66f18e | 112 | m_mgr.Update(); |
50acee04 JS |
113 | |
114 | if (pane.min_size.IsFullySpecified()) | |
115 | { | |
116 | // because SetSizeHints() calls Fit() too (which sets the window | |
117 | // size to its minimum allowed), we keep the size before calling | |
118 | // SetSizeHints() and reset it afterwards... | |
119 | wxSize tmp = GetSize(); | |
120 | GetSizer()->SetSizeHints(this); | |
121 | SetSize(tmp); | |
122 | } | |
be66f18e | 123 | |
50acee04 JS |
124 | SetTitle(pane.caption); |
125 | ||
efd516c2 VZ |
126 | // This code is slightly awkward because we need to reset wxRESIZE_BORDER |
127 | // before calling SetClientSize() below as doing it after setting the | |
128 | // client size would actually change it, at least under MSW, where the | |
129 | // total window size doesn't change and hence, as the borders size changes, | |
130 | // the client size does change. | |
131 | // | |
132 | // So we must call it first but doing it generates a size event and updates | |
133 | // pane.floating_size from inside it so we must also record its original | |
134 | // value before doing it. | |
135 | const bool hasFloatingSize = pane.floating_size != wxDefaultSize; | |
136 | if (pane.IsFixed()) | |
137 | { | |
138 | SetWindowStyleFlag(GetWindowStyleFlag() & ~wxRESIZE_BORDER); | |
139 | } | |
140 | ||
141 | if ( hasFloatingSize ) | |
50acee04 JS |
142 | { |
143 | SetSize(pane.floating_size); | |
144 | } | |
cedd7b22 | 145 | else |
50acee04 JS |
146 | { |
147 | wxSize size = pane.best_size; | |
148 | if (size == wxDefaultSize) | |
149 | size = pane.min_size; | |
150 | if (size == wxDefaultSize) | |
9a29fe70 VZ |
151 | size = m_paneWindow->GetSize(); |
152 | if (m_ownerMgr && pane.HasGripper()) | |
50acee04 JS |
153 | { |
154 | if (pane.HasGripperTop()) | |
9a29fe70 | 155 | size.y += m_ownerMgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE); |
50acee04 | 156 | else |
9a29fe70 | 157 | size.x += m_ownerMgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE); |
50acee04 | 158 | } |
be66f18e | 159 | |
50acee04 JS |
160 | SetClientSize(size); |
161 | } | |
162 | } | |
163 | ||
4dc79cfb BW |
164 | wxAuiManager* wxAuiFloatingFrame::GetOwnerManager() const |
165 | { | |
9a29fe70 | 166 | return m_ownerMgr; |
4dc79cfb BW |
167 | } |
168 | ||
169 | ||
76e1326a | 170 | void wxAuiFloatingFrame::OnSize(wxSizeEvent& WXUNUSED(event)) |
50acee04 | 171 | { |
9a29fe70 | 172 | if (m_ownerMgr) |
601398b9 | 173 | { |
9a29fe70 | 174 | m_ownerMgr->OnFloatingPaneResized(m_paneWindow, GetRect()); |
601398b9 | 175 | } |
50acee04 JS |
176 | } |
177 | ||
00c1c94c | 178 | void wxAuiFloatingFrame::OnClose(wxCloseEvent& evt) |
50acee04 | 179 | { |
9a29fe70 | 180 | if (m_ownerMgr) |
601398b9 | 181 | { |
9a29fe70 | 182 | m_ownerMgr->OnFloatingPaneClosed(m_paneWindow, evt); |
601398b9 BP |
183 | } |
184 | if (!evt.GetVeto()) | |
185 | { | |
9a29fe70 | 186 | m_mgr.DetachPane(m_paneWindow); |
c68038f3 | 187 | Destroy(); |
a23717e5 | 188 | } |
50acee04 JS |
189 | } |
190 | ||
00c1c94c | 191 | void wxAuiFloatingFrame::OnMoveEvent(wxMoveEvent& event) |
50acee04 | 192 | { |
9a29fe70 | 193 | if (!m_solidDrag) |
22fec94a BW |
194 | { |
195 | // systems without solid window dragging need to be | |
196 | // handled slightly differently, due to the lack of | |
197 | // the constant stream of EVT_MOVING events | |
198 | if (!isMouseDown()) | |
199 | return; | |
200 | OnMoveStart(); | |
201 | OnMoving(event.GetRect(), wxNORTH); | |
202 | m_moving = true; | |
203 | return; | |
204 | } | |
cedd7b22 PC |
205 | |
206 | ||
9a29fe70 | 207 | wxRect winRect = GetRect(); |
50acee04 | 208 | |
9a29fe70 | 209 | if (winRect == m_lastRect) |
322c5ec4 RR |
210 | return; |
211 | ||
50acee04 | 212 | // skip the first move event |
9a29fe70 | 213 | if (m_lastRect.IsEmpty()) |
50acee04 | 214 | { |
9a29fe70 | 215 | m_lastRect = winRect; |
50acee04 JS |
216 | return; |
217 | } | |
218 | ||
cedd7b22 | 219 | // skip if moving too fast to avoid massive redraws and |
322c5ec4 | 220 | // jumping hint windows |
9a29fe70 VZ |
221 | if ((abs(winRect.x - m_lastRect.x) > 3) || |
222 | (abs(winRect.y - m_lastRect.y) > 3)) | |
0ae3bace | 223 | { |
9a29fe70 VZ |
224 | m_last3Rect = m_last2Rect; |
225 | m_last2Rect = m_lastRect; | |
226 | m_lastRect = winRect; | |
c180fd77 VZ |
227 | |
228 | // However still update the internally stored position to avoid | |
229 | // snapping back to the old one later. | |
9a29fe70 | 230 | if (m_ownerMgr) |
c180fd77 | 231 | { |
9a29fe70 VZ |
232 | m_ownerMgr->GetPane(m_paneWindow). |
233 | floating_pos = winRect.GetPosition(); | |
c180fd77 VZ |
234 | } |
235 | ||
0ae3bace RR |
236 | return; |
237 | } | |
238 | ||
50acee04 | 239 | // prevent frame redocking during resize |
9a29fe70 | 240 | if (m_lastRect.GetSize() != winRect.GetSize()) |
50acee04 | 241 | { |
9a29fe70 VZ |
242 | m_last3Rect = m_last2Rect; |
243 | m_last2Rect = m_lastRect; | |
244 | m_lastRect = winRect; | |
50acee04 JS |
245 | return; |
246 | } | |
247 | ||
322c5ec4 | 248 | wxDirection dir = wxALL; |
cedd7b22 | 249 | |
9a29fe70 VZ |
250 | int horiz_dist = abs(winRect.x - m_last3Rect.x); |
251 | int vert_dist = abs(winRect.y - m_last3Rect.y); | |
cedd7b22 | 252 | |
322c5ec4 RR |
253 | if (vert_dist >= horiz_dist) |
254 | { | |
9a29fe70 | 255 | if (winRect.y < m_last3Rect.y) |
322c5ec4 RR |
256 | dir = wxNORTH; |
257 | else | |
258 | dir = wxSOUTH; | |
259 | } | |
260 | else | |
261 | { | |
9a29fe70 | 262 | if (winRect.x < m_last3Rect.x) |
322c5ec4 RR |
263 | dir = wxWEST; |
264 | else | |
265 | dir = wxEAST; | |
266 | } | |
cedd7b22 | 267 | |
9a29fe70 VZ |
268 | m_last3Rect = m_last2Rect; |
269 | m_last2Rect = m_lastRect; | |
270 | m_lastRect = winRect; | |
be66f18e | 271 | |
50acee04 JS |
272 | if (!isMouseDown()) |
273 | return; | |
274 | ||
275 | if (!m_moving) | |
276 | { | |
277 | OnMoveStart(); | |
278 | m_moving = true; | |
279 | } | |
280 | ||
9a29fe70 | 281 | if (m_last3Rect.IsEmpty()) |
322c5ec4 | 282 | return; |
cedd7b22 | 283 | |
22fec94a | 284 | OnMoving(event.GetRect(), dir); |
50acee04 JS |
285 | } |
286 | ||
00c1c94c | 287 | void wxAuiFloatingFrame::OnIdle(wxIdleEvent& event) |
50acee04 JS |
288 | { |
289 | if (m_moving) | |
290 | { | |
291 | if (!isMouseDown()) | |
292 | { | |
293 | m_moving = false; | |
294 | OnMoveFinished(); | |
295 | } | |
cedd7b22 | 296 | else |
50acee04 JS |
297 | { |
298 | event.RequestMore(); | |
299 | } | |
300 | } | |
301 | } | |
302 | ||
00c1c94c | 303 | void wxAuiFloatingFrame::OnMoveStart() |
50acee04 JS |
304 | { |
305 | // notify the owner manager that the pane has started to move | |
9a29fe70 | 306 | if (m_ownerMgr) |
601398b9 | 307 | { |
9a29fe70 | 308 | m_ownerMgr->OnFloatingPaneMoveStart(m_paneWindow); |
601398b9 | 309 | } |
50acee04 JS |
310 | } |
311 | ||
00c1c94c | 312 | void wxAuiFloatingFrame::OnMoving(const wxRect& WXUNUSED(window_rect), wxDirection dir) |
50acee04 JS |
313 | { |
314 | // notify the owner manager that the pane is moving | |
9a29fe70 | 315 | if (m_ownerMgr) |
601398b9 | 316 | { |
9a29fe70 | 317 | m_ownerMgr->OnFloatingPaneMoving(m_paneWindow, dir); |
601398b9 | 318 | } |
322c5ec4 | 319 | m_lastDirection = dir; |
50acee04 JS |
320 | } |
321 | ||
00c1c94c | 322 | void wxAuiFloatingFrame::OnMoveFinished() |
50acee04 JS |
323 | { |
324 | // notify the owner manager that the pane has finished moving | |
9a29fe70 | 325 | if (m_ownerMgr) |
601398b9 | 326 | { |
9a29fe70 | 327 | m_ownerMgr->OnFloatingPaneMoved(m_paneWindow, m_lastDirection); |
601398b9 | 328 | } |
50acee04 JS |
329 | } |
330 | ||
00c1c94c | 331 | void wxAuiFloatingFrame::OnActivate(wxActivateEvent& event) |
50acee04 | 332 | { |
9a29fe70 | 333 | if (m_ownerMgr && event.GetActive()) |
50acee04 | 334 | { |
9a29fe70 | 335 | m_ownerMgr->OnFloatingPaneActivated(m_paneWindow); |
50acee04 JS |
336 | } |
337 | } | |
338 | ||
339 | // utility function which determines the state of the mouse button | |
340 | // (independant of having a wxMouseEvent handy) - utimately a better | |
341 | // mechanism for this should be found (possibly by adding the | |
342 | // functionality to wxWidgets itself) | |
00c1c94c | 343 | bool wxAuiFloatingFrame::isMouseDown() |
50acee04 | 344 | { |
45496810 | 345 | return wxGetMouseState().LeftIsDown(); |
50acee04 JS |
346 | } |
347 | ||
348 | ||
00c1c94c BW |
349 | BEGIN_EVENT_TABLE(wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass) |
350 | EVT_SIZE(wxAuiFloatingFrame::OnSize) | |
351 | EVT_MOVE(wxAuiFloatingFrame::OnMoveEvent) | |
352 | EVT_MOVING(wxAuiFloatingFrame::OnMoveEvent) | |
353 | EVT_CLOSE(wxAuiFloatingFrame::OnClose) | |
354 | EVT_IDLE(wxAuiFloatingFrame::OnIdle) | |
355 | EVT_ACTIVATE(wxAuiFloatingFrame::OnActivate) | |
50acee04 JS |
356 | END_EVENT_TABLE() |
357 | ||
358 | ||
359 | #endif // wxUSE_AUI |