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