- Rect bounds ;
- Str255 title ;
- m_bmpNormal = bitmap;
- wxBitmapRefData * bmap = NULL ;
-
- if ( m_bmpNormal.Ok() )
- bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ;
-
- MacPreControlCreate( parent , id , "" , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
-
- m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 ,
- kControlBehaviorOffsetContents +
- ( bmap && bmap->m_bitmapType == kMacBitmapTypeIcon ?
- kControlContentCIconHandle : kControlContentPictHandle ) , 0,
- (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
- wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
-
- ControlButtonContentInfo info ;
- wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
- if ( info.contentType != kControlNoContent )
- {
- ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
+ if ( bitmap.Ok() && HasFlag(wxBORDER_NONE) )
+ {
+ // 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