X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dbeddfb93d3479d03d8ec4c0121dfbe3bbcc422b..bb69632a56a827bed4cfae842bfffa88259ac1aa:/src/osx/cocoa/utils.mm diff --git a/src/osx/cocoa/utils.mm b/src/osx/cocoa/utils.mm index a9cdfeff83..ab7f2f4cff 100644 --- a/src/osx/cocoa/utils.mm +++ b/src/osx/cocoa/utils.mm @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/cocoa/utils.mm +// Name: src/osx/cocoa/utils.mm // Purpose: various cocoa utility functions // Author: Stefan Csomor // Modified by: @@ -31,6 +31,7 @@ #if wxUSE_GUI #if wxOSX_USE_COCOA_OR_CARBON #include + #include "wx/osx/dcclient.h" #include "wx/osx/private/timer.h" #endif #endif // wxUSE_GUI @@ -56,6 +57,8 @@ void wxMacWakeUp() #endif // wxUSE_BASE +#if wxUSE_GUI + bool wxApp::DoInitGui() { [NSApplication sharedApplication]; @@ -67,8 +70,6 @@ void wxApp::DoCleanUp() { } -#if wxUSE_GUI - void wxClientDisplayRect(int *x, int *y, int *width, int *height) { NSRect displayRect = [[NSScreen mainScreen] visibleFrame]; @@ -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 = (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