]>
Commit | Line | Data |
---|---|---|
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 | ||
23 | IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxPaintDC) | |
24 | ||
fea35690 | 25 | void 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 | |
35 | wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) ) | |
e40298d5 | 36 | : m_selected() |
e9576ca5 | 37 | { |
fea35690 | 38 | Init(); |
cefe5886 | 39 | } |
e9576ca5 | 40 | |
3dec57ad | 41 | wxMemoryDC::~wxMemoryDC() |
e9576ca5 | 42 | { |
e40298d5 JS |
43 | if ( m_selected.Ok() ) |
44 | { | |
20b69855 | 45 | m_selected.EndRawAccess() ; |
20b69855 SC |
46 | delete m_graphicContext ; |
47 | m_graphicContext = NULL ; | |
e40298d5 | 48 | } |
cefe5886 | 49 | } |
e9576ca5 | 50 | |
fea35690 | 51 | void wxMemoryDC::DoSelect( const wxBitmap& bitmap ) |
e9576ca5 | 52 | { |
e40298d5 JS |
53 | if ( m_selected.Ok() ) |
54 | { | |
20b69855 | 55 | m_selected.EndRawAccess() ; |
20b69855 SC |
56 | delete m_graphicContext ; |
57 | m_graphicContext = NULL ; | |
e40298d5 | 58 | } |
cefe5886 | 59 | |
3dec57ad SC |
60 | m_selected = bitmap; |
61 | if (m_selected.Ok()) | |
62 | { | |
514fd350 SC |
63 | if ( m_selected.GetDepth() != 1 ) |
64 | m_selected.UseAlpha() ; | |
6239ee05 SC |
65 | m_selected.BeginRawAccess() ; |
66 | m_width = bitmap.GetWidth(); | |
67 | m_height = bitmap.GetHeight(); | |
20b69855 | 68 | CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace(); |
6239ee05 | 69 | CGContextRef bmCtx = (CGContextRef) m_selected.GetHBITMAP(); |
20b69855 | 70 | |
cefe5886 | 71 | if ( bmCtx ) |
20b69855 | 72 | { |
f38924e8 WS |
73 | CGContextSetFillColorSpace( bmCtx, genericColorSpace ); |
74 | CGContextSetStrokeColorSpace( bmCtx, genericColorSpace ); | |
f7862d3e | 75 | SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) ); |
20b69855 | 76 | } |
cefe5886 | 77 | m_ok = (m_graphicContext != NULL) ; |
e40298d5 JS |
78 | } |
79 | else | |
80 | { | |
cefe5886 | 81 | m_ok = false; |
e40298d5 | 82 | } |
3dec57ad | 83 | } |
e9576ca5 | 84 | |
0a67a93b | 85 | void wxMemoryDC::DoGetSize( int *width, int *height ) const |
e9576ca5 | 86 | { |
e40298d5 JS |
87 | if (m_selected.Ok()) |
88 | { | |
cefe5886 DS |
89 | if (width) |
90 | (*width) = m_selected.GetWidth(); | |
91 | if (height) | |
92 | (*height) = m_selected.GetHeight(); | |
e40298d5 JS |
93 | } |
94 | else | |
95 | { | |
cefe5886 DS |
96 | if (width) |
97 | (*width) = 0; | |
98 | if (height) | |
99 | (*height) = 0; | |
e40298d5 | 100 | } |
3dec57ad | 101 | } |