]> git.saurik.com Git - wxWidgets.git/blob - src/univ/framuniv.cpp
Separated wxImage::FloodFill from image.cpp
[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
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, -1);
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 height += m_frameStatusBar->GetSize().y;
263
264 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
265 width += m_frameToolBar->GetSize().x;
266 else
267 height += m_frameToolBar->GetSize().y;
268 }
269 #endif // wxUSE_TOOLBAR
270
271 wxFrameBase::DoSetClientSize(width, height);
272 }
273
274 int wxFrame::GetMinWidth() const
275 {
276 #if wxUSE_MENUS
277 if ( m_frameMenuBar )
278 {
279 return wxMax(m_frameMenuBar->GetBestSize().x, wxFrameBase::GetMinWidth());
280 }
281 else
282 #endif // wxUSE_MENUS
283 return wxFrameBase::GetMinWidth();
284 }
285
286 int wxFrame::GetMinHeight() const
287 {
288 int height = 0;
289
290 #if wxUSE_MENUS
291 if ( m_frameMenuBar )
292 {
293 height += m_frameMenuBar->GetSize().y;
294 }
295 #endif // wxUSE_MENUS
296
297 #if wxUSE_TOOLBAR
298 if ( m_frameToolBar )
299 {
300 height += m_frameToolBar->GetSize().y;
301 }
302 #endif // wxUSE_TOOLBAR
303
304 #if wxUSE_STATUSBAR
305 if ( m_frameStatusBar )
306 {
307 height += m_frameStatusBar->GetSize().y;
308 }
309 #endif // wxUSE_STATUSBAR
310
311 if ( height )
312 return height + wxMax(0, wxFrameBase::GetMinHeight());
313 else
314 return wxFrameBase::GetMinHeight();
315 }
316
317 bool wxFrame::Enable(bool enable)
318 {
319 if (!wxFrameBase::Enable(enable))
320 return FALSE;
321 #ifdef __WXMICROWIN__
322 if (m_frameMenuBar)
323 m_frameMenuBar->Enable(enable);
324 #endif
325 return TRUE;
326 }