]>
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 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 | 73 | wxAuiFloatingFrame::~wxAuiFloatingFrame() |
50acee04 | 74 | { |
20d64475 | 75 | // if we do not do this, then we can crash... |
1afad0ac | 76 | if (m_owner_mgr && m_owner_mgr->m_action_window == this) |
4dc79cfb | 77 | { |
1afad0ac | 78 | m_owner_mgr->m_action_window = NULL; |
20d64475 | 79 | } |
601398b9 | 80 | |
50acee04 JS |
81 | m_mgr.UnInit(); |
82 | } | |
83 | ||
00c1c94c | 84 | void wxAuiFloatingFrame::SetPaneWindow(const wxAuiPaneInfo& pane) |
50acee04 JS |
85 | { |
86 | m_pane_window = pane.window; | |
87 | m_pane_window->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 | ||
50acee04 | 111 | m_mgr.AddPane(m_pane_window, 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 | ||
50acee04 JS |
126 | if (pane.floating_size != wxDefaultSize) |
127 | { | |
128 | SetSize(pane.floating_size); | |
129 | } | |
cedd7b22 | 130 | else |
50acee04 JS |
131 | { |
132 | wxSize size = pane.best_size; | |
133 | if (size == wxDefaultSize) | |
134 | size = pane.min_size; | |
135 | if (size == wxDefaultSize) | |
136 | size = m_pane_window->GetSize(); | |
601398b9 | 137 | if (m_owner_mgr && pane.HasGripper()) |
50acee04 JS |
138 | { |
139 | if (pane.HasGripperTop()) | |
254a3429 | 140 | size.y += m_owner_mgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE); |
50acee04 | 141 | else |
254a3429 | 142 | size.x += m_owner_mgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE); |
50acee04 | 143 | } |
be66f18e | 144 | |
50acee04 JS |
145 | SetClientSize(size); |
146 | } | |
45496810 | 147 | |
94497522 BW |
148 | if (pane.IsFixed()) |
149 | { | |
150 | SetWindowStyleFlag(GetWindowStyleFlag() & ~wxRESIZE_BORDER); | |
151 | } | |
50acee04 JS |
152 | } |
153 | ||
4dc79cfb BW |
154 | wxAuiManager* wxAuiFloatingFrame::GetOwnerManager() const |
155 | { | |
156 | return m_owner_mgr; | |
157 | } | |
158 | ||
159 | ||
76e1326a | 160 | void wxAuiFloatingFrame::OnSize(wxSizeEvent& WXUNUSED(event)) |
50acee04 | 161 | { |
601398b9 BP |
162 | if (m_owner_mgr) |
163 | { | |
76e1326a | 164 | m_owner_mgr->OnFloatingPaneResized(m_pane_window, GetRect()); |
601398b9 | 165 | } |
50acee04 JS |
166 | } |
167 | ||
00c1c94c | 168 | void wxAuiFloatingFrame::OnClose(wxCloseEvent& evt) |
50acee04 | 169 | { |
601398b9 BP |
170 | if (m_owner_mgr) |
171 | { | |
172 | m_owner_mgr->OnFloatingPaneClosed(m_pane_window, evt); | |
173 | } | |
174 | if (!evt.GetVeto()) | |
175 | { | |
cedd7b22 | 176 | m_mgr.DetachPane(m_pane_window); |
c68038f3 | 177 | Destroy(); |
a23717e5 | 178 | } |
50acee04 JS |
179 | } |
180 | ||
00c1c94c | 181 | void wxAuiFloatingFrame::OnMoveEvent(wxMoveEvent& event) |
50acee04 | 182 | { |
22fec94a BW |
183 | if (!m_solid_drag) |
184 | { | |
185 | // systems without solid window dragging need to be | |
186 | // handled slightly differently, due to the lack of | |
187 | // the constant stream of EVT_MOVING events | |
188 | if (!isMouseDown()) | |
189 | return; | |
190 | OnMoveStart(); | |
191 | OnMoving(event.GetRect(), wxNORTH); | |
192 | m_moving = true; | |
193 | return; | |
194 | } | |
cedd7b22 PC |
195 | |
196 | ||
50acee04 JS |
197 | wxRect win_rect = GetRect(); |
198 | ||
322c5ec4 RR |
199 | if (win_rect == m_last_rect) |
200 | return; | |
201 | ||
50acee04 JS |
202 | // skip the first move event |
203 | if (m_last_rect.IsEmpty()) | |
204 | { | |
205 | m_last_rect = win_rect; | |
206 | return; | |
207 | } | |
208 | ||
cedd7b22 | 209 | // skip if moving too fast to avoid massive redraws and |
322c5ec4 RR |
210 | // jumping hint windows |
211 | if ((abs(win_rect.x - m_last_rect.x) > 3) || | |
212 | (abs(win_rect.y - m_last_rect.y) > 3)) | |
0ae3bace | 213 | { |
322c5ec4 RR |
214 | m_last3_rect = m_last2_rect; |
215 | m_last2_rect = m_last_rect; | |
0ae3bace | 216 | m_last_rect = win_rect; |
c180fd77 VZ |
217 | |
218 | // However still update the internally stored position to avoid | |
219 | // snapping back to the old one later. | |
220 | if (m_owner_mgr) | |
221 | { | |
222 | m_owner_mgr->GetPane(m_pane_window). | |
223 | floating_pos = win_rect.GetPosition(); | |
224 | } | |
225 | ||
0ae3bace RR |
226 | return; |
227 | } | |
228 | ||
50acee04 JS |
229 | // prevent frame redocking during resize |
230 | if (m_last_rect.GetSize() != win_rect.GetSize()) | |
231 | { | |
322c5ec4 RR |
232 | m_last3_rect = m_last2_rect; |
233 | m_last2_rect = m_last_rect; | |
50acee04 JS |
234 | m_last_rect = win_rect; |
235 | return; | |
236 | } | |
237 | ||
322c5ec4 | 238 | wxDirection dir = wxALL; |
cedd7b22 | 239 | |
322c5ec4 RR |
240 | int horiz_dist = abs(win_rect.x - m_last3_rect.x); |
241 | int vert_dist = abs(win_rect.y - m_last3_rect.y); | |
cedd7b22 | 242 | |
322c5ec4 RR |
243 | if (vert_dist >= horiz_dist) |
244 | { | |
245 | if (win_rect.y < m_last3_rect.y) | |
246 | dir = wxNORTH; | |
247 | else | |
248 | dir = wxSOUTH; | |
249 | } | |
250 | else | |
251 | { | |
252 | if (win_rect.x < m_last3_rect.x) | |
253 | dir = wxWEST; | |
254 | else | |
255 | dir = wxEAST; | |
256 | } | |
cedd7b22 | 257 | |
322c5ec4 RR |
258 | m_last3_rect = m_last2_rect; |
259 | m_last2_rect = m_last_rect; | |
50acee04 | 260 | m_last_rect = win_rect; |
be66f18e | 261 | |
50acee04 JS |
262 | if (!isMouseDown()) |
263 | return; | |
264 | ||
265 | if (!m_moving) | |
266 | { | |
267 | OnMoveStart(); | |
268 | m_moving = true; | |
269 | } | |
270 | ||
322c5ec4 RR |
271 | if (m_last3_rect.IsEmpty()) |
272 | return; | |
cedd7b22 | 273 | |
22fec94a | 274 | OnMoving(event.GetRect(), dir); |
50acee04 JS |
275 | } |
276 | ||
00c1c94c | 277 | void wxAuiFloatingFrame::OnIdle(wxIdleEvent& event) |
50acee04 JS |
278 | { |
279 | if (m_moving) | |
280 | { | |
281 | if (!isMouseDown()) | |
282 | { | |
283 | m_moving = false; | |
284 | OnMoveFinished(); | |
285 | } | |
cedd7b22 | 286 | else |
50acee04 JS |
287 | { |
288 | event.RequestMore(); | |
289 | } | |
290 | } | |
291 | } | |
292 | ||
00c1c94c | 293 | void wxAuiFloatingFrame::OnMoveStart() |
50acee04 JS |
294 | { |
295 | // notify the owner manager that the pane has started to move | |
601398b9 BP |
296 | if (m_owner_mgr) |
297 | { | |
298 | m_owner_mgr->OnFloatingPaneMoveStart(m_pane_window); | |
299 | } | |
50acee04 JS |
300 | } |
301 | ||
00c1c94c | 302 | void wxAuiFloatingFrame::OnMoving(const wxRect& WXUNUSED(window_rect), wxDirection dir) |
50acee04 JS |
303 | { |
304 | // notify the owner manager that the pane is moving | |
601398b9 BP |
305 | if (m_owner_mgr) |
306 | { | |
307 | m_owner_mgr->OnFloatingPaneMoving(m_pane_window, dir); | |
308 | } | |
322c5ec4 | 309 | m_lastDirection = dir; |
50acee04 JS |
310 | } |
311 | ||
00c1c94c | 312 | void wxAuiFloatingFrame::OnMoveFinished() |
50acee04 JS |
313 | { |
314 | // notify the owner manager that the pane has finished moving | |
601398b9 BP |
315 | if (m_owner_mgr) |
316 | { | |
317 | m_owner_mgr->OnFloatingPaneMoved(m_pane_window, m_lastDirection); | |
318 | } | |
50acee04 JS |
319 | } |
320 | ||
00c1c94c | 321 | void wxAuiFloatingFrame::OnActivate(wxActivateEvent& event) |
50acee04 | 322 | { |
601398b9 | 323 | if (m_owner_mgr && event.GetActive()) |
50acee04 JS |
324 | { |
325 | m_owner_mgr->OnFloatingPaneActivated(m_pane_window); | |
326 | } | |
327 | } | |
328 | ||
329 | // utility function which determines the state of the mouse button | |
330 | // (independant of having a wxMouseEvent handy) - utimately a better | |
331 | // mechanism for this should be found (possibly by adding the | |
332 | // functionality to wxWidgets itself) | |
00c1c94c | 333 | bool wxAuiFloatingFrame::isMouseDown() |
50acee04 | 334 | { |
45496810 | 335 | return wxGetMouseState().LeftIsDown(); |
50acee04 JS |
336 | } |
337 | ||
338 | ||
00c1c94c BW |
339 | BEGIN_EVENT_TABLE(wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass) |
340 | EVT_SIZE(wxAuiFloatingFrame::OnSize) | |
341 | EVT_MOVE(wxAuiFloatingFrame::OnMoveEvent) | |
342 | EVT_MOVING(wxAuiFloatingFrame::OnMoveEvent) | |
343 | EVT_CLOSE(wxAuiFloatingFrame::OnClose) | |
344 | EVT_IDLE(wxAuiFloatingFrame::OnIdle) | |
345 | EVT_ACTIVATE(wxAuiFloatingFrame::OnActivate) | |
50acee04 JS |
346 | END_EVENT_TABLE() |
347 | ||
348 | ||
349 | #endif // wxUSE_AUI |