1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmapButton
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "bmpbuttn.h"
16 #include "wx/bmpbuttn.h"
18 #if !USE_SHARED_LIBRARY
19 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
22 #include <wx/mac/uma.h>
24 PicHandle
MakePict(GWorldPtr wp
, GWorldPtr mask
) ;
26 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
28 const wxSize
& size
, long style
,
29 const wxValidator
& validator
,
32 m_buttonBitmap
= bitmap
;
43 m_windowId
= NewControlId();
47 if ( width
== -1 && bitmap
.Ok())
48 width
= bitmap
.GetWidth() + 2*m_marginX
;
50 if ( height
== -1 && bitmap
.Ok())
51 height
= bitmap
.GetHeight() + 2*m_marginY
;
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 (( style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevelProc
: 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 if ( m_buttonBitmap
.GetMask() )
73 icon
= MakePict( bmap
->m_hBitmap
, m_buttonBitmap
.GetMask()->GetMaskBitmap() ) ;
77 icon
= MakePict( bmap
->m_hBitmap
, NULL
) ;
81 ControlButtonContentInfo info
;
83 info
.contentType
= kControlContentPictHandle
;
84 info
.u
.picture
= icon
;
86 UMASetControlData( m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
88 MacPostControlCreate() ;
93 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
95 m_buttonBitmap
= bitmap
;
96 PicHandle icon
= NULL
;
97 if ( m_buttonBitmap
.Ok() )
99 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( m_buttonBitmap
.GetRefData()) ;
100 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
101 icon
= bmap
->m_hPict
;
102 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
104 if ( m_buttonBitmap
.GetMask() )
106 icon
= MakePict( bmap
->m_hBitmap
, m_buttonBitmap
.GetMask()->GetMaskBitmap() ) ;
110 icon
= MakePict( bmap
->m_hBitmap
, NULL
) ;
114 ControlButtonContentInfo info
;
116 info
.contentType
= kControlContentPictHandle
;
117 info
.u
.picture
= icon
;
119 UMASetControlData( m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;