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
);
77 SetValidator( validator
);
79 m_widget
= gtk_radio_button_new_with_label( (GSList
*) NULL
, label
.mbc_str() );
81 m_theOtherRadioButtton
=
82 gtk_radio_button_new_with_label(
83 gtk_radio_button_group( GTK_RADIO_BUTTON(m_widget
) ),
88 m_blockFirstEvent
= FALSE
;
90 if (newSize
.x
== -1) newSize
.x
= 22+gdk_string_measure( m_widget
->style
->font
, label
.mbc_str() );
91 if (newSize
.y
== -1) newSize
.y
= 26;
92 SetSize( newSize
.x
, newSize
.y
);
94 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
95 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback
), (gpointer
*)this );
97 m_parent
->DoAddChild( this );
101 SetBackgroundColour( parent
->GetBackgroundColour() );
102 SetForegroundColour( parent
->GetForegroundColour() );
103 SetFont( parent
->GetFont() );
110 void wxRadioButton::SetLabel( const wxString
& label
)
112 wxCHECK_RET( m_widget
!= NULL
, _T("invalid radiobutton") );
114 wxControl::SetLabel( label
);
115 GtkButton
*bin
= GTK_BUTTON( m_widget
);
116 GtkLabel
*g_label
= GTK_LABEL( bin
->child
);
117 gtk_label_set( g_label
, GetLabel().mbc_str() );
120 void wxRadioButton::SetValue( bool val
)
122 wxCHECK_RET( m_widget
!= NULL
, _T("invalid radiobutton") );
124 if ( val
== GetValue() )
127 m_blockFirstEvent
= TRUE
;
130 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget
), TRUE
);
132 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_theOtherRadioButtton
), TRUE
);
135 bool wxRadioButton::GetValue() const
137 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, _T("invalid radiobutton") );
139 return GTK_TOGGLE_BUTTON(m_widget
)->active
;
142 bool wxRadioButton::Enable( bool enable
)
144 if ( !wxControl::Enable( enable
) )
147 gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable
);
152 void wxRadioButton::ApplyWidgetStyle()
155 gtk_widget_set_style( m_widget
, m_widgetStyle
);
156 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle
);