1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxBitmapButton 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:       wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "bmpbuttn.h" 
  16 #include "wx/window.h" 
  17 #include "wx/bmpbuttn.h" 
  19 #if !USE_SHARED_LIBRARY 
  20 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
) 
  23 #include "wx/mac/uma.h" 
  24 #include "wx/bitmap.h" 
  26 bool wxBitmapButton::Create(wxWindow 
*parent
, wxWindowID id
, const wxBitmap
& bitmap
, 
  28            const wxSize
& size
, long style
, 
  29            const wxValidator
& validator
, 
  32     // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create 
  33     // essentially creates an additional button 
  34     if ( !wxControl::Create(parent
, id
, pos
, size
, 
  35                                      style
, validator
, name
) ) 
  40     if (style 
& wxBU_AUTODRAW
) 
  42         m_marginX 
= wxDEFAULT_BUTTON_MARGIN
; 
  43         m_marginY 
= wxDEFAULT_BUTTON_MARGIN
; 
  56         wxSize newSize 
= DoGetBestSize(); 
  66     wxBitmapRefData 
* bmap 
= NULL 
; 
  68     if ( m_bmpNormal
.Ok() ) 
  69         bmap 
= (wxBitmapRefData
*) ( m_bmpNormal
.GetRefData()) ; 
  71     MacPreControlCreate( parent 
, id 
,  wxEmptyString 
, pos 
, wxSize( width 
, height 
) ,style
, validator 
, name 
, &bounds 
, title 
) ; 
  73     m_macControl 
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds 
, title 
, false , 0 ,  
  74         kControlBehaviorOffsetContents 
+  
  75             ( bmap 
&& bmap
->m_bitmapType 
== kMacBitmapTypeIcon 
?  
  76             kControlContentCIconHandle 
: kControlContentPictHandle 
) , 0,  
  77           (( style 
& wxBU_AUTODRAW 
) ? kControlBevelButtonSmallBevelProc 
: kControlBevelButtonNormalBevelProc 
), (long) this ) ; 
  78     wxASSERT_MSG( (ControlHandle
) m_macControl 
!= NULL 
, wxT("No valid mac control") ) ; 
  80     ControlButtonContentInfo info 
; 
  81     wxMacCreateBitmapButton( &info 
, m_bmpNormal 
) ; 
  82     if ( info
.contentType 
!= kControlNoContent 
) 
  84         ::SetControlData( (ControlHandle
) m_macControl 
, kControlButtonPart 
, kControlBevelButtonContentTag 
, sizeof(info
) , (char*) &info 
) ; 
  86     MacPostControlCreate() ; 
  91 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
) 
  96     ControlButtonContentInfo info 
; 
  97     wxMacCreateBitmapButton( &info 
, m_bmpNormal 
) ; 
  98     if ( info
.contentType 
!= kControlNoContent 
) 
 100         ::SetControlData( (ControlHandle
) m_macControl 
, kControlButtonPart 
, kControlBevelButtonContentTag 
, sizeof(info
) , (char*) &info 
) ; 
 105 wxSize 
wxBitmapButton::DoGetBestSize() const 
 108     if (m_bmpNormal
.Ok()) 
 110         best
.x 
= m_bmpNormal
.GetWidth() + 2*m_marginX
; 
 111         best
.y 
= m_bmpNormal
.GetHeight() + 2*m_marginY
;