]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/carbon/graphics.cpp
Fix hangups when using sockets under OS X.
[wxWidgets.git] / src / osx / carbon / graphics.cpp
index e81a541cb53afe34139a170159b1c5fbbc603b4c..b3fc827537ebeb18f4ddf7d9146868389be4e196 100644 (file)
@@ -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.GetCTFont());
+    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 ; }
 
@@ -867,19 +869,19 @@ wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* rendere
             kATSUSizeTag ,
             kATSUColorTag ,
     };
-    ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
+    ByteCount atsuSizes[WXSIZEOF(atsuTags)] =
     {
             sizeof( Fixed ) ,
             sizeof( RGBColor ) ,
     };
-    ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
+    ATSUAttributeValuePtr atsuValues[WXSIZEOF(atsuTags)] =
     {
             &atsuSize ,
             &atsuColor ,
     };
 
     status = ::ATSUSetAttributes(
-        m_macATSUIStyle, sizeof(atsuTags) / sizeof(ATSUAttributeTag) ,
+        m_macATSUIStyle, WXSIZEOF(atsuTags),
         atsuTags, atsuSizes, atsuValues);
 
     wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") );
@@ -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,17 +1598,24 @@ 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();
-            wxASSERT_MSG( m_cgContext != NULL, _T("Unable to retrieve drawing context from View"));
+            m_cgContext = wxOSXGetContextFromCurrentContext();
+            wxASSERT_MSG( m_cgContext != NULL, wxT("Unable to retrieve drawing context from View"));
         }
         else
         {
             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
@@ -2016,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
         }
@@ -2165,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<CFNumberRef> underlined( CFNumberCreate(NULL, kCFNumberSInt32Type, &ustyle) );
@@ -2255,15 +2268,15 @@ void wxMacCoreGraphicsContext::DoDrawRotatedText(const wxString &str,
             {
                 kATSULineRotationTag ,
             };
-            ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
+            ByteCount atsuSizes[WXSIZEOF(atsuTags)] =
             {
                 sizeof( Fixed ) ,
             };
-            ATSUAttributeValuePtr    atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
+            ATSUAttributeValuePtr    atsuValues[WXSIZEOF(atsuTags)] =
             {
                 &atsuAngle ,
             };
-            status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags) / sizeof(ATSUAttributeTag),
+            status = ::ATSUSetLayoutControls(atsuLayout , WXSIZEOF(atsuTags),
                                              atsuTags, atsuSizes, atsuValues );
         }
 
@@ -2272,15 +2285,15 @@ void wxMacCoreGraphicsContext::DoDrawRotatedText(const wxString &str,
             {
                 kATSUCGContextTag ,
             };
-            ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
+            ByteCount atsuSizes[WXSIZEOF(atsuTags)] =
             {
                 sizeof( CGContextRef ) ,
             };
-            ATSUAttributeValuePtr    atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
+            ATSUAttributeValuePtr    atsuValues[WXSIZEOF(atsuTags)] =
             {
                 &m_cgContext ,
             };
-            status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags) / sizeof(ATSUAttributeTag),
+            status = ::ATSUSetLayoutControls(atsuLayout , WXSIZEOF(atsuTags),
                                              atsuTags, atsuSizes, atsuValues );
         }
 
@@ -2342,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  };
@@ -2437,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  };