1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmapButton
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/window.h"
13 #include "wx/bmpbuttn.h"
15 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
17 #include "wx/mac/uma.h"
18 #include "wx/bitmap.h"
20 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
22 const wxSize
& size
, long style
,
23 const wxValidator
& validator
,
26 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
27 // essentially creates an additional button
28 if ( !wxControl::Create(parent
, id
, pos
, size
,
29 style
, validator
, name
) )
34 if (style
& wxBU_AUTODRAW
)
36 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
37 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
50 wxSize newSize
= DoGetBestSize();
60 wxBitmapRefData
* bmap
= NULL
;
62 if ( m_bmpNormal
.Ok() )
63 bmap
= (wxBitmapRefData
*) ( m_bmpNormal
.GetRefData()) ;
65 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, wxSize( width
, height
) ,style
, validator
, name
, &bounds
, title
) ;
67 m_macControl
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false , 0 ,
68 kControlBehaviorOffsetContents
+
69 ( bmap
&& bmap
->m_bitmapType
== kMacBitmapTypeIcon
?
70 kControlContentCIconHandle
: kControlContentPictHandle
) , 0,
71 (( style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevelProc
: kControlBevelButtonNormalBevelProc
), (long) this ) ;
72 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
74 ControlButtonContentInfo info
;
75 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
76 if ( info
.contentType
!= kControlNoContent
)
78 ::SetControlData( (ControlHandle
) m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
80 MacPostControlCreate() ;
85 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
90 ControlButtonContentInfo info
;
91 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
92 if ( info
.contentType
!= kControlNoContent
)
94 ::SetControlData( (ControlHandle
) m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
99 wxSize
wxBitmapButton::DoGetBestSize() const
102 if (m_bmpNormal
.Ok())
104 best
.x
= m_bmpNormal
.GetWidth() + 2*m_marginX
;
105 best
.y
= m_bmpNormal
.GetHeight() + 2*m_marginY
;