1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMemoryDC class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "dcmemory.h"
16 #include "wx/wxprec.h"
18 #include "wx/dcmemory.h"
19 #include "wx/mac/private.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC
,wxPaintDC
)
27 wxMemoryDC::wxMemoryDC(void)
31 SetBackground(*wxWHITE_BRUSH
);
32 SetBrush(*wxWHITE_BRUSH
);
34 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
= ((wxMacCGContext
*)(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
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
72 delete m_graphicContext
;
73 m_graphicContext
= NULL
;
74 CGContextRelease( bmCtx
) ;
76 // TODO UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
82 #if wxMAC_USE_CORE_GRAPHICS
83 m_selected
.UseAlpha() ;
84 void * data
= m_selected
.BeginRawAccess() ;
87 int bytesPerPixel
= 4 ;
88 int w
= bitmap
.GetWidth() ;
89 int h
= bitmap
.GetHeight() ;
90 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") ) ;
95 CGContextSetFillColorSpace(bmCtx
, genericColorSpace
);
96 CGContextSetStrokeColorSpace(bmCtx
, genericColorSpace
);
100 CGContextTranslateCTM( bmCtx
, 0 , m_selected
.GetHeight() ) ;
101 CGContextScaleCTM( bmCtx
, 1 , -1 ) ;
102 m_graphicContext
= new wxMacCGContext( bmCtx
) ;
103 m_graphicContext
->SetPen( m_pen
) ;
104 m_graphicContext
->SetBrush( m_brush
) ;
106 m_ok
= (m_graphicContext
!= NULL
) ;
108 if ( ( m_macPort
= m_selected
.GetHBITMAP( &m_macMask
) ) != NULL
)
110 LockPixels( GetGWorldPixMap( (CGrafPtr
) m_macPort
) ) ;
112 wxMask * mask = bitmap.GetMask() ;
115 m_macMask = mask->GetHBITMAP() ;
118 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, 0 , 0 , m_selected
.GetWidth() , m_selected
.GetHeight() ) ;
119 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
,(RgnHandle
) m_macCurrentClipRgn
) ;
134 void wxMemoryDC::DoGetSize( int *width
, int *height
) const
138 if (width
) (*width
) = m_selected
.GetWidth();
139 if (height
) (*height
) = m_selected
.GetHeight();
143 if (width
) (*width
) = 0;
144 if (height
) (*height
) = 0;