1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/overlay.cpp
3 // Purpose: common wxOverlay code
4 // Author: Stefan Csomor
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/overlay.h"
28 #include "wx/private/overlay.h"
29 #include "wx/dcclient.h"
31 #if wxHAS_NATIVE_OVERLAY
33 // ============================================================================
35 // ============================================================================
37 wxOverlayImpl::wxOverlayImpl()
40 m_overlayContext
= NULL
;
41 m_overlayWindow
= NULL
;
44 wxOverlayImpl::~wxOverlayImpl()
49 bool wxOverlayImpl::IsOk()
51 return m_overlayWindow
!= NULL
;
54 void wxOverlayImpl::MacGetBounds( Rect
*bounds
)
57 origin
= m_window
->ClientToScreen( origin
);
58 bounds
->top
= origin
.y
;
59 bounds
->left
= origin
.x
;
60 bounds
->bottom
= origin
.y
+m_y
+m_height
;
61 bounds
->right
= origin
.x
+m_x
+m_width
;
64 OSStatus
wxOverlayImpl::CreateOverlayWindow()
68 WindowAttributes overlayAttributes
= kWindowIgnoreClicksAttribute
;
72 m_overlayParentWindow
=(WindowRef
) m_window
->MacGetTopLevelWindowRef();
75 MacGetBounds(&bounds
);
76 err
= CreateNewWindow( kOverlayWindowClass
, overlayAttributes
, &bounds
, &m_overlayWindow
);
79 SetWindowGroup( m_overlayWindow
, GetWindowGroup(m_overlayParentWindow
)); // Put them in the same group so that their window layers are consistent
84 m_overlayParentWindow
= NULL
;
86 cgbounds
= CGDisplayBounds(CGMainDisplayID());
88 bounds
.top
= cgbounds
.origin
.y
;
89 bounds
.left
= cgbounds
.origin
.x
;
90 bounds
.bottom
= bounds
.top
+ cgbounds
.size
.height
;
91 bounds
.right
= bounds
.left
+ cgbounds
.size
.width
;
92 err
= CreateNewWindow( kOverlayWindowClass
, overlayAttributes
, &bounds
, &m_overlayWindow
);
94 ShowWindow(m_overlayWindow
);
98 void wxOverlayImpl::Init( wxWindowDC
* dc
, int x
, int y
, int width
, int height
)
100 wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );
102 m_window
= dc
->GetWindow();
108 OSStatus err
= CreateOverlayWindow();
109 wxASSERT_MSG( err
== noErr
, _("Couldn't create the overlay window") );
111 err
= QDBeginCGContext(GetWindowPort(m_overlayWindow
), &m_overlayContext
);
113 CGContextTranslateCTM( m_overlayContext
, 0, m_height
+m_y
);
114 CGContextScaleCTM( m_overlayContext
, 1, -1 );
115 wxASSERT_MSG( err
== noErr
, _("Couldn't init the context on the overlay window") );
118 void wxOverlayImpl::BeginDrawing( wxWindowDC
* dc
)
121 dc
->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext
) );
123 delete dc->m_graphicContext ;
124 dc->m_graphicContext = new wxMacCGContext( m_overlayContext );
125 // we are right now startin at 0,0 not at the wxWindow's origin, so most of the calculations
126 // int dc are already corect
127 // just to make sure :
128 dc->m_macLocalOrigin.x = 0 ;
129 dc->m_macLocalOrigin.y = 0 ;
131 wxSize size
= dc
->GetSize() ;
132 dc
->SetClippingRegion( 0 , 0 , size
.x
, size
.y
) ;
135 void wxOverlayImpl::EndDrawing( wxWindowDC
* dc
)
137 dc
->SetGraphicsContext(NULL
);
140 void wxOverlayImpl::Clear(wxWindowDC
* dc
)
142 wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") );
143 CGRect box
= CGRectMake( m_x
- 1, m_y
- 1 , m_width
+ 2 , m_height
+ 2 );
144 CGContextClearRect( m_overlayContext
, box
);
147 void wxOverlayImpl::Reset()
149 if ( m_overlayContext
)
152 OSStatus err
= QDEndCGContext(GetWindowPort(m_overlayWindow
), &m_overlayContext
);
153 wxASSERT_MSG( err
== noErr
, _("Couldn't end the context on the overlay window") );
155 m_overlayContext
= NULL
;
158 // todo : don't dispose, only hide and reposition on next run
161 DisposeWindow(m_overlayWindow
);
162 m_overlayWindow
= NULL
;
166 #endif // wxHAS_NATIVE_OVERLAY