1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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"
17 #include "wx/bmpbuttn.h"
19 #include "wx/gtk/private.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 extern void wxapp_install_idle_handler();
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 extern bool g_blockEventsOnDrag
;
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
45 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
48 wxapp_install_idle_handler();
50 if (!button
->m_hasVMT
) return;
51 if (g_blockEventsOnDrag
) return;
53 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
54 event
.SetEventObject(button
);
55 button
->GetEventHandler()->ProcessEvent(event
);
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
64 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
66 if (!button
->m_hasVMT
) return;
67 if (g_blockEventsOnDrag
) return;
73 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
78 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
80 if (!button
->m_hasVMT
) return;
81 if (g_blockEventsOnDrag
) return;
87 //-----------------------------------------------------------------------------
89 //-----------------------------------------------------------------------------
92 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
94 if (!button
->m_hasVMT
) return;
95 if (g_blockEventsOnDrag
) return;
97 button
->StartSelect();
101 //-----------------------------------------------------------------------------
103 //-----------------------------------------------------------------------------
106 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
108 if (!button
->m_hasVMT
) return;
109 if (g_blockEventsOnDrag
) return;
115 //-----------------------------------------------------------------------------
117 //-----------------------------------------------------------------------------
119 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxButton
)
121 void wxBitmapButton::Init()
124 m_isSelected
= false;
127 bool wxBitmapButton::Create( wxWindow
*parent
,
129 const wxBitmap
& bitmap
,
133 const wxValidator
& validator
,
134 const wxString
&name
)
137 m_acceptsFocus
= true;
139 if (!PreCreation( parent
, pos
, size
) ||
140 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
142 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
146 m_bmpNormal
= bitmap
;
148 m_widget
= gtk_button_new();
150 if (style
& wxNO_BORDER
)
151 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
153 if (m_bmpNormal
.Ok())
158 gtk_signal_connect_after( GTK_OBJECT(m_widget
), "clicked",
159 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
161 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
162 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
163 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
164 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
165 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
166 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
167 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
168 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
170 m_parent
->DoAddChild( this );
177 void wxBitmapButton::SetDefault()
179 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
180 gtk_widget_grab_default( m_widget
);
182 SetSize( m_x
, m_y
, m_width
, m_height
);
185 void wxBitmapButton::SetLabel( const wxString
&label
)
187 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
189 wxControl::SetLabel( label
);
192 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
194 if ( !BUTTON_CHILD(m_widget
) )
197 wxButton::DoApplyWidgetStyle(style
);
200 void wxBitmapButton::OnSetBitmap()
202 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
204 InvalidateBestSize();
208 the_one
= m_bmpDisabled
;
209 else if (m_isSelected
)
210 the_one
= m_bmpSelected
;
212 the_one
= m_bmpFocus
;
214 the_one
= m_bmpNormal
;
216 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
217 if (!the_one
.Ok()) return;
219 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
220 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
222 GtkWidget
*child
= BUTTON_CHILD(m_widget
);
228 if (the_one
.HasPixbuf())
229 pixmap
= gtk_image_new_from_pixbuf(the_one
.GetPixbuf());
231 pixmap
= gtk_image_new_from_pixmap(the_one
.GetPixmap(), mask
);
233 gtk_widget_show(pixmap
);
234 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
237 { // subsequent bitmaps
238 GtkImage
*pixmap
= GTK_IMAGE(child
);
239 if (the_one
.HasPixbuf())
240 gtk_image_set_from_pixbuf(pixmap
, the_one
.GetPixbuf());
242 gtk_image_set_from_pixmap(pixmap
, the_one
.GetPixmap(), mask
);
246 wxSize
wxBitmapButton::DoGetBestSize() const
248 return wxControl::DoGetBestSize();
251 bool wxBitmapButton::Enable( bool enable
)
253 if ( !wxWindow::Enable(enable
) )
261 void wxBitmapButton::HasFocus()
267 void wxBitmapButton::NotFocus()
273 void wxBitmapButton::StartSelect()
279 void wxBitmapButton::EndSelect()
281 m_isSelected
= false;
285 #endif // wxUSE_BMPBUTTON