1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/overlay.cpp
3 // Purpose: common wxOverlay code
4 // Author: Stefan Csomor
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #include "wx/overlay.h"
29 #include "wx/dcclient.h"
32 #include "wx/private/overlay.h"
34 #ifdef wxHAS_NATIVE_OVERLAY
36 // ============================================================================
38 // ============================================================================
40 wxOverlayImpl::wxOverlayImpl()
43 m_overlayContext
= NULL
;
44 m_overlayWindow
= NULL
;
47 wxOverlayImpl::~wxOverlayImpl()
52 bool wxOverlayImpl::IsOk()
54 return m_overlayWindow
!= NULL
;
57 void wxOverlayImpl::MacGetBounds( Rect
*bounds
)
61 m_window
->MacWindowToRootWindow( &x
, &y
) ;
62 wxNonOwnedWindow
* tlw
= m_window
->MacGetTopLevelWindow();
63 tlw
->GetNonOwnedPeer()->WindowToScreen( &x
, &y
);
67 bounds
->bottom
= y
+m_y
+m_height
;
68 bounds
->right
= x
+m_x
+m_width
;
71 OSStatus
wxOverlayImpl::CreateOverlayWindow()
75 WindowAttributes overlayAttributes
= kWindowIgnoreClicksAttribute
;
79 m_overlayParentWindow
=(WindowRef
) m_window
->MacGetTopLevelWindowRef();
82 MacGetBounds(&bounds
);
83 err
= CreateNewWindow( kOverlayWindowClass
, overlayAttributes
, &bounds
, &m_overlayWindow
);
86 SetWindowGroup( m_overlayWindow
, GetWindowGroup(m_overlayParentWindow
)); // Put them in the same group so that their window layers are consistent
91 m_overlayParentWindow
= NULL
;
93 cgbounds
= CGDisplayBounds(CGMainDisplayID());
95 bounds
.top
= (short)cgbounds
.origin
.y
;
96 bounds
.left
= (short)cgbounds
.origin
.x
;
97 bounds
.bottom
= (short)(bounds
.top
+ cgbounds
.size
.height
);
98 bounds
.right
= (short)(bounds
.left
+ cgbounds
.size
.width
);
99 err
= CreateNewWindow( kOverlayWindowClass
, overlayAttributes
, &bounds
, &m_overlayWindow
);
101 ShowWindow(m_overlayWindow
);
105 void wxOverlayImpl::Init( wxDC
* dc
, int x
, int y
, int width
, int height
)
107 wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );
109 m_window
= dc
->GetWindow();
112 if ( dc
->IsKindOf( CLASSINFO( wxClientDC
) ))
114 wxPoint origin
= m_window
->GetClientAreaOrigin();
121 OSStatus err
= CreateOverlayWindow();
122 wxASSERT_MSG( err
== noErr
, _("Couldn't create the overlay window") );
124 err
= QDBeginCGContext(GetWindowPort(m_overlayWindow
), &m_overlayContext
);
126 CGContextTranslateCTM( m_overlayContext
, 0, m_height
);
127 CGContextScaleCTM( m_overlayContext
, 1, -1 );
128 CGContextTranslateCTM( m_overlayContext
, -m_x
, -m_y
);
129 wxASSERT_MSG( err
== noErr
, _("Couldn't init the context on the overlay window") );
132 void wxOverlayImpl::BeginDrawing( wxDC
* dc
)
134 wxDCImpl
*impl
= dc
->GetImpl();
135 wxGCDCImpl
*win_impl
= wxDynamicCast(impl
,wxGCDCImpl
);
138 win_impl
->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext
) );
139 dc
->SetClippingRegion( m_x
, m_y
, m_width
, m_height
) ;
143 void wxOverlayImpl::EndDrawing( wxDC
* dc
)
145 wxDCImpl
*impl
= dc
->GetImpl();
146 wxGCDCImpl
*win_impl
= wxDynamicCast(impl
,wxGCDCImpl
);
148 win_impl
->SetGraphicsContext(NULL
);
150 CGContextFlush( m_overlayContext
);
153 void wxOverlayImpl::Clear(wxDC
* WXUNUSED(dc
))
155 wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") );
156 CGRect box
= CGRectMake( m_x
- 1, m_y
- 1 , m_width
+ 2 , m_height
+ 2 );
157 CGContextClearRect( m_overlayContext
, box
);
160 void wxOverlayImpl::Reset()
162 if ( m_overlayContext
)
165 OSStatus err
= QDEndCGContext(GetWindowPort(m_overlayWindow
), &m_overlayContext
);
168 wxFAIL_MSG("Couldn't end the context on the overlay window");
171 m_overlayContext
= NULL
;
174 // todo : don't dispose, only hide and reposition on next run
177 DisposeWindow(m_overlayWindow
);
178 m_overlayWindow
= NULL
;
182 #endif // wxHAS_NATIVE_OVERLAY