1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/bmpbuttn.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "bmpbuttn.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
21 #include "wx/bmpbuttn.h"
23 #include "wx/gtk/private.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 extern void wxapp_install_idle_handler();
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 extern bool g_blockEventsOnDrag
;
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
49 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
52 wxapp_install_idle_handler();
54 if (!button
->m_hasVMT
) return;
55 if (g_blockEventsOnDrag
) return;
57 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
58 event
.SetEventObject(button
);
59 button
->GetEventHandler()->ProcessEvent(event
);
63 //-----------------------------------------------------------------------------
65 //-----------------------------------------------------------------------------
68 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
70 if (!button
->m_hasVMT
) return;
71 if (g_blockEventsOnDrag
) return;
77 //-----------------------------------------------------------------------------
79 //-----------------------------------------------------------------------------
82 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
84 if (!button
->m_hasVMT
) return;
85 if (g_blockEventsOnDrag
) return;
91 //-----------------------------------------------------------------------------
93 //-----------------------------------------------------------------------------
96 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
98 if (!button
->m_hasVMT
) return;
99 if (g_blockEventsOnDrag
) return;
101 button
->StartSelect();
105 //-----------------------------------------------------------------------------
107 //-----------------------------------------------------------------------------
110 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
112 if (!button
->m_hasVMT
) return;
113 if (g_blockEventsOnDrag
) return;
119 //-----------------------------------------------------------------------------
121 //-----------------------------------------------------------------------------
123 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxButton
)
125 void wxBitmapButton::Init()
128 m_isSelected
= false;
131 bool wxBitmapButton::Create( wxWindow
*parent
,
133 const wxBitmap
& bitmap
,
137 const wxValidator
& validator
,
138 const wxString
&name
)
141 m_acceptsFocus
= true;
143 if (!PreCreation( parent
, pos
, size
) ||
144 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
146 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
150 m_bmpNormal
= bitmap
;
152 m_widget
= gtk_button_new();
154 if (style
& wxNO_BORDER
)
155 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
157 if (m_bmpNormal
.Ok())
162 gtk_signal_connect_after( GTK_OBJECT(m_widget
), "clicked",
163 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
165 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
166 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
167 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
168 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
169 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
170 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
171 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
172 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
174 m_parent
->DoAddChild( this );
181 void wxBitmapButton::SetDefault()
183 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
184 gtk_widget_grab_default( m_widget
);
186 SetSize( m_x
, m_y
, m_width
, m_height
);
189 void wxBitmapButton::SetLabel( const wxString
&label
)
191 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
193 wxControl::SetLabel( label
);
196 wxString
wxBitmapButton::GetLabel() const
198 wxCHECK_MSG( m_widget
!= NULL
, wxEmptyString
, wxT("invalid button") );
200 return wxControl::GetLabel();
203 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
205 if ( !BUTTON_CHILD(m_widget
) )
208 wxButton::DoApplyWidgetStyle(style
);
211 void wxBitmapButton::OnSetBitmap()
213 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
215 InvalidateBestSize();
219 the_one
= m_bmpDisabled
;
220 else if (m_isSelected
)
221 the_one
= m_bmpSelected
;
223 the_one
= m_bmpFocus
;
225 the_one
= m_bmpNormal
;
227 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
228 if (!the_one
.Ok()) return;
230 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
231 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
233 GtkWidget
*child
= BUTTON_CHILD(m_widget
);
239 if (the_one
.HasPixbuf())
240 pixmap
= gtk_image_new_from_pixbuf(the_one
.GetPixbuf());
242 pixmap
= gtk_image_new_from_pixmap(the_one
.GetPixmap(), mask
);
244 pixmap
= gtk_pixmap_new(the_one
.GetPixmap(), mask
);
246 gtk_widget_show(pixmap
);
247 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
250 { // subsequent bitmaps
252 GtkImage
*pixmap
= GTK_IMAGE(child
);
253 if (the_one
.HasPixbuf())
254 gtk_image_set_from_pixbuf(pixmap
, the_one
.GetPixbuf());
256 gtk_image_set_from_pixmap(pixmap
, the_one
.GetPixmap(), mask
);
258 GtkPixmap
*pixmap
= GTK_PIXMAP(child
);
259 gtk_pixmap_set(pixmap
, the_one
.GetPixmap(), mask
);
264 wxSize
wxBitmapButton::DoGetBestSize() const
266 return wxControl::DoGetBestSize();
269 bool wxBitmapButton::Enable( bool enable
)
271 if ( !wxWindow::Enable(enable
) )
279 void wxBitmapButton::HasFocus()
285 void wxBitmapButton::NotFocus()
291 void wxBitmapButton::StartSelect()
297 void wxBitmapButton::EndSelect()
299 m_isSelected
= false;
303 #endif // wxUSE_BMPBUTTON