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"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 extern void wxapp_install_idle_handler();
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 extern bool g_blockEventsOnDrag
;
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
40 void gtk_radiobutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxRadioButton
*rb
)
42 if (g_isIdle
) wxapp_install_idle_handler();
44 if (!rb
->m_hasVMT
) return;
46 if (rb
->m_blockFirstEvent
)
48 rb
->m_blockFirstEvent
= FALSE
;
52 if (g_blockEventsOnDrag
) return;
54 wxCommandEvent
event( wxEVT_COMMAND_RADIOBUTTON_SELECTED
, rb
->GetId());
55 event
.SetInt( rb
->GetValue() );
56 event
.SetEventObject( rb
);
57 rb
->GetEventHandler()->ProcessEvent( event
);
60 //-----------------------------------------------------------------------------
62 //-----------------------------------------------------------------------------
64 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
,wxControl
)
66 bool wxRadioButton::Create( wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
67 const wxPoint
& pos
, const wxSize
& size
, long style
,
68 const wxValidator
& validator
, const wxString
& name
)
70 m_acceptsFocus
= TRUE
;
73 wxSize newSize
= size
;
75 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
78 SetValidator( validator
);
81 m_widget
= gtk_radio_button_new_with_label( (GSList
*) NULL
, label
.mbc_str() );
83 m_theOtherRadioButtton
=
84 gtk_radio_button_new_with_label(
85 gtk_radio_button_group( GTK_RADIO_BUTTON(m_widget
) ),
90 m_blockFirstEvent
= FALSE
;
92 if (newSize
.x
== -1) newSize
.x
= 22+gdk_string_measure( m_widget
->style
->font
, label
.mbc_str() );
93 if (newSize
.y
== -1) newSize
.y
= 26;
94 SetSize( newSize
.x
, newSize
.y
);
96 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
97 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback
), (gpointer
*)this );
99 m_parent
->DoAddChild( this );
103 SetBackgroundColour( parent
->GetBackgroundColour() );
104 SetForegroundColour( parent
->GetForegroundColour() );
105 SetFont( parent
->GetFont() );
112 void wxRadioButton::SetLabel( const wxString
& label
)
114 wxCHECK_RET( m_widget
!= NULL
, _T("invalid radiobutton") );
116 wxControl::SetLabel( label
);
117 GtkButton
*bin
= GTK_BUTTON( m_widget
);
118 GtkLabel
*g_label
= GTK_LABEL( bin
->child
);
119 gtk_label_set( g_label
, GetLabel().mbc_str() );
122 void wxRadioButton::SetValue( bool val
)
124 wxCHECK_RET( m_widget
!= NULL
, _T("invalid radiobutton") );
126 if ( val
== GetValue() )
129 m_blockFirstEvent
= TRUE
;
132 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget
), TRUE
);
134 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_theOtherRadioButtton
), TRUE
);
137 bool wxRadioButton::GetValue() const
139 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, _T("invalid radiobutton") );
141 return GTK_TOGGLE_BUTTON(m_widget
)->active
;
144 bool wxRadioButton::Enable( bool enable
)
146 if ( !wxControl::Enable( enable
) )
149 gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable
);
154 void wxRadioButton::ApplyWidgetStyle()
157 gtk_widget_set_style( m_widget
, m_widgetStyle
);
158 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle
);