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 bool g_blockEventsOnDrag
;
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
37 if (!button
->HasVMT()) return;
38 if (g_blockEventsOnDrag
) return;
40 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
41 event
.SetEventObject(button
);
42 button
->GetEventHandler()->ProcessEvent(event
);
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
49 static void gtk_bmpbutton_enter_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
51 if (!button
->HasVMT()) return;
52 if (g_blockEventsOnDrag
) return;
57 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
61 static void gtk_bmpbutton_leave_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
63 if (!button
->HasVMT()) return;
64 if (g_blockEventsOnDrag
) return;
69 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
73 static void gtk_bmpbutton_press_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
75 if (!button
->HasVMT()) return;
76 if (g_blockEventsOnDrag
) return;
78 button
->StartSelect();
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
85 static void gtk_bmpbutton_release_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
87 if (!button
->HasVMT()) return;
88 if (g_blockEventsOnDrag
) return;
93 //-----------------------------------------------------------------------------
95 //-----------------------------------------------------------------------------
97 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxControl
)
99 wxBitmapButton::wxBitmapButton()
103 bool wxBitmapButton::Create( wxWindow
*parent
, wxWindowID id
, const wxBitmap
&bitmap
,
104 const wxPoint
&pos
, const wxSize
&size
,
105 long style
, const wxValidator
& validator
, const wxString
&name
)
108 m_acceptsFocus
= TRUE
;
110 wxSize newSize
= size
;
112 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
114 SetValidator( validator
);
123 m_widget
= gtk_button_new();
127 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
128 if (m_bitmap
.GetMask()) mask
= m_bitmap
.GetMask()->GetBitmap();
129 GtkWidget
*pixmap
= gtk_pixmap_new( m_bitmap
.GetPixmap(), mask
);
131 gtk_widget_show( pixmap
);
132 gtk_container_add( GTK_CONTAINER(m_widget
), pixmap
);
135 if (newSize
.x
== -1) newSize
.x
= m_bitmap
.GetHeight()+10;
136 if (newSize
.y
== -1) newSize
.y
= m_bitmap
.GetWidth()+10;
137 SetSize( newSize
.x
, newSize
.y
);
139 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
140 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
142 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter",
143 GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this );
144 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave",
145 GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this );
146 gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed",
147 GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this );
148 gtk_signal_connect( GTK_OBJECT(m_widget
), "released",
149 GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this );
151 m_parent
->AddChild( this );
153 (m_parent
->m_insertCallback
)( m_parent
, this );
157 SetBackgroundColour( parent
->GetBackgroundColour() );
164 void wxBitmapButton::SetDefault()
167 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
168 gtk_widget_grab_default( m_widget );
172 void wxBitmapButton::SetLabel( const wxString
&label
)
174 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
176 wxControl::SetLabel( label
);
179 wxString
wxBitmapButton::GetLabel() const
181 wxCHECK_MSG( m_widget
!= NULL
, "", "invalid button" );
183 return wxControl::GetLabel();
186 void wxBitmapButton::ApplyWidgetStyle()
190 void wxBitmapButton::SetBitmap()
192 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
197 the_one
= m_disabled
;
202 the_one
= m_selected
;
213 if ( ! the_one
.Ok() ) the_one
= m_bitmap
;
214 if ( ! the_one
.Ok() ) return;
216 GtkButton
*bin
= GTK_BUTTON( m_widget
);
217 GtkPixmap
*g_pixmap
= GTK_PIXMAP( bin
->child
);
219 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
220 if (the_one
.GetMask()) mask
= the_one
.GetMask()->GetBitmap();
222 gtk_pixmap_set( g_pixmap
, the_one
.GetPixmap(), mask
);
225 void wxBitmapButton::SetBitmapDisabled( const wxBitmap
& bitmap
)
227 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
229 if ( ! m_disabled
.Ok() ) return;
235 void wxBitmapButton::SetBitmapFocus( const wxBitmap
& bitmap
)
237 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
239 if ( ! m_focus
.Ok() ) return;
245 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
247 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
249 if (!m_bitmap
.Ok()) return;
255 void wxBitmapButton::SetBitmapSelected( const wxBitmap
& bitmap
)
257 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
259 if ( ! m_selected
.Ok() ) return;
265 void wxBitmapButton::Enable( const bool enable
)
267 wxWindow::Enable(enable
);
272 void wxBitmapButton::HasFocus()
278 void wxBitmapButton::NotFocus()
284 void wxBitmapButton::StartSelect()
290 void wxBitmapButton::EndSelect()
292 m_isSelected
= FALSE
;