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"
17 #include "wx/gtk/private.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 extern bool g_blockEventsOnDrag
;
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
36 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
39 wxapp_install_idle_handler();
41 if (!button
->m_hasVMT
) return;
42 if (g_blockEventsOnDrag
) return;
44 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
45 event
.SetEventObject(button
);
46 button
->GetEventHandler()->ProcessEvent(event
);
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
55 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
57 if (!button
->m_hasVMT
) return;
58 if (g_blockEventsOnDrag
) return;
64 //-----------------------------------------------------------------------------
66 //-----------------------------------------------------------------------------
69 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
71 if (!button
->m_hasVMT
) return;
72 if (g_blockEventsOnDrag
) return;
78 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
83 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
85 if (!button
->m_hasVMT
) return;
86 if (g_blockEventsOnDrag
) return;
88 button
->StartSelect();
92 //-----------------------------------------------------------------------------
94 //-----------------------------------------------------------------------------
97 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
99 if (!button
->m_hasVMT
) return;
100 if (g_blockEventsOnDrag
) return;
106 //-----------------------------------------------------------------------------
108 //-----------------------------------------------------------------------------
110 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxButton
)
112 void wxBitmapButton::Init()
115 m_isSelected
= false;
118 bool wxBitmapButton::Create( wxWindow
*parent
,
120 const wxBitmap
& bitmap
,
124 const wxValidator
& validator
,
125 const wxString
&name
)
129 if (!PreCreation( parent
, pos
, size
) ||
130 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
132 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
136 m_bmpNormal
= bitmap
;
138 m_widget
= gtk_button_new();
140 if (style
& wxNO_BORDER
)
141 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
143 if (m_bmpNormal
.Ok())
148 g_signal_connect_after (m_widget
, "clicked",
149 G_CALLBACK (gtk_bmpbutton_clicked_callback
),
152 g_signal_connect (m_widget
, "enter",
153 G_CALLBACK (gtk_bmpbutton_enter_callback
), this);
154 g_signal_connect (m_widget
, "leave",
155 G_CALLBACK (gtk_bmpbutton_leave_callback
), this);
156 g_signal_connect (m_widget
, "pressed",
157 G_CALLBACK (gtk_bmpbutton_press_callback
), this);
158 g_signal_connect (m_widget
, "released",
159 G_CALLBACK (gtk_bmpbutton_release_callback
), this);
161 m_parent
->DoAddChild( this );
168 void wxBitmapButton::SetDefault()
170 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
171 gtk_widget_grab_default( m_widget
);
173 SetSize( m_x
, m_y
, m_width
, m_height
);
176 void wxBitmapButton::SetLabel( const wxString
&label
)
178 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
180 wxControl::SetLabel( label
);
183 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
185 if (!GTK_BIN(m_widget
)->child
)
188 wxButton::DoApplyWidgetStyle(style
);
191 void wxBitmapButton::OnSetBitmap()
193 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
195 InvalidateBestSize();
198 if (!IsThisEnabled())
199 the_one
= m_bmpDisabled
;
200 else if (m_isSelected
)
201 the_one
= m_bmpSelected
;
203 the_one
= m_bmpFocus
;
205 the_one
= m_bmpNormal
;
207 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
208 if (!the_one
.Ok()) return;
210 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
211 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
213 GtkWidget
*child
= GTK_BIN(m_widget
)->child
;
219 if (the_one
.HasPixbuf())
220 pixmap
= gtk_image_new_from_pixbuf(the_one
.GetPixbuf());
222 pixmap
= gtk_image_new_from_pixmap(the_one
.GetPixmap(), mask
);
224 gtk_widget_show(pixmap
);
225 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
228 { // subsequent bitmaps
229 GtkImage
*pixmap
= GTK_IMAGE(child
);
230 if (the_one
.HasPixbuf())
231 gtk_image_set_from_pixbuf(pixmap
, the_one
.GetPixbuf());
233 gtk_image_set_from_pixmap(pixmap
, the_one
.GetPixmap(), mask
);
237 wxSize
wxBitmapButton::DoGetBestSize() const
239 return wxControl::DoGetBestSize();
242 bool wxBitmapButton::Enable( bool enable
)
244 if ( !wxWindow::Enable(enable
) )
252 void wxBitmapButton::HasFocus()
258 void wxBitmapButton::NotFocus()
264 void wxBitmapButton::StartSelect()
270 void wxBitmapButton::EndSelect()
272 m_isSelected
= false;
276 #endif // wxUSE_BMPBUTTON