1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/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/gtk1/private.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 extern void wxapp_install_idle_handler();
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 extern bool g_blockEventsOnDrag
;
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
43 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
46 wxapp_install_idle_handler();
48 if (!button
->m_hasVMT
) return;
49 if (g_blockEventsOnDrag
) return;
51 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
52 event
.SetEventObject(button
);
53 button
->GetEventHandler()->ProcessEvent(event
);
57 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
62 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
64 if (!button
->m_hasVMT
) return;
65 if (g_blockEventsOnDrag
) return;
71 //-----------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------
76 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
78 if (!button
->m_hasVMT
) return;
79 if (g_blockEventsOnDrag
) return;
85 //-----------------------------------------------------------------------------
87 //-----------------------------------------------------------------------------
90 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
92 if (!button
->m_hasVMT
) return;
93 if (g_blockEventsOnDrag
) return;
95 button
->StartSelect();
99 //-----------------------------------------------------------------------------
101 //-----------------------------------------------------------------------------
104 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
106 if (!button
->m_hasVMT
) return;
107 if (g_blockEventsOnDrag
) return;
113 //-----------------------------------------------------------------------------
115 //-----------------------------------------------------------------------------
117 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxButton
)
119 void wxBitmapButton::Init()
122 m_isSelected
= false;
125 bool wxBitmapButton::Create( wxWindow
*parent
,
127 const wxBitmap
& bitmap
,
131 const wxValidator
& validator
,
132 const wxString
&name
)
135 m_acceptsFocus
= true;
137 if (!PreCreation( parent
, pos
, size
) ||
138 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
140 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
144 m_bmpNormal
= bitmap
;
146 m_widget
= gtk_button_new();
148 if (style
& wxNO_BORDER
)
149 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
151 if (m_bmpNormal
.Ok())
156 gtk_signal_connect_after( GTK_OBJECT(m_widget
), "clicked",
157 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
159 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
160 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
161 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
162 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
163 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
164 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
165 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
166 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
168 m_parent
->DoAddChild( this );
175 void wxBitmapButton::SetLabel( const wxString
&label
)
177 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
179 wxControl::SetLabel( label
);
182 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
184 if ( !BUTTON_CHILD(m_widget
) )
187 wxButton::DoApplyWidgetStyle(style
);
190 void wxBitmapButton::OnSetBitmap()
192 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
194 InvalidateBestSize();
197 if (!IsThisEnabled())
198 the_one
= m_bmpDisabled
;
199 else if (m_isSelected
)
200 the_one
= m_bmpSelected
;
202 the_one
= m_bmpFocus
;
204 the_one
= m_bmpNormal
;
206 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
207 if (!the_one
.Ok()) return;
209 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
210 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
212 GtkWidget
*child
= BUTTON_CHILD(m_widget
);
217 pixmap
= gtk_pixmap_new(the_one
.GetPixmap(), mask
);
218 gtk_widget_show(pixmap
);
219 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
222 { // subsequent bitmaps
223 GtkPixmap
*pixmap
= GTK_PIXMAP(child
);
224 gtk_pixmap_set(pixmap
, the_one
.GetPixmap(), mask
);
228 wxSize
wxBitmapButton::DoGetBestSize() const
230 return wxControl::DoGetBestSize();
233 bool wxBitmapButton::Enable( bool enable
)
235 if ( !wxWindow::Enable(enable
) )
243 void wxBitmapButton::HasFocus()
249 void wxBitmapButton::NotFocus()
255 void wxBitmapButton::StartSelect()
261 void wxBitmapButton::EndSelect()
263 m_isSelected
= false;
267 #endif // wxUSE_BMPBUTTON