]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/overlay.cpp
62ca692d161f98caaae95caf6fad61590e6db57a
[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 #include "wx/private/overlay.h"
29 #include "wx/dcclient.h"
30
31 #if wxHAS_NATIVE_OVERLAY
32
33 // ============================================================================
34 // implementation
35 // ============================================================================
36
37 wxOverlayImpl::wxOverlayImpl()
38 {
39 m_window = NULL ;
40 m_overlayContext = NULL ;
41 m_overlayWindow = NULL ;
42 }
43
44 wxOverlayImpl::~wxOverlayImpl()
45 {
46 Reset();
47 }
48
49 bool wxOverlayImpl::IsOk()
50 {
51 return m_overlayWindow != NULL ;
52 }
53
54 void wxOverlayImpl::MacGetBounds( Rect *bounds )
55 {
56 wxPoint origin(0,0);
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;
62 }
63
64 OSStatus wxOverlayImpl::CreateOverlayWindow()
65 {
66 OSStatus err;
67
68 WindowAttributes overlayAttributes = kWindowIgnoreClicksAttribute;
69
70 if ( m_window )
71 {
72 m_overlayParentWindow =(WindowRef) m_window->MacGetTopLevelWindowRef();
73
74 Rect bounds ;
75 MacGetBounds(&bounds);
76 err = CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, &m_overlayWindow );
77 if ( err == noErr )
78 {
79 SetWindowGroup( m_overlayWindow, GetWindowGroup(m_overlayParentWindow)); // Put them in the same group so that their window layers are consistent
80 }
81 }
82 else
83 {
84 m_overlayParentWindow = NULL ;
85 CGRect cgbounds ;
86 cgbounds = CGDisplayBounds(CGMainDisplayID());
87 Rect bounds;
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 );
93 }
94 ShowWindow(m_overlayWindow);
95 return err;
96 }
97
98 void wxOverlayImpl::Init( wxWindowDC* dc, int x , int y , int width , int height )
99 {
100 wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );
101
102 m_window = dc->GetWindow();
103 m_x = x ;
104 m_y = y ;
105 m_width = width ;
106 m_height = height ;
107
108 OSStatus err = CreateOverlayWindow();
109 wxASSERT_MSG( err == noErr , _("Couldn't create the overlay window") );
110 #ifndef __LP64__
111 err = QDBeginCGContext(GetWindowPort(m_overlayWindow), &m_overlayContext);
112 #endif
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") );
116 }
117
118 void wxOverlayImpl::BeginDrawing( wxWindowDC* dc)
119 {
120 // TODO CS
121 dc->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext ) );
122 /*
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 ;
130 */
131 wxSize size = dc->GetSize() ;
132 dc->SetClippingRegion( 0 , 0 , size.x , size.y ) ;
133 }
134
135 void wxOverlayImpl::EndDrawing( wxWindowDC* dc)
136 {
137 dc->SetGraphicsContext(NULL);
138 }
139
140 void wxOverlayImpl::Clear(wxWindowDC* dc)
141 {
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 );
145 }
146
147 void wxOverlayImpl::Reset()
148 {
149 if ( m_overlayContext )
150 {
151 #ifndef __LP64__
152 OSStatus err = QDEndCGContext(GetWindowPort(m_overlayWindow), &m_overlayContext);
153 wxASSERT_MSG( err == noErr , _("Couldn't end the context on the overlay window") );
154 #endif
155 m_overlayContext = NULL ;
156 }
157
158 // todo : don't dispose, only hide and reposition on next run
159 if (m_overlayWindow)
160 {
161 DisposeWindow(m_overlayWindow);
162 m_overlayWindow = NULL ;
163 }
164 }
165
166 #endif // wxHAS_NATIVE_OVERLAY