]>
Commit | Line | Data |
---|---|---|
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 | wxFloatingPane::wxFloatingPane(wxWindow* parent, | |
36 | wxFrameManager* owner_mgr, | |
37 | wxWindowID id /*= wxID_ANY*/, | |
38 | const wxPoint& pos /*= wxDefaultPosition*/, | |
39 | const wxSize& size /*= wxDefaultSize*/) | |
40 | : wxFloatingPaneBaseClass(parent, id, wxEmptyString, pos, size, | |
41 | wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | | |
42 | wxCLOSE_BOX | wxFRAME_NO_TASKBAR | | |
43 | wxFRAME_FLOAT_ON_PARENT | wxCLIP_CHILDREN) | |
44 | { | |
45 | m_owner_mgr = owner_mgr; | |
46 | m_moving = false; | |
47 | m_last_rect = wxRect(); | |
48 | m_mgr.SetFrame(this); | |
49 | SetExtraStyle(wxWS_EX_PROCESS_IDLE); | |
50 | } | |
51 | ||
52 | wxFloatingPane::~wxFloatingPane() | |
53 | { | |
54 | m_mgr.UnInit(); | |
55 | } | |
56 | ||
57 | void wxFloatingPane::SetPaneWindow(const wxPaneInfo& pane) | |
58 | { | |
59 | m_pane_window = pane.window; | |
60 | m_pane_window->Reparent(this); | |
61 | ||
62 | wxPaneInfo contained_pane = pane; | |
63 | contained_pane.Dock().Center().Show(). | |
64 | CaptionVisible(false). | |
65 | PaneBorder(false). | |
66 | Layer(0).Row(0).Position(0); | |
67 | ||
68 | m_mgr.AddPane(m_pane_window, contained_pane); | |
69 | m_mgr.Update(); | |
70 | ||
71 | if (pane.min_size.IsFullySpecified()) | |
72 | { | |
73 | // because SetSizeHints() calls Fit() too (which sets the window | |
74 | // size to its minimum allowed), we keep the size before calling | |
75 | // SetSizeHints() and reset it afterwards... | |
76 | wxSize tmp = GetSize(); | |
77 | GetSizer()->SetSizeHints(this); | |
78 | SetSize(tmp); | |
79 | } | |
80 | ||
81 | SetTitle(pane.caption); | |
82 | ||
83 | if (contained_pane.IsFixed()) | |
84 | SetWindowStyle(GetWindowStyle() & ~wxRESIZE_BORDER); | |
85 | ||
86 | if (pane.floating_size != wxDefaultSize) | |
87 | { | |
88 | SetSize(pane.floating_size); | |
89 | } | |
90 | else | |
91 | { | |
92 | wxSize size = pane.best_size; | |
93 | if (size == wxDefaultSize) | |
94 | size = pane.min_size; | |
95 | if (size == wxDefaultSize) | |
96 | size = m_pane_window->GetSize(); | |
97 | if (pane.HasGripper()) | |
98 | { | |
99 | if (pane.HasGripperTop()) | |
100 | size.y += m_owner_mgr->m_art->GetMetric(wxAUI_ART_GRIPPER_SIZE); | |
101 | else | |
102 | size.x += m_owner_mgr->m_art->GetMetric(wxAUI_ART_GRIPPER_SIZE); | |
103 | } | |
104 | ||
105 | SetClientSize(size); | |
106 | } | |
107 | } | |
108 | ||
109 | void wxFloatingPane::OnSize(wxSizeEvent& event) | |
110 | { | |
111 | m_owner_mgr->OnFloatingPaneResized(m_pane_window, event.GetSize()); | |
112 | } | |
113 | ||
114 | void wxFloatingPane::OnClose(wxCloseEvent& WXUNUSED(event)) | |
115 | { | |
116 | m_owner_mgr->OnFloatingPaneClosed(m_pane_window); | |
117 | Destroy(); | |
118 | } | |
119 | ||
120 | void wxFloatingPane::OnMoveEvent(wxMoveEvent& event) | |
121 | { | |
122 | wxRect win_rect = GetRect(); | |
123 | ||
124 | // skip the first move event | |
125 | if (m_last_rect.IsEmpty()) | |
126 | { | |
127 | m_last_rect = win_rect; | |
128 | return; | |
129 | } | |
130 | ||
131 | // prevent frame redocking during resize | |
132 | if (m_last_rect.GetSize() != win_rect.GetSize()) | |
133 | { | |
134 | m_last_rect = win_rect; | |
135 | return; | |
136 | } | |
137 | ||
138 | m_last_rect = win_rect; | |
139 | ||
140 | if (!isMouseDown()) | |
141 | return; | |
142 | ||
143 | if (!m_moving) | |
144 | { | |
145 | OnMoveStart(); | |
146 | m_moving = true; | |
147 | } | |
148 | ||
149 | OnMoving(event.GetRect()); | |
150 | } | |
151 | ||
152 | void wxFloatingPane::OnIdle(wxIdleEvent& event) | |
153 | { | |
154 | if (m_moving) | |
155 | { | |
156 | if (!isMouseDown()) | |
157 | { | |
158 | m_moving = false; | |
159 | OnMoveFinished(); | |
160 | } | |
161 | else | |
162 | { | |
163 | event.RequestMore(); | |
164 | } | |
165 | } | |
166 | } | |
167 | ||
168 | void wxFloatingPane::OnMoveStart() | |
169 | { | |
170 | // notify the owner manager that the pane has started to move | |
171 | m_owner_mgr->OnFloatingPaneMoveStart(m_pane_window); | |
172 | } | |
173 | ||
174 | void wxFloatingPane::OnMoving(const wxRect& WXUNUSED(window_rect)) | |
175 | { | |
176 | // notify the owner manager that the pane is moving | |
177 | m_owner_mgr->OnFloatingPaneMoving(m_pane_window); | |
178 | } | |
179 | ||
180 | void wxFloatingPane::OnMoveFinished() | |
181 | { | |
182 | // notify the owner manager that the pane has finished moving | |
183 | m_owner_mgr->OnFloatingPaneMoved(m_pane_window); | |
184 | } | |
185 | ||
186 | void wxFloatingPane::OnActivate(wxActivateEvent& event) | |
187 | { | |
188 | if (event.GetActive()) | |
189 | { | |
190 | m_owner_mgr->OnFloatingPaneActivated(m_pane_window); | |
191 | } | |
192 | } | |
193 | ||
194 | // utility function which determines the state of the mouse button | |
195 | // (independant of having a wxMouseEvent handy) - utimately a better | |
196 | // mechanism for this should be found (possibly by adding the | |
197 | // functionality to wxWidgets itself) | |
198 | bool wxFloatingPane::isMouseDown() | |
199 | { | |
200 | return wxGetMouseState().LeftDown(); | |
201 | } | |
202 | ||
203 | ||
204 | BEGIN_EVENT_TABLE(wxFloatingPane, wxFloatingPaneBaseClass) | |
205 | EVT_SIZE(wxFloatingPane::OnSize) | |
206 | EVT_MOVE(wxFloatingPane::OnMoveEvent) | |
207 | EVT_MOVING(wxFloatingPane::OnMoveEvent) | |
208 | EVT_CLOSE(wxFloatingPane::OnClose) | |
209 | EVT_IDLE(wxFloatingPane::OnIdle) | |
210 | EVT_ACTIVATE(wxFloatingPane::OnActivate) | |
211 | END_EVENT_TABLE() | |
212 | ||
213 | ||
214 | #endif // wxUSE_AUI |