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 m_selected
.EndRawAccess() ;
46 delete m_graphicContext
;
47 m_graphicContext
= NULL
;
51 void wxMemoryDC::DoSelect( const wxBitmap
& bitmap
)
53 if ( m_selected
.Ok() )
55 m_selected
.EndRawAccess() ;
56 delete m_graphicContext
;
57 m_graphicContext
= NULL
;
63 if ( m_selected
.GetDepth() != 1 )
64 m_selected
.UseAlpha() ;
65 m_selected
.BeginRawAccess() ;
66 m_width
= bitmap
.GetWidth();
67 m_height
= bitmap
.GetHeight();
68 CGColorSpaceRef genericColorSpace
= wxMacGetGenericRGBColorSpace();
69 CGContextRef bmCtx
= (CGContextRef
) m_selected
.GetHBITMAP();
73 CGContextSetFillColorSpace( bmCtx
, genericColorSpace
);
74 CGContextSetStrokeColorSpace( bmCtx
, genericColorSpace
);
75 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx
) );
77 m_ok
= (m_graphicContext
!= NULL
) ;
85 void wxMemoryDC::DoGetSize( int *width
, int *height
) const
90 (*width
) = m_selected
.GetWidth();
92 (*height
) = m_selected
.GetHeight();