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 g_signal_connect_after (m_widget
, "clicked",
159 G_CALLBACK (gtk_bmpbutton_clicked_callback
),
162 g_signal_connect (m_widget
, "enter",
163 G_CALLBACK (gtk_bmpbutton_enter_callback
), this);
164 g_signal_connect (m_widget
, "leave",
165 G_CALLBACK (gtk_bmpbutton_leave_callback
), this);
166 g_signal_connect (m_widget
, "pressed",
167 G_CALLBACK (gtk_bmpbutton_press_callback
), this);
168 g_signal_connect (m_widget
, "released",
169 G_CALLBACK (gtk_bmpbutton_release_callback
), this);
171 m_parent
->DoAddChild( this );
178 void wxBitmapButton::SetDefault()
180 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
181 gtk_widget_grab_default( m_widget
);
183 SetSize( m_x
, m_y
, m_width
, m_height
);
186 void wxBitmapButton::SetLabel( const wxString
&label
)
188 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
190 wxControl::SetLabel( label
);
193 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
195 if ( !BUTTON_CHILD(m_widget
) )
198 wxButton::DoApplyWidgetStyle(style
);
201 void wxBitmapButton::OnSetBitmap()
203 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
205 InvalidateBestSize();
209 the_one
= m_bmpDisabled
;
210 else if (m_isSelected
)
211 the_one
= m_bmpSelected
;
213 the_one
= m_bmpFocus
;
215 the_one
= m_bmpNormal
;
217 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
218 if (!the_one
.Ok()) return;
220 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
221 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
223 GtkWidget
*child
= BUTTON_CHILD(m_widget
);
229 if (the_one
.HasPixbuf())
230 pixmap
= gtk_image_new_from_pixbuf(the_one
.GetPixbuf());
232 pixmap
= gtk_image_new_from_pixmap(the_one
.GetPixmap(), mask
);
234 gtk_widget_show(pixmap
);
235 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
238 { // subsequent bitmaps
239 GtkImage
*pixmap
= GTK_IMAGE(child
);
240 if (the_one
.HasPixbuf())
241 gtk_image_set_from_pixbuf(pixmap
, the_one
.GetPixbuf());
243 gtk_image_set_from_pixmap(pixmap
, the_one
.GetPixmap(), mask
);
247 wxSize
wxBitmapButton::DoGetBestSize() const
249 return wxControl::DoGetBestSize();
252 bool wxBitmapButton::Enable( bool enable
)
254 if ( !wxWindow::Enable(enable
) )
262 void wxBitmapButton::HasFocus()
268 void wxBitmapButton::NotFocus()
274 void wxBitmapButton::StartSelect()
280 void wxBitmapButton::EndSelect()
282 m_isSelected
= false;
286 #endif // wxUSE_BMPBUTTON