1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "button.h"
14 #include "wx/button.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 extern bool g_blockEventsOnDrag
;
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxButton
*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 IMPLEMENT_DYNAMIC_CLASS(wxButton
,wxControl
)
57 if (m_clientData
) delete m_clientData
;
60 bool wxButton::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&label
,
61 const wxPoint
&pos
, const wxSize
&size
,
62 long style
, const wxValidator
& validator
, const wxString
&name
)
64 m_clientData
= (wxClientData
*) NULL
;
66 m_acceptsFocus
= TRUE
;
68 wxSize newSize
= size
;
70 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
72 SetValidator( validator
);
74 m_widget
= gtk_button_new_with_label( m_label
);
77 if (newSize
.x
== -1) newSize
.x
= 15+gdk_string_measure( m_widget
->style
->font
, label
);
78 if (newSize
.y
== -1) newSize
.y
= 26;
79 SetSize( newSize
.x
, newSize
.y
);
81 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
82 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
84 m_parent
->AddChild( this );
86 (m_parent
->m_insertCallback
)( m_parent
, this );
90 SetBackgroundColour( parent
->GetBackgroundColour() );
91 SetForegroundColour( parent
->GetForegroundColour() );
92 SetFont( parent
->GetFont() );
99 void wxButton::SetDefault(void)
101 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
102 gtk_widget_grab_default( m_widget
);
104 SetSize( m_x
, m_y
, m_width
, m_height
);
107 void wxButton::SetLabel( const wxString
&label
)
109 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
111 wxControl::SetLabel( label
);
113 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget
)->child
), GetLabel() );
116 void wxButton::Enable( bool enable
)
118 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
120 wxControl::Enable( enable
);
122 gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable
);
125 void wxButton::ApplyWidgetStyle()
128 gtk_widget_set_style( m_widget
, m_widgetStyle
);
129 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle
);