Fixed conflicts with Robert's similar fixes; fixed toolbar size calculation
[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 #ifdef __GNUG__
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 if (m_frameToolBar)
102 heightTbar = m_frameToolBar->GetSize().y;
103
104 m_frameMenuBar->SetSize(0,
105 #ifdef __WXPM__ // FIXME -- remove this, make wxOS2/Univ behave as
106 // the rest of the world!!!
107 GetClientSize().y - heightMbar - heightTbar,
108 #else
109 - (heightMbar + heightTbar),
110 #endif
111 GetClientSize().x, heightMbar);
112 }
113 }
114
115 void wxFrame::DetachMenuBar()
116 {
117 wxFrameBase::DetachMenuBar();
118 SendSizeEvent();
119 }
120
121 void wxFrame::AttachMenuBar(wxMenuBar *menubar)
122 {
123 wxFrameBase::AttachMenuBar(menubar);
124 SendSizeEvent();
125 }
126
127 #endif // wxUSE_MENUS
128
129 #if wxUSE_STATUSBAR
130
131 void wxFrame::PositionStatusBar()
132 {
133 if ( m_frameStatusBar )
134 {
135 wxSize size = GetClientSize();
136 m_frameStatusBar->SetSize(0, size.y, size.x, -1);
137 }
138 }
139
140 wxStatusBar* wxFrame::CreateStatusBar(int number, long style,
141 wxWindowID id, const wxString& name)
142 {
143 wxStatusBar *bar = wxFrameBase::CreateStatusBar(number, style, id, name);
144 SendSizeEvent();
145 return bar;
146 }
147
148 #endif // wxUSE_STATUSBAR
149
150 #if wxUSE_TOOLBAR
151
152 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
153 {
154 if ( wxFrameBase::CreateToolBar(style, id, name) )
155 {
156 PositionToolBar();
157 }
158
159 return m_frameToolBar;
160 }
161
162 void wxFrame::PositionToolBar()
163 {
164 if ( m_frameToolBar )
165 {
166 wxSize size = GetClientSize();
167 int tw, th, tx, ty;
168
169 tx = ty = 0;
170 m_frameToolBar->GetSize(&tw, &th);
171 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
172 {
173 tx = -tw;
174 th = size.y;
175 }
176 else
177 {
178 ty = -th;
179 tw = size.x;
180 }
181
182 m_frameToolBar->SetSize(tx, ty, tw, th);
183 }
184 }
185 #endif // wxUSE_TOOLBAR
186
187 wxPoint wxFrame::GetClientAreaOrigin() const
188 {
189 wxPoint pt = wxFrameBase::GetClientAreaOrigin();
190
191 #if wxUSE_MENUS && !defined(__WXPM__)
192 if ( m_frameMenuBar )
193 {
194 pt.y += m_frameMenuBar->GetSize().y;
195 }
196 #endif // wxUSE_MENUS
197
198 // This is done in wxFrameBase already
199 #if 0 // wxUSE_TOOLBAR
200 if ( m_frameToolBar )
201 {
202 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
203 pt.x += m_frameToolBar->GetSize().x;
204 else
205 pt.y += m_frameToolBar->GetSize().y;
206 }
207 #endif // wxUSE_TOOLBAR
208
209 return pt;
210 }
211
212 void wxFrame::DoGetClientSize(int *width, int *height) const
213 {
214 wxFrameBase::DoGetClientSize(width, height);
215
216 #if wxUSE_MENUS
217 if ( m_frameMenuBar && height )
218 {
219 (*height) -= m_frameMenuBar->GetSize().y;
220 }
221 #endif // wxUSE_MENUS
222
223 #if wxUSE_STATUSBAR
224 if ( m_frameStatusBar && height )
225 {
226 (*height) -= m_frameStatusBar->GetSize().y;
227 }
228 #endif // wxUSE_STATUSBAR
229
230 #if wxUSE_TOOLBAR
231 if ( m_frameToolBar )
232 {
233 if ( width && (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL) )
234 (*width) -= m_frameToolBar->GetSize().x;
235 else if ( height )
236 (*height) -= m_frameToolBar->GetSize().y;
237 }
238 #endif // wxUSE_TOOLBAR
239 }
240
241 void wxFrame::DoSetClientSize(int width, int height)
242 {
243 #if wxUSE_MENUS
244 if ( m_frameMenuBar )
245 {
246 height += m_frameMenuBar->GetSize().y;
247 }
248 #endif // wxUSE_MENUS
249
250 #if wxUSE_STATUSBAR
251 if ( m_frameStatusBar )
252 {
253 height += m_frameStatusBar->GetSize().y;
254 }
255 #endif // wxUSE_STATUSBAR
256
257 #if wxUSE_TOOLBAR
258 if ( m_frameToolBar )
259 {
260 height += m_frameStatusBar->GetSize().y;
261
262 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
263 width += m_frameToolBar->GetSize().x;
264 else
265 height += m_frameToolBar->GetSize().y;
266 }
267 #endif // wxUSE_TOOLBAR
268
269 wxFrameBase::DoSetClientSize(width, height);
270 }
271
272 int wxFrame::GetMinWidth() const
273 {
274 #if wxUSE_MENUS
275 if ( m_frameMenuBar )
276 {
277 return wxMax(m_frameMenuBar->GetBestSize().x, wxFrameBase::GetMinWidth());
278 }
279 else
280 #endif // wxUSE_MENUS
281 return wxFrameBase::GetMinWidth();
282 }
283
284 int wxFrame::GetMinHeight() const
285 {
286 int height = 0;
287
288 #if wxUSE_MENUS
289 if ( m_frameMenuBar )
290 {
291 height += m_frameMenuBar->GetSize().y;
292 }
293 #endif // wxUSE_MENUS
294
295 #if wxUSE_TOOLBAR
296 if ( m_frameToolBar )
297 {
298 height += m_frameToolBar->GetSize().y;
299 }
300 #endif // wxUSE_TOOLBAR
301
302 #if wxUSE_STATUSBAR
303 if ( m_frameStatusBar )
304 {
305 height += m_frameStatusBar->GetSize().y;
306 }
307 #endif // wxUSE_STATUSBAR
308
309 if ( height )
310 return height + wxMax(0, wxFrameBase::GetMinHeight());
311 else
312 return wxFrameBase::GetMinHeight();
313 }
314
315 bool wxFrame::Enable(bool enable)
316 {
317 if (!wxFrameBase::Enable(enable))
318 return FALSE;
319 #ifdef __WXMICROWIN__
320 if (m_frameMenuBar)
321 m_frameMenuBar->Enable(enable);
322 #endif
323 return TRUE;
324 }