]> git.saurik.com Git - wxWidgets.git/blob - src/univ/framuniv.cpp
minor cleanup
[wxWidgets.git] / src / univ / framuniv.cpp
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$
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/menu.h"
28 #ifndef WX_PRECOMP
29 #include "wx/frame.h"
30 #include "wx/statusbr.h"
31 #include "wx/settings.h"
32 #include "wx/toolbar.h"
33 #endif // WX_PRECOMP
34
35 // ============================================================================
36 // implementation
37 // ============================================================================
38
39 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
40 EVT_SIZE(wxFrame::OnSize)
41 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
42 END_EVENT_TABLE()
43
44 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
45
46 // ----------------------------------------------------------------------------
47 // ctors
48 // ----------------------------------------------------------------------------
49
50 bool 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)
57 {
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;
64 }
65
66 // Responds to colour changes, and passes event on to children.
67 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
68 {
69 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
70 Refresh();
71
72 event.Skip();
73 }
74
75 // ----------------------------------------------------------------------------
76 // menu support
77 // ----------------------------------------------------------------------------
78
79 void wxFrame::OnSize(wxSizeEvent& event)
80 {
81 #if wxUSE_MENUS
82 PositionMenuBar();
83 #endif // wxUSE_MENUS
84 #if wxUSE_STATUSBAR
85 PositionStatusBar();
86 #endif // wxUSE_STATUSBAR
87 #if wxUSE_TOOLBAR
88 PositionToolBar();
89 #endif // wxUSE_TOOLBAR
90
91 event.Skip();
92 }
93
94 void wxFrame::SendSizeEvent()
95 {
96 wxSizeEvent event(GetSize(), GetId());
97 event.SetEventObject(this);
98 GetEventHandler()->ProcessEvent(event);
99 }
100
101 #if wxUSE_MENUS
102
103 void wxFrame::PositionMenuBar()
104 {
105 if ( m_frameMenuBar )
106 {
107 // the menubar is positioned above the client size, hence the negative
108 // y coord
109 wxCoord heightMbar = m_frameMenuBar->GetSize().y;
110
111 wxCoord heightTbar = 0;
112
113 #if wxUSE_TOOLBAR
114 if ( m_frameToolBar )
115 heightTbar = m_frameToolBar->GetSize().y;
116 #endif // wxUSE_TOOLBAR
117
118 m_frameMenuBar->SetSize(0,
119 #ifdef __WXPM__ // FIXME -- remove this, make wxOS2/Univ behave as
120 // the rest of the world!!!
121 GetClientSize().y - heightMbar - heightTbar,
122 #else
123 - (heightMbar + heightTbar),
124 #endif
125 GetClientSize().x, heightMbar);
126 }
127 }
128
129 void wxFrame::DetachMenuBar()
130 {
131 wxFrameBase::DetachMenuBar();
132 SendSizeEvent();
133 }
134
135 void wxFrame::AttachMenuBar(wxMenuBar *menubar)
136 {
137 wxFrameBase::AttachMenuBar(menubar);
138 SendSizeEvent();
139 }
140
141 #endif // wxUSE_MENUS
142
143 #if wxUSE_STATUSBAR
144
145 void wxFrame::PositionStatusBar()
146 {
147 if ( m_frameStatusBar )
148 {
149 wxSize size = GetClientSize();
150 m_frameStatusBar->SetSize(0, size.y, size.x, wxDefaultCoord);
151 }
152 }
153
154 wxStatusBar* 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
162 #endif // wxUSE_STATUSBAR
163
164 #if wxUSE_TOOLBAR
165
166 wxToolBar* 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
176 void 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
201 wxPoint wxFrame::GetClientAreaOrigin() const
202 {
203 wxPoint pt = wxFrameBase::GetClientAreaOrigin();
204
205 #if wxUSE_MENUS && !defined(__WXPM__)
206 if ( m_frameMenuBar )
207 {
208 pt.y += m_frameMenuBar->GetSize().y;
209 }
210 #endif // wxUSE_MENUS
211
212 #if wxUSE_TOOLBAR
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
222 return pt;
223 }
224
225 void wxFrame::DoGetClientSize(int *width, int *height) const
226 {
227 wxFrameBase::DoGetClientSize(width, height);
228
229 #if wxUSE_MENUS
230 if ( m_frameMenuBar && height )
231 {
232 (*height) -= m_frameMenuBar->GetSize().y;
233 }
234 #endif // wxUSE_MENUS
235
236 #if wxUSE_STATUSBAR
237 if ( m_frameStatusBar && height )
238 {
239 (*height) -= m_frameStatusBar->GetSize().y;
240 }
241 #endif // wxUSE_STATUSBAR
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
252 }
253
254 void 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
262
263 #if wxUSE_STATUSBAR
264 if ( m_frameStatusBar )
265 {
266 height += m_frameStatusBar->GetSize().y;
267 }
268 #endif // wxUSE_STATUSBAR
269
270 #if wxUSE_TOOLBAR
271 if ( m_frameToolBar )
272 {
273 #if wxUSE_STATUSBAR
274 height += m_frameStatusBar->GetSize().y;
275 #endif // wxUSE_STATUSBAR
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
284 wxFrameBase::DoSetClientSize(width, height);
285 }
286
287 int 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
299 int 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
323
324 if ( height )
325 return height + wxMax(0, wxFrameBase::GetMinHeight());
326 else
327 return wxFrameBase::GetMinHeight();
328 }
329
330 bool wxFrame::Enable(bool enable)
331 {
332 if (!wxFrameBase::Enable(enable))
333 return false;
334 #ifdef __WXMICROWIN__
335 if (m_frameMenuBar)
336 m_frameMenuBar->Enable(enable);
337 #endif
338 return true;
339 }