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"
16 #include "wx/osx/dcmemory.h"
18 #include "wx/osx/private.h"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl
,wxPaintDCImpl
)
27 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC
*owner
)
28 : wxPaintDCImpl( owner
)
33 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC
*owner
, wxBitmap
& bitmap
)
34 : wxPaintDCImpl( owner
)
40 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC
*owner
, wxDC
* WXUNUSED(dc
) )
41 : wxPaintDCImpl( owner
)
46 void wxMemoryDCImpl::Init()
49 SetBackground(*wxWHITE_BRUSH
);
50 SetBrush(*wxWHITE_BRUSH
);
52 SetFont(*wxNORMAL_FONT
);
56 wxMemoryDCImpl::~wxMemoryDCImpl()
58 if ( m_selected
.Ok() )
60 m_selected
.EndRawAccess() ;
61 delete m_graphicContext
;
62 m_graphicContext
= NULL
;
66 void wxMemoryDCImpl::DoSelect( const wxBitmap
& bitmap
)
68 if ( m_selected
.Ok() )
70 m_selected
.EndRawAccess() ;
71 delete m_graphicContext
;
72 m_graphicContext
= NULL
;
78 if ( m_selected
.GetDepth() != 1 )
79 m_selected
.UseAlpha() ;
80 m_selected
.BeginRawAccess() ;
81 m_width
= bitmap
.GetWidth();
82 m_height
= bitmap
.GetHeight();
83 CGColorSpaceRef genericColorSpace
= wxMacGetGenericRGBColorSpace();
84 CGContextRef bmCtx
= (CGContextRef
) m_selected
.GetHBITMAP();
88 CGContextSetFillColorSpace( bmCtx
, genericColorSpace
);
89 CGContextSetStrokeColorSpace( bmCtx
, genericColorSpace
);
90 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx
) );
92 m_ok
= (m_graphicContext
!= NULL
) ;
100 void wxMemoryDCImpl::DoGetSize( int *width
, int *height
) const
105 (*width
) = m_selected
.GetWidth();
107 (*height
) = m_selected
.GetHeight();