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"
17 //-----------------------------------------------------------------------------
19 //-----------------------------------------------------------------------------
21 extern bool g_blockEventsOnDrag
;
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
,wxControl
)
29 static void gtk_radiobutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxRadioButton
*rb
)
31 if (!rb
->HasVMT()) return;
32 if (g_blockEventsOnDrag
) return;
34 wxCommandEvent
event( wxEVT_COMMAND_RADIOBUTTON_SELECTED
, rb
->GetId());
35 event
.SetInt( rb
->GetValue() );
36 event
.SetEventObject( rb
);
37 rb
->GetEventHandler()->ProcessEvent( event
);
40 bool wxRadioButton::Create( wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
41 const wxPoint
& pos
, const wxSize
& size
, long style
,
42 const wxValidator
& validator
, const wxString
& name
)
46 wxSize newSize
= size
;
48 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
50 SetValidator( validator
);
52 m_widget
= gtk_radio_button_new_with_label( (GSList
*) NULL
, label
);
56 if (newSize
.x
== -1) newSize
.x
= 22+gdk_string_measure( m_widget
->style
->font
, label
);
57 if (newSize
.y
== -1) newSize
.y
= 26;
58 SetSize( newSize
.x
, newSize
.y
);
60 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
61 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback
), (gpointer
*)this );
70 void wxRadioButton::SetLabel( const wxString
& label
)
72 wxCHECK_RET( m_widget
!= NULL
, "invalid radiobutton" );
74 wxControl::SetLabel( label
);
75 GtkButton
*bin
= GTK_BUTTON( m_widget
);
76 GtkLabel
*g_label
= GTK_LABEL( bin
->child
);
77 gtk_label_set( g_label
, GetLabel() );
80 void wxRadioButton::SetValue( bool val
)
82 wxCHECK_RET( m_widget
!= NULL
, "invalid radiobutton" );
84 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget
), val
);
87 bool wxRadioButton::GetValue(void) const
89 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, "invalid radiobutton" );
91 return GTK_TOGGLE_BUTTON(m_widget
)->active
;
94 void wxRadioButton::Enable( bool enable
)
96 wxCHECK_RET( m_widget
!= NULL
, "invalid radiobutton" );
98 wxControl::Enable( enable
);
100 gtk_widget_set_sensitive( GTK_BUTTON(m_widget
)->child
, enable
);
103 void wxRadioButton::SetFont( const wxFont
&font
)
105 wxCHECK_RET( m_widget
!= NULL
, "invalid radiobutton" );
107 wxControl::SetFont( font
);
109 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
,
111 gtk_widget_get_style( m_widget
) ) );
114 void wxRadioButton::SetBackgroundColour( const wxColour
&colour
)
118 wxCHECK_RET( m_widget
!= NULL
, "invalid radiobutton" );
120 wxControl::SetBackgroundColour( colour
);
122 if (!m_backgroundColour
.Ok()) return;
124 gtk_widget_set_style( GTK_BUTTON(m_widget
)->child
,
126 gtk_widget_get_style( m_widget
) ) );