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