]>
Commit | Line | Data |
---|---|---|
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 | #ifdef __WXMSW__ | |
36 | #include "wx/msw/private.h" | |
37 | #endif | |
38 | ||
39 | IMPLEMENT_CLASS(wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass) | |
40 | ||
41 | wxAuiFloatingFrame::wxAuiFloatingFrame(wxWindow* parent, | |
42 | wxAuiManager* owner_mgr, | |
43 | const wxAuiPaneInfo& pane, | |
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 | */) | |
49 | : wxAuiFloatingFrameBaseClass(parent, id, wxEmptyString, | |
50 | pane.floating_pos, pane.floating_size, | |
51 | style | | |
52 | (pane.HasCloseButton()?wxCLOSE_BOX:0) | | |
53 | (pane.HasMaximizeButton()?wxMAXIMIZE_BOX:0) | | |
54 | (pane.IsFixed()?0:wxRESIZE_BORDER) | |
55 | ) | |
56 | { | |
57 | m_owner_mgr = owner_mgr; | |
58 | m_moving = false; | |
59 | m_mgr.SetManagedWindow(this); | |
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 | |
64 | #ifdef __WXMSW__ | |
65 | BOOL b = TRUE; | |
66 | SystemParametersInfo(38 /*SPI_GETDRAGFULLWINDOWS*/, 0, &b, 0); | |
67 | m_solid_drag = b ? true : false; | |
68 | #endif | |
69 | ||
70 | SetExtraStyle(wxWS_EX_PROCESS_IDLE); | |
71 | } | |
72 | ||
73 | wxAuiFloatingFrame::~wxAuiFloatingFrame() | |
74 | { | |
75 | // if we do not do this, then we can crash... | |
76 | if(m_owner_mgr) | |
77 | { | |
78 | if(m_owner_mgr->m_action_window == this) | |
79 | m_owner_mgr->m_action_window = NULL; | |
80 | m_owner_mgr->UnregisterFloatingFrame(this); | |
81 | } | |
82 | ||
83 | m_mgr.UnInit(); | |
84 | } | |
85 | ||
86 | void wxAuiFloatingFrame::SetPaneWindow(const wxAuiPaneInfo& pane) | |
87 | { | |
88 | m_pane_window = pane.window; | |
89 | m_pane_window->Reparent(this); | |
90 | ||
91 | wxAuiPaneInfo contained_pane = pane; | |
92 | contained_pane.Dock().Center().Show(). | |
93 | CaptionVisible(false). | |
94 | PaneBorder(false). | |
95 | Layer(0).Row(0).Position(0); | |
96 | ||
97 | // Carry over the minimum size | |
98 | wxSize pane_min_size = pane.window->GetMinSize(); | |
99 | ||
100 | // if the frame window's max size is greater than the min size | |
101 | // then set the max size to the min size as well | |
102 | wxSize cur_max_size = GetMaxSize(); | |
103 | if (cur_max_size.IsFullySpecified() && | |
104 | (cur_max_size.x < pane.min_size.x || | |
105 | cur_max_size.y < pane.min_size.y) | |
106 | ) | |
107 | { | |
108 | SetMaxSize(pane_min_size); | |
109 | } | |
110 | ||
111 | SetMinSize(pane.window->GetMinSize()); | |
112 | ||
113 | m_mgr.AddPane(m_pane_window, contained_pane); | |
114 | m_mgr.Update(); | |
115 | ||
116 | if (pane.min_size.IsFullySpecified()) | |
117 | { | |
118 | // because SetSizeHints() calls Fit() too (which sets the window | |
119 | // size to its minimum allowed), we keep the size before calling | |
120 | // SetSizeHints() and reset it afterwards... | |
121 | wxSize tmp = GetSize(); | |
122 | GetSizer()->SetSizeHints(this); | |
123 | SetSize(tmp); | |
124 | } | |
125 | ||
126 | SetTitle(pane.caption); | |
127 | ||
128 | if (pane.floating_size != wxDefaultSize) | |
129 | { | |
130 | SetSize(pane.floating_size); | |
131 | } | |
132 | else | |
133 | { | |
134 | wxSize size = pane.best_size; | |
135 | if (size == wxDefaultSize) | |
136 | size = pane.min_size; | |
137 | if (size == wxDefaultSize) | |
138 | size = m_pane_window->GetSize(); | |
139 | if (m_owner_mgr && pane.HasGripper()) | |
140 | { | |
141 | if (pane.HasGripperTop()) | |
142 | size.y += m_owner_mgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE); | |
143 | else | |
144 | size.x += m_owner_mgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE); | |
145 | } | |
146 | ||
147 | SetClientSize(size); | |
148 | } | |
149 | } | |
150 | ||
151 | wxAuiManager* wxAuiFloatingFrame::GetOwnerManager() const | |
152 | { | |
153 | return m_owner_mgr; | |
154 | } | |
155 | ||
156 | void wxAuiFloatingFrame::SetOwnerManager(wxAuiManager* owner_mgr) | |
157 | { | |
158 | // we want to allow for NULL here to avoid crashing in dtor | |
159 | m_owner_mgr = owner_mgr; | |
160 | } | |
161 | ||
162 | void wxAuiFloatingFrame::OnSize(wxSizeEvent& event) | |
163 | { | |
164 | if (m_owner_mgr) | |
165 | { | |
166 | m_owner_mgr->OnFloatingPaneResized(m_pane_window, event.GetSize()); | |
167 | } | |
168 | } | |
169 | ||
170 | void wxAuiFloatingFrame::OnClose(wxCloseEvent& evt) | |
171 | { | |
172 | if (m_owner_mgr) | |
173 | { | |
174 | m_owner_mgr->OnFloatingPaneClosed(m_pane_window, evt); | |
175 | } | |
176 | if (!evt.GetVeto()) | |
177 | { | |
178 | m_mgr.DetachPane(m_pane_window); | |
179 | Destroy(); | |
180 | } | |
181 | } | |
182 | ||
183 | void wxAuiFloatingFrame::OnMoveEvent(wxMoveEvent& event) | |
184 | { | |
185 | if (!m_solid_drag) | |
186 | { | |
187 | // systems without solid window dragging need to be | |
188 | // handled slightly differently, due to the lack of | |
189 | // the constant stream of EVT_MOVING events | |
190 | if (!isMouseDown()) | |
191 | return; | |
192 | OnMoveStart(); | |
193 | OnMoving(event.GetRect(), wxNORTH); | |
194 | m_moving = true; | |
195 | return; | |
196 | } | |
197 | ||
198 | ||
199 | wxRect win_rect = GetRect(); | |
200 | ||
201 | if (win_rect == m_last_rect) | |
202 | return; | |
203 | ||
204 | // skip the first move event | |
205 | if (m_last_rect.IsEmpty()) | |
206 | { | |
207 | m_last_rect = win_rect; | |
208 | return; | |
209 | } | |
210 | ||
211 | // skip if moving too fast to avoid massive redraws and | |
212 | // jumping hint windows | |
213 | if ((abs(win_rect.x - m_last_rect.x) > 3) || | |
214 | (abs(win_rect.y - m_last_rect.y) > 3)) | |
215 | { | |
216 | m_last3_rect = m_last2_rect; | |
217 | m_last2_rect = m_last_rect; | |
218 | m_last_rect = win_rect; | |
219 | return; | |
220 | } | |
221 | ||
222 | // prevent frame redocking during resize | |
223 | if (m_last_rect.GetSize() != win_rect.GetSize()) | |
224 | { | |
225 | m_last3_rect = m_last2_rect; | |
226 | m_last2_rect = m_last_rect; | |
227 | m_last_rect = win_rect; | |
228 | return; | |
229 | } | |
230 | ||
231 | wxDirection dir = wxALL; | |
232 | ||
233 | int horiz_dist = abs(win_rect.x - m_last3_rect.x); | |
234 | int vert_dist = abs(win_rect.y - m_last3_rect.y); | |
235 | ||
236 | if (vert_dist >= horiz_dist) | |
237 | { | |
238 | if (win_rect.y < m_last3_rect.y) | |
239 | dir = wxNORTH; | |
240 | else | |
241 | dir = wxSOUTH; | |
242 | } | |
243 | else | |
244 | { | |
245 | if (win_rect.x < m_last3_rect.x) | |
246 | dir = wxWEST; | |
247 | else | |
248 | dir = wxEAST; | |
249 | } | |
250 | ||
251 | m_last3_rect = m_last2_rect; | |
252 | m_last2_rect = m_last_rect; | |
253 | m_last_rect = win_rect; | |
254 | ||
255 | if (!isMouseDown()) | |
256 | return; | |
257 | ||
258 | if (!m_moving) | |
259 | { | |
260 | OnMoveStart(); | |
261 | m_moving = true; | |
262 | } | |
263 | ||
264 | if (m_last3_rect.IsEmpty()) | |
265 | return; | |
266 | ||
267 | OnMoving(event.GetRect(), dir); | |
268 | } | |
269 | ||
270 | void wxAuiFloatingFrame::OnIdle(wxIdleEvent& event) | |
271 | { | |
272 | if (m_moving) | |
273 | { | |
274 | if (!isMouseDown()) | |
275 | { | |
276 | m_moving = false; | |
277 | OnMoveFinished(); | |
278 | } | |
279 | else | |
280 | { | |
281 | event.RequestMore(); | |
282 | } | |
283 | } | |
284 | } | |
285 | ||
286 | void wxAuiFloatingFrame::OnMoveStart() | |
287 | { | |
288 | // notify the owner manager that the pane has started to move | |
289 | if (m_owner_mgr) | |
290 | { | |
291 | m_owner_mgr->OnFloatingPaneMoveStart(m_pane_window); | |
292 | } | |
293 | } | |
294 | ||
295 | void wxAuiFloatingFrame::OnMoving(const wxRect& WXUNUSED(window_rect), wxDirection dir) | |
296 | { | |
297 | // notify the owner manager that the pane is moving | |
298 | if (m_owner_mgr) | |
299 | { | |
300 | m_owner_mgr->OnFloatingPaneMoving(m_pane_window, dir); | |
301 | } | |
302 | m_lastDirection = dir; | |
303 | } | |
304 | ||
305 | void wxAuiFloatingFrame::OnMoveFinished() | |
306 | { | |
307 | // notify the owner manager that the pane has finished moving | |
308 | if (m_owner_mgr) | |
309 | { | |
310 | m_owner_mgr->OnFloatingPaneMoved(m_pane_window, m_lastDirection); | |
311 | } | |
312 | } | |
313 | ||
314 | void wxAuiFloatingFrame::OnActivate(wxActivateEvent& event) | |
315 | { | |
316 | if (m_owner_mgr && event.GetActive()) | |
317 | { | |
318 | m_owner_mgr->OnFloatingPaneActivated(m_pane_window); | |
319 | } | |
320 | } | |
321 | ||
322 | // utility function which determines the state of the mouse button | |
323 | // (independant of having a wxMouseEvent handy) - utimately a better | |
324 | // mechanism for this should be found (possibly by adding the | |
325 | // functionality to wxWidgets itself) | |
326 | bool wxAuiFloatingFrame::isMouseDown() | |
327 | { | |
328 | return wxGetMouseState().LeftDown(); | |
329 | } | |
330 | ||
331 | ||
332 | BEGIN_EVENT_TABLE(wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass) | |
333 | EVT_SIZE(wxAuiFloatingFrame::OnSize) | |
334 | EVT_MOVE(wxAuiFloatingFrame::OnMoveEvent) | |
335 | EVT_MOVING(wxAuiFloatingFrame::OnMoveEvent) | |
336 | EVT_CLOSE(wxAuiFloatingFrame::OnClose) | |
337 | EVT_IDLE(wxAuiFloatingFrame::OnIdle) | |
338 | EVT_ACTIVATE(wxAuiFloatingFrame::OnActivate) | |
339 | END_EVENT_TABLE() | |
340 | ||
341 | ||
342 | #endif // wxUSE_AUI |