]> git.saurik.com Git - wxWidgets.git/commitdiff
scaling for 24x24 and 64x64 sizes
authorStefan Csomor <csomor@advancedconcepts.ch>
Wed, 23 Feb 2005 18:18:33 +0000 (18:18 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Wed, 23 Feb 2005 18:18:33 +0000 (18:18 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32333 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/carbon/bitmap.cpp

index 3e1761ba738643f75645919a619bb9e365899795..24cb80549f92a936b19e03539992223916790dad 100644 (file)
@@ -56,28 +56,47 @@ void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bi
     memset( info , 0 , sizeof(ControlButtonContentInfo) ) ;
     if ( bitmap.Ok() )
     {
-        wxBitmapRefData * bmap = (wxBitmapRefData*) ( bitmap.GetRefData()) ;
+        wxBitmapRefData * bmap = bitmap.GetBitmapData() ;
         if ( bmap == NULL )
             return ;
             
-        if ( bmap->HasNativeSize() )
+        if ( ( bmap->HasNativeSize() && forceType == 0 ) || forceType == kControlContentIconRef )
         {
+            wxBitmap scaleBmp ;
+            
+            wxBitmapRefData* bmp = bmap ;
+            
+            if ( !bmap->HasNativeSize() )
+            {
+                // as PICT conversion will only result in a 16x16 icon, let's attempt
+                // a few scales for better results 
+                
+                int w = bitmap.GetWidth() ;
+                int h = bitmap.GetHeight() ;
+                int sz = wxMax( w , h ) ;
+                if ( sz == 24 || sz == 64)
+                {
+                    scaleBmp = wxBitmap( bitmap.ConvertToImage().Scale( w * 2 , h * 2 ) ) ;
+                    bmp = scaleBmp.GetBitmapData() ;
+                }
+            }
+            
             info->contentType = kControlContentIconRef ;
-            info->u.iconRef = bmap->GetIconRef() ;
+            info->u.iconRef = bmp->GetIconRef() ;
+            AcquireIconRef( info->u.iconRef ) ;
+        }
+#if wxMAC_USE_CORE_GRAPHICS              
+        else if ( forceType == kControlContentCGImageRef )
+        {
+            info->contentType = kControlContentCGImageRef ;
+            info->u.imageRef = (CGImageRef) bmap->CGImageCreate() ;
         }
+#endif
         else
         {
             info->contentType = kControlContentPictHandle ;
             info->u.picture = bmap->GetPictHandle() ;
         }
-#if wxMAC_USE_CORE_GRAPHICS              
-        /*
-            // only on 10.4 more controls will accept a CGImage
-        
-            info->contentType = kControlContentCGImageRef ;
-            info->u.imageRef = (CGImageRef) bmap->CGImageCreate() ;
-        */
-#endif
     }
 }
 
@@ -85,11 +104,11 @@ void wxMacReleaseBitmapButton( ControlButtonContentInfo*info )
 {
     if ( info->contentType == kControlContentIconRef )
     {
-        // as the bitmap is now the owner, no need to release here
+        ReleaseIconRef( info->u.iconRef ) ;
     }
     else if ( info->contentType == kControlContentPictHandle )
     {
-        // owned by the bitma, no release here
+        // owned by the bitmap, no release here
     }
 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
     else if ( info->contentType == kControlContentCGImageRef )