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