]> git.saurik.com Git - wxWidgets.git/blob - src/univ/framuniv.cpp
MS-DOS cross-compilation w/ DJGPP
[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 m_frameMenuBar->SetSize(0,
100 #ifdef __WXPM__ // FIXME -- remove this, make wxOS2/Univ behave as
101 // the rest of the world!!!
102 GetClientSize().y - heightMbar,
103 #else
104 -heightMbar,
105 #endif
106 GetClientSize().x, heightMbar);
107 }
108 }
109
110 void wxFrame::DetachMenuBar()
111 {
112 wxFrameBase::DetachMenuBar();
113 SendSizeEvent();
114 }
115
116 void wxFrame::AttachMenuBar(wxMenuBar *menubar)
117 {
118 wxFrameBase::AttachMenuBar(menubar);
119 SendSizeEvent();
120 }
121
122 #endif // wxUSE_MENUS
123
124 #if wxUSE_STATUSBAR
125
126 void wxFrame::PositionStatusBar()
127 {
128 if ( m_frameStatusBar )
129 {
130 wxSize size = GetClientSize();
131 m_frameStatusBar->SetSize(0, size.y, size.x, -1);
132 }
133 }
134
135 wxStatusBar* wxFrame::CreateStatusBar(int number, long style,
136 wxWindowID id, const wxString& name)
137 {
138 wxStatusBar *bar = wxFrameBase::CreateStatusBar(number, style, id, name);
139 SendSizeEvent();
140 return bar;
141 }
142
143 #endif // wxUSE_STATUSBAR
144
145 #if wxUSE_TOOLBAR
146
147 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
148 {
149 if ( wxFrameBase::CreateToolBar(style, id, name) )
150 {
151 PositionToolBar();
152 }
153
154 return m_frameToolBar;
155 }
156
157 void wxFrame::PositionToolBar()
158 {
159 if ( m_frameToolBar )
160 {
161 wxSize size = GetClientSize();
162 int tw, th, tx, ty;
163
164 tx = ty = 0;
165 m_frameToolBar->GetSize(&tw, &th);
166 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
167 {
168 tx = -tw;
169 th = size.y;
170 }
171 else
172 {
173 ty = -th;
174 tw = size.x;
175 }
176
177 m_frameToolBar->SetSize(tx, ty, tw, th);
178 }
179 }
180 #endif // wxUSE_TOOLBAR
181
182 wxPoint wxFrame::GetClientAreaOrigin() const
183 {
184 wxPoint pt = wxFrameBase::GetClientAreaOrigin();
185
186 #if wxUSE_MENUS && !defined(__WXPM__)
187 if ( m_frameMenuBar )
188 {
189 pt.y += m_frameMenuBar->GetSize().y;
190 }
191 #endif // wxUSE_MENUS
192
193 #if wxUSE_TOOLBAR
194 if ( m_frameToolBar )
195 {
196 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
197 pt.x += m_frameToolBar->GetSize().x;
198 else
199 pt.y += m_frameToolBar->GetSize().y;
200 }
201 #endif // wxUSE_TOOLBAR
202
203 return pt;
204 }
205
206 void wxFrame::DoGetClientSize(int *width, int *height) const
207 {
208 wxFrameBase::DoGetClientSize(width, height);
209
210 #if wxUSE_MENUS
211 if ( m_frameMenuBar && height )
212 {
213 (*height) -= m_frameMenuBar->GetSize().y;
214 }
215 #endif // wxUSE_MENUS
216
217 #if wxUSE_STATUSBAR
218 if ( m_frameStatusBar && height )
219 {
220 (*height) -= m_frameStatusBar->GetSize().y;
221 }
222 #endif // wxUSE_STATUSBAR
223
224 #if wxUSE_TOOLBAR
225 if ( m_frameToolBar )
226 {
227 if ( width && (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL) )
228 (*width) -= m_frameToolBar->GetSize().x;
229 else if ( height )
230 (*height) -= m_frameToolBar->GetSize().y;
231 }
232 #endif // wxUSE_TOOLBAR
233 }
234
235 void wxFrame::DoSetClientSize(int width, int height)
236 {
237 #if wxUSE_MENUS
238 if ( m_frameMenuBar )
239 {
240 height += m_frameMenuBar->GetSize().y;
241 }
242 #endif // wxUSE_MENUS
243
244 #if wxUSE_STATUSBAR
245 if ( m_frameStatusBar )
246 {
247 height += m_frameStatusBar->GetSize().y;
248 }
249 #endif // wxUSE_STATUSBAR
250
251 #if wxUSE_TOOLBAR
252 if ( m_frameToolBar )
253 {
254 height += m_frameStatusBar->GetSize().y;
255
256 if ( m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL )
257 width += m_frameToolBar->GetSize().x;
258 else
259 height += m_frameToolBar->GetSize().y;
260 }
261 #endif // wxUSE_TOOLBAR
262
263 wxFrameBase::DoSetClientSize(width, height);
264 }
265
266 bool wxFrame::Enable(bool enable)
267 {
268 if (!wxFrameBase::Enable(enable))
269 return FALSE;
270 #ifdef __WXMICROWIN__
271 if (m_frameMenuBar)
272 m_frameMenuBar->Enable(enable);
273 #endif
274 return TRUE;
275 }