]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/dcclient.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/dcclient.cpp
3 // Purpose: wxClientDCImpl class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/dcclient.h"
18 #include "wx/window.h"
19 #include "wx/dcmemory.h"
20 #include "wx/settings.h"
21 #include "wx/toplevel.h"
23 #include "wx/region.h"
26 #include "wx/graphics.h"
27 #include "wx/rawbmp.h"
28 #include "wx/osx/private.h"
29 #include "wx/osx/dcclient.h"
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl
, wxGCDCImpl
)
37 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
)
44 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
, wxWindow
*window
)
51 m_window
->GetSize( &m_width
, &m_height
);
52 if ( !m_window
->IsShownOnScreen() )
53 m_width
= m_height
= 0;
55 CGContextRef cg
= (CGContextRef
) window
->MacGetCGContextRef();
60 SetGraphicsContext( wxGraphicsContext::Create( window
) ) ;
64 CGContextSaveGState( cg
);
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() );
71 SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg
) );
73 DoSetClippingRegion( 0 , 0 , m_width
, m_height
) ;
75 SetBackground(wxBrush(window
->GetBackgroundColour(),wxSOLID
));
77 SetFont( window
->GetFont() ) ;
80 wxWindowDCImpl::~wxWindowDCImpl()
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
);
91 void wxWindowDCImpl::DoGetSize( int* width
, int* height
) const
100 wxBitmap
wxWindowDCImpl::DoGetAsBitmap(const wxRect
*subrect
) const
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.
107 ControlRef handle
= (ControlRef
) m_window
->GetHandle();
113 CGContextRef context
;
115 HIViewCreateOffscreenImage( handle
, 0, &rect
, &image
);
118 int width
= subrect
!= NULL
? subrect
->width
: (int)rect
.size
.width
;
119 int height
= subrect
!= NULL
? subrect
->height
: (int)rect
.size
.height
;
121 wxBitmap bmp
= wxBitmap(width
, height
, 32);
123 context
= (CGContextRef
)bmp
.GetHBITMAP();
125 CGContextSaveGState(context
);
127 CGContextTranslateCTM( context
, 0, height
);
128 CGContextScaleCTM( context
, 1, -1 );
131 rect
= CGRectOffset( rect
, -subrect
->x
, -subrect
->y
) ;
132 CGContextDrawImage( context
, rect
, image
);
134 CGContextRestoreGState(context
);
143 IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl
, wxWindowDCImpl
)
145 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
)
146 : wxWindowDCImpl( owner
)
150 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
, wxWindow
*window
) :
151 wxWindowDCImpl( owner
, window
)
153 wxCHECK_RET( window
, _T("invalid window in wxClientDCImpl") );
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
) ;
162 wxClientDCImpl::~wxClientDCImpl()
170 IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl
, wxWindowDCImpl
)
172 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
)
173 : wxWindowDCImpl( owner
)
177 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
, wxWindow
*window
) :
178 wxWindowDCImpl( owner
, window
)
180 wxASSERT_MSG( window
->MacGetCGContextRef() != NULL
, _T("using wxPaintDC without being in a native paint event") );
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
) ;
187 wxPaintDCImpl::~wxPaintDCImpl()