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"
30 #include "wx/dcclient.h"
33 #include "wx/private/overlay.h"
35 #ifdef wxHAS_NATIVE_OVERLAY
37 // ============================================================================
39 // ============================================================================
41 wxOverlayImpl::wxOverlayImpl()
44 m_overlayContext
= NULL
;
45 m_overlayWindow
= NULL
;
48 wxOverlayImpl::~wxOverlayImpl()
53 bool wxOverlayImpl::IsOk()
55 return m_overlayWindow
!= NULL
;
58 void wxOverlayImpl::MacGetBounds( Rect
*bounds
)
61 origin
= m_window
->ClientToScreen( origin
);
62 bounds
->top
= origin
.y
;
63 bounds
->left
= origin
.x
;
64 bounds
->bottom
= origin
.y
+m_y
+m_height
;
65 bounds
->right
= origin
.x
+m_x
+m_width
;
68 OSStatus
wxOverlayImpl::CreateOverlayWindow()
72 WindowAttributes overlayAttributes
= kWindowIgnoreClicksAttribute
;
76 m_overlayParentWindow
=(WindowRef
) m_window
->MacGetTopLevelWindowRef();
79 MacGetBounds(&bounds
);
80 err
= CreateNewWindow( kOverlayWindowClass
, overlayAttributes
, &bounds
, &m_overlayWindow
);
83 SetWindowGroup( m_overlayWindow
, GetWindowGroup(m_overlayParentWindow
)); // Put them in the same group so that their window layers are consistent
88 m_overlayParentWindow
= NULL
;
90 cgbounds
= CGDisplayBounds(CGMainDisplayID());
92 bounds
.top
= cgbounds
.origin
.y
;
93 bounds
.left
= cgbounds
.origin
.x
;
94 bounds
.bottom
= bounds
.top
+ cgbounds
.size
.height
;
95 bounds
.right
= bounds
.left
+ cgbounds
.size
.width
;
96 err
= CreateNewWindow( kOverlayWindowClass
, overlayAttributes
, &bounds
, &m_overlayWindow
);
98 ShowWindow(m_overlayWindow
);
102 void wxOverlayImpl::Init( wxWindowDC
* dc
, int x
, int y
, int width
, int height
)
104 wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );
106 m_window
= dc
->GetWindow();
112 OSStatus err
= CreateOverlayWindow();
113 wxASSERT_MSG( err
== noErr
, _("Couldn't create the overlay window") );
115 err
= QDBeginCGContext(GetWindowPort(m_overlayWindow
), &m_overlayContext
);
117 CGContextTranslateCTM( m_overlayContext
, 0, m_height
+m_y
);
118 CGContextScaleCTM( m_overlayContext
, 1, -1 );
119 wxASSERT_MSG( err
== noErr
, _("Couldn't init the context on the overlay window") );
122 void wxOverlayImpl::BeginDrawing( wxWindowDC
* dc
)
125 dc
->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext
) );
127 delete dc->m_graphicContext ;
128 dc->m_graphicContext = new wxMacCGContext( m_overlayContext );
129 // we are right now startin at 0,0 not at the wxWindow's origin, so most of the calculations
130 // int dc are already corect
131 // just to make sure :
132 dc->m_macLocalOrigin.x = 0 ;
133 dc->m_macLocalOrigin.y = 0 ;
135 wxSize size
= dc
->GetSize() ;
136 dc
->SetClippingRegion( 0 , 0 , size
.x
, size
.y
) ;
139 void wxOverlayImpl::EndDrawing( wxWindowDC
* dc
)
141 dc
->SetGraphicsContext(NULL
);
142 CGContextSynchronize( m_overlayContext
);
145 void wxOverlayImpl::Clear(wxWindowDC
* dc
)
147 wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") );
148 CGRect box
= CGRectMake( m_x
- 1, m_y
- 1 , m_width
+ 2 , m_height
+ 2 );
149 CGContextClearRect( m_overlayContext
, box
);
152 void wxOverlayImpl::Reset()
154 if ( m_overlayContext
)
157 OSStatus err
= QDEndCGContext(GetWindowPort(m_overlayWindow
), &m_overlayContext
);
158 wxASSERT_MSG( err
== noErr
, _("Couldn't end the context on the overlay window") );
160 m_overlayContext
= NULL
;
163 // todo : don't dispose, only hide and reposition on next run
166 DisposeWindow(m_overlayWindow
);
167 m_overlayWindow
= NULL
;
171 #endif // wxHAS_NATIVE_OVERLAY