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