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