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