]>
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 | | |
46 | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT | | |
47 | wxCLIP_CHILDREN | |
48 | */) | |
00c1c94c | 49 | : wxAuiFloatingFrameBaseClass(parent, id, wxEmptyString, |
e5ab82d3 | 50 | pane.floating_pos, pane.floating_size, |
bc429ce0 | 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 BW |
60 | m_solid_drag = true; |
61 | ||
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 |
22fec94a | 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... |
4dc79cfb BW |
76 | if(m_owner_mgr && m_owner_mgr->m_action_window == this) |
77 | { | |
20d64475 RR |
78 | m_owner_mgr->m_action_window = NULL; |
79 | } | |
50acee04 JS |
80 | m_mgr.UnInit(); |
81 | } | |
82 | ||
00c1c94c | 83 | void wxAuiFloatingFrame::SetPaneWindow(const wxAuiPaneInfo& pane) |
50acee04 JS |
84 | { |
85 | m_pane_window = pane.window; | |
86 | m_pane_window->Reparent(this); | |
be66f18e | 87 | |
a3a5df9d | 88 | wxAuiPaneInfo contained_pane = pane; |
50acee04 JS |
89 | contained_pane.Dock().Center().Show(). |
90 | CaptionVisible(false). | |
91 | PaneBorder(false). | |
92 | Layer(0).Row(0).Position(0); | |
be66f18e | 93 | |
5c62cb6c | 94 | // Carry over the minimum size |
bc07ab17 RD |
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.x < pane.min_size.x || | |
101 | cur_max_size.y < pane.min_size.y) | |
102 | { | |
103 | SetMaxSize(pane_min_size); | |
104 | } | |
105 | ||
5c62cb6c AB |
106 | SetMinSize(pane.window->GetMinSize()); |
107 | ||
50acee04 | 108 | m_mgr.AddPane(m_pane_window, contained_pane); |
be66f18e | 109 | m_mgr.Update(); |
50acee04 JS |
110 | |
111 | if (pane.min_size.IsFullySpecified()) | |
112 | { | |
113 | // because SetSizeHints() calls Fit() too (which sets the window | |
114 | // size to its minimum allowed), we keep the size before calling | |
115 | // SetSizeHints() and reset it afterwards... | |
116 | wxSize tmp = GetSize(); | |
117 | GetSizer()->SetSizeHints(this); | |
118 | SetSize(tmp); | |
119 | } | |
be66f18e | 120 | |
50acee04 JS |
121 | SetTitle(pane.caption); |
122 | ||
50acee04 JS |
123 | if (pane.floating_size != wxDefaultSize) |
124 | { | |
125 | SetSize(pane.floating_size); | |
126 | } | |
127 | else | |
128 | { | |
129 | wxSize size = pane.best_size; | |
130 | if (size == wxDefaultSize) | |
131 | size = pane.min_size; | |
132 | if (size == wxDefaultSize) | |
133 | size = m_pane_window->GetSize(); | |
134 | if (pane.HasGripper()) | |
135 | { | |
136 | if (pane.HasGripperTop()) | |
254a3429 | 137 | size.y += m_owner_mgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE); |
50acee04 | 138 | else |
254a3429 | 139 | size.x += m_owner_mgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE); |
50acee04 | 140 | } |
be66f18e | 141 | |
50acee04 JS |
142 | SetClientSize(size); |
143 | } | |
144 | } | |
145 | ||
4dc79cfb BW |
146 | wxAuiManager* wxAuiFloatingFrame::GetOwnerManager() const |
147 | { | |
148 | return m_owner_mgr; | |
149 | } | |
150 | ||
151 | ||
00c1c94c | 152 | void wxAuiFloatingFrame::OnSize(wxSizeEvent& event) |
50acee04 JS |
153 | { |
154 | m_owner_mgr->OnFloatingPaneResized(m_pane_window, event.GetSize()); | |
155 | } | |
156 | ||
00c1c94c | 157 | void wxAuiFloatingFrame::OnClose(wxCloseEvent& evt) |
50acee04 | 158 | { |
58754643 BW |
159 | m_owner_mgr->OnFloatingPaneClosed(m_pane_window, evt); |
160 | if (!evt.GetVeto()) | |
c68038f3 | 161 | Destroy(); |
50acee04 JS |
162 | } |
163 | ||
00c1c94c | 164 | void wxAuiFloatingFrame::OnMoveEvent(wxMoveEvent& event) |
50acee04 | 165 | { |
22fec94a BW |
166 | if (!m_solid_drag) |
167 | { | |
168 | // systems without solid window dragging need to be | |
169 | // handled slightly differently, due to the lack of | |
170 | // the constant stream of EVT_MOVING events | |
171 | if (!isMouseDown()) | |
172 | return; | |
173 | OnMoveStart(); | |
174 | OnMoving(event.GetRect(), wxNORTH); | |
175 | m_moving = true; | |
176 | return; | |
177 | } | |
178 | ||
179 | ||
50acee04 JS |
180 | wxRect win_rect = GetRect(); |
181 | ||
322c5ec4 RR |
182 | if (win_rect == m_last_rect) |
183 | return; | |
184 | ||
50acee04 JS |
185 | // skip the first move event |
186 | if (m_last_rect.IsEmpty()) | |
187 | { | |
188 | m_last_rect = win_rect; | |
189 | return; | |
190 | } | |
191 | ||
322c5ec4 RR |
192 | // skip if moving too fast to avoid massive redraws and |
193 | // jumping hint windows | |
194 | if ((abs(win_rect.x - m_last_rect.x) > 3) || | |
195 | (abs(win_rect.y - m_last_rect.y) > 3)) | |
0ae3bace | 196 | { |
322c5ec4 RR |
197 | m_last3_rect = m_last2_rect; |
198 | m_last2_rect = m_last_rect; | |
0ae3bace RR |
199 | m_last_rect = win_rect; |
200 | return; | |
201 | } | |
202 | ||
50acee04 JS |
203 | // prevent frame redocking during resize |
204 | if (m_last_rect.GetSize() != win_rect.GetSize()) | |
205 | { | |
322c5ec4 RR |
206 | m_last3_rect = m_last2_rect; |
207 | m_last2_rect = m_last_rect; | |
50acee04 JS |
208 | m_last_rect = win_rect; |
209 | return; | |
210 | } | |
211 | ||
322c5ec4 RR |
212 | wxDirection dir = wxALL; |
213 | ||
214 | int horiz_dist = abs(win_rect.x - m_last3_rect.x); | |
215 | int vert_dist = abs(win_rect.y - m_last3_rect.y); | |
216 | ||
217 | if (vert_dist >= horiz_dist) | |
218 | { | |
219 | if (win_rect.y < m_last3_rect.y) | |
220 | dir = wxNORTH; | |
221 | else | |
222 | dir = wxSOUTH; | |
223 | } | |
224 | else | |
225 | { | |
226 | if (win_rect.x < m_last3_rect.x) | |
227 | dir = wxWEST; | |
228 | else | |
229 | dir = wxEAST; | |
230 | } | |
231 | ||
232 | m_last3_rect = m_last2_rect; | |
233 | m_last2_rect = m_last_rect; | |
50acee04 | 234 | m_last_rect = win_rect; |
be66f18e | 235 | |
50acee04 JS |
236 | if (!isMouseDown()) |
237 | return; | |
238 | ||
239 | if (!m_moving) | |
240 | { | |
241 | OnMoveStart(); | |
242 | m_moving = true; | |
243 | } | |
244 | ||
322c5ec4 RR |
245 | if (m_last3_rect.IsEmpty()) |
246 | return; | |
247 | ||
22fec94a | 248 | OnMoving(event.GetRect(), dir); |
50acee04 JS |
249 | } |
250 | ||
00c1c94c | 251 | void wxAuiFloatingFrame::OnIdle(wxIdleEvent& event) |
50acee04 JS |
252 | { |
253 | if (m_moving) | |
254 | { | |
255 | if (!isMouseDown()) | |
256 | { | |
257 | m_moving = false; | |
258 | OnMoveFinished(); | |
259 | } | |
22fec94a | 260 | else |
50acee04 JS |
261 | { |
262 | event.RequestMore(); | |
263 | } | |
264 | } | |
265 | } | |
266 | ||
00c1c94c | 267 | void wxAuiFloatingFrame::OnMoveStart() |
50acee04 JS |
268 | { |
269 | // notify the owner manager that the pane has started to move | |
270 | m_owner_mgr->OnFloatingPaneMoveStart(m_pane_window); | |
271 | } | |
272 | ||
00c1c94c | 273 | void wxAuiFloatingFrame::OnMoving(const wxRect& WXUNUSED(window_rect), wxDirection dir) |
50acee04 JS |
274 | { |
275 | // notify the owner manager that the pane is moving | |
322c5ec4 RR |
276 | m_owner_mgr->OnFloatingPaneMoving(m_pane_window, dir); |
277 | m_lastDirection = dir; | |
50acee04 JS |
278 | } |
279 | ||
00c1c94c | 280 | void wxAuiFloatingFrame::OnMoveFinished() |
50acee04 JS |
281 | { |
282 | // notify the owner manager that the pane has finished moving | |
322c5ec4 | 283 | m_owner_mgr->OnFloatingPaneMoved(m_pane_window, m_lastDirection); |
50acee04 JS |
284 | } |
285 | ||
00c1c94c | 286 | void wxAuiFloatingFrame::OnActivate(wxActivateEvent& event) |
50acee04 JS |
287 | { |
288 | if (event.GetActive()) | |
289 | { | |
290 | m_owner_mgr->OnFloatingPaneActivated(m_pane_window); | |
291 | } | |
292 | } | |
293 | ||
294 | // utility function which determines the state of the mouse button | |
295 | // (independant of having a wxMouseEvent handy) - utimately a better | |
296 | // mechanism for this should be found (possibly by adding the | |
297 | // functionality to wxWidgets itself) | |
00c1c94c | 298 | bool wxAuiFloatingFrame::isMouseDown() |
50acee04 JS |
299 | { |
300 | return wxGetMouseState().LeftDown(); | |
301 | } | |
302 | ||
303 | ||
00c1c94c BW |
304 | BEGIN_EVENT_TABLE(wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass) |
305 | EVT_SIZE(wxAuiFloatingFrame::OnSize) | |
306 | EVT_MOVE(wxAuiFloatingFrame::OnMoveEvent) | |
307 | EVT_MOVING(wxAuiFloatingFrame::OnMoveEvent) | |
308 | EVT_CLOSE(wxAuiFloatingFrame::OnClose) | |
309 | EVT_IDLE(wxAuiFloatingFrame::OnIdle) | |
310 | EVT_ACTIVATE(wxAuiFloatingFrame::OnActivate) | |
50acee04 JS |
311 | END_EVENT_TABLE() |
312 | ||
313 | ||
314 | #endif // wxUSE_AUI |