]>
Commit | Line | Data |
---|---|---|
1e6feb95 VZ |
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$ | |
442b35b5 | 8 | // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com) |
1e6feb95 VZ |
9 | // Licence: wxWindows licence |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // =========================================================================== | |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
a3870b2f | 21 | #pragma implementation "univframe.h" |
1e6feb95 VZ |
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" | |
d08e6e59 | 34 | #include "wx/statusbr.h" |
443aec6f | 35 | #include "wx/toolbar.h" |
1e6feb95 VZ |
36 | #endif // WX_PRECOMP |
37 | ||
38 | // ============================================================================ | |
39 | // implementation | |
40 | // ============================================================================ | |
41 | ||
d9d4df0e | 42 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) |
1e6feb95 VZ |
43 | EVT_SIZE(wxFrame::OnSize) |
44 | END_EVENT_TABLE() | |
45 | ||
d9d4df0e | 46 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) |
1e6feb95 VZ |
47 | |
48 | // ---------------------------------------------------------------------------- | |
49 | // ctors | |
50 | // ---------------------------------------------------------------------------- | |
51 | ||
d9d4df0e VS |
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) | |
1e6feb95 | 59 | { |
d9d4df0e | 60 | return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name); |
1e6feb95 VZ |
61 | } |
62 | ||
d9d4df0e | 63 | |
1e6feb95 | 64 | // ---------------------------------------------------------------------------- |
3379ed37 | 65 | // menu support |
1e6feb95 VZ |
66 | // ---------------------------------------------------------------------------- |
67 | ||
68 | void wxFrame::OnSize(wxSizeEvent& event) | |
69 | { | |
3379ed37 | 70 | #if wxUSE_MENUS |
1e6feb95 | 71 | PositionMenuBar(); |
54800df8 | 72 | #endif // wxUSE_MENUS |
d08e6e59 VS |
73 | #if wxUSE_STATUSBAR |
74 | PositionStatusBar(); | |
75 | #endif // wxUSE_STATUSBAR | |
443aec6f VS |
76 | #if wxUSE_TOOLBAR |
77 | PositionToolBar(); | |
78 | #endif // wxUSE_TOOLBAR | |
1e6feb95 VZ |
79 | |
80 | event.Skip(); | |
81 | } | |
82 | ||
6821401b | 83 | void wxFrame::SendSizeEvent() |
71e03035 | 84 | { |
6821401b VS |
85 | wxSizeEvent event(GetSize(), GetId()); |
86 | event.SetEventObject(this); | |
87 | GetEventHandler()->ProcessEvent(event); | |
88 | } | |
89 | ||
3379ed37 VZ |
90 | #if wxUSE_MENUS |
91 | ||
1e6feb95 VZ |
92 | void wxFrame::PositionMenuBar() |
93 | { | |
1e6feb95 VZ |
94 | if ( m_frameMenuBar ) |
95 | { | |
96 | // the menubar is positioned above the client size, hence the negative | |
97 | // y coord | |
75c9da25 | 98 | wxCoord heightMbar = m_frameMenuBar->GetSize().y; |
e5053ade | 99 | |
19193a2c | 100 | m_frameMenuBar->SetSize(0, |
443aec6f VS |
101 | #ifdef __WXPM__ // FIXME -- remove this, make wxOS2/Univ behave as |
102 | // the rest of the world!!! | |
19193a2c KB |
103 | GetClientSize().y - heightMbar, |
104 | #else | |
443aec6f | 105 | -heightMbar, |
19193a2c | 106 | #endif |
75c9da25 | 107 | GetClientSize().x, heightMbar); |
1e6feb95 | 108 | } |
1e6feb95 | 109 | } |
75c9da25 | 110 | |
6821401b VS |
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 | ||
3379ed37 VZ |
123 | #endif // wxUSE_MENUS |
124 | ||
d08e6e59 VS |
125 | #if wxUSE_STATUSBAR |
126 | ||
127 | void wxFrame::PositionStatusBar() | |
128 | { | |
129 | if ( m_frameStatusBar ) | |
130 | { | |
71e03035 VZ |
131 | wxSize size = GetClientSize(); |
132 | m_frameStatusBar->SetSize(0, size.y, size.x, -1); | |
d08e6e59 VS |
133 | } |
134 | } | |
135 | ||
6821401b VS |
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 | ||
d08e6e59 VS |
144 | #endif // wxUSE_STATUSBAR |
145 | ||
443aec6f VS |
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 | ||
1e6feb95 VZ |
183 | wxPoint wxFrame::GetClientAreaOrigin() const |
184 | { | |
d9d4df0e | 185 | wxPoint pt = wxFrameBase::GetClientAreaOrigin(); |
1e6feb95 | 186 | |
19193a2c | 187 | #if wxUSE_MENUS && !defined(__WXPM__) |
1e6feb95 VZ |
188 | if ( m_frameMenuBar ) |
189 | { | |
190 | pt.y += m_frameMenuBar->GetSize().y; | |
191 | } | |
192 | #endif // wxUSE_MENUS | |
193 | ||
443aec6f VS |
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 | ||
1e6feb95 VZ |
204 | return pt; |
205 | } | |
206 | ||
a9152a05 VS |
207 | void wxFrame::DoGetClientSize(int *width, int *height) const |
208 | { | |
209 | wxFrameBase::DoGetClientSize(width, height); | |
d08e6e59 | 210 | |
a9152a05 VS |
211 | #if wxUSE_MENUS |
212 | if ( m_frameMenuBar && height ) | |
213 | { | |
214 | (*height) -= m_frameMenuBar->GetSize().y; | |
215 | } | |
216 | #endif // wxUSE_MENUS | |
d08e6e59 VS |
217 | |
218 | #if wxUSE_STATUSBAR | |
219 | if ( m_frameStatusBar && height ) | |
220 | { | |
221 | (*height) -= m_frameStatusBar->GetSize().y; | |
222 | } | |
223 | #endif // wxUSE_STATUSBAR | |
443aec6f VS |
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 | |
a9152a05 VS |
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 | |
d08e6e59 VS |
244 | |
245 | #if wxUSE_STATUSBAR | |
246 | if ( m_frameStatusBar ) | |
247 | { | |
248 | height += m_frameStatusBar->GetSize().y; | |
249 | } | |
250 | #endif // wxUSE_STATUSBAR | |
251 | ||
443aec6f VS |
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 | ||
a9152a05 VS |
264 | wxFrameBase::DoSetClientSize(width, height); |
265 | } | |
266 | ||
e7dda1ff VS |
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 | ||
d9d4df0e | 310 | bool wxFrame::Enable(bool enable) |
98363307 | 311 | { |
d9d4df0e | 312 | if (!wxFrameBase::Enable(enable)) |
443aec6f | 313 | return FALSE; |
98363307 JS |
314 | #ifdef __WXMICROWIN__ |
315 | if (m_frameMenuBar) | |
316 | m_frameMenuBar->Enable(enable); | |
317 | #endif | |
318 | return TRUE; | |
319 | } |