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"
16 //-----------------------------------------------------------------------------
18 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 extern bool g_blockEventsOnDrag
;
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 static void gtk_bmpbutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxBitmapButton
*button
)
34 if (!button
->HasVMT()) return;
35 if (g_blockEventsOnDrag
) return;
37 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
38 event
.SetEventObject(button
);
39 button
->GetEventHandler()->ProcessEvent(event
);
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxControl
)
48 wxBitmapButton::wxBitmapButton(void)
52 bool wxBitmapButton::Create( wxWindow
*parent
, wxWindowID id
, const wxBitmap
&bitmap
,
53 const wxPoint
&pos
, const wxSize
&size
,
54 long style
, const wxValidator
& validator
, const wxString
&name
)
58 wxSize newSize
= size
;
60 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
62 SetValidator( validator
);
67 m_widget
= gtk_button_new();
71 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
72 if (m_bitmap
.GetMask()) mask
= m_bitmap
.GetMask()->GetBitmap();
73 GtkWidget
*pixmap
= gtk_pixmap_new( m_bitmap
.GetPixmap(), mask
);
75 gtk_widget_show( pixmap
);
76 gtk_container_add( GTK_CONTAINER(m_widget
), pixmap
);
79 if (newSize
.x
== -1) newSize
.x
= m_bitmap
.GetHeight()+10;
80 if (newSize
.y
== -1) newSize
.y
= m_bitmap
.GetWidth()+10;
81 SetSize( newSize
.x
, newSize
.y
);
83 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
84 GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this );
86 m_parent
->AddChild( this );
88 (m_parent
->m_insertCallback
)( m_parent
, this );
92 SetBackgroundColour( parent
->GetBackgroundColour() );
99 void wxBitmapButton::SetDefault(void)
102 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
103 gtk_widget_grab_default( m_widget );
107 void wxBitmapButton::SetLabel( const wxString
&label
)
109 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
111 wxControl::SetLabel( label
);
114 wxString
wxBitmapButton::GetLabel(void) const
116 wxCHECK_MSG( m_widget
!= NULL
, "", "invalid button" );
118 return wxControl::GetLabel();
121 void wxBitmapButton::SetBitmapLabel( const wxBitmap
& bitmap
)
123 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
126 if (!m_bitmap
.Ok()) return;
128 GtkButton
*bin
= GTK_BUTTON( m_widget
);
129 GtkPixmap
*g_pixmap
= GTK_PIXMAP( bin
->child
);
131 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
132 if (m_bitmap
.GetMask()) mask
= m_bitmap
.GetMask()->GetBitmap();
134 gtk_pixmap_set( g_pixmap
, m_bitmap
.GetPixmap(), mask
);
137 void wxBitmapButton::ApplyWidgetStyle()