]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: univ/frame.cpp | |
3 | // Purpose: wxFrame class for wxUniversal | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 19.05.01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com) | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // =========================================================================== | |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "univframe.h" | |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #include "wx/menu.h" | |
32 | #ifndef WX_PRECOMP | |
33 | #include "wx/frame.h" | |
34 | #include "wx/statusbr.h" | |
35 | #include "wx/toolbar.h" | |
36 | #endif // WX_PRECOMP | |
37 | ||
38 | // ============================================================================ | |
39 | // implementation | |
40 | // ============================================================================ | |
41 | ||
42 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) | |
43 | EVT_SIZE(wxFrame::OnSize) | |
44 | END_EVENT_TABLE() | |
45 | ||
46 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) | |
47 | ||
48 | // ---------------------------------------------------------------------------- | |
49 | // ctors | |
50 | // ---------------------------------------------------------------------------- | |
51 | ||
52 | bool wxFrame::Create(wxWindow *parent, | |
53 | wxWindowID id, | |
54 | const wxString& title, | |
55 | const wxPoint& pos, | |
56 | const wxSize& size, | |
57 | long style, | |
58 | const wxString& name) | |
59 | { | |
60 | return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name); | |
61 | } | |
62 | ||
63 | ||
64 | // ---------------------------------------------------------------------------- | |
65 | // menu support | |
66 | // ---------------------------------------------------------------------------- | |
67 | ||
68 | void wxFrame::OnSize(wxSizeEvent& event) | |
69 | { | |
70 | #if wxUSE_MENUS | |
71 | PositionMenuBar(); | |
72 | #endif // wxUSE_MENUS | |
73 | #if wxUSE_STATUSBAR | |
74 | PositionStatusBar(); | |
75 | #endif // wxUSE_STATUSBAR | |
76 | #if wxUSE_TOOLBAR | |
77 | PositionToolBar(); | |
78 | #endif // wxUSE_TOOLBAR | |
79 | ||
80 | event.Skip(); | |
81 | } | |
82 | ||
83 | void wxFrame::SendSizeEvent() | |
84 | { | |
85 | wxSizeEvent event(GetSize(), GetId()); | |
86 | event.SetEventObject(this); | |
87 | GetEventHandler()->ProcessEvent(event); | |
88 | } | |
89 | ||
90 | #if wxUSE_MENUS | |
91 | ||
92 | void wxFrame::PositionMenuBar() | |
93 | { | |
94 | if ( m_frameMenuBar ) | |
95 | { | |
96 | // the menubar is positioned above the client size, hence the negative | |
97 | // y coord | |
98 | wxCoord heightMbar = m_frameMenuBar->GetSize().y; | |
99 | ||
100 | m_frameMenuBar->SetSize(0, | |
101 | #ifdef __WXPM__ // FIXME -- remove this, make wxOS2/Univ behave as | |
102 | // the rest of the world!!! | |
103 | GetClientSize().y - heightMbar, | |
104 | #else | |
105 | -heightMbar, | |
106 | #endif | |
107 | GetClientSize().x, heightMbar); | |
108 | } | |
109 | } | |
110 | ||
111 | void wxFrame::DetachMenuBar() | |
112 | { | |
113 | wxFrameBase::DetachMenuBar(); | |
114 | SendSizeEvent(); | |
115 | } | |
116 | ||
117 | void wxFrame::AttachMenuBar(wxMenuBar *menubar) | |
118 | { | |
119 | wxFrameBase::AttachMenuBar(menubar); | |
120 | SendSizeEvent(); | |
121 | } | |
122 | ||
123 | #endif // wxUSE_MENUS | |
124 | ||
125 | #if wxUSE_STATUSBAR | |
126 | ||
127 | void wxFrame::PositionStatusBar() | |
128 | { | |
129 | if ( m_frameStatusBar ) | |
130 | { | |
131 | wxSize size = GetClientSize(); | |
132 | m_frameStatusBar->SetSize(0, size.y, size.x, -1); | |
133 | } | |
134 | } | |
135 | ||
136 | wxStatusBar* wxFrame::CreateStatusBar(int number, long style, | |
137 | wxWindowID id, const wxString& name) | |
138 | { | |
139 | wxStatusBar *bar = wxFrameBase::CreateStatusBar(number, style, id, name); | |
140 | SendSizeEvent(); | |
141 | return bar; | |
142 | } | |
143 | ||
144 | #endif // wxUSE_STATUSBAR | |
145 | ||
146 | #if wxUSE_TOOLBAR | |
147 | ||
148 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) | |
149 | { | |
150 | if ( wxFrameBase::CreateToolBar(style, id, name) ) | |
151 | { | |
152 | PositionToolBar(); | |
153 | } | |
154 | ||
155 | return m_frameToolBar; | |
156 | } | |
157 | ||
158 | void wxFrame::PositionToolBar() | |
159 | { | |
160 | if ( m_frameToolBar ) | |
161 | { | |
162 | wxSize size = GetClientSize(); | |
163 | int tw, th, tx, ty; | |
164 | ||
165 | tx = ty = 0; | |
166 | m_frameToolBar->GetSize(&tw, &th); | |
167 | if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
168 | { | |
169 | tx = -tw; | |
170 | th = size.y; | |
171 | } | |
172 | else | |
173 | { | |
174 | ty = -th; | |
175 | tw = size.x; | |
176 | } | |
177 | ||
178 | m_frameToolBar->SetSize(tx, ty, tw, th); | |
179 | } | |
180 | } | |
181 | #endif // wxUSE_TOOLBAR | |
182 | ||
183 | wxPoint wxFrame::GetClientAreaOrigin() const | |
184 | { | |
185 | wxPoint pt = wxFrameBase::GetClientAreaOrigin(); | |
186 | ||
187 | #if wxUSE_MENUS && !defined(__WXPM__) | |
188 | if ( m_frameMenuBar ) | |
189 | { | |
190 | pt.y += m_frameMenuBar->GetSize().y; | |
191 | } | |
192 | #endif // wxUSE_MENUS | |
193 | ||
194 | #if wxUSE_TOOLBAR | |
195 | if ( m_frameToolBar ) | |
196 | { | |
197 | if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
198 | pt.x += m_frameToolBar->GetSize().x; | |
199 | else | |
200 | pt.y += m_frameToolBar->GetSize().y; | |
201 | } | |
202 | #endif // wxUSE_TOOLBAR | |
203 | ||
204 | return pt; | |
205 | } | |
206 | ||
207 | void wxFrame::DoGetClientSize(int *width, int *height) const | |
208 | { | |
209 | wxFrameBase::DoGetClientSize(width, height); | |
210 | ||
211 | #if wxUSE_MENUS | |
212 | if ( m_frameMenuBar && height ) | |
213 | { | |
214 | (*height) -= m_frameMenuBar->GetSize().y; | |
215 | } | |
216 | #endif // wxUSE_MENUS | |
217 | ||
218 | #if wxUSE_STATUSBAR | |
219 | if ( m_frameStatusBar && height ) | |
220 | { | |
221 | (*height) -= m_frameStatusBar->GetSize().y; | |
222 | } | |
223 | #endif // wxUSE_STATUSBAR | |
224 | ||
225 | #if wxUSE_TOOLBAR | |
226 | if ( m_frameToolBar ) | |
227 | { | |
228 | if ( width && (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL) ) | |
229 | (*width) -= m_frameToolBar->GetSize().x; | |
230 | else if ( height ) | |
231 | (*height) -= m_frameToolBar->GetSize().y; | |
232 | } | |
233 | #endif // wxUSE_TOOLBAR | |
234 | } | |
235 | ||
236 | void wxFrame::DoSetClientSize(int width, int height) | |
237 | { | |
238 | #if wxUSE_MENUS | |
239 | if ( m_frameMenuBar ) | |
240 | { | |
241 | height += m_frameMenuBar->GetSize().y; | |
242 | } | |
243 | #endif // wxUSE_MENUS | |
244 | ||
245 | #if wxUSE_STATUSBAR | |
246 | if ( m_frameStatusBar ) | |
247 | { | |
248 | height += m_frameStatusBar->GetSize().y; | |
249 | } | |
250 | #endif // wxUSE_STATUSBAR | |
251 | ||
252 | #if wxUSE_TOOLBAR | |
253 | if ( m_frameToolBar ) | |
254 | { | |
255 | height += m_frameStatusBar->GetSize().y; | |
256 | ||
257 | if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
258 | width += m_frameToolBar->GetSize().x; | |
259 | else | |
260 | height += m_frameToolBar->GetSize().y; | |
261 | } | |
262 | #endif // wxUSE_TOOLBAR | |
263 | ||
264 | wxFrameBase::DoSetClientSize(width, height); | |
265 | } | |
266 | ||
267 | int wxFrame::GetMinWidth() const | |
268 | { | |
269 | #if wxUSE_MENUS | |
270 | if ( m_frameMenuBar ) | |
271 | { | |
272 | return wxMax(m_frameMenuBar->GetBestSize().x, wxFrameBase::GetMinWidth()); | |
273 | } | |
274 | else | |
275 | #endif // wxUSE_MENUS | |
276 | return wxFrameBase::GetMinWidth(); | |
277 | } | |
278 | ||
279 | int wxFrame::GetMinHeight() const | |
280 | { | |
281 | int height = 0; | |
282 | ||
283 | #if wxUSE_MENUS | |
284 | if ( m_frameMenuBar ) | |
285 | { | |
286 | height += m_frameMenuBar->GetSize().y; | |
287 | } | |
288 | #endif // wxUSE_MENUS | |
289 | ||
290 | #if wxUSE_TOOLBAR | |
291 | if ( m_frameToolBar ) | |
292 | { | |
293 | height += m_frameToolBar->GetSize().y; | |
294 | } | |
295 | #endif // wxUSE_TOOLBAR | |
296 | ||
297 | #if wxUSE_STATUSBAR | |
298 | if ( m_frameStatusBar ) | |
299 | { | |
300 | height += m_frameStatusBar->GetSize().y; | |
301 | } | |
302 | #endif // wxUSE_STATUSBAR | |
303 | ||
304 | if ( height ) | |
305 | return height + wxMax(0, wxFrameBase::GetMinHeight()); | |
306 | else | |
307 | return wxFrameBase::GetMinHeight(); | |
308 | } | |
309 | ||
310 | bool wxFrame::Enable(bool enable) | |
311 | { | |
312 | if (!wxFrameBase::Enable(enable)) | |
313 | return FALSE; | |
314 | #ifdef __WXMICROWIN__ | |
315 | if (m_frameMenuBar) | |
316 | m_frameMenuBar->Enable(enable); | |
317 | #endif | |
318 | return TRUE; | |
319 | } |