1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/bmpbuttn.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "bmpbuttn.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
21 #include "wx/bmpbuttn.h"
23 #include "wx/gtk/private.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 extern void wxapp_install_idle_handler();
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 extern bool g_blockEventsOnDrag
;
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
48 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
51 wxapp_install_idle_handler();
53 if (!button
->m_hasVMT
) return;
54 if (g_blockEventsOnDrag
) return;
56 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
57 event
.SetEventObject(button
);
58 button
->GetEventHandler()->ProcessEvent(event
);
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
65 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
67 if (!button
->m_hasVMT
) return;
68 if (g_blockEventsOnDrag
) return;
73 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
77 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
79 if (!button
->m_hasVMT
) return;
80 if (g_blockEventsOnDrag
) return;
85 //-----------------------------------------------------------------------------
87 //-----------------------------------------------------------------------------
89 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
91 if (!button
->m_hasVMT
) return;
92 if (g_blockEventsOnDrag
) return;
94 button
->StartSelect();
97 //-----------------------------------------------------------------------------
99 //-----------------------------------------------------------------------------
101 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
103 if (!button
->m_hasVMT
) return;
104 if (g_blockEventsOnDrag
) return;
109 //-----------------------------------------------------------------------------
111 //-----------------------------------------------------------------------------
113 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxButton
)
115 void wxBitmapButton::Init()
118 m_isSelected
= FALSE
;
121 bool wxBitmapButton::Create( wxWindow
*parent
,
123 const wxBitmap
& bitmap
,
127 const wxValidator
& validator
,
128 const wxString
&name
)
131 m_acceptsFocus
= TRUE
;
133 if (!PreCreation( parent
, pos
, size
) ||
134 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
136 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
143 m_bmpSelected
= bitmap
;
145 m_widget
= gtk_button_new();
147 #if (GTK_MINOR_VERSION > 0)
148 if (style
& wxNO_BORDER
)
149 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
152 if (m_bmpNormal
.Ok())
154 wxSize newSize
= size
;
155 int border
= (style
& wxNO_BORDER
) ? 4 : 10;
157 newSize
.x
= m_bmpNormal
.GetWidth()+border
;
159 newSize
.y
= m_bmpNormal
.GetHeight()+border
;
160 SetSize( newSize
.x
, newSize
.y
);
164 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
165 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
167 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
168 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
169 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
170 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
171 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
172 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
173 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
174 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
176 m_parent
->DoAddChild( this );
180 SetBackgroundColour( parent
->GetBackgroundColour() );
187 void wxBitmapButton::SetDefault()
189 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
190 gtk_widget_grab_default( m_widget
);
192 SetSize( m_x
, m_y
, m_width
, m_height
);
195 void wxBitmapButton::SetLabel( const wxString
&label
)
197 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
199 wxControl::SetLabel( label
);
202 wxString
wxBitmapButton::GetLabel() const
204 wxCHECK_MSG( m_widget
!= NULL
, wxT(""), wxT("invalid button") );
206 return wxControl::GetLabel();
209 void wxBitmapButton::ApplyWidgetStyle()
211 if ( !BUTTON_CHILD(m_widget
) )
214 wxButton::ApplyWidgetStyle();
217 void wxBitmapButton::OnSetBitmap()
219 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
223 the_one
= m_bmpDisabled
;
224 else if (m_isSelected
)
225 the_one
= m_bmpSelected
;
227 the_one
= m_bmpFocus
;
232 the_one
= m_bmpSelected
;
237 the_one
= m_bmpFocus
;
239 the_one
= m_bmpNormal
;
243 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
244 if (!the_one
.Ok()) return;
246 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
247 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
249 GtkWidget
*child
= BUTTON_CHILD(m_widget
);
253 GtkWidget
*pixmap
= gtk_pixmap_new(the_one
.GetPixmap(), mask
);
254 gtk_widget_show(pixmap
);
255 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
258 { // subsequent bitmaps
259 GtkPixmap
*g_pixmap
= GTK_PIXMAP(child
);
260 gtk_pixmap_set(g_pixmap
, the_one
.GetPixmap(), mask
);
264 bool wxBitmapButton::Enable( bool enable
)
266 if ( !wxWindow::Enable(enable
) )
274 void wxBitmapButton::HasFocus()
280 void wxBitmapButton::NotFocus()
286 void wxBitmapButton::StartSelect()
292 void wxBitmapButton::EndSelect()
294 m_isSelected
= FALSE
;
298 #endif // wxUSE_BMPBUTTON