1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dcmemory.cpp
3 // Purpose: wxMemoryDC class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/dcmemory.h"
16 #include "wx/mac/private.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC
,wxPaintDC
)
24 wxMemoryDC::wxMemoryDC()
28 SetBackground(*wxWHITE_BRUSH
);
29 SetBrush(*wxWHITE_BRUSH
);
31 SetFont(*wxNORMAL_FONT
);
35 wxMemoryDC::wxMemoryDC( wxDC
*WXUNUSED(dc
) )
39 SetBackground(*wxWHITE_BRUSH
);
40 SetBrush(*wxWHITE_BRUSH
);
42 SetFont(*wxNORMAL_FONT
);
46 wxMemoryDC::~wxMemoryDC()
48 if ( m_selected
.Ok() )
50 #if wxMAC_USE_CORE_GRAPHICS
51 m_selected
.EndRawAccess() ;
52 CGContextRef bmCtx
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
53 delete m_graphicContext
;
54 m_graphicContext
= NULL
;
55 CGContextRelease( bmCtx
) ;
57 // TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
62 void wxMemoryDC::SelectObject( const wxBitmap
& bitmap
)
64 if ( m_selected
.Ok() )
66 #if wxMAC_USE_CORE_GRAPHICS
67 m_selected
.EndRawAccess() ;
68 CGContextRef bmCtx
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
69 delete m_graphicContext
;
70 m_graphicContext
= NULL
;
71 CGContextRelease( bmCtx
) ;
73 // TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
80 #if wxMAC_USE_CORE_GRAPHICS
81 m_selected
.UseAlpha() ;
82 void * data
= m_selected
.BeginRawAccess() ;
85 int bytesPerPixel
= 4 ;
86 int w
= bitmap
.GetWidth() ;
87 int h
= bitmap
.GetHeight() ;
89 // TODO: should this be kCGImageAlphaPremultiplied[First,Last] ?
90 CGImageAlphaInfo a
= kCGImageAlphaNoneSkipFirst
;
92 CGColorSpaceRef genericColorSpace
= wxMacGetGenericRGBColorSpace();
93 CGContextRef bmCtx
= CGBitmapContextCreate( data
, w
, h
, bitsPerComp
, bytesPerPixel
* w
, genericColorSpace
, a
);
94 wxASSERT_MSG( bmCtx
, wxT("Unable to create bitmap context") ) ;
98 CGContextSetFillColorSpace( bmCtx
, genericColorSpace
);
99 CGContextSetStrokeColorSpace( bmCtx
, genericColorSpace
);
101 CGContextTranslateCTM( bmCtx
, 0 , m_selected
.GetHeight() ) ;
102 CGContextScaleCTM( bmCtx
, 1 , -1 ) ;
104 m_graphicContext
= new wxMacCGContext( bmCtx
) ;
105 m_graphicContext
->SetPen( m_pen
) ;
106 m_graphicContext
->SetBrush( m_brush
) ;
108 m_ok
= (m_graphicContext
!= NULL
) ;
111 m_macPort
= m_selected
.GetHBITMAP( &m_macMask
) ;
112 m_ok
= (m_macPort
!= NULL
) ;
115 LockPixels( GetGWorldPixMap( (CGrafPtr
) m_macPort
) ) ;
116 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, 0 , 0 , m_selected
.GetWidth() , m_selected
.GetHeight() ) ;
117 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
127 void wxMemoryDC::DoGetSize( int *width
, int *height
) const
132 (*width
) = m_selected
.GetWidth();
134 (*height
) = m_selected
.GetHeight();