1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/core/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
.IsOk() )
60 m_selected
.EndRawAccess() ;
61 wxDELETE(m_graphicContext
);
65 void wxMemoryDCImpl::DoSelect( const wxBitmap
& bitmap
)
67 if ( m_selected
.IsOk() )
69 m_selected
.EndRawAccess() ;
70 wxDELETE(m_graphicContext
);
74 if (m_selected
.IsOk())
76 if ( m_selected
.GetDepth() != 1 )
77 m_selected
.UseAlpha() ;
78 m_selected
.BeginRawAccess() ;
79 m_width
= bitmap
.GetScaledWidth();
80 m_height
= bitmap
.GetScaledHeight();
81 m_contentScaleFactor
= bitmap
.GetScaleFactor();
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
101 if (m_selected
.IsOk())
104 (*width
) = m_selected
.GetScaledWidth();
106 (*height
) = m_selected
.GetScaledHeight();