]>
Commit | Line | Data |
---|---|---|
13f0c85a SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/osx/cocoa/overlay.mm | |
3 | // Purpose: common wxOverlay code | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 2006-10-20 | |
7 | // RCS-ID: $Id: overlay.cpp 55419 2008-09-02 16:53:23Z SC $ | |
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/dcgraph.h" | |
34 | ||
35 | #include "wx/private/overlay.h" | |
36 | ||
37 | #ifdef wxHAS_NATIVE_OVERLAY | |
38 | ||
39 | // ============================================================================ | |
40 | // implementation | |
41 | // ============================================================================ | |
42 | ||
43 | wxOverlayImpl::wxOverlayImpl() | |
44 | { | |
45 | m_window = NULL ; | |
46 | m_overlayContext = NULL ; | |
47 | m_overlayWindow = NULL ; | |
48 | } | |
49 | ||
50 | wxOverlayImpl::~wxOverlayImpl() | |
51 | { | |
52 | Reset(); | |
53 | } | |
54 | ||
55 | bool wxOverlayImpl::IsOk() | |
56 | { | |
57 | return m_overlayWindow != NULL ; | |
58 | } | |
59 | ||
60 | void wxOverlayImpl::CreateOverlayWindow() | |
61 | { | |
62 | if ( m_window ) | |
63 | { | |
64 | m_overlayParentWindow = m_window->MacGetTopLevelWindowRef(); | |
65 | [m_overlayParentWindow makeKeyAndOrderFront:nil]; | |
66 | ||
67 | NSView* view = m_window->GetHandle(); | |
68 | ||
69 | NSPoint viewOriginBase, viewOriginScreen; | |
70 | viewOriginBase = [view convertPoint:NSMakePoint(0, 0) toView:nil]; | |
71 | viewOriginScreen = [m_overlayParentWindow convertBaseToScreen:viewOriginBase]; | |
72 | ||
73 | NSSize viewSize = [view frame].size; | |
74 | if ( [view isFlipped] ) | |
75 | viewOriginScreen.y -= viewSize.height; | |
76 | ||
77 | m_overlayWindow=[[NSWindow alloc] initWithContentRect:NSMakeRect(viewOriginScreen.x,viewOriginScreen.y, | |
78 | viewSize.width, | |
79 | viewSize.height) | |
80 | styleMask:NSBorderlessWindowMask | |
81 | backing:NSBackingStoreBuffered | |
82 | defer:YES]; | |
83 | ||
84 | [m_overlayParentWindow addChildWindow:m_overlayWindow ordered:NSWindowAbove]; | |
85 | } | |
86 | else | |
87 | { | |
88 | m_overlayParentWindow = NULL ; | |
89 | CGRect cgbounds ; | |
90 | cgbounds = CGDisplayBounds(CGMainDisplayID()); | |
91 | ||
92 | m_overlayWindow=[[NSWindow alloc] initWithContentRect:NSMakeRect(cgbounds.origin.x,cgbounds.origin.y, | |
93 | cgbounds.size.width, | |
94 | cgbounds.size.height) | |
95 | styleMask:NSBorderlessWindowMask | |
96 | backing:NSBackingStoreBuffered | |
97 | defer:YES]; | |
98 | } | |
99 | [m_overlayWindow setOpaque:NO]; | |
13f0c85a | 100 | [m_overlayWindow setIgnoresMouseEvents:YES]; |
583982c8 | 101 | [m_overlayWindow setAlphaValue:1.0]; |
13f0c85a SC |
102 | |
103 | [m_overlayWindow orderFront:nil]; | |
104 | } | |
105 | ||
106 | void wxOverlayImpl::Init( wxDC* dc, int x , int y , int width , int height ) | |
107 | { | |
108 | wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") ); | |
109 | ||
110 | m_window = dc->GetWindow(); | |
111 | m_x = x ; | |
112 | m_y = y ; | |
113 | if ( dc->IsKindOf( CLASSINFO( wxClientDC ) )) | |
114 | { | |
115 | wxPoint origin = m_window->GetClientAreaOrigin(); | |
116 | m_x += origin.x; | |
117 | m_y += origin.y; | |
118 | } | |
119 | m_width = width ; | |
120 | m_height = height ; | |
121 | ||
122 | CreateOverlayWindow(); | |
123 | wxASSERT_MSG( m_overlayWindow != NULL , _("Couldn't create the overlay window") ); | |
124 | m_overlayContext = (CGContextRef) [[m_overlayWindow graphicsContext] graphicsPort]; | |
125 | wxASSERT_MSG( m_overlayContext != NULL , _("Couldn't init the context on the overlay window") ); | |
126 | ||
127 | int ySize = 0; | |
128 | if ( m_window ) | |
129 | { | |
130 | NSView* view = m_window->GetHandle(); | |
131 | NSSize viewSize = [view frame].size; | |
132 | ySize = viewSize.height; | |
133 | } | |
134 | else | |
135 | { | |
136 | CGRect cgbounds ; | |
137 | cgbounds = CGDisplayBounds(CGMainDisplayID()); | |
138 | ySize = cgbounds.size.height; | |
139 | ||
140 | ||
141 | ||
142 | } | |
143 | CGContextTranslateCTM( m_overlayContext, 0, ySize ); | |
144 | CGContextScaleCTM( m_overlayContext, 1, -1 ); | |
145 | CGContextTranslateCTM( m_overlayContext, -m_x , -m_y ); | |
146 | } | |
147 | ||
148 | void wxOverlayImpl::BeginDrawing( wxDC* dc) | |
149 | { | |
150 | wxDCImpl *impl = dc->GetImpl(); | |
151 | wxGCDCImpl *win_impl = wxDynamicCast(impl,wxGCDCImpl); | |
152 | if (win_impl) | |
153 | { | |
154 | win_impl->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext ) ); | |
155 | dc->SetClippingRegion( m_x , m_y , m_width , m_height ) ; | |
156 | } | |
157 | } | |
158 | ||
159 | void wxOverlayImpl::EndDrawing( wxDC* dc) | |
160 | { | |
161 | wxDCImpl *impl = dc->GetImpl(); | |
162 | wxGCDCImpl *win_impl = wxDynamicCast(impl,wxGCDCImpl); | |
163 | if (win_impl) | |
164 | win_impl->SetGraphicsContext(NULL); | |
165 | ||
166 | CGContextFlush( m_overlayContext ); | |
167 | } | |
168 | ||
169 | void wxOverlayImpl::Clear(wxDC* WXUNUSED(dc)) | |
170 | { | |
171 | wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") ); | |
172 | CGRect box = CGRectMake( m_x - 1, m_y - 1 , m_width + 2 , m_height + 2 ); | |
173 | CGContextClearRect( m_overlayContext, box ); | |
174 | } | |
175 | ||
176 | void wxOverlayImpl::Reset() | |
177 | { | |
178 | if ( m_overlayContext ) | |
179 | { | |
180 | m_overlayContext = NULL ; | |
181 | } | |
182 | ||
183 | // todo : don't dispose, only hide and reposition on next run | |
184 | if (m_overlayWindow) | |
185 | { | |
186 | [m_overlayParentWindow removeChildWindow:m_overlayWindow]; | |
187 | [m_overlayWindow release]; | |
188 | m_overlayWindow = NULL ; | |
189 | } | |
190 | } | |
191 | ||
192 | #endif // wxHAS_NATIVE_OVERLAY |