1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/aui/floatpane.cpp
3 // Purpose: wxaui: wx advanced user interface - docking window manager
4 // Author: Benjamin I. Williams
8 // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
9 // Licence: wxWindows Library Licence, Version 3.1
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/aui/framemanager.h"
29 #include "wx/aui/floatpane.h"
30 #include "wx/aui/dockart.h"
36 #include "wx/msw/private.h"
39 IMPLEMENT_CLASS( wxFloatingPane
, wxFloatingPaneBaseClass
)
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 |
49 : wxFloatingPaneBaseClass(parent
, id
, wxEmptyString
,
50 pane
.floating_pos
, pane
.floating_size
,
52 (pane
.HasCloseButton()?wxCLOSE_BOX
:0) |
53 (pane
.IsFixed()?0:wxRESIZE_BORDER
)
56 m_owner_mgr
= owner_mgr
;
58 m_mgr
.SetManagedWindow(this);
61 // find out if the system supports solid window drag.
62 // on non-msw systems, this is assumed to be the case
65 SystemParametersInfo(38 /*SPI_GETDRAGFULLWINDOWS*/, 0, &b
, 0);
66 m_solid_drag
= b
? true : false;
69 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
72 wxFloatingPane::~wxFloatingPane()
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
;
81 void wxFloatingPane::SetPaneWindow(const wxPaneInfo
& pane
)
83 m_pane_window
= pane
.window
;
84 m_pane_window
->Reparent(this);
86 wxPaneInfo contained_pane
= pane
;
87 contained_pane
.Dock().Center().Show().
88 CaptionVisible(false).
90 Layer(0).Row(0).Position(0);
92 // Carry over the minimum size
93 SetMinSize(pane
.window
->GetMinSize());
95 m_mgr
.AddPane(m_pane_window
, contained_pane
);
98 if (pane
.min_size
.IsFullySpecified())
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);
108 SetTitle(pane
.caption
);
110 if (pane
.floating_size
!= wxDefaultSize
)
112 SetSize(pane
.floating_size
);
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())
123 if (pane
.HasGripperTop())
124 size
.y
+= m_owner_mgr
->m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
126 size
.x
+= m_owner_mgr
->m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
133 void wxFloatingPane::OnSize(wxSizeEvent
& event
)
135 m_owner_mgr
->OnFloatingPaneResized(m_pane_window
, event
.GetSize());
138 void wxFloatingPane::OnClose(wxCloseEvent
& evt
)
140 m_owner_mgr
->OnFloatingPaneClosed(m_pane_window
, evt
);
145 void wxFloatingPane::OnMoveEvent(wxMoveEvent
& event
)
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
155 OnMoving(event
.GetRect(), wxNORTH
);
161 wxRect win_rect
= GetRect();
163 if (win_rect
== m_last_rect
)
166 // skip the first move event
167 if (m_last_rect
.IsEmpty())
169 m_last_rect
= win_rect
;
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))
178 m_last3_rect
= m_last2_rect
;
179 m_last2_rect
= m_last_rect
;
180 m_last_rect
= win_rect
;
184 // prevent frame redocking during resize
185 if (m_last_rect
.GetSize() != win_rect
.GetSize())
187 m_last3_rect
= m_last2_rect
;
188 m_last2_rect
= m_last_rect
;
189 m_last_rect
= win_rect
;
193 wxDirection dir
= wxALL
;
195 int horiz_dist
= abs(win_rect
.x
- m_last3_rect
.x
);
196 int vert_dist
= abs(win_rect
.y
- m_last3_rect
.y
);
198 if (vert_dist
>= horiz_dist
)
200 if (win_rect
.y
< m_last3_rect
.y
)
207 if (win_rect
.x
< m_last3_rect
.x
)
213 m_last3_rect
= m_last2_rect
;
214 m_last2_rect
= m_last_rect
;
215 m_last_rect
= win_rect
;
226 if (m_last3_rect
.IsEmpty())
229 OnMoving(event
.GetRect(), dir
);
232 void wxFloatingPane::OnIdle(wxIdleEvent
& event
)
248 void wxFloatingPane::OnMoveStart()
250 // notify the owner manager that the pane has started to move
251 m_owner_mgr
->OnFloatingPaneMoveStart(m_pane_window
);
254 void wxFloatingPane::OnMoving(const wxRect
& WXUNUSED(window_rect
), wxDirection dir
)
256 // notify the owner manager that the pane is moving
257 m_owner_mgr
->OnFloatingPaneMoving(m_pane_window
, dir
);
258 m_lastDirection
= dir
;
261 void wxFloatingPane::OnMoveFinished()
263 // notify the owner manager that the pane has finished moving
264 m_owner_mgr
->OnFloatingPaneMoved(m_pane_window
, m_lastDirection
);
267 void wxFloatingPane::OnActivate(wxActivateEvent
& event
)
269 if (event
.GetActive())
271 m_owner_mgr
->OnFloatingPaneActivated(m_pane_window
);
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()
281 return wxGetMouseState().LeftDown();
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
)