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 void wxapp_install_idle_handler();
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 extern bool g_blockEventsOnDrag
;
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxButton
*button
)
45 wxapp_install_idle_handler();
47 if (!button
->m_hasVMT
) return;
48 if (g_blockEventsOnDrag
) return;
50 printf( "clicked: %s.\n", button
->GetLabel().c_str() );
52 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
53 event
.SetEventObject(button
);
54 button
->GetEventHandler()->ProcessEvent(event
);
57 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
61 IMPLEMENT_DYNAMIC_CLASS(wxButton
,wxControl
)
69 if (m_clientData
) delete m_clientData
;
72 bool wxButton::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&label
,
73 const wxPoint
&pos
, const wxSize
&size
,
74 long style
, const wxValidator
& validator
, const wxString
&name
)
76 m_clientData
= (wxClientData
*) NULL
;
78 m_acceptsFocus
= TRUE
;
80 wxSize newSize
= size
;
82 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
84 SetValidator( validator
);
86 m_widget
= gtk_button_new_with_label( "" );
88 #if (GTK_MINOR_VERSION > 0)
89 if (style
& wxNO_BORDER
)
90 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
95 if (newSize
.x
== -1) newSize
.x
= 15+gdk_string_measure( m_widget
->style
->font
, label
.mbc_str() );
96 if (newSize
.y
== -1) newSize
.y
= 26;
97 SetSize( newSize
.x
, newSize
.y
);
99 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
100 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
102 m_parent
->DoAddChild( this );
106 SetBackgroundColour( parent
->GetBackgroundColour() );
107 SetForegroundColour( parent
->GetForegroundColour() );
108 SetFont( parent
->GetFont() );
115 void wxButton::SetDefault(void)
117 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
118 gtk_widget_grab_default( m_widget
);
120 SetSize( m_x
, m_y
, m_width
, m_height
);
123 void wxButton::SetLabel( const wxString
&label
)
125 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
127 wxControl::SetLabel( label
);
129 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget
)->child
), GetLabel().mbc_str() );
132 bool wxButton::Enable( bool enable
)
134 if ( !wxControl::Enable( enable
) )
137 gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable
);
142 void wxButton::ApplyWidgetStyle()
145 gtk_widget_set_style( m_widget
, m_widgetStyle
);
146 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle
);