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(wxAuiFloatingFrame
, wxAuiFloatingFrameBaseClass
)
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 |
49 : wxAuiFloatingFrameBaseClass(parent
, id
, wxEmptyString
,
50 pane
.floating_pos
, pane
.floating_size
,
52 (pane
.HasCloseButton()?wxCLOSE_BOX
:0) |
53 (pane
.HasMaximizeButton()?wxMAXIMIZE_BOX
:0) |
54 (pane
.IsFixed()?0:wxRESIZE_BORDER
)
57 m_owner_mgr
= owner_mgr
;
59 m_mgr
.SetManagedWindow(this);
62 // find out if the system supports solid window drag.
63 // on non-msw systems, this is assumed to be the case
66 SystemParametersInfo(38 /*SPI_GETDRAGFULLWINDOWS*/, 0, &b
, 0);
67 m_solid_drag
= b
? true : false;
70 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
73 wxAuiFloatingFrame::~wxAuiFloatingFrame()
75 // if we do not do this, then we can crash...
76 if(m_owner_mgr
&& m_owner_mgr
->m_action_window
== this)
78 m_owner_mgr
->m_action_window
= NULL
;
83 void wxAuiFloatingFrame::SetPaneWindow(const wxAuiPaneInfo
& pane
)
85 m_pane_window
= pane
.window
;
86 m_pane_window
->Reparent(this);
88 wxAuiPaneInfo contained_pane
= pane
;
89 contained_pane
.Dock().Center().Show().
90 CaptionVisible(false).
92 Layer(0).Row(0).Position(0);
94 // Carry over the minimum size
95 SetMinSize(pane
.window
->GetMinSize());
97 m_mgr
.AddPane(m_pane_window
, contained_pane
);
100 if (pane
.min_size
.IsFullySpecified())
102 // because SetSizeHints() calls Fit() too (which sets the window
103 // size to its minimum allowed), we keep the size before calling
104 // SetSizeHints() and reset it afterwards...
105 wxSize tmp
= GetSize();
106 GetSizer()->SetSizeHints(this);
110 SetTitle(pane
.caption
);
112 if (pane
.floating_size
!= wxDefaultSize
)
114 SetSize(pane
.floating_size
);
118 wxSize size
= pane
.best_size
;
119 if (size
== wxDefaultSize
)
120 size
= pane
.min_size
;
121 if (size
== wxDefaultSize
)
122 size
= m_pane_window
->GetSize();
123 if (pane
.HasGripper())
125 if (pane
.HasGripperTop())
126 size
.y
+= m_owner_mgr
->m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
128 size
.x
+= m_owner_mgr
->m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
135 wxAuiManager
* wxAuiFloatingFrame::GetOwnerManager() const
141 void wxAuiFloatingFrame::OnSize(wxSizeEvent
& event
)
143 m_owner_mgr
->OnFloatingPaneResized(m_pane_window
, event
.GetSize());
146 void wxAuiFloatingFrame::OnClose(wxCloseEvent
& evt
)
148 m_owner_mgr
->OnFloatingPaneClosed(m_pane_window
, evt
);
153 void wxAuiFloatingFrame::OnMoveEvent(wxMoveEvent
& event
)
157 // systems without solid window dragging need to be
158 // handled slightly differently, due to the lack of
159 // the constant stream of EVT_MOVING events
163 OnMoving(event
.GetRect(), wxNORTH
);
169 wxRect win_rect
= GetRect();
171 if (win_rect
== m_last_rect
)
174 // skip the first move event
175 if (m_last_rect
.IsEmpty())
177 m_last_rect
= win_rect
;
181 // skip if moving too fast to avoid massive redraws and
182 // jumping hint windows
183 if ((abs(win_rect
.x
- m_last_rect
.x
) > 3) ||
184 (abs(win_rect
.y
- m_last_rect
.y
) > 3))
186 m_last3_rect
= m_last2_rect
;
187 m_last2_rect
= m_last_rect
;
188 m_last_rect
= win_rect
;
192 // prevent frame redocking during resize
193 if (m_last_rect
.GetSize() != win_rect
.GetSize())
195 m_last3_rect
= m_last2_rect
;
196 m_last2_rect
= m_last_rect
;
197 m_last_rect
= win_rect
;
201 wxDirection dir
= wxALL
;
203 int horiz_dist
= abs(win_rect
.x
- m_last3_rect
.x
);
204 int vert_dist
= abs(win_rect
.y
- m_last3_rect
.y
);
206 if (vert_dist
>= horiz_dist
)
208 if (win_rect
.y
< m_last3_rect
.y
)
215 if (win_rect
.x
< m_last3_rect
.x
)
221 m_last3_rect
= m_last2_rect
;
222 m_last2_rect
= m_last_rect
;
223 m_last_rect
= win_rect
;
234 if (m_last3_rect
.IsEmpty())
237 OnMoving(event
.GetRect(), dir
);
240 void wxAuiFloatingFrame::OnIdle(wxIdleEvent
& event
)
256 void wxAuiFloatingFrame::OnMoveStart()
258 // notify the owner manager that the pane has started to move
259 m_owner_mgr
->OnFloatingPaneMoveStart(m_pane_window
);
262 void wxAuiFloatingFrame::OnMoving(const wxRect
& WXUNUSED(window_rect
), wxDirection dir
)
264 // notify the owner manager that the pane is moving
265 m_owner_mgr
->OnFloatingPaneMoving(m_pane_window
, dir
);
266 m_lastDirection
= dir
;
269 void wxAuiFloatingFrame::OnMoveFinished()
271 // notify the owner manager that the pane has finished moving
272 m_owner_mgr
->OnFloatingPaneMoved(m_pane_window
, m_lastDirection
);
275 void wxAuiFloatingFrame::OnActivate(wxActivateEvent
& event
)
277 if (event
.GetActive())
279 m_owner_mgr
->OnFloatingPaneActivated(m_pane_window
);
283 // utility function which determines the state of the mouse button
284 // (independant of having a wxMouseEvent handy) - utimately a better
285 // mechanism for this should be found (possibly by adding the
286 // functionality to wxWidgets itself)
287 bool wxAuiFloatingFrame::isMouseDown()
289 return wxGetMouseState().LeftDown();
293 BEGIN_EVENT_TABLE(wxAuiFloatingFrame
, wxAuiFloatingFrameBaseClass
)
294 EVT_SIZE(wxAuiFloatingFrame::OnSize
)
295 EVT_MOVE(wxAuiFloatingFrame::OnMoveEvent
)
296 EVT_MOVING(wxAuiFloatingFrame::OnMoveEvent
)
297 EVT_CLOSE(wxAuiFloatingFrame::OnClose
)
298 EVT_IDLE(wxAuiFloatingFrame::OnIdle
)
299 EVT_ACTIVATE(wxAuiFloatingFrame::OnActivate
)