]> git.saurik.com Git - wxWidgets.git/blob - src/osx/core/dcmemory.cpp
Don't use DDEExec registry key in wxMSW wxExecute() if it's empty.
[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 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #include "wx/dcmemory.h"
14 #include "wx/graphics.h"
15 #include "wx/osx/dcmemory.h"
16
17 #include "wx/osx/private.h"
18
19 //-----------------------------------------------------------------------------
20 // wxMemoryDCImpl
21 //-----------------------------------------------------------------------------
22
23 IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl,wxPaintDCImpl)
24
25
26 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner )
27 : wxPaintDCImpl( owner )
28 {
29 Init();
30 }
31
32 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxBitmap& bitmap )
33 : wxPaintDCImpl( owner )
34 {
35 Init();
36 DoSelect(bitmap);
37 }
38
39 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxDC * WXUNUSED(dc) )
40 : wxPaintDCImpl( owner )
41 {
42 Init();
43 }
44
45 void 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
55 wxMemoryDCImpl::~wxMemoryDCImpl()
56 {
57 if ( m_selected.IsOk() )
58 {
59 m_selected.EndRawAccess() ;
60 wxDELETE(m_graphicContext);
61 }
62 }
63
64 void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap )
65 {
66 if ( m_selected.IsOk() )
67 {
68 m_selected.EndRawAccess() ;
69 wxDELETE(m_graphicContext);
70 }
71
72 m_selected = bitmap;
73 if (m_selected.IsOk())
74 {
75 if ( m_selected.GetDepth() != 1 )
76 m_selected.UseAlpha() ;
77 m_selected.BeginRawAccess() ;
78 m_width = bitmap.GetScaledWidth();
79 m_height = bitmap.GetScaledHeight();
80 m_contentScaleFactor = bitmap.GetScaleFactor();
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.GetScaledWidth();
104 if (height)
105 (*height) = m_selected.GetScaledHeight();
106 }
107 else
108 {
109 if (width)
110 (*width) = 0;
111 if (height)
112 (*height) = 0;
113 }
114 }