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"
20 #include "wx/window.h"
21 #include "wx/bmpbuttn.h"
23 #if !USE_SHARED_LIBRARY
24 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
27 #include "wx/mac/uma.h"
28 #include "wx/bitmap.h"
30 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
32 const wxSize
& size
, long style
,
33 const wxValidator
& validator
,
36 m_macIsUserPane
= FALSE
;
38 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
39 // essentially creates an additional button
40 if ( !wxControl::Create(parent
, id
, pos
, size
,
41 style
, validator
, name
) )
46 if (style
& wxBU_AUTODRAW
)
48 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
49 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
62 wxSize newSize
= DoGetBestSize();
71 ControlButtonContentInfo info
;
72 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
74 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
75 m_peer
= new wxMacControl( this ) ;
76 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
77 (( style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevel
: kControlBevelButtonNormalBevel
) ,
78 kControlBehaviorOffsetContents
, &info
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
80 wxMacReleaseBitmapButton( &info
) ;
81 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
83 MacPostControlCreate(pos
,size
) ;
88 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
93 ControlButtonContentInfo info
;
94 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
95 if ( info
.contentType
!= kControlNoContent
)
97 m_peer
->SetData( kControlButtonPart
, kControlBevelButtonContentTag
, info
) ;
99 wxMacReleaseBitmapButton( &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
;