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);
55 SetExtraStyle(wxWS_EX_PROCESS_IDLE
);
58 wxFloatingPane::~wxFloatingPane()
63 void wxFloatingPane::SetPaneWindow(const wxPaneInfo
& pane
)
65 m_pane_window
= pane
.window
;
66 m_pane_window
->Reparent(this);
68 wxPaneInfo contained_pane
= pane
;
69 contained_pane
.Dock().Center().Show().
70 CaptionVisible(false).
72 Layer(0).Row(0).Position(0);
74 // Carry over the minimum size
75 SetMinSize(pane
.window
->GetMinSize());
77 m_mgr
.AddPane(m_pane_window
, contained_pane
);
80 if (pane
.min_size
.IsFullySpecified())
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);
90 SetTitle(pane
.caption
);
92 if (pane
.floating_size
!= wxDefaultSize
)
94 SetSize(pane
.floating_size
);
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())
105 if (pane
.HasGripperTop())
106 size
.y
+= m_owner_mgr
->m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
108 size
.x
+= m_owner_mgr
->m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
115 void wxFloatingPane::OnSize(wxSizeEvent
& event
)
117 m_owner_mgr
->OnFloatingPaneResized(m_pane_window
, event
.GetSize());
120 void wxFloatingPane::OnClose(wxCloseEvent
& evt
)
122 m_owner_mgr
->OnFloatingPaneClosed(m_pane_window
, evt
);
127 void wxFloatingPane::OnMoveEvent(wxMoveEvent
& event
)
129 wxRect win_rect
= GetRect();
131 if (win_rect
== m_last_rect
)
134 // skip the first move event
135 if (m_last_rect
.IsEmpty())
137 m_last_rect
= win_rect
;
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))
146 m_last3_rect
= m_last2_rect
;
147 m_last2_rect
= m_last_rect
;
148 m_last_rect
= win_rect
;
152 // prevent frame redocking during resize
153 if (m_last_rect
.GetSize() != win_rect
.GetSize())
155 m_last3_rect
= m_last2_rect
;
156 m_last2_rect
= m_last_rect
;
157 m_last_rect
= win_rect
;
161 wxDirection dir
= wxALL
;
163 int horiz_dist
= abs(win_rect
.x
- m_last3_rect
.x
);
164 int vert_dist
= abs(win_rect
.y
- m_last3_rect
.y
);
166 if (vert_dist
>= horiz_dist
)
168 if (win_rect
.y
< m_last3_rect
.y
)
175 if (win_rect
.x
< m_last3_rect
.x
)
181 m_last3_rect
= m_last2_rect
;
182 m_last2_rect
= m_last_rect
;
183 m_last_rect
= win_rect
;
194 if (m_last3_rect
.IsEmpty())
197 OnMoving(event
.GetRect(), dir
);
200 void wxFloatingPane::OnIdle(wxIdleEvent
& event
)
216 void wxFloatingPane::OnMoveStart()
218 // notify the owner manager that the pane has started to move
219 m_owner_mgr
->OnFloatingPaneMoveStart(m_pane_window
);
222 void wxFloatingPane::OnMoving(const wxRect
& WXUNUSED(window_rect
), wxDirection dir
)
224 // notify the owner manager that the pane is moving
225 m_owner_mgr
->OnFloatingPaneMoving(m_pane_window
, dir
);
226 m_lastDirection
= dir
;
229 void wxFloatingPane::OnMoveFinished()
231 // notify the owner manager that the pane has finished moving
232 m_owner_mgr
->OnFloatingPaneMoved(m_pane_window
, m_lastDirection
);
235 void wxFloatingPane::OnActivate(wxActivateEvent
& event
)
237 if (event
.GetActive())
239 m_owner_mgr
->OnFloatingPaneActivated(m_pane_window
);
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()
249 return wxGetMouseState().LeftDown();
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
)