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