]> git.saurik.com Git - wxWidgets.git/blame - src/univ/bmpbuttn.cpp
fixed typos in wxBase template and project file
[wxWidgets.git] / src / univ / bmpbuttn.cpp
CommitLineData
1e6feb95
VZ
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$
442b35b5 8// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
1e6feb95
VZ
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
a3870b2f 21 #pragma implementation "univbmpbuttn.h"
1e6feb95
VZ
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
44IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
45
46BEGIN_EVENT_TABLE(wxBitmapButton, wxButton)
47 EVT_SET_FOCUS(wxBitmapButton::OnSetFocus)
48 EVT_KILL_FOCUS(wxBitmapButton::OnKillFocus)
49END_EVENT_TABLE()
50
51// ----------------------------------------------------------------------------
52// wxBitmapButton
53// ----------------------------------------------------------------------------
54
55bool 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 if ( !wxButton::Create(parent, id, bitmap, _T(""),
65 pos, size, style, validator, name) )
66 return FALSE;
67
68 m_bmpNormal = bitmap;
69
70 return TRUE;
71}
72
73void wxBitmapButton::OnSetBitmap()
74{
75 wxBitmap bmp;
76 if ( !IsEnabled() )
77 {
78 bmp = m_bmpDisabled;
79 }
80 else if ( IsPressed() )
81 {
82 bmp = m_bmpSelected;
83 }
84 else if ( IsFocused() )
85 {
86 bmp = m_bmpFocus;
87 }
88 else
89 {
90 bmp = m_bmpNormal;
91 }
92
93 ChangeBitmap(bmp);
94}
95
96bool wxBitmapButton::ChangeBitmap(const wxBitmap& bmp)
97{
98 wxBitmap bitmap = bmp.Ok() ? bmp : m_bmpNormal;
99 if ( bitmap != m_bitmap )
100 {
101 m_bitmap = bitmap;
102
103 return TRUE;
104 }
105
106 return FALSE;
107}
108
109bool wxBitmapButton::Enable(bool enable)
110{
111 if ( !wxButton::Enable(enable) )
112 return FALSE;
113
114 if ( !enable && ChangeBitmap(m_bmpDisabled) )
115 Refresh();
116
117 return TRUE;
118}
119
120bool wxBitmapButton::SetCurrent(bool doit)
121{
122 ChangeBitmap(doit ? m_bmpFocus : m_bmpNormal);
123
124 return wxButton::SetCurrent(doit);
125}
126
127void wxBitmapButton::OnSetFocus(wxFocusEvent& event)
128{
129 if ( ChangeBitmap(m_bmpFocus) )
130 Refresh();
131
132 event.Skip();
133}
134
135void wxBitmapButton::OnKillFocus(wxFocusEvent& event)
136{
137 if ( ChangeBitmap(m_bmpNormal) )
138 Refresh();
139
140 event.Skip();
141}
142
143void wxBitmapButton::Press()
144{
145 ChangeBitmap(m_bmpSelected);
146
147 wxButton::Press();
148}
149
150void wxBitmapButton::Release()
151{
152 ChangeBitmap(IsFocused() ? m_bmpFocus : m_bmpNormal);
153
154 wxButton::Release();
155}
156
157#endif // wxUSE_BMPBUTTON
158