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 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
21 #include "wx/mac/uma.h"
22 #include "wx/bitmap.h"
24 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
26 const wxSize
& size
, long style
,
27 const wxValidator
& validator
,
30 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
31 // essentially creates an additional button
32 if ( !wxControl::Create(parent
, id
, pos
, size
,
33 style
, validator
, name
) )
38 if (style
& wxBU_AUTODRAW
)
40 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
41 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
54 wxSize newSize
= DoGetBestSize();
64 wxBitmapRefData
* bmap
= NULL
;
66 if ( m_bmpNormal
.Ok() )
67 bmap
= (wxBitmapRefData
*) ( m_bmpNormal
.GetRefData()) ;
69 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, wxSize( width
, height
) ,style
, validator
, name
, &bounds
, title
) ;
71 m_macControl
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false , 0 ,
72 kControlBehaviorOffsetContents
+
73 ( bmap
&& bmap
->m_bitmapType
== kMacBitmapTypeIcon
?
74 kControlContentCIconHandle
: kControlContentPictHandle
) , 0,
75 (( style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevelProc
: kControlBevelButtonNormalBevelProc
), (long) this ) ;
76 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
78 ControlButtonContentInfo info
;
79 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
80 if ( info
.contentType
!= kControlNoContent
)
82 ::SetControlData( (ControlHandle
) m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
84 MacPostControlCreate() ;
89 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
94 ControlButtonContentInfo info
;
95 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
96 if ( info
.contentType
!= kControlNoContent
)
98 ::SetControlData( (ControlHandle
) m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
103 wxSize
wxBitmapButton::DoGetBestSize() const
106 if (m_bmpNormal
.Ok())
108 best
.x
= m_bmpNormal
.GetWidth() + 2*m_marginX
;
109 best
.y
= m_bmpNormal
.GetHeight() + 2*m_marginY
;