]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dcmemory.cpp
Use empty check consistent with other parts.
[wxWidgets.git] / src / mac / carbon / dcmemory.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: dcmemory.cpp
3// Purpose: wxMemoryDC class
a31a5f85 4// Author: Stefan Csomor
e9576ca5
SC
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "dcmemory.h"
14#endif
15
3d1a4878
SC
16#include "wx/wxprec.h"
17
e9576ca5 18#include "wx/dcmemory.h"
76a5e5d2 19#include "wx/mac/private.h"
e9576ca5
SC
20
21//-----------------------------------------------------------------------------
22// wxMemoryDC
23//-----------------------------------------------------------------------------
24
25IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxPaintDC)
26
27wxMemoryDC::wxMemoryDC(void)
e40298d5 28: m_selected()
e9576ca5 29{
e40298d5 30 m_ok = TRUE;
0a67a93b
SC
31 SetBackground(*wxWHITE_BRUSH);
32 SetBrush(*wxWHITE_BRUSH);
33 SetPen(*wxBLACK_PEN);
20b69855 34 SetFont(*wxNORMAL_FONT) ;
e40298d5 35 m_ok = FALSE;
e9576ca5
SC
36};
37
38wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
e40298d5 39: m_selected()
e9576ca5 40{
e40298d5 41 m_ok = TRUE;
0a67a93b
SC
42 SetBackground(*wxWHITE_BRUSH);
43 SetBrush(*wxWHITE_BRUSH);
44 SetPen(*wxBLACK_PEN);
20b69855 45 SetFont(*wxNORMAL_FONT) ;
e40298d5 46 m_ok = FALSE;
e9576ca5
SC
47};
48
3dec57ad 49wxMemoryDC::~wxMemoryDC()
e9576ca5 50{
e40298d5
JS
51 if ( m_selected.Ok() )
52 {
20b69855
SC
53#if wxMAC_USE_CORE_GRAPHICS
54 m_selected.EndRawAccess() ;
626fd619 55 CGContextRef bmCtx = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
20b69855
SC
56 delete m_graphicContext ;
57 m_graphicContext = NULL ;
58 CGContextRelease( bmCtx ) ;
59#else
60// TODO UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
61#endif
e40298d5 62 }
e9576ca5
SC
63};
64
65void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
66{
e40298d5
JS
67 if ( m_selected.Ok() )
68 {
20b69855
SC
69#if wxMAC_USE_CORE_GRAPHICS
70 m_selected.EndRawAccess() ;
626fd619 71 CGContextRef bmCtx = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
20b69855
SC
72 delete m_graphicContext ;
73 m_graphicContext = NULL ;
74 CGContextRelease( bmCtx ) ;
75#else
76// TODO UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
77#endif
e40298d5 78 }
3dec57ad
SC
79 m_selected = bitmap;
80 if (m_selected.Ok())
81 {
20b69855
SC
82#if wxMAC_USE_CORE_GRAPHICS
83 m_selected.UseAlpha() ;
84 void * data = m_selected.BeginRawAccess() ;
85
86 int bitsPerComp = 8 ;
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") ) ;
94
95 CGContextSetFillColorSpace(bmCtx, genericColorSpace);
96 CGContextSetStrokeColorSpace(bmCtx, genericColorSpace);
97
98 if( bmCtx )
99 {
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 ) ;
105 }
106 m_ok = (m_graphicContext != NULL) ;
107#else
108 if ( ( m_macPort = m_selected.GetHBITMAP( &m_macMask ) ) != NULL )
e40298d5 109 {
e40298d5 110 LockPixels( GetGWorldPixMap( (CGrafPtr) m_macPort ) ) ;
20b69855 111 /*
e40298d5
JS
112 wxMask * mask = bitmap.GetMask() ;
113 if ( mask )
114 {
20b69855 115 m_macMask = mask->GetHBITMAP() ;
e40298d5 116 }
20b69855 117 */
e40298d5
JS
118 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , 0 , 0 , m_selected.GetWidth() , m_selected.GetHeight() ) ;
119 CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ;
120 m_ok = TRUE ;
121 }
122 else
123 {
124 m_ok = FALSE;
125 }
20b69855 126#endif
e40298d5
JS
127 }
128 else
129 {
130 m_ok = FALSE;
131 }
3dec57ad 132}
e9576ca5 133
0a67a93b 134void wxMemoryDC::DoGetSize( int *width, int *height ) const
e9576ca5 135{
e40298d5
JS
136 if (m_selected.Ok())
137 {
138 if (width) (*width) = m_selected.GetWidth();
139 if (height) (*height) = m_selected.GetHeight();
140 }
141 else
142 {
143 if (width) (*width) = 0;
144 if (height) (*height) = 0;
145 }
3dec57ad 146}
e9576ca5
SC
147
148