]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/overlay.cpp
popup activation scope and l&f
[wxWidgets.git] / src / mac / carbon / overlay.cpp
CommitLineData
30c841c8
VS
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"
b64c92ee
WS
28
29#ifndef WX_PRECOMP
30 #include "wx/dcclient.h"
31#endif
32
30c841c8
VS
33#include "wx/private/overlay.h"
34
69a5bc23 35#ifdef wxHAS_NATIVE_OVERLAY
30c841c8
VS
36
37// ============================================================================
38// implementation
39// ============================================================================
40
41wxOverlayImpl::wxOverlayImpl()
42{
43 m_window = NULL ;
44 m_overlayContext = NULL ;
45 m_overlayWindow = NULL ;
46}
47
48wxOverlayImpl::~wxOverlayImpl()
49{
50 Reset();
51}
52
b64c92ee 53bool wxOverlayImpl::IsOk()
30c841c8
VS
54{
55 return m_overlayWindow != NULL ;
56}
57
58void wxOverlayImpl::MacGetBounds( Rect *bounds )
59{
b2e2f950
SC
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
c348a710
SC
68 bounds->top = localwhere.v+m_y;
69 bounds->left = localwhere.h+m_x;
b2e2f950
SC
70 bounds->bottom = localwhere.v+m_y+m_height;
71 bounds->right = localwhere.h+m_x+m_width;
30c841c8
VS
72}
73
74OSStatus wxOverlayImpl::CreateOverlayWindow()
75{
76 OSStatus err;
77
78 WindowAttributes overlayAttributes = kWindowIgnoreClicksAttribute;
b64c92ee
WS
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;
f984d2af
VZ
98 bounds.top = (short)cgbounds.origin.y;
99 bounds.left = (short)cgbounds.origin.x;
100 bounds.bottom = (short)(bounds.top + cgbounds.size.height);
101 bounds.right = (short)(bounds.left + cgbounds.size.width);
b64c92ee
WS
102 err = CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, &m_overlayWindow );
103 }
104 ShowWindow(m_overlayWindow);
105 return err;
30c841c8
VS
106}
107
e686aa37 108void wxOverlayImpl::Init( wxDC* dc, int x , int y , int width , int height )
30c841c8
VS
109{
110 wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );
111
b64c92ee 112 m_window = dc->GetWindow();
30c841c8
VS
113 m_x = x ;
114 m_y = y ;
b2e2f950
SC
115 if ( dc->IsKindOf( CLASSINFO( wxClientDC ) ))
116 {
117 wxPoint origin = m_window->GetClientAreaOrigin();
f984d2af 118 m_x += origin.x;
b2e2f950
SC
119 m_y += origin.y;
120 }
30c841c8
VS
121 m_width = width ;
122 m_height = height ;
b64c92ee 123
30c841c8
VS
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
c348a710 129 CGContextTranslateCTM( m_overlayContext, 0, m_height );
30c841c8 130 CGContextScaleCTM( m_overlayContext, 1, -1 );
c348a710 131 CGContextTranslateCTM( m_overlayContext, -m_x , -m_y );
30c841c8
VS
132 wxASSERT_MSG( err == noErr , _("Couldn't init the context on the overlay window") );
133}
134
e686aa37 135void wxOverlayImpl::BeginDrawing( wxDC* dc)
30c841c8 136{
888dde65 137 wxDCImpl *impl = dc->GetImpl();
cc2cc2c4 138 wxGCDCImpl *win_impl = wxDynamicCast(impl,wxGCDCImpl);
888dde65
RR
139 if (win_impl)
140 {
141 win_impl->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext ) );
cc2cc2c4 142 dc->SetClippingRegion( m_x , m_y , m_width , m_height ) ;
888dde65 143 }
30c841c8
VS
144}
145
e686aa37 146void wxOverlayImpl::EndDrawing( wxDC* dc)
30c841c8 147{
888dde65 148 wxDCImpl *impl = dc->GetImpl();
cc2cc2c4 149 wxGCDCImpl *win_impl = wxDynamicCast(impl,wxGCDCImpl);
888dde65
RR
150 if (win_impl)
151 win_impl->SetGraphicsContext(NULL);
947f3b35 152
6239ee05 153 CGContextFlush( m_overlayContext );
30c841c8
VS
154}
155
e686aa37 156void wxOverlayImpl::Clear(wxDC* WXUNUSED(dc))
30c841c8
VS
157{
158 wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") );
159 CGRect box = CGRectMake( m_x - 1, m_y - 1 , m_width + 2 , m_height + 2 );
160 CGContextClearRect( m_overlayContext, box );
161}
162
163void wxOverlayImpl::Reset()
164{
165 if ( m_overlayContext )
166 {
167#ifndef __LP64__
168 OSStatus err = QDEndCGContext(GetWindowPort(m_overlayWindow), &m_overlayContext);
947f3b35
VZ
169 if ( err != noErr )
170 {
171 wxFAIL_MSG("Couldn't end the context on the overlay window");
172 }
30c841c8
VS
173#endif
174 m_overlayContext = NULL ;
b64c92ee
WS
175 }
176
30c841c8
VS
177 // todo : don't dispose, only hide and reposition on next run
178 if (m_overlayWindow)
179 {
180 DisposeWindow(m_overlayWindow);
181 m_overlayWindow = NULL ;
182 }
183}
184
185#endif // wxHAS_NATIVE_OVERLAY