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
, wxT(""), 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
;
228 the_one
= m_bmpSelected
;
233 the_one
= m_bmpFocus
;
235 the_one
= m_bmpNormal
;
239 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
240 if (!the_one
.Ok()) return;
242 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
243 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
245 GtkWidget
*child
= BUTTON_CHILD(m_widget
);
251 if (the_one
.HasPixbuf())
252 pixmap
= gtk_image_new_from_pixbuf(the_one
.GetPixbuf());
254 pixmap
= gtk_image_new_from_pixmap(the_one
.GetPixmap(), mask
);
256 pixmap
= gtk_pixmap_new(the_one
.GetPixmap(), mask
);
258 gtk_widget_show(pixmap
);
259 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
262 { // subsequent bitmaps
264 GtkImage
*pixmap
= GTK_IMAGE(child
);
265 if (the_one
.HasPixbuf())
266 gtk_image_set_from_pixbuf(pixmap
, the_one
.GetPixbuf());
268 gtk_image_set_from_pixmap(pixmap
, the_one
.GetPixmap(), mask
);
270 GtkPixmap
*pixmap
= GTK_PIXMAP(child
);
271 gtk_pixmap_set(pixmap
, the_one
.GetPixmap(), mask
);
276 wxSize
wxBitmapButton::DoGetBestSize() const
278 return wxControl::DoGetBestSize();
281 bool wxBitmapButton::Enable( bool enable
)
283 if ( !wxWindow::Enable(enable
) )
291 void wxBitmapButton::HasFocus()
297 void wxBitmapButton::NotFocus()
303 void wxBitmapButton::StartSelect()
309 void wxBitmapButton::EndSelect()
311 m_isSelected
= FALSE
;
315 #endif // wxUSE_BMPBUTTON