1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "button.h"
18 #include "wx/button.h"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 extern void wxapp_install_idle_handler();
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 extern bool g_blockEventsOnDrag
;
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxButton
*button
)
49 wxapp_install_idle_handler();
51 if (!button
->m_hasVMT
) return;
52 if (g_blockEventsOnDrag
) return;
54 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
55 event
.SetEventObject(button
);
56 button
->GetEventHandler()->ProcessEvent(event
);
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
63 IMPLEMENT_DYNAMIC_CLASS(wxButton
,wxControl
)
73 bool wxButton::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&label
,
74 const wxPoint
&pos
, const wxSize
&size
,
75 long style
, const wxValidator
& validator
, const wxString
&name
)
78 m_acceptsFocus
= TRUE
;
80 if (!PreCreation( parent
, pos
, size
) ||
81 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
83 wxFAIL_MSG( wxT("wxButton creation failed") );
88 wxString label2( label );
89 for (size_t i = 0; i < label2.Len(); i++)
91 if (label2.GetChar(i) == wxT('&'))
92 label2.SetChar(i,wxT('_'));
95 GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() );
96 gtk_widget_show( accel_label );
98 m_widget = gtk_button_new();
99 gtk_container_add( GTK_CONTAINER(m_widget), accel_label );
101 gtk_accel_label_set_accel_widget( GTK_ACCEL_LABEL(accel_label), m_widget );
103 guint accel_key = gtk_label_parse_uline (GTK_LABEL(accel_label), label2.mb_str() );
104 gtk_accel_label_refetch( GTK_ACCEL_LABEL(accel_label) );
106 wxControl::SetLabel( label );
109 m_widget
= gtk_button_new_with_label("");
113 #if (GTK_MINOR_VERSION > 0)
114 if (style
& wxNO_BORDER
)
115 gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE
);
118 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
119 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
121 m_parent
->DoAddChild( this );
125 SetFont( parent
->GetFont() );
127 wxSize
best_size( DoGetBestSize() );
128 wxSize
new_size( size
);
129 if (new_size
.x
== -1)
130 new_size
.x
= best_size
.x
;
131 if (new_size
.y
== -1)
132 new_size
.y
= best_size
.y
;
133 if ((new_size
.x
!= size
.x
) || (new_size
.y
!= size
.y
))
134 SetSize( new_size
.x
, new_size
.y
);
138 SetBackgroundColour( parent
->GetBackgroundColour() );
139 SetForegroundColour( parent
->GetForegroundColour() );
146 void wxButton::SetDefault()
148 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
149 gtk_widget_grab_default( m_widget
);
151 SetSize( m_x
, m_y
, m_width
, m_height
);
155 wxSize
wxButton::GetDefaultSize()
157 return wxSize(80,26);
160 void wxButton::SetLabel( const wxString
&label
)
162 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid button") );
164 wxControl::SetLabel( label
);
166 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget
)->child
), GetLabel().mbc_str() );
169 bool wxButton::Enable( bool enable
)
171 if ( !wxControl::Enable( enable
) )
174 gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable
);
179 void wxButton::ApplyWidgetStyle()
182 gtk_widget_set_style( m_widget
, m_widgetStyle
);
183 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle
);
186 wxSize
wxButton::DoGetBestSize() const
188 wxSize
ret( wxControl::DoGetBestSize() );
189 if (ret
.x
< 80) ret
.x
= 80;
193 #endif // wxUSE_BUTTON