1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "bmpbuttn.h"
14 #include "wx/bmpbuttn.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 extern void wxapp_install_idle_handler();
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 extern bool g_blockEventsOnDrag
;
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
44 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
47 wxapp_install_idle_handler();
49 if (!button
->m_hasVMT
) return;
50 if (g_blockEventsOnDrag
) return;
52 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
53 event
.SetEventObject(button
);
54 button
->GetEventHandler()->ProcessEvent(event
);
57 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
61 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
63 if (!button
->m_hasVMT
) return;
64 if (g_blockEventsOnDrag
) return;
69 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
73 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
75 if (!button
->m_hasVMT
) return;
76 if (g_blockEventsOnDrag
) return;
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
85 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
87 if (!button
->m_hasVMT
) return;
88 if (g_blockEventsOnDrag
) return;
90 button
->StartSelect();
93 //-----------------------------------------------------------------------------
95 //-----------------------------------------------------------------------------
97 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
99 if (!button
->m_hasVMT
) return;
100 if (g_blockEventsOnDrag
) return;
105 //-----------------------------------------------------------------------------
107 //-----------------------------------------------------------------------------
109 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxButton
)
111 wxBitmapButton::wxBitmapButton()
115 bool wxBitmapButton::Create( wxWindow
*parent
, wxWindowID id
, const wxBitmap
&bitmap
,
116 const wxPoint
&pos
, const wxSize
&size
,
117 long style
, const wxValidator
& validator
, const wxString
&name
)
120 m_acceptsFocus
= TRUE
;
122 if (!PreCreation( parent
, pos
, size
) ||
123 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
125 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
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
);
145 wxSize newSize
= size
;
147 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
148 if (m_bitmap
.GetMask()) mask
= m_bitmap
.GetMask()->GetBitmap();
149 GtkWidget
*pixmap
= gtk_pixmap_new( m_bitmap
.GetPixmap(), mask
);
151 gtk_widget_show( pixmap
);
152 gtk_container_add( GTK_CONTAINER(m_widget
), pixmap
);
155 if (style
& wxNO_BORDER
) border
= 4;
156 if (newSize
.x
== -1) newSize
.x
= m_bitmap
.GetWidth()+border
;
157 if (newSize
.y
== -1) newSize
.y
= m_bitmap
.GetHeight()+border
;
158 SetSize( newSize
.x
, newSize
.y
);
161 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
162 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
164 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
165 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
166 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
167 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
168 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
169 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
170 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
171 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
173 m_parent
->DoAddChild( this );
177 SetBackgroundColour( parent
->GetBackgroundColour() );
184 void wxBitmapButton::SetDefault()
186 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
187 gtk_widget_grab_default( m_widget
);
189 SetSize( m_x
, m_y
, m_width
, m_height
);
192 void wxBitmapButton::SetLabel( const wxString
&label
)
194 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
196 wxControl::SetLabel( label
);
199 wxString
wxBitmapButton::GetLabel() const
201 wxCHECK_MSG( m_widget
!= NULL
, wxT(""), wxT("invalid button") );
203 return wxControl::GetLabel();
206 void wxBitmapButton::ApplyWidgetStyle()
210 void wxBitmapButton::SetBitmap()
212 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
217 the_one
= m_disabled
;
222 the_one
= m_selected
;
233 if (!the_one
.Ok()) the_one
= m_bitmap
;
234 if (!the_one
.Ok()) return;
236 GtkButton
*bin
= GTK_BUTTON( m_widget
);
237 GtkPixmap
*g_pixmap
= GTK_PIXMAP( bin
->child
);
239 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
240 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
242 gtk_pixmap_set( g_pixmap
, the_one
.GetPixmap(), mask
);
245 void wxBitmapButton::SetBitmapDisabled( const wxBitmap
& bitmap
)
247 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
249 if ( ! m_disabled
.Ok() ) return;
255 void wxBitmapButton::SetBitmapFocus( const wxBitmap
& bitmap
)
257 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
259 if ( ! m_focus
.Ok() ) return;
265 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
267 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
269 if (!m_bitmap
.Ok()) return;
275 void wxBitmapButton::SetBitmapSelected( const wxBitmap
& bitmap
)
277 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
279 if ( ! m_selected
.Ok() ) return;
285 bool wxBitmapButton::Enable( bool enable
)
287 if ( !wxWindow::Enable(enable
) )
295 void wxBitmapButton::HasFocus()
301 void wxBitmapButton::NotFocus()
307 void wxBitmapButton::StartSelect()
313 void wxBitmapButton::EndSelect()
315 m_isSelected
= FALSE
;