1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/bmpbuttn.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "bmpbuttn.h"
18 #include "wx/bmpbuttn.h"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 extern void wxapp_install_idle_handler();
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 extern bool g_blockEventsOnDrag
;
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
49 wxapp_install_idle_handler();
51 if (!button
->m_hasVMT
) return;
52 if (g_blockEventsOnDrag
) return;
54 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
55 event
.SetEventObject(button
);
56 button
->GetEventHandler()->ProcessEvent(event
);
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
63 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
65 if (!button
->m_hasVMT
) return;
66 if (g_blockEventsOnDrag
) return;
71 //-----------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------
75 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
77 if (!button
->m_hasVMT
) return;
78 if (g_blockEventsOnDrag
) return;
83 //-----------------------------------------------------------------------------
85 //-----------------------------------------------------------------------------
87 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
89 if (!button
->m_hasVMT
) return;
90 if (g_blockEventsOnDrag
) return;
92 button
->StartSelect();
95 //-----------------------------------------------------------------------------
97 //-----------------------------------------------------------------------------
99 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
101 if (!button
->m_hasVMT
) return;
102 if (g_blockEventsOnDrag
) return;
107 //-----------------------------------------------------------------------------
109 //-----------------------------------------------------------------------------
111 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxButton
)
113 wxBitmapButton::wxBitmapButton()
117 bool wxBitmapButton::Create( wxWindow
*parent
, wxWindowID id
, const wxBitmap
&bitmap
,
118 const wxPoint
&pos
, const wxSize
&size
,
119 long style
, const wxValidator
& validator
, const wxString
&name
)
122 m_acceptsFocus
= TRUE
;
124 if (!PreCreation( parent
, pos
, size
) ||
125 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
127 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
134 m_bmpSelected
= bitmap
;
136 m_widget
= gtk_button_new();
138 #if (GTK_MINOR_VERSION > 0)
139 if (style
& wxNO_BORDER
)
140 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
143 if (m_bmpNormal
.Ok())
145 wxSize newSize
= size
;
146 int border
= (style
& wxNO_BORDER
) ? 4 : 10;
147 if (newSize
.x
== -1) newSize
.x
= m_bitmap
.GetWidth()+border
;
148 if (newSize
.y
== -1) newSize
.y
= m_bitmap
.GetHeight()+border
;
149 SetSize( newSize
.x
, newSize
.y
);
153 gtk_signal_connect( 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 );
169 SetBackgroundColour( parent
->GetBackgroundColour() );
176 void wxBitmapButton::SetDefault()
178 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
179 gtk_widget_grab_default( m_widget
);
181 SetSize( m_x
, m_y
, m_width
, m_height
);
184 void wxBitmapButton::SetLabel( const wxString
&label
)
186 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
188 wxControl::SetLabel( label
);
191 wxString
wxBitmapButton::GetLabel() const
193 wxCHECK_MSG( m_widget
!= NULL
, wxT(""), wxT("invalid button") );
195 return wxControl::GetLabel();
198 void wxBitmapButton::ApplyWidgetStyle()
200 if (GTK_BUTTON(m_widget
)->child
== NULL
) return;
202 wxButton::ApplyWidgetStyle();
205 void wxBitmapButton::SetBitmap()
207 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
211 the_one
= m_disabled
;
212 else if (m_isSelected
)
213 the_one
= m_selected
;
220 the_one
= m_bmpSelected
;
225 the_one
= m_bmpFocus
;
227 the_one
= m_bmpNormal
;
231 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
232 if (!the_one
.Ok()) return;
234 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
235 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
237 GtkButton
*bin
= GTK_BUTTON(m_widget
);
238 if (bin
->child
== NULL
)
240 GtkWidget
*pixmap
= gtk_pixmap_new(the_one
.GetPixmap(), mask
);
241 gtk_widget_show(pixmap
);
242 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
245 { // subsequent bitmaps
246 GtkPixmap
*g_pixmap
= GTK_PIXMAP(bin
->child
);
247 gtk_pixmap_set(g_pixmap
, the_one
.GetPixmap(), mask
);
251 void wxBitmapButton::SetBitmapDisabled( const wxBitmap
& bitmap
)
253 if (!bitmap
.Ok()) return;
259 void wxBitmapButton::SetBitmapFocus( const wxBitmap
& bitmap
)
261 if (!bitmap
.Ok()) return;
267 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
269 if (!bitmap
.Ok()) return;
275 void wxBitmapButton::SetBitmapSelected( const wxBitmap
& bitmap
)
277 if (!bitmap
.Ok()) return;
283 bool wxBitmapButton::Enable( bool enable
)
285 if ( !wxWindow::Enable(enable
) )
293 void wxBitmapButton::HasFocus()
299 void wxBitmapButton::NotFocus()
305 void wxBitmapButton::StartSelect()
311 void wxBitmapButton::EndSelect()
313 m_isSelected
= FALSE
;
317 #endif // wxUSE_BMPBUTTON