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
)
105 m_acceptsFocus
= TRUE
;
107 wxSize newSize
= size
;
109 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
111 SetValidator( validator
);
120 m_widget
= gtk_button_new();
124 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
125 if (m_bitmap
.GetMask()) mask
= m_bitmap
.GetMask()->GetBitmap();
126 GtkWidget
*pixmap
= gtk_pixmap_new( m_bitmap
.GetPixmap(), mask
);
128 gtk_widget_show( pixmap
);
129 gtk_container_add( GTK_CONTAINER(m_widget
), pixmap
);
132 if (newSize
.x
== -1) newSize
.x
= m_bitmap
.GetHeight()+10;
133 if (newSize
.y
== -1) newSize
.y
= m_bitmap
.GetWidth()+10;
134 SetSize( newSize
.x
, newSize
.y
);
136 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
137 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
139 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
140 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
141 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
142 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
143 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
144 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
145 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
146 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
148 m_parent
->AddChild( this );
150 (m_parent
->m_insertCallback
)( m_parent
, this );
154 SetBackgroundColour( parent
->GetBackgroundColour() );
161 void wxBitmapButton::SetDefault()
164 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
165 gtk_widget_grab_default( m_widget );
169 void wxBitmapButton::SetLabel( const wxString
&label
)
171 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
173 wxControl::SetLabel( label
);
176 wxString
wxBitmapButton::GetLabel() const
178 wxCHECK_MSG( m_widget
!= NULL
, "", "invalid button" );
180 return wxControl::GetLabel();
183 void wxBitmapButton::ApplyWidgetStyle()
187 void wxBitmapButton::SetBitmap()
189 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
194 the_one
= m_disabled
;
199 the_one
= m_selected
;
210 if ( ! the_one
.Ok() ) the_one
= m_bitmap
;
211 if ( ! the_one
.Ok() ) return;
213 GtkButton
*bin
= GTK_BUTTON( m_widget
);
214 GtkPixmap
*g_pixmap
= GTK_PIXMAP( bin
->child
);
216 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
217 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
219 gtk_pixmap_set( g_pixmap
, the_one
.GetPixmap(), mask
);
222 void wxBitmapButton::SetBitmapDisabled( const wxBitmap
& bitmap
)
224 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
226 if ( ! m_disabled
.Ok() ) return;
232 void wxBitmapButton::SetBitmapFocus( const wxBitmap
& bitmap
)
234 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
236 if ( ! m_focus
.Ok() ) return;
242 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
244 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
246 if (!m_bitmap
.Ok()) return;
252 void wxBitmapButton::SetBitmapSelected( const wxBitmap
& bitmap
)
254 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
256 if ( ! m_selected
.Ok() ) return;
262 void wxBitmapButton::Enable( const bool enable
)
264 wxWindow::Enable(enable
);
269 void wxBitmapButton::HasFocus()
275 void wxBitmapButton::NotFocus()
281 void wxBitmapButton::StartSelect()
287 void wxBitmapButton::EndSelect()
289 m_isSelected
= FALSE
;