]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/bmpbuttn.cpp
check for wxUSE_REARRANGECTRL being defined
[wxWidgets.git] / src / gtk / bmpbuttn.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/bmpbuttn.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#if wxUSE_BMPBUTTON
14
15#include "wx/bmpbuttn.h"
16
17#include <gtk/gtk.h>
18
19//-----------------------------------------------------------------------------
20// classes
21//-----------------------------------------------------------------------------
22
23class wxBitmapButton;
24
25//-----------------------------------------------------------------------------
26// data
27//-----------------------------------------------------------------------------
28
29extern bool g_blockEventsOnDrag;
30
31//-----------------------------------------------------------------------------
32// "clicked"
33//-----------------------------------------------------------------------------
34
35extern "C" {
36static void gtk_bmpbutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
37{
38 if (!button->m_hasVMT) return;
39 if (g_blockEventsOnDrag) return;
40
41 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
42 event.SetEventObject(button);
43 button->HandleWindowEvent(event);
44}
45}
46
47//-----------------------------------------------------------------------------
48// "enter"
49//-----------------------------------------------------------------------------
50
51extern "C" {
52static void gtk_bmpbutton_enter_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
53{
54 if (!button->m_hasVMT) return;
55 if (g_blockEventsOnDrag) return;
56
57 button->GTKMouseEnters();
58}
59}
60
61//-----------------------------------------------------------------------------
62// "leave"
63//-----------------------------------------------------------------------------
64
65extern "C" {
66static void gtk_bmpbutton_leave_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
67{
68 if (!button->m_hasVMT) return;
69 if (g_blockEventsOnDrag) return;
70
71 button->GTKMouseLeaves();
72}
73}
74
75//-----------------------------------------------------------------------------
76// "pressed"
77//-----------------------------------------------------------------------------
78
79extern "C" {
80static void gtk_bmpbutton_press_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
81{
82 if (!button->m_hasVMT) return;
83 if (g_blockEventsOnDrag) return;
84
85 button->GTKPressed();
86}
87}
88
89//-----------------------------------------------------------------------------
90// "released"
91//-----------------------------------------------------------------------------
92
93extern "C" {
94static void gtk_bmpbutton_release_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button )
95{
96 if (!button->m_hasVMT) return;
97 if (g_blockEventsOnDrag) return;
98
99 button->GTKReleased();
100}
101}
102
103//-----------------------------------------------------------------------------
104// wxBitmapButton
105//-----------------------------------------------------------------------------
106
107IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton,wxButton)
108
109BEGIN_EVENT_TABLE(wxBitmapButton, wxButton)
110 EVT_SET_FOCUS(wxBitmapButton::OnFocusChange)
111 EVT_KILL_FOCUS(wxBitmapButton::OnFocusChange)
112END_EVENT_TABLE()
113
114
115void wxBitmapButton::Init()
116{
117 m_mouseHovers =
118 m_isPressed = false;
119}
120
121bool wxBitmapButton::Create( wxWindow *parent,
122 wxWindowID id,
123 const wxBitmap& bitmap,
124 const wxPoint& pos,
125 const wxSize& size,
126 long style,
127 const wxValidator& validator,
128 const wxString &name )
129{
130 if (!PreCreation( parent, pos, size ) ||
131 !CreateBase( parent, id, pos, size, style, validator, name ))
132 {
133 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
134 return false;
135 }
136
137 m_bmpNormal = bitmap;
138
139 m_widget = gtk_button_new();
140 g_object_ref(m_widget);
141
142 if (style & wxNO_BORDER)
143 gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
144
145 if (m_bmpNormal.Ok())
146 {
147 OnSetBitmap();
148 }
149
150 g_signal_connect_after (m_widget, "clicked",
151 G_CALLBACK (gtk_bmpbutton_clicked_callback),
152 this);
153
154 g_signal_connect (m_widget, "enter",
155 G_CALLBACK (gtk_bmpbutton_enter_callback), this);
156 g_signal_connect (m_widget, "leave",
157 G_CALLBACK (gtk_bmpbutton_leave_callback), this);
158 g_signal_connect (m_widget, "pressed",
159 G_CALLBACK (gtk_bmpbutton_press_callback), this);
160 g_signal_connect (m_widget, "released",
161 G_CALLBACK (gtk_bmpbutton_release_callback), this);
162
163 m_parent->DoAddChild( this );
164
165 PostCreation(size);
166
167 return true;
168}
169
170void wxBitmapButton::SetLabel( const wxString &label )
171{
172 wxCHECK_RET( m_widget != NULL, wxT("invalid button") );
173
174 wxControl::SetLabel( label );
175}
176
177void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle *style)
178{
179 if (!GTK_BIN(m_widget)->child)
180 return;
181
182 wxButton::DoApplyWidgetStyle(style);
183}
184
185void wxBitmapButton::OnSetBitmap()
186{
187 wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") );
188
189 InvalidateBestSize();
190
191 wxBitmap the_one;
192 if (!IsThisEnabled())
193 the_one = m_bmpDisabled;
194 else if (m_isPressed)
195 the_one = m_bmpSelected;
196 else if (m_mouseHovers)
197 the_one = m_bmpHover;
198 else if (HasFocus())
199 the_one = m_bmpFocus;
200 else
201 the_one = m_bmpNormal;
202
203 if (!the_one.Ok())
204 the_one = m_bmpNormal;
205 if (!the_one.Ok())
206 return;
207
208 GtkWidget* image = GTK_BIN(m_widget)->child;
209 if (image == NULL)
210 {
211 image = gtk_image_new();
212 gtk_widget_show(image);
213 gtk_container_add(GTK_CONTAINER(m_widget), image);
214 }
215 // always use pixbuf, because pixmap mask does not
216 // work with disabled images in some themes
217 gtk_image_set_from_pixbuf(GTK_IMAGE(image), the_one.GetPixbuf());
218}
219
220wxSize wxBitmapButton::DoGetBestSize() const
221{
222 return wxControl::DoGetBestSize();
223}
224
225bool wxBitmapButton::Enable( bool enable )
226{
227 if ( !wxWindow::Enable(enable) )
228 return false;
229
230 OnSetBitmap();
231
232 return true;
233}
234
235void wxBitmapButton::GTKMouseEnters()
236{
237 m_mouseHovers = true;
238 OnSetBitmap();
239}
240
241void wxBitmapButton::GTKMouseLeaves()
242{
243 m_mouseHovers = false;
244 OnSetBitmap();
245}
246
247void wxBitmapButton::GTKPressed()
248{
249 m_isPressed = true;
250 OnSetBitmap();
251}
252
253void wxBitmapButton::GTKReleased()
254{
255 m_isPressed = false;
256 OnSetBitmap();
257}
258
259void wxBitmapButton::OnFocusChange(wxFocusEvent& event)
260{
261 event.Skip();
262 OnSetBitmap();
263}
264
265#endif // wxUSE_BMPBUTTON