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 wxBitmapButtonBase::wxBitmapButtonBase()
36 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
38 const wxSize
& size
, long style
,
39 const wxValidator
& validator
,
42 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
43 // essentially creates an additional button
44 if ( !wxControl::Create(parent
, id
, pos
, size
,
45 style
, validator
, name
) )
50 if (style
& wxBU_AUTODRAW
)
52 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
53 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
64 if ( width
== -1 && bitmap
.Ok())
65 width
= bitmap
.GetWidth() + 2*m_marginX
;
67 if ( height
== -1 && bitmap
.Ok())
68 height
= bitmap
.GetHeight() + 2*m_marginY
;
73 wxBitmapRefData
* bmap
= NULL
;
75 if ( m_bmpNormal
.Ok() )
76 bmap
= (wxBitmapRefData
*) ( m_bmpNormal
.GetRefData()) ;
78 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, wxSize( width
, height
) ,style
, validator
, name
, &bounds
, title
) ;
80 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false , 0 ,
81 kControlBehaviorOffsetContents
+
82 ( bmap
&& bmap
->m_bitmapType
== kMacBitmapTypeIcon
?
83 kControlContentCIconHandle
: kControlContentPictHandle
) , 0,
84 (( style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevelProc
: kControlBevelButtonNormalBevelProc
), (long) this ) ;
85 wxASSERT_MSG( (ControlHandle
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
87 ControlButtonContentInfo info
;
88 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
89 if ( info
.contentType
!= kControlNoContent
)
91 ::SetControlData( (ControlHandle
) m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
93 MacPostControlCreate() ;
98 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
100 m_bmpNormal
= bitmap
;
102 ControlButtonContentInfo info
;
103 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
104 if ( info
.contentType
!= kControlNoContent
)
106 ::SetControlData( (ControlHandle
) m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;