1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmapButton
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "bmpbuttn.h"
16 #include "wx/wxprec.h"
18 #include "wx/window.h"
19 #include "wx/bmpbuttn.h"
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
25 #include "wx/mac/uma.h"
26 #include "wx/bitmap.h"
28 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
30 const wxSize
& size
, long style
,
31 const wxValidator
& validator
,
34 m_macIsUserPane
= FALSE
;
36 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
37 // essentially creates an additional button
38 if ( !wxControl::Create(parent
, id
, pos
, size
,
39 style
, validator
, name
) )
44 if (style
& wxBU_AUTODRAW
)
46 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
47 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
60 wxSize newSize
= DoGetBestSize();
69 wxBitmapRefData
* bmap
= NULL
;
71 if ( m_bmpNormal
.Ok() )
72 bmap
= (wxBitmapRefData
*) ( m_bmpNormal
.GetRefData()) ;
74 ControlButtonContentInfo info
;
75 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
77 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
78 m_peer
= new wxMacControl() ;
79 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
80 (( style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevel
: kControlBevelButtonNormalBevel
) ,
81 kControlBehaviorOffsetContents
, &info
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
84 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
86 MacPostControlCreate(pos
,size
) ;
91 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
96 ControlButtonContentInfo info
;
97 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
98 if ( info
.contentType
!= kControlNoContent
)
100 m_peer
->SetData( kControlButtonPart
, kControlBevelButtonContentTag
, info
) ;
105 wxSize
wxBitmapButton::DoGetBestSize() const
108 if (m_bmpNormal
.Ok())
110 best
.x
= m_bmpNormal
.GetWidth() + 2*m_marginX
;
111 best
.y
= m_bmpNormal
.GetHeight() + 2*m_marginY
;