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"
16 //-----------------------------------------------------------------------------
18 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 extern bool g_blockEventsOnDrag
;
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
34 if (!button
->HasVMT()) return;
35 if (g_blockEventsOnDrag
) return;
37 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
38 event
.SetEventObject(button
);
39 button
->GetEventHandler()->ProcessEvent(event
);
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
48 if (!button
->HasVMT()) return;
49 if (g_blockEventsOnDrag
) return;
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
60 if (!button
->HasVMT()) return;
61 if (g_blockEventsOnDrag
) return;
66 //-----------------------------------------------------------------------------
68 //-----------------------------------------------------------------------------
70 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
72 if (!button
->HasVMT()) return;
73 if (g_blockEventsOnDrag
) return;
75 button
->StartSelect();
78 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
82 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
84 if (!button
->HasVMT()) return;
85 if (g_blockEventsOnDrag
) return;
90 //-----------------------------------------------------------------------------
92 //-----------------------------------------------------------------------------
94 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxControl
)
96 wxBitmapButton::wxBitmapButton()
100 bool wxBitmapButton::Create( wxWindow
*parent
, wxWindowID id
, const wxBitmap
&bitmap
,
101 const wxPoint
&pos
, const wxSize
&size
,
102 long style
, const wxValidator
& validator
, const wxString
&name
)
106 wxSize newSize
= size
;
108 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
110 SetValidator( validator
);
119 m_widget
= gtk_button_new();
123 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
124 if (m_bitmap
.GetMask()) mask
= m_bitmap
.GetMask()->GetBitmap();
125 GtkWidget
*pixmap
= gtk_pixmap_new( m_bitmap
.GetPixmap(), mask
);
127 gtk_widget_show( pixmap
);
128 gtk_container_add( GTK_CONTAINER(m_widget
), pixmap
);
131 if (newSize
.x
== -1) newSize
.x
= m_bitmap
.GetHeight()+10;
132 if (newSize
.y
== -1) newSize
.y
= m_bitmap
.GetWidth()+10;
133 SetSize( newSize
.x
, newSize
.y
);
135 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
136 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
138 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
139 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
140 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
141 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
142 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
143 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
144 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
145 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
147 m_parent
->AddChild( this );
149 (m_parent
->m_insertCallback
)( m_parent
, this );
153 SetBackgroundColour( parent
->GetBackgroundColour() );
160 void wxBitmapButton::SetDefault()
163 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
164 gtk_widget_grab_default( m_widget );
168 void wxBitmapButton::SetLabel( const wxString
&label
)
170 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
172 wxControl::SetLabel( label
);
175 wxString
wxBitmapButton::GetLabel() const
177 wxCHECK_MSG( m_widget
!= NULL
, "", "invalid button" );
179 return wxControl::GetLabel();
182 void wxBitmapButton::ApplyWidgetStyle()
186 void wxBitmapButton::SetBitmap()
188 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
193 the_one
= m_disabled
;
198 the_one
= m_selected
;
209 if ( ! the_one
.Ok() ) the_one
= m_bitmap
;
210 if ( ! the_one
.Ok() ) return;
212 GtkButton
*bin
= GTK_BUTTON( m_widget
);
213 GtkPixmap
*g_pixmap
= GTK_PIXMAP( bin
->child
);
215 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
216 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
218 gtk_pixmap_set( g_pixmap
, the_one
.GetPixmap(), mask
);
221 void wxBitmapButton::SetBitmapDisabled( const wxBitmap
& bitmap
)
223 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
225 if ( ! m_disabled
.Ok() ) return;
231 void wxBitmapButton::SetBitmapFocus( const wxBitmap
& bitmap
)
233 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
235 if ( ! m_focus
.Ok() ) return;
241 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
243 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
245 if (!m_bitmap
.Ok()) return;
251 void wxBitmapButton::SetBitmapSelected( const wxBitmap
& bitmap
)
253 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
255 if ( ! m_selected
.Ok() ) return;
261 void wxBitmapButton::Enable( const bool enable
)
263 wxWindow::Enable(enable
);
268 void wxBitmapButton::HasFocus()
274 void wxBitmapButton::NotFocus()
280 void wxBitmapButton::StartSelect()
286 void wxBitmapButton::EndSelect()
288 m_isSelected
= FALSE
;