]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/overlay.cpp
e1bb6db9b9d6c9289bb2aaaba19aa0c265496671
[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
30 #if wxHAS_NATIVE_OVERLAY
31
32 // ============================================================================
33 // implementation
34 // ============================================================================
35
36 wxOverlayImpl::wxOverlayImpl()
37 {
38 m_window = NULL ;
39 m_overlayContext = NULL ;
40 m_overlayWindow = NULL ;
41 }
42
43 wxOverlayImpl::~wxOverlayImpl()
44 {
45 Reset();
46 }
47
48 bool wxOverlayImpl::IsOk()
49 {
50 return m_overlayWindow != NULL ;
51 }
52
53 void wxOverlayImpl::MacGetBounds( Rect *bounds )
54 {
55 wxPoint origin(0,0);
56 origin = m_window->ClientToScreen( origin );
57 bounds->top = origin.y;
58 bounds->left = origin.x;
59 bounds->bottom = origin.y+m_y+m_height;
60 bounds->right = origin.x+m_x+m_width;
61 }
62
63 OSStatus wxOverlayImpl::CreateOverlayWindow()
64 {
65 OSStatus err;
66
67 WindowAttributes overlayAttributes = kWindowIgnoreClicksAttribute;
68
69 if ( m_window )
70 {
71 m_overlayParentWindow =(WindowRef) m_window->MacGetTopLevelWindowRef();
72
73 Rect bounds ;
74 MacGetBounds(&bounds);
75 err = CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, &m_overlayWindow );
76 if ( err == noErr )
77 {
78 SetWindowGroup( m_overlayWindow, GetWindowGroup(m_overlayParentWindow)); // Put them in the same group so that their window layers are consistent
79 }
80 }
81 else
82 {
83 m_overlayParentWindow = NULL ;
84 CGRect cgbounds ;
85 cgbounds = CGDisplayBounds(CGMainDisplayID());
86 Rect bounds;
87 bounds.top = cgbounds.origin.y;
88 bounds.left = cgbounds.origin.x;
89 bounds.bottom = bounds.top + cgbounds.size.height;
90 bounds.right = bounds.left + cgbounds.size.width;
91 err = CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, &m_overlayWindow );
92 }
93 ShowWindow(m_overlayWindow);
94 return err;
95 }
96
97 void wxOverlayImpl::Init( wxWindowDC* dc, int x , int y , int width , int height )
98 {
99 wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );
100
101 m_window = dc->GetWindow();
102 m_x = x ;
103 m_y = y ;
104 m_width = width ;
105 m_height = height ;
106
107 OSStatus err = CreateOverlayWindow();
108 wxASSERT_MSG( err == noErr , _("Couldn't create the overlay window") );
109 #ifndef __LP64__
110 err = QDBeginCGContext(GetWindowPort(m_overlayWindow), &m_overlayContext);
111 #endif
112 CGContextTranslateCTM( m_overlayContext, 0, m_height+m_y );
113 CGContextScaleCTM( m_overlayContext, 1, -1 );
114 wxASSERT_MSG( err == noErr , _("Couldn't init the context on the overlay window") );
115 }
116
117 void wxOverlayImpl::BeginDrawing( wxWindowDC* dc)
118 {
119 // TODO CS
120 dc->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext ) );
121 /*
122 delete dc->m_graphicContext ;
123 dc->m_graphicContext = new wxMacCGContext( m_overlayContext );
124 // we are right now startin at 0,0 not at the wxWindow's origin, so most of the calculations
125 // int dc are already corect
126 // just to make sure :
127 dc->m_macLocalOrigin.x = 0 ;
128 dc->m_macLocalOrigin.y = 0 ;
129 */
130 wxSize size = dc->GetSize() ;
131 dc->SetClippingRegion( 0 , 0 , size.x , size.y ) ;
132 }
133
134 void wxOverlayImpl::EndDrawing( wxWindowDC* dc)
135 {
136 dc->SetGraphicsContext(NULL);
137 }
138
139 void wxOverlayImpl::Clear(wxWindowDC* dc)
140 {
141 wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") );
142 CGRect box = CGRectMake( m_x - 1, m_y - 1 , m_width + 2 , m_height + 2 );
143 CGContextClearRect( m_overlayContext, box );
144 }
145
146 void wxOverlayImpl::Reset()
147 {
148 if ( m_overlayContext )
149 {
150 #ifndef __LP64__
151 OSStatus err = QDEndCGContext(GetWindowPort(m_overlayWindow), &m_overlayContext);
152 wxASSERT_MSG( err == noErr , _("Couldn't end the context on the overlay window") );
153 #endif
154 m_overlayContext = NULL ;
155 }
156
157 // todo : don't dispose, only hide and reposition on next run
158 if (m_overlayWindow)
159 {
160 DisposeWindow(m_overlayWindow);
161 m_overlayWindow = NULL ;
162 }
163 }
164
165 #endif // wxHAS_NATIVE_OVERLAY