1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/bmpbuttn.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
15 #include "wx/bmpbuttn.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 extern bool g_blockEventsOnDrag
;
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
36 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
38 if (!button
->m_hasVMT
) return;
39 if (g_blockEventsOnDrag
) return;
41 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
42 event
.SetEventObject(button
);
43 button
->HandleWindowEvent(event
);
47 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
52 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
54 if (!button
->m_hasVMT
) return;
55 if (g_blockEventsOnDrag
) return;
57 button
->GTKMouseEnters();
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
66 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
68 if (!button
->m_hasVMT
) return;
69 if (g_blockEventsOnDrag
) return;
71 button
->GTKMouseLeaves();
75 //-----------------------------------------------------------------------------
77 //-----------------------------------------------------------------------------
80 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
82 if (!button
->m_hasVMT
) return;
83 if (g_blockEventsOnDrag
) return;
89 //-----------------------------------------------------------------------------
91 //-----------------------------------------------------------------------------
94 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
96 if (!button
->m_hasVMT
) return;
97 if (g_blockEventsOnDrag
) return;
99 button
->GTKReleased();
103 //-----------------------------------------------------------------------------
105 //-----------------------------------------------------------------------------
107 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxButton
)
109 BEGIN_EVENT_TABLE(wxBitmapButton
, wxButton
)
110 EVT_SET_FOCUS(wxBitmapButton::OnFocusChange
)
111 EVT_KILL_FOCUS(wxBitmapButton::OnFocusChange
)
115 void wxBitmapButton::Init()
121 bool wxBitmapButton::Create( wxWindow
*parent
,
123 const wxBitmap
& bitmap
,
127 const wxValidator
& validator
,
128 const wxString
&name
)
130 if (!PreCreation( parent
, pos
, size
) ||
131 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
133 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
137 m_bmpNormal
= bitmap
;
139 m_widget
= gtk_button_new();
141 if (style
& wxNO_BORDER
)
142 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
144 if (m_bmpNormal
.Ok())
149 g_signal_connect_after (m_widget
, "clicked",
150 G_CALLBACK (gtk_bmpbutton_clicked_callback
),
153 g_signal_connect (m_widget
, "enter",
154 G_CALLBACK (gtk_bmpbutton_enter_callback
), this);
155 g_signal_connect (m_widget
, "leave",
156 G_CALLBACK (gtk_bmpbutton_leave_callback
), this);
157 g_signal_connect (m_widget
, "pressed",
158 G_CALLBACK (gtk_bmpbutton_press_callback
), this);
159 g_signal_connect (m_widget
, "released",
160 G_CALLBACK (gtk_bmpbutton_release_callback
), this);
162 m_parent
->DoAddChild( this );
169 void wxBitmapButton::SetLabel( const wxString
&label
)
171 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
173 wxControl::SetLabel( label
);
176 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
178 if (!GTK_BIN(m_widget
)->child
)
181 wxButton::DoApplyWidgetStyle(style
);
184 void wxBitmapButton::OnSetBitmap()
186 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
188 InvalidateBestSize();
191 if (!IsThisEnabled())
192 the_one
= m_bmpDisabled
;
193 else if (m_isPressed
)
194 the_one
= m_bmpSelected
;
195 else if (m_mouseHovers
)
196 the_one
= m_bmpHover
;
198 the_one
= m_bmpFocus
;
200 the_one
= m_bmpNormal
;
203 the_one
= m_bmpNormal
;
207 GtkWidget
* image
= GTK_BIN(m_widget
)->child
;
210 image
= gtk_image_new();
211 gtk_widget_show(image
);
212 gtk_container_add(GTK_CONTAINER(m_widget
), image
);
214 // always use pixbuf, because pixmap mask does not
215 // work with disabled images in some themes
216 gtk_image_set_from_pixbuf(GTK_IMAGE(image
), the_one
.GetPixbuf());
219 wxSize
wxBitmapButton::DoGetBestSize() const
221 return wxControl::DoGetBestSize();
224 bool wxBitmapButton::Enable( bool enable
)
226 if ( !wxWindow::Enable(enable
) )
234 void wxBitmapButton::GTKMouseEnters()
236 m_mouseHovers
= true;
240 void wxBitmapButton::GTKMouseLeaves()
242 m_mouseHovers
= false;
246 void wxBitmapButton::GTKPressed()
252 void wxBitmapButton::GTKReleased()
258 void wxBitmapButton::OnFocusChange(wxFocusEvent
& event
)
264 #endif // wxUSE_BMPBUTTON