]> git.saurik.com Git - wxWidgets.git/commitdiff
cleanup, going private with platform specific that is only needed at one place
authorStefan Csomor <csomor@advancedconcepts.ch>
Wed, 28 Nov 2007 10:51:16 +0000 (10:51 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Wed, 28 Nov 2007 10:51:16 +0000 (10:51 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50309 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/carbon/bitmap.cpp
src/mac/carbon/graphics.cpp
src/mac/carbon/mdi.cpp
src/mac/carbon/metafile.cpp
src/mac/carbon/textctrl.cpp
src/mac/carbon/toplevel.cpp
src/mac/carbon/uma.cpp
src/mac/carbon/utils.cpp

index b14a7a6be6f15566f414331f05a13124ff9da2a7..3304fdacec1bf4dd1119891e506574a5fbd3c5c5 100644 (file)
@@ -606,17 +606,6 @@ PicHandle wxBitmapRefData::GetPictHandle()
     return m_pictHandle ;
 }
 
-void wxMacMemoryBufferReleaseProc(void *info, const void *data, size_t size);
-
-void wxMacMemoryBufferReleaseProc(void *info, const void *data, size_t WXUNUSED(size))
-{
-    wxMemoryBuffer* membuf = (wxMemoryBuffer*) info ;
-
-    wxASSERT( data == membuf->GetData() ) ;
-
-    delete membuf ;
-}
-
 CGImageRef wxBitmapRefData::CreateCGImage() const
 {
     wxASSERT( m_ok ) ;
@@ -644,16 +633,15 @@ CGImageRef wxBitmapRefData::CreateCGImage() const
             int w = m_width ;
             int h = m_height ;
             CGImageAlphaInfo alphaInfo = kCGImageAlphaNoneSkipFirst ;
-            wxMemoryBuffer* membuf = NULL ;
+            wxMemoryBuffer membuf;
             
             if ( m_bitmapMask )
             {
                 alphaInfo = kCGImageAlphaFirst ;
-                membuf = new wxMemoryBuffer( imageSize ) ;
-                memcpy( membuf->GetData() , dataBuffer , imageSize ) ;
+                unsigned char *destalphastart = (unsigned char*) membuf.GetWriteBuf( imageSize ) ;
+                memcpy( destalphastart , dataBuffer , imageSize ) ;
                 unsigned char *sourcemaskstart = (unsigned char *) m_bitmapMask->GetRawAccess() ;
                 int maskrowbytes = m_bitmapMask->GetBytesPerRow() ;
-                unsigned char *destalphastart = (unsigned char *) membuf->GetData() ;
                 for ( int y = 0 ; y < h ; ++y , destalphastart += m_bytesPerRow, sourcemaskstart += maskrowbytes)
                 {
                     unsigned char *sourcemask = sourcemaskstart ;
@@ -663,6 +651,7 @@ CGImageRef wxBitmapRefData::CreateCGImage() const
                         *destalpha = 0xFF - *sourcemask ;
                     }
                 }
+                membuf.UngetWriteBuf( imageSize );
             }
             else
             {
@@ -675,35 +664,37 @@ CGImageRef wxBitmapRefData::CreateCGImage() const
 #endif
                 }
                 
-                membuf = new wxMemoryBuffer( m_memBuf ) ;
+                membuf = m_memBuf;
             }
             
             CGDataProviderRef dataProvider = NULL ;
             if ( m_depth == 1 )
             {
-                wxMemoryBuffer* maskBuf = new wxMemoryBuffer( m_width * m_height );
-                unsigned char * maskBufData = (unsigned char *) maskBuf->GetData();
-                unsigned char * bufData = (unsigned char *) membuf->GetData() ;
+                // TODO CHECK ALIGNMENT
+                wxMemoryBuffer maskBuf;
+                unsigned char * maskBufData = (unsigned char*) maskBuf.GetWriteBuf( m_width * m_height );
+                unsigned char * bufData = (unsigned char *) membuf.GetData() ;
                 // copy one color component
-                for( int i = 0 ; i < m_width * m_height ; ++i )
-                    maskBufData[i] = bufData[i*4+3];
+                size_t i = 0;
+                for( int y = 0 ; y < m_height ; bufData+= m_bytesPerRow, ++y )
+                {
+                    unsigned char *bufDataIter = bufData+3;
+                    for ( int x = 0 ; x < m_width ; bufDataIter += 4, ++x, ++i )
+                    {
+                        maskBufData[i] = *bufDataIter;
+                    }
+                }
+                maskBuf.UngetWriteBuf( m_width * m_height );
+                
                 dataProvider =
-                    CGDataProviderCreateWithData(
-                                                 maskBuf , (const void *) maskBufData , m_width * m_height,
-                                                 wxMacMemoryBufferReleaseProc );
-                // as we are now passing the mask buffer to the data provider, we have
-                // to release the membuf ourselves
-                delete membuf ;
+                    wxMacCGDataProviderCreateWithMemoryBuffer( maskBuf );
                 
                 image = ::CGImageMaskCreate( w, h, 8, 8, m_width , dataProvider, NULL, false );
             }
             else
             {
                 CGColorSpaceRef colorSpace = wxMacGetGenericRGBColorSpace();
-                dataProvider =
-                    CGDataProviderCreateWithData(
-                                                 membuf , (const void *)membuf->GetData() , imageSize,
-                                                 wxMacMemoryBufferReleaseProc );
+                dataProvider = wxMacCGDataProviderCreateWithMemoryBuffer( membuf );
                 image =
                     ::CGImageCreate(
                                     w, h, 8 , 32 , m_bytesPerRow , colorSpace, alphaInfo ,
index 2f284a1abacc5dbb49801589f6fa9af4106f9f41..6282651f3e18dbf8d80abc7b2508c3d0690d4107 100644 (file)
@@ -2221,3 +2221,67 @@ wxGraphicsFont wxMacCoreGraphicsRenderer::CreateFont( const wxFont &font , const
         return wxNullGraphicsFont;
 }
 
+//
+// CoreGraphics Helper Methods
+//
+
+// Data Providers and Consumers
+
+size_t UMAPutBytesCFRefCallback( void *info, const void *bytes, size_t count )
+{
+    CFMutableDataRef data = (CFMutableDataRef) info;
+    if ( data )
+    {
+        CFDataAppendBytes( data, (const UInt8*) bytes, count );
+    }
+    return count;
+}
+
+void wxMacReleaseCFDataProviderCallback(void *info,
+                                      const void *WXUNUSED(data),
+                                      size_t WXUNUSED(count))
+{
+    if ( info )
+        CFRelease( (CFDataRef) info );
+}
+
+void wxMacReleaseCFDataConsumerCallback( void *info )
+{
+    if ( info )
+        CFRelease( (CFDataRef) info );
+}
+
+CGDataProviderRef wxMacCGDataProviderCreateWithCFData( CFDataRef data )
+{
+    if ( data == NULL )
+        return NULL;
+
+    return CGDataProviderCreateWithCFData( data );
+}
+
+CGDataConsumerRef wxMacCGDataConsumerCreateWithCFData( CFMutableDataRef data )
+{
+    if ( data == NULL )
+        return NULL;
+
+    return CGDataConsumerCreateWithCFData( data );
+}
+
+void wxMacReleaseMemoryBufferProviderCallback(void *info, const void *data, size_t WXUNUSED(size))
+{
+    wxMemoryBuffer* membuf = (wxMemoryBuffer*) info ;
+
+    wxASSERT( data == membuf->GetData() ) ;
+
+    delete membuf ;
+}
+
+CGDataProviderRef wxMacCGDataProviderCreateWithMemoryBuffer( const wxMemoryBuffer& buf )
+{
+    wxMemoryBuffer* b = new wxMemoryBuffer( buf );
+    if ( b->GetDataLen() == 0 )
+        return NULL;
+        
+    return CGDataProviderCreateWithData( b , (const void *) b->GetData() , b->GetDataLen() ,
+                                                 wxMacReleaseMemoryBufferProviderCallback );
+}
\ No newline at end of file
index 324c8b22bb6265e7e0243a577fb33bb0dcddcdbb..58a00ae186b50cad1700e7d0b280d047bab1212a 100644 (file)
@@ -48,6 +48,37 @@ static const int IDM_WINDOWICONS = 4003;
 static const int IDM_WINDOWNEXT = 4004;
 static const int IDM_WINDOWTILEVERT = 4005;
 
+// others
+
+void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
+{
+#if 1 // TODO REMOVE
+    if ( inWindowRef )
+    {
+//        bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
+//        if ( inActivate != isHighlighted )
+#ifndef __LP64__
+        GrafPtr port ;
+        GetPort( &port ) ;
+        SetPortWindowPort( inWindowRef ) ;
+#endif
+        HiliteWindow( inWindowRef , inActivate ) ;
+        ControlRef control = NULL ;
+        ::GetRootControl( inWindowRef , &control ) ;
+        if ( control )
+        {
+            if ( inActivate )
+                ::ActivateControl( control ) ;
+            else
+                ::DeactivateControl( control ) ;
+        }
+#ifndef __LP64__
+        SetPort( port ) ;
+#endif
+    }
+#endif
+}
+
 // ----------------------------------------------------------------------------
 // Parent frame
 // ----------------------------------------------------------------------------
index 03ba23bfe62cec67ae62c98ff359bca1f8d897c9..dee2ea82912d0ddff8cbd7404a3f554d1c3bb8d8 100644 (file)
@@ -100,7 +100,7 @@ wxMetafileRefData::wxMetafileRefData( int width, int height)
 
     CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0);
     m_data.reset(data);
-    CGDataConsumerRef dataConsumer = UMACGDataConsumerCreateWithCFData(data);
+    CGDataConsumerRef dataConsumer = wxMacCGDataConsumerCreateWithCFData(data);
     m_context = CGPDFContextCreate( dataConsumer, (width != 0 && height != 0) ? &r : NULL , NULL );
     CGDataConsumerRelease( dataConsumer );
     if ( m_context )
@@ -140,7 +140,7 @@ void wxMetafileRefData::Close()
 
 void wxMetafileRefData::UpdateDocumentFromData()
 {
-    wxCFRef<CGDataProviderRef> provider(UMACGDataProviderCreateWithCFData(m_data));
+    wxCFRef<CGDataProviderRef> provider(wxMacCGDataProviderCreateWithCFData(m_data));
     m_pdfDoc.reset(CGPDFDocumentCreateWithProvider(provider));
     if ( m_pdfDoc != NULL )
     {
@@ -209,7 +209,7 @@ void wxMetafile::SetPICT(void* pictHandle)
     Handle picHandle = (Handle) pictHandle;
     HLock(picHandle);
     CFDataRef data = CFDataCreateWithBytesNoCopy( kCFAllocatorDefault, (const UInt8*) *picHandle, GetHandleSize(picHandle), kCFAllocatorNull);
-    wxCFRef<CGDataProviderRef> provider(UMACGDataProviderCreateWithCFData(data));
+    wxCFRef<CGDataProviderRef> provider(wxMacCGDataProviderCreateWithCFData(data));
     QDPictRef pictRef = QDPictCreateWithProvider(provider);
     CGRect rect = QDPictGetBounds(pictRef);
     m_refData = new wxMetafileRefData(wx_static_cast(int, rect.size.width),
index 84caa012ba45ddfd2021eda25f7aab397005a6b5..43d5d64a8cbc9b8445638ad9beeccec4c5ef6cd0 100644 (file)
@@ -2398,7 +2398,7 @@ void wxMacMLTEClassicControl::MacUpdatePosition()
         return ;
 
     Rect bounds ;
-    UMAGetControlBoundsInWindowCoords( m_controlRef, &bounds );
+    GetRectInWindowCoords( &bounds );
 
     wxRect visRect = textctrl->MacGetClippedClientRect() ;
     Rect visBounds = { visRect.y , visRect.x , visRect.y + visRect.height , visRect.x + visRect.width } ;
@@ -2826,7 +2826,7 @@ OSStatus wxMacMLTEClassicControl::DoCreate()
     SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneFocusProcTag, sizeof(gTPFocusProc), &gTPFocusProc);
 
     // calculate the rectangles used by the control
-    UMAGetControlBoundsInWindowCoords( m_controlRef, &bounds );
+    GetRectInWindowCoords( &bounds );
 
     m_txnControlBounds = bounds ;
     m_txnVisBounds = bounds ;
index 6a9fb50ef1f9134fcab15779ebe71ef43b89e19f..31e507961bcb2a4c4fb22dad58e84925247805ce 100644 (file)
@@ -390,59 +390,6 @@ void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent )
     }
 }
 
