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
->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
->HasVMT()) return;
61 if (g_blockEventsOnDrag
) return;
66 //-----------------------------------------------------------------------------
68 //-----------------------------------------------------------------------------
70 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
72 if (!button
->HasVMT()) return;
73 if (g_blockEventsOnDrag
) return;
78 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
82 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
84 if (!button
->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
->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();
136 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
137 if (m_bitmap
.GetMask()) mask
= m_bitmap
.GetMask()->GetBitmap();
138 GtkWidget
*pixmap
= gtk_pixmap_new( m_bitmap
.GetPixmap(), mask
);
140 gtk_widget_show( pixmap
);
141 gtk_container_add( GTK_CONTAINER(m_widget
), pixmap
);
144 if (newSize
.x
== -1) newSize
.x
= m_bitmap
.GetHeight()+10;
145 if (newSize
.y
== -1) newSize
.y
= m_bitmap
.GetWidth()+10;
146 SetSize( newSize
.x
, newSize
.y
);
148 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
149 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
151 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
152 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
153 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
154 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
155 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
156 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
157 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
158 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
160 m_parent
->AddChild( this );
162 (m_parent
->m_insertCallback
)( m_parent
, this );
166 SetBackgroundColour( parent
->GetBackgroundColour() );
173 void wxBitmapButton::SetDefault()
175 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
176 gtk_widget_grab_default( m_widget
);
178 SetSize( m_x
, m_y
, m_width
, m_height
);
181 void wxBitmapButton::SetLabel( const wxString
&label
)
183 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
185 wxControl::SetLabel( label
);
188 wxString
wxBitmapButton::GetLabel() const
190 wxCHECK_MSG( m_widget
!= NULL
, _T(""), _T("invalid button") );
192 return wxControl::GetLabel();
195 void wxBitmapButton::ApplyWidgetStyle()
199 void wxBitmapButton::SetBitmap()
201 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
206 the_one
= m_disabled
;
211 the_one
= m_selected
;
222 if ( ! the_one
.Ok() ) the_one
= m_bitmap
;
223 if ( ! the_one
.Ok() ) return;
225 GtkButton
*bin
= GTK_BUTTON( m_widget
);
226 GtkPixmap
*g_pixmap
= GTK_PIXMAP( bin
->child
);
228 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
229 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
231 gtk_pixmap_set( g_pixmap
, the_one
.GetPixmap(), mask
);
234 void wxBitmapButton::SetBitmapDisabled( const wxBitmap
& bitmap
)
236 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
238 if ( ! m_disabled
.Ok() ) return;
244 void wxBitmapButton::SetBitmapFocus( const wxBitmap
& bitmap
)
246 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
248 if ( ! m_focus
.Ok() ) return;
254 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
256 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
258 if (!m_bitmap
.Ok()) return;
264 void wxBitmapButton::SetBitmapSelected( const wxBitmap
& bitmap
)
266 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
268 if ( ! m_selected
.Ok() ) return;
274 void wxBitmapButton::Enable( const bool enable
)
276 wxWindow::Enable(enable
);
281 void wxBitmapButton::HasFocus()
287 void wxBitmapButton::NotFocus()
293 void wxBitmapButton::StartSelect()
299 void wxBitmapButton::EndSelect()
301 m_isSelected
= FALSE
;