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