]> git.saurik.com Git - wxWidgets.git/blame - src/univ/framuniv.cpp
changed charset to iso8859-2
[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;
16c9a425 99
d1017acf 100 wxCoord heightTbar = 0;
d1017acf
RR
101 if (m_frameToolBar)
102 heightTbar = m_frameToolBar->GetSize().y;
e5053ade 103
19193a2c 104 m_frameMenuBar->SetSize(0,
443aec6f
VS
105#ifdef __WXPM__ // FIXME -- remove this, make wxOS2/Univ behave as
106 // the rest of the world!!!
16c9a425 107 GetClientSize().y - heightMbar - heightTbar,
19193a2c 108#else
16c9a425 109 - (heightMbar + heightTbar),
19193a2c 110#endif
75c9da25 111 GetClientSize().x, heightMbar);
1e6feb95 112 }
1e6feb95 113}
75c9da25 114
6821401b
VS
115void wxFrame::DetachMenuBar()
116{
117 wxFrameBase::DetachMenuBar();
118 SendSizeEvent();
119}
120
121void wxFrame::AttachMenuBar(wxMenuBar *menubar)
122{
123 wxFrameBase::AttachMenuBar(menubar);
124 SendSizeEvent();
125}
126
3379ed37
VZ
127#endif // wxUSE_MENUS
128
d08e6e59
VS
129#if wxUSE_STATUSBAR
130
131void wxFrame::PositionStatusBar()
132{
133 if ( m_frameStatusBar )
134 {
71e03035
VZ
135 wxSize size = GetClientSize();
136 m_frameStatusBar->SetSize(0, size.y, size.x, -1);
d08e6e59
VS
137 }
138}
139
6821401b
VS
140wxStatusBar* 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
d08e6e59
VS
148#endif // wxUSE_STATUSBAR
149
443aec6f
VS
150#if wxUSE_TOOLBAR
151
152wxToolBar* 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
162void 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
1e6feb95
VZ
187wxPoint wxFrame::GetClientAreaOrigin() const
188{
d9d4df0e 189 wxPoint pt = wxFrameBase::GetClientAreaOrigin();
1e6feb95 190
19193a2c 191#if wxUSE_MENUS && !defined(__WXPM__)
1e6feb95
VZ
192 if ( m_frameMenuBar )
193 {
194 pt.y += m_frameMenuBar->GetSize().y;
195 }
196#endif // wxUSE_MENUS
197
5e885a58 198#if wxUSE_TOOLBAR
443aec6f
VS
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
1e6feb95
VZ
208 return pt;
209}
210
a9152a05
VS
211void wxFrame::DoGetClientSize(int *width, int *height) const
212{
213 wxFrameBase::DoGetClientSize(width, height);
d08e6e59 214
a9152a05
VS
215#if wxUSE_MENUS
216 if ( m_frameMenuBar && height )
217 {
218 (*height) -= m_frameMenuBar->GetSize().y;
219 }
220#endif // wxUSE_MENUS
d08e6e59
VS
221
222#if wxUSE_STATUSBAR
223 if ( m_frameStatusBar && height )
224 {
225 (*height) -= m_frameStatusBar->GetSize().y;
226 }
227#endif // wxUSE_STATUSBAR
443aec6f
VS
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
a9152a05
VS
238}
239
240void 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
d08e6e59
VS
248
249#if wxUSE_STATUSBAR
250 if ( m_frameStatusBar )
251 {
252 height += m_frameStatusBar->GetSize().y;
253 }
254#endif // wxUSE_STATUSBAR
255
443aec6f
VS
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
a9152a05
VS
268 wxFrameBase::DoSetClientSize(width, height);
269}
270
e7dda1ff
VS
271int 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
283int 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
d9d4df0e 314bool wxFrame::Enable(bool enable)
98363307 315{
d9d4df0e 316 if (!wxFrameBase::Enable(enable))
443aec6f 317 return FALSE;
98363307
JS
318#ifdef __WXMICROWIN__
319 if (m_frameMenuBar)
320 m_frameMenuBar->Enable(enable);
321#endif
322 return TRUE;
323}