]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/overlay.cpp
renamed IsRefTo() to IsSameAs() (do complain if this is not more clear) and
[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 int x, y;
61 x=y=0;
62 m_window->MacWindowToRootWindow( &x , &y ) ;
63 WindowRef window = (WindowRef) m_window->MacGetTopLevelWindowRef() ;
64
65 Point localwhere = { y, x };
66 wxMacLocalToGlobal( window, &localwhere ) ;
67
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;
72 }
73
74 OSStatus wxOverlayImpl::CreateOverlayWindow()
75 {
76 OSStatus err;
77
78 WindowAttributes overlayAttributes = kWindowIgnoreClicksAttribute;
79
80 if ( m_window )
81 {
82 m_overlayParentWindow =(WindowRef) m_window->MacGetTopLevelWindowRef();
83
84 Rect bounds ;
85 MacGetBounds(&bounds);
86 err = CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, &m_overlayWindow );
87 if ( err == noErr )
88 {
89 SetWindowGroup( m_overlayWindow, GetWindowGroup(m_overlayParentWindow)); // Put them in the same group so that their window layers are consistent
90 }
91 }
92 else
93 {
94 m_overlayParentWindow = NULL ;
95 CGRect cgbounds ;
96 cgbounds = CGDisplayBounds(CGMainDisplayID());
97 Rect bounds;
98 bounds.top = cgbounds.origin.y;
99 bounds.left = cgbounds.origin.x;
100 bounds.bottom = bounds.top + cgbounds.size.height;
101 bounds.right = bounds.left + cgbounds.size.width;
102 err = CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, &m_overlayWindow );
103 }
104 ShowWindow(m_overlayWindow);
105 return err;
106 }
107
108 void wxOverlayImpl::Init( wxWindowDC* dc, int x , int y , int width , int height )
109 {
110 wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );
111
112 m_window = dc->GetWindow();
113 m_x = x ;
114 m_y = y ;
115 if ( dc->IsKindOf( CLASSINFO( wxClientDC ) ))
116 {
117 wxPoint origin = m_window->GetClientAreaOrigin();
118 m_x += origin.x;
119 m_y += origin.y;
120 }
121 m_width = width ;
122 m_height = height ;
123
124 OSStatus err = CreateOverlayWindow();
125 wxASSERT_MSG( err == noErr , _("Couldn't create the overlay window") );
126 #ifndef __LP64__
127 err = QDBeginCGContext(GetWindowPort(m_overlayWindow), &m_overlayContext);
128 #endif
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") );
133 }
134
135 void wxOverlayImpl::BeginDrawing( wxWindowDC* dc)
136 {
137 // TODO CS
138 dc->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext ) );
139 // triggers an application of the already set device origins to the native context
140 dc->SetUserScale(1,1);
141 wxSize size = dc->GetSize() ;
142 dc->SetClippingRegion( 0 , 0 , size.x , size.y ) ;
143 }
144
145 void wxOverlayImpl::EndDrawing( wxWindowDC* dc)
146 {
147 dc->SetGraphicsContext(NULL);
148 CGContextSynchronize( m_overlayContext );
149 }
150
151 void wxOverlayImpl::Clear(wxWindowDC* dc)
152 {
153 wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") );
154 CGRect box = CGRectMake( m_x - 1, m_y - 1 , m_width + 2 , m_height + 2 );
155 CGContextClearRect( m_overlayContext, box );
156 }
157
158 void wxOverlayImpl::Reset()
159 {
160 if ( m_overlayContext )
161 {
162 #ifndef __LP64__
163 OSStatus err = QDEndCGContext(GetWindowPort(m_overlayWindow), &m_overlayContext);
164 wxASSERT_MSG( err == noErr , _("Couldn't end the context on the overlay window") );
165 #endif
166 m_overlayContext = NULL ;
167 }
168
169 // todo : don't dispose, only hide and reposition on next run
170 if (m_overlayWindow)
171 {
172 DisposeWindow(m_overlayWindow);
173 m_overlayWindow = NULL ;
174 }
175 }
176
177 #endif // wxHAS_NATIVE_OVERLAY