]>
Commit | Line | Data |
---|---|---|
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 | ||
21 | IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxPaintDC) | |
22 | ||
23 | wxMemoryDC::wxMemoryDC(void) | |
e40298d5 | 24 | : m_selected() |
e9576ca5 | 25 | { |
e40298d5 | 26 | m_ok = TRUE; |
0a67a93b SC |
27 | SetBackground(*wxWHITE_BRUSH); |
28 | SetBrush(*wxWHITE_BRUSH); | |
29 | SetPen(*wxBLACK_PEN); | |
20b69855 | 30 | SetFont(*wxNORMAL_FONT) ; |
e40298d5 | 31 | m_ok = FALSE; |
e9576ca5 SC |
32 | }; |
33 | ||
34 | wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) ) | |
e40298d5 | 35 | : m_selected() |
e9576ca5 | 36 | { |
e40298d5 | 37 | m_ok = TRUE; |
0a67a93b SC |
38 | SetBackground(*wxWHITE_BRUSH); |
39 | SetBrush(*wxWHITE_BRUSH); | |
40 | SetPen(*wxBLACK_PEN); | |
20b69855 | 41 | SetFont(*wxNORMAL_FONT) ; |
e40298d5 | 42 | m_ok = FALSE; |
e9576ca5 SC |
43 | }; |
44 | ||
3dec57ad | 45 | wxMemoryDC::~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 | |
56 | // TODO UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) ); | |
57 | #endif | |
e40298d5 | 58 | } |
e9576ca5 SC |
59 | }; |
60 | ||
61 | void 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 | |
72 | // TODO UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) ); | |
73 | #endif | |
e40298d5 | 74 | } |
3dec57ad SC |
75 | m_selected = bitmap; |
76 | if (m_selected.Ok()) | |
77 | { | |
20b69855 SC |
78 | #if wxMAC_USE_CORE_GRAPHICS |
79 | m_selected.UseAlpha() ; | |
80 | void * data = m_selected.BeginRawAccess() ; | |
81 | ||
82 | int bitsPerComp = 8 ; | |
83 | int bytesPerPixel = 4 ; | |
84 | int w = bitmap.GetWidth() ; | |
85 | int h = bitmap.GetHeight() ; | |
86 | CGImageAlphaInfo a = kCGImageAlphaNoneSkipFirst ; | |
87 | CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace(); | |
88 | CGContextRef bmCtx = CGBitmapContextCreate(data , w, h, bitsPerComp , bytesPerPixel * w , genericColorSpace, a); | |
89 | wxASSERT_MSG( bmCtx , wxT("Unable to create bitmap context") ) ; | |
90 | ||
91 | CGContextSetFillColorSpace(bmCtx, genericColorSpace); | |
92 | CGContextSetStrokeColorSpace(bmCtx, genericColorSpace); | |
93 | ||
94 | if( bmCtx ) | |
95 | { | |
96 | CGContextTranslateCTM( bmCtx , 0 , m_selected.GetHeight() ) ; | |
97 | CGContextScaleCTM( bmCtx , 1 , -1 ) ; | |
98 | m_graphicContext = new wxMacCGContext( bmCtx ) ; | |
99 | m_graphicContext->SetPen( m_pen ) ; | |
100 | m_graphicContext->SetBrush( m_brush ) ; | |
101 | } | |
102 | m_ok = (m_graphicContext != NULL) ; | |
103 | #else | |
104 | if ( ( m_macPort = m_selected.GetHBITMAP( &m_macMask ) ) != NULL ) | |
e40298d5 | 105 | { |
e40298d5 | 106 | LockPixels( GetGWorldPixMap( (CGrafPtr) m_macPort ) ) ; |
20b69855 | 107 | /* |
e40298d5 JS |
108 | wxMask * mask = bitmap.GetMask() ; |
109 | if ( mask ) | |
110 | { | |
20b69855 | 111 | m_macMask = mask->GetHBITMAP() ; |
e40298d5 | 112 | } |
20b69855 | 113 | */ |
e40298d5 JS |
114 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , 0 , 0 , m_selected.GetWidth() , m_selected.GetHeight() ) ; |
115 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ; | |
116 | m_ok = TRUE ; | |
117 | } | |
118 | else | |
119 | { | |
120 | m_ok = FALSE; | |
121 | } | |
20b69855 | 122 | #endif |
e40298d5 JS |
123 | } |
124 | else | |
125 | { | |
126 | m_ok = FALSE; | |
127 | } | |
3dec57ad | 128 | } |
e9576ca5 | 129 | |
0a67a93b | 130 | void wxMemoryDC::DoGetSize( int *width, int *height ) const |
e9576ca5 | 131 | { |
e40298d5 JS |
132 | if (m_selected.Ok()) |
133 | { | |
134 | if (width) (*width) = m_selected.GetWidth(); | |
135 | if (height) (*height) = m_selected.GetHeight(); | |
136 | } | |
137 | else | |
138 | { | |
139 | if (width) (*width) = 0; | |
140 | if (height) (*height) = 0; | |
141 | } | |
3dec57ad | 142 | } |
e9576ca5 SC |
143 | |
144 |