]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dcmemory.cpp
cleanup
[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() ;
20b69855
SC
47 delete m_graphicContext ;
48 m_graphicContext = NULL ;
20b69855 49#else
cefe5886 50// TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
20b69855 51#endif
e40298d5 52 }
cefe5886 53}
e9576ca5 54
fea35690 55void wxMemoryDC::DoSelect( const wxBitmap& bitmap )
e9576ca5 56{
e40298d5
JS
57 if ( m_selected.Ok() )
58 {
20b69855
SC
59#if wxMAC_USE_CORE_GRAPHICS
60 m_selected.EndRawAccess() ;
20b69855
SC
61 delete m_graphicContext ;
62 m_graphicContext = NULL ;
20b69855 63#else
cefe5886 64// TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
20b69855 65#endif
e40298d5 66 }
cefe5886 67
3dec57ad
SC
68 m_selected = bitmap;
69 if (m_selected.Ok())
70 {
20b69855 71#if wxMAC_USE_CORE_GRAPHICS
514fd350
SC
72 if ( m_selected.GetDepth() != 1 )
73 m_selected.UseAlpha() ;
6239ee05
SC
74 m_selected.BeginRawAccess() ;
75 m_width = bitmap.GetWidth();
76 m_height = bitmap.GetHeight();
20b69855 77 CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
6239ee05 78 CGContextRef bmCtx = (CGContextRef) m_selected.GetHBITMAP();
20b69855 79
cefe5886 80 if ( bmCtx )
20b69855 81 {
f38924e8
WS
82 CGContextSetFillColorSpace( bmCtx, genericColorSpace );
83 CGContextSetStrokeColorSpace( bmCtx, genericColorSpace );
f7862d3e 84 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) );
20b69855 85 }
cefe5886
DS
86 m_ok = (m_graphicContext != NULL) ;
87
20b69855 88#else
cefe5886
DS
89 m_macPort = m_selected.GetHBITMAP( &m_macMask ) ;
90 m_ok = (m_macPort != NULL) ;
91 if (m_ok)
e40298d5 92 {
cefe5886 93 LockPixels( GetGWorldPixMap( (CGrafPtr) m_macPort ) ) ;
e40298d5 94 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , 0 , 0 , m_selected.GetWidth() , m_selected.GetHeight() ) ;
cefe5886 95 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
e40298d5 96 }
20b69855 97#endif
e40298d5
JS
98 }
99 else
100 {
cefe5886 101 m_ok = false;
e40298d5 102 }
3dec57ad 103}
e9576ca5 104
0a67a93b 105void wxMemoryDC::DoGetSize( int *width, int *height ) const
e9576ca5 106{
e40298d5
JS
107 if (m_selected.Ok())
108 {
cefe5886
DS
109 if (width)
110 (*width) = m_selected.GetWidth();
111 if (height)
112 (*height) = m_selected.GetHeight();
e40298d5
JS
113 }
114 else
115 {
cefe5886
DS
116 if (width)
117 (*width) = 0;
118 if (height)
119 (*height) = 0;
e40298d5 120 }
3dec57ad 121}