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