]>
git.saurik.com Git - wxWidgets.git/blob - src/univ/bmpbuttn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/bmpbuttn.cpp
3 // Purpose: wxBitmapButton implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/bmpbuttn.h"
32 #include "wx/validate.h"
35 #include "wx/univ/renderer.h"
37 // ============================================================================
39 // ============================================================================
41 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
43 BEGIN_EVENT_TABLE(wxBitmapButton
, wxButton
)
44 EVT_SET_FOCUS(wxBitmapButton::OnSetFocus
)
45 EVT_KILL_FOCUS(wxBitmapButton::OnKillFocus
)
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 bool wxBitmapButton::Create(wxWindow
*parent
,
54 const wxBitmap
& bitmap
,
58 const wxValidator
& validator
,
61 // we add wxBU_EXACTFIT because the bitmap buttons are not the standard
62 // ones and so shouldn't be forced to be of the standard size which is
63 // typically too big for them
64 if ( !wxButton::Create(parent
, id
, bitmap
, wxEmptyString
,
65 pos
, size
, style
| wxBU_EXACTFIT
, validator
, name
) )
68 m_bitmaps
[State_Normal
] = bitmap
;
73 void wxBitmapButton::OnSetBitmap()
78 bmp
= GetBitmapDisabled();
80 else if ( IsPressed() )
82 bmp
= GetBitmapPressed();
84 else if ( IsFocused() )
86 bmp
= GetBitmapFocus();
88 //else: just leave it invalid, this means "normal" anyhow in ChangeBitmap()
93 bool wxBitmapButton::ChangeBitmap(const wxBitmap
& bmp
)
95 wxBitmap bitmap
= bmp
.IsOk() ? bmp
: GetBitmapLabel();
96 if ( bitmap
.IsSameAs(m_bitmap
) )
104 bool wxBitmapButton::Enable(bool enable
)
106 if ( !wxButton::Enable(enable
) )
109 if ( !enable
&& ChangeBitmap(GetBitmapDisabled()) )
115 bool wxBitmapButton::SetCurrent(bool doit
)
117 ChangeBitmap(doit
? GetBitmapFocus() : GetBitmapLabel());
119 return wxButton::SetCurrent(doit
);
122 void wxBitmapButton::OnSetFocus(wxFocusEvent
& event
)
124 if ( ChangeBitmap(GetBitmapFocus()) )
130 void wxBitmapButton::OnKillFocus(wxFocusEvent
& event
)
132 if ( ChangeBitmap(GetBitmapLabel()) )
138 void wxBitmapButton::Press()
140 ChangeBitmap(GetBitmapPressed());
145 void wxBitmapButton::Release()
147 ChangeBitmap(IsFocused() ? GetBitmapFocus() : GetBitmapLabel());
152 #endif // wxUSE_BMPBUTTON