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