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