1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "radiobut.h"
15 #include "wx/radiobut.h"
17 //-----------------------------------------------------------------------------
19 //-----------------------------------------------------------------------------
21 extern bool g_blockEventsOnDrag
;
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
28 void gtk_radiobutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxRadioButton
*rb
)
30 if (!rb
->HasVMT()) return;
32 if (rb
->m_blockFirstEvent
)
34 rb
->m_blockFirstEvent
= FALSE
;
38 if (g_blockEventsOnDrag
) return;
40 wxCommandEvent
event( wxEVT_COMMAND_RADIOBUTTON_SELECTED
, rb
->GetId());
41 event
.SetInt( rb
->GetValue() );
42 event
.SetEventObject( rb
);
43 rb
->GetEventHandler()->ProcessEvent( event
);
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
50 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
,wxControl
)
52 bool wxRadioButton::Create( wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
53 const wxPoint
& pos
, const wxSize
& size
, long style
,
54 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_radio_button_new_with_label( (GSList
*) NULL
, label
);
66 m_theOtherRadioButtton
=
67 gtk_radio_button_new_with_label(
68 gtk_radio_button_group( GTK_RADIO_BUTTON(m_widget
) ),
73 m_blockFirstEvent
= FALSE
;
75 if (newSize
.x
== -1) newSize
.x
= 22+gdk_string_measure( m_widget
->style
->font
, label
);
76 if (newSize
.y
== -1) newSize
.y
= 26;
77 SetSize( newSize
.x
, newSize
.y
);
79 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
80 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback
), (gpointer
*)this );
82 m_parent
->AddChild( this );
84 (m_parent
->m_insertCallback
)( m_parent
, this );
88 SetBackgroundColour( parent
->GetBackgroundColour() );
89 SetForegroundColour( parent
->GetForegroundColour() );
96 void wxRadioButton::SetLabel( const wxString
& label
)
98 wxCHECK_RET( m_widget
!= NULL
, "invalid radiobutton" );
100 wxControl::SetLabel( label
);
101 GtkButton
*bin
= GTK_BUTTON( m_widget
);
102 GtkLabel
*g_label
= GTK_LABEL( bin
->child
);
103 gtk_label_set( g_label
, GetLabel() );
106 void wxRadioButton::SetValue( bool val
)
108 wxCHECK_RET( m_widget
!= NULL
, "invalid radiobutton" );
110 m_blockFirstEvent
= TRUE
;
113 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget
), TRUE
);
115 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_theOtherRadioButtton
), TRUE
);
118 bool wxRadioButton::GetValue(void) const
120 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, "invalid radiobutton" );
122 return GTK_TOGGLE_BUTTON(m_widget
)->active
;
125 void wxRadioButton::Enable( bool enable
)
127 wxCHECK_RET( m_widget
!= NULL
, "invalid radiobutton" );
129 wxControl::Enable( enable
);
131 gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable
);
134 void wxRadioButton::ApplyWidgetStyle()
137 gtk_widget_set_style( m_widget
, m_widgetStyle
);
138 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle
);