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>
25 PicHandle
MakePict(GWorldPtr wp
, GWorldPtr mask
) ;
27 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
29 const wxSize
& size
, long style
,
30 const wxValidator
& validator
,
33 m_buttonBitmap
= bitmap
;
44 m_windowId
= NewControlId();
48 if ( width
== -1 && bitmap
.Ok())
49 width
= bitmap
.GetWidth() + 2*m_marginX
;
51 if ( height
== -1 && bitmap
.Ok())
52 height
= bitmap
.GetHeight() + 2*m_marginY
;
56 m_buttonBitmap
= bitmap
;
57 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( m_buttonBitmap
.GetRefData()) ;
59 MacPreControlCreate( parent
, id
, "" , pos
, wxSize( width
, height
) ,style
, validator
, name
, &bounds
, title
) ;
61 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, false , 0 ,
62 kControlBehaviorOffsetContents
+
63 ( bmap
->m_bitmapType
== kMacBitmapTypeIcon
? kControlContentCIconHandle
: kControlContentPictHandle
) , 0,
64 (( style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevelProc
: kControlBevelButtonNormalBevelProc
), (long) this ) ;
65 wxASSERT_MSG( m_macControl
!= NULL
, "No valid mac control" ) ;
67 ControlButtonContentInfo info
;
70 if ( m_buttonBitmap
.Ok() )
72 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
) {
73 info
.contentType
= kControlContentPictHandle
;
74 info
.u
.picture
= bmap
->m_hPict
;
76 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
78 info
.contentType
= kControlContentPictHandle
;
79 if ( m_buttonBitmap
.GetMask() )
81 info
.u
.picture
= MakePict( bmap
->m_hBitmap
, m_buttonBitmap
.GetMask()->GetMaskBitmap() ) ;
85 info
.u
.picture
= MakePict( bmap
->m_hBitmap
, NULL
) ;
88 else if ( bmap
->m_bitmapType
== kMacBitmapTypeIcon
)
90 info
.contentType
= kControlContentCIconHandle
;
91 info
.u
.cIconHandle
= bmap
->m_hIcon
;
95 UMASetControlData( m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
97 MacPostControlCreate() ;
102 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
104 ControlButtonContentInfo info
;
105 m_buttonBitmap
= bitmap
;
107 if ( m_buttonBitmap
.Ok() )
109 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( m_buttonBitmap
.GetRefData()) ;
110 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
112 info
.contentType
= kControlContentPictHandle
;
113 info
.u
.picture
= bmap
->m_hPict
;
115 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
117 info
.contentType
= kControlContentPictHandle
;
118 if ( m_buttonBitmap
.GetMask() )
120 info
.u
.picture
= MakePict( bmap
->m_hBitmap
, m_buttonBitmap
.GetMask()->GetMaskBitmap() ) ;
124 info
.u
.picture
= MakePict( bmap
->m_hBitmap
, NULL
) ;
127 else if ( bmap
->m_bitmapType
== kMacBitmapTypeIcon
)
129 info
.contentType
= kControlContentCIconHandle
;
130 info
.u
.cIconHandle
= bmap
->m_hIcon
;
133 UMASetControlData( m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;