]> git.saurik.com Git - wxWidgets.git/blob - src/osx/core/dcmemory.cpp
init pattern
[wxWidgets.git] / src / osx / core / dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/core/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 #include "wx/osx/dcmemory.h"
17
18 #include "wx/osx/private.h"
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 {
58 if ( m_selected.IsOk() )
59 {
60 m_selected.EndRawAccess() ;
61 wxDELETE(m_graphicContext);
62 }
63 }
64
65 void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap )
66 {
67 if ( m_selected.IsOk() )
68 {
69 m_selected.EndRawAccess() ;
70 wxDELETE(m_graphicContext);
71 }
72
73 m_selected = bitmap;
74 if (m_selected.IsOk())
75 {
76 if ( m_selected.GetDepth() != 1 )
77 m_selected.UseAlpha() ;
78 m_selected.BeginRawAccess() ;
79 m_width = bitmap.GetWidth();
80 m_height = bitmap.GetHeight();
81 CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
82 CGContextRef bmCtx = (CGContextRef) m_selected.GetHBITMAP();
83
84 if ( bmCtx )
85 {
86 CGContextSetFillColorSpace( bmCtx, genericColorSpace );
87 CGContextSetStrokeColorSpace( bmCtx, genericColorSpace );
88 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) );
89 }
90 m_ok = (m_graphicContext != NULL) ;
91 }
92 else
93 {
94 m_ok = false;
95 }
96 }
97
98 void wxMemoryDCImpl::DoGetSize( int *width, int *height ) const
99 {
100 if (m_selected.IsOk())
101 {
102 if (width)
103 (*width) = m_selected.GetWidth();
104 if (height)
105 (*height) = m_selected.GetHeight();
106 }
107 else
108 {
109 if (width)
110 (*width) = 0;
111 if (height)
112 (*height) = 0;
113 }
114 }