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