]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dcmemory.cpp
cleanup
[wxWidgets.git] / src / mac / carbon / dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dcmemory.cpp
3 // Purpose: wxMemoryDC class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/dcmemory.h"
15 #include "wx/graphics.h"
16
17 #include "wx/mac/private.h"
18
19 //-----------------------------------------------------------------------------
20 // wxMemoryDC
21 //-----------------------------------------------------------------------------
22
23 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxPaintDC)
24
25 void wxMemoryDC::Init()
26 {
27 m_ok = true;
28 SetBackground(*wxWHITE_BRUSH);
29 SetBrush(*wxWHITE_BRUSH);
30 SetPen(*wxBLACK_PEN);
31 SetFont(*wxNORMAL_FONT);
32 m_ok = false;
33 }
34
35 wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
36 : m_selected()
37 {
38 Init();
39 }
40
41 wxMemoryDC::~wxMemoryDC()
42 {
43 if ( m_selected.Ok() )
44 {
45 #if wxMAC_USE_CORE_GRAPHICS
46 m_selected.EndRawAccess() ;
47 delete m_graphicContext ;
48 m_graphicContext = NULL ;
49 #else
50 // TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
51 #endif
52 }
53 }
54
55 void wxMemoryDC::DoSelect( const wxBitmap& bitmap )
56 {
57 if ( m_selected.Ok() )
58 {
59 #if wxMAC_USE_CORE_GRAPHICS
60 m_selected.EndRawAccess() ;
61 delete m_graphicContext ;
62 m_graphicContext = NULL ;
63 #else
64 // TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
65 #endif
66 }
67
68 m_selected = bitmap;
69 if (m_selected.Ok())
70 {
71 #if wxMAC_USE_CORE_GRAPHICS
72 if ( m_selected.GetDepth() != 1 )
73 m_selected.UseAlpha() ;
74 m_selected.BeginRawAccess() ;
75 m_width = bitmap.GetWidth();
76 m_height = bitmap.GetHeight();
77 CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
78 CGContextRef bmCtx = (CGContextRef) m_selected.GetHBITMAP();
79
80 if ( bmCtx )
81 {
82 CGContextSetFillColorSpace( bmCtx, genericColorSpace );
83 CGContextSetStrokeColorSpace( bmCtx, genericColorSpace );
84 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) );
85 }
86 m_ok = (m_graphicContext != NULL) ;
87
88 #else
89 m_macPort = m_selected.GetHBITMAP( &m_macMask ) ;
90 m_ok = (m_macPort != NULL) ;
91 if (m_ok)
92 {
93 LockPixels( GetGWorldPixMap( (CGrafPtr) m_macPort ) ) ;
94 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , 0 , 0 , m_selected.GetWidth() , m_selected.GetHeight() ) ;
95 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
96 }
97 #endif
98 }
99 else
100 {
101 m_ok = false;
102 }
103 }
104
105 void wxMemoryDC::DoGetSize( int *width, int *height ) const
106 {
107 if (m_selected.Ok())
108 {
109 if (width)
110 (*width) = m_selected.GetWidth();
111 if (height)
112 (*height) = m_selected.GetHeight();
113 }
114 else
115 {
116 if (width)
117 (*width) = 0;
118 if (height)
119 (*height) = 0;
120 }
121 }