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"
16 #include "wx/mac/private.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC
,wxPaintDC
)
24 wxMemoryDC::wxMemoryDC( const wxBitmap
& bitmap
)
28 SetBackground(*wxWHITE_BRUSH
);
29 SetBrush(*wxWHITE_BRUSH
);
31 SetFont(*wxNORMAL_FONT
);
38 wxMemoryDC::wxMemoryDC( wxDC
*WXUNUSED(dc
) )
42 SetBackground(*wxWHITE_BRUSH
);
43 SetBrush(*wxWHITE_BRUSH
);
45 SetFont(*wxNORMAL_FONT
);
49 wxMemoryDC::~wxMemoryDC()
51 if ( m_selected
.Ok() )
53 #if wxMAC_USE_CORE_GRAPHICS
54 m_selected
.EndRawAccess() ;
55 CGContextRef bmCtx
= (CGContextRef
) m_graphicContext
->GetNativeContext() ;
56 delete m_graphicContext
;
57 m_graphicContext
= NULL
;
58 CGContextRelease( bmCtx
) ;
60 // TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
65 void wxMemoryDC::SelectObject( const wxBitmap
& bitmap
)
67 if ( m_selected
.Ok() )
69 #if wxMAC_USE_CORE_GRAPHICS
70 m_selected
.EndRawAccess() ;
71 CGContextRef bmCtx
= (CGContextRef
) m_graphicContext
->GetNativeContext() ;
72 delete m_graphicContext
;
73 m_graphicContext
= NULL
;
74 CGContextRelease( bmCtx
) ;
76 // TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
83 #if wxMAC_USE_CORE_GRAPHICS
84 if ( m_selected
.GetDepth() != 1 )
85 m_selected
.UseAlpha() ;
86 void * data
= m_selected
.BeginRawAccess() ;
89 int bytesPerPixel
= 4 ;
90 int w
= bitmap
.GetWidth() ;
91 int h
= bitmap
.GetHeight() ;
95 // TODO: should this be kCGImageAlphaPremultiplied[First,Last] ?
96 CGImageAlphaInfo a
= kCGImageAlphaNoneSkipFirst
;
98 CGColorSpaceRef genericColorSpace
= wxMacGetGenericRGBColorSpace();
99 CGContextRef bmCtx
= CGBitmapContextCreate( data
, w
, h
, bitsPerComp
, bytesPerPixel
* w
, genericColorSpace
, a
);
100 wxASSERT_MSG( bmCtx
, wxT("Unable to create bitmap context") ) ;
104 CGContextSetFillColorSpace( bmCtx
, genericColorSpace
);
105 CGContextSetStrokeColorSpace( bmCtx
, genericColorSpace
);
107 CGContextTranslateCTM( bmCtx
, 0 , m_selected
.GetHeight() ) ;
108 CGContextScaleCTM( bmCtx
, 1 , -1 ) ;
110 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx
) );
111 m_graphicContext
->SetPen( m_pen
) ;
112 m_graphicContext
->SetBrush( m_brush
) ;
113 m_graphicContext
->SetFont( m_font
) ;
115 m_ok
= (m_graphicContext
!= NULL
) ;
118 m_macPort
= m_selected
.GetHBITMAP( &m_macMask
) ;
119 m_ok
= (m_macPort
!= NULL
) ;
122 LockPixels( GetGWorldPixMap( (CGrafPtr
) m_macPort
) ) ;
123 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, 0 , 0 , m_selected
.GetWidth() , m_selected
.GetHeight() ) ;
124 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
134 void wxMemoryDC::DoGetSize( int *width
, int *height
) const
139 (*width
) = m_selected
.GetWidth();
141 (*height
) = m_selected
.GetHeight();