+ // in Mac OS X the icon controls (which are used for borderless bitmap
+ // buttons) can have only one of the few standard sizes and if they
+ // don't, the OS rescales them automatically resulting in really ugly
+ // images, so centre the image in a square of standard size instead
+
+ // the supported sizes, sorted in decreasng order
+ static const int stdSizes[] = { 128, 48, 32, 16, 0 };
+
+ const int width = bitmap.GetWidth();
+ const int height = bitmap.GetHeight();
+
+ int n;
+ for ( n = 0; n < (int)WXSIZEOF(stdSizes); n++ )
+ {
+ const int sizeStd = stdSizes[n];
+ if ( width > sizeStd || height > sizeStd )
+ {
+ // it will become -1 if the bitmap is larger than the biggest
+ // supported size, this is intentional
+ n--;
+
+ break;
+ }
+ }
+
+ if ( n != -1 )
+ {
+ const int sizeStd = stdSizes[n];
+ if ( width != sizeStd || height != sizeStd )
+ {
+ wxASSERT_MSG( width <= sizeStd && height <= sizeStd,
+ _T("bitmap shouldn't be cropped") );
+
+ m_bmpNormal.Create(sizeStd, sizeStd);
+ wxMemoryDC dcMem;
+ dcMem.SelectObject(m_bmpNormal);
+ dcMem.Clear();
+
+ dcMem.DrawBitmap(bitmap,
+ (sizeStd - width)/2, (sizeStd-height)/2,
+ true);
+ }
+ }
+ //else: let the system rescale the bitmap