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::SetDefault()
177 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
178 gtk_widget_grab_default( m_widget
);
180 SetSize( m_x
, m_y
, m_width
, m_height
);
183 void wxBitmapButton::SetLabel( const wxString
&label
)
185 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
187 wxControl::SetLabel( label
);
190 void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
192 if ( !BUTTON_CHILD(m_widget
) )
195 wxButton::DoApplyWidgetStyle(style
);
198 void wxBitmapButton::OnSetBitmap()
200 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
202 InvalidateBestSize();
206 the_one
= m_bmpDisabled
;
207 else if (m_isSelected
)
208 the_one
= m_bmpSelected
;
210 the_one
= m_bmpFocus
;
212 the_one
= m_bmpNormal
;
214 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
215 if (!the_one
.Ok()) return;
217 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
218 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
220 GtkWidget
*child
= BUTTON_CHILD(m_widget
);
225 pixmap
= gtk_pixmap_new(the_one
.GetPixmap(), mask
);
226 gtk_widget_show(pixmap
);
227 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
230 { // subsequent bitmaps
231 GtkPixmap
*pixmap
= GTK_PIXMAP(child
);
232 gtk_pixmap_set(pixmap
, the_one
.GetPixmap(), mask
);
236 wxSize
wxBitmapButton::DoGetBestSize() const
238 return wxControl::DoGetBestSize();
241 bool wxBitmapButton::Enable( bool enable
)
243 if ( !wxWindow::Enable(enable
) )
251 void wxBitmapButton::HasFocus()
257 void wxBitmapButton::NotFocus()
263 void wxBitmapButton::StartSelect()
269 void wxBitmapButton::EndSelect()
271 m_isSelected
= false;
275 #endif // wxUSE_BMPBUTTON