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
,wxButton
)
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 if (!PreCreation( parent
, pos
, size
) ||
122 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
124 wxFAIL_MSG( T("wxBitmapButton creation failed") );
135 m_widget
= gtk_button_new();
137 #if (GTK_MINOR_VERSION > 0)
138 if (style
& wxNO_BORDER
)
139 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
144 wxSize newSize
= size
;
146 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
147 if (m_bitmap
.GetMask()) mask
= m_bitmap
.GetMask()->GetBitmap();
148 GtkWidget
*pixmap
= gtk_pixmap_new( m_bitmap
.GetPixmap(), mask
);
150 gtk_widget_show( pixmap
);
151 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
);
160 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
161 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
163 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
164 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
165 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
166 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
167 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
168 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
169 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
170 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
172 m_parent
->DoAddChild( this );
176 SetBackgroundColour( parent
->GetBackgroundColour() );
183 void wxBitmapButton::SetDefault()
185 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
186 gtk_widget_grab_default( m_widget
);
188 SetSize( m_x
, m_y
, m_width
, m_height
);
191 void wxBitmapButton::SetLabel( const wxString
&label
)
193 wxCHECK_RET( m_widget
!= NULL
, T("invalid button") );
195 wxControl::SetLabel( label
);
198 wxString
wxBitmapButton::GetLabel() const
200 wxCHECK_MSG( m_widget
!= NULL
, T(""), T("invalid button") );
202 return wxControl::GetLabel();
205 void wxBitmapButton::ApplyWidgetStyle()
209 void wxBitmapButton::SetBitmap()
211 wxCHECK_RET( m_widget
!= NULL
, T("invalid button") );
216 the_one
= m_disabled
;
221 the_one
= m_selected
;
232 if (!the_one
.Ok()) the_one
= m_bitmap
;
233 if (!the_one
.Ok()) return;
235 GtkButton
*bin
= GTK_BUTTON( m_widget
);
236 GtkPixmap
*g_pixmap
= GTK_PIXMAP( bin
->child
);
238 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
239 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
241 gtk_pixmap_set( g_pixmap
, the_one
.GetPixmap(), mask
);
244 void wxBitmapButton::SetBitmapDisabled( const wxBitmap
& bitmap
)
246 wxCHECK_RET( m_widget
!= NULL
, T("invalid button") );
248 if ( ! m_disabled
.Ok() ) return;
254 void wxBitmapButton::SetBitmapFocus( const wxBitmap
& bitmap
)
256 wxCHECK_RET( m_widget
!= NULL
, T("invalid button") );
258 if ( ! m_focus
.Ok() ) return;
264 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
266 wxCHECK_RET( m_widget
!= NULL
, T("invalid button") );
268 if (!m_bitmap
.Ok()) return;
274 void wxBitmapButton::SetBitmapSelected( const wxBitmap
& bitmap
)
276 wxCHECK_RET( m_widget
!= NULL
, T("invalid button") );
278 if ( ! m_selected
.Ok() ) return;
284 bool wxBitmapButton::Enable( bool enable
)
286 if ( !wxWindow::Enable(enable
) )
294 void wxBitmapButton::HasFocus()
300 void wxBitmapButton::NotFocus()
306 void wxBitmapButton::StartSelect()
312 void wxBitmapButton::EndSelect()
314 m_isSelected
= FALSE
;