1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmapButton
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWidgets 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_macIsUserPane
= FALSE
;
34 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
35 // essentially creates an additional button
36 if ( !wxControl::Create(parent
, id
, pos
, size
,
37 style
, validator
, name
) )
42 if (style
& wxBU_AUTODRAW
)
44 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
45 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
58 wxSize newSize
= DoGetBestSize();
67 wxBitmapRefData
* bmap
= NULL
;
69 if ( m_bmpNormal
.Ok() )
70 bmap
= (wxBitmapRefData
*) ( m_bmpNormal
.GetRefData()) ;
72 ControlButtonContentInfo info
;
73 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
75 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
76 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
77 (( style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevel
: kControlBevelButtonNormalBevel
) ,
78 kControlBehaviorOffsetContents
, &info
, 0 , 0 , 0 , (ControlRef
*) &m_macControl
) ) ;
80 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
82 MacPostControlCreate(pos
,size
) ;
87 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
91 ControlButtonContentInfo info
;
92 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
93 if ( info
.contentType
!= kControlNoContent
)
95 ::SetControlData( (ControlRef
) m_macControl
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
100 wxSize
wxBitmapButton::DoGetBestSize() const
103 if (m_bmpNormal
.Ok())
105 best
.x
= m_bmpNormal
.GetWidth() + 2*m_marginX
;
106 best
.y
= m_bmpNormal
.GetHeight() + 2*m_marginY
;