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_bitmaps
[State_Normal
] = bitmap
;
139 m_widget
= gtk_button_new();
140 g_object_ref(m_widget
);
142 if (style
& wxNO_BORDER
)
143 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
150 g_signal_connect_after (m_widget
, "clicked",
151 G_CALLBACK (gtk_bmpbutton_clicked_callback
),
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);
163 m_parent
->DoAddChild( this );
170 void wxBitmapButton::SetLabel( const wxString
&label
)
172 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
174 wxControl::SetLabel( label
);
177 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
179 if (!GTK_BIN(m_widget
)->child
)
182 wxButton::DoApplyWidgetStyle(style
);
185 void wxBitmapButton::OnSetBitmap()
187 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
189 InvalidateBestSize();
192 if (!IsThisEnabled())
193 the_one
= GetBitmapDisabled();
194 else if (m_isPressed
)
195 the_one
= GetBitmapPressed();
196 else if (m_mouseHovers
)
197 the_one
= GetBitmapHover();
199 the_one
= GetBitmapFocus();
203 the_one
= GetBitmapLabel();
208 GtkWidget
* image
= GTK_BIN(m_widget
)->child
;
211 image
= gtk_image_new();
212 gtk_widget_show(image
);
213 gtk_container_add(GTK_CONTAINER(m_widget
), image
);
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());
220 wxSize
wxBitmapButton::DoGetBestSize() const
222 return wxControl::DoGetBestSize();
225 bool wxBitmapButton::Enable( bool enable
)
227 if ( !wxWindow::Enable(enable
) )
235 void wxBitmapButton::GTKMouseEnters()
237 m_mouseHovers
= true;
241 void wxBitmapButton::GTKMouseLeaves()
243 m_mouseHovers
= false;
247 void wxBitmapButton::GTKPressed()
253 void wxBitmapButton::GTKReleased()
259 void wxBitmapButton::OnFocusChange(wxFocusEvent
& event
)
265 #endif // wxUSE_BMPBUTTON