]> git.saurik.com Git - wxWidgets.git/blob - src/univ/bmpbuttn.cpp
Added some missing wx namespace corrections
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 wxBitmapButtonBase::wxBitmapButtonBase()
56 : m_bmpNormal(),
57 m_bmpSelected(),
58 m_bmpFocus(),
59 m_bmpDisabled(),
60 m_marginX(0),
61 m_marginY(0)
62 {
63 }
64
65 wxBitmapButton::wxBitmapButton()
66 {
67 }
68
69 wxBitmapButton::wxBitmapButton(wxWindow *parent,
70 wxWindowID id,
71 const wxBitmap& bitmap,
72 const wxPoint& pos,
73 const wxSize& size,
74 long style,
75 const wxValidator& validator,
76 const wxString& name)
77 {
78 Create(parent, id, bitmap, pos, size, style, validator, name);
79 }
80
81 bool wxBitmapButton::Create(wxWindow *parent,
82 wxWindowID id,
83 const wxBitmap& bitmap,
84 const wxPoint &pos,
85 const wxSize &size,
86 long style,
87 const wxValidator& validator,
88 const wxString &name)
89 {
90 // we add wxBU_EXACTFIT because the bitmap buttons are not the standard
91 // ones and so shouldn't be forced to be of the standard size which is
92 // typically too big for them
93 if ( !wxButton::Create(parent, id, bitmap, _T(""),
94 pos, size, style | wxBU_EXACTFIT, validator, name) )
95 return FALSE;
96
97 m_bmpNormal = bitmap;
98
99 return TRUE;
100 }
101
102 void wxBitmapButton::OnSetBitmap()
103 {
104 wxBitmap bmp;
105 if ( !IsEnabled() )
106 {
107 bmp = m_bmpDisabled;
108 }
109 else if ( IsPressed() )
110 {
111 bmp = m_bmpSelected;
112 }
113 else if ( IsFocused() )
114 {
115 bmp = m_bmpFocus;
116 }
117 else
118 {
119 bmp = m_bmpNormal;
120 }
121
122 ChangeBitmap(bmp);
123 }
124
125 bool wxBitmapButton::ChangeBitmap(const wxBitmap& bmp)
126 {
127 wxBitmap bitmap = bmp.Ok() ? bmp : m_bmpNormal;
128 if ( bitmap != m_bitmap )
129 {
130 m_bitmap = bitmap;
131
132 return TRUE;
133 }
134
135 return FALSE;
136 }
137
138 bool wxBitmapButton::Enable(bool enable)
139 {
140 if ( !wxButton::Enable(enable) )
141 return FALSE;
142
143 if ( !enable && ChangeBitmap(m_bmpDisabled) )
144 Refresh();
145
146 return TRUE;
147 }
148
149 bool wxBitmapButton::SetCurrent(bool doit)
150 {
151 ChangeBitmap(doit ? m_bmpFocus : m_bmpNormal);
152
153 return wxButton::SetCurrent(doit);
154 }
155
156 void wxBitmapButton::OnSetFocus(wxFocusEvent& event)
157 {
158 if ( ChangeBitmap(m_bmpFocus) )
159 Refresh();
160
161 event.Skip();
162 }
163
164 void wxBitmapButton::OnKillFocus(wxFocusEvent& event)
165 {
166 if ( ChangeBitmap(m_bmpNormal) )
167 Refresh();
168
169 event.Skip();
170 }
171
172 void wxBitmapButton::Press()
173 {
174 ChangeBitmap(m_bmpSelected);
175
176 wxButton::Press();
177 }
178
179 void wxBitmapButton::Release()
180 {
181 ChangeBitmap(IsFocused() ? m_bmpFocus : m_bmpNormal);
182
183 wxButton::Release();
184 }
185
186 #endif // wxUSE_BMPBUTTON
187