X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bf02a7f9761ce9c0a1279ae958a0e5d53f603e15..d58526d55433162cef8ad2ed7f422689862c3019:/src/osx/carbon/graphics.cpp diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index bb499d3df2..4a1e139f31 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -72,10 +72,12 @@ int UMAGetSystemVersion() #endif #if wxOSX_USE_COCOA_OR_IPHONE -extern CGContextRef wxOSXGetContextFromCurrentNSContext() ; +extern CGContextRef wxOSXGetContextFromCurrentContext() ; +#if wxOSX_USE_COCOA extern bool wxOSXLockFocus( WXWidget view) ; extern void wxOSXUnlockFocus( WXWidget view) ; #endif +#endif #if 1 // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 @@ -171,7 +173,7 @@ CGColorRef wxMacCreateCGColor( const wxColour& col ) CTFontRef wxMacCreateCTFont( const wxFont& font ) { #ifdef __WXMAC__ - return wxCFRetain((CTFontRef) font.MacGetCTFont()); + return wxCFRetain((CTFontRef) font.OSXGetCTFont()); #else return CTFontCreateWithName( wxCFStringRef( font.GetFaceName(), wxLocale::GetSystemEncoding() ) , font.GetPointSize() , NULL ); #endif @@ -815,7 +817,7 @@ public: virtual ATSUStyle GetATSUStyle() { return m_macATSUIStyle; } #endif #if wxOSX_USE_CORE_TEXT - CTFontRef GetCTFont() const { return m_ctFont ; } + CTFontRef OSXGetCTFont() const { return m_ctFont ; } #endif wxColour GetColour() const { return m_colour ; } @@ -853,13 +855,13 @@ wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* rendere OSStatus status = noErr; m_macATSUIStyle = NULL; - status = ATSUCreateAndcopyStyle( (ATSUStyle) font.MacGetATSUStyle() , &m_macATSUIStyle ); + status = ATSUCreateAndCopyStyle( (ATSUStyle) font.MacGetATSUStyle() , &m_macATSUIStyle ); wxASSERT_MSG( status == noErr, wxT("couldn't create ATSU style") ); // we need the scale here ... - Fixed atsuSize = IntToFixed( int( 1 * font.MacGetFontSize()) ); + Fixed atsuSize = IntToFixed( int( 1 * font.GetPointSize()) ); RGBColor atsuColor ; col.GetRGBColor( &atsuColor ); ATSUAttributeTag atsuTags[] = @@ -1519,12 +1521,14 @@ wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer* renderer #if wxOSX_USE_COCOA_OR_IPHONE m_view = window->GetHandle(); - if ( !((wxWidgetCocoaImpl*) window->GetPeer())->IsFlipped() ) +#if wxOSX_USE_COCOA + if ( ! window->GetPeer()->IsFlipped() ) { m_windowTransform = CGAffineTransformMakeTranslation( 0 , m_height ); m_windowTransform = CGAffineTransformScale( m_windowTransform , 1 , -1 ); } else +#endif { m_windowTransform = CGAffineTransformIdentity; } @@ -1594,10 +1598,10 @@ bool wxMacCoreGraphicsContext::EnsureIsValid() if (m_invisible) return false; -#if wxOSX_USE_COCOA_OR_IPHONE +#if wxOSX_USE_COCOA if ( wxOSXLockFocus(m_view) ) { - m_cgContext = wxOSXGetContextFromCurrentNSContext(); + m_cgContext = wxOSXGetContextFromCurrentContext(); wxASSERT_MSG( m_cgContext != NULL, _T("Unable to retrieve drawing context from View")); } else @@ -1605,6 +1609,13 @@ bool wxMacCoreGraphicsContext::EnsureIsValid() m_invisible = true; } #endif +#if wxOSX_USE_IPHONE + m_cgContext = wxOSXGetContextFromCurrentContext(); + if ( m_cgContext == NULL ) + { + m_invisible = true; + } +#endif #if wxOSX_USE_CARBON OSStatus status = QDBeginCGContext( GetWindowPort( m_windowRef ) , &m_cgContext ); if ( status != noErr ) @@ -1617,6 +1628,7 @@ bool wxMacCoreGraphicsContext::EnsureIsValid() CGContextConcatCTM( m_cgContext, m_windowTransform ); CGContextSaveGState( m_cgContext ); m_contextSynthesized = true; +#if wxOSX_USE_COCOA_OR_CARBON if ( m_clipRgn.get() ) { // the clip region is in device coordinates, so we convert this again to user coordinates @@ -1635,6 +1647,7 @@ bool wxMacCoreGraphicsContext::EnsureIsValid() CGContextClip( m_cgContext ); } } +#endif CGContextSaveGState( m_cgContext ); #if 0 // turn on for debugging of clientdc @@ -1698,7 +1711,6 @@ bool wxMacCoreGraphicsContext::SetCompositionMode(wxCompositionMode op) return true; #if wxOSX_USE_COCOA_OR_CARBON -#if 1 // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 if ( UMAGetSystemVersion() < 0x1060 ) { CGCompositeOperation cop = kCGCompositeOperationSourceOver; @@ -1738,9 +1750,11 @@ bool wxMacCoreGraphicsContext::SetCompositionMode(wxCompositionMode op) case wxCOMPOSITION_XOR: cop = kCGCompositeOperationXOR; break; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 case wxCOMPOSITION_ADD: mode = kCGBlendModePlusLighter ; break; +#endif default: return false; } @@ -1749,9 +1763,9 @@ bool wxMacCoreGraphicsContext::SetCompositionMode(wxCompositionMode op) else CGContextSetBlendMode(m_cgContext, mode); } - else -#endif #endif +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 + else { CGBlendMode mode = kCGBlendModeNormal; switch( op ) @@ -1798,13 +1812,14 @@ bool wxMacCoreGraphicsContext::SetCompositionMode(wxCompositionMode op) } CGContextSetBlendMode(m_cgContext, mode); } +#endif return true; } void wxMacCoreGraphicsContext::BeginLayer(wxDouble opacity) { CGContextSaveGState(m_cgContext); - CGContextSetAlpha(m_cgContext, opacity); + CGContextSetAlpha(m_cgContext, (CGFloat) opacity); CGContextBeginTransparencyLayer(m_cgContext, 0); } @@ -2014,7 +2029,7 @@ void wxMacCoreGraphicsContext::SetNativeContext( CGContextRef cg ) #if wxOSX_USE_CARBON QDEndCGContext( GetWindowPort( m_windowRef ) , &m_cgContext); #endif -#if wxOSX_USE_COCOA_OR_IPHONE +#if wxOSX_USE_COCOA wxOSXUnlockFocus(m_view); #endif } @@ -2163,7 +2178,7 @@ void wxMacCoreGraphicsContext::DoDrawText( const wxString &str, wxDouble x, wxDo { wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData(); wxCFStringRef text(str, wxLocale::GetSystemEncoding() ); - CTFontRef font = fref->GetCTFont(); + CTFontRef font = fref->OSXGetCTFont(); CGColorRef col = wxMacCreateCGColor( fref->GetColour() ); CTUnderlineStyle ustyle = fref->GetUnderlined() ? kCTUnderlineStyleSingle : kCTUnderlineStyleNone ; wxCFRef underlined( CFNumberCreate(NULL, kCFNumberSInt32Type, &ustyle) ); @@ -2177,7 +2192,7 @@ void wxMacCoreGraphicsContext::DoDrawText( const wxString &str, wxDouble x, wxDo y += CTFontGetAscent(font); CGContextSaveGState(m_cgContext); - CGContextTranslateCTM(m_cgContext, x, y); + CGContextTranslateCTM(m_cgContext, (CGFloat) x, (CGFloat) y); CGContextScaleCTM(m_cgContext, 1, -1); CGContextSetTextPosition(m_cgContext, 0, 0); CTLineDraw( line, m_cgContext ); @@ -2340,7 +2355,7 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid if ( UMAGetSystemVersion() >= 0x1050 ) { wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData(); - CTFontRef font = fref->GetCTFont(); + CTFontRef font = fref->OSXGetCTFont(); wxCFStringRef text(str, wxLocale::GetSystemEncoding() ); CFStringRef keys[] = { kCTFontAttributeName }; @@ -2350,7 +2365,8 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid wxCFRef attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, attributes) ); wxCFRef line( CTLineCreateWithAttributedString(attrtext) ); - CGFloat w, a, d, l; + double w; + CGFloat a, d, l; w = CTLineGetTypographicBounds(line, &a, &d, &l) ; @@ -2434,7 +2450,7 @@ void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString& text, wxArr #if wxOSX_USE_CORE_TEXT { wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData(); - CTFontRef font = fref->GetCTFont(); + CTFontRef font = fref->OSXGetCTFont(); wxCFStringRef t(text, wxLocale::GetSystemEncoding() ); CFStringRef keys[] = { kCTFontAttributeName }; @@ -2701,6 +2717,7 @@ wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateContextFromNativeWindow( vo #if wxOSX_USE_CARBON return new wxMacCoreGraphicsContext(this,(WindowRef)window); #else + wxUnusedVar(window); return NULL; #endif }