1 /////////////////////////////////////////////////////////////////////////////
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/mac/private.h"
17 //-----------------------------------------------------------------------------
19 //-----------------------------------------------------------------------------
21 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC
,wxPaintDC
)
23 wxMemoryDC::wxMemoryDC()
27 SetBackground(*wxWHITE_BRUSH
);
28 SetBrush(*wxWHITE_BRUSH
);
30 SetFont(*wxNORMAL_FONT
);
34 wxMemoryDC::wxMemoryDC( wxDC
*WXUNUSED(dc
) )
38 SetBackground(*wxWHITE_BRUSH
);
39 SetBrush(*wxWHITE_BRUSH
);
41 SetFont(*wxNORMAL_FONT
);
45 wxMemoryDC::~wxMemoryDC()
47 if ( m_selected
.Ok() )
49 #if wxMAC_USE_CORE_GRAPHICS
50 m_selected
.EndRawAccess() ;
51 CGContextRef bmCtx
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
52 delete m_graphicContext
;
53 m_graphicContext
= NULL
;
54 CGContextRelease( bmCtx
) ;
56 // TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
61 void wxMemoryDC::SelectObject( const wxBitmap
& bitmap
)
63 if ( m_selected
.Ok() )
65 #if wxMAC_USE_CORE_GRAPHICS
66 m_selected
.EndRawAccess() ;
67 CGContextRef bmCtx
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
68 delete m_graphicContext
;
69 m_graphicContext
= NULL
;
70 CGContextRelease( bmCtx
) ;
72 // TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
79 #if wxMAC_USE_CORE_GRAPHICS
80 m_selected
.UseAlpha() ;
81 void * data
= m_selected
.BeginRawAccess() ;
84 int bytesPerPixel
= 4 ;
85 int w
= bitmap
.GetWidth() ;
86 int h
= bitmap
.GetHeight() ;
88 // TODO: should this be kCGImageAlphaPremultiplied[First,Last] ?
89 CGImageAlphaInfo a
= kCGImageAlphaNoneSkipFirst
;
91 CGColorSpaceRef genericColorSpace
= wxMacGetGenericRGBColorSpace();
92 CGContextRef bmCtx
= CGBitmapContextCreate( data
, w
, h
, bitsPerComp
, bytesPerPixel
* w
, genericColorSpace
, a
);
93 wxASSERT_MSG( bmCtx
, wxT("Unable to create bitmap context") ) ;
97 CGContextSetFillColorSpace( bmCtx
, genericColorSpace
);
98 CGContextSetStrokeColorSpace( bmCtx
, genericColorSpace
);
100 CGContextTranslateCTM( bmCtx
, 0 , m_selected
.GetHeight() ) ;
101 CGContextScaleCTM( bmCtx
, 1 , -1 ) ;
103 m_graphicContext
= new wxMacCGContext( bmCtx
) ;
104 m_graphicContext
->SetPen( m_pen
) ;
105 m_graphicContext
->SetBrush( m_brush
) ;
107 m_ok
= (m_graphicContext
!= NULL
) ;
110 m_macPort
= m_selected
.GetHBITMAP( &m_macMask
) ;
111 m_ok
= (m_macPort
!= NULL
) ;
114 LockPixels( GetGWorldPixMap( (CGrafPtr
) m_macPort
) ) ;
115 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, 0 , 0 , m_selected
.GetWidth() , m_selected
.GetHeight() ) ;
116 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
126 void wxMemoryDC::DoGetSize( int *width
, int *height
) const
131 (*width
) = m_selected
.GetWidth();
133 (*height
) = m_selected
.GetHeight();