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"
16 //-----------------------------------------------------------------------------
18 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 extern bool g_blockEventsOnDrag
;
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxButton
*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(wxButton
,wxControl
)
48 wxButton::wxButton(void)
52 bool wxButton::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&label
,
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
);
64 m_widget
= gtk_button_new_with_label( m_label
);
67 if (newSize
.x
== -1) newSize
.x
= 15+gdk_string_measure( m_widget
->style
->font
, label
);
68 if (newSize
.y
== -1) newSize
.y
= 26;
69 SetSize( newSize
.x
, newSize
.y
);
71 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
72 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
76 SetBackgroundColour( parent
->GetBackgroundColour() );
83 void wxButton::SetDefault(void)
86 GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
87 gtk_widget_grab_default( m_widget );
91 void wxButton::SetLabel( const wxString
&label
)
93 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
95 wxControl::SetLabel( label
);
97 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget
)->child
), GetLabel() );
100 void wxButton::Enable( bool enable
)
102 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
104 wxControl::Enable( enable
);
106 gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable
);
109 void wxButton::SetFont( const wxFont
&font
)
111 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
113 wxControl::SetFont( font
);
115 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle
);
118 void wxButton::SetBackgroundColour( const wxColour
&colour
)
120 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
122 wxControl::SetBackgroundColour( colour
);
124 if (!m_backgroundColour
.Ok()) return;
126 gtk_widget_set_style( m_widget
, m_widgetStyle
);
129 void wxButton::SetForegroundColour( const wxColour
&colour
)
131 wxCHECK_RET( m_widget
!= NULL
, "invalid button" );
133 wxControl::SetForegroundColour( colour
);
135 if (!m_foregroundColour
.Ok()) return;
137 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle
);