]> git.saurik.com Git - wxWidgets.git/blob - src/univ/framuniv.cpp
replaced by CHANGES.txt
[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 wxFrame::wxFrame()
53 {
54 }
55
56 wxFrame::wxFrame(wxWindow *parent,
57 wxWindowID id,
58 const wxString& title,
59 const wxPoint& pos,
60 const wxSize& size,
61 long style,
62 const wxString& name)
63 {
64 Create(parent, id, title, pos, size, style, name);
65 }
66
67 bool wxFrame::Create(wxWindow *parent,
68 wxWindowID id,
69 const wxString& title,
70 const wxPoint& pos,
71 const wxSize& size,
72 long style,
73 const wxString& name)
74 {
75 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
76 }
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, -1);
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 height += m_frameStatusBar->GetSize().y;
278
279 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
280 width += m_frameToolBar->GetSize().x;
281 else
282 height += m_frameToolBar->GetSize().y;
283 }
284 #endif // wxUSE_TOOLBAR
285
286 wxFrameBase::DoSetClientSize(width, height);
287 }
288
289 int wxFrame::GetMinWidth() const
290 {
291 #if wxUSE_MENUS
292 if ( m_frameMenuBar )
293 {
294 return wxMax(m_frameMenuBar->GetBestSize().x, wxFrameBase::GetMinWidth());
295 }
296 else
297 #endif // wxUSE_MENUS
298 return wxFrameBase::GetMinWidth();
299 }
300
301 int wxFrame::GetMinHeight() const
302 {
303 int height = 0;
304
305 #if wxUSE_MENUS
306 if ( m_frameMenuBar )
307 {
308 height += m_frameMenuBar->GetSize().y;
309 }
310 #endif // wxUSE_MENUS
311
312 #if wxUSE_TOOLBAR
313 if ( m_frameToolBar )
314 {
315 height += m_frameToolBar->GetSize().y;
316 }
317 #endif // wxUSE_TOOLBAR
318
319 #if wxUSE_STATUSBAR
320 if ( m_frameStatusBar )
321 {
322 height += m_frameStatusBar->GetSize().y;
323 }
324 #endif // wxUSE_STATUSBAR
325
326 if ( height )
327 return height + wxMax(0, wxFrameBase::GetMinHeight());
328 else
329 return wxFrameBase::GetMinHeight();
330 }
331
332 bool wxFrame::Enable(bool enable)
333 {
334 if (!wxFrameBase::Enable(enable))
335 return FALSE;
336 #ifdef __WXMICROWIN__
337 if (m_frameMenuBar)
338 m_frameMenuBar->Enable(enable);
339 #endif
340 return TRUE;
341 }