DoGetAsBitmap implementation for Cocoa.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55539 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Kevin Ollivier
2008-09-11 05:40:35 +00:00
parent 1a4e2d5b2f
commit 928e7a7e1b
2 changed files with 38 additions and 4 deletions

View File

@@ -96,6 +96,7 @@ void wxWindowDCImpl::DoGetSize( int* width, int* height ) const
*height = m_height;
}
#if wxOSX_USE_CARBON
wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
{
// wxScreenDC is derived from wxWindowDC, so a screen dc will
@@ -103,7 +104,6 @@ wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
if (!m_window)
return wxNullBitmap;
#if wxOSX_USE_CARBON
ControlRef handle = (ControlRef) m_window->GetHandle();
if ( !handle )
return wxNullBitmap;
@@ -136,10 +136,8 @@ wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
CGContextRestoreGState(context);
return bmp;
#else
return wxNullBitmap;
#endif
}
#endif
/*
* wxClientDCImpl

View File

@@ -31,6 +31,7 @@
#if wxUSE_GUI
#if wxOSX_USE_COCOA_OR_CARBON
#include <CoreServices/CoreServices.h>
#include "wx/osx/dcclient.h"
#include "wx/osx/private/timer.h"
#endif
#endif // wxUSE_GUI
@@ -140,6 +141,41 @@ void wxMacLocalToGlobal( WindowRef window , Point*pt )
{
}
wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
{
// wxScreenDC is derived from wxWindowDC, so a screen dc will
// call this method when a Blit is performed with it as a source.
if (!m_window)
return wxNullBitmap;
wxSize sz = m_window->GetSize();
int left = subrect != NULL ? subrect->x : 0 ;
int top = subrect != NULL ? subrect->y : 0 ;
int width = subrect != NULL ? subrect->width : sz.x;
int height = subrect != NULL ? subrect->height : sz.y ;
NSRect rect = NSMakeRect(left, top, width, height );
NSView* view = (NSView*) m_window->GetHandle();
[view lockFocus];
// we use this method as other methods force a repaint, and this method can be
// called from OnPaint, even with the window's paint dc as source (see wxHTMLWindow)
NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect: [view bounds]] retain];
[view unlockFocus];
CGImageRef cgImageRef = [rep CGImage];
wxBitmap bitmap(CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) );
CGRect r = CGRectMake( 0 , 0 , CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) );
// since our context is upside down we dont use CGContextDrawImage
wxMacDrawCGImage( (CGContextRef) bitmap.GetHBITMAP() , &r, cgImageRef ) ;
CGImageRelease(cgImageRef);
cgImageRef = NULL;
[rep release];
return bitmap;
}
#endif // wxUSE_GUI