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/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
,
25 wxWindowID id
, const wxBitmap
& bitmap
,
29 const wxValidator
& validator
,
30 const wxString
& name
)
32 m_macIsUserPane
= false;
34 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
35 // essentially creates an additional button
36 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
41 if ( style
& wxBU_AUTODRAW
)
44 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
57 wxSize newSize
= DoGetBestSize();
67 ControlButtonContentInfo info
;
69 Rect bounds
= wxMacGetBoundsForControl( this, pos
, size
);
70 m_peer
= new wxMacControl( this );
73 if ( HasFlag( wxBORDER_NONE
) )
75 wxMacCreateBitmapButton( &info
, m_bmpNormal
, kControlContentIconRef
);
76 err
= CreateIconControl(
77 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()),
78 &bounds
, &info
, false, m_peer
->GetControlRefAddr() );
83 wxMacCreateBitmapButton( &info
, m_bmpNormal
);
84 err
= CreateBevelButtonControl(
85 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
, CFSTR(""),
86 ((style
& wxBU_AUTODRAW
) ? kControlBevelButtonSmallBevel
: kControlBevelButtonNormalBevel
),
87 kControlBehaviorOffsetContents
, &info
, 0, 0, 0, m_peer
->GetControlRefAddr() );
92 wxMacReleaseBitmapButton( &info
);
93 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok(), wxT("No valid native Mac control") );
95 MacPostControlCreate( pos
, size
);
100 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
102 m_bmpNormal
= bitmap
;
103 InvalidateBestSize();
105 ControlButtonContentInfo info
;
108 if ( HasFlag( wxBORDER_NONE
) )
110 wxMacCreateBitmapButton( &info
, m_bmpNormal
, kControlContentIconRef
);
111 if ( info
.contentType
!= kControlNoContent
)
112 m_peer
->SetData( kControlIconPart
, kControlIconContentTag
, info
);
117 wxMacCreateBitmapButton( &info
, m_bmpNormal
);
118 if ( info
.contentType
!= kControlNoContent
)
119 m_peer
->SetData( kControlButtonPart
, kControlBevelButtonContentTag
, info
);
122 wxMacReleaseBitmapButton( &info
);
125 wxSize
wxBitmapButton::DoGetBestSize() const
129 best
.x
= 2 * m_marginX
;
130 best
.y
= 2 * m_marginY
;
131 if ( m_bmpNormal
.Ok() )
133 best
.x
+= m_bmpNormal
.GetWidth();
134 best
.y
+= m_bmpNormal
.GetHeight();