1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/bmpbuttn.cpp
3 // Purpose: wxBitmapButton
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/bmpbuttn.h"
19 #include "wx/window.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
24 #include "wx/mac/uma.h"
25 #include "wx/bitmap.h"
27 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
29 const wxSize
& size
, long style
,
30 const wxValidator
& validator
,
33 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
34 // essentially creates an additional button
35 if ( !wxControl::Create(parent
, id
, pos
, size
,
36 style
, validator
, name
) )
41 if (style
& wxBU_AUTODRAW
)
43 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
44 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
57 wxSize newSize
= DoGetBestSize();
67 wxBitmapRefData
* bmap
= NULL
;
69 if ( m_bmpNormal
.Ok() )
70 bmap
= (wxBitmapRefData
*) ( m_bmpNormal
.GetRefData()) ;
72 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, wxSize( width
, height
) ,style
, validator
, name
, &bounds
, title
) ;
74 m_macControl
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false , 0 ,
75 kControlBehaviorOffsetContents
+
76 ( bmap
&& bmap
->m_bitmapType
== kMacBitmapTypeIcon
?
77 kControlContentCIconHandle
: kControlContentPictHandle
) , 0,
78 (( style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevelProc
: kControlBevelButtonNormalBevelProc
), (long) this ) ;
79 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
81 ControlButtonContentInfo info
;
82 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
83 if ( info
.contentType
!= kControlNoContent
)
85 ::SetControlData( (ControlHandle
) m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
87 MacPostControlCreate() ;
92 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
97 ControlButtonContentInfo info
;
98 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
99 if ( info
.contentType
!= kControlNoContent
)
101 ::SetControlData( (ControlHandle
) m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
106 wxSize
wxBitmapButton::DoGetBestSize() const
109 if (m_bmpNormal
.Ok())
111 best
.x
= m_bmpNormal
.GetWidth() + 2*m_marginX
;
112 best
.y
= m_bmpNormal
.GetHeight() + 2*m_marginY
;
117 #endif // wxUSE_BMPBUTTON