]> git.saurik.com Git - wxWidgets.git/blame - src/univ/framuniv.cpp
Extract wxFDIOEventLoopSourceHandler in its own header.
[wxWidgets.git] / src / univ / framuniv.cpp
CommitLineData
1e6feb95 1///////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/univ/framuniv.cpp
1e6feb95
VZ
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
1e6feb95
VZ
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
76b49cf4
WS
27#include "wx/frame.h"
28
1e6feb95 29#ifndef WX_PRECOMP
76b49cf4 30 #include "wx/menu.h"
d08e6e59 31 #include "wx/statusbr.h"
afad4a88 32 #include "wx/settings.h"
443aec6f 33 #include "wx/toolbar.h"
1e6feb95
VZ
34#endif // WX_PRECOMP
35
36// ============================================================================
37// implementation
38// ============================================================================
39
d9d4df0e 40BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
1e6feb95 41 EVT_SIZE(wxFrame::OnSize)
afad4a88 42 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
1e6feb95
VZ
43END_EVENT_TABLE()
44
1e6feb95
VZ
45// ----------------------------------------------------------------------------
46// ctors
47// ----------------------------------------------------------------------------
48
d9d4df0e 49bool wxFrame::Create(wxWindow *parent,
9a6384ca
WS
50 wxWindowID id,
51 const wxString& title,
52 const wxPoint& pos,
53 const wxSize& size,
54 long style,
55 const wxString& name)
1e6feb95 56{
afad4a88
VZ
57 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
58 return false;
59
60 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
61
62 return true;
1e6feb95
VZ
63}
64
afad4a88
VZ
65// Responds to colour changes, and passes event on to children.
66void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
67{
68 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
69 Refresh();
70
71 event.Skip();
72}
d9d4df0e 73
1e6feb95 74// ----------------------------------------------------------------------------
3379ed37 75// menu support
1e6feb95
VZ
76// ----------------------------------------------------------------------------
77
78void wxFrame::OnSize(wxSizeEvent& event)
79{
3379ed37 80#if wxUSE_MENUS
1e6feb95 81 PositionMenuBar();
54800df8 82#endif // wxUSE_MENUS
d08e6e59
VS
83#if wxUSE_STATUSBAR
84 PositionStatusBar();
85#endif // wxUSE_STATUSBAR
443aec6f
VS
86#if wxUSE_TOOLBAR
87 PositionToolBar();
88#endif // wxUSE_TOOLBAR
1e6feb95
VZ
89
90 event.Skip();
91}
92
3379ed37
VZ
93#if wxUSE_MENUS
94
1e6feb95
VZ
95void wxFrame::PositionMenuBar()
96{
1e6feb95
VZ
97 if ( m_frameMenuBar )
98 {
99 // the menubar is positioned above the client size, hence the negative
100 // y coord
75c9da25 101 wxCoord heightMbar = m_frameMenuBar->GetSize().y;
16c9a425 102
d1017acf 103 wxCoord heightTbar = 0;
6a317e61
VZ
104
105#if wxUSE_TOOLBAR
106 if ( m_frameToolBar )
d1017acf 107 heightTbar = m_frameToolBar->GetSize().y;
6a317e61 108#endif // wxUSE_TOOLBAR
e5053ade 109
6a317e61 110 m_frameMenuBar->SetSize(0,
a290fa5a 111#ifdef __WXPM__ // FIXME -- remove this, make wxOS2/Univ behave as
443aec6f 112 // the rest of the world!!!
16c9a425 113 GetClientSize().y - heightMbar - heightTbar,
19193a2c 114#else
16c9a425 115 - (heightMbar + heightTbar),
6a317e61 116#endif
75c9da25 117 GetClientSize().x, heightMbar);
1e6feb95 118 }
1e6feb95 119}
75c9da25 120
6821401b
VS
121void wxFrame::DetachMenuBar()
122{
123 wxFrameBase::DetachMenuBar();
124 SendSizeEvent();
125}
126
127void wxFrame::AttachMenuBar(wxMenuBar *menubar)
128{
129 wxFrameBase::AttachMenuBar(menubar);
130 SendSizeEvent();
131}
132
3379ed37
VZ
133#endif // wxUSE_MENUS
134
d08e6e59
VS
135#if wxUSE_STATUSBAR
136
137void wxFrame::PositionStatusBar()
138{
139 if ( m_frameStatusBar )
140 {
71e03035 141 wxSize size = GetClientSize();
a290fa5a 142 m_frameStatusBar->SetSize(0, size.y, size.x, wxDefaultCoord);
d08e6e59
VS
143 }
144}
145
6821401b
VS
146wxStatusBar* wxFrame::CreateStatusBar(int number, long style,
147 wxWindowID id, const wxString& name)
148{
149 wxStatusBar *bar = wxFrameBase::CreateStatusBar(number, style, id, name);
150 SendSizeEvent();
151 return bar;
152}
153
d08e6e59
VS
154#endif // wxUSE_STATUSBAR
155
443aec6f
VS
156#if wxUSE_TOOLBAR
157
158wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
159{
160 if ( wxFrameBase::CreateToolBar(style, id, name) )
161 {
162 PositionToolBar();
163 }
164
165 return m_frameToolBar;
166}
167
168void wxFrame::PositionToolBar()
169{
170 if ( m_frameToolBar )
171 {
172 wxSize size = GetClientSize();
173 int tw, th, tx, ty;
174
175 tx = ty = 0;
176 m_frameToolBar->GetSize(&tw, &th);
177 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
178 {
179 tx = -tw;
180 th = size.y;
181 }
182 else
183 {
184 ty = -th;
185 tw = size.x;
186 }
187
188 m_frameToolBar->SetSize(tx, ty, tw, th);
189 }
190}
191#endif // wxUSE_TOOLBAR
192
1e6feb95
VZ
193wxPoint wxFrame::GetClientAreaOrigin() const
194{
d9d4df0e 195 wxPoint pt = wxFrameBase::GetClientAreaOrigin();
1e6feb95 196
19193a2c 197#if wxUSE_MENUS && !defined(__WXPM__)
1e6feb95
VZ
198 if ( m_frameMenuBar )
199 {
200 pt.y += m_frameMenuBar->GetSize().y;
201 }
202#endif // wxUSE_MENUS
203
5e885a58 204#if wxUSE_TOOLBAR
443aec6f
VS
205 if ( m_frameToolBar )
206 {
207 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
208 pt.x += m_frameToolBar->GetSize().x;
209 else
210 pt.y += m_frameToolBar->GetSize().y;
211 }
212#endif // wxUSE_TOOLBAR
213
1e6feb95
VZ
214 return pt;
215}
216
a9152a05
VS
217void wxFrame::DoGetClientSize(int *width, int *height) const
218{
219 wxFrameBase::DoGetClientSize(width, height);
d08e6e59 220
a9152a05
VS
221#if wxUSE_MENUS
222 if ( m_frameMenuBar && height )
223 {
224 (*height) -= m_frameMenuBar->GetSize().y;
225 }
226#endif // wxUSE_MENUS
d08e6e59
VS
227
228#if wxUSE_STATUSBAR
229 if ( m_frameStatusBar && height )
230 {
231 (*height) -= m_frameStatusBar->GetSize().y;
232 }
233#endif // wxUSE_STATUSBAR
443aec6f
VS
234
235#if wxUSE_TOOLBAR
236 if ( m_frameToolBar )
237 {
238 if ( width && (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL) )
239 (*width) -= m_frameToolBar->GetSize().x;
240 else if ( height )
241 (*height) -= m_frameToolBar->GetSize().y;
242 }
243#endif // wxUSE_TOOLBAR
a9152a05
VS
244}
245
246void wxFrame::DoSetClientSize(int width, int height)
247{
248#if wxUSE_MENUS
249 if ( m_frameMenuBar )
250 {
251 height += m_frameMenuBar->GetSize().y;
252 }
253#endif // wxUSE_MENUS
d08e6e59
VS
254
255#if wxUSE_STATUSBAR
256 if ( m_frameStatusBar )
257 {
258 height += m_frameStatusBar->GetSize().y;
259 }
260#endif // wxUSE_STATUSBAR
261
443aec6f
VS
262#if wxUSE_TOOLBAR
263 if ( m_frameToolBar )
264 {
443aec6f
VS
265 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
266 width += m_frameToolBar->GetSize().x;
267 else
268 height += m_frameToolBar->GetSize().y;
269 }
270#endif // wxUSE_TOOLBAR
271
a9152a05
VS
272 wxFrameBase::DoSetClientSize(width, height);
273}
274
894057d1 275wxSize wxFrame::GetMinSize() const
e7dda1ff 276{
894057d1 277 wxSize size = wxFrameBase::GetMinSize();
e7dda1ff
VS
278
279#if wxUSE_MENUS
280 if ( m_frameMenuBar )
281 {
894057d1
VZ
282 const wxSize sizeMenu = m_frameMenuBar->GetBestSize();
283 if ( sizeMenu.x > size.x )
284 size.x = sizeMenu.x;
285 size.y += sizeMenu.y;
e7dda1ff
VS
286 }
287#endif // wxUSE_MENUS
288
289#if wxUSE_TOOLBAR
290 if ( m_frameToolBar )
291 {
894057d1 292 size.y += m_frameToolBar->GetSize().y;
e7dda1ff
VS
293 }
294#endif // wxUSE_TOOLBAR
295
296#if wxUSE_STATUSBAR
297 if ( m_frameStatusBar )
298 {
894057d1 299 size.y += m_frameStatusBar->GetSize().y;
e7dda1ff
VS
300 }
301#endif // wxUSE_STATUSBAR
6a317e61 302
894057d1 303 return size;
e7dda1ff
VS
304}
305
d9d4df0e 306bool wxFrame::Enable(bool enable)
98363307 307{
d9d4df0e 308 if (!wxFrameBase::Enable(enable))
a290fa5a 309 return false;
98363307
JS
310#ifdef __WXMICROWIN__
311 if (m_frameMenuBar)
312 m_frameMenuBar->Enable(enable);
313#endif
a290fa5a 314 return true;
98363307 315}