1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/bmpbuttn_osx.cpp
3 // Purpose: wxBitmapButton
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: bmpbuttn.cpp 54820 2008-07-29 20:04:11Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/bmpbuttn.h"
20 #include "wx/dcmemory.h"
23 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
25 BEGIN_EVENT_TABLE(wxBitmapButton
, wxButton
)
26 EVT_ENTER_WINDOW(wxBitmapButton
::OnEnterWindow
)
27 EVT_LEAVE_WINDOW(wxBitmapButton
::OnLeaveWindow
)
30 #include "wx/osx/private.h"
32 //---------------------------------------------------------------------------
34 bool wxBitmapButton
::Create( wxWindow
*parent
,
36 const wxBitmap
& bitmap
,
40 const wxValidator
& validator
,
41 const wxString
& name
)
43 m_macIsUserPane
= false;
45 if ( !wxBitmapButtonBase
::Create(parent
, id
, pos
, size
, style
,
49 if ( style
& wxBU_AUTODRAW
)
52 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
60 m_bitmaps
[State_Normal
] = bitmap
;
62 m_peer
= wxWidgetImpl
::CreateBitmapButton( this, parent
, id
, bitmap
, pos
, size
, style
, GetExtraStyle() );
64 MacPostControlCreate( pos
, size
);
69 void wxBitmapButton
::DoSetBitmap(const wxBitmap
& bitmap
, State which
)
71 wxBitmapButtonBase
::DoSetBitmap(bitmap
, which
);
73 // we don't support any other states currently
74 if ( which
== State_Normal
)
76 m_peer
->SetBitmap( bitmap
);
78 else if ( which
== State_Pressed
)
80 wxBitmapButtonImpl
* bi
= dynamic_cast<wxBitmapButtonImpl
*> (m_peer
);
82 bi
->SetPressedBitmap(bitmap
);
86 wxSize wxBitmapButton
::DoGetBestSize() const
88 wxSize
best(m_marginX
, m_marginY
);
92 if ( GetBitmapLabel().IsOk() )
94 best
+= GetBitmapLabel().GetSize();
100 void wxBitmapButton
::OnEnterWindow( wxMouseEvent
& WXUNUSED(event
))
102 if ( DoGetBitmap( State_Current
).IsOk() )
103 m_peer
->SetBitmap( DoGetBitmap( State_Current
) );
106 void wxBitmapButton
::OnLeaveWindow( wxMouseEvent
& WXUNUSED(event
))
108 if ( DoGetBitmap( State_Current
).IsOk() )
109 m_peer
->SetBitmap( DoGetBitmap( State_Normal
) );
112 #endif // wxUSE_BMPBUTTON