1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmapButton
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/window.h"
17 #include "wx/bmpbuttn.h"
19 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
21 #include "wx/mac/uma.h"
22 #include "wx/bitmap.h"
24 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
26 const wxSize
& size
, long style
,
27 const wxValidator
& validator
,
30 m_macIsUserPane
= FALSE
;
32 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
33 // essentially creates an additional button
34 if ( !wxControl::Create(parent
, id
, pos
, size
,
35 style
, validator
, name
) )
40 if (style
& wxBU_AUTODRAW
)
42 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
43 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
56 wxSize newSize
= DoGetBestSize();
65 ControlButtonContentInfo info
;
67 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
68 m_peer
= new wxMacControl( this ) ;
71 if ( HasFlag( wxBORDER_NONE
) )
73 wxMacCreateBitmapButton( &info
, m_bmpNormal
, kControlContentIconRef
) ;
74 verify_noerr ( CreateIconControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, &info
, false , m_peer
->GetControlRefAddr() ) );
79 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
80 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
81 (( style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevel
: kControlBevelButtonNormalBevel
) ,
82 kControlBehaviorOffsetContents
, &info
, 0 , 0 , 0 , m_peer
->GetControlRefAddr() ) );
84 wxMacReleaseBitmapButton( &info
) ;
85 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
87 MacPostControlCreate(pos
,size
) ;
92 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
97 ControlButtonContentInfo info
;
99 if ( HasFlag( wxBORDER_NONE
) )
101 wxMacCreateBitmapButton( &info
, m_bmpNormal
, kControlContentIconRef
) ;
102 if ( info
.contentType
!= kControlNoContent
)
104 m_peer
->SetData( kControlIconPart
, kControlIconContentTag
, info
) ;
110 wxMacCreateBitmapButton( &info
, m_bmpNormal
) ;
111 if ( info
.contentType
!= kControlNoContent
)
113 m_peer
->SetData( kControlButtonPart
, kControlBevelButtonContentTag
, info
) ;
116 wxMacReleaseBitmapButton( &info
) ;
120 wxSize
wxBitmapButton::DoGetBestSize() const
123 if (m_bmpNormal
.Ok())
125 best
.x
= m_bmpNormal
.GetWidth() + 2*m_marginX
;
126 best
.y
= m_bmpNormal
.GetHeight() + 2*m_marginY
;