-ControlRef wxMacFindSubControl( wxTopLevelWindowMac* toplevelWindow, const Point& location , ControlRef superControl , ControlPartCode *outPart )
-{
-    if ( superControl )
-    {
-        UInt16 childrenCount = 0 ;
-        ControlHandle sibling ;
-        Rect r ;
-        OSStatus err = CountSubControls( superControl , &childrenCount ) ;
-        if ( err == errControlIsNotEmbedder )
-            return NULL ;
-
-        wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
-
-        for ( UInt16 i = childrenCount ; i >=1  ; --i )
-        {
-            err = GetIndexedSubControl( superControl , i , & sibling ) ;
-            if ( err == errControlIsNotEmbedder )
-                return NULL ;
-
-            wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
-            if ( IsControlVisible( sibling ) )
-            {
-                UMAGetControlBoundsInWindowCoords( sibling , &r ) ;
-                if ( MacPtInRect( location , &r ) )
-                {
-                    ControlHandle child = wxMacFindSubControl( toplevelWindow , location , sibling , outPart ) ;
-                    if ( child )
-                    {
-                        return child ;
-                    }
-                    else
-                    {
-                        Point testLocation = location ;
-
-                        if ( toplevelWindow )
-                        {
-                            testLocation.h -= r.left ;
-                            testLocation.v -= r.top ;
-                        }
-
-                        *outPart = TestControl( sibling , testLocation ) ;
-
-                        return sibling ;
-                    }
-                }
-            }
-        }
-    }
-
-    return NULL ;
-}
-
-
 #define NEW_CAPTURE_HANDLING 1
 
 pascal OSStatus
