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
) ;
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
;
53 m_macHorizontalBorder
= 2 ; // additional pixels around the real control
54 m_macVerticalBorder
= 2 ;
57 MacPreControlCreate( parent
, id
, "" , pos
, wxSize( width
, height
) ,style
, validator
, name
, &bounds
, title
) ;
59 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 ,
60 kControlBehaviorOffsetContents
+ kControlContentPictHandle
, 0,
61 kControlBevelButtonNormalBevelProc
, (long) this ) ;
62 wxASSERT_MSG( m_macControl
!= NULL
, "No valid mac control" ) ;
64 m_buttonBitmap
= bitmap
;
65 PicHandle icon
= NULL
;
66 if ( m_buttonBitmap
.Ok() )
68 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( m_buttonBitmap
.GetRefData()) ;
69 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
70 icon
= bmap
->m_hPict
;
71 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
73 icon
= MakePict( bmap
->m_hBitmap
) ;
76 ControlButtonContentInfo info
;
78 info
.contentType
= kControlContentPictHandle
;
79 info
.u
.picture
= icon
;
81 UMASetControlData( m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
83 MacPostControlCreate() ;
88 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
90 m_buttonBitmap
= bitmap
;
91 PicHandle icon
= NULL
;
92 if ( m_buttonBitmap
.Ok() )
94 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( m_buttonBitmap
.GetRefData()) ;
95 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
96 icon
= bmap
->m_hPict
;
97 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
99 icon
= MakePict( bmap
->m_hBitmap
) ;
102 ControlButtonContentInfo info
;
104 info
.contentType
= kControlContentPictHandle
;
105 info
.u
.picture
= icon
;
107 UMASetControlData( m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;