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
)
62 m_window
->MacWindowToRootWindow( &x
, &y
) ;
63 WindowRef window
= (WindowRef
) m_window
->MacGetTopLevelWindowRef() ;
65 Point localwhere
= { y
, x
};
66 wxMacLocalToGlobal( window
, &localwhere
) ;
68 bounds
->top
= localwhere
.v
+m_y
;
69 bounds
->left
= localwhere
.h
+m_x
;
70 bounds
->bottom
= localwhere
.v
+m_y
+m_height
;
71 bounds
->right
= localwhere
.h
+m_x
+m_width
;
74 OSStatus
wxOverlayImpl::CreateOverlayWindow()
78 WindowAttributes overlayAttributes
= kWindowIgnoreClicksAttribute
;
82 m_overlayParentWindow
=(WindowRef
) m_window
->MacGetTopLevelWindowRef();
85 MacGetBounds(&bounds
);
86 err
= CreateNewWindow( kOverlayWindowClass
, overlayAttributes
, &bounds
, &m_overlayWindow
);
89 SetWindowGroup( m_overlayWindow
, GetWindowGroup(m_overlayParentWindow
)); // Put them in the same group so that their window layers are consistent
94 m_overlayParentWindow
= NULL
;
96 cgbounds
= CGDisplayBounds(CGMainDisplayID());
98 bounds
.top
= (short)cgbounds
.origin
.y
;
99 bounds
.left
= (short)cgbounds
.origin
.x
;
100 bounds
.bottom
= (short)(bounds
.top
+ cgbounds
.size
.height
);
101 bounds
.right
= (short)(bounds
.left
+ cgbounds
.size
.width
);
102 err
= CreateNewWindow( kOverlayWindowClass
, overlayAttributes
, &bounds
, &m_overlayWindow
);
104 ShowWindow(m_overlayWindow
);
108 void wxOverlayImpl::Init( wxWindowDC
* dc
, int x
, int y
, int width
, int height
)
110 wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );
112 m_window
= dc
->GetWindow();
115 if ( dc
->IsKindOf( CLASSINFO( wxClientDC
) ))
117 wxPoint origin
= m_window
->GetClientAreaOrigin();
124 OSStatus err
= CreateOverlayWindow();
125 wxASSERT_MSG( err
== noErr
, _("Couldn't create the overlay window") );
127 err
= QDBeginCGContext(GetWindowPort(m_overlayWindow
), &m_overlayContext
);
129 CGContextTranslateCTM( m_overlayContext
, 0, m_height
);
130 CGContextScaleCTM( m_overlayContext
, 1, -1 );
131 CGContextTranslateCTM( m_overlayContext
, -m_x
, -m_y
);
132 wxASSERT_MSG( err
== noErr
, _("Couldn't init the context on the overlay window") );
135 void wxOverlayImpl::BeginDrawing( wxWindowDC
* dc
)
137 dc
->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext
) );
138 wxSize size
= dc
->GetSize() ;
139 dc
->SetClippingRegion( 0 , 0 , size
.x
, size
.y
) ;
142 void wxOverlayImpl::EndDrawing( wxWindowDC
* dc
)
144 dc
->SetGraphicsContext(NULL
);
145 CGContextFlush( m_overlayContext
);
148 void wxOverlayImpl::Clear(wxWindowDC
* WXUNUSED(dc
))
150 wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") );
151 CGRect box
= CGRectMake( m_x
- 1, m_y
- 1 , m_width
+ 2 , m_height
+ 2 );
152 CGContextClearRect( m_overlayContext
, box
);
155 void wxOverlayImpl::Reset()
157 if ( m_overlayContext
)
160 OSStatus err
= QDEndCGContext(GetWindowPort(m_overlayWindow
), &m_overlayContext
);
161 wxASSERT_MSG( err
== noErr
, _("Couldn't end the context on the overlay window") );
163 m_overlayContext
= NULL
;
166 // todo : don't dispose, only hide and reposition on next run
169 DisposeWindow(m_overlayWindow
);
170 m_overlayWindow
= NULL
;
174 #endif // wxHAS_NATIVE_OVERLAY