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