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 bool g_blockEventsOnDrag
;
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
38 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
41 wxapp_install_idle_handler();
43 if (!button
->m_hasVMT
) return;
44 if (g_blockEventsOnDrag
) return;
46 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
47 event
.SetEventObject(button
);
48 button
->GetEventHandler()->ProcessEvent(event
);
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
57 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
59 if (!button
->m_hasVMT
) return;
60 if (g_blockEventsOnDrag
) return;
66 //-----------------------------------------------------------------------------
68 //-----------------------------------------------------------------------------
71 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
73 if (!button
->m_hasVMT
) return;
74 if (g_blockEventsOnDrag
) return;
80 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
85 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
87 if (!button
->m_hasVMT
) return;
88 if (g_blockEventsOnDrag
) return;
90 button
->StartSelect();
94 //-----------------------------------------------------------------------------
96 //-----------------------------------------------------------------------------
99 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
101 if (!button
->m_hasVMT
) return;
102 if (g_blockEventsOnDrag
) return;
108 //-----------------------------------------------------------------------------
110 //-----------------------------------------------------------------------------
112 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxButton
)
114 void wxBitmapButton::Init()
117 m_isSelected
= false;
120 bool wxBitmapButton::Create( wxWindow
*parent
,
122 const wxBitmap
& bitmap
,
126 const wxValidator
& validator
,
127 const wxString
&name
)
130 m_acceptsFocus
= true;
132 if (!PreCreation( parent
, pos
, size
) ||
133 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
135 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
139 m_bmpNormal
= bitmap
;
141 m_widget
= gtk_button_new();
143 if (style
& wxNO_BORDER
)
144 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
146 if (m_bmpNormal
.Ok())
151 g_signal_connect_after (m_widget
, "clicked",
152 G_CALLBACK (gtk_bmpbutton_clicked_callback
),
155 g_signal_connect (m_widget
, "enter",
156 G_CALLBACK (gtk_bmpbutton_enter_callback
), this);
157 g_signal_connect (m_widget
, "leave",
158 G_CALLBACK (gtk_bmpbutton_leave_callback
), this);
159 g_signal_connect (m_widget
, "pressed",
160 G_CALLBACK (gtk_bmpbutton_press_callback
), this);
161 g_signal_connect (m_widget
, "released",
162 G_CALLBACK (gtk_bmpbutton_release_callback
), this);
164 m_parent
->DoAddChild( this );
171 void wxBitmapButton::SetDefault()
173 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
174 gtk_widget_grab_default( m_widget
);
176 SetSize( m_x
, m_y
, m_width
, m_height
);
179 void wxBitmapButton::SetLabel( const wxString
&label
)
181 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
183 wxControl::SetLabel( label
);
186 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
188 if (!GTK_BIN(m_widget
)->child
)
191 wxButton::DoApplyWidgetStyle(style
);
194 void wxBitmapButton::OnSetBitmap()
196 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
198 InvalidateBestSize();
202 the_one
= m_bmpDisabled
;
203 else if (m_isSelected
)
204 the_one
= m_bmpSelected
;
206 the_one
= m_bmpFocus
;
208 the_one
= m_bmpNormal
;
210 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
211 if (!the_one
.Ok()) return;
213 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
214 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
216 GtkWidget
*child
= GTK_BIN(m_widget
)->child
;
222 if (the_one
.HasPixbuf())
223 pixmap
= gtk_image_new_from_pixbuf(the_one
.GetPixbuf());
225 pixmap
= gtk_image_new_from_pixmap(the_one
.GetPixmap(), mask
);
227 gtk_widget_show(pixmap
);
228 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
231 { // subsequent bitmaps
232 GtkImage
*pixmap
= GTK_IMAGE(child
);
233 if (the_one
.HasPixbuf())
234 gtk_image_set_from_pixbuf(pixmap
, the_one
.GetPixbuf());
236 gtk_image_set_from_pixmap(pixmap
, the_one
.GetPixmap(), mask
);
240 wxSize
wxBitmapButton::DoGetBestSize() const
242 return wxControl::DoGetBestSize();
245 bool wxBitmapButton::Enable( bool enable
)
247 if ( !wxWindow::Enable(enable
) )
255 void wxBitmapButton::HasFocus()
261 void wxBitmapButton::NotFocus()
267 void wxBitmapButton::StartSelect()
273 void wxBitmapButton::EndSelect()
275 m_isSelected
= false;
279 #endif // wxUSE_BMPBUTTON