1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/osx/core/dcmemory.cpp 
   3 // Purpose:     wxMemoryDC class 
   4 // Author:      Stefan Csomor 
   7 // Copyright:   (c) Stefan Csomor 
   8 // Licence:     wxWindows licence 
   9 ///////////////////////////////////////////////////////////////////////////// 
  11 #include "wx/wxprec.h" 
  13 #include "wx/dcmemory.h" 
  14 #include "wx/graphics.h" 
  15 #include "wx/osx/dcmemory.h" 
  17 #include "wx/osx/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
.IsOk() ) 
  59         m_selected
.EndRawAccess() ; 
  60         wxDELETE(m_graphicContext
); 
  64 void wxMemoryDCImpl::DoSelect( const wxBitmap
& bitmap 
) 
  66     if ( m_selected
.IsOk() ) 
  68         m_selected
.EndRawAccess() ; 
  69         wxDELETE(m_graphicContext
); 
  73     if (m_selected
.IsOk()) 
  75         if ( m_selected
.GetDepth() != 1 ) 
  76             m_selected
.UseAlpha() ; 
  77         m_selected
.BeginRawAccess() ; 
  78         m_width 
= bitmap
.GetScaledWidth(); 
  79         m_height 
= bitmap
.GetScaledHeight(); 
  80         m_contentScaleFactor 
= bitmap
.GetScaleFactor(); 
  81         CGColorSpaceRef genericColorSpace  
= wxMacGetGenericRGBColorSpace(); 
  82         CGContextRef bmCtx 
= (CGContextRef
) m_selected
.GetHBITMAP(); 
  86             CGContextSetFillColorSpace( bmCtx
, genericColorSpace 
); 
  87             CGContextSetStrokeColorSpace( bmCtx
, genericColorSpace 
); 
  88             SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx 
) ); 
  90         m_ok 
= (m_graphicContext 
!= NULL
) ; 
  98 void wxMemoryDCImpl::DoGetSize( int *width
, int *height 
) const 
 100     if (m_selected
.IsOk()) 
 103             (*width
) = m_selected
.GetScaledWidth(); 
 105             (*height
) = m_selected
.GetScaledHeight();