]> git.saurik.com Git - wxWidgets.git/blob - src/univ/framuniv.cpp
Applied #10639 (Not all previewed fonts are displayed with the correct nameface)
[wxWidgets.git] / src / univ / framuniv.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/frame.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/menu.h"
31 #include "wx/statusbr.h"
32 #include "wx/settings.h"
33 #include "wx/toolbar.h"
34 #endif // WX_PRECOMP
35
36 // ============================================================================
37 // implementation
38 // ============================================================================
39
40 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
41 EVT_SIZE(wxFrame::OnSize)
42 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
43 END_EVENT_TABLE()
44
45 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
46
47 // ----------------------------------------------------------------------------
48 // ctors
49 // ----------------------------------------------------------------------------
50
51 bool wxFrame::Create(wxWindow *parent,
52 wxWindowID id,
53 const wxString& title,
54 const wxPoint& pos,
55 const wxSize& size,
56 long style,
57 const wxString& name)
58 {
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;
65 }
66
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 }
75
76 // ----------------------------------------------------------------------------
77 // menu support
78 // ----------------------------------------------------------------------------
79
80 void wxFrame::OnSize(wxSizeEvent& event)
81 {
82 #if wxUSE_MENUS
83 PositionMenuBar();
84 #endif // wxUSE_MENUS
85 #if wxUSE_STATUSBAR
86 PositionStatusBar();
87 #endif // wxUSE_STATUSBAR
88 #if wxUSE_TOOLBAR
89 PositionToolBar();
90 #endif // wxUSE_TOOLBAR
91
92 event.Skip();
93 }
94
95 #if wxUSE_MENUS
96
97 void wxFrame::PositionMenuBar()
98 {
99 if ( m_frameMenuBar )
100 {
101 // the menubar is positioned above the client size, hence the negative
102 // y coord
103 wxCoord heightMbar = m_frameMenuBar->GetSize().y;
104
105 wxCoord heightTbar = 0;
106
107 #if wxUSE_TOOLBAR
108 if ( m_frameToolBar )
109 heightTbar = m_frameToolBar->GetSize().y;
110 #endif // wxUSE_TOOLBAR
111
112 m_frameMenuBar->SetSize(0,
113 #ifdef __WXPM__ // FIXME -- remove this, make wxOS2/Univ behave as
114 // the rest of the world!!!
115 GetClientSize().y - heightMbar - heightTbar,
116 #else
117 - (heightMbar + heightTbar),
118 #endif
119 GetClientSize().x, heightMbar);
120 }
121 }
122
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
135 #endif // wxUSE_MENUS
136
137 #if wxUSE_STATUSBAR
138
139 void wxFrame::PositionStatusBar()
140 {
141 if ( m_frameStatusBar )
142 {
143 wxSize size = GetClientSize();
144 m_frameStatusBar->SetSize(0, size.y, size.x, wxDefaultCoord);
145 }
146 }
147
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
156 #endif // wxUSE_STATUSBAR
157
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
195 wxPoint wxFrame::GetClientAreaOrigin() const
196 {
197 wxPoint pt = wxFrameBase::GetClientAreaOrigin();
198
199 #if wxUSE_MENUS && !defined(__WXPM__)
200 if ( m_frameMenuBar )
201 {
202 pt.y += m_frameMenuBar->GetSize().y;
203 }
204 #endif // wxUSE_MENUS
205
206 #if wxUSE_TOOLBAR
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
216 return pt;
217 }
218
219 void wxFrame::DoGetClientSize(int *width, int *height) const
220 {
221 wxFrameBase::DoGetClientSize(width, height);
222
223 #if wxUSE_MENUS
224 if ( m_frameMenuBar && height )
225 {
226 (*height) -= m_frameMenuBar->GetSize().y;
227 }
228 #endif // wxUSE_MENUS
229
230 #if wxUSE_STATUSBAR
231 if ( m_frameStatusBar && height )
232 {
233 (*height) -= m_frameStatusBar->GetSize().y;
234 }
235 #endif // wxUSE_STATUSBAR
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
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
256
257 #if wxUSE_STATUSBAR
258 if ( m_frameStatusBar )
259 {
260 height += m_frameStatusBar->GetSize().y;
261 }
262 #endif // wxUSE_STATUSBAR
263
264 #if wxUSE_TOOLBAR
265 if ( m_frameToolBar )
266 {
267 #if wxUSE_STATUSBAR
268 height += m_frameStatusBar->GetSize().y;
269 #endif // wxUSE_STATUSBAR
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
278 wxFrameBase::DoSetClientSize(width, height);
279 }
280
281 wxSize wxFrame::GetMinSize() const
282 {
283 wxSize size = wxFrameBase::GetMinSize();
284
285 #if wxUSE_MENUS
286 if ( m_frameMenuBar )
287 {
288 const wxSize sizeMenu = m_frameMenuBar->GetBestSize();
289 if ( sizeMenu.x > size.x )
290 size.x = sizeMenu.x;
291 size.y += sizeMenu.y;
292 }
293 #endif // wxUSE_MENUS
294
295 #if wxUSE_TOOLBAR
296 if ( m_frameToolBar )
297 {
298 size.y += m_frameToolBar->GetSize().y;
299 }
300 #endif // wxUSE_TOOLBAR
301
302 #if wxUSE_STATUSBAR
303 if ( m_frameStatusBar )
304 {
305 size.y += m_frameStatusBar->GetSize().y;
306 }
307 #endif // wxUSE_STATUSBAR
308
309 return size;
310 }
311
312 bool wxFrame::Enable(bool enable)
313 {
314 if (!wxFrameBase::Enable(enable))
315 return false;
316 #ifdef __WXMICROWIN__
317 if (m_frameMenuBar)
318 m_frameMenuBar->Enable(enable);
319 #endif
320 return true;
321 }