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