Work around problems with sizing floating panes on GTK
[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 : wxFloatingPaneBaseClass(parent, id, wxEmptyString,
42 pane.floating_pos, pane.floating_size,
43 wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION |
44 (pane.HasCloseButton()?wxCLOSE_BOX:0) |
45 wxFRAME_NO_TASKBAR |
46 wxFRAME_FLOAT_ON_PARENT | wxCLIP_CHILDREN |
47 (pane.IsFixed()?0:wxRESIZE_BORDER)
48 )
49 {
50 m_owner_mgr = owner_mgr;
51 m_moving = false;
52 m_last_rect = wxRect();
53 m_mgr.SetManagedWindow(this);
54 SetExtraStyle(wxWS_EX_PROCESS_IDLE);
55 }
56
57 wxFloatingPane::~wxFloatingPane()
58 {
59 m_mgr.UnInit();
60 }
61
62 void wxFloatingPane::SetPaneWindow(const wxPaneInfo& pane)
63 {
64 m_pane_window = pane.window;
65 m_pane_window->Reparent(this);
66
67 wxPaneInfo contained_pane = pane;
68 contained_pane.Dock().Center().Show().
69 CaptionVisible(false).
70 PaneBorder(false).
71 Layer(0).Row(0).Position(0);
72
73 // Carry over the minimum size
74 SetMinSize(pane.window->GetMinSize());
75
76 m_mgr.AddPane(m_pane_window, contained_pane);
77 m_mgr.Update();
78
79 if (pane.min_size.IsFullySpecified())
80 {
81 // because SetSizeHints() calls Fit() too (which sets the window
82 // size to its minimum allowed), we keep the size before calling
83 // SetSizeHints() and reset it afterwards...
84 wxSize tmp = GetSize();
85 GetSizer()->SetSizeHints(this);
86 SetSize(tmp);
87 }
88
89 SetTitle(pane.caption);
90
91 if (pane.floating_size != wxDefaultSize)
92 {
93 SetSize(pane.floating_size);
94 }
95 else
96 {
97 wxSize size = pane.best_size;
98 if (size == wxDefaultSize)
99 size = pane.min_size;
100 if (size == wxDefaultSize)
101 size = m_pane_window->GetSize();
102 if (pane.HasGripper())
103 {
104 if (pane.HasGripperTop())
105 size.y += m_owner_mgr->m_art->GetMetric(wxAUI_ART_GRIPPER_SIZE);
106 else
107 size.x += m_owner_mgr->m_art->GetMetric(wxAUI_ART_GRIPPER_SIZE);
108 }
109
110 SetClientSize(size);
111 }
112 }
113
114 void wxFloatingPane::OnSize(wxSizeEvent& event)
115 {
116 m_owner_mgr->OnFloatingPaneResized(m_pane_window, event.GetSize());
117 }
118
119 void wxFloatingPane::OnClose(wxCloseEvent& evt)
120 {
121 m_owner_mgr->OnFloatingPaneClosed(m_pane_window, evt);
122 if (!evt.GetVeto())
123 Destroy();
124 }
125
126 void wxFloatingPane::OnMoveEvent(wxMoveEvent& event)
127 {
128 #ifdef __WXGTK__
129 // On wxGTK 2.6 and 2.7 for some unknown reason, wxSizeEvents are not
130 // emitted for wxFloatingPanes when they are manually resized.
131 // See Bug #1528554.
132 // However, it does (fortunately) wrongly emit wxMoveEvent in this scenario.
133 // So we having on that to update the floating pane size - let's hope noone
134 // fixes this useful bug, without fixing the above.
135 m_owner_mgr->OnFloatingPaneResized(m_pane_window, GetSize());
136 #endif
137
138 wxRect win_rect = GetRect();
139
140 // skip the first move event
141 if (m_last_rect.IsEmpty())
142 {
143 m_last_rect = win_rect;
144 return;
145 }
146
147 // prevent frame redocking during resize
148 if (m_last_rect.GetSize() != win_rect.GetSize())
149 {
150 m_last_rect = win_rect;
151 return;
152 }
153
154 m_last_rect = win_rect;
155
156 if (!isMouseDown())
157 return;
158
159 if (!m_moving)
160 {
161 OnMoveStart();
162 m_moving = true;
163 }
164
165 OnMoving(event.GetRect());
166 }
167
168 void wxFloatingPane::OnIdle(wxIdleEvent& event)
169 {
170 if (m_moving)
171 {
172 if (!isMouseDown())
173 {
174 m_moving = false;
175 OnMoveFinished();
176 }
177 else
178 {
179 event.RequestMore();
180 }
181 }
182 }
183
184 void wxFloatingPane::OnMoveStart()
185 {
186 // notify the owner manager that the pane has started to move
187 m_owner_mgr->OnFloatingPaneMoveStart(m_pane_window);
188 }
189
190 void wxFloatingPane::OnMoving(const wxRect& WXUNUSED(window_rect))
191 {
192 // notify the owner manager that the pane is moving
193 m_owner_mgr->OnFloatingPaneMoving(m_pane_window);
194 }
195
196 void wxFloatingPane::OnMoveFinished()
197 {
198 // notify the owner manager that the pane has finished moving
199 m_owner_mgr->OnFloatingPaneMoved(m_pane_window);
200 }
201
202 void wxFloatingPane::OnActivate(wxActivateEvent& event)
203 {
204 if (event.GetActive())
205 {
206 m_owner_mgr->OnFloatingPaneActivated(m_pane_window);
207 }
208 }
209
210 // utility function which determines the state of the mouse button
211 // (independant of having a wxMouseEvent handy) - utimately a better
212 // mechanism for this should be found (possibly by adding the
213 // functionality to wxWidgets itself)
214 bool wxFloatingPane::isMouseDown()
215 {
216 return wxGetMouseState().LeftDown();
217 }
218
219
220 BEGIN_EVENT_TABLE(wxFloatingPane, wxFloatingPaneBaseClass)
221 EVT_SIZE(wxFloatingPane::OnSize)
222 EVT_MOVE(wxFloatingPane::OnMoveEvent)
223 EVT_MOVING(wxFloatingPane::OnMoveEvent)
224 EVT_CLOSE(wxFloatingPane::OnClose)
225 EVT_IDLE(wxFloatingPane::OnIdle)
226 EVT_ACTIVATE(wxFloatingPane::OnActivate)
227 END_EVENT_TABLE()
228
229
230 #endif // wxUSE_AUI