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