@@ -1068,9 +1015,9 @@ bool wxTopLevelWindowMac::SetBackgroundColour(const wxColour& col )
     if ( !wxTopLevelWindowBase::SetBackgroundColour(col) && m_hasBgCol )
         return false ;
     
-    if ( col == wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) )
+    if ( col == wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) || col == wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground)) )
         SetThemeWindowBackground( (WindowRef) m_macWindow,  kThemeBrushDocumentWindowBackground, false ) ;
-    else if ( col == wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) )
+    else if ( col == wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) || col == wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive)) )
         SetThemeWindowBackground( (WindowRef) m_macWindow,  kThemeBrushDialogBackgroundActive, false ) ;
     // TODO BETTER THEME SUPPORT
     return true;
index 7fcd7abee38414194824ea570bebc76ba6d4a93e..47a6fb92c8ac7da84a0ef1559b66ccdaa7f79c3b 100644 (file)
@@ -57,32 +57,6 @@ void UMAInitToolbox( UInt16 WXUNUSED(inMoreMastersCalls),
 #endif
 }
 
-// process manager
-long UMAGetProcessMode()
-{
-    OSErr err ;
-    ProcessInfoRec processinfo;
-    ProcessSerialNumber procno ;
-
-    procno.highLongOfPSN = 0 ;
-    procno.lowLongOfPSN = kCurrentProcess ;
-    processinfo.processInfoLength = sizeof(ProcessInfoRec);
-    processinfo.processName = NULL;
-#ifndef __LP64__
-    processinfo.processAppSpec = NULL;
-#endif
-
-    err = ::GetProcessInformation( &procno , &processinfo ) ;
-    wxASSERT( err == noErr ) ;
-
-    return processinfo.processMode ;
-}
-
-bool UMAGetProcessModeDoesActivateOnFGSwitch()
-{
-    return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ;
-}
-
 // menu manager
 
 #if wxMAC_USE_COCOA == 0
