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
)
128 m_acceptsFocus
= true;
130 if (!PreCreation( parent
, pos
, size
) ||
131 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
133 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
137 m_bmpNormal
= bitmap
;
139 m_widget
= gtk_button_new();
141 if (style
& wxNO_BORDER
)
142 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
144 if (m_bmpNormal
.Ok())
149 g_signal_connect_after (m_widget
, "clicked",
150 G_CALLBACK (gtk_bmpbutton_clicked_callback
),
153 g_signal_connect (m_widget
, "enter",
154 G_CALLBACK (gtk_bmpbutton_enter_callback
), this);
155 g_signal_connect (m_widget
, "leave",
156 G_CALLBACK (gtk_bmpbutton_leave_callback
), this);
157 g_signal_connect (m_widget
, "pressed",
158 G_CALLBACK (gtk_bmpbutton_press_callback
), this);
159 g_signal_connect (m_widget
, "released",
160 G_CALLBACK (gtk_bmpbutton_release_callback
), this);
162 m_parent
->DoAddChild( this );
169 void wxBitmapButton::SetDefault()
171 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
172 gtk_widget_grab_default( m_widget
);
174 SetSize( m_x
, m_y
, m_width
, m_height
);
177 void wxBitmapButton::SetLabel( const wxString
&label
)
179 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
181 wxControl::SetLabel( label
);
184 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
186 if (!GTK_BIN(m_widget
)->child
)
189 wxButton::DoApplyWidgetStyle(style
);
192 void wxBitmapButton::OnSetBitmap()
194 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
196 InvalidateBestSize();
200 the_one
= m_bmpDisabled
;
201 else if (m_isSelected
)
202 the_one
= m_bmpSelected
;
204 the_one
= m_bmpFocus
;
206 the_one
= m_bmpNormal
;
208 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
209 if (!the_one
.Ok()) return;
211 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
212 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
214 GtkWidget
*child
= GTK_BIN(m_widget
)->child
;
220 if (the_one
.HasPixbuf())
221 pixmap
= gtk_image_new_from_pixbuf(the_one
.GetPixbuf());
223 pixmap
= gtk_image_new_from_pixmap(the_one
.GetPixmap(), mask
);
225 gtk_widget_show(pixmap
);
226 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
229 { // subsequent bitmaps
230 GtkImage
*pixmap
= GTK_IMAGE(child
);
231 if (the_one
.HasPixbuf())
232 gtk_image_set_from_pixbuf(pixmap
, the_one
.GetPixbuf());
234 gtk_image_set_from_pixmap(pixmap
, the_one
.GetPixmap(), mask
);
238 wxSize
wxBitmapButton::DoGetBestSize() const
240 return wxControl::DoGetBestSize();
243 bool wxBitmapButton::Enable( bool enable
)
245 if ( !wxWindow::Enable(enable
) )
253 void wxBitmapButton::HasFocus()
259 void wxBitmapButton::NotFocus()
265 void wxBitmapButton::StartSelect()
271 void wxBitmapButton::EndSelect()
273 m_isSelected
= false;
277 #endif // wxUSE_BMPBUTTON