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"
35 IMPLEMENT_CLASS( wxFloatingPane
, wxFloatingPaneBaseClass
)
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 |
45 : wxFloatingPaneBaseClass(parent
, id
, wxEmptyString
,
46 pane
.floating_pos
, pane
.floating_size
,
48 (pane
.HasCloseButton()?wxCLOSE_BOX
:0) |
49 (pane
.IsFixed()?0:wxRESIZE_BORDER
)
52 m_owner_mgr
= owner_mgr
;
54 m_mgr
.SetManagedWindow(this);
57 // find out if the system supports solid window drag.
58 // on non-msw systems, this is assumed to be the case
61 SystemParametersInfo(38 /*SPI_GETDRAGFULLWINDOWS*/, 0, &b
, 0);
62 m_solid_drag
= b
? true : false;
65 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
68 wxFloatingPane::~wxFloatingPane()
73 void wxFloatingPane::SetPaneWindow(const wxPaneInfo
& pane
)
75 m_pane_window
= pane
.window
;
76 m_pane_window
->Reparent(this);
78 wxPaneInfo contained_pane
= pane
;
79 contained_pane
.Dock().Center().Show().
80 CaptionVisible(false).
82 Layer(0).Row(0).Position(0);
84 // Carry over the minimum size
85 SetMinSize(pane
.window
->GetMinSize());
87 m_mgr
.AddPane(m_pane_window
, contained_pane
);
90 if (pane
.min_size
.IsFullySpecified())
92 // because SetSizeHints() calls Fit() too (which sets the window
93 // size to its minimum allowed), we keep the size before calling
94 // SetSizeHints() and reset it afterwards...
95 wxSize tmp
= GetSize();
96 GetSizer()->SetSizeHints(this);
100 SetTitle(pane
.caption
);
102 if (pane
.floating_size
!= wxDefaultSize
)
104 SetSize(pane
.floating_size
);
108 wxSize size
= pane
.best_size
;
109 if (size
== wxDefaultSize
)
110 size
= pane
.min_size
;
111 if (size
== wxDefaultSize
)
112 size
= m_pane_window
->GetSize();
113 if (pane
.HasGripper())
115 if (pane
.HasGripperTop())
116 size
.y
+= m_owner_mgr
->m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
118 size
.x
+= m_owner_mgr
->m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
125 void wxFloatingPane::OnSize(wxSizeEvent
& event
)
127 m_owner_mgr
->OnFloatingPaneResized(m_pane_window
, event
.GetSize());
130 void wxFloatingPane::OnClose(wxCloseEvent
& evt
)
132 m_owner_mgr
->OnFloatingPaneClosed(m_pane_window
, evt
);
137 void wxFloatingPane::OnMoveEvent(wxMoveEvent
& event
)
141 // systems without solid window dragging need to be
142 // handled slightly differently, due to the lack of
143 // the constant stream of EVT_MOVING events
147 OnMoving(event
.GetRect(), wxNORTH
);
153 wxRect win_rect
= GetRect();
155 if (win_rect
== m_last_rect
)
158 // skip the first move event
159 if (m_last_rect
.IsEmpty())
161 m_last_rect
= win_rect
;
165 // skip if moving too fast to avoid massive redraws and
166 // jumping hint windows
167 if ((abs(win_rect
.x
- m_last_rect
.x
) > 3) ||
168 (abs(win_rect
.y
- m_last_rect
.y
) > 3))
170 m_last3_rect
= m_last2_rect
;
171 m_last2_rect
= m_last_rect
;
172 m_last_rect
= win_rect
;
176 // prevent frame redocking during resize
177 if (m_last_rect
.GetSize() != win_rect
.GetSize())
179 m_last3_rect
= m_last2_rect
;
180 m_last2_rect
= m_last_rect
;
181 m_last_rect
= win_rect
;
185 wxDirection dir
= wxALL
;
187 int horiz_dist
= abs(win_rect
.x
- m_last3_rect
.x
);
188 int vert_dist
= abs(win_rect
.y
- m_last3_rect
.y
);
190 if (vert_dist
>= horiz_dist
)
192 if (win_rect
.y
< m_last3_rect
.y
)
199 if (win_rect
.x
< m_last3_rect
.x
)
205 m_last3_rect
= m_last2_rect
;
206 m_last2_rect
= m_last_rect
;
207 m_last_rect
= win_rect
;
218 if (m_last3_rect
.IsEmpty())
221 OnMoving(event
.GetRect(), dir
);
224 void wxFloatingPane::OnIdle(wxIdleEvent
& event
)
240 void wxFloatingPane::OnMoveStart()
242 // notify the owner manager that the pane has started to move
243 m_owner_mgr
->OnFloatingPaneMoveStart(m_pane_window
);
246 void wxFloatingPane::OnMoving(const wxRect
& WXUNUSED(window_rect
), wxDirection dir
)
248 // notify the owner manager that the pane is moving
249 m_owner_mgr
->OnFloatingPaneMoving(m_pane_window
, dir
);
250 m_lastDirection
= dir
;
253 void wxFloatingPane::OnMoveFinished()
255 // notify the owner manager that the pane has finished moving
256 m_owner_mgr
->OnFloatingPaneMoved(m_pane_window
, m_lastDirection
);
259 void wxFloatingPane::OnActivate(wxActivateEvent
& event
)
261 if (event
.GetActive())
263 m_owner_mgr
->OnFloatingPaneActivated(m_pane_window
);
267 // utility function which determines the state of the mouse button
268 // (independant of having a wxMouseEvent handy) - utimately a better
269 // mechanism for this should be found (possibly by adding the
270 // functionality to wxWidgets itself)
271 bool wxFloatingPane::isMouseDown()
273 return wxGetMouseState().LeftDown();
277 BEGIN_EVENT_TABLE(wxFloatingPane
, wxFloatingPaneBaseClass
)
278 EVT_SIZE(wxFloatingPane::OnSize
)
279 EVT_MOVE(wxFloatingPane::OnMoveEvent
)
280 EVT_MOVING(wxFloatingPane::OnMoveEvent
)
281 EVT_CLOSE(wxFloatingPane::OnClose
)
282 EVT_IDLE(wxFloatingPane::OnIdle
)
283 EVT_ACTIVATE(wxFloatingPane::OnActivate
)