1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmapButton
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
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_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 m_peer
= new wxMacControl() ;
77 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
78 (( style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevel
: kControlBevelButtonNormalBevel
) ,
79 kControlBehaviorOffsetContents
, &info
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
82 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
84 MacPostControlCreate(pos
,size
) ;
89 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
94 ControlButtonContentInfo info
;
95 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
96 if ( info
.contentType
!= kControlNoContent
)
98 m_peer
->SetData( kControlButtonPart
, kControlBevelButtonContentTag
, info
) ;
103 wxSize
wxBitmapButton::DoGetBestSize() const
106 if (m_bmpNormal
.Ok())
108 best
.x
= m_bmpNormal
.GetWidth() + 2*m_marginX
;
109 best
.y
= m_bmpNormal
.GetHeight() + 2*m_marginY
;