]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/dcmemory.cpp
added wxWindow::GetPrev/NextSibling()
[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// wxMemoryDC
21//-----------------------------------------------------------------------------
22
23IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxPaintDC)
24
25void wxMemoryDC::Init()
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 Init();
39}
40
41wxMemoryDC::~wxMemoryDC()
42{
43 if ( m_selected.Ok() )
44 {
45 m_selected.EndRawAccess() ;
46 delete m_graphicContext ;
47 m_graphicContext = NULL ;
48 }
49}
50
51void wxMemoryDC::DoSelect( const wxBitmap& bitmap )
52{
53 if ( m_selected.Ok() )
54 {
55 m_selected.EndRawAccess() ;
56 delete m_graphicContext ;
57 m_graphicContext = NULL ;
58 }
59
60 m_selected = bitmap;
61 if (m_selected.Ok())
62 {
63 if ( m_selected.GetDepth() != 1 )
64 m_selected.UseAlpha() ;
65 m_selected.BeginRawAccess() ;
66 m_width = bitmap.GetWidth();
67 m_height = bitmap.GetHeight();
68 CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
69 CGContextRef bmCtx = (CGContextRef) m_selected.GetHBITMAP();
70
71 if ( bmCtx )
72 {
73 CGContextSetFillColorSpace( bmCtx, genericColorSpace );
74 CGContextSetStrokeColorSpace( bmCtx, genericColorSpace );
75 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) );
76 }
77 m_ok = (m_graphicContext != NULL) ;
78 }
79 else
80 {
81 m_ok = false;
82 }
83}
84
85void wxMemoryDC::DoGetSize( int *width, int *height ) const
86{
87 if (m_selected.Ok())
88 {
89 if (width)
90 (*width) = m_selected.GetWidth();
91 if (height)
92 (*height) = m_selected.GetHeight();
93 }
94 else
95 {
96 if (width)
97 (*width) = 0;
98 if (height)
99 (*height) = 0;
100 }
101}