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
->GetEventHandler()->ProcessEvent(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;
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;
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
->StartSelect();
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;
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 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
198 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
200 GtkWidget
*child
= GTK_BIN(m_widget
)->child
;
206 if (the_one
.HasPixbuf())
207 pixmap
= gtk_image_new_from_pixbuf(the_one
.GetPixbuf());
209 pixmap
= gtk_image_new_from_pixmap(the_one
.GetPixmap(), mask
);
211 gtk_widget_show(pixmap
);
212 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
215 { // subsequent bitmaps
216 GtkImage
*pixmap
= GTK_IMAGE(child
);
217 if (the_one
.HasPixbuf())
218 gtk_image_set_from_pixbuf(pixmap
, the_one
.GetPixbuf());
220 gtk_image_set_from_pixmap(pixmap
, the_one
.GetPixmap(), mask
);
224 wxSize
wxBitmapButton::DoGetBestSize() const
226 return wxControl::DoGetBestSize();
229 bool wxBitmapButton::Enable( bool enable
)
231 if ( !wxWindow::Enable(enable
) )
239 void wxBitmapButton::HasFocus()
245 void wxBitmapButton::NotFocus()
251 void wxBitmapButton::StartSelect()
257 void wxBitmapButton::EndSelect()
259 m_isSelected
= false;
263 #endif // wxUSE_BMPBUTTON