]>
Commit | Line | Data |
---|---|---|
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 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) | |
42 | ||
43 | BEGIN_EVENT_TABLE(wxBitmapButton, wxButton) | |
44 | EVT_SET_FOCUS(wxBitmapButton::OnSetFocus) | |
45 | EVT_KILL_FOCUS(wxBitmapButton::OnKillFocus) | |
46 | END_EVENT_TABLE() | |
47 | ||
48 | // ---------------------------------------------------------------------------- | |
49 | // wxBitmapButton | |
50 | // ---------------------------------------------------------------------------- | |
51 | ||
52 | bool wxBitmapButton::Create(wxWindow *parent, | |
53 | wxWindowID id, | |
54 | const wxBitmap& bitmap, | |
55 | const wxPoint &pos, | |
56 | const wxSize &size, | |
57 | long style, | |
58 | const wxValidator& validator, | |
59 | const wxString &name) | |
60 | { | |
61 | // we add wxBU_EXACTFIT because the bitmap buttons are not the standard | |
62 | // ones and so shouldn't be forced to be of the standard size which is | |
63 | // typically too big for them | |
64 | if ( !wxButton::Create(parent, id, bitmap, wxEmptyString, | |
65 | pos, size, style | wxBU_EXACTFIT, validator, name) ) | |
66 | return false; | |
67 | ||
68 | m_bmpNormal = bitmap; | |
69 | ||
70 | return true; | |
71 | } | |
72 | ||
73 | void 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 | ||
96 | bool 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 | ||
109 | bool 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 | ||
120 | bool wxBitmapButton::SetCurrent(bool doit) | |
121 | { | |
122 | ChangeBitmap(doit ? m_bmpFocus : m_bmpNormal); | |
123 | ||
124 | return wxButton::SetCurrent(doit); | |
125 | } | |
126 | ||
127 | void wxBitmapButton::OnSetFocus(wxFocusEvent& event) | |
128 | { | |
129 | if ( ChangeBitmap(m_bmpFocus) ) | |
130 | Refresh(); | |
131 | ||
132 | event.Skip(); | |
133 | } | |
134 | ||
135 | void wxBitmapButton::OnKillFocus(wxFocusEvent& event) | |
136 | { | |
137 | if ( ChangeBitmap(m_bmpNormal) ) | |
138 | Refresh(); | |
139 | ||
140 | event.Skip(); | |
141 | } | |
142 | ||
143 | void wxBitmapButton::Press() | |
144 | { | |
145 | ChangeBitmap(m_bmpSelected); | |
146 | ||
147 | wxButton::Press(); | |
148 | } | |
149 | ||
150 | void wxBitmapButton::Release() | |
151 | { | |
152 | ChangeBitmap(IsFocused() ? m_bmpFocus : m_bmpNormal); | |
153 | ||
154 | wxButton::Release(); | |
155 | } | |
156 | ||
157 | #endif // wxUSE_BMPBUTTON |