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"
15 #include "wx/graphics.h"
17 #include "wx/mac/private.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC
,wxPaintDC
)
25 void wxMemoryDC::Init()
28 SetBackground(*wxWHITE_BRUSH
);
29 SetBrush(*wxWHITE_BRUSH
);
31 SetFont(*wxNORMAL_FONT
);
35 wxMemoryDC::wxMemoryDC( wxDC
*WXUNUSED(dc
) )
41 wxMemoryDC::~wxMemoryDC()
43 if ( m_selected
.Ok() )
45 #if wxMAC_USE_CORE_GRAPHICS
46 m_selected
.EndRawAccess() ;
47 CGContextRef bmCtx
= (CGContextRef
) m_graphicContext
->GetNativeContext() ;
48 delete m_graphicContext
;
49 m_graphicContext
= NULL
;
50 CGContextRelease( bmCtx
) ;
52 // TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
57 void wxMemoryDC::DoSelect( const wxBitmap
& bitmap
)
59 if ( m_selected
.Ok() )
61 #if wxMAC_USE_CORE_GRAPHICS
62 m_selected
.EndRawAccess() ;
63 CGContextRef bmCtx
= (CGContextRef
) m_graphicContext
->GetNativeContext() ;
64 delete m_graphicContext
;
65 m_graphicContext
= NULL
;
66 CGContextRelease( bmCtx
) ;
68 // TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
75 #if wxMAC_USE_CORE_GRAPHICS
76 if ( m_selected
.GetDepth() != 1 )
77 m_selected
.UseAlpha() ;
78 void * data
= m_selected
.BeginRawAccess() ;
81 int bytesPerPixel
= 4 ;
82 int w
= bitmap
.GetWidth() ;
83 int h
= bitmap
.GetHeight() ;
87 // TODO: should this be kCGImageAlphaPremultiplied[First,Last] ?
88 CGImageAlphaInfo a
= kCGImageAlphaNoneSkipFirst
;
90 CGColorSpaceRef genericColorSpace
= wxMacGetGenericRGBColorSpace();
91 CGContextRef bmCtx
= CGBitmapContextCreate( data
, w
, h
, bitsPerComp
, bytesPerPixel
* w
, genericColorSpace
, a
);
92 wxASSERT_MSG( bmCtx
, wxT("Unable to create bitmap context") ) ;
96 CGContextSetFillColorSpace( bmCtx
, genericColorSpace
);
97 CGContextSetStrokeColorSpace( bmCtx
, genericColorSpace
);
99 CGContextTranslateCTM( bmCtx
, 0 , m_selected
.GetHeight() ) ;
100 CGContextScaleCTM( bmCtx
, 1 , -1 ) ;
102 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx
) );
104 m_ok
= (m_graphicContext
!= NULL
) ;
107 m_macPort
= m_selected
.GetHBITMAP( &m_macMask
) ;
108 m_ok
= (m_macPort
!= NULL
) ;
111 LockPixels( GetGWorldPixMap( (CGrafPtr
) m_macPort
) ) ;
112 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, 0 , 0 , m_selected
.GetWidth() , m_selected
.GetHeight() ) ;
113 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
123 void wxMemoryDC::DoGetSize( int *width
, int *height
) const
128 (*width
) = m_selected
.GetWidth();
130 (*height
) = m_selected
.GetHeight();