1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "radiobut.h"
16 #include "wx/radiobut.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 extern bool g_blockEventsOnDrag
;
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
,wxControl
)
30 static void gtk_radiobutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxRadioButton
*rb
)
32 if (!rb
->HasVMT()) return;
33 if (g_blockEventsOnDrag
) return;
35 wxCommandEvent
event( wxEVT_COMMAND_RADIOBUTTON_SELECTED
, rb
->GetId());
36 event
.SetInt( rb
->GetValue() );
37 event
.SetEventObject( rb
);
38 rb
->GetEventHandler()->ProcessEvent( event
);
41 bool wxRadioButton::Create( wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
42 const wxPoint
& pos
, const wxSize
& size
, long style
,
43 const wxValidator
& validator
, const wxString
& name
)
47 wxSize newSize
= size
;
49 PreCreation( parent
, id
, pos
, newSize
, style
, name
);
51 SetValidator( validator
);
53 m_widget
= gtk_radio_button_new_with_label( (GSList
*) NULL
, label
);
57 if (newSize
.x
== -1) newSize
.x
= 22+gdk_string_measure( m_widget
->style
->font
, label
);
58 if (newSize
.y
== -1) newSize
.y
= 26;
59 SetSize( newSize
.x
, newSize
.y
);
61 gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked",
62 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback
), (gpointer
*)this );
71 void wxRadioButton::SetLabel( const wxString
& label
)
73 wxControl::SetLabel( label
);
74 GtkButton
*bin
= GTK_BUTTON( m_widget
);
75 GtkLabel
*g_label
= GTK_LABEL( bin
->child
);
76 gtk_label_set( g_label
, GetLabel() );
79 void wxRadioButton::SetValue( bool val
)
81 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget
), val
);
84 bool wxRadioButton::GetValue(void) const
86 return GTK_TOGGLE_BUTTON(m_widget
)->active
;
89 void wxRadioButton::SetFont( const wxFont
&font
)
93 GtkButton
*bin
= GTK_BUTTON( m_widget
);
94 GtkWidget
*label
= bin
->child
;
96 GtkStyle
*style
= (GtkStyle
*) NULL
;
100 style
= gtk_style_copy( gtk_widget_get_style( label
) );
104 style
= gtk_widget_get_style( label
);
107 gdk_font_unref( style
->font
);
108 style
->font
= gdk_font_ref( m_font
.GetInternalFont( 1.0 ) );
110 gtk_widget_set_style( label
, style
);