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 ControlButtonContentInfo info
;
70 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
72 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
73 m_peer
= new wxMacControl() ;
74 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
75 (( style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevel
: kControlBevelButtonNormalBevel
) ,
76 kControlBehaviorOffsetContents
, &info
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
78 wxMacReleaseBitmapButton( &info
) ;
79 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
81 MacPostControlCreate(pos
,size
) ;
86 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
91 ControlButtonContentInfo info
;
92 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
93 if ( info
.contentType
!= kControlNoContent
)
95 m_peer
->SetData( kControlButtonPart
, kControlBevelButtonContentTag
, info
) ;
97 wxMacReleaseBitmapButton( &info
) ;
101 wxSize
wxBitmapButton::DoGetBestSize() const
104 if (m_bmpNormal
.Ok())
106 best
.x
= m_bmpNormal
.GetWidth() + 2*m_marginX
;
107 best
.y
= m_bmpNormal
.GetHeight() + 2*m_marginY
;