]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dcmemory.cpp
pen.h depends from brush.h in compat mode
[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"
8acd14d1 15#include "wx/graphics.h"
f38924e8 16
76a5e5d2 17#include "wx/mac/private.h"
e9576ca5
SC
18
19//-----------------------------------------------------------------------------
888dde65 20// wxMemoryDCImpl
e9576ca5
SC
21//-----------------------------------------------------------------------------
22
888dde65 23IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl,wxPaintDCImpl)
e9576ca5 24
888dde65
RR
25
26wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner )
27 : wxPaintDCImpl( owner )
9a8864ca
VZ
28{
29 Init();
888dde65
RR
30}
31
32wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxBitmap& bitmap )
33 : wxPaintDCImpl( owner )
9a8864ca
VZ
34{
35 Init();
888dde65
RR
36 DoSelect(bitmap);
37}
38
9a8864ca 39wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxDC * WXUNUSED(dc) )
888dde65
RR
40 : wxPaintDCImpl( owner )
41{
42 Init();
43}
44
45void wxMemoryDCImpl::Init()
e9576ca5 46{
cefe5886 47 m_ok = true;
0a67a93b
SC
48 SetBackground(*wxWHITE_BRUSH);
49 SetBrush(*wxWHITE_BRUSH);
50 SetPen(*wxBLACK_PEN);
cefe5886
DS
51 SetFont(*wxNORMAL_FONT);
52 m_ok = false;
53}
e9576ca5 54
888dde65 55wxMemoryDCImpl::~wxMemoryDCImpl()
e9576ca5 56{
e40298d5
JS
57 if ( m_selected.Ok() )
58 {
20b69855 59 m_selected.EndRawAccess() ;
20b69855
SC
60 delete m_graphicContext ;
61 m_graphicContext = NULL ;
e40298d5 62 }
cefe5886 63}
e9576ca5 64
888dde65 65void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap )
e9576ca5 66{
e40298d5
JS
67 if ( m_selected.Ok() )
68 {
20b69855 69 m_selected.EndRawAccess() ;
20b69855
SC
70 delete m_graphicContext ;
71 m_graphicContext = NULL ;
e40298d5 72 }
cefe5886 73
3dec57ad
SC
74 m_selected = bitmap;
75 if (m_selected.Ok())
76 {
514fd350
SC
77 if ( m_selected.GetDepth() != 1 )
78 m_selected.UseAlpha() ;
6239ee05
SC
79 m_selected.BeginRawAccess() ;
80 m_width = bitmap.GetWidth();
81 m_height = bitmap.GetHeight();
20b69855 82 CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
6239ee05 83 CGContextRef bmCtx = (CGContextRef) m_selected.GetHBITMAP();
20b69855 84
cefe5886 85 if ( bmCtx )
20b69855 86 {
f38924e8
WS
87 CGContextSetFillColorSpace( bmCtx, genericColorSpace );
88 CGContextSetStrokeColorSpace( bmCtx, genericColorSpace );
f7862d3e 89 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) );
20b69855 90 }
cefe5886 91 m_ok = (m_graphicContext != NULL) ;
e40298d5
JS
92 }
93 else
94 {
cefe5886 95 m_ok = false;
e40298d5 96 }
3dec57ad 97}
e9576ca5 98
888dde65 99void wxMemoryDCImpl::DoGetSize( int *width, int *height ) const
e9576ca5 100{
e40298d5
JS
101 if (m_selected.Ok())
102 {
cefe5886
DS
103 if (width)
104 (*width) = m_selected.GetWidth();
105 if (height)
106 (*height) = m_selected.GetHeight();
e40298d5
JS
107 }
108 else
109 {
cefe5886
DS
110 if (width)
111 (*width) = 0;
112 if (height)
113 (*height) = 0;
e40298d5 114 }
3dec57ad 115}