1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/bmpbuttn.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "bmpbuttn.h"
18 #include "wx/bmpbuttn.h"
20 #include "wx/gtk/private.h"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 extern void wxapp_install_idle_handler();
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 extern bool g_blockEventsOnDrag
;
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
48 wxapp_install_idle_handler();
50 if (!button
->m_hasVMT
) return;
51 if (g_blockEventsOnDrag
) return;
53 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
54 event
.SetEventObject(button
);
55 button
->GetEventHandler()->ProcessEvent(event
);
58 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
62 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
64 if (!button
->m_hasVMT
) return;
65 if (g_blockEventsOnDrag
) return;
70 //-----------------------------------------------------------------------------
72 //-----------------------------------------------------------------------------
74 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
76 if (!button
->m_hasVMT
) return;
77 if (g_blockEventsOnDrag
) return;
82 //-----------------------------------------------------------------------------
84 //-----------------------------------------------------------------------------
86 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
88 if (!button
->m_hasVMT
) return;
89 if (g_blockEventsOnDrag
) return;
91 button
->StartSelect();
94 //-----------------------------------------------------------------------------
96 //-----------------------------------------------------------------------------
98 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
100 if (!button
->m_hasVMT
) return;
101 if (g_blockEventsOnDrag
) return;
106 //-----------------------------------------------------------------------------
108 //-----------------------------------------------------------------------------
110 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxButton
)
112 wxBitmapButton::wxBitmapButton()
116 bool wxBitmapButton::Create( wxWindow
*parent
, wxWindowID id
, const wxBitmap
&bitmap
,
117 const wxPoint
&pos
, const wxSize
&size
,
118 long style
, const wxValidator
& validator
, const wxString
&name
)
121 m_acceptsFocus
= TRUE
;
123 if (!PreCreation( parent
, pos
, size
) ||
124 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
126 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
133 m_bmpSelected
= bitmap
;
135 m_widget
= gtk_button_new();
137 #if (GTK_MINOR_VERSION > 0)
138 if (style
& wxNO_BORDER
)
139 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
142 if (m_bmpNormal
.Ok())
144 wxSize newSize
= size
;
145 int border
= (style
& wxNO_BORDER
) ? 4 : 10;
147 newSize
.x
= m_bmpNormal
.GetWidth()+border
;
149 newSize
.y
= m_bmpNormal
.GetHeight()+border
;
150 SetSize( newSize
.x
, newSize
.y
);
154 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
155 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
157 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
158 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
159 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
160 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
161 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
162 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
163 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
164 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
166 m_parent
->DoAddChild( this );
170 SetBackgroundColour( parent
->GetBackgroundColour() );
177 void wxBitmapButton::SetDefault()
179 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
180 gtk_widget_grab_default( m_widget
);
182 SetSize( m_x
, m_y
, m_width
, m_height
);
185 void wxBitmapButton::SetLabel( const wxString
&label
)
187 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
189 wxControl::SetLabel( label
);
192 wxString
wxBitmapButton::GetLabel() const
194 wxCHECK_MSG( m_widget
!= NULL
, wxT(""), wxT("invalid button") );
196 return wxControl::GetLabel();
199 void wxBitmapButton::ApplyWidgetStyle()
201 if ( !BUTTON_CHILD(m_widget
) )
204 wxButton::ApplyWidgetStyle();
207 void wxBitmapButton::OnSetBitmap()
209 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
213 the_one
= m_bmpDisabled
;
214 else if (m_isSelected
)
215 the_one
= m_bmpSelected
;
217 the_one
= m_bmpFocus
;
222 the_one
= m_bmpSelected
;
227 the_one
= m_bmpFocus
;
229 the_one
= m_bmpNormal
;
233 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
234 if (!the_one
.Ok()) return;
236 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
237 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
239 GtkWidget
*child
= BUTTON_CHILD(m_widget
);
243 GtkWidget
*pixmap
= gtk_pixmap_new(the_one
.GetPixmap(), mask
);
244 gtk_widget_show(pixmap
);
245 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
248 { // subsequent bitmaps
249 GtkPixmap
*g_pixmap
= GTK_PIXMAP(child
);
250 gtk_pixmap_set(g_pixmap
, the_one
.GetPixmap(), mask
);
254 bool wxBitmapButton::Enable( bool enable
)
256 if ( !wxWindow::Enable(enable
) )
264 void wxBitmapButton::HasFocus()
270 void wxBitmapButton::NotFocus()
276 void wxBitmapButton::StartSelect()
282 void wxBitmapButton::EndSelect()
284 m_isSelected
= FALSE
;
288 #endif // wxUSE_BMPBUTTON