]> git.saurik.com Git - wxWidgets.git/blame - src/univ/framuniv.cpp
implemented wxSS::GetMetric on wxGTK2 (patch 950618)
[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)
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
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
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;
6a317e61
VZ
101
102#if wxUSE_TOOLBAR
103 if ( m_frameToolBar )
d1017acf 104 heightTbar = m_frameToolBar->GetSize().y;
6a317e61 105#endif // wxUSE_TOOLBAR
e5053ade 106
6a317e61 107 m_frameMenuBar->SetSize(0,
443aec6f
VS
108#ifdef __WXPM__ // FIXME -- remove this, make wxOS2/Univ behave as
109 // the rest of the world!!!
16c9a425 110 GetClientSize().y - heightMbar - heightTbar,
19193a2c 111#else
16c9a425 112 - (heightMbar + heightTbar),
6a317e61 113#endif
75c9da25 114 GetClientSize().x, heightMbar);
1e6feb95 115 }
1e6feb95 116}
75c9da25 117
6821401b
VS
118void wxFrame::DetachMenuBar()
119{
120 wxFrameBase::DetachMenuBar();
121 SendSizeEvent();
122}
123
124void wxFrame::AttachMenuBar(wxMenuBar *menubar)
125{
126 wxFrameBase::AttachMenuBar(menubar);
127 SendSizeEvent();
128}
129
3379ed37
VZ
130#endif // wxUSE_MENUS
131
d08e6e59
VS
132#if wxUSE_STATUSBAR
133
134void wxFrame::PositionStatusBar()
135{
136 if ( m_frameStatusBar )
137 {
71e03035
VZ
138 wxSize size = GetClientSize();
139 m_frameStatusBar->SetSize(0, size.y, size.x, -1);
d08e6e59
VS
140 }
141}
142
6821401b
VS
143wxStatusBar* wxFrame::CreateStatusBar(int number, long style,
144 wxWindowID id, const wxString& name)
145{
146 wxStatusBar *bar = wxFrameBase::CreateStatusBar(number, style, id, name);
147 SendSizeEvent();
148 return bar;
149}
150
d08e6e59
VS
151#endif // wxUSE_STATUSBAR
152
443aec6f
VS
153#if wxUSE_TOOLBAR
154
155wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
156{
157 if ( wxFrameBase::CreateToolBar(style, id, name) )
158 {
159 PositionToolBar();
160 }
161
162 return m_frameToolBar;
163}
164
165void wxFrame::PositionToolBar()
166{
167 if ( m_frameToolBar )
168 {
169 wxSize size = GetClientSize();
170 int tw, th, tx, ty;
171
172 tx = ty = 0;
173 m_frameToolBar->GetSize(&tw, &th);
174 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
175 {
176 tx = -tw;
177 th = size.y;
178 }
179 else
180 {
181 ty = -th;
182 tw = size.x;
183 }
184
185 m_frameToolBar->SetSize(tx, ty, tw, th);
186 }
187}
188#endif // wxUSE_TOOLBAR
189
1e6feb95
VZ
190wxPoint wxFrame::GetClientAreaOrigin() const
191{
d9d4df0e 192 wxPoint pt = wxFrameBase::GetClientAreaOrigin();
1e6feb95 193
19193a2c 194#if wxUSE_MENUS && !defined(__WXPM__)
1e6feb95
VZ
195 if ( m_frameMenuBar )
196 {
197 pt.y += m_frameMenuBar->GetSize().y;
198 }
199#endif // wxUSE_MENUS
200
5e885a58 201#if wxUSE_TOOLBAR
443aec6f
VS
202 if ( m_frameToolBar )
203 {
204 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
205 pt.x += m_frameToolBar->GetSize().x;
206 else
207 pt.y += m_frameToolBar->GetSize().y;
208 }
209#endif // wxUSE_TOOLBAR
210
1e6feb95
VZ
211 return pt;
212}
213
a9152a05
VS
214void wxFrame::DoGetClientSize(int *width, int *height) const
215{
216 wxFrameBase::DoGetClientSize(width, height);
d08e6e59 217
a9152a05
VS
218#if wxUSE_MENUS
219 if ( m_frameMenuBar && height )
220 {
221 (*height) -= m_frameMenuBar->GetSize().y;
222 }
223#endif // wxUSE_MENUS
d08e6e59
VS
224
225#if wxUSE_STATUSBAR
226 if ( m_frameStatusBar && height )
227 {
228 (*height) -= m_frameStatusBar->GetSize().y;
229 }
230#endif // wxUSE_STATUSBAR
443aec6f
VS
231
232#if wxUSE_TOOLBAR
233 if ( m_frameToolBar )
234 {
235 if ( width && (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL) )
236 (*width) -= m_frameToolBar->GetSize().x;
237 else if ( height )
238 (*height) -= m_frameToolBar->GetSize().y;
239 }
240#endif // wxUSE_TOOLBAR
a9152a05
VS
241}
242
243void wxFrame::DoSetClientSize(int width, int height)
244{
245#if wxUSE_MENUS
246 if ( m_frameMenuBar )
247 {
248 height += m_frameMenuBar->GetSize().y;
249 }
250#endif // wxUSE_MENUS
d08e6e59
VS
251
252#if wxUSE_STATUSBAR
253 if ( m_frameStatusBar )
254 {
255 height += m_frameStatusBar->GetSize().y;
256 }
257#endif // wxUSE_STATUSBAR
258
443aec6f
VS
259#if wxUSE_TOOLBAR
260 if ( m_frameToolBar )
261 {
262 height += m_frameStatusBar->GetSize().y;
263
264 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
265 width += m_frameToolBar->GetSize().x;
266 else
267 height += m_frameToolBar->GetSize().y;
268 }
269#endif // wxUSE_TOOLBAR
270
a9152a05
VS
271 wxFrameBase::DoSetClientSize(width, height);
272}
273
e7dda1ff
VS
274int wxFrame::GetMinWidth() const
275{
276#if wxUSE_MENUS
277 if ( m_frameMenuBar )
278 {
279 return wxMax(m_frameMenuBar->GetBestSize().x, wxFrameBase::GetMinWidth());
280 }
281 else
282#endif // wxUSE_MENUS
283 return wxFrameBase::GetMinWidth();
284}
285
286int wxFrame::GetMinHeight() const
287{
288 int height = 0;
289
290#if wxUSE_MENUS
291 if ( m_frameMenuBar )
292 {
293 height += m_frameMenuBar->GetSize().y;
294 }
295#endif // wxUSE_MENUS
296
297#if wxUSE_TOOLBAR
298 if ( m_frameToolBar )
299 {
300 height += m_frameToolBar->GetSize().y;
301 }
302#endif // wxUSE_TOOLBAR
303
304#if wxUSE_STATUSBAR
305 if ( m_frameStatusBar )
306 {
307 height += m_frameStatusBar->GetSize().y;
308 }
309#endif // wxUSE_STATUSBAR
6a317e61 310
e7dda1ff
VS
311 if ( height )
312 return height + wxMax(0, wxFrameBase::GetMinHeight());
313 else
314 return wxFrameBase::GetMinHeight();
315}
316
d9d4df0e 317bool wxFrame::Enable(bool enable)
98363307 318{
d9d4df0e 319 if (!wxFrameBase::Enable(enable))
443aec6f 320 return FALSE;
98363307
JS
321#ifdef __WXMICROWIN__
322 if (m_frameMenuBar)
323 m_frameMenuBar->Enable(enable);
324#endif
325 return TRUE;
326}