]> git.saurik.com Git - wxWidgets.git/blob - src/univ/framuniv.cpp
Set event object correctly for the generated wxSizeEvents.
[wxWidgets.git] / src / univ / framuniv.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/framuniv.cpp
3 // Purpose: wxFrame class for wxUniversal
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 19.05.01
7 // RCS-ID: $Id$
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
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/frame.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/menu.h"
31 #include "wx/statusbr.h"
32 #include "wx/settings.h"
33 #include "wx/toolbar.h"
34 #endif // WX_PRECOMP
35
36 // ============================================================================
37 // implementation
38 // ============================================================================
39
40 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
41 EVT_SIZE(wxFrame::OnSize)
42 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
43 END_EVENT_TABLE()
44
45 // ----------------------------------------------------------------------------
46 // ctors
47 // ----------------------------------------------------------------------------
48
49 bool wxFrame::Create(wxWindow *parent,
50 wxWindowID id,
51 const wxString& title,
52 const wxPoint& pos,
53 const wxSize& size,
54 long style,
55 const wxString& name)
56 {
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;
63 }
64
65 // Responds to colour changes, and passes event on to children.
66 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
67 {
68 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
69 Refresh();
70
71 event.Skip();
72 }
73
74 // ----------------------------------------------------------------------------
75 // menu support
76 // ----------------------------------------------------------------------------
77
78 void wxFrame::OnSize(wxSizeEvent& event)
79 {
80 #if wxUSE_MENUS
81 PositionMenuBar();
82 #endif // wxUSE_MENUS
83 #if wxUSE_STATUSBAR
84 PositionStatusBar();
85 #endif // wxUSE_STATUSBAR
86 #if wxUSE_TOOLBAR
87 PositionToolBar();
88 #endif // wxUSE_TOOLBAR
89
90 event.Skip();
91 }
92
93 #if wxUSE_MENUS
94
95 void wxFrame::PositionMenuBar()
96 {
97 if ( m_frameMenuBar )
98 {
99 // the menubar is positioned above the client size, hence the negative
100 // y coord
101 wxCoord heightMbar = m_frameMenuBar->GetSize().y;
102
103 wxCoord heightTbar = 0;
104
105 #if wxUSE_TOOLBAR
106 if ( m_frameToolBar )
107 heightTbar = m_frameToolBar->GetSize().y;
108 #endif // wxUSE_TOOLBAR
109
110 m_frameMenuBar->SetSize(0,
111 #ifdef __WXPM__ // FIXME -- remove this, make wxOS2/Univ behave as
112 // the rest of the world!!!
113 GetClientSize().y - heightMbar - heightTbar,
114 #else
115 - (heightMbar + heightTbar),
116 #endif
117 GetClientSize().x, heightMbar);
118 }
119 }
120
121 void wxFrame::DetachMenuBar()
122 {
123 wxFrameBase::DetachMenuBar();
124 SendSizeEvent();
125 }
126
127 void wxFrame::AttachMenuBar(wxMenuBar *menubar)
128 {
129 wxFrameBase::AttachMenuBar(menubar);
130 SendSizeEvent();
131 }
132
133 #endif // wxUSE_MENUS
134
135 #if wxUSE_STATUSBAR
136
137 void wxFrame::PositionStatusBar()
138 {
139 if ( m_frameStatusBar )
140 {
141 wxSize size = GetClientSize();
142 m_frameStatusBar->SetSize(0, size.y, size.x, wxDefaultCoord);
143 }
144 }
145
146 wxStatusBar* 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
154 #endif // wxUSE_STATUSBAR
155
156 #if wxUSE_TOOLBAR
157
158 wxToolBar* 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
168 void 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
193 wxPoint wxFrame::GetClientAreaOrigin() const
194 {
195 wxPoint pt = wxFrameBase::GetClientAreaOrigin();
196
197 #if wxUSE_MENUS && !defined(__WXPM__)
198 if ( m_frameMenuBar )
199 {
200 pt.y += m_frameMenuBar->GetSize().y;
201 }
202 #endif // wxUSE_MENUS
203
204 #if wxUSE_TOOLBAR
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
214 return pt;
215 }
216
217 void wxFrame::DoGetClientSize(int *width, int *height) const
218 {
219 wxFrameBase::DoGetClientSize(width, height);
220
221 #if wxUSE_MENUS
222 if ( m_frameMenuBar && height )
223 {
224 (*height) -= m_frameMenuBar->GetSize().y;
225 }
226 #endif // wxUSE_MENUS
227
228 #if wxUSE_STATUSBAR
229 if ( m_frameStatusBar && height )
230 {
231 (*height) -= m_frameStatusBar->GetSize().y;
232 }
233 #endif // wxUSE_STATUSBAR
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
244 }
245
246 void 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
254
255 #if wxUSE_STATUSBAR
256 if ( m_frameStatusBar )
257 {
258 height += m_frameStatusBar->GetSize().y;
259 }
260 #endif // wxUSE_STATUSBAR
261
262 #if wxUSE_TOOLBAR
263 if ( m_frameToolBar )
264 {
265 #if wxUSE_STATUSBAR
266 height += m_frameStatusBar->GetSize().y;
267 #endif // wxUSE_STATUSBAR
268
269 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
270 width += m_frameToolBar->GetSize().x;
271 else
272 height += m_frameToolBar->GetSize().y;
273 }
274 #endif // wxUSE_TOOLBAR
275
276 wxFrameBase::DoSetClientSize(width, height);
277 }
278
279 wxSize wxFrame::GetMinSize() const
280 {
281 wxSize size = wxFrameBase::GetMinSize();
282
283 #if wxUSE_MENUS
284 if ( m_frameMenuBar )
285 {
286 const wxSize sizeMenu = m_frameMenuBar->GetBestSize();
287 if ( sizeMenu.x > size.x )
288 size.x = sizeMenu.x;
289 size.y += sizeMenu.y;
290 }
291 #endif // wxUSE_MENUS
292
293 #if wxUSE_TOOLBAR
294 if ( m_frameToolBar )
295 {
296 size.y += m_frameToolBar->GetSize().y;
297 }
298 #endif // wxUSE_TOOLBAR
299
300 #if wxUSE_STATUSBAR
301 if ( m_frameStatusBar )
302 {
303 size.y += m_frameStatusBar->GetSize().y;
304 }
305 #endif // wxUSE_STATUSBAR
306
307 return size;
308 }
309
310 bool wxFrame::Enable(bool enable)
311 {
312 if (!wxFrameBase::Enable(enable))
313 return false;
314 #ifdef __WXMICROWIN__
315 if (m_frameMenuBar)
316 m_frameMenuBar->Enable(enable);
317 #endif
318 return true;
319 }