]> git.saurik.com Git - wxWidgets.git/blob - src/univ/framuniv.cpp
Attempt at creating appropriate fonts in Nano-X
[wxWidgets.git] / src / univ / framuniv.cpp
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$
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 #ifdef __GNUG__
21 #pragma implementation "univframe.h"
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"
34 #include "wx/statusbr.h"
35 #include "wx/toolbar.h"
36 #endif // WX_PRECOMP
37
38 // ============================================================================
39 // implementation
40 // ============================================================================
41
42 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
43 EVT_SIZE(wxFrame::OnSize)
44 END_EVENT_TABLE()
45
46 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
47
48 // ----------------------------------------------------------------------------
49 // ctors
50 // ----------------------------------------------------------------------------
51
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)
59 {
60 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
61 }
62
63
64 // ----------------------------------------------------------------------------
65 // menu support
66 // ----------------------------------------------------------------------------
67
68 void wxFrame::OnSize(wxSizeEvent& event)
69 {
70 #if wxUSE_MENUS
71 PositionMenuBar();
72 #endif // wxUSE_MENUS
73 #if wxUSE_STATUSBAR
74 PositionStatusBar();
75 #endif // wxUSE_STATUSBAR
76 #if wxUSE_TOOLBAR
77 PositionToolBar();
78 #endif // wxUSE_TOOLBAR
79
80 event.Skip();
81 }
82
83 void wxFrame::SendSizeEvent()
84 {
85 wxSizeEvent event(GetSize(), GetId());
86 event.SetEventObject(this);
87 GetEventHandler()->ProcessEvent(event);
88 }
89
90 #if wxUSE_MENUS
91
92 void wxFrame::PositionMenuBar()
93 {
94 if ( m_frameMenuBar )
95 {
96 // the menubar is positioned above the client size, hence the negative
97 // y coord
98 wxCoord heightMbar = m_frameMenuBar->GetSize().y;
99
100 wxCoord heightTbar = 0;
101 if (m_frameToolBar)
102 heightTbar = m_frameToolBar->GetSize().y;
103
104 m_frameMenuBar->SetSize(0,
105 #ifdef __WXPM__ // FIXME -- remove this, make wxOS2/Univ behave as
106 // the rest of the world!!!
107 GetClientSize().y - heightMbar - heightTbar,
108 #else
109 - (heightMbar + heightTbar),
110 #endif
111 GetClientSize().x, heightMbar);
112 }
113 }
114
115 void wxFrame::DetachMenuBar()
116 {
117 wxFrameBase::DetachMenuBar();
118 SendSizeEvent();
119 }
120
121 void wxFrame::AttachMenuBar(wxMenuBar *menubar)
122 {
123 wxFrameBase::AttachMenuBar(menubar);
124 SendSizeEvent();
125 }
126
127 #endif // wxUSE_MENUS
128
129 #if wxUSE_STATUSBAR
130
131 void wxFrame::PositionStatusBar()
132 {
133 if ( m_frameStatusBar )
134 {
135 wxSize size = GetClientSize();
136 m_frameStatusBar->SetSize(0, size.y, size.x, -1);
137 }
138 }
139
140 wxStatusBar* wxFrame::CreateStatusBar(int number, long style,
141 wxWindowID id, const wxString& name)
142 {
143 wxStatusBar *bar = wxFrameBase::CreateStatusBar(number, style, id, name);
144 SendSizeEvent();
145 return bar;
146 }
147
148 #endif // wxUSE_STATUSBAR
149
150 #if wxUSE_TOOLBAR
151
152 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
153 {
154 if ( wxFrameBase::CreateToolBar(style, id, name) )
155 {
156 PositionToolBar();
157 }
158
159 return m_frameToolBar;
160 }
161
162 void wxFrame::PositionToolBar()
163 {
164 if ( m_frameToolBar )
165 {
166 wxSize size = GetClientSize();
167 int tw, th, tx, ty;
168
169 tx = ty = 0;
170 m_frameToolBar->GetSize(&tw, &th);
171 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
172 {
173 tx = -tw;
174 th = size.y;
175 }
176 else
177 {
178 ty = -th;
179 tw = size.x;
180 }
181
182 m_frameToolBar->SetSize(tx, ty, tw, th);
183 }
184 }
185 #endif // wxUSE_TOOLBAR
186
187 wxPoint wxFrame::GetClientAreaOrigin() const
188 {
189 wxPoint pt = wxFrameBase::GetClientAreaOrigin();
190
191 #if wxUSE_MENUS && !defined(__WXPM__)
192 if ( m_frameMenuBar )
193 {
194 pt.y += m_frameMenuBar->GetSize().y;
195 }
196 #endif // wxUSE_MENUS
197
198 #if wxUSE_TOOLBAR
199 if ( m_frameToolBar )
200 {
201 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
202 pt.x += m_frameToolBar->GetSize().x;
203 else
204 pt.y += m_frameToolBar->GetSize().y;
205 }
206 #endif // wxUSE_TOOLBAR
207
208 return pt;
209 }
210
211 void wxFrame::DoGetClientSize(int *width, int *height) const
212 {
213 wxFrameBase::DoGetClientSize(width, height);
214
215 #if wxUSE_MENUS
216 if ( m_frameMenuBar && height )
217 {
218 (*height) -= m_frameMenuBar->GetSize().y;
219 }
220 #endif // wxUSE_MENUS
221
222 #if wxUSE_STATUSBAR
223 if ( m_frameStatusBar && height )
224 {
225 (*height) -= m_frameStatusBar->GetSize().y;
226 }
227 #endif // wxUSE_STATUSBAR
228
229 #if wxUSE_TOOLBAR
230 if ( m_frameToolBar )
231 {
232 if ( width && (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL) )
233 (*width) -= m_frameToolBar->GetSize().x;
234 else if ( height )
235 (*height) -= m_frameToolBar->GetSize().y;
236 }
237 #endif // wxUSE_TOOLBAR
238 }
239
240 void wxFrame::DoSetClientSize(int width, int height)
241 {
242 #if wxUSE_MENUS
243 if ( m_frameMenuBar )
244 {
245 height += m_frameMenuBar->GetSize().y;
246 }
247 #endif // wxUSE_MENUS
248
249 #if wxUSE_STATUSBAR
250 if ( m_frameStatusBar )
251 {
252 height += m_frameStatusBar->GetSize().y;
253 }
254 #endif // wxUSE_STATUSBAR
255
256 #if wxUSE_TOOLBAR
257 if ( m_frameToolBar )
258 {
259 height += m_frameStatusBar->GetSize().y;
260
261 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
262 width += m_frameToolBar->GetSize().x;
263 else
264 height += m_frameToolBar->GetSize().y;
265 }
266 #endif // wxUSE_TOOLBAR
267
268 wxFrameBase::DoSetClientSize(width, height);
269 }
270
271 int wxFrame::GetMinWidth() const
272 {
273 #if wxUSE_MENUS
274 if ( m_frameMenuBar )
275 {
276 return wxMax(m_frameMenuBar->GetBestSize().x, wxFrameBase::GetMinWidth());
277 }
278 else
279 #endif // wxUSE_MENUS
280 return wxFrameBase::GetMinWidth();
281 }
282
283 int wxFrame::GetMinHeight() const
284 {
285 int height = 0;
286
287 #if wxUSE_MENUS
288 if ( m_frameMenuBar )
289 {
290 height += m_frameMenuBar->GetSize().y;
291 }
292 #endif // wxUSE_MENUS
293
294 #if wxUSE_TOOLBAR
295 if ( m_frameToolBar )
296 {
297 height += m_frameToolBar->GetSize().y;
298 }
299 #endif // wxUSE_TOOLBAR
300
301 #if wxUSE_STATUSBAR
302 if ( m_frameStatusBar )
303 {
304 height += m_frameStatusBar->GetSize().y;
305 }
306 #endif // wxUSE_STATUSBAR
307
308 if ( height )
309 return height + wxMax(0, wxFrameBase::GetMinHeight());
310 else
311 return wxFrameBase::GetMinHeight();
312 }
313
314 bool wxFrame::Enable(bool enable)
315 {
316 if (!wxFrameBase::Enable(enable))
317 return FALSE;
318 #ifdef __WXMICROWIN__
319 if (m_frameMenuBar)
320 m_frameMenuBar->Enable(enable);
321 #endif
322 return TRUE;
323 }