fixing file paths after renaming
[wxWidgets.git] / src / osx / carbon / dcclient.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dcclient.cpp
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"
28 #include "wx/osx/private.h"
29
30 //-----------------------------------------------------------------------------
31 // wxWindowDCImpl
32 //-----------------------------------------------------------------------------
33
34 IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl, wxGCDCImpl)
35
36 wxWindowDCImpl::wxWindowDCImpl( wxDC *owner )
37 : wxGCDCImpl( owner )
38 {
39 m_release = false;
40 }
41
42 wxWindowDCImpl::wxWindowDCImpl( wxDC *owner, wxWindow *window )
43 : wxGCDCImpl( owner )
44 {
45 m_window = window;
46
47 WindowRef rootwindow = (WindowRef) window->MacGetTopLevelWindowRef() ;
48 if (!rootwindow)
49 return;
50
51 m_ok = true ;
52
53 m_window->GetSize( &m_width , &m_height);
54 if ( !m_window->IsShownOnScreen() )
55 m_width = m_height = 0;
56 CGContextRef cg = (CGContextRef) window->MacGetCGContextRef();
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
99 wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
100 {
101 // wxScreenDC is derived from wxWindowDC, so a screen dc will
102 // call this method when a Blit is performed with it as a source.
103 if (!m_window)
104 return wxNullBitmap;
105
106 #ifdef __LP64__
107 return wxNullBitmap;
108 #else
109 ControlRef handle = (ControlRef) m_window->GetHandle();
110 if ( !handle )
111 return wxNullBitmap;
112
113 HIRect rect;
114 CGImageRef image;
115 CGContextRef context;
116 void* data;
117
118 size_t bytesPerRow;
119
120 HIViewCreateOffscreenImage( handle, 0, &rect, &image);
121
122
123 int width = subrect != NULL ? subrect->width : (int)rect.size.width;
124 int height = subrect != NULL ? subrect->height : (int)rect.size.height ;
125
126 wxBitmap bmp = wxBitmap(width, height, 32);
127
128 context = (CGContextRef)bmp.GetHBITMAP();
129
130 CGContextSaveGState(context);
131
132 CGContextTranslateCTM( context, 0, height );
133 CGContextScaleCTM( context, 1, -1 );
134
135 if ( subrect )
136 rect = CGRectOffset( rect, -subrect->x, -subrect->y ) ;
137 CGContextDrawImage( context, rect, image );
138
139 CGContextRestoreGState(context);
140
141 return bmp;
142 #endif
143 }
144
145 /*
146 * wxClientDCImpl
147 */
148
149 IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl, wxWindowDCImpl)
150
151 wxClientDCImpl::wxClientDCImpl( wxDC *owner )
152 : wxWindowDCImpl( owner )
153 {
154 }
155
156 wxClientDCImpl::wxClientDCImpl( wxDC *owner, wxWindow *window ) :
157 wxWindowDCImpl( owner, window )
158 {
159 wxCHECK_RET( window, _T("invalid window in wxClientDCImpl") );
160 wxPoint origin = window->GetClientAreaOrigin() ;
161 m_window->GetClientSize( &m_width , &m_height);
162 if ( !m_window->IsShownOnScreen() )
163 m_width = m_height = 0;
164 SetDeviceOrigin( origin.x, origin.y );
165 DoSetClippingRegion( 0 , 0 , m_width , m_height ) ;
166 }
167
168 wxClientDCImpl::~wxClientDCImpl()
169 {
170 }
171
172 /*
173 * wxPaintDCImpl
174 */
175
176 IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl, wxWindowDCImpl)
177
178 wxPaintDCImpl::wxPaintDCImpl( wxDC *owner )
179 : wxWindowDCImpl( owner )
180 {
181 }
182
183 wxPaintDCImpl::wxPaintDCImpl( wxDC *owner, wxWindow *window ) :
184 wxWindowDCImpl( owner, window )
185 {
186 wxPoint origin = window->GetClientAreaOrigin() ;
187 m_window->GetClientSize( &m_width , &m_height);
188 SetDeviceOrigin( origin.x, origin.y );
189 DoSetClippingRegion( 0 , 0 , m_width , m_height ) ;
190 }
191
192 wxPaintDCImpl::~wxPaintDCImpl()
193 {
194 }