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::SetLabel( const wxString
&label
)
170 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
172 wxControl::SetLabel( label
);
175 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
177 if (!GTK_BIN(m_widget
)->child
)
180 wxButton::DoApplyWidgetStyle(style
);
183 void wxBitmapButton::OnSetBitmap()
185 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
187 InvalidateBestSize();
190 if (!IsThisEnabled())
191 the_one
= m_bmpDisabled
;
192 else if (m_isSelected
)
193 the_one
= m_bmpSelected
;
195 the_one
= m_bmpFocus
;
197 the_one
= m_bmpNormal
;
199 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
200 if (!the_one
.Ok()) return;
202 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
203 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
205 GtkWidget
*child
= GTK_BIN(m_widget
)->child
;
211 if (the_one
.HasPixbuf())
212 pixmap
= gtk_image_new_from_pixbuf(the_one
.GetPixbuf());
214 pixmap
= gtk_image_new_from_pixmap(the_one
.GetPixmap(), mask
);
216 gtk_widget_show(pixmap
);
217 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
220 { // subsequent bitmaps
221 GtkImage
*pixmap
= GTK_IMAGE(child
);
222 if (the_one
.HasPixbuf())
223 gtk_image_set_from_pixbuf(pixmap
, the_one
.GetPixbuf());
225 gtk_image_set_from_pixmap(pixmap
, the_one
.GetPixmap(), mask
);
229 wxSize
wxBitmapButton::DoGetBestSize() const
231 return wxControl::DoGetBestSize();
234 bool wxBitmapButton::Enable( bool enable
)
236 if ( !wxWindow::Enable(enable
) )
244 void wxBitmapButton::HasFocus()
250 void wxBitmapButton::NotFocus()
256 void wxBitmapButton::StartSelect()
262 void wxBitmapButton::EndSelect()
264 m_isSelected
= false;
268 #endif // wxUSE_BMPBUTTON