]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dcmemory.cpp
wxPalmOS build fix.
[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
SC
12#include "wx/wxprec.h"
13
e9576ca5 14#include "wx/dcmemory.h"
76a5e5d2 15#include "wx/mac/private.h"
e9576ca5
SC
16
17//-----------------------------------------------------------------------------
18// wxMemoryDC
19//-----------------------------------------------------------------------------
20
21IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxPaintDC)
22
cefe5886 23wxMemoryDC::wxMemoryDC()
e40298d5 24: m_selected()
e9576ca5 25{
cefe5886 26 m_ok = true;
0a67a93b
SC
27 SetBackground(*wxWHITE_BRUSH);
28 SetBrush(*wxWHITE_BRUSH);
29 SetPen(*wxBLACK_PEN);
cefe5886
DS
30 SetFont(*wxNORMAL_FONT);
31 m_ok = false;
32}
e9576ca5
SC
33
34wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
e40298d5 35: m_selected()
e9576ca5 36{
cefe5886 37 m_ok = true;
0a67a93b
SC
38 SetBackground(*wxWHITE_BRUSH);
39 SetBrush(*wxWHITE_BRUSH);
40 SetPen(*wxBLACK_PEN);
cefe5886
DS
41 SetFont(*wxNORMAL_FONT);
42 m_ok = false;
43}
e9576ca5 44
3dec57ad 45wxMemoryDC::~wxMemoryDC()
e9576ca5 46{
e40298d5
JS
47 if ( m_selected.Ok() )
48 {
20b69855
SC
49#if wxMAC_USE_CORE_GRAPHICS
50 m_selected.EndRawAccess() ;
626fd619 51 CGContextRef bmCtx = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
20b69855
SC
52 delete m_graphicContext ;
53 m_graphicContext = NULL ;
54 CGContextRelease( bmCtx ) ;
55#else
cefe5886 56// TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
20b69855 57#endif
e40298d5 58 }
cefe5886 59}
e9576ca5
SC
60
61void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
62{
e40298d5
JS
63 if ( m_selected.Ok() )
64 {
20b69855
SC
65#if wxMAC_USE_CORE_GRAPHICS
66 m_selected.EndRawAccess() ;
626fd619 67 CGContextRef bmCtx = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
20b69855
SC
68 delete m_graphicContext ;
69 m_graphicContext = NULL ;
70 CGContextRelease( bmCtx ) ;
71#else
cefe5886 72// TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
20b69855 73#endif
e40298d5 74 }
cefe5886 75
3dec57ad
SC
76 m_selected = bitmap;
77 if (m_selected.Ok())
78 {
20b69855
SC
79#if wxMAC_USE_CORE_GRAPHICS
80 m_selected.UseAlpha() ;
81 void * data = m_selected.BeginRawAccess() ;
82
83 int bitsPerComp = 8 ;
84 int bytesPerPixel = 4 ;
85 int w = bitmap.GetWidth() ;
86 int h = bitmap.GetHeight() ;
cefe5886
DS
87
88 // TODO: should this be kCGImageAlphaPremultiplied[First,Last] ?
20b69855 89 CGImageAlphaInfo a = kCGImageAlphaNoneSkipFirst ;
cefe5886 90
20b69855 91 CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
cefe5886 92 CGContextRef bmCtx = CGBitmapContextCreate( data , w, h, bitsPerComp , bytesPerPixel * w , genericColorSpace, a );
20b69855
SC
93 wxASSERT_MSG( bmCtx , wxT("Unable to create bitmap context") ) ;
94
cefe5886 95 if ( bmCtx )
20b69855 96 {
cefe5886
DS
97 CGContextSetFillColorSpace( bmCtx, genericColorSpace );
98 CGContextSetStrokeColorSpace( bmCtx, genericColorSpace );
99
20b69855
SC
100 CGContextTranslateCTM( bmCtx , 0 , m_selected.GetHeight() ) ;
101 CGContextScaleCTM( bmCtx , 1 , -1 ) ;
cefe5886 102
20b69855
SC
103 m_graphicContext = new wxMacCGContext( bmCtx ) ;
104 m_graphicContext->SetPen( m_pen ) ;
105 m_graphicContext->SetBrush( m_brush ) ;
106 }
cefe5886
DS
107 m_ok = (m_graphicContext != NULL) ;
108
20b69855 109#else
cefe5886
DS
110 m_macPort = m_selected.GetHBITMAP( &m_macMask ) ;
111 m_ok = (m_macPort != NULL) ;
112 if (m_ok)
e40298d5 113 {
cefe5886 114 LockPixels( GetGWorldPixMap( (CGrafPtr) m_macPort ) ) ;
e40298d5 115 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , 0 , 0 , m_selected.GetWidth() , m_selected.GetHeight() ) ;
cefe5886 116 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
e40298d5 117 }
20b69855 118#endif
e40298d5
JS
119 }
120 else
121 {
cefe5886 122 m_ok = false;
e40298d5 123 }
3dec57ad 124}
e9576ca5 125
0a67a93b 126void wxMemoryDC::DoGetSize( int *width, int *height ) const
e9576ca5 127{
e40298d5
JS
128 if (m_selected.Ok())
129 {
cefe5886
DS
130 if (width)
131 (*width) = m_selected.GetWidth();
132 if (height)
133 (*height) = m_selected.GetHeight();
e40298d5
JS
134 }
135 else
136 {
cefe5886
DS
137 if (width)
138 (*width) = 0;
139 if (height)
140 (*height) = 0;
e40298d5 141 }
3dec57ad 142}