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
)
44 if (g_isIdle
) wxapp_install_idle_handler();
46 if (!button
->HasVMT()) return;
47 if (g_blockEventsOnDrag
) return;
49 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId());
50 event
.SetEventObject(button
);
51 button
->GetEventHandler()->ProcessEvent(event
);
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 IMPLEMENT_DYNAMIC_CLASS(wxButton
,wxControl
)
66 if (m_clientData
) delete m_clientData
;
69 bool wxButton::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&label
,
70 const wxPoint
&pos
, const wxSize
&size
,
71 long style
, const wxValidator
& validator
, const wxString
&name
)
73 m_clientData
= (wxClientData
*) NULL
;
75 m_acceptsFocus
= TRUE
;
77 wxSize newSize
= size
;
79 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
81 SetValidator( validator
);
83 m_widget
= gtk_button_new_with_label( m_label
.mbc_str() );
86 if (newSize
.x
== -1) newSize
.x
= 15+gdk_string_measure( m_widget
->style
->font
, label
.mbc_str() );
87 if (newSize
.y
== -1) newSize
.y
= 26;
88 SetSize( newSize
.x
, newSize
.y
);
90 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
91 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
93 m_parent
->AddChild( this );
95 (m_parent
->m_insertCallback
)( m_parent
, this );
99 SetBackgroundColour( parent
->GetBackgroundColour() );
100 SetForegroundColour( parent
->GetForegroundColour() );
101 SetFont( parent
->GetFont() );
108 void wxButton::SetDefault(void)
110 GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT
);
111 gtk_widget_grab_default( m_widget
);
113 SetSize( m_x
, m_y
, m_width
, m_height
);
116 void wxButton::SetLabel( const wxString
&label
)
118 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
120 wxControl::SetLabel( label
);
122 gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget
)->child
), GetLabel().mbc_str() );
125 void wxButton::Enable( bool enable
)
127 wxCHECK_RET( m_widget
!= NULL
, _T("invalid button") );
129 wxControl::Enable( enable
);
131 gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable
);
134 void wxButton::ApplyWidgetStyle()
137 gtk_widget_set_style( m_widget
, m_widgetStyle
);
138 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle
);