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
.mbc_str() );
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
.mbc_str() );
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() );
93 SetFont( parent
->GetFont() );
100 void wxRadioButton::SetLabel( const wxString
& label
)
102 wxCHECK_RET( m_widget
!= NULL
, _T("invalid radiobutton") );
104 wxControl::SetLabel( label
);
105 GtkButton
*bin
= GTK_BUTTON( m_widget
);
106 GtkLabel
*g_label
= GTK_LABEL( bin
->child
);
107 gtk_label_set( g_label
, GetLabel().mbc_str() );
110 void wxRadioButton::SetValue( bool val
)
112 wxCHECK_RET( m_widget
!= NULL
, _T("invalid radiobutton") );
114 if ( val
== GetValue() )
117 m_blockFirstEvent
= TRUE
;
120 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget
), TRUE
);
122 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_theOtherRadioButtton
), TRUE
);
125 bool wxRadioButton::GetValue(void) const
127 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, _T("invalid radiobutton") );
129 return GTK_TOGGLE_BUTTON(m_widget
)->active
;
132 void wxRadioButton::Enable( bool enable
)
134 wxCHECK_RET( m_widget
!= NULL
, _T("invalid radiobutton") );
136 wxControl::Enable( enable
);
138 gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable
);
141 void wxRadioButton::ApplyWidgetStyle()
144 gtk_widget_set_style( m_widget
, m_widgetStyle
);
145 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle
);