]>
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
) ) ;
61 SetDeviceOrigin(-window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize());
65 CGContextSaveGState( cg
);
67 // make sure the context is having its origin at the wx-window coordinates of the
68 // view (read at the top of window.cpp about the differences)
69 if ( window
->MacGetLeftBorderSize() != 0 || window
->MacGetTopBorderSize() != 0 )
70 CGContextTranslateCTM( cg
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
72 wxGraphicsContext
* context
= wxGraphicsContext::CreateFromNative( cg
);
73 context
->EnableOffset(true);
74 SetGraphicsContext( context
);
76 DoSetClippingRegion( 0 , 0 , m_width
, m_height
) ;
78 SetBackground(wxBrush(window
->GetBackgroundColour(),wxSOLID
));
80 SetFont( window
->GetFont() ) ;
83 wxWindowDCImpl::~wxWindowDCImpl()
87 // this must not necessarily be the current context, we must restore the state of the
88 // cg we started with above (before the CGContextTranslateCTM call)
89 CGContextRef cg
= (CGContextRef
) m_window
->MacGetCGContextRef();
90 CGContextRestoreGState(cg
);
94 void wxWindowDCImpl::DoGetSize( int* width
, int* height
) const
103 wxBitmap
wxWindowDCImpl::DoGetAsBitmap(const wxRect
*subrect
) const
105 // wxScreenDC is derived from wxWindowDC, so a screen dc will
106 // call this method when a Blit is performed with it as a source.
110 ControlRef handle
= (ControlRef
) m_window
->GetHandle();
116 CGContextRef context
;
118 HIViewCreateOffscreenImage( handle
, 0, &rect
, &image
);
121 int width
= subrect
!= NULL
? subrect
->width
: (int)rect
.size
.width
;
122 int height
= subrect
!= NULL
? subrect
->height
: (int)rect
.size
.height
;
124 wxBitmap bmp
= wxBitmap(width
, height
, 32);
126 context
= (CGContextRef
)bmp
.GetHBITMAP();
128 CGContextSaveGState(context
);
130 CGContextTranslateCTM( context
, 0, height
);
131 CGContextScaleCTM( context
, 1, -1 );
134 rect
= CGRectOffset( rect
, -subrect
->x
, -subrect
->y
) ;
135 CGContextDrawImage( context
, rect
, image
);
137 CGContextRestoreGState(context
);
146 IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl
, wxWindowDCImpl
)
148 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
)
149 : wxWindowDCImpl( owner
)
153 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
, wxWindow
*window
) :
154 wxWindowDCImpl( owner
, window
)
156 wxCHECK_RET( window
, wxT("invalid window in wxClientDCImpl") );
157 wxPoint origin
= window
->GetClientAreaOrigin() ;
158 m_window
->GetClientSize( &m_width
, &m_height
);
159 if ( !m_window
->IsShownOnScreen() )
160 m_width
= m_height
= 0;
163 DoGetDeviceOrigin(&x0
,&y0
);
164 SetDeviceOrigin( origin
.x
+ x0
, origin
.y
+ y0
);
166 DoSetClippingRegion( 0 , 0 , m_width
, m_height
) ;
169 wxClientDCImpl::~wxClientDCImpl()
171 if( GetGraphicsContext() && GetGraphicsContext()->GetNativeContext() )
179 IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl
, wxWindowDCImpl
)
181 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
)
182 : wxWindowDCImpl( owner
)
186 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
, wxWindow
*window
) :
187 wxWindowDCImpl( owner
, window
)
189 wxASSERT_MSG( window
->MacGetCGContextRef() != NULL
, wxT("using wxPaintDC without being in a native paint event") );
190 wxPoint origin
= window
->GetClientAreaOrigin() ;
191 m_window
->GetClientSize( &m_width
, &m_height
);
192 SetDeviceOrigin( origin
.x
, origin
.y
);
193 DoSetClippingRegion( 0 , 0 , m_width
, m_height
) ;
196 wxPaintDCImpl::~wxPaintDCImpl()