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 void wxBitmapButton::Init()
115 m_isSelected
= FALSE
;
118 bool wxBitmapButton::Create( wxWindow
*parent
,
120 const wxBitmap
& bitmap
,
124 const wxValidator
& validator
,
125 const wxString
&name
)
128 m_acceptsFocus
= TRUE
;
130 if (!PreCreation( parent
, pos
, size
) ||
131 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
133 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
140 m_bmpSelected
= bitmap
;
142 m_widget
= gtk_button_new();
144 #if (GTK_MINOR_VERSION > 0)
145 if (style
& wxNO_BORDER
)
146 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
149 if (m_bmpNormal
.Ok())
151 wxSize newSize
= size
;
152 int border
= (style
& wxNO_BORDER
) ? 4 : 10;
154 newSize
.x
= m_bmpNormal
.GetWidth()+border
;
156 newSize
.y
= m_bmpNormal
.GetHeight()+border
;
157 SetSize( newSize
.x
, newSize
.y
);
161 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
162 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
164 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
165 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
166 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
167 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
168 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
169 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
170 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
171 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
173 m_parent
->DoAddChild( this );
177 SetBackgroundColour( parent
->GetBackgroundColour() );
184 void wxBitmapButton::SetDefault()
186 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
187 gtk_widget_grab_default( m_widget
);
189 SetSize( m_x
, m_y
, m_width
, m_height
);
192 void wxBitmapButton::SetLabel( const wxString
&label
)
194 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
196 wxControl::SetLabel( label
);
199 wxString
wxBitmapButton::GetLabel() const
201 wxCHECK_MSG( m_widget
!= NULL
, wxT(""), wxT("invalid button") );
203 return wxControl::GetLabel();
206 void wxBitmapButton::ApplyWidgetStyle()
208 if ( !BUTTON_CHILD(m_widget
) )
211 wxButton::ApplyWidgetStyle();
214 void wxBitmapButton::OnSetBitmap()
216 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid bitmap button") );
220 the_one
= m_bmpDisabled
;
221 else if (m_isSelected
)
222 the_one
= m_bmpSelected
;
224 the_one
= m_bmpFocus
;
229 the_one
= m_bmpSelected
;
234 the_one
= m_bmpFocus
;
236 the_one
= m_bmpNormal
;
240 if (!the_one
.Ok()) the_one
= m_bmpNormal
;
241 if (!the_one
.Ok()) return;
243 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
244 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
246 GtkWidget
*child
= BUTTON_CHILD(m_widget
);
250 GtkWidget
*pixmap
= gtk_pixmap_new(the_one
.GetPixmap(), mask
);
251 gtk_widget_show(pixmap
);
252 gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
);
255 { // subsequent bitmaps
256 GtkPixmap
*g_pixmap
= GTK_PIXMAP(child
);
257 gtk_pixmap_set(g_pixmap
, the_one
.GetPixmap(), mask
);
261 bool wxBitmapButton::Enable( bool enable
)
263 if ( !wxWindow::Enable(enable
) )
271 void wxBitmapButton::HasFocus()
277 void wxBitmapButton::NotFocus()
283 void wxBitmapButton::StartSelect()
289 void wxBitmapButton::EndSelect()
291 m_isSelected
= FALSE
;
295 #endif // wxUSE_BMPBUTTON