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
)
126 if (!PreCreation( parent
, pos
, size
) ||
127 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
129 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
133 m_bmpNormal
= bitmap
;
135 m_widget
= gtk_button_new();
137 if (style
& wxNO_BORDER
)
138 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
140 if (m_bmpNormal
.Ok())
145 g_signal_connect_after (m_widget
, "clicked",
146 G_CALLBACK (gtk_bmpbutton_clicked_callback
),
149 g_signal_connect (m_widget
, "enter",
150 G_CALLBACK (gtk_bmpbutton_enter_callback
), this);
151 g_signal_connect (m_widget
, "leave",
152 G_CALLBACK (gtk_bmpbutton_leave_callback
), this);
153 g_signal_connect (m_widget
, "pressed",
154 G_CALLBACK (gtk_bmpbutton_press_callback
), this);
155 g_signal_connect (m_widget
, "released",
156 G_CALLBACK (gtk_bmpbutton_release_callback
), this);
158 m_parent
->DoAddChild( this );
165 void wxBitmapButton::SetLabel( const wxString
&label
)
167 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
169 wxControl::SetLabel( label
);
172 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
174 if (!GTK_BIN(m_widget
)->child
)
177 wxButton::DoApplyWidgetStyle(style
);
180 void wxBitmapButton::OnSetBitmap()
182 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
184 InvalidateBestSize();
187 if (!IsThisEnabled())
188 the_one
= m_bmpDisabled
;
189 else if (m_isSelected
)
190 the_one
= m_bmpSelected
;
192 the_one
= m_bmpFocus
;
194 the_one
= m_bmpNormal
;
196 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
197 if (!the_one
.Ok()) return;
199 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
200 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
202 GtkWidget
*child
= GTK_BIN(m_widget
)->child
;
208 if (the_one
.HasPixbuf())
209 pixmap
= gtk_image_new_from_pixbuf(the_one
.GetPixbuf());
211 pixmap
= gtk_image_new_from_pixmap(the_one
.GetPixmap(), mask
);
213 gtk_widget_show(pixmap
);
214 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
217 { // subsequent bitmaps
218 GtkImage
*pixmap
= GTK_IMAGE(child
);
219 if (the_one
.HasPixbuf())
220 gtk_image_set_from_pixbuf(pixmap
, the_one
.GetPixbuf());
222 gtk_image_set_from_pixmap(pixmap
, the_one
.GetPixmap(), mask
);
226 wxSize
wxBitmapButton::DoGetBestSize() const
228 return wxControl::DoGetBestSize();
231 bool wxBitmapButton::Enable( bool enable
)
233 if ( !wxWindow::Enable(enable
) )
241 void wxBitmapButton::HasFocus()
247 void wxBitmapButton::NotFocus()
253 void wxBitmapButton::StartSelect()
259 void wxBitmapButton::EndSelect()
261 m_isSelected
= false;
265 #endif // wxUSE_BMPBUTTON