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