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 void wxapp_install_idle_handler();
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 extern bool g_blockEventsOnDrag
;
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
37 void gtk_radiobutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxRadioButton
*rb
)
39 if (g_isIdle
) wxapp_install_idle_handler();
41 if (!rb
->HasVMT()) return;
43 if (rb
->m_blockFirstEvent
)
45 rb
->m_blockFirstEvent
= FALSE
;
49 if (g_blockEventsOnDrag
) return;
51 wxCommandEvent
event( wxEVT_COMMAND_RADIOBUTTON_SELECTED
, rb
->GetId());
52 event
.SetInt( rb
->GetValue() );
53 event
.SetEventObject( rb
);
54 rb
->GetEventHandler()->ProcessEvent( event
);
57 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
61 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
,wxControl
)
63 bool wxRadioButton::Create( wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
64 const wxPoint
& pos
, const wxSize
& size
, long style
,
65 const wxValidator
& validator
, const wxString
& name
)
67 m_acceptsFocus
= TRUE
;
70 wxSize newSize
= size
;
72 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
74 SetValidator( validator
);
76 m_widget
= gtk_radio_button_new_with_label( (GSList
*) NULL
, label
.mbc_str() );
78 m_theOtherRadioButtton
=
79 gtk_radio_button_new_with_label(
80 gtk_radio_button_group( GTK_RADIO_BUTTON(m_widget
) ),
85 m_blockFirstEvent
= FALSE
;
87 if (newSize
.x
== -1) newSize
.x
= 22+gdk_string_measure( m_widget
->style
->font
, label
.mbc_str() );
88 if (newSize
.y
== -1) newSize
.y
= 26;
89 SetSize( newSize
.x
, newSize
.y
);
91 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
92 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback
), (gpointer
*)this );
94 m_parent
->AddChild( this );
96 (m_parent
->m_insertCallback
)( m_parent
, this );
100 SetBackgroundColour( parent
->GetBackgroundColour() );
101 SetForegroundColour( parent
->GetForegroundColour() );
102 SetFont( parent
->GetFont() );
109 void wxRadioButton::SetLabel( const wxString
& label
)
111 wxCHECK_RET( m_widget
!= NULL
, _T("invalid radiobutton") );
113 wxControl::SetLabel( label
);
114 GtkButton
*bin
= GTK_BUTTON( m_widget
);
115 GtkLabel
*g_label
= GTK_LABEL( bin
->child
);
116 gtk_label_set( g_label
, GetLabel().mbc_str() );
119 void wxRadioButton::SetValue( bool val
)
121 wxCHECK_RET( m_widget
!= NULL
, _T("invalid radiobutton") );
123 if ( val
== GetValue() )
126 m_blockFirstEvent
= TRUE
;
129 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget
), TRUE
);
131 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_theOtherRadioButtton
), TRUE
);
134 bool wxRadioButton::GetValue(void) const
136 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, _T("invalid radiobutton") );
138 return GTK_TOGGLE_BUTTON(m_widget
)->active
;
141 void wxRadioButton::Enable( bool enable
)
143 wxCHECK_RET( m_widget
!= NULL
, _T("invalid radiobutton") );
145 wxControl::Enable( enable
);
147 gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable
);
150 void wxRadioButton::ApplyWidgetStyle()
153 gtk_widget_set_style( m_widget
, m_widgetStyle
);
154 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
, m_widgetStyle
);