1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "bmpbuttn.h"
15 #include "wx/bmpbuttn.h"
17 //-----------------------------------------------------------------------------
19 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 extern bool g_blockEventsOnDrag
;
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
35 if (!button
->HasVMT()) return;
36 if (g_blockEventsOnDrag
) return;
38 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
39 event
.SetEventObject(button
);
40 button
->GetEventHandler()->ProcessEvent(event
);
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
47 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxControl
)
49 wxBitmapButton::wxBitmapButton(void)
53 bool wxBitmapButton::Create( wxWindow
*parent
, wxWindowID id
, const wxBitmap
&bitmap
,
54 const wxPoint
&pos
, const wxSize
&size
,
55 long style
, const wxValidator
& validator
, const wxString
&name
)
59 wxSize newSize
= size
;
61 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
63 SetValidator( validator
);
68 m_widget
= gtk_button_new();
72 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
73 if (m_bitmap
.GetMask()) mask
= m_bitmap
.GetMask()->GetBitmap();
74 GtkWidget
*pixmap
= gtk_pixmap_new( m_bitmap
.GetPixmap(), mask
);
76 gtk_widget_show( pixmap
);
77 gtk_container_add( GTK_CONTAINER(m_widget
), pixmap
);
80 if (newSize
.x
== -1) newSize
.x
= m_bitmap
.GetHeight()+10;
81 if (newSize
.y
== -1) newSize
.y
= m_bitmap
.GetWidth()+10;
82 SetSize( newSize
.x
, newSize
.y
);
84 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
85 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
94 void wxBitmapButton::SetDefault(void)
97 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
98 gtk_widget_grab_default( m_widget );
102 void wxBitmapButton::SetLabel( const wxString
&label
)
104 wxControl::SetLabel( label
);
107 wxString
wxBitmapButton::GetLabel(void) const
109 return wxControl::GetLabel();
112 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
115 if (!m_bitmap
.Ok()) return;
117 GtkButton
*bin
= GTK_BUTTON( m_widget
);
118 GtkPixmap
*g_pixmap
= GTK_PIXMAP( bin
->child
);
120 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
121 if (m_bitmap
.GetMask()) mask
= m_bitmap
.GetMask()->GetBitmap();
123 gtk_pixmap_set( g_pixmap
, m_bitmap
.GetPixmap(), mask
);