]> git.saurik.com Git - wxWidgets.git/blob - src/univ/bmpbuttn.cpp
Applied patch [ 774886 ] wxnotebook bug
[wxWidgets.git] / src / univ / bmpbuttn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: univ/bmpbuttn.cpp
3 // Purpose: wxBitmapButton implementation
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 25.08.00
7 // RCS-ID: $Id$
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "univbmpbuttn.h"
22 #endif
23
24 #include "wx/wxprec.h"
25
26 #ifdef __BORLANDC__
27 #pragma hdrstop
28 #endif
29
30 #if wxUSE_BMPBUTTON
31
32 #ifndef WX_PRECOMP
33 #include "wx/dc.h"
34 #include "wx/bmpbuttn.h"
35 #include "wx/validate.h"
36 #endif
37
38 #include "wx/univ/renderer.h"
39
40 // ============================================================================
41 // implementation
42 // ============================================================================
43
44 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
45
46 BEGIN_EVENT_TABLE(wxBitmapButton, wxButton)
47 EVT_SET_FOCUS(wxBitmapButton::OnSetFocus)
48 EVT_KILL_FOCUS(wxBitmapButton::OnKillFocus)
49 END_EVENT_TABLE()
50
51 // ----------------------------------------------------------------------------
52 // wxBitmapButton
53 // ----------------------------------------------------------------------------
54
55 bool wxBitmapButton::Create(wxWindow *parent,
56 wxWindowID id,
57 const wxBitmap& bitmap,
58 const wxPoint &pos,
59 const wxSize &size,
60 long style,
61 const wxValidator& validator,
62 const wxString &name)
63 {
64 // we add wxBU_EXACTFIT because the bitmap buttons are not the standard
65 // ones and so shouldn't be forced to be of the standard size which is
66 // typically too big for them
67 if ( !wxButton::Create(parent, id, bitmap, _T(""),
68 pos, size, style | wxBU_EXACTFIT, validator, name) )
69 return FALSE;
70
71 m_bmpNormal = bitmap;
72
73 return TRUE;
74 }
75
76 void wxBitmapButton::OnSetBitmap()
77 {
78 wxBitmap bmp;
79 if ( !IsEnabled() )
80 {
81 bmp = m_bmpDisabled;
82 }
83 else if ( IsPressed() )
84 {
85 bmp = m_bmpSelected;
86 }
87 else if ( IsFocused() )
88 {
89 bmp = m_bmpFocus;
90 }
91 else
92 {
93 bmp = m_bmpNormal;
94 }
95
96 ChangeBitmap(bmp);
97 }
98
99 bool wxBitmapButton::ChangeBitmap(const wxBitmap& bmp)
100 {
101 wxBitmap bitmap = bmp.Ok() ? bmp : m_bmpNormal;
102 if ( bitmap != m_bitmap )
103 {
104 m_bitmap = bitmap;
105
106 return TRUE;
107 }
108
109 return FALSE;
110 }
111
112 bool wxBitmapButton::Enable(bool enable)
113 {
114 if ( !wxButton::Enable(enable) )
115 return FALSE;
116
117 if ( !enable && ChangeBitmap(m_bmpDisabled) )
118 Refresh();
119
120 return TRUE;
121 }
122
123 bool wxBitmapButton::SetCurrent(bool doit)
124 {
125 ChangeBitmap(doit ? m_bmpFocus : m_bmpNormal);
126
127 return wxButton::SetCurrent(doit);
128 }
129
130 void wxBitmapButton::OnSetFocus(wxFocusEvent& event)
131 {
132 if ( ChangeBitmap(m_bmpFocus) )
133 Refresh();
134
135 event.Skip();
136 }
137
138 void wxBitmapButton::OnKillFocus(wxFocusEvent& event)
139 {
140 if ( ChangeBitmap(m_bmpNormal) )
141 Refresh();
142
143 event.Skip();
144 }
145
146 void wxBitmapButton::Press()
147 {
148 ChangeBitmap(m_bmpSelected);
149
150 wxButton::Press();
151 }
152
153 void wxBitmapButton::Release()
154 {
155 ChangeBitmap(IsFocused() ? m_bmpFocus : m_bmpNormal);
156
157 wxButton::Release();
158 }
159
160 #endif // wxUSE_BMPBUTTON
161