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();
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
->AddChild( this );
169 (m_parent
->m_insertCallback
)( m_parent
, this );
173 SetBackgroundColour( parent
->GetBackgroundColour() );
180 void wxBitmapButton::SetDefault()
182 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
183 gtk_widget_grab_default( m_widget
);
185 SetSize( m_x
, m_y
, m_width
, m_height
);
188 void wxBitmapButton::SetLabel( const wxString
&label
)
190 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
192 wxControl::SetLabel( label
);
195 wxString
wxBitmapButton::GetLabel() const
197 wxCHECK_MSG( m_widget
!= NULL
, _T(""), _T("invalid button") );
199 return wxControl::GetLabel();
202 void wxBitmapButton::ApplyWidgetStyle()
206 void wxBitmapButton::SetBitmap()
208 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
213 the_one
= m_disabled
;
218 the_one
= m_selected
;
229 if (!the_one
.Ok()) the_one
= m_bitmap
;
230 if (!the_one
.Ok()) return;
232 GtkButton
*bin
= GTK_BUTTON( m_widget
);
233 GtkPixmap
*g_pixmap
= GTK_PIXMAP( bin
->child
);
235 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
236 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
238 gtk_pixmap_set( g_pixmap
, the_one
.GetPixmap(), mask
);
241 void wxBitmapButton::SetBitmapDisabled( const wxBitmap
& bitmap
)
243 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
245 if ( ! m_disabled
.Ok() ) return;
251 void wxBitmapButton::SetBitmapFocus( const wxBitmap
& bitmap
)
253 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
255 if ( ! m_focus
.Ok() ) return;
261 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
263 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
265 if (!m_bitmap
.Ok()) return;
271 void wxBitmapButton::SetBitmapSelected( const wxBitmap
& bitmap
)
273 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
275 if ( ! m_selected
.Ok() ) return;
281 void wxBitmapButton::Enable( const bool enable
)
283 wxWindow::Enable(enable
);
288 void wxBitmapButton::HasFocus()
294 void wxBitmapButton::NotFocus()
300 void wxBitmapButton::StartSelect()
306 void wxBitmapButton::EndSelect()
308 m_isSelected
= FALSE
;