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