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"
14 #include "wx/bmpbuttn.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 extern void wxapp_install_idle_handler();
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 extern bool g_blockEventsOnDrag
;
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
44 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
47 wxapp_install_idle_handler();
49 if (!button
->m_hasVMT
) return;
50 if (g_blockEventsOnDrag
) return;
52 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
53 event
.SetEventObject(button
);
54 button
->GetEventHandler()->ProcessEvent(event
);
57 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
61 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
63 if (!button
->m_hasVMT
) return;
64 if (g_blockEventsOnDrag
) return;
69 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
73 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
75 if (!button
->m_hasVMT
) return;
76 if (g_blockEventsOnDrag
) return;
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
85 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
87 if (!button
->m_hasVMT
) return;
88 if (g_blockEventsOnDrag
) return;
90 button
->StartSelect();
93 //-----------------------------------------------------------------------------
95 //-----------------------------------------------------------------------------
97 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
99 if (!button
->m_hasVMT
) return;
100 if (g_blockEventsOnDrag
) return;
105 //-----------------------------------------------------------------------------
107 //-----------------------------------------------------------------------------
109 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxButton
)
111 wxBitmapButton::wxBitmapButton()
115 bool wxBitmapButton::Create( wxWindow
*parent
, wxWindowID id
, const wxBitmap
&bitmap
,
116 const wxPoint
&pos
, const wxSize
&size
,
117 long style
, const wxValidator
& validator
, const wxString
&name
)
120 m_acceptsFocus
= TRUE
;
125 if (!PreCreation( parent
, pos
, size
) ||
126 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
128 wxFAIL_MSG( wxT("wxBitmapButton creation failed") );
137 m_widget
= gtk_button_new();
139 #if (GTK_MINOR_VERSION > 0)
140 if (style
& wxNO_BORDER
)
141 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
146 wxSize newSize
= size
;
148 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
149 if (m_bitmap
.GetMask()) mask
= m_bitmap
.GetMask()->GetBitmap();
150 GtkWidget
*pixmap
= gtk_pixmap_new( m_bitmap
.GetPixmap(), mask
);
152 gtk_widget_show( pixmap
);
153 gtk_container_add( GTK_CONTAINER(m_widget
), pixmap
);
156 if (style
& wxNO_BORDER
) border
= 4;
157 if (newSize
.x
== -1) newSize
.x
= m_bitmap
.GetWidth()+border
;
158 if (newSize
.y
== -1) newSize
.y
= m_bitmap
.GetHeight()+border
;
159 SetSize( newSize
.x
, newSize
.y
);
162 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
163 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
165 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
166 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
167 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
168 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
169 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
170 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
171 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
172 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
174 m_parent
->DoAddChild( this );
178 SetBackgroundColour( parent
->GetBackgroundColour() );
185 void wxBitmapButton::SetDefault()
187 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
188 gtk_widget_grab_default( m_widget
);
190 SetSize( m_x
, m_y
, m_width
, m_height
);
193 void wxBitmapButton::SetLabel( const wxString
&label
)
195 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
197 wxControl::SetLabel( label
);
200 wxString
wxBitmapButton::GetLabel() const
202 wxCHECK_MSG( m_widget
!= NULL
, wxT(""), wxT("invalid button") );
204 return wxControl::GetLabel();
207 void wxBitmapButton::ApplyWidgetStyle()
211 void wxBitmapButton::SetBitmap()
213 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
218 the_one
= m_disabled
;
223 the_one
= m_selected
;
234 if (!the_one
.Ok()) the_one
= m_bitmap
;
235 if (!the_one
.Ok()) return;
237 GtkButton
*bin
= GTK_BUTTON( m_widget
);
238 GtkPixmap
*g_pixmap
= GTK_PIXMAP( bin
->child
);
240 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
241 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
243 gtk_pixmap_set( g_pixmap
, the_one
.GetPixmap(), mask
);
246 void wxBitmapButton::SetBitmapDisabled( const wxBitmap
& bitmap
)
248 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
250 if ( ! m_disabled
.Ok() ) return;
256 void wxBitmapButton::SetBitmapFocus( const wxBitmap
& bitmap
)
258 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
260 if ( ! m_focus
.Ok() ) return;
266 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
268 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
270 if (!m_bitmap
.Ok()) return;
276 void wxBitmapButton::SetBitmapSelected( const wxBitmap
& bitmap
)
278 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
280 if ( ! m_selected
.Ok() ) return;
286 bool wxBitmapButton::Enable( bool enable
)
288 if ( !wxWindow::Enable(enable
) )
296 void wxBitmapButton::HasFocus()
302 void wxBitmapButton::NotFocus()
308 void wxBitmapButton::StartSelect()
314 void wxBitmapButton::EndSelect()
316 m_isSelected
= FALSE
;
320 #endif // wxUSE_BMPBUTTON