]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/dcclient.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/dcclient.cpp
3 // Purpose: wxClientDCImpl class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/dcclient.h"
18 #include "wx/window.h"
19 #include "wx/dcmemory.h"
20 #include "wx/settings.h"
21 #include "wx/toplevel.h"
23 #include "wx/region.h"
26 #include "wx/graphics.h"
27 #include "wx/rawbmp.h"
28 #include "wx/osx/private.h"
29 #include "wx/osx/dcclient.h"
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl
, wxGCDCImpl
)
37 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
)
44 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
, wxWindow
*window
)
51 m_window
->GetSize( &m_width
, &m_height
);
52 if ( !m_window
->IsShownOnScreen() )
53 m_width
= m_height
= 0;
55 CGContextRef cg
= (CGContextRef
) window
->MacGetCGContextRef();
60 SetGraphicsContext( wxGraphicsContext::Create( window
) ) ;
64 CGContextSaveGState( cg
);
66 // make sure the context is having its origin at the wx-window coordinates of the
67 // view (read at the top of window.cpp about the differences)
68 if ( window
->MacGetLeftBorderSize() != 0 || window
->MacGetTopBorderSize() != 0 )
69 CGContextTranslateCTM( cg
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
71 wxGraphicsContext
* context
= wxGraphicsContext::CreateFromNative( cg
);
72 context
->EnableOffset(true);
73 SetGraphicsContext( context
);
75 DoSetClippingRegion( 0 , 0 , m_width
, m_height
) ;
77 SetBackground(wxBrush(window
->GetBackgroundColour(),wxSOLID
));
79 SetFont( window
->GetFont() ) ;
82 wxWindowDCImpl::~wxWindowDCImpl()
86 // this must not necessarily be the current context, we must restore the state of the
87 // cg we started with above (before the CGContextTranslateCTM call)
88 CGContextRef cg
= (CGContextRef
) m_window
->MacGetCGContextRef();
89 CGContextRestoreGState(cg
);
93 void wxWindowDCImpl::DoGetSize( int* width
, int* height
) const
102 wxBitmap
wxWindowDCImpl::DoGetAsBitmap(const wxRect
*subrect
) const
104 // wxScreenDC is derived from wxWindowDC, so a screen dc will
105 // call this method when a Blit is performed with it as a source.
109 ControlRef handle
= (ControlRef
) m_window
->GetHandle();
115 CGContextRef context
;
117 HIViewCreateOffscreenImage( handle
, 0, &rect
, &image
);
120 int width
= subrect
!= NULL
? subrect
->width
: (int)rect
.size
.width
;
121 int height
= subrect
!= NULL
? subrect
->height
: (int)rect
.size
.height
;
123 wxBitmap bmp
= wxBitmap(width
, height
, 32);
125 context
= (CGContextRef
)bmp
.GetHBITMAP();
127 CGContextSaveGState(context
);
129 CGContextTranslateCTM( context
, 0, height
);
130 CGContextScaleCTM( context
, 1, -1 );
133 rect
= CGRectOffset( rect
, -subrect
->x
, -subrect
->y
) ;
134 CGContextDrawImage( context
, rect
, image
);
136 CGContextRestoreGState(context
);
145 IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl
, wxWindowDCImpl
)
147 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
)
148 : wxWindowDCImpl( owner
)
152 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
, wxWindow
*window
) :
153 wxWindowDCImpl( owner
, window
)
155 wxCHECK_RET( window
, wxT("invalid window in wxClientDCImpl") );
156 wxPoint origin
= window
->GetClientAreaOrigin() ;
157 m_window
->GetClientSize( &m_width
, &m_height
);
158 if ( !m_window
->IsShownOnScreen() )
159 m_width
= m_height
= 0;
160 SetDeviceOrigin( origin
.x
, origin
.y
);
161 DoSetClippingRegion( 0 , 0 , m_width
, m_height
) ;
164 wxClientDCImpl::~wxClientDCImpl()
166 if( GetGraphicsContext() && GetGraphicsContext()->GetNativeContext() )
174 IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl
, wxWindowDCImpl
)
176 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
)
177 : wxWindowDCImpl( owner
)
181 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
, wxWindow
*window
) :
182 wxWindowDCImpl( owner
, window
)
184 wxASSERT_MSG( window
->MacGetCGContextRef() != NULL
, wxT("using wxPaintDC without being in a native paint event") );
185 wxPoint origin
= window
->GetClientAreaOrigin() ;
186 m_window
->GetClientSize( &m_width
, &m_height
);
187 SetDeviceOrigin( origin
.x
, origin
.y
);
188 DoSetClippingRegion( 0 , 0 , m_width
, m_height
) ;
191 wxPaintDCImpl::~wxPaintDCImpl()