]>
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 | ||
3379ed37 VZ |
95 | #if wxUSE_MENUS |
96 | ||
1e6feb95 VZ |
97 | void wxFrame::PositionMenuBar() |
98 | { | |
1e6feb95 VZ |
99 | if ( m_frameMenuBar ) |
100 | { | |
101 | // the menubar is positioned above the client size, hence the negative | |
102 | // y coord | |
75c9da25 | 103 | wxCoord heightMbar = m_frameMenuBar->GetSize().y; |
16c9a425 | 104 | |
d1017acf | 105 | wxCoord heightTbar = 0; |
6a317e61 VZ |
106 | |
107 | #if wxUSE_TOOLBAR | |
108 | if ( m_frameToolBar ) | |
d1017acf | 109 | heightTbar = m_frameToolBar->GetSize().y; |
6a317e61 | 110 | #endif // wxUSE_TOOLBAR |
e5053ade | 111 | |
6a317e61 | 112 | m_frameMenuBar->SetSize(0, |
a290fa5a | 113 | #ifdef __WXPM__ // FIXME -- remove this, make wxOS2/Univ behave as |
443aec6f | 114 | // the rest of the world!!! |
16c9a425 | 115 | GetClientSize().y - heightMbar - heightTbar, |
19193a2c | 116 | #else |
16c9a425 | 117 | - (heightMbar + heightTbar), |
6a317e61 | 118 | #endif |
75c9da25 | 119 | GetClientSize().x, heightMbar); |
1e6feb95 | 120 | } |
1e6feb95 | 121 | } |
75c9da25 | 122 | |
6821401b VS |
123 | void wxFrame::DetachMenuBar() |
124 | { | |
125 | wxFrameBase::DetachMenuBar(); | |
126 | SendSizeEvent(); | |
127 | } | |
128 | ||
129 | void wxFrame::AttachMenuBar(wxMenuBar *menubar) | |
130 | { | |
131 | wxFrameBase::AttachMenuBar(menubar); | |
132 | SendSizeEvent(); | |
133 | } | |
134 | ||
3379ed37 VZ |
135 | #endif // wxUSE_MENUS |
136 | ||
d08e6e59 VS |
137 | #if wxUSE_STATUSBAR |
138 | ||
139 | void wxFrame::PositionStatusBar() | |
140 | { | |
141 | if ( m_frameStatusBar ) | |
142 | { | |
71e03035 | 143 | wxSize size = GetClientSize(); |
a290fa5a | 144 | m_frameStatusBar->SetSize(0, size.y, size.x, wxDefaultCoord); |
d08e6e59 VS |
145 | } |
146 | } | |
147 | ||
6821401b VS |
148 | wxStatusBar* wxFrame::CreateStatusBar(int number, long style, |
149 | wxWindowID id, const wxString& name) | |
150 | { | |
151 | wxStatusBar *bar = wxFrameBase::CreateStatusBar(number, style, id, name); | |
152 | SendSizeEvent(); | |
153 | return bar; | |
154 | } | |
155 | ||
d08e6e59 VS |
156 | #endif // wxUSE_STATUSBAR |
157 | ||
443aec6f VS |
158 | #if wxUSE_TOOLBAR |
159 | ||
160 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) | |
161 | { | |
162 | if ( wxFrameBase::CreateToolBar(style, id, name) ) | |
163 | { | |
164 | PositionToolBar(); | |
165 | } | |
166 | ||
167 | return m_frameToolBar; | |
168 | } | |
169 | ||
170 | void wxFrame::PositionToolBar() | |
171 | { | |
172 | if ( m_frameToolBar ) | |
173 | { | |
174 | wxSize size = GetClientSize(); | |
175 | int tw, th, tx, ty; | |
176 | ||
177 | tx = ty = 0; | |
178 | m_frameToolBar->GetSize(&tw, &th); | |
179 | if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
180 | { | |
181 | tx = -tw; | |
182 | th = size.y; | |
183 | } | |
184 | else | |
185 | { | |
186 | ty = -th; | |
187 | tw = size.x; | |
188 | } | |
189 | ||
190 | m_frameToolBar->SetSize(tx, ty, tw, th); | |
191 | } | |
192 | } | |
193 | #endif // wxUSE_TOOLBAR | |
194 | ||
1e6feb95 VZ |
195 | wxPoint wxFrame::GetClientAreaOrigin() const |
196 | { | |
d9d4df0e | 197 | wxPoint pt = wxFrameBase::GetClientAreaOrigin(); |
1e6feb95 | 198 | |
19193a2c | 199 | #if wxUSE_MENUS && !defined(__WXPM__) |
1e6feb95 VZ |
200 | if ( m_frameMenuBar ) |
201 | { | |
202 | pt.y += m_frameMenuBar->GetSize().y; | |
203 | } | |
204 | #endif // wxUSE_MENUS | |
205 | ||
5e885a58 | 206 | #if wxUSE_TOOLBAR |
443aec6f VS |
207 | if ( m_frameToolBar ) |
208 | { | |
209 | if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
210 | pt.x += m_frameToolBar->GetSize().x; | |
211 | else | |
212 | pt.y += m_frameToolBar->GetSize().y; | |
213 | } | |
214 | #endif // wxUSE_TOOLBAR | |
215 | ||
1e6feb95 VZ |
216 | return pt; |
217 | } | |
218 | ||
a9152a05 VS |
219 | void wxFrame::DoGetClientSize(int *width, int *height) const |
220 | { | |
221 | wxFrameBase::DoGetClientSize(width, height); | |
d08e6e59 | 222 | |
a9152a05 VS |
223 | #if wxUSE_MENUS |
224 | if ( m_frameMenuBar && height ) | |
225 | { | |
226 | (*height) -= m_frameMenuBar->GetSize().y; | |
227 | } | |
228 | #endif // wxUSE_MENUS | |
d08e6e59 VS |
229 | |
230 | #if wxUSE_STATUSBAR | |
231 | if ( m_frameStatusBar && height ) | |
232 | { | |
233 | (*height) -= m_frameStatusBar->GetSize().y; | |
234 | } | |
235 | #endif // wxUSE_STATUSBAR | |
443aec6f VS |
236 | |
237 | #if wxUSE_TOOLBAR | |
238 | if ( m_frameToolBar ) | |
239 | { | |
240 | if ( width && (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL) ) | |
241 | (*width) -= m_frameToolBar->GetSize().x; | |
242 | else if ( height ) | |
243 | (*height) -= m_frameToolBar->GetSize().y; | |
244 | } | |
245 | #endif // wxUSE_TOOLBAR | |
a9152a05 VS |
246 | } |
247 | ||
248 | void wxFrame::DoSetClientSize(int width, int height) | |
249 | { | |
250 | #if wxUSE_MENUS | |
251 | if ( m_frameMenuBar ) | |
252 | { | |
253 | height += m_frameMenuBar->GetSize().y; | |
254 | } | |
255 | #endif // wxUSE_MENUS | |
d08e6e59 VS |
256 | |
257 | #if wxUSE_STATUSBAR | |
258 | if ( m_frameStatusBar ) | |
259 | { | |
260 | height += m_frameStatusBar->GetSize().y; | |
261 | } | |
262 | #endif // wxUSE_STATUSBAR | |
263 | ||
443aec6f VS |
264 | #if wxUSE_TOOLBAR |
265 | if ( m_frameToolBar ) | |
266 | { | |
67a99992 | 267 | #if wxUSE_STATUSBAR |
443aec6f | 268 | height += m_frameStatusBar->GetSize().y; |
67a99992 | 269 | #endif // wxUSE_STATUSBAR |
443aec6f VS |
270 | |
271 | if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
272 | width += m_frameToolBar->GetSize().x; | |
273 | else | |
274 | height += m_frameToolBar->GetSize().y; | |
275 | } | |
276 | #endif // wxUSE_TOOLBAR | |
277 | ||
a9152a05 VS |
278 | wxFrameBase::DoSetClientSize(width, height); |
279 | } | |
280 | ||
894057d1 | 281 | wxSize wxFrame::GetMinSize() const |
e7dda1ff | 282 | { |
894057d1 | 283 | wxSize size = wxFrameBase::GetMinSize(); |
e7dda1ff VS |
284 | |
285 | #if wxUSE_MENUS | |
286 | if ( m_frameMenuBar ) | |
287 | { | |
894057d1 VZ |
288 | const wxSize sizeMenu = m_frameMenuBar->GetBestSize(); |
289 | if ( sizeMenu.x > size.x ) | |
290 | size.x = sizeMenu.x; | |
291 | size.y += sizeMenu.y; | |
e7dda1ff VS |
292 | } |
293 | #endif // wxUSE_MENUS | |
294 | ||
295 | #if wxUSE_TOOLBAR | |
296 | if ( m_frameToolBar ) | |
297 | { | |
894057d1 | 298 | size.y += m_frameToolBar->GetSize().y; |
e7dda1ff VS |
299 | } |
300 | #endif // wxUSE_TOOLBAR | |
301 | ||
302 | #if wxUSE_STATUSBAR | |
303 | if ( m_frameStatusBar ) | |
304 | { | |
894057d1 | 305 | size.y += m_frameStatusBar->GetSize().y; |
e7dda1ff VS |
306 | } |
307 | #endif // wxUSE_STATUSBAR | |
6a317e61 | 308 | |
894057d1 | 309 | return size; |
e7dda1ff VS |
310 | } |
311 | ||
d9d4df0e | 312 | bool wxFrame::Enable(bool enable) |
98363307 | 313 | { |
d9d4df0e | 314 | if (!wxFrameBase::Enable(enable)) |
a290fa5a | 315 | return false; |
98363307 JS |
316 | #ifdef __WXMICROWIN__ |
317 | if (m_frameMenuBar) | |
318 | m_frameMenuBar->Enable(enable); | |
319 | #endif | |
a290fa5a | 320 | return true; |
98363307 | 321 | } |