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
);
125 SetValidator( validator
);
134 m_widget
= gtk_button_new();
136 #if (GTK_MINOR_VERSION > 0)
137 if (style
& wxNO_BORDER
)
138 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
143 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
144 if (m_bitmap
.GetMask()) mask
= m_bitmap
.GetMask()->GetBitmap();
145 GtkWidget
*pixmap
= gtk_pixmap_new( m_bitmap
.GetPixmap(), mask
);
147 gtk_widget_show( pixmap
);
148 gtk_container_add( GTK_CONTAINER(m_widget
), pixmap
);
152 if (style
& wxNO_BORDER
) border
= 4;
153 if (newSize
.x
== -1) newSize
.x
= m_bitmap
.GetWidth()+border
;
154 if (newSize
.y
== -1) newSize
.y
= m_bitmap
.GetHeight()+border
;
155 SetSize( newSize
.x
, newSize
.y
);
157 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
158 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
160 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
161 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
162 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
163 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
164 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
165 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
166 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
167 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
169 m_parent
->DoAddChild( this );
173 SetBackgroundColour( parent
->GetBackgroundColour() );
180 void wxBitmapButton::SetDefault()
182 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
183 gtk_widget_grab_default( m_widget
);
185 SetSize( m_x
, m_y
, m_width
, m_height
);
188 void wxBitmapButton::SetLabel( const wxString
&label
)
190 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
192 wxControl::SetLabel( label
);
195 wxString
wxBitmapButton::GetLabel() const
197 wxCHECK_MSG( m_widget
!= NULL
, _T(""), _T("invalid button") );
199 return wxControl::GetLabel();
202 void wxBitmapButton::ApplyWidgetStyle()
206 void wxBitmapButton::SetBitmap()
208 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
213 the_one
= m_disabled
;
218 the_one
= m_selected
;
229 if (!the_one
.Ok()) the_one
= m_bitmap
;
230 if (!the_one
.Ok()) return;
232 GtkButton
*bin
= GTK_BUTTON( m_widget
);
233 GtkPixmap
*g_pixmap
= GTK_PIXMAP( bin
->child
);
235 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
236 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
238 gtk_pixmap_set( g_pixmap
, the_one
.GetPixmap(), mask
);
241 void wxBitmapButton::SetBitmapDisabled( const wxBitmap
& bitmap
)
243 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
245 if ( ! m_disabled
.Ok() ) return;
251 void wxBitmapButton::SetBitmapFocus( const wxBitmap
& bitmap
)
253 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
255 if ( ! m_focus
.Ok() ) return;
261 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
263 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
265 if (!m_bitmap
.Ok()) return;
271 void wxBitmapButton::SetBitmapSelected( const wxBitmap
& bitmap
)
273 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
275 if ( ! m_selected
.Ok() ) return;
281 bool wxBitmapButton::Enable( bool enable
)
283 if ( !wxWindow::Enable(enable
) )
291 void wxBitmapButton::HasFocus()
297 void wxBitmapButton::NotFocus()
303 void wxBitmapButton::StartSelect()
309 void wxBitmapButton::EndSelect()
311 m_isSelected
= FALSE
;