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"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 extern void wxapp_install_idle_handler();
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 extern bool g_blockEventsOnDrag
;
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
44 if (g_isIdle
) wxapp_install_idle_handler();
46 if (!button
->m_hasVMT
) return;
47 if (g_blockEventsOnDrag
) return;
49 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
50 event
.SetEventObject(button
);
51 button
->GetEventHandler()->ProcessEvent(event
);
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
60 if (!button
->m_hasVMT
) return;
61 if (g_blockEventsOnDrag
) return;
66 //-----------------------------------------------------------------------------
68 //-----------------------------------------------------------------------------
70 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
72 if (!button
->m_hasVMT
) return;
73 if (g_blockEventsOnDrag
) return;
78 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
82 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
84 if (!button
->m_hasVMT
) return;
85 if (g_blockEventsOnDrag
) return;
87 button
->StartSelect();
90 //-----------------------------------------------------------------------------
92 //-----------------------------------------------------------------------------
94 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
96 if (!button
->m_hasVMT
) return;
97 if (g_blockEventsOnDrag
) return;
102 //-----------------------------------------------------------------------------
104 //-----------------------------------------------------------------------------
106 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxControl
)
108 wxBitmapButton::wxBitmapButton()
112 bool wxBitmapButton::Create( wxWindow
*parent
, wxWindowID id
, const wxBitmap
&bitmap
,
113 const wxPoint
&pos
, const wxSize
&size
,
114 long style
, const wxValidator
& validator
, const wxString
&name
)
117 m_acceptsFocus
= TRUE
;
119 wxSize newSize
= size
;
121 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
123 SetValidator( validator
);
132 m_widget
= gtk_button_new();
134 #if (GTK_MINOR_VERSION > 0)
135 if (style
& wxNO_BORDER
)
136 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
141 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
142 if (m_bitmap
.GetMask()) mask
= m_bitmap
.GetMask()->GetBitmap();
143 GtkWidget
*pixmap
= gtk_pixmap_new( m_bitmap
.GetPixmap(), mask
);
145 gtk_widget_show( pixmap
);
146 gtk_container_add( GTK_CONTAINER(m_widget
), pixmap
);
150 if (style
& wxNO_BORDER
) border
= 4;
151 if (newSize
.x
== -1) newSize
.x
= m_bitmap
.GetWidth()+border
;
152 if (newSize
.y
== -1) newSize
.y
= m_bitmap
.GetHeight()+border
;
153 SetSize( newSize
.x
, newSize
.y
);
155 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
156 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
158 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
159 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
160 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
161 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
162 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
163 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
164 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
165 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
167 m_parent
->DoAddChild( this );
171 SetBackgroundColour( parent
->GetBackgroundColour() );
178 void wxBitmapButton::SetDefault()
180 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
181 gtk_widget_grab_default( m_widget
);
183 SetSize( m_x
, m_y
, m_width
, m_height
);
186 void wxBitmapButton::SetLabel( const wxString
&label
)
188 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
190 wxControl::SetLabel( label
);
193 wxString
wxBitmapButton::GetLabel() const
195 wxCHECK_MSG( m_widget
!= NULL
, _T(""), _T("invalid button") );
197 return wxControl::GetLabel();
200 void wxBitmapButton::ApplyWidgetStyle()
204 void wxBitmapButton::SetBitmap()
206 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
211 the_one
= m_disabled
;
216 the_one
= m_selected
;
227 if (!the_one
.Ok()) the_one
= m_bitmap
;
228 if (!the_one
.Ok()) return;
230 GtkButton
*bin
= GTK_BUTTON( m_widget
);
231 GtkPixmap
*g_pixmap
= GTK_PIXMAP( bin
->child
);
233 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
234 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
236 gtk_pixmap_set( g_pixmap
, the_one
.GetPixmap(), mask
);
239 void wxBitmapButton::SetBitmapDisabled( const wxBitmap
& bitmap
)
241 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
243 if ( ! m_disabled
.Ok() ) return;
249 void wxBitmapButton::SetBitmapFocus( const wxBitmap
& bitmap
)
251 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
253 if ( ! m_focus
.Ok() ) return;
259 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
261 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
263 if (!m_bitmap
.Ok()) return;
269 void wxBitmapButton::SetBitmapSelected( const wxBitmap
& bitmap
)
271 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
273 if ( ! m_selected
.Ok() ) return;
279 bool wxBitmapButton::Enable( bool enable
)
281 if ( !wxWindow::Enable(enable
) )
289 void wxBitmapButton::HasFocus()
295 void wxBitmapButton::NotFocus()
301 void wxBitmapButton::StartSelect()
307 void wxBitmapButton::EndSelect()
309 m_isSelected
= FALSE
;