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 m_buttonBitmap
= bitmap
;
56 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( m_buttonBitmap
.GetRefData()) ;
58 MacPreControlCreate( parent
, id
, "" , pos
, wxSize( width
, height
) ,style
, validator
, name
, &bounds
, title
) ;
60 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, false , 0 ,
61 kControlBehaviorOffsetContents
+
62 ( bmap
->m_bitmapType
== kMacBitmapTypeIcon
? kControlContentCIconHandle
: kControlContentPictHandle
) , 0,
63 (( style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevelProc
: kControlBevelButtonNormalBevelProc
), (long) this ) ;
64 wxASSERT_MSG( m_macControl
!= NULL
, "No valid mac control" ) ;
66 ControlButtonContentInfo info
;
69 if ( m_buttonBitmap
.Ok() )
71 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
) {
72 info
.contentType
= kControlContentPictHandle
;
73 info
.u
.picture
= bmap
->m_hPict
;
75 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
77 info
.contentType
= kControlContentPictHandle
;
78 if ( m_buttonBitmap
.GetMask() )
80 info
.u
.picture
= MakePict( bmap
->m_hBitmap
, m_buttonBitmap
.GetMask()->GetMaskBitmap() ) ;
84 info
.u
.picture
= MakePict( bmap
->m_hBitmap
, NULL
) ;
87 else if ( bmap
->m_bitmapType
== kMacBitmapTypeIcon
)
89 info
.contentType
= kControlContentCIconHandle
;
90 info
.u
.cIconHandle
= bmap
->m_hIcon
;
94 UMASetControlData( m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
96 MacPostControlCreate() ;
101 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
103 ControlButtonContentInfo info
;
104 m_buttonBitmap
= bitmap
;
106 if ( m_buttonBitmap
.Ok() )
108 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( m_buttonBitmap
.GetRefData()) ;
109 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
111 info
.contentType
= kControlContentPictHandle
;
112 info
.u
.picture
= bmap
->m_hPict
;
114 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
116 info
.contentType
= kControlContentPictHandle
;
117 if ( m_buttonBitmap
.GetMask() )
119 info
.u
.picture
= MakePict( bmap
->m_hBitmap
, m_buttonBitmap
.GetMask()->GetMaskBitmap() ) ;
123 info
.u
.picture
= MakePict( bmap
->m_hBitmap
, NULL
) ;
126 else if ( bmap
->m_bitmapType
== kMacBitmapTypeIcon
)
128 info
.contentType
= kControlContentCIconHandle
;
129 info
.u
.cIconHandle
= bmap
->m_hIcon
;
132 UMASetControlData( m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;