]> git.saurik.com Git - wxWidgets.git/commitdiff
Return smaller images for wxART_MENU/BUTTON under OS X.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 5 Oct 2009 22:57:24 +0000 (22:57 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 5 Oct 2009 22:57:24 +0000 (22:57 +0000)
Requesting images with client id of wxART_MENU/BUTTON used to return the large
32*32 icons because GetNativeSizeHint() wasn't implemented for these client
ids.

Moreover, under Mac some icons (notably message box ones) are created from the
corresponding icon bundle and the code in wxArtProvider::GetBitmap() didn't
resize them correctly in this case, fix this.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62299 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/artprov.cpp
src/osx/artmac.cpp

index 79c9470e01693d39dd5bea94c8dc19f70b456c33..3a4f56b04cfe9142345d0c85bc522e920f2c72c4 100644 (file)
@@ -238,6 +238,7 @@ wxArtProvider::~wxArtProvider()
                 break;
         }
 
                 break;
         }
 
+        wxSize sizeNeeded = size;
         if ( !bmp.Ok() )
         {
             // no bitmap created -- as a fallback, try if we can find desired
         if ( !bmp.Ok() )
         {
             // no bitmap created -- as a fallback, try if we can find desired
@@ -245,28 +246,31 @@ wxArtProvider::~wxArtProvider()
             wxIconBundle iconBundle = DoGetIconBundle(id, client);
             if ( iconBundle.IsOk() )
             {
             wxIconBundle iconBundle = DoGetIconBundle(id, client);
             if ( iconBundle.IsOk() )
             {
-                wxSize sz(size != wxDefaultSize
-                            ? size
-                            : GetNativeSizeHint(client));
-                wxIcon icon(iconBundle.GetIcon(sz));
+                if ( sizeNeeded == wxDefaultSize )
+                    sizeNeeded = GetNativeSizeHint(client);
+
+                wxIcon icon(iconBundle.GetIcon(sizeNeeded));
                 if ( icon.IsOk() )
                 if ( icon.IsOk() )
+                {
+                    // this icon may be not of the correct size, it will be
+                    // rescaled below in such case
                     bmp.CopyFromIcon(icon);
                     bmp.CopyFromIcon(icon);
+                }
             }
         }
 
             }
         }
 
-        if ( bmp.IsOk() )
-        {
-            // if we didn't get the correct size, resize the bitmap
+        // if we didn't get the correct size, resize the bitmap
 #if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
 #if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
-            if ( size != wxDefaultSize &&
-                 (bmp.GetWidth() != size.x || bmp.GetHeight() != size.y) )
+        if ( bmp.IsOk() && sizeNeeded != wxDefaultSize )
+        {
+            if ( bmp.GetSize() != sizeNeeded )
             {
                 wxImage img = bmp.ConvertToImage();
             {
                 wxImage img = bmp.ConvertToImage();
-                img.Rescale(size.x, size.y);
+                img.Rescale(sizeNeeded.x, sizeNeeded.y);
                 bmp = wxBitmap(img);
             }
                 bmp = wxBitmap(img);
             }
-#endif
         }
         }
+#endif // wxUSE_IMAGE
 
         sm_cache->PutBitmap(hashId, bmp);
     }
 
         sm_cache->PutBitmap(hashId, bmp);
     }
index 6b49934787fd15869a16148acb69f471a63c3abf..04acf5caf43f6a83b97fae5d2611ebd97c4af206 100644 (file)
@@ -117,6 +117,14 @@ wxSize wxArtProvider::GetNativeSizeHint(const wxArtClient& client)
         // "32 x 32 pixels is the recommended size"
         return wxSize(32, 32);
     }
         // "32 x 32 pixels is the recommended size"
         return wxSize(32, 32);
     }
+    else if ( client == wxART_BUTTON || client == wxART_MENU )
+    {
+        // Mac UI doesn't use any images in neither buttons nor menus in
+        // general but the code using wxArtProvider can use wxART_BUTTON to
+        // find the icons of a roughly appropriate size for the buttons and
+        // 16x16 seems to be the best choice for this kind of use
+        return wxSize(16, 16);
+    }
 
     return wxDefaultSize;
 }
 
     return wxDefaultSize;
 }