1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/bmpbuttn.cpp
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
14 #include "wx/bmpbuttn.h"
16 #include "wx/gtk1/private.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 extern void wxapp_install_idle_handler();
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 extern bool g_blockEventsOnDrag
;
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
42 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
45 wxapp_install_idle_handler();
47 if (!button
->m_hasVMT
) return;
48 if (g_blockEventsOnDrag
) return;
50 wxCommandEvent
event(wxEVT_BUTTON
, button
->GetId());
51 event
.SetEventObject(button
);
52 button
->HandleWindowEvent(event
);
56 //-----------------------------------------------------------------------------
58 //-----------------------------------------------------------------------------
61 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
63 if (!button
->m_hasVMT
) return;
64 if (g_blockEventsOnDrag
) return;
66 button
->GTKSetHasFocus();
70 //-----------------------------------------------------------------------------
72 //-----------------------------------------------------------------------------
75 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
77 if (!button
->m_hasVMT
) return;
78 if (g_blockEventsOnDrag
) return;
80 button
->GTKSetNotFocus();
84 //-----------------------------------------------------------------------------
86 //-----------------------------------------------------------------------------
89 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
91 if (!button
->m_hasVMT
) return;
92 if (g_blockEventsOnDrag
) return;
94 button
->StartSelect();
98 //-----------------------------------------------------------------------------
100 //-----------------------------------------------------------------------------
103 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
105 if (!button
->m_hasVMT
) return;
106 if (g_blockEventsOnDrag
) return;
112 //-----------------------------------------------------------------------------
114 //-----------------------------------------------------------------------------
116 void wxBitmapButton::Init()
119 m_isSelected
= false;
122 bool wxBitmapButton::Create( wxWindow
*parent
,
124 const wxBitmap
& bitmap
,
128 const wxValidator
& validator
,
129 const wxString
&name
)
132 m_acceptsFocus
= true;
134 if (!PreCreation( parent
, pos
, size
) ||
135 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
137 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
141 m_bitmaps
[State_Normal
] = bitmap
;
143 m_widget
= gtk_button_new();
145 if (style
& wxNO_BORDER
)
146 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
153 gtk_signal_connect_after( GTK_OBJECT(m_widget
), "clicked",
154 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
156 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
157 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
158 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
159 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
160 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
161 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
162 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
163 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
165 m_parent
->DoAddChild( this );
172 void wxBitmapButton::SetLabel( const wxString
&label
)
174 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
176 wxControl::SetLabel( label
);
179 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
181 if ( !BUTTON_CHILD(m_widget
) )
184 wxButton::DoApplyWidgetStyle(style
);
187 void wxBitmapButton::OnSetBitmap()
189 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
191 InvalidateBestSize();
194 if (!IsThisEnabled())
195 the_one
= GetBitmapDisabled();
196 else if (m_isSelected
)
197 the_one
= GetBitmapPressed();
199 the_one
= GetBitmapFocus();
203 the_one
= GetBitmapLabel();
208 GdkBitmap
*mask
= NULL
;
209 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
211 GtkWidget
*child
= BUTTON_CHILD(m_widget
);
216 pixmap
= gtk_pixmap_new(the_one
.GetPixmap(), mask
);
217 gtk_widget_show(pixmap
);
218 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
221 { // subsequent bitmaps
222 GtkPixmap
*pixmap
= GTK_PIXMAP(child
);
223 gtk_pixmap_set(pixmap
, the_one
.GetPixmap(), mask
);
227 wxSize
wxBitmapButton::DoGetBestSize() const
229 return wxControl::DoGetBestSize();
232 bool wxBitmapButton::Enable( bool enable
)
234 if ( !wxWindow::Enable(enable
) )
242 void wxBitmapButton::GTKSetHasFocus()
248 void wxBitmapButton::GTKSetNotFocus()
254 void wxBitmapButton::StartSelect()
260 void wxBitmapButton::EndSelect()
262 m_isSelected
= false;
266 #endif // wxUSE_BMPBUTTON