]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dcclient.cpp
remove pict support for 64bit
[wxWidgets.git] / src / mac / carbon / dcclient.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dcclient.cpp
3 // Purpose: wxClientDC 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"
28 #include "wx/mac/private.h"
29
30 //-----------------------------------------------------------------------------
31 // constants
32 //-----------------------------------------------------------------------------
33
34 //-----------------------------------------------------------------------------
35 // wxPaintDC
36 //-----------------------------------------------------------------------------
37
38 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
39 IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
40 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
41
42 /*
43 * wxWindowDC
44 */
45
46 #include "wx/mac/uma.h"
47 #include "wx/notebook.h"
48 #include "wx/tabctrl.h"
49
50
51
52 wxWindowDC::wxWindowDC()
53 {
54 m_window = NULL ;
55 m_release = false;
56 }
57
58 wxWindowDC::wxWindowDC(wxWindow *window)
59 {
60 m_window = window ;
61 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
62 if (!rootwindow)
63 return;
64
65 m_ok = true ;
66
67 m_window->GetSize( &m_width , &m_height);
68 CGContextRef cg = (CGContextRef) window->MacGetCGContextRef();
69 m_release = false;
70 if ( cg == NULL )
71 {
72 SetGraphicsContext( wxGraphicsContext::Create( window ) ) ;
73 }
74 else
75 {
76 CGContextSaveGState( cg );
77 m_release = true ;
78 // make sure the context is having its origin at the wx-window coordinates of the
79 // view (read at the top of window.cpp about the differences)
80 if ( window->MacGetLeftBorderSize() != 0 || window->MacGetTopBorderSize() != 0 )
81 CGContextTranslateCTM( cg , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() );
82
83 SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) );
84 }
85 SetClippingRegion( 0 , 0 , m_width , m_height ) ;
86
87 SetBackground(wxBrush(window->GetBackgroundColour(),wxSOLID));
88
89 SetFont( window->GetFont() ) ;
90 }
91
92 wxWindowDC::~wxWindowDC()
93 {
94 if ( m_release )
95 {
96 // this must not necessarily be the current context, we must restore the state of the
97 // cg we started with above (before the CGContextTranslateCTM call)
98 CGContextRef cg = (CGContextRef) m_window->MacGetCGContextRef();
99 CGContextRestoreGState(cg);
100 }
101 }
102
103 void wxWindowDC::DoGetSize( int* width, int* height ) const
104 {
105 if ( width )
106 *width = m_width;
107 if ( height )
108 *height = m_height;
109 }
110
111 wxBitmap wxWindowDC::DoGetAsBitmap(const wxRect *subrect) const
112 {
113 // wxScreenDC is derived from wxWindowDC, so a screen dc will
114 // call this method when a Blit is performed with it as a source.
115 if (!m_window)
116 return wxNullBitmap;
117
118 ControlRef handle = (ControlRef) m_window->GetHandle();
119 if ( !handle )
120 return wxNullBitmap;
121
122 HIRect rect;
123 CGImageRef image;
124 CGContextRef context;
125 void* data;
126
127 size_t bytesPerRow;
128
129 HIViewCreateOffscreenImage( handle, 0, &rect, &image);
130
131
132 int width = subrect != NULL ? subrect->width : (int)rect.size.width;
133 int height = subrect != NULL ? subrect->height : (int)rect.size.height ;
134
135 bytesPerRow = ( ( width * 8 * 4 + 7 ) / 8 );
136
137 data = calloc( 1, bytesPerRow * height );
138 context = CGBitmapContextCreate( data, width, height, 8, bytesPerRow, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedFirst );
139
140 if ( subrect )
141 rect = CGRectOffset( rect, -subrect->x, -subrect->y ) ;
142 CGContextDrawImage( context, rect, image );
143
144 unsigned char* buffer = (unsigned char*) data;
145 wxBitmap bmp = wxBitmap(width, height, 32);
146 wxAlphaPixelData pixData(bmp, wxPoint(0,0), wxSize(width, height));
147
148 wxAlphaPixelData::Iterator p(pixData);
149 for (int y=0; y<height; y++) {
150 wxAlphaPixelData::Iterator rowStart = p;
151 for (int x=0; x<width; x++) {
152 unsigned char a = buffer[3];
153 p.Red() = a; buffer++;
154 p.Green() = a; buffer++;
155 p.Blue() = a; buffer++;
156 p.Alpha() = a; buffer++;
157 ++p;
158 }
159 p = rowStart;
160 p.OffsetY(pixData, 1);
161 }
162
163 return bmp;
164 }
165
166 /*
167 * wxClientDC
168 */
169
170 wxClientDC::wxClientDC()
171 {
172 m_window = NULL ;
173 }
174
175 wxClientDC::wxClientDC(wxWindow *window) :
176 wxWindowDC( window )
177 {
178 wxCHECK_RET( window, _T("invalid window in wxClientDC") );
179 wxPoint origin = window->GetClientAreaOrigin() ;
180 m_window->GetClientSize( &m_width , &m_height);
181 SetDeviceOrigin( origin.x, origin.y );
182 SetClippingRegion( 0 , 0 , m_width , m_height ) ;
183 }
184
185 wxClientDC::~wxClientDC()
186 {
187 }
188
189 /*
190 * wxPaintDC
191 */
192
193 wxPaintDC::wxPaintDC()
194 {
195 m_window = NULL ;
196 }
197
198 wxPaintDC::wxPaintDC(wxWindow *window) :
199 wxWindowDC( window )
200 {
201 wxPoint origin = window->GetClientAreaOrigin() ;
202 m_window->GetClientSize( &m_width , &m_height);
203 SetDeviceOrigin( origin.x, origin.y );
204 SetClippingRegion( 0 , 0 , m_width , m_height ) ;
205 }
206
207 wxPaintDC::~wxPaintDC()
208 {
209 }