1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmapButton
8 // Copyright: (c) AUTHOR
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 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
= ::NewControl( 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 if ( m_buttonBitmap
.GetMask() )
79 info
.contentType
= kControlContentCIconHandle
;
80 info
.u
.cIconHandle
= wxMacCreateCIcon( bmap
->m_hBitmap
, m_buttonBitmap
.GetMask()->GetMaskBitmap() ,
85 info
.contentType
= kControlContentCIconHandle
;
86 info
.u
.cIconHandle
= wxMacCreateCIcon( bmap
->m_hBitmap
, NULL
,
90 else if ( bmap
->m_bitmapType
== kMacBitmapTypeIcon
)
92 info
.contentType
= kControlContentCIconHandle
;
93 info
.u
.cIconHandle
= bmap
->m_hIcon
;
97 ::SetControlData( m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
99 MacPostControlCreate() ;
104 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
106 ControlButtonContentInfo info
;
107 m_buttonBitmap
= bitmap
;
109 if ( m_buttonBitmap
.Ok() )
111 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( m_buttonBitmap
.GetRefData()) ;
112 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
) {
113 info
.contentType
= kControlContentPictHandle
;
114 info
.u
.picture
= bmap
->m_hPict
;
116 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
118 if ( m_buttonBitmap
.GetMask() )
120 info
.contentType
= kControlContentCIconHandle
;
121 info
.u
.cIconHandle
= wxMacCreateCIcon( bmap
->m_hBitmap
, m_buttonBitmap
.GetMask()->GetMaskBitmap() ,
126 info
.contentType
= kControlContentCIconHandle
;
127 info
.u
.cIconHandle
= wxMacCreateCIcon( bmap
->m_hBitmap
, NULL
,
131 else if ( bmap
->m_bitmapType
== kMacBitmapTypeIcon
)
133 info
.contentType
= kControlContentCIconHandle
;
134 info
.u
.cIconHandle
= bmap
->m_hIcon
;
138 ::SetControlData( m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;