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