]> git.saurik.com Git - wxWidgets.git/blob - src/aui/floatpane.cpp
don't use negative sizes for row/column labels subwindows to avoid GTK warnings ...
[wxWidgets.git] / src / aui / floatpane.cpp
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 && m_owner_mgr->m_action_window == this)
77 {
78 m_owner_mgr->m_action_window = NULL;
79 }
80
81 m_mgr.UnInit();
82 }
83
84 void wxAuiFloatingFrame::SetPaneWindow(const wxAuiPaneInfo& pane)
85 {
86 m_pane_window = pane.window;
87 m_pane_window->Reparent(this);
88
89 wxAuiPaneInfo contained_pane = pane;
90 contained_pane.Dock().Center().Show().
91 CaptionVisible(false).
92 PaneBorder(false).
93 Layer(0).Row(0).Position(0);
94
95 // Carry over the minimum size
96 wxSize pane_min_size = pane.window->GetMinSize();
97
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();
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 )
105 {
106 SetMaxSize(pane_min_size);
107 }
108
109 SetMinSize(pane.window->GetMinSize());
110
111 m_mgr.AddPane(m_pane_window, contained_pane);
112 m_mgr.Update();
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 }
123
124 SetTitle(pane.caption);
125
126 if (pane.floating_size != wxDefaultSize)
127 {
128 SetSize(pane.floating_size);
129 }
130 else
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();
137 if (m_owner_mgr && pane.HasGripper())
138 {
139 if (pane.HasGripperTop())
140 size.y += m_owner_mgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE);
141 else
142 size.x += m_owner_mgr->m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE);
143 }
144
145 SetClientSize(size);
146 }
147 }
148
149 wxAuiManager* wxAuiFloatingFrame::GetOwnerManager() const
150 {
151 return m_owner_mgr;
152 }
153
154
155 void wxAuiFloatingFrame::OnSize(wxSizeEvent& event)
156 {
157 if (m_owner_mgr)
158 {
159 m_owner_mgr->OnFloatingPaneResized(m_pane_window, event.GetSize());
160 }
161 }
162
163 void wxAuiFloatingFrame::OnClose(wxCloseEvent& evt)
164 {
165 if (m_owner_mgr)
166 {
167 m_owner_mgr->OnFloatingPaneClosed(m_pane_window, evt);
168 }
169 if (!evt.GetVeto())
170 {
171 m_mgr.DetachPane(m_pane_window);
172 Destroy();
173 }
174 }
175
176 void wxAuiFloatingFrame::OnMoveEvent(wxMoveEvent& event)
177 {
178 if (!m_solid_drag)
179 {
180 // systems without solid window dragging need to be
181 // handled slightly differently, due to the lack of
182 // the constant stream of EVT_MOVING events
183 if (!isMouseDown())
184 return;
185 OnMoveStart();
186 OnMoving(event.GetRect(), wxNORTH);
187 m_moving = true;
188 return;
189 }
190
191
192 wxRect win_rect = GetRect();
193
194 if (win_rect == m_last_rect)
195 return;
196
197 // skip the first move event
198 if (m_last_rect.IsEmpty())
199 {
200 m_last_rect = win_rect;
201 return;
202 }
203
204 // skip if moving too fast to avoid massive redraws and
205 // jumping hint windows
206 if ((abs(win_rect.x - m_last_rect.x) > 3) ||
207 (abs(win_rect.y - m_last_rect.y) > 3))
208 {
209 m_last3_rect = m_last2_rect;
210 m_last2_rect = m_last_rect;
211 m_last_rect = win_rect;
212 return;
213 }
214
215 // prevent frame redocking during resize
216 if (m_last_rect.GetSize() != win_rect.GetSize())
217 {
218 m_last3_rect = m_last2_rect;
219 m_last2_rect = m_last_rect;
220 m_last_rect = win_rect;
221 return;
222 }
223
224 wxDirection dir = wxALL;
225
226 int horiz_dist = abs(win_rect.x - m_last3_rect.x);
227 int vert_dist = abs(win_rect.y - m_last3_rect.y);
228
229 if (vert_dist >= horiz_dist)
230 {
231 if (win_rect.y < m_last3_rect.y)
232 dir = wxNORTH;
233 else
234 dir = wxSOUTH;
235 }
236 else
237 {
238 if (win_rect.x < m_last3_rect.x)
239 dir = wxWEST;
240 else
241 dir = wxEAST;
242 }
243
244 m_last3_rect = m_last2_rect;
245 m_last2_rect = m_last_rect;
246 m_last_rect = win_rect;
247
248 if (!isMouseDown())
249 return;
250
251 if (!m_moving)
252 {
253 OnMoveStart();
254 m_moving = true;
255 }
256
257 if (m_last3_rect.IsEmpty())
258 return;
259
260 OnMoving(event.GetRect(), dir);
261 }
262
263 void wxAuiFloatingFrame::OnIdle(wxIdleEvent& event)
264 {
265 if (m_moving)
266 {
267 if (!isMouseDown())
268 {
269 m_moving = false;
270 OnMoveFinished();
271 }
272 else
273 {
274 event.RequestMore();
275 }
276 }
277 }
278
279 void wxAuiFloatingFrame::OnMoveStart()
280 {
281 // notify the owner manager that the pane has started to move
282 if (m_owner_mgr)
283 {
284 m_owner_mgr->OnFloatingPaneMoveStart(m_pane_window);
285 }
286 }
287
288 void wxAuiFloatingFrame::OnMoving(const wxRect& WXUNUSED(window_rect), wxDirection dir)
289 {
290 // notify the owner manager that the pane is moving
291 if (m_owner_mgr)
292 {
293 m_owner_mgr->OnFloatingPaneMoving(m_pane_window, dir);
294 }
295 m_lastDirection = dir;
296 }
297
298 void wxAuiFloatingFrame::OnMoveFinished()
299 {
300 // notify the owner manager that the pane has finished moving
301 if (m_owner_mgr)
302 {
303 m_owner_mgr->OnFloatingPaneMoved(m_pane_window, m_lastDirection);
304 }
305 }
306
307 void wxAuiFloatingFrame::OnActivate(wxActivateEvent& event)
308 {
309 if (m_owner_mgr && event.GetActive())
310 {
311 m_owner_mgr->OnFloatingPaneActivated(m_pane_window);
312 }
313 }
314
315 // utility function which determines the state of the mouse button
316 // (independant of having a wxMouseEvent handy) - utimately a better
317 // mechanism for this should be found (possibly by adding the
318 // functionality to wxWidgets itself)
319 bool wxAuiFloatingFrame::isMouseDown()
320 {
321 return wxGetMouseState().LeftDown();
322 }
323
324
325 BEGIN_EVENT_TABLE(wxAuiFloatingFrame, wxAuiFloatingFrameBaseClass)
326 EVT_SIZE(wxAuiFloatingFrame::OnSize)
327 EVT_MOVE(wxAuiFloatingFrame::OnMoveEvent)
328 EVT_MOVING(wxAuiFloatingFrame::OnMoveEvent)
329 EVT_CLOSE(wxAuiFloatingFrame::OnClose)
330 EVT_IDLE(wxAuiFloatingFrame::OnIdle)
331 EVT_ACTIVATE(wxAuiFloatingFrame::OnActivate)
332 END_EVENT_TABLE()
333
334
335 #endif // wxUSE_AUI