- Rect bounds ;
- Str255 title ;
- m_bmpNormal = bitmap;
- wxBitmapRefData * bmap = NULL ;
-
- if ( m_bmpNormal.Ok() )
- bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ;
-
- MacPreControlCreate( parent , id , wxEmptyString , 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 , wxT("No valid mac control") ) ;
-
- ControlButtonContentInfo info ;
- wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
- if ( info.contentType != kControlNoContent )
+ // 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
+ }
+
+ if ( !m_bmpNormal.Ok() )
+ m_bmpNormal = bitmap;
+
+
+#ifdef __WXMAC_OSX__
+ if ( HasFlag( wxBORDER_NONE ) )
+ {
+ wxMacCreateBitmapButton( &info, m_bmpNormal, kControlContentIconRef );
+ err = CreateIconControl(
+ MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
+ &bounds, &info, false, m_peer->GetControlRefAddr() );
+ }
+ else
+#endif