]> git.saurik.com Git - wxWidgets.git/blob - src/univ/bmpbuttn.cpp
guard grid XRC handler by #if wxUSE_GRID
[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 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_BMPBUTTON
27
28 #ifndef WX_PRECOMP
29 #include "wx/dc.h"
30 #include "wx/bmpbuttn.h"
31 #include "wx/validate.h"
32 #endif
33
34 #include "wx/univ/renderer.h"
35
36 // ============================================================================
37 // implementation
38 // ============================================================================
39
40 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
41
42 BEGIN_EVENT_TABLE(wxBitmapButton, wxButton)
43 EVT_SET_FOCUS(wxBitmapButton::OnSetFocus)
44 EVT_KILL_FOCUS(wxBitmapButton::OnKillFocus)
45 END_EVENT_TABLE()
46
47 // ----------------------------------------------------------------------------
48 // wxBitmapButton
49 // ----------------------------------------------------------------------------
50
51 bool wxBitmapButton::Create(wxWindow *parent,
52 wxWindowID id,
53 const wxBitmap& bitmap,
54 const wxPoint &pos,
55 const wxSize &size,
56 long style,
57 const wxValidator& validator,
58 const wxString &name)
59 {
60 // we add wxBU_EXACTFIT because the bitmap buttons are not the standard
61 // ones and so shouldn't be forced to be of the standard size which is
62 // typically too big for them
63 if ( !wxButton::Create(parent, id, bitmap, wxEmptyString,
64 pos, size, style | wxBU_EXACTFIT, validator, name) )
65 return false;
66
67 m_bmpNormal = bitmap;
68
69 return true;
70 }
71
72 void wxBitmapButton::OnSetBitmap()
73 {
74 wxBitmap bmp;
75 if ( !IsEnabled() )
76 {
77 bmp = m_bmpDisabled;
78 }
79 else if ( IsPressed() )
80 {
81 bmp = m_bmpSelected;
82 }
83 else if ( IsFocused() )
84 {
85 bmp = m_bmpFocus;
86 }
87 else
88 {
89 bmp = m_bmpNormal;
90 }
91
92 ChangeBitmap(bmp);
93 }
94
95 bool wxBitmapButton::ChangeBitmap(const wxBitmap& bmp)
96 {
97 wxBitmap bitmap = bmp.Ok() ? bmp : m_bmpNormal;
98 if ( bitmap != m_bitmap )
99 {
100 m_bitmap = bitmap;
101
102 return true;
103 }
104
105 return false;
106 }
107
108 bool wxBitmapButton::Enable(bool enable)
109 {
110 if ( !wxButton::Enable(enable) )
111 return false;
112
113 if ( !enable && ChangeBitmap(m_bmpDisabled) )
114 Refresh();
115
116 return true;
117 }
118
119 bool wxBitmapButton::SetCurrent(bool doit)
120 {
121 ChangeBitmap(doit ? m_bmpFocus : m_bmpNormal);
122
123 return wxButton::SetCurrent(doit);
124 }
125
126 void wxBitmapButton::OnSetFocus(wxFocusEvent& event)
127 {
128 if ( ChangeBitmap(m_bmpFocus) )
129 Refresh();
130
131 event.Skip();
132 }
133
134 void wxBitmapButton::OnKillFocus(wxFocusEvent& event)
135 {
136 if ( ChangeBitmap(m_bmpNormal) )
137 Refresh();
138
139 event.Skip();
140 }
141
142 void wxBitmapButton::Press()
143 {
144 ChangeBitmap(m_bmpSelected);
145
146 wxButton::Press();
147 }
148
149 void wxBitmapButton::Release()
150 {
151 ChangeBitmap(IsFocused() ? m_bmpFocus : m_bmpNormal);
152
153 wxButton::Release();
154 }
155
156 #endif // wxUSE_BMPBUTTON
157