]>
Commit | Line | Data |
---|---|---|
489468fe | 1 | ///////////////////////////////////////////////////////////////////////////// |
524c47aa | 2 | // Name: src/osx/carbon/dcclient.cpp |
489468fe SC |
3 | // Purpose: wxClientDCImpl class |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #include "wx/dcclient.h" | |
15 | ||
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/log.h" | |
18 | #include "wx/window.h" | |
19 | #include "wx/dcmemory.h" | |
20 | #include "wx/settings.h" | |
21 | #include "wx/toplevel.h" | |
22 | #include "wx/math.h" | |
23 | #include "wx/region.h" | |
24 | #endif | |
25 | ||
26 | #include "wx/graphics.h" | |
27 | #include "wx/rawbmp.h" | |
1f0c8f31 | 28 | #include "wx/osx/private.h" |
b2680ced | 29 | #include "wx/osx/dcclient.h" |
489468fe SC |
30 | |
31 | //----------------------------------------------------------------------------- | |
32 | // wxWindowDCImpl | |
33 | //----------------------------------------------------------------------------- | |
34 | ||
35 | IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl, wxGCDCImpl) | |
36 | ||
37 | wxWindowDCImpl::wxWindowDCImpl( wxDC *owner ) | |
38 | : wxGCDCImpl( owner ) | |
39 | { | |
40 | m_release = false; | |
41 | } | |
42 | ||
b2680ced | 43 | |
489468fe SC |
44 | wxWindowDCImpl::wxWindowDCImpl( wxDC *owner, wxWindow *window ) |
45 | : wxGCDCImpl( owner ) | |
46 | { | |
47 | m_window = window; | |
03647350 | 48 | |
489468fe SC |
49 | m_ok = true ; |
50 | ||
51 | m_window->GetSize( &m_width , &m_height); | |
52 | if ( !m_window->IsShownOnScreen() ) | |
53 | m_width = m_height = 0; | |
b2680ced | 54 | |
489468fe | 55 | CGContextRef cg = (CGContextRef) window->MacGetCGContextRef(); |
b2680ced | 56 | |
489468fe SC |
57 | m_release = false; |
58 | if ( cg == NULL ) | |
59 | { | |
60 | SetGraphicsContext( wxGraphicsContext::Create( window ) ) ; | |
0ffa23cc | 61 | SetDeviceOrigin(-window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize()); |
489468fe SC |
62 | } |
63 | else | |
64 | { | |
65 | CGContextSaveGState( cg ); | |
66 | m_release = true ; | |
67 | // make sure the context is having its origin at the wx-window coordinates of the | |
68 | // view (read at the top of window.cpp about the differences) | |
69 | if ( window->MacGetLeftBorderSize() != 0 || window->MacGetTopBorderSize() != 0 ) | |
70 | CGContextTranslateCTM( cg , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ); | |
71 | ||
058e3f1b SC |
72 | wxGraphicsContext* context = wxGraphicsContext::CreateFromNative( cg ); |
73 | context->EnableOffset(true); | |
74 | SetGraphicsContext( context ); | |
489468fe SC |
75 | } |
76 | DoSetClippingRegion( 0 , 0 , m_width , m_height ) ; | |
77 | ||
78 | SetBackground(wxBrush(window->GetBackgroundColour(),wxSOLID)); | |
79 | ||
80 | SetFont( window->GetFont() ) ; | |
81 | } | |
82 | ||
83 | wxWindowDCImpl::~wxWindowDCImpl() | |
84 | { | |
85 | if ( m_release ) | |
86 | { | |
87 | // this must not necessarily be the current context, we must restore the state of the | |
88 | // cg we started with above (before the CGContextTranslateCTM call) | |
89 | CGContextRef cg = (CGContextRef) m_window->MacGetCGContextRef(); | |
90 | CGContextRestoreGState(cg); | |
91 | } | |
92 | } | |
93 | ||
94 | void wxWindowDCImpl::DoGetSize( int* width, int* height ) const | |
95 | { | |
96 | if ( width ) | |
97 | *width = m_width; | |
98 | if ( height ) | |
99 | *height = m_height; | |
100 | } | |
101 | ||
928e7a7e | 102 | #if wxOSX_USE_CARBON |
489468fe SC |
103 | wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const |
104 | { | |
105 | // wxScreenDC is derived from wxWindowDC, so a screen dc will | |
106 | // call this method when a Blit is performed with it as a source. | |
107 | if (!m_window) | |
108 | return wxNullBitmap; | |
109 | ||
489468fe SC |
110 | ControlRef handle = (ControlRef) m_window->GetHandle(); |
111 | if ( !handle ) | |
112 | return wxNullBitmap; | |
03647350 | 113 | |
489468fe SC |
114 | HIRect rect; |
115 | CGImageRef image; | |
116 | CGContextRef context; | |
489468fe SC |
117 | |
118 | HIViewCreateOffscreenImage( handle, 0, &rect, &image); | |
119 | ||
120 | ||
121 | int width = subrect != NULL ? subrect->width : (int)rect.size.width; | |
122 | int height = subrect != NULL ? subrect->height : (int)rect.size.height ; | |
123 | ||
124 | wxBitmap bmp = wxBitmap(width, height, 32); | |
03647350 | 125 | |
489468fe | 126 | context = (CGContextRef)bmp.GetHBITMAP(); |
03647350 | 127 | |
489468fe | 128 | CGContextSaveGState(context); |
03647350 | 129 | |
489468fe SC |
130 | CGContextTranslateCTM( context, 0, height ); |
131 | CGContextScaleCTM( context, 1, -1 ); | |
132 | ||
133 | if ( subrect ) | |
134 | rect = CGRectOffset( rect, -subrect->x, -subrect->y ) ; | |
135 | CGContextDrawImage( context, rect, image ); | |
136 | ||
137 | CGContextRestoreGState(context); | |
489468fe | 138 | return bmp; |
524c47aa | 139 | } |
928e7a7e | 140 | #endif |
489468fe SC |
141 | |
142 | /* | |
143 | * wxClientDCImpl | |
144 | */ | |
145 | ||
146 | IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl, wxWindowDCImpl) | |
147 | ||
148 | wxClientDCImpl::wxClientDCImpl( wxDC *owner ) | |
149 | : wxWindowDCImpl( owner ) | |
150 | { | |
151 | } | |
152 | ||
153 | wxClientDCImpl::wxClientDCImpl( wxDC *owner, wxWindow *window ) : | |
154 | wxWindowDCImpl( owner, window ) | |
155 | { | |
9a83f860 | 156 | wxCHECK_RET( window, wxT("invalid window in wxClientDCImpl") ); |
489468fe SC |
157 | wxPoint origin = window->GetClientAreaOrigin() ; |
158 | m_window->GetClientSize( &m_width , &m_height); | |
159 | if ( !m_window->IsShownOnScreen() ) | |
160 | m_width = m_height = 0; | |
0ffa23cc SC |
161 | |
162 | int x0,y0; | |
163 | DoGetDeviceOrigin(&x0,&y0); | |
164 | SetDeviceOrigin( origin.x + x0, origin.y + y0 ); | |
165 | ||
489468fe SC |
166 | DoSetClippingRegion( 0 , 0 , m_width , m_height ) ; |
167 | } | |
168 | ||
169 | wxClientDCImpl::~wxClientDCImpl() | |
170 | { | |
72a0d0fc SC |
171 | if( GetGraphicsContext() && GetGraphicsContext()->GetNativeContext() ) |
172 | Flush(); | |
489468fe SC |
173 | } |
174 | ||
175 | /* | |
176 | * wxPaintDCImpl | |
177 | */ | |
178 | ||
179 | IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl, wxWindowDCImpl) | |
180 | ||
181 | wxPaintDCImpl::wxPaintDCImpl( wxDC *owner ) | |
182 | : wxWindowDCImpl( owner ) | |
183 | { | |
184 | } | |
185 | ||
186 | wxPaintDCImpl::wxPaintDCImpl( wxDC *owner, wxWindow *window ) : | |
187 | wxWindowDCImpl( owner, window ) | |
188 | { | |
9a83f860 | 189 | wxASSERT_MSG( window->MacGetCGContextRef() != NULL, wxT("using wxPaintDC without being in a native paint event") ); |
489468fe SC |
190 | wxPoint origin = window->GetClientAreaOrigin() ; |
191 | m_window->GetClientSize( &m_width , &m_height); | |
192 | SetDeviceOrigin( origin.x, origin.y ); | |
193 | DoSetClippingRegion( 0 , 0 , m_width , m_height ) ; | |
194 | } | |
195 | ||
196 | wxPaintDCImpl::~wxPaintDCImpl() | |
197 | { | |
198 | } |