]> git.saurik.com Git - wxWidgets.git/blame - src/univ/framuniv.cpp
reSWIGged
[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
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"
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
1169a919
JS
52wxFrame::wxFrame()
53{
54}
55
56wxFrame::wxFrame(wxWindow *parent,
57 wxWindowID id,
58 const wxString& title,
59 const wxPoint& pos,
60 const wxSize& size,
61 long style,
62 const wxString& name)
63{
64 Create(parent, id, title, pos, size, style, name);
65}
66
d9d4df0e
VS
67bool wxFrame::Create(wxWindow *parent,
68 wxWindowID id,
69 const wxString& title,
70 const wxPoint& pos,
71 const wxSize& size,
72 long style,
73 const wxString& name)
1e6feb95 74{
d9d4df0e 75 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
1e6feb95
VZ
76}
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,
443aec6f
VS
123#ifdef __WXPM__ // FIXME -- remove this, make wxOS2/Univ behave as
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
VZ
153 wxSize size = GetClientSize();
154 m_frameStatusBar->SetSize(0, size.y, size.x, -1);
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 {
277 height += m_frameStatusBar->GetSize().y;
278
279 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
280 width += m_frameToolBar->GetSize().x;
281 else
282 height += m_frameToolBar->GetSize().y;
283 }
284#endif // wxUSE_TOOLBAR
285
a9152a05
VS
286 wxFrameBase::DoSetClientSize(width, height);
287}
288
e7dda1ff
VS
289int wxFrame::GetMinWidth() const
290{
291#if wxUSE_MENUS
292 if ( m_frameMenuBar )
293 {
294 return wxMax(m_frameMenuBar->GetBestSize().x, wxFrameBase::GetMinWidth());
295 }
296 else
297#endif // wxUSE_MENUS
298 return wxFrameBase::GetMinWidth();
299}
300
301int wxFrame::GetMinHeight() const
302{
303 int height = 0;
304
305#if wxUSE_MENUS
306 if ( m_frameMenuBar )
307 {
308 height += m_frameMenuBar->GetSize().y;
309 }
310#endif // wxUSE_MENUS
311
312#if wxUSE_TOOLBAR
313 if ( m_frameToolBar )
314 {
315 height += m_frameToolBar->GetSize().y;
316 }
317#endif // wxUSE_TOOLBAR
318
319#if wxUSE_STATUSBAR
320 if ( m_frameStatusBar )
321 {
322 height += m_frameStatusBar->GetSize().y;
323 }
324#endif // wxUSE_STATUSBAR
6a317e61 325
e7dda1ff
VS
326 if ( height )
327 return height + wxMax(0, wxFrameBase::GetMinHeight());
328 else
329 return wxFrameBase::GetMinHeight();
330}
331
d9d4df0e 332bool wxFrame::Enable(bool enable)
98363307 333{
d9d4df0e 334 if (!wxFrameBase::Enable(enable))
443aec6f 335 return FALSE;
98363307
JS
336#ifdef __WXMICROWIN__
337 if (m_frameMenuBar)
338 m_frameMenuBar->Enable(enable);
339#endif
340 return TRUE;
341}