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 delete m_graphicContext
;
48 m_graphicContext
= NULL
;
50 // TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
55 void wxMemoryDC::DoSelect( const wxBitmap
& bitmap
)
57 if ( m_selected
.Ok() )
59 #if wxMAC_USE_CORE_GRAPHICS
60 m_selected
.EndRawAccess() ;
61 delete m_graphicContext
;
62 m_graphicContext
= NULL
;
64 // TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
71 #if wxMAC_USE_CORE_GRAPHICS
72 if ( m_selected
.GetDepth() != 1 )
73 m_selected
.UseAlpha() ;
74 m_selected
.BeginRawAccess() ;
75 m_width
= bitmap
.GetWidth();
76 m_height
= bitmap
.GetHeight();
77 CGColorSpaceRef genericColorSpace
= wxMacGetGenericRGBColorSpace();
78 CGContextRef bmCtx
= (CGContextRef
) m_selected
.GetHBITMAP();
82 CGContextSetFillColorSpace( bmCtx
, genericColorSpace
);
83 CGContextSetStrokeColorSpace( bmCtx
, genericColorSpace
);
84 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx
) );
86 m_ok
= (m_graphicContext
!= NULL
) ;
89 m_macPort
= m_selected
.GetHBITMAP( &m_macMask
) ;
90 m_ok
= (m_macPort
!= NULL
) ;
93 LockPixels( GetGWorldPixMap( (CGrafPtr
) m_macPort
) ) ;
94 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, 0 , 0 , m_selected
.GetWidth() , m_selected
.GetHeight() ) ;
95 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
105 void wxMemoryDC::DoGetSize( int *width
, int *height
) const
110 (*width
) = m_selected
.GetWidth();
112 (*height
) = m_selected
.GetHeight();