]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/dcmemory.cpp
Include wx/font.h according to precompiled headers of wx/wx.h (with other minor clean...
[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
16#include "wx/mac/private.h"
17
18//-----------------------------------------------------------------------------
19// wxMemoryDC
20//-----------------------------------------------------------------------------
21
22IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxPaintDC)
23
24wxMemoryDC::wxMemoryDC()
25: m_selected()
26{
27 m_ok = true;
28 SetBackground(*wxWHITE_BRUSH);
29 SetBrush(*wxWHITE_BRUSH);
30 SetPen(*wxBLACK_PEN);
31 SetFont(*wxNORMAL_FONT);
32 m_ok = false;
33}
34
35wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
36: m_selected()
37{
38 m_ok = true;
39 SetBackground(*wxWHITE_BRUSH);
40 SetBrush(*wxWHITE_BRUSH);
41 SetPen(*wxBLACK_PEN);
42 SetFont(*wxNORMAL_FONT);
43 m_ok = false;
44}
45
46wxMemoryDC::~wxMemoryDC()
47{
48 if ( m_selected.Ok() )
49 {
50#if wxMAC_USE_CORE_GRAPHICS
51 m_selected.EndRawAccess() ;
52 CGContextRef bmCtx = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
53 delete m_graphicContext ;
54 m_graphicContext = NULL ;
55 CGContextRelease( bmCtx ) ;
56#else
57// TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
58#endif
59 }
60}
61
62void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
63{
64 if ( m_selected.Ok() )
65 {
66#if wxMAC_USE_CORE_GRAPHICS
67 m_selected.EndRawAccess() ;
68 CGContextRef bmCtx = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
69 delete m_graphicContext ;
70 m_graphicContext = NULL ;
71 CGContextRelease( bmCtx ) ;
72#else
73// TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
74#endif
75 }
76
77 m_selected = bitmap;
78 if (m_selected.Ok())
79 {
80#if wxMAC_USE_CORE_GRAPHICS
81 m_selected.UseAlpha() ;
82 void * data = m_selected.BeginRawAccess() ;
83
84 int bitsPerComp = 8 ;
85 int bytesPerPixel = 4 ;
86 int w = bitmap.GetWidth() ;
87 int h = bitmap.GetHeight() ;
88
89 // TODO: should this be kCGImageAlphaPremultiplied[First,Last] ?
90 CGImageAlphaInfo a = kCGImageAlphaNoneSkipFirst ;
91
92 CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
93 CGContextRef bmCtx = CGBitmapContextCreate( data , w, h, bitsPerComp , bytesPerPixel * w , genericColorSpace, a );
94 wxASSERT_MSG( bmCtx , wxT("Unable to create bitmap context") ) ;
95
96 if ( bmCtx )
97 {
98 CGContextSetFillColorSpace( bmCtx, genericColorSpace );
99 CGContextSetStrokeColorSpace( bmCtx, genericColorSpace );
100
101 CGContextTranslateCTM( bmCtx , 0 , m_selected.GetHeight() ) ;
102 CGContextScaleCTM( bmCtx , 1 , -1 ) ;
103
104 m_graphicContext = new wxMacCGContext( bmCtx ) ;
105 m_graphicContext->SetPen( m_pen ) ;
106 m_graphicContext->SetBrush( m_brush ) ;
107 }
108 m_ok = (m_graphicContext != NULL) ;
109
110#else
111 m_macPort = m_selected.GetHBITMAP( &m_macMask ) ;
112 m_ok = (m_macPort != NULL) ;
113 if (m_ok)
114 {
115 LockPixels( GetGWorldPixMap( (CGrafPtr) m_macPort ) ) ;
116 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , 0 , 0 , m_selected.GetWidth() , m_selected.GetHeight() ) ;
117 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
118 }
119#endif
120 }
121 else
122 {
123 m_ok = false;
124 }
125}
126
127void wxMemoryDC::DoGetSize( int *width, int *height ) const
128{
129 if (m_selected.Ok())
130 {
131 if (width)
132 (*width) = m_selected.GetWidth();
133 if (height)
134 (*height) = m_selected.GetHeight();
135 }
136 else
137 {
138 if (width)
139 (*width) = 0;
140 if (height)
141 (*height) = 0;
142 }
143}