1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/bmpbuttn.cpp
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/bmpbuttn.h"
19 #include "wx/window.h"
20 #include "wx/bitmap.h"
23 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
25 #include "wx/mac/uma.h"
27 bool wxBitmapButton::Create( wxWindow
*parent
,
28 wxWindowID id
, const wxBitmap
& bitmap
,
32 const wxValidator
& validator
,
33 const wxString
& name
)
35 m_macIsUserPane
= false;
37 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
38 // essentially creates an additional button
39 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
44 if ( style
& wxBU_AUTODRAW
)
47 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
60 wxSize newSize
= DoGetBestSize();
61 if ( width
== wxDefaultCoord
)
63 if ( height
== wxDefaultCoord
)
70 ControlButtonContentInfo info
;
72 Rect bounds
= wxMacGetBoundsForControl( this, pos
, size
);
73 m_peer
= new wxMacControl( this );
76 if ( HasFlag( wxBORDER_NONE
) )
78 wxMacCreateBitmapButton( &info
, m_bmpNormal
, kControlContentIconRef
);
79 err
= CreateIconControl(
80 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()),
81 &bounds
, &info
, false, m_peer
->GetControlRefAddr() );
86 wxMacCreateBitmapButton( &info
, m_bmpNormal
);
87 err
= CreateBevelButtonControl(
88 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
, CFSTR(""),
89 ((style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevel
: kControlBevelButtonNormalBevel
),
90 kControlBehaviorOffsetContents
, &info
, 0, 0, 0, m_peer
->GetControlRefAddr() );
95 wxMacReleaseBitmapButton( &info
);
96 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok(), wxT("No valid native Mac control") );
98 MacPostControlCreate( pos
, size
);
103 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
105 m_bmpNormal
= bitmap
;
106 InvalidateBestSize();
108 ControlButtonContentInfo info
;
111 if ( HasFlag( wxBORDER_NONE
) )
113 wxMacCreateBitmapButton( &info
, m_bmpNormal
, kControlContentIconRef
);
114 if ( info
.contentType
!= kControlNoContent
)
115 m_peer
->SetData( kControlIconPart
, kControlIconContentTag
, info
);
120 wxMacCreateBitmapButton( &info
, m_bmpNormal
);
121 if ( info
.contentType
!= kControlNoContent
)
122 m_peer
->SetData( kControlButtonPart
, kControlBevelButtonContentTag
, info
);
125 wxMacReleaseBitmapButton( &info
);
128 wxSize
wxBitmapButton::DoGetBestSize() const
132 best
.x
= 2 * m_marginX
;
133 best
.y
= 2 * m_marginY
;
134 if ( m_bmpNormal
.Ok() )
136 best
.x
+= m_bmpNormal
.GetWidth();
137 best
.y
+= m_bmpNormal
.GetHeight();