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 wxString
wxBitmapButton::GetLabel() const
194 wxCHECK_MSG( m_widget
!= NULL
, wxEmptyString
, wxT("invalid button") );
196 return wxControl::GetLabel();
199 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
201 if ( !BUTTON_CHILD(m_widget
) )
204 wxButton::DoApplyWidgetStyle(style
);
207 void wxBitmapButton::OnSetBitmap()
209 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
211 InvalidateBestSize();
215 the_one
= m_bmpDisabled
;
216 else if (m_isSelected
)
217 the_one
= m_bmpSelected
;
219 the_one
= m_bmpFocus
;
221 the_one
= m_bmpNormal
;
223 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
224 if (!the_one
.Ok()) return;
226 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
227 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
229 GtkWidget
*child
= BUTTON_CHILD(m_widget
);
235 if (the_one
.HasPixbuf())
236 pixmap
= gtk_image_new_from_pixbuf(the_one
.GetPixbuf());
238 pixmap
= gtk_image_new_from_pixmap(the_one
.GetPixmap(), mask
);
240 pixmap
= gtk_pixmap_new(the_one
.GetPixmap(), mask
);
242 gtk_widget_show(pixmap
);
243 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
246 { // subsequent bitmaps
248 GtkImage
*pixmap
= GTK_IMAGE(child
);
249 if (the_one
.HasPixbuf())
250 gtk_image_set_from_pixbuf(pixmap
, the_one
.GetPixbuf());
252 gtk_image_set_from_pixmap(pixmap
, the_one
.GetPixmap(), mask
);
254 GtkPixmap
*pixmap
= GTK_PIXMAP(child
);
255 gtk_pixmap_set(pixmap
, the_one
.GetPixmap(), mask
);
260 wxSize
wxBitmapButton::DoGetBestSize() const
262 return wxControl::DoGetBestSize();
265 bool wxBitmapButton::Enable( bool enable
)
267 if ( !wxWindow::Enable(enable
) )
275 void wxBitmapButton::HasFocus()
281 void wxBitmapButton::NotFocus()
287 void wxBitmapButton::StartSelect()
293 void wxBitmapButton::EndSelect()
295 m_isSelected
= false;
299 #endif // wxUSE_BMPBUTTON