supporting graphics context on invisible views, icon refs are available under 64 bit cocoa as well, turn drawing on again, fixes #10490
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58823 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -39,12 +39,7 @@
|
|||||||
#include "wx/osx/dcprint.h"
|
#include "wx/osx/dcprint.h"
|
||||||
#include "wx/osx/dcclient.h"
|
#include "wx/osx/dcclient.h"
|
||||||
#include "wx/osx/dcmemory.h"
|
#include "wx/osx/dcmemory.h"
|
||||||
#if wxOSX_USE_CARBON
|
#include "wx/osx/private.h"
|
||||||
#include "wx/osx/uma.h"
|
|
||||||
#else
|
|
||||||
#include "wx/osx/private.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include "CoreServices/CoreServices.h"
|
#include "CoreServices/CoreServices.h"
|
||||||
#include "ApplicationServices/ApplicationServices.h"
|
#include "ApplicationServices/ApplicationServices.h"
|
||||||
@@ -78,7 +73,7 @@ int UMAGetSystemVersion()
|
|||||||
|
|
||||||
#if wxOSX_USE_COCOA_OR_IPHONE
|
#if wxOSX_USE_COCOA_OR_IPHONE
|
||||||
extern CGContextRef wxOSXGetContextFromCurrentNSContext() ;
|
extern CGContextRef wxOSXGetContextFromCurrentNSContext() ;
|
||||||
extern void wxOSXLockFocus( WXWidget view) ;
|
extern bool wxOSXLockFocus( WXWidget view) ;
|
||||||
extern void wxOSXUnlockFocus( WXWidget view) ;
|
extern void wxOSXUnlockFocus( WXWidget view) ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1391,7 +1386,7 @@ public:
|
|||||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacCoreGraphicsContext)
|
DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacCoreGraphicsContext)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void EnsureIsValid();
|
bool EnsureIsValid();
|
||||||
|
|
||||||
virtual void DoDrawText( const wxString &str, wxDouble x, wxDouble y );
|
virtual void DoDrawText( const wxString &str, wxDouble x, wxDouble y );
|
||||||
virtual void DoDrawRotatedText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle );
|
virtual void DoDrawRotatedText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle );
|
||||||
@@ -1406,6 +1401,7 @@ private:
|
|||||||
CGAffineTransform m_windowTransform;
|
CGAffineTransform m_windowTransform;
|
||||||
wxDouble m_width;
|
wxDouble m_width;
|
||||||
wxDouble m_height;
|
wxDouble m_height;
|
||||||
|
bool m_invisible;
|
||||||
|
|
||||||
#if wxOSX_USE_COCOA_OR_CARBON
|
#if wxOSX_USE_COCOA_OR_CARBON
|
||||||
wxCFRef<HIShapeRef> m_clipRgn;
|
wxCFRef<HIShapeRef> m_clipRgn;
|
||||||
@@ -1462,6 +1458,7 @@ void wxMacCoreGraphicsContext::Init()
|
|||||||
#if wxOSX_USE_COCOA_OR_IPHONE
|
#if wxOSX_USE_COCOA_OR_IPHONE
|
||||||
m_view = NULL;
|
m_view = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
m_invisible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer* renderer, CGContextRef cgcontext, wxDouble width, wxDouble height ) : wxGraphicsContext(renderer)
|
wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer* renderer, CGContextRef cgcontext, wxDouble width, wxDouble height ) : wxGraphicsContext(renderer)
|
||||||
@@ -1565,13 +1562,23 @@ void wxMacCoreGraphicsContext::Flush()
|
|||||||
CGContextFlush(m_cgContext);
|
CGContextFlush(m_cgContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxMacCoreGraphicsContext::EnsureIsValid()
|
bool wxMacCoreGraphicsContext::EnsureIsValid()
|
||||||
{
|
{
|
||||||
if ( !m_cgContext )
|
if ( !m_cgContext )
|
||||||
{
|
{
|
||||||
|
if (m_invisible)
|
||||||
|
return false;
|
||||||
|
|
||||||
#if wxOSX_USE_COCOA_OR_IPHONE
|
#if wxOSX_USE_COCOA_OR_IPHONE
|
||||||
wxOSXLockFocus(m_view);
|
if ( wxOSXLockFocus(m_view) )
|
||||||
|
{
|
||||||
m_cgContext = wxOSXGetContextFromCurrentNSContext();
|
m_cgContext = wxOSXGetContextFromCurrentNSContext();
|
||||||
|
wxASSERT_MSG( m_cgContext != NULL, _T("Unable to retrieve drawing context from View"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_invisible = true;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#if wxOSX_USE_CARBON
|
#if wxOSX_USE_CARBON
|
||||||
OSStatus status = QDBeginCGContext( GetWindowPort( m_windowRef ) , &m_cgContext );
|
OSStatus status = QDBeginCGContext( GetWindowPort( m_windowRef ) , &m_cgContext );
|
||||||
@@ -1580,6 +1587,8 @@ void wxMacCoreGraphicsContext::EnsureIsValid()
|
|||||||
wxFAIL_MSG("Cannot nest wxDCs on the same window");
|
wxFAIL_MSG("Cannot nest wxDCs on the same window");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if ( m_cgContext )
|
||||||
|
{
|
||||||
CGContextConcatCTM( m_cgContext, m_windowTransform );
|
CGContextConcatCTM( m_cgContext, m_windowTransform );
|
||||||
CGContextSaveGState( m_cgContext );
|
CGContextSaveGState( m_cgContext );
|
||||||
m_contextSynthesized = true;
|
m_contextSynthesized = true;
|
||||||
@@ -1620,6 +1629,8 @@ void wxMacCoreGraphicsContext::EnsureIsValid()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return m_cgContext != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO test whether the private CGContextSetCompositeOperation works under 10.3 (using NSCompositingModes)
|
// TODO test whether the private CGContextSetCompositeOperation works under 10.3 (using NSCompositingModes)
|
||||||
@@ -1629,7 +1640,8 @@ bool wxMacCoreGraphicsContext::SetLogicalFunction( wxRasterOperationMode functio
|
|||||||
if (m_logicalFunction == function)
|
if (m_logicalFunction == function)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
EnsureIsValid();
|
if (EnsureIsValid()==false)
|
||||||
|
return true;
|
||||||
|
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
bool shouldAntiAlias = true;
|
bool shouldAntiAlias = true;
|
||||||
@@ -1773,7 +1785,8 @@ void wxMacCoreGraphicsContext::StrokePath( const wxGraphicsPath &path )
|
|||||||
if ( m_pen.IsNull() )
|
if ( m_pen.IsNull() )
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
EnsureIsValid();
|
if (EnsureIsValid()==false)
|
||||||
|
return;
|
||||||
|
|
||||||
wxQuartzOffsetHelper helper( m_cgContext , ShouldOffset() );
|
wxQuartzOffsetHelper helper( m_cgContext , ShouldOffset() );
|
||||||
|
|
||||||
@@ -1784,6 +1797,9 @@ void wxMacCoreGraphicsContext::StrokePath( const wxGraphicsPath &path )
|
|||||||
|
|
||||||
void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath &path , wxPolygonFillMode fillStyle )
|
void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath &path , wxPolygonFillMode fillStyle )
|
||||||
{
|
{
|
||||||
|
if (EnsureIsValid()==false)
|
||||||
|
return;
|
||||||
|
|
||||||
if ( !m_brush.IsNull() && ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->IsShading() )
|
if ( !m_brush.IsNull() && ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->IsShading() )
|
||||||
{
|
{
|
||||||
// when using shading, we cannot draw pen and brush at the same time
|
// when using shading, we cannot draw pen and brush at the same time
|
||||||
@@ -1818,8 +1834,6 @@ void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath &path , wxPolygonF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EnsureIsValid();
|
|
||||||
|
|
||||||
if ( !m_brush.IsNull() )
|
if ( !m_brush.IsNull() )
|
||||||
((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->Apply(this);
|
((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->Apply(this);
|
||||||
if ( !m_pen.IsNull() )
|
if ( !m_pen.IsNull() )
|
||||||
@@ -1836,7 +1850,8 @@ void wxMacCoreGraphicsContext::FillPath( const wxGraphicsPath &path , wxPolygonF
|
|||||||
if ( m_brush.IsNull() )
|
if ( m_brush.IsNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EnsureIsValid();
|
if (EnsureIsValid()==false)
|
||||||
|
return;
|
||||||
|
|
||||||
if ( ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->IsShading() )
|
if ( ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->IsShading() )
|
||||||
{
|
{
|
||||||
@@ -1933,7 +1948,9 @@ void wxMacCoreGraphicsContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDo
|
|||||||
|
|
||||||
void wxMacCoreGraphicsContext::DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
|
void wxMacCoreGraphicsContext::DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
|
||||||
{
|
{
|
||||||
EnsureIsValid();
|
if (EnsureIsValid()==false)
|
||||||
|
return;
|
||||||
|
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
wxMacCoreGraphicsBitmapData* refdata =static_cast<wxMacCoreGraphicsBitmapData*>(bmp.GetRefData());
|
wxMacCoreGraphicsBitmapData* refdata =static_cast<wxMacCoreGraphicsBitmapData*>(bmp.GetRefData());
|
||||||
CGImageRef image = refdata->GetBitmap();
|
CGImageRef image = refdata->GetBitmap();
|
||||||
@@ -1970,29 +1987,32 @@ void wxMacCoreGraphicsContext::DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble
|
|||||||
|
|
||||||
void wxMacCoreGraphicsContext::DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
|
void wxMacCoreGraphicsContext::DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
|
||||||
{
|
{
|
||||||
EnsureIsValid();
|
if (EnsureIsValid()==false)
|
||||||
|
return;
|
||||||
|
|
||||||
CGRect r = CGRectMake( (CGFloat) 0.0 , (CGFloat) 0.0 , (CGFloat) w , (CGFloat) h );
|
CGRect r = CGRectMake( (CGFloat) 0.0 , (CGFloat) 0.0 , (CGFloat) w , (CGFloat) h );
|
||||||
CGContextSaveGState( m_cgContext );
|
CGContextSaveGState( m_cgContext );
|
||||||
CGContextTranslateCTM( m_cgContext,(CGFloat) x ,(CGFloat) (y + h) );
|
CGContextTranslateCTM( m_cgContext,(CGFloat) x ,(CGFloat) (y + h) );
|
||||||
CGContextScaleCTM( m_cgContext, 1, -1 );
|
CGContextScaleCTM( m_cgContext, 1, -1 );
|
||||||
#if wxOSX_USE_CARBON
|
#if wxOSX_USE_COCOA_OR_CARBON
|
||||||
PlotIconRefInContext( m_cgContext , &r , kAlignNone , kTransformNone ,
|
PlotIconRefInContext( m_cgContext , &r , kAlignNone , kTransformNone ,
|
||||||
NULL , kPlotIconRefNormalFlags , MAC_WXHICON( icon.GetHICON() ) );
|
NULL , kPlotIconRefNormalFlags , icon.GetHICON() );
|
||||||
#endif
|
#endif
|
||||||
CGContextRestoreGState( m_cgContext );
|
CGContextRestoreGState( m_cgContext );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxMacCoreGraphicsContext::PushState()
|
void wxMacCoreGraphicsContext::PushState()
|
||||||
{
|
{
|
||||||
EnsureIsValid();
|
if (EnsureIsValid()==false)
|
||||||
|
return;
|
||||||
|
|
||||||
CGContextSaveGState( m_cgContext );
|
CGContextSaveGState( m_cgContext );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxMacCoreGraphicsContext::PopState()
|
void wxMacCoreGraphicsContext::PopState()
|
||||||
{
|
{
|
||||||
EnsureIsValid();
|
if (EnsureIsValid()==false)
|
||||||
|
return;
|
||||||
|
|
||||||
CGContextRestoreGState( m_cgContext );
|
CGContextRestoreGState( m_cgContext );
|
||||||
}
|
}
|
||||||
@@ -2001,7 +2021,9 @@ void wxMacCoreGraphicsContext::DoDrawText( const wxString &str, wxDouble x, wxDo
|
|||||||
{
|
{
|
||||||
wxCHECK_RET( !m_font.IsNull(), wxT("wxMacCoreGraphicsContext::DrawText - no valid font set") );
|
wxCHECK_RET( !m_font.IsNull(), wxT("wxMacCoreGraphicsContext::DrawText - no valid font set") );
|
||||||
|
|
||||||
EnsureIsValid();
|
if (EnsureIsValid()==false)
|
||||||
|
return;
|
||||||
|
|
||||||
#if wxOSX_USE_CORE_TEXT
|
#if wxOSX_USE_CORE_TEXT
|
||||||
if ( UMAGetSystemVersion() >= 0x1050 )
|
if ( UMAGetSystemVersion() >= 0x1050 )
|
||||||
{
|
{
|
||||||
@@ -2059,7 +2081,9 @@ void wxMacCoreGraphicsContext::DoDrawRotatedText(const wxString &str,
|
|||||||
{
|
{
|
||||||
wxCHECK_RET( !m_font.IsNull(), wxT("wxMacCoreGraphicsContext::DrawText - no valid font set") );
|
wxCHECK_RET( !m_font.IsNull(), wxT("wxMacCoreGraphicsContext::DrawText - no valid font set") );
|
||||||
|
|
||||||
EnsureIsValid();
|
if (EnsureIsValid()==false)
|
||||||
|
return;
|
||||||
|
|
||||||
#if wxOSX_USE_CORE_TEXT
|
#if wxOSX_USE_CORE_TEXT
|
||||||
if ( UMAGetSystemVersion() >= 0x1050 )
|
if ( UMAGetSystemVersion() >= 0x1050 )
|
||||||
{
|
{
|
||||||
|
@@ -53,9 +53,9 @@ CGContextRef wxOSXGetContextFromCurrentNSContext()
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxOSXLockFocus( WXWidget view)
|
bool wxOSXLockFocus( WXWidget view)
|
||||||
{
|
{
|
||||||
[view lockFocusIfCanDraw];
|
return [view lockFocusIfCanDraw];
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxOSXUnlockFocus( WXWidget view)
|
void wxOSXUnlockFocus( WXWidget view)
|
||||||
|
Reference in New Issue
Block a user