]> git.saurik.com Git - wxWidgets.git/blame - src/univ/bmpbuttn.cpp
precompiled headers changed
[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)
6aa89a22 9// Licence: wxWindows licence
1e6feb95
VZ
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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{
ef2f095a
VZ
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
1e6feb95 67 if ( !wxButton::Create(parent, id, bitmap, _T(""),
ef2f095a 68 pos, size, style | wxBU_EXACTFIT, validator, name) )
1e6feb95
VZ
69 return FALSE;
70
71 m_bmpNormal = bitmap;
72
73 return TRUE;
74}
75
76void 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
99bool 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
112bool 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
123bool wxBitmapButton::SetCurrent(bool doit)
124{
125 ChangeBitmap(doit ? m_bmpFocus : m_bmpNormal);
126
127 return wxButton::SetCurrent(doit);
128}
129
130void wxBitmapButton::OnSetFocus(wxFocusEvent& event)
131{
132 if ( ChangeBitmap(m_bmpFocus) )
133 Refresh();
134
135 event.Skip();
136}
137
138void wxBitmapButton::OnKillFocus(wxFocusEvent& event)
139{
140 if ( ChangeBitmap(m_bmpNormal) )
141 Refresh();
142
143 event.Skip();
144}
145
146void wxBitmapButton::Press()
147{
148 ChangeBitmap(m_bmpSelected);
149
150 wxButton::Press();
151}
152
153void wxBitmapButton::Release()
154{
155 ChangeBitmap(IsFocused() ? m_bmpFocus : m_bmpNormal);
156
157 wxButton::Release();
158}
159
160#endif // wxUSE_BMPBUTTON
161