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(void)
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())) );
78 #if wxMAC_USE_CORE_GRAPHICS
79 m_selected
.UseAlpha() ;
80 void * data
= m_selected
.BeginRawAccess() ;
83 int bytesPerPixel
= 4 ;
84 int w
= bitmap
.GetWidth() ;
85 int h
= bitmap
.GetHeight() ;
86 CGImageAlphaInfo a
= kCGImageAlphaNoneSkipFirst
;
87 CGColorSpaceRef genericColorSpace
= wxMacGetGenericRGBColorSpace();
88 CGContextRef bmCtx
= CGBitmapContextCreate(data
, w
, h
, bitsPerComp
, bytesPerPixel
* w
, genericColorSpace
, a
);
89 wxASSERT_MSG( bmCtx
, wxT("Unable to create bitmap context") ) ;
91 CGContextSetFillColorSpace(bmCtx
, genericColorSpace
);
92 CGContextSetStrokeColorSpace(bmCtx
, genericColorSpace
);
96 CGContextTranslateCTM( bmCtx
, 0 , m_selected
.GetHeight() ) ;
97 CGContextScaleCTM( bmCtx
, 1 , -1 ) ;
98 m_graphicContext
= new wxMacCGContext( bmCtx
) ;
99 m_graphicContext
->SetPen( m_pen
) ;
100 m_graphicContext
->SetBrush( m_brush
) ;
102 m_ok
= (m_graphicContext
!= NULL
) ;
104 if ( ( m_macPort
= m_selected
.GetHBITMAP( &m_macMask
) ) != NULL
)
106 LockPixels( GetGWorldPixMap( (CGrafPtr
) m_macPort
) ) ;
108 wxMask * mask = bitmap.GetMask() ;
111 m_macMask = mask->GetHBITMAP() ;
114 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, 0 , 0 , m_selected
.GetWidth() , m_selected
.GetHeight() ) ;
115 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
,(RgnHandle
) m_macCurrentClipRgn
) ;
130 void wxMemoryDC::DoGetSize( int *width
, int *height
) const
134 if (width
) (*width
) = m_selected
.GetWidth();
135 if (height
) (*height
) = m_selected
.GetHeight();
139 if (width
) (*width
) = 0;
140 if (height
) (*height
) = 0;