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_DYNAMIC_CLASS(wxMemoryDC
,wxPaintDC
)
25 wxMemoryDC::wxMemoryDC( const wxBitmap
& bitmap
)
29 SetBackground(*wxWHITE_BRUSH
);
30 SetBrush(*wxWHITE_BRUSH
);
32 SetFont(*wxNORMAL_FONT
);
39 wxMemoryDC::wxMemoryDC( wxDC
*WXUNUSED(dc
) )
43 SetBackground(*wxWHITE_BRUSH
);
44 SetBrush(*wxWHITE_BRUSH
);
46 SetFont(*wxNORMAL_FONT
);
50 wxMemoryDC::~wxMemoryDC()
52 if ( m_selected
.Ok() )
54 #if wxMAC_USE_CORE_GRAPHICS
55 m_selected
.EndRawAccess() ;
56 CGContextRef bmCtx
= (CGContextRef
) m_graphicContext
->GetNativeContext() ;
57 delete m_graphicContext
;
58 m_graphicContext
= NULL
;
59 CGContextRelease( bmCtx
) ;
61 // TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
66 void wxMemoryDC::SelectObject( const wxBitmap
& bitmap
)
68 if ( m_selected
.Ok() )
70 #if wxMAC_USE_CORE_GRAPHICS
71 m_selected
.EndRawAccess() ;
72 CGContextRef bmCtx
= (CGContextRef
) m_graphicContext
->GetNativeContext() ;
73 delete m_graphicContext
;
74 m_graphicContext
= NULL
;
75 CGContextRelease( bmCtx
) ;
77 // TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
84 #if wxMAC_USE_CORE_GRAPHICS
85 if ( m_selected
.GetDepth() != 1 )
86 m_selected
.UseAlpha() ;
87 void * data
= m_selected
.BeginRawAccess() ;
90 int bytesPerPixel
= 4 ;
91 int w
= bitmap
.GetWidth() ;
92 int h
= bitmap
.GetHeight() ;
96 // TODO: should this be kCGImageAlphaPremultiplied[First,Last] ?
97 CGImageAlphaInfo a
= kCGImageAlphaNoneSkipFirst
;
99 CGColorSpaceRef genericColorSpace
= wxMacGetGenericRGBColorSpace();
100 CGContextRef bmCtx
= CGBitmapContextCreate( data
, w
, h
, bitsPerComp
, bytesPerPixel
* w
, genericColorSpace
, a
);
101 wxASSERT_MSG( bmCtx
, wxT("Unable to create bitmap context") ) ;
105 CGContextSetFillColorSpace( bmCtx
, genericColorSpace
);
106 CGContextSetStrokeColorSpace( bmCtx
, genericColorSpace
);
108 CGContextTranslateCTM( bmCtx
, 0 , m_selected
.GetHeight() ) ;
109 CGContextScaleCTM( bmCtx
, 1 , -1 ) ;
111 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx
) );
112 m_graphicContext
->SetPen( m_pen
) ;
113 m_graphicContext
->SetBrush( m_brush
) ;
114 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
) ;
116 m_ok
= (m_graphicContext
!= NULL
) ;
119 m_macPort
= m_selected
.GetHBITMAP( &m_macMask
) ;
120 m_ok
= (m_macPort
!= NULL
) ;
123 LockPixels( GetGWorldPixMap( (CGrafPtr
) m_macPort
) ) ;
124 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, 0 , 0 , m_selected
.GetWidth() , m_selected
.GetHeight() ) ;
125 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
135 void wxMemoryDC::DoGetSize( int *width
, int *height
) const
140 (*width
) = m_selected
.GetWidth();
142 (*height
) = m_selected
.GetHeight();