]>
Commit | Line | Data |
---|---|---|
489468fe | 1 | ///////////////////////////////////////////////////////////////////////////// |
96dabe43 | 2 | // Name: src/osx/core/dcmemory.cpp |
489468fe SC |
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" | |
1f0c8f31 | 16 | #include "wx/osx/dcmemory.h" |
489468fe | 17 | |
1f0c8f31 | 18 | #include "wx/osx/private.h" |
489468fe SC |
19 | |
20 | //----------------------------------------------------------------------------- | |
21 | // wxMemoryDCImpl | |
22 | //----------------------------------------------------------------------------- | |
23 | ||
24 | IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl,wxPaintDCImpl) | |
25 | ||
26 | ||
27 | wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner ) | |
28 | : wxPaintDCImpl( owner ) | |
29 | { | |
30 | Init(); | |
31 | } | |
32 | ||
33 | wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxBitmap& bitmap ) | |
34 | : wxPaintDCImpl( owner ) | |
35 | { | |
36 | Init(); | |
37 | DoSelect(bitmap); | |
38 | } | |
39 | ||
40 | wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxDC * WXUNUSED(dc) ) | |
41 | : wxPaintDCImpl( owner ) | |
42 | { | |
43 | Init(); | |
44 | } | |
45 | ||
46 | void wxMemoryDCImpl::Init() | |
47 | { | |
48 | m_ok = true; | |
49 | SetBackground(*wxWHITE_BRUSH); | |
50 | SetBrush(*wxWHITE_BRUSH); | |
51 | SetPen(*wxBLACK_PEN); | |
52 | SetFont(*wxNORMAL_FONT); | |
53 | m_ok = false; | |
54 | } | |
55 | ||
56 | wxMemoryDCImpl::~wxMemoryDCImpl() | |
57 | { | |
a1b806b9 | 58 | if ( m_selected.IsOk() ) |
489468fe SC |
59 | { |
60 | m_selected.EndRawAccess() ; | |
5276b0a5 | 61 | wxDELETE(m_graphicContext); |
489468fe SC |
62 | } |
63 | } | |
64 | ||
65 | void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap ) | |
66 | { | |
a1b806b9 | 67 | if ( m_selected.IsOk() ) |
489468fe SC |
68 | { |
69 | m_selected.EndRawAccess() ; | |
5276b0a5 | 70 | wxDELETE(m_graphicContext); |
489468fe SC |
71 | } |
72 | ||
73 | m_selected = bitmap; | |
a1b806b9 | 74 | if (m_selected.IsOk()) |
489468fe SC |
75 | { |
76 | if ( m_selected.GetDepth() != 1 ) | |
77 | m_selected.UseAlpha() ; | |
78 | m_selected.BeginRawAccess() ; | |
7e0fda87 SC |
79 | m_width = bitmap.GetScaledWidth(); |
80 | m_height = bitmap.GetScaledHeight(); | |
81 | m_contentScaleFactor = bitmap.GetScaleFactor(); | |
489468fe SC |
82 | CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace(); |
83 | CGContextRef bmCtx = (CGContextRef) m_selected.GetHBITMAP(); | |
84 | ||
85 | if ( bmCtx ) | |
86 | { | |
87 | CGContextSetFillColorSpace( bmCtx, genericColorSpace ); | |
88 | CGContextSetStrokeColorSpace( bmCtx, genericColorSpace ); | |
03647350 | 89 | SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) ); |
489468fe SC |
90 | } |
91 | m_ok = (m_graphicContext != NULL) ; | |
92 | } | |
93 | else | |
94 | { | |
95 | m_ok = false; | |
96 | } | |
97 | } | |
98 | ||
99 | void wxMemoryDCImpl::DoGetSize( int *width, int *height ) const | |
100 | { | |
a1b806b9 | 101 | if (m_selected.IsOk()) |
489468fe SC |
102 | { |
103 | if (width) | |
7e0fda87 | 104 | (*width) = m_selected.GetScaledWidth(); |
489468fe | 105 | if (height) |
7e0fda87 | 106 | (*height) = m_selected.GetScaledHeight(); |
489468fe SC |
107 | } |
108 | else | |
109 | { | |
110 | if (width) | |
111 | (*width) = 0; | |
112 | if (height) | |
113 | (*height) = 0; | |
114 | } | |
115 | } |