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