1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmapButton
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "bmpbuttn.h"
16 #include "wx/bmpbuttn.h"
18 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
20 #include <wx/mac/uma.h>
22 PicHandle
MakePict(GWorldPtr wp
) ;
24 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
26 const wxSize
& size
, long style
,
27 const wxValidator
& validator
,
30 m_buttonBitmap
= bitmap
;
41 m_windowId
= NewControlId();
45 if ( width
== -1 && bitmap
.Ok())
46 width
= bitmap
.GetWidth() + 2*m_marginX
;
48 if ( height
== -1 && bitmap
.Ok())
49 height
= bitmap
.GetHeight() + 2*m_marginY
;
51 m_macHorizontalBorder
= 2 ; // additional pixels around the real control
52 m_macVerticalBorder
= 2 ;
55 MacPreControlCreate( parent
, id
, "" , pos
, wxSize( width
, height
) ,style
, validator
, name
, &bounds
, title
) ;
57 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 ,
58 kControlBehaviorOffsetContents
+ kControlContentPictHandle
, 0,
59 kControlBevelButtonNormalBevelProc
, (long) this ) ;
60 wxASSERT_MSG( m_macControl
!= NULL
, "No valid mac control" ) ;
62 m_buttonBitmap
= bitmap
;
63 PicHandle icon
= NULL
;
64 if ( m_buttonBitmap
.Ok() )
66 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( m_buttonBitmap
.GetRefData()) ;
67 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
68 icon
= bmap
->m_hPict
;
69 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
71 icon
= MakePict( bmap
->m_hBitmap
) ;
74 ControlButtonContentInfo info
;
76 info
.contentType
= kControlContentPictHandle
;
77 info
.u
.picture
= icon
;
79 UMASetControlData( m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
81 MacPostControlCreate() ;
86 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
88 m_buttonBitmap
= bitmap
;
89 PicHandle icon
= NULL
;
90 if ( m_buttonBitmap
.Ok() )
92 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( m_buttonBitmap
.GetRefData()) ;
93 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
94 icon
= bmap
->m_hPict
;
95 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
97 icon
= MakePict( bmap
->m_hBitmap
) ;
100 ControlButtonContentInfo info
;
102 info
.contentType
= kControlContentPictHandle
;
103 info
.u
.picture
= icon
;
105 UMASetControlData( m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;