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