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
)
46 if (g_isIdle
) 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
);
56 //-----------------------------------------------------------------------------
58 //-----------------------------------------------------------------------------
60 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
62 if (!button
->m_hasVMT
) return;
63 if (g_blockEventsOnDrag
) return;
68 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
72 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
74 if (!button
->m_hasVMT
) return;
75 if (g_blockEventsOnDrag
) return;
80 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
84 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
86 if (!button
->m_hasVMT
) return;
87 if (g_blockEventsOnDrag
) return;
89 button
->StartSelect();
92 //-----------------------------------------------------------------------------
94 //-----------------------------------------------------------------------------
96 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
98 if (!button
->m_hasVMT
) return;
99 if (g_blockEventsOnDrag
) return;
104 //-----------------------------------------------------------------------------
106 //-----------------------------------------------------------------------------
108 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxControl
)
110 wxBitmapButton::wxBitmapButton()
114 bool wxBitmapButton::Create( wxWindow
*parent
, wxWindowID id
, const wxBitmap
&bitmap
,
115 const wxPoint
&pos
, const wxSize
&size
,
116 long style
, const wxValidator
& validator
, const wxString
&name
)
119 m_acceptsFocus
= TRUE
;
121 wxSize newSize
= size
;
123 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
126 SetValidator( validator
);
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 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
146 if (m_bitmap
.GetMask()) mask
= m_bitmap
.GetMask()->GetBitmap();
147 GtkWidget
*pixmap
= gtk_pixmap_new( m_bitmap
.GetPixmap(), mask
);
149 gtk_widget_show( pixmap
);
150 gtk_container_add( GTK_CONTAINER(m_widget
), pixmap
);
154 if (style
& wxNO_BORDER
) border
= 4;
155 if (newSize
.x
== -1) newSize
.x
= m_bitmap
.GetWidth()+border
;
156 if (newSize
.y
== -1) newSize
.y
= m_bitmap
.GetHeight()+border
;
157 SetSize( newSize
.x
, newSize
.y
);
159 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
160 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
162 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
163 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
164 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
165 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
166 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
167 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
168 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
169 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
171 m_parent
->DoAddChild( this );
175 SetBackgroundColour( parent
->GetBackgroundColour() );
182 void wxBitmapButton::SetDefault()
184 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
185 gtk_widget_grab_default( m_widget
);
187 SetSize( m_x
, m_y
, m_width
, m_height
);
190 void wxBitmapButton::SetLabel( const wxString
&label
)
192 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
194 wxControl::SetLabel( label
);
197 wxString
wxBitmapButton::GetLabel() const
199 wxCHECK_MSG( m_widget
!= NULL
, _T(""), _T("invalid button") );
201 return wxControl::GetLabel();
204 void wxBitmapButton::ApplyWidgetStyle()
208 void wxBitmapButton::SetBitmap()
210 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
215 the_one
= m_disabled
;
220 the_one
= m_selected
;
231 if (!the_one
.Ok()) the_one
= m_bitmap
;
232 if (!the_one
.Ok()) return;
234 GtkButton
*bin
= GTK_BUTTON( m_widget
);
235 GtkPixmap
*g_pixmap
= GTK_PIXMAP( bin
->child
);
237 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
238 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
240 gtk_pixmap_set( g_pixmap
, the_one
.GetPixmap(), mask
);
243 void wxBitmapButton::SetBitmapDisabled( const wxBitmap
& bitmap
)
245 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
247 if ( ! m_disabled
.Ok() ) return;
253 void wxBitmapButton::SetBitmapFocus( const wxBitmap
& bitmap
)
255 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
257 if ( ! m_focus
.Ok() ) return;
263 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
265 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
267 if (!m_bitmap
.Ok()) return;
273 void wxBitmapButton::SetBitmapSelected( const wxBitmap
& bitmap
)
275 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
277 if ( ! m_selected
.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
;