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_ABSTRACT_CLASS(wxMemoryDCImpl
,wxPaintDCImpl
)
26 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC
*owner
)
27 : wxPaintDCImpl( owner
)
32 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC
*owner
, wxBitmap
& bitmap
)
33 : wxPaintDCImpl( owner
)
39 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC
*owner
, wxDC
* WXUNUSED(dc
) )
40 : wxPaintDCImpl( owner
)
45 void wxMemoryDCImpl::Init()
48 SetBackground(*wxWHITE_BRUSH
);
49 SetBrush(*wxWHITE_BRUSH
);
51 SetFont(*wxNORMAL_FONT
);
55 wxMemoryDCImpl::~wxMemoryDCImpl()
57 if ( m_selected
.Ok() )
59 m_selected
.EndRawAccess() ;
60 delete m_graphicContext
;
61 m_graphicContext
= NULL
;
65 void wxMemoryDCImpl::DoSelect( const wxBitmap
& bitmap
)
67 if ( m_selected
.Ok() )
69 m_selected
.EndRawAccess() ;
70 delete m_graphicContext
;
71 m_graphicContext
= NULL
;
77 if ( m_selected
.GetDepth() != 1 )
78 m_selected
.UseAlpha() ;
79 m_selected
.BeginRawAccess() ;
80 m_width
= bitmap
.GetWidth();
81 m_height
= bitmap
.GetHeight();
82 CGColorSpaceRef genericColorSpace
= wxMacGetGenericRGBColorSpace();
83 CGContextRef bmCtx
= (CGContextRef
) m_selected
.GetHBITMAP();
87 CGContextSetFillColorSpace( bmCtx
, genericColorSpace
);
88 CGContextSetStrokeColorSpace( bmCtx
, genericColorSpace
);
89 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx
) );
91 m_ok
= (m_graphicContext
!= NULL
) ;
99 void wxMemoryDCImpl::DoGetSize( int *width
, int *height
) const
104 (*width
) = m_selected
.GetWidth();
106 (*height
) = m_selected
.GetHeight();