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"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 extern bool g_blockEventsOnDrag
;
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
30 void gtk_radiobutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxRadioButton
*rb
)
32 if (!rb
->HasVMT()) return;
34 if (rb
->m_blockFirstEvent
)
36 rb
->m_blockFirstEvent
= FALSE
;
40 if (g_blockEventsOnDrag
) return;
42 wxCommandEvent
event( wxEVT_COMMAND_RADIOBUTTON_SELECTED
, rb
->GetId());
43 event
.SetInt( rb
->GetValue() );
44 event
.SetEventObject( rb
);
45 rb
->GetEventHandler()->ProcessEvent( event
);
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
,wxControl
)
54 bool wxRadioButton::Create( wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
55 const wxPoint
& pos
, const wxSize
& size
, long style
,
56 const wxValidator
& validator
, const wxString
& name
)
58 m_acceptsFocus
= TRUE
;
61 wxSize newSize
= size
;
63 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
65 SetValidator( validator
);
67 m_widget
= gtk_radio_button_new_with_label( (GSList
*) NULL
, label
);
69 m_theOtherRadioButtton
=
70 gtk_radio_button_new_with_label(
71 gtk_radio_button_group( GTK_RADIO_BUTTON(m_widget
) ),
76 m_blockFirstEvent
= FALSE
;
78 if (newSize
.x
== -1) newSize
.x
= 22+gdk_string_measure( m_widget
->style
->font
, label
);
79 if (newSize
.y
== -1) newSize
.y
= 26;
80 SetSize( newSize
.x
, newSize
.y
);
82 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
83 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback
), (gpointer
*)this );
85 m_parent
->AddChild( this );
87 (m_parent
->m_insertCallback
)( m_parent
, this );
91 SetBackgroundColour( parent
->GetBackgroundColour() );
92 SetForegroundColour( parent
->GetForegroundColour() );
99 void wxRadioButton::SetLabel( const wxString
& label
)
101 wxCHECK_RET( m_widget
!= NULL
, "invalid radiobutton" );
103 wxControl::SetLabel( label
);
104 GtkButton
*bin
= GTK_BUTTON( m_widget
);
105 GtkLabel
*g_label
= GTK_LABEL( bin
->child
);
106 gtk_label_set( g_label
, GetLabel() );
109 void wxRadioButton::SetValue( bool val
)
111 wxCHECK_RET( m_widget
!= NULL
, "invalid radiobutton" );
113 if ( val
== GetValue() )
116 m_blockFirstEvent
= TRUE
;
119 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget
), TRUE
);
121 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_theOtherRadioButtton
), TRUE
);
124 bool wxRadioButton::GetValue(void) const
126 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, "invalid radiobutton" );
128 return GTK_TOGGLE_BUTTON(m_widget
)->active
;
131 void wxRadioButton::Enable( bool enable
)
133 wxCHECK_RET( m_widget
!= NULL
, "invalid radiobutton" );
135 wxControl::Enable( enable
);
137 gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable
);
140 void wxRadioButton::ApplyWidgetStyle()
143 gtk_widget_set_style( m_widget
, m_widgetStyle
);
144 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle
);