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
->GTKHasFocus();
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
->GTKNotFocus();
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;
85 button
->GTKStartSelect();
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
->GTKEndSelect();
103 //-----------------------------------------------------------------------------
105 //-----------------------------------------------------------------------------
107 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxButton
)
109 void wxBitmapButton::Init()
112 m_isSelected
= false;
115 bool wxBitmapButton::Create( wxWindow
*parent
,
117 const wxBitmap
& bitmap
,
121 const wxValidator
& validator
,
122 const wxString
&name
)
124 if (!PreCreation( parent
, pos
, size
) ||
125 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
127 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
131 m_bmpNormal
= bitmap
;
133 m_widget
= gtk_button_new();
135 if (style
& wxNO_BORDER
)
136 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
138 if (m_bmpNormal
.Ok())
143 g_signal_connect_after (m_widget
, "clicked",
144 G_CALLBACK (gtk_bmpbutton_clicked_callback
),
147 g_signal_connect (m_widget
, "enter",
148 G_CALLBACK (gtk_bmpbutton_enter_callback
), this);
149 g_signal_connect (m_widget
, "leave",
150 G_CALLBACK (gtk_bmpbutton_leave_callback
), this);
151 g_signal_connect (m_widget
, "pressed",
152 G_CALLBACK (gtk_bmpbutton_press_callback
), this);
153 g_signal_connect (m_widget
, "released",
154 G_CALLBACK (gtk_bmpbutton_release_callback
), this);
156 m_parent
->DoAddChild( this );
163 void wxBitmapButton::SetLabel( const wxString
&label
)
165 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
167 wxControl::SetLabel( label
);
170 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
172 if (!GTK_BIN(m_widget
)->child
)
175 wxButton::DoApplyWidgetStyle(style
);
178 void wxBitmapButton::OnSetBitmap()
180 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
182 InvalidateBestSize();
185 if (!IsThisEnabled())
186 the_one
= m_bmpDisabled
;
187 else if (m_isSelected
)
188 the_one
= m_bmpSelected
;
190 the_one
= m_bmpFocus
;
192 the_one
= m_bmpNormal
;
194 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
195 if (!the_one
.Ok()) return;
197 GtkWidget
*child
= GTK_BIN(m_widget
)->child
;
202 gtk_image_new_from_pixbuf(the_one
.GetPixbuf());
204 gtk_widget_show(pixmap
);
205 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
208 { // subsequent bitmaps
209 GtkImage
*pixmap
= GTK_IMAGE(child
);
210 gtk_image_set_from_pixbuf(pixmap
, the_one
.GetPixbuf());
214 wxSize
wxBitmapButton::DoGetBestSize() const
216 return wxControl::DoGetBestSize();
219 bool wxBitmapButton::Enable( bool enable
)
221 if ( !wxWindow::Enable(enable
) )
229 void wxBitmapButton::GTKHasFocus()
235 void wxBitmapButton::GTKNotFocus()
241 void wxBitmapButton::GTKStartSelect()
247 void wxBitmapButton::GTKEndSelect()
249 m_isSelected
= false;
253 #endif // wxUSE_BMPBUTTON