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