]>
Commit | Line | Data |
---|---|---|
3ccc5735 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/osx/nonownedwnd_osx.cpp | |
3 | // Purpose: implementation of wxNonOwnedWindow | |
4 | // Author: Stefan Csomor | |
5 | // Created: 2008-03-24 | |
b5b208a1 | 6 | // RCS-ID: $Id$ |
3ccc5735 SC |
7 | // Copyright: (c) Stefan Csomor 2008 |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // For compilers that support precompilation, includes "wx.h". | |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifndef WX_PRECOMP | |
15 | #include "wx/app.h" | |
83ed867e | 16 | #include "wx/dcmemory.h" |
e1f833da | 17 | #include "wx/log.h" |
3ccc5735 SC |
18 | #endif // WX_PRECOMP |
19 | ||
20 | #include "wx/hashmap.h" | |
21 | #include "wx/evtloop.h" | |
22 | #include "wx/tooltip.h" | |
23 | #include "wx/nonownedwnd.h" | |
24 | ||
25 | #include "wx/osx/private.h" | |
26 | #include "wx/settings.h" | |
27 | #include "wx/frame.h" | |
28 | ||
29 | #if wxUSE_SYSTEM_OPTIONS | |
30 | #include "wx/sysopt.h" | |
31 | #endif | |
32 | ||
33 | // ---------------------------------------------------------------------------- | |
34 | // constants | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
37 | // trace mask for activation tracing messages | |
38 | #define TRACE_ACTIVATE "activation" | |
39 | ||
40 | wxWindow* g_MacLastWindow = NULL ; | |
41 | ||
7dc941e3 SC |
42 | clock_t wxNonOwnedWindow::s_lastFlush = 0; |
43 | ||
3ccc5735 SC |
44 | // unified title and toolbar constant - not in Tiger headers, so we duplicate it here |
45 | #define kWindowUnifiedTitleAndToolbarAttribute (1 << 7) | |
46 | ||
47 | // --------------------------------------------------------------------------- | |
48 | // wxWindowMac utility functions | |
49 | // --------------------------------------------------------------------------- | |
50 | ||
638b3cd7 | 51 | WX_DECLARE_HASH_MAP(WXWindow, wxNonOwnedWindowImpl*, wxPointerHash, wxPointerEqual, MacWindowMap); |
3ccc5735 SC |
52 | |
53 | static MacWindowMap wxWinMacWindowList; | |
54 | ||
638b3cd7 | 55 | wxNonOwnedWindow* wxNonOwnedWindow::GetFromWXWindow( WXWindow win ) |
3ccc5735 | 56 | { |
638b3cd7 | 57 | wxNonOwnedWindowImpl* impl = wxNonOwnedWindowImpl::FindFromWXWindow(win); |
ce00f59b | 58 | |
638b3cd7 | 59 | return ( impl != NULL ? impl->GetWXPeer() : NULL ) ; |
3ccc5735 SC |
60 | } |
61 | ||
638b3cd7 | 62 | wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::FindFromWXWindow (WXWindow window) |
3ccc5735 | 63 | { |
638b3cd7 | 64 | MacWindowMap::iterator node = wxWinMacWindowList.find(window); |
ce00f59b | 65 | |
638b3cd7 | 66 | return (node == wxWinMacWindowList.end()) ? NULL : node->second; |
3ccc5735 SC |
67 | } |
68 | ||
638b3cd7 | 69 | void wxNonOwnedWindowImpl::RemoveAssociations( wxNonOwnedWindowImpl* impl) |
3ccc5735 SC |
70 | { |
71 | MacWindowMap::iterator it; | |
72 | for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it ) | |
73 | { | |
638b3cd7 | 74 | if ( it->second == impl ) |
3ccc5735 SC |
75 | { |
76 | wxWinMacWindowList.erase(it); | |
77 | break; | |
78 | } | |
79 | } | |
80 | } | |
81 | ||
638b3cd7 | 82 | void wxNonOwnedWindowImpl::Associate( WXWindow window, wxNonOwnedWindowImpl *impl ) |
3ccc5735 | 83 | { |
638b3cd7 SC |
84 | // adding NULL WindowRef is (first) surely a result of an error and |
85 | // nothing else :-) | |
86 | wxCHECK_RET( window != (WXWindow) NULL, wxT("attempt to add a NULL WindowRef to window list") ); | |
ce00f59b | 87 | |
638b3cd7 | 88 | wxWinMacWindowList[window] = impl; |
3ccc5735 SC |
89 | } |
90 | ||
91 | // ---------------------------------------------------------------------------- | |
92 | // wxNonOwnedWindow creation | |
93 | // ---------------------------------------------------------------------------- | |
94 | ||
95 | IMPLEMENT_ABSTRACT_CLASS( wxNonOwnedWindowImpl , wxObject ) | |
96 | ||
97 | wxNonOwnedWindow *wxNonOwnedWindow::s_macDeactivateWindow = NULL; | |
98 | ||
99 | void wxNonOwnedWindow::Init() | |
100 | { | |
101 | m_nowpeer = NULL; | |
17e2694c | 102 | m_isNativeWindowWrapper = false; |
3ccc5735 SC |
103 | } |
104 | ||
105 | bool wxNonOwnedWindow::Create(wxWindow *parent, | |
106 | wxWindowID id, | |
e08b4823 VZ |
107 | const wxPoint& posOrig, |
108 | const wxSize& sizeOrig, | |
3ccc5735 SC |
109 | long style, |
110 | const wxString& name) | |
111 | { | |
3ccc5735 SC |
112 | m_windowStyle = style; |
113 | ||
114 | SetName( name ); | |
115 | ||
116 | m_windowId = id == -1 ? NewControlId() : id; | |
117 | m_windowStyle = style; | |
118 | m_isShown = false; | |
119 | ||
e08b4823 | 120 | // use the appropriate defaults for the position and size if necessary |
e08b4823 VZ |
121 | wxSize size(sizeOrig); |
122 | if ( !size.IsFullySpecified() ) | |
123 | size.SetDefaults(wxTopLevelWindow::GetDefaultSize()); | |
3ccc5735 | 124 | |
0d65f8d2 VZ |
125 | wxPoint pos(posOrig); |
126 | if ( !pos.IsFullySpecified() ) | |
127 | { | |
128 | wxRect rectWin = wxRect(size).CentreIn(wxGetClientDisplayRect()); | |
129 | ||
130 | // The size of the window is often not really known yet, TLWs are often | |
131 | // created with some small initial size and later are fitted to contain | |
132 | // their children so centering the window will show it too much to the | |
133 | // right and bottom, adjust for it by putting it more to the left and | |
134 | // center. | |
135 | rectWin.x /= 2; | |
136 | rectWin.y /= 2; | |
137 | ||
138 | pos.SetDefaults(rectWin.GetPosition()); | |
139 | } | |
140 | ||
e08b4823 VZ |
141 | // create frame. |
142 | m_nowpeer = wxNonOwnedWindowImpl::CreateNonOwnedWindow | |
143 | ( | |
144 | this, parent, | |
145 | pos , size, | |
146 | style, GetExtraStyle(), | |
147 | name | |
148 | ); | |
638b3cd7 | 149 | wxNonOwnedWindowImpl::Associate( m_nowpeer->GetWXWindow() , m_nowpeer ) ; |
22756322 | 150 | SetPeer(wxWidgetImpl::CreateContentView(this)); |
3ccc5735 SC |
151 | |
152 | DoSetWindowVariant( m_windowVariant ) ; | |
153 | ||
154 | wxWindowCreateEvent event(this); | |
155 | HandleWindowEvent(event); | |
156 | ||
157 | SetBackgroundColour(wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE )); | |
158 | ||
159 | if ( parent ) | |
160 | parent->AddChild(this); | |
161 | ||
162 | return true; | |
163 | } | |
164 | ||
17e2694c SC |
165 | bool wxNonOwnedWindow::Create(wxWindow *parent, WXWindow nativeWindow) |
166 | { | |
d623e8b1 SC |
167 | if ( parent ) |
168 | parent->AddChild(this); | |
ce00f59b | 169 | |
d623e8b1 | 170 | SubclassWin(nativeWindow); |
ce00f59b | 171 | |
d623e8b1 SC |
172 | return true; |
173 | } | |
174 | ||
175 | void wxNonOwnedWindow::SubclassWin(WXWindow nativeWindow) | |
176 | { | |
177 | wxASSERT_MSG( !m_isNativeWindowWrapper, wxT("subclassing window twice?") ); | |
178 | wxASSERT_MSG( m_nowpeer == NULL, wxT("window already was created") ); | |
179 | ||
180 | m_nowpeer = wxNonOwnedWindowImpl::CreateNonOwnedWindow(this, GetParent(), nativeWindow ); | |
17e2694c | 181 | m_isNativeWindowWrapper = true; |
638b3cd7 | 182 | wxNonOwnedWindowImpl::Associate( m_nowpeer->GetWXWindow() , m_nowpeer ) ; |
22756322 | 183 | SetPeer(wxWidgetImpl::CreateContentView(this)); |
d623e8b1 | 184 | } |
17e2694c | 185 | |
d623e8b1 SC |
186 | void wxNonOwnedWindow::UnsubclassWin() |
187 | { | |
188 | wxASSERT_MSG( m_isNativeWindowWrapper, wxT("window was not subclassed") ); | |
189 | ||
190 | if ( GetParent() ) | |
191 | GetParent()->RemoveChild(this); | |
ce00f59b VZ |
192 | |
193 | wxNonOwnedWindowImpl::RemoveAssociations(m_nowpeer) ; | |
d623e8b1 | 194 | wxDELETE(m_nowpeer); |
22756322 | 195 | SetPeer(NULL); |
77eb08cc | 196 | m_isNativeWindowWrapper = false; |
17e2694c SC |
197 | } |
198 | ||
d623e8b1 | 199 | |
3ccc5735 SC |
200 | wxNonOwnedWindow::~wxNonOwnedWindow() |
201 | { | |
c6212a0c | 202 | SendDestroyEvent(); |
03647350 | 203 | |
638b3cd7 | 204 | wxNonOwnedWindowImpl::RemoveAssociations(m_nowpeer) ; |
03647350 | 205 | |
524c47aa | 206 | DestroyChildren(); |
03647350 | 207 | |
5276b0a5 | 208 | wxDELETE(m_nowpeer); |
3ccc5735 SC |
209 | |
210 | // avoid dangling refs | |
211 | if ( s_macDeactivateWindow == this ) | |
212 | s_macDeactivateWindow = NULL; | |
213 | } | |
214 | ||
e2758e21 | 215 | bool wxNonOwnedWindow::Destroy() |
0aaa6ace | 216 | { |
e2758e21 | 217 | WillBeDestroyed(); |
ce00f59b | 218 | |
e2758e21 KO |
219 | return wxWindow::Destroy(); |
220 | } | |
221 | ||
222 | void wxNonOwnedWindow::WillBeDestroyed() | |
223 | { | |
0aaa6ace SC |
224 | if ( m_nowpeer ) |
225 | m_nowpeer->WillBeDestroyed(); | |
226 | } | |
227 | ||
3ccc5735 SC |
228 | // ---------------------------------------------------------------------------- |
229 | // wxNonOwnedWindow misc | |
230 | // ---------------------------------------------------------------------------- | |
231 | ||
ab9a0b84 VZ |
232 | bool wxNonOwnedWindow::OSXShowWithEffect(bool show, |
233 | wxShowEffect effect, | |
234 | unsigned timeout) | |
03647350 | 235 | { |
ab9a0b84 VZ |
236 | // Cocoa code needs to manage window visibility on its own and so calls |
237 | // wxWindow::Show() as needed but if we already changed the internal | |
238 | // visibility flag here, Show() would do nothing, so avoid doing it | |
239 | #if wxOSX_USE_CARBON | |
240 | if ( !wxWindow::Show(show) ) | |
3ccc5735 | 241 | return false; |
ab9a0b84 | 242 | #endif // Carbon |
3ccc5735 | 243 | |
ab9a0b84 VZ |
244 | if ( effect == wxSHOW_EFFECT_NONE || |
245 | !m_nowpeer || !m_nowpeer->ShowWithEffect(show, effect, timeout) ) | |
246 | return Show(show); | |
3ccc5735 | 247 | |
ab9a0b84 VZ |
248 | if ( show ) |
249 | { | |
250 | // as apps expect a size event to occur when the window is shown, | |
251 | // generate one when it is shown with effect too | |
252 | wxSizeEvent event(GetSize(), m_windowId); | |
253 | event.SetEventObject(this); | |
254 | HandleWindowEvent(event); | |
255 | } | |
3ccc5735 | 256 | |
ab9a0b84 | 257 | return true; |
3ccc5735 SC |
258 | } |
259 | ||
260 | wxPoint wxNonOwnedWindow::GetClientAreaOrigin() const | |
261 | { | |
262 | int left, top, width, height; | |
263 | m_nowpeer->GetContentArea(left, top, width, height); | |
264 | return wxPoint(left, top); | |
265 | } | |
266 | ||
267 | bool wxNonOwnedWindow::SetBackgroundColour(const wxColour& c ) | |
03647350 | 268 | { |
3ccc5735 SC |
269 | if ( !wxWindow::SetBackgroundColour(c) && m_hasBgCol ) |
270 | return false ; | |
03647350 | 271 | |
3ccc5735 SC |
272 | if ( GetBackgroundStyle() != wxBG_STYLE_CUSTOM ) |
273 | { | |
524c47aa SC |
274 | if ( m_nowpeer ) |
275 | return m_nowpeer->SetBackgroundColour(c); | |
3ccc5735 SC |
276 | } |
277 | return true; | |
03647350 | 278 | } |
3ccc5735 | 279 | |
b6dc21e7 KO |
280 | void wxNonOwnedWindow::SetWindowStyleFlag(long flags) |
281 | { | |
282 | if (flags == GetWindowStyleFlag()) | |
283 | return; | |
ce00f59b | 284 | |
b6dc21e7 | 285 | wxWindow::SetWindowStyleFlag(flags); |
ce00f59b | 286 | |
b6dc21e7 KO |
287 | if (m_nowpeer) |
288 | m_nowpeer->SetWindowStyleFlag(flags); | |
289 | } | |
290 | ||
3ccc5735 SC |
291 | // Raise the window to the top of the Z order |
292 | void wxNonOwnedWindow::Raise() | |
293 | { | |
294 | m_nowpeer->Raise(); | |
295 | } | |
296 | ||
297 | // Lower the window to the bottom of the Z order | |
298 | void wxNonOwnedWindow::Lower() | |
299 | { | |
300 | m_nowpeer->Lower(); | |
301 | } | |
302 | ||
303 | void wxNonOwnedWindow::HandleActivated( double timestampsec, bool didActivate ) | |
304 | { | |
305 | MacActivate( (int) (timestampsec * 1000) , didActivate); | |
306 | wxActivateEvent wxevent(wxEVT_ACTIVATE, didActivate , GetId()); | |
307 | wxevent.SetTimestamp( (int) (timestampsec * 1000) ); | |
308 | wxevent.SetEventObject(this); | |
309 | HandleWindowEvent(wxevent); | |
310 | } | |
311 | ||
312 | void wxNonOwnedWindow::HandleResized( double timestampsec ) | |
313 | { | |
314 | wxSizeEvent wxevent( GetSize() , GetId()); | |
315 | wxevent.SetTimestamp( (int) (timestampsec * 1000) ); | |
316 | wxevent.SetEventObject( this ); | |
317 | HandleWindowEvent(wxevent); | |
318 | // we have to inform some controls that have to reset things | |
319 | // relative to the toplevel window (e.g. OpenGL buffers) | |
320 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified | |
321 | } | |
322 | ||
0faf03bf | 323 | void wxNonOwnedWindow::HandleResizing( double WXUNUSED(timestampsec), wxRect* rect ) |
3ccc5735 SC |
324 | { |
325 | wxRect r = *rect ; | |
326 | ||
327 | // this is a EVT_SIZING not a EVT_SIZE type ! | |
328 | wxSizeEvent wxevent( r , GetId() ) ; | |
329 | wxevent.SetEventObject( this ) ; | |
330 | if ( HandleWindowEvent(wxevent) ) | |
331 | r = wxevent.GetRect() ; | |
332 | ||
333 | if ( GetMaxWidth() != -1 && r.GetWidth() > GetMaxWidth() ) | |
334 | r.SetWidth( GetMaxWidth() ) ; | |
335 | if ( GetMaxHeight() != -1 && r.GetHeight() > GetMaxHeight() ) | |
336 | r.SetHeight( GetMaxHeight() ) ; | |
337 | if ( GetMinWidth() != -1 && r.GetWidth() < GetMinWidth() ) | |
338 | r.SetWidth( GetMinWidth() ) ; | |
339 | if ( GetMinHeight() != -1 && r.GetHeight() < GetMinHeight() ) | |
340 | r.SetHeight( GetMinHeight() ) ; | |
341 | ||
342 | *rect = r; | |
343 | // TODO actuall this is too early, in case the window extents are adjusted | |
344 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified | |
345 | } | |
346 | ||
347 | void wxNonOwnedWindow::HandleMoved( double timestampsec ) | |
348 | { | |
349 | wxMoveEvent wxevent( GetPosition() , GetId()); | |
350 | wxevent.SetTimestamp( (int) (timestampsec * 1000) ); | |
351 | wxevent.SetEventObject( this ); | |
352 | HandleWindowEvent(wxevent); | |
353 | } | |
354 | ||
355 | void wxNonOwnedWindow::MacDelayedDeactivation(long timestamp) | |
356 | { | |
357 | if (s_macDeactivateWindow) | |
358 | { | |
359 | wxLogTrace(TRACE_ACTIVATE, | |
360 | wxT("Doing delayed deactivation of %p"), | |
361 | s_macDeactivateWindow); | |
362 | ||
363 | s_macDeactivateWindow->MacActivate(timestamp, false); | |
364 | } | |
365 | } | |
366 | ||
367 | void wxNonOwnedWindow::MacActivate( long timestamp , bool WXUNUSED(inIsActivating) ) | |
368 | { | |
369 | wxLogTrace(TRACE_ACTIVATE, wxT("TopLevel=%p::MacActivate"), this); | |
370 | ||
371 | if (s_macDeactivateWindow == this) | |
372 | s_macDeactivateWindow = NULL; | |
373 | ||
374 | MacDelayedDeactivation(timestamp); | |
375 | } | |
376 | ||
377 | bool wxNonOwnedWindow::Show(bool show) | |
378 | { | |
379 | if ( !wxWindow::Show(show) ) | |
380 | return false; | |
381 | ||
382 | if ( m_nowpeer ) | |
383 | m_nowpeer->Show(show); | |
03647350 | 384 | |
3ccc5735 SC |
385 | if ( show ) |
386 | { | |
387 | // because apps expect a size event to occur at this moment | |
388 | wxSizeEvent event(GetSize() , m_windowId); | |
389 | event.SetEventObject(this); | |
390 | HandleWindowEvent(event); | |
391 | } | |
03647350 | 392 | |
3ccc5735 SC |
393 | return true ; |
394 | } | |
395 | ||
396 | bool wxNonOwnedWindow::SetTransparent(wxByte alpha) | |
397 | { | |
398 | return m_nowpeer->SetTransparent(alpha); | |
399 | } | |
400 | ||
401 | ||
402 | bool wxNonOwnedWindow::CanSetTransparent() | |
403 | { | |
404 | return m_nowpeer->CanSetTransparent(); | |
405 | } | |
406 | ||
407 | ||
408 | void wxNonOwnedWindow::SetExtraStyle(long exStyle) | |
409 | { | |
410 | if ( GetExtraStyle() == exStyle ) | |
411 | return ; | |
412 | ||
413 | wxWindow::SetExtraStyle( exStyle ) ; | |
414 | ||
415 | if ( m_nowpeer ) | |
416 | m_nowpeer->SetExtraStyle(exStyle); | |
417 | } | |
418 | ||
419 | bool wxNonOwnedWindow::SetBackgroundStyle(wxBackgroundStyle style) | |
420 | { | |
421 | if ( !wxWindow::SetBackgroundStyle(style) ) | |
422 | return false ; | |
03647350 | 423 | |
4d949e7f | 424 | return m_nowpeer ? m_nowpeer->SetBackgroundStyle(style) : true; |
3ccc5735 SC |
425 | } |
426 | ||
427 | void wxNonOwnedWindow::DoMoveWindow(int x, int y, int width, int height) | |
428 | { | |
b8afff01 SC |
429 | if ( m_nowpeer == NULL ) |
430 | return; | |
431 | ||
3ccc5735 SC |
432 | m_cachedClippedRectValid = false ; |
433 | ||
434 | m_nowpeer->MoveWindow(x, y, width, height); | |
435 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified | |
436 | } | |
437 | ||
438 | void wxNonOwnedWindow::DoGetPosition( int *x, int *y ) const | |
439 | { | |
b8afff01 SC |
440 | if ( m_nowpeer == NULL ) |
441 | return; | |
442 | ||
3ccc5735 SC |
443 | int x1,y1 ; |
444 | m_nowpeer->GetPosition(x1, y1); | |
445 | ||
446 | if (x) | |
447 | *x = x1 ; | |
448 | if (y) | |
449 | *y = y1 ; | |
450 | } | |
451 | ||
452 | void wxNonOwnedWindow::DoGetSize( int *width, int *height ) const | |
453 | { | |
b8afff01 SC |
454 | if ( m_nowpeer == NULL ) |
455 | return; | |
03647350 | 456 | |
3ccc5735 | 457 | int w,h; |
03647350 | 458 | |
3ccc5735 SC |
459 | m_nowpeer->GetSize(w, h); |
460 | ||
461 | if (width) | |
462 | *width = w ; | |
463 | if (height) | |
464 | *height = h ; | |
465 | } | |
466 | ||
467 | void wxNonOwnedWindow::DoGetClientSize( int *width, int *height ) const | |
468 | { | |
b8afff01 SC |
469 | if ( m_nowpeer == NULL ) |
470 | return; | |
471 | ||
3ccc5735 | 472 | int left, top, w, h; |
bacea497 SC |
473 | // under iphone with a translucent status bar the m_nowpeer returns the |
474 | // inner area, while the content area extends under the translucent | |
475 | // status bar, therefore we use the content view's area | |
5397ea53 | 476 | #ifdef __WXOSX_IPHONE__ |
22756322 | 477 | GetPeer()->GetContentArea(left, top, w, h); |
5397ea53 | 478 | #else |
3ccc5735 | 479 | m_nowpeer->GetContentArea(left, top, w, h); |
5397ea53 SC |
480 | #endif |
481 | ||
3ccc5735 SC |
482 | if (width) |
483 | *width = w ; | |
484 | if (height) | |
485 | *height = h ; | |
486 | } | |
487 | ||
7dc941e3 SC |
488 | void wxNonOwnedWindow::WindowWasPainted() |
489 | { | |
490 | s_lastFlush = clock(); | |
491 | } | |
3ccc5735 SC |
492 | |
493 | void wxNonOwnedWindow::Update() | |
494 | { | |
7dc941e3 SC |
495 | if ( clock() - s_lastFlush > CLOCKS_PER_SEC / 30 ) |
496 | { | |
497 | s_lastFlush = clock(); | |
498 | m_nowpeer->Update(); | |
499 | } | |
3ccc5735 SC |
500 | } |
501 | ||
502 | WXWindow wxNonOwnedWindow::GetWXWindow() const | |
503 | { | |
504 | return m_nowpeer ? m_nowpeer->GetWXWindow() : NULL; | |
505 | } | |
506 | ||
507 | // --------------------------------------------------------------------------- | |
508 | // Shape implementation | |
509 | // --------------------------------------------------------------------------- | |
510 | ||
46ea442c | 511 | bool wxNonOwnedWindow::DoClearShape() |
3ccc5735 | 512 | { |
46ea442c VZ |
513 | m_shape.Clear(); |
514 | ||
515 | wxSize sz = GetClientSize(); | |
516 | wxRegion region(0, 0, sz.x, sz.y); | |
517 | ||
518 | return m_nowpeer->SetShape(region); | |
519 | } | |
3ccc5735 | 520 | |
46ea442c VZ |
521 | bool wxNonOwnedWindow::DoSetRegionShape(const wxRegion& region) |
522 | { | |
b61b8371 | 523 | m_shape = region; |
ce00f59b | 524 | |
46ea442c VZ |
525 | return m_nowpeer->SetShape(region); |
526 | } | |
527 | ||
528 | #if wxUSE_GRAPHICS_CONTEXT | |
529 | ||
530 | #include "wx/scopedptr.h" | |
531 | ||
532 | bool wxNonOwnedWindow::DoSetPathShape(const wxGraphicsPath& path) | |
533 | { | |
534 | m_shapePath = path; | |
535 | ||
536 | // Convert the path to wxRegion by rendering the path on a window-sized | |
537 | // bitmap, creating a mask from it and finally creating the region from | |
538 | // this mask. | |
539 | wxBitmap bmp(GetSize()); | |
540 | ||
3ccc5735 | 541 | { |
46ea442c VZ |
542 | wxMemoryDC dc(bmp); |
543 | dc.SetBackground(*wxBLACK); | |
544 | dc.Clear(); | |
545 | ||
546 | wxScopedPtr<wxGraphicsContext> context(wxGraphicsContext::Create(dc)); | |
547 | context->SetBrush(*wxWHITE); | |
548 | context->FillPath(m_shapePath); | |
3ccc5735 SC |
549 | } |
550 | ||
46ea442c VZ |
551 | bmp.SetMask(new wxMask(bmp, *wxBLACK)); |
552 | ||
553 | return DoSetRegionShape(wxRegion(bmp)); | |
3ccc5735 | 554 | } |
46ea442c VZ |
555 | |
556 | #endif // wxUSE_GRAPHICS_CONTEXT |