]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/overlay.cpp
moving rounded rect and ellipse to path class
[wxWidgets.git] / src / mac / carbon / overlay.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/overlay.cpp
3 // Purpose: common wxOverlay code
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 2006-10-20
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/overlay.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/dcclient.h"
31 #endif
32
33 #include "wx/private/overlay.h"
34
35 #ifdef wxHAS_NATIVE_OVERLAY
36
37 // ============================================================================
38 // implementation
39 // ============================================================================
40
41 wxOverlayImpl::wxOverlayImpl()
42 {
43 m_window = NULL ;
44 m_overlayContext = NULL ;
45 m_overlayWindow = NULL ;
46 }
47
48 wxOverlayImpl::~wxOverlayImpl()
49 {
50 Reset();
51 }
52
53 bool wxOverlayImpl::IsOk()
54 {
55 return m_overlayWindow != NULL ;
56 }
57
58 void wxOverlayImpl::MacGetBounds( Rect *bounds )
59 {
60 wxPoint origin(0,0);
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;
66 }
67
68 OSStatus wxOverlayImpl::CreateOverlayWindow()
69 {
70 OSStatus err;
71
72 WindowAttributes overlayAttributes = kWindowIgnoreClicksAttribute;
73
74 if ( m_window )
75 {
76 m_overlayParentWindow =(WindowRef) m_window->MacGetTopLevelWindowRef();
77
78 Rect bounds ;
79 MacGetBounds(&bounds);
80 err = CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, &m_overlayWindow );
81 if ( err == noErr )
82 {
83 SetWindowGroup( m_overlayWindow, GetWindowGroup(m_overlayParentWindow)); // Put them in the same group so that their window layers are consistent
84 }
85 }
86 else
87 {
88 m_overlayParentWindow = NULL ;
89 CGRect cgbounds ;
90 cgbounds = CGDisplayBounds(CGMainDisplayID());
91 Rect bounds;
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 );
97 }
98 ShowWindow(m_overlayWindow);
99 return err;
100 }
101
102 void wxOverlayImpl::Init( wxWindowDC* dc, int x , int y , int width , int height )
103 {
104 wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );
105
106 m_window = dc->GetWindow();
107 m_x = x ;
108 m_y = y ;
109 m_width = width ;
110 m_height = height ;
111
112 OSStatus err = CreateOverlayWindow();
113 wxASSERT_MSG( err == noErr , _("Couldn't create the overlay window") );
114 #ifndef __LP64__
115 err = QDBeginCGContext(GetWindowPort(m_overlayWindow), &m_overlayContext);
116 #endif
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") );
120 }
121
122 void wxOverlayImpl::BeginDrawing( wxWindowDC* dc)
123 {
124 // TODO CS
125 dc->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext ) );
126 /*
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 ;
134 */
135 wxSize size = dc->GetSize() ;
136 dc->SetClippingRegion( 0 , 0 , size.x , size.y ) ;
137 }
138
139 void wxOverlayImpl::EndDrawing( wxWindowDC* dc)
140 {
141 dc->SetGraphicsContext(NULL);
142 }
143
144 void wxOverlayImpl::Clear(wxWindowDC* dc)
145 {
146 wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") );
147 CGRect box = CGRectMake( m_x - 1, m_y - 1 , m_width + 2 , m_height + 2 );
148 CGContextClearRect( m_overlayContext, box );
149 }
150
151 void wxOverlayImpl::Reset()
152 {
153 if ( m_overlayContext )
154 {
155 #ifndef __LP64__
156 OSStatus err = QDEndCGContext(GetWindowPort(m_overlayWindow), &m_overlayContext);
157 wxASSERT_MSG( err == noErr , _("Couldn't end the context on the overlay window") );
158 #endif
159 m_overlayContext = NULL ;
160 }
161
162 // todo : don't dispose, only hide and reposition on next run
163 if (m_overlayWindow)
164 {
165 DisposeWindow(m_overlayWindow);
166 m_overlayWindow = NULL ;
167 }
168 }
169
170 #endif // wxHAS_NATIVE_OVERLAY