]>
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; | |
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 ) ) ; | |
61 | } | |
62 | else | |
63 | { | |
64 | CGContextSaveGState( cg ); | |
65 | m_release = true ; | |
66 | // make sure the context is having its origin at the wx-window coordinates of the | |
67 | // view (read at the top of window.cpp about the differences) | |
68 | if ( window->MacGetLeftBorderSize() != 0 || window->MacGetTopBorderSize() != 0 ) | |
69 | CGContextTranslateCTM( cg , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ); | |
70 | ||
71 | SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) ); | |
72 | } | |
73 | DoSetClippingRegion( 0 , 0 , m_width , m_height ) ; | |
74 | ||
75 | SetBackground(wxBrush(window->GetBackgroundColour(),wxSOLID)); | |
76 | ||
77 | SetFont( window->GetFont() ) ; | |
78 | } | |
79 | ||
80 | wxWindowDCImpl::~wxWindowDCImpl() | |
81 | { | |
82 | if ( m_release ) | |
83 | { | |
84 | // this must not necessarily be the current context, we must restore the state of the | |
85 | // cg we started with above (before the CGContextTranslateCTM call) | |
86 | CGContextRef cg = (CGContextRef) m_window->MacGetCGContextRef(); | |
87 | CGContextRestoreGState(cg); | |
88 | } | |
89 | } | |
90 | ||
91 | void wxWindowDCImpl::DoGetSize( int* width, int* height ) const | |
92 | { | |
93 | if ( width ) | |
94 | *width = m_width; | |
95 | if ( height ) | |
96 | *height = m_height; | |
97 | } | |
98 | ||
928e7a7e | 99 | #if wxOSX_USE_CARBON |
489468fe SC |
100 | wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const |
101 | { | |
102 | // wxScreenDC is derived from wxWindowDC, so a screen dc will | |
103 | // call this method when a Blit is performed with it as a source. | |
104 | if (!m_window) | |
105 | return wxNullBitmap; | |
106 | ||
489468fe SC |
107 | ControlRef handle = (ControlRef) m_window->GetHandle(); |
108 | if ( !handle ) | |
109 | return wxNullBitmap; | |
110 | ||
111 | HIRect rect; | |
112 | CGImageRef image; | |
113 | CGContextRef context; | |
489468fe SC |
114 | |
115 | HIViewCreateOffscreenImage( handle, 0, &rect, &image); | |
116 | ||
117 | ||
118 | int width = subrect != NULL ? subrect->width : (int)rect.size.width; | |
119 | int height = subrect != NULL ? subrect->height : (int)rect.size.height ; | |
120 | ||
121 | wxBitmap bmp = wxBitmap(width, height, 32); | |
122 | ||
123 | context = (CGContextRef)bmp.GetHBITMAP(); | |
124 | ||
125 | CGContextSaveGState(context); | |
126 | ||
127 | CGContextTranslateCTM( context, 0, height ); | |
128 | CGContextScaleCTM( context, 1, -1 ); | |
129 | ||
130 | if ( subrect ) | |
131 | rect = CGRectOffset( rect, -subrect->x, -subrect->y ) ; | |
132 | CGContextDrawImage( context, rect, image ); | |
133 | ||
134 | CGContextRestoreGState(context); | |
489468fe | 135 | return bmp; |
524c47aa | 136 | } |
928e7a7e | 137 | #endif |
489468fe SC |
138 | |
139 | /* | |
140 | * wxClientDCImpl | |
141 | */ | |
142 | ||
143 | IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl, wxWindowDCImpl) | |
144 | ||
145 | wxClientDCImpl::wxClientDCImpl( wxDC *owner ) | |
146 | : wxWindowDCImpl( owner ) | |
147 | { | |
148 | } | |
149 | ||
150 | wxClientDCImpl::wxClientDCImpl( wxDC *owner, wxWindow *window ) : | |
151 | wxWindowDCImpl( owner, window ) | |
152 | { | |
9a83f860 | 153 | wxCHECK_RET( window, wxT("invalid window in wxClientDCImpl") ); |
489468fe SC |
154 | wxPoint origin = window->GetClientAreaOrigin() ; |
155 | m_window->GetClientSize( &m_width , &m_height); | |
156 | if ( !m_window->IsShownOnScreen() ) | |
157 | m_width = m_height = 0; | |
158 | SetDeviceOrigin( origin.x, origin.y ); | |
159 | DoSetClippingRegion( 0 , 0 , m_width , m_height ) ; | |
160 | } | |
161 | ||
162 | wxClientDCImpl::~wxClientDCImpl() | |
163 | { | |
164 | } | |
165 | ||
166 | /* | |
167 | * wxPaintDCImpl | |
168 | */ | |
169 | ||
170 | IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl, wxWindowDCImpl) | |
171 | ||
172 | wxPaintDCImpl::wxPaintDCImpl( wxDC *owner ) | |
173 | : wxWindowDCImpl( owner ) | |
174 | { | |
175 | } | |
176 | ||
177 | wxPaintDCImpl::wxPaintDCImpl( wxDC *owner, wxWindow *window ) : | |
178 | wxWindowDCImpl( owner, window ) | |
179 | { | |
9a83f860 | 180 | wxASSERT_MSG( window->MacGetCGContextRef() != NULL, wxT("using wxPaintDC without being in a native paint event") ); |
489468fe SC |
181 | wxPoint origin = window->GetClientAreaOrigin() ; |
182 | m_window->GetClientSize( &m_width , &m_height); | |
183 | SetDeviceOrigin( origin.x, origin.y ); | |
184 | DoSetClippingRegion( 0 , 0 , m_width , m_height ) ; | |
185 | } | |
186 | ||
187 | wxPaintDCImpl::~wxPaintDCImpl() | |
188 | { | |
189 | } |