@@ -339,108 +313,4 @@ OSStatus UMAGetHelpMenuDontCreate(
 
 #endif
 
-// window manager
-
-#if wxMAC_USE_QUICKDRAW
-
-void UMAActivateControl( ControlRef inControl )
-{
-    ::ActivateControl( inControl ) ;
-}
-
-void UMADeactivateControl( ControlRef inControl )
-{
-    ::DeactivateControl( inControl ) ;
-}
-
-// others
-
-void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
-{
-#if 1 // TODO REMOVE
-    if ( inWindowRef )
-    {
-//        bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
-//        if ( inActivate != isHighlighted )
-#ifndef __LP64__
-        GrafPtr port ;
-        GetPort( &port ) ;
-        SetPortWindowPort( inWindowRef ) ;
-#endif
-        HiliteWindow( inWindowRef , inActivate ) ;
-        ControlRef control = NULL ;
-        ::GetRootControl( inWindowRef , &control ) ;
-        if ( control )
-        {
-            if ( inActivate )
-                UMAActivateControl( control ) ;
-            else
-                UMADeactivateControl( control ) ;
-        }
-#ifndef __LP64__
-        SetPort( port ) ;
-#endif
-    }
-#endif
-}
-
-Rect * UMAGetControlBoundsInWindowCoords( ControlRef theControl, Rect *bounds )
-{
-    GetControlBounds( theControl , bounds ) ;
-    
-    WindowRef tlwref = GetControlOwner( theControl ) ;
-    
-    wxTopLevelWindowMac* tlwwx = wxFindWinFromMacWindow( tlwref ) ;
-    if ( tlwwx != NULL )
-    {
-        ControlRef rootControl = tlwwx->GetPeer()->GetControlRef() ;
-        HIPoint hiPoint = CGPointMake( 0 , 0 ) ;
-        HIViewConvertPoint( &hiPoint , HIViewGetSuperview(theControl) , rootControl ) ;
-        OffsetRect( bounds , (short) hiPoint.x , (short) hiPoint.y ) ;
-    }
-    
-    return bounds ;
-}
-
-#endif
-
-size_t UMAPutBytesCFRefCallback( void *info, const void *bytes, size_t count )
-{
-    CFMutableDataRef data = (CFMutableDataRef) info;
-    if ( data )
-    {
-        CFDataAppendBytes( data, (const UInt8*) bytes, count );
-    }
-    return count;
-}
-
-void UMAReleaseCFDataProviderCallback(void *info,
-                                      const void *WXUNUSED(data),
-                                      size_t WXUNUSED(count))
-{
-    if ( info )
-        CFRelease( (CFDataRef) info );
-}
-
-void UMAReleaseCFDataConsumerCallback( void *info )
-{
-    if ( info )
-        CFRelease( (CFDataRef) info );
-}
-
-CGDataProviderRef UMACGDataProviderCreateWithCFData( CFDataRef data )
-{
-    if ( data == NULL )
-        return NULL;
-
-    return CGDataProviderCreateWithCFData( data );
-}
-
-CGDataConsumerRef UMACGDataConsumerCreateWithCFData( CFMutableDataRef data )
-{
-    if ( data == NULL )
-        return NULL;
-
-    return CGDataConsumerCreateWithCFData( data );
-}
 #endif  // wxUSE_GUI
index 8db3bdc87fc55a9a65dfcc8a84b0193ad132c1b7..5cbb3089a0c07fc7c4b794d8d9918771a0351757 100644 (file)
@@ -823,7 +823,18 @@ void wxMacControl::GetRect( Rect *r )
 
 void wxMacControl::GetRectInWindowCoords( Rect *r )
 {
-    UMAGetControlBoundsInWindowCoords( m_controlRef , r );
+    GetControlBounds( m_controlRef , r ) ;
+    
+    WindowRef tlwref = GetControlOwner( m_controlRef ) ;
+    
+    wxTopLevelWindowMac* tlwwx = wxFindWinFromMacWindow( tlwref ) ;
+    if ( tlwwx != NULL )
+    {
+        ControlRef rootControl = tlwwx->GetPeer()->GetControlRef() ;
+        HIPoint hiPoint = CGPointMake( 0 , 0 ) ;
+        HIViewConvertPoint( &hiPoint , HIViewGetSuperview(m_controlRef) , rootControl ) ;
+        OffsetRect( r , (short) hiPoint.x , (short) hiPoint.y ) ;
+    }
 }
 
 void wxMacControl::GetBestRect( Rect *r )