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::Enable( bool enable
)
91 wxControl::Enable( enable
);
92 GtkButton
*bin
= GTK_BUTTON( m_widget
);
93 GtkWidget
*label
= bin
->child
;
94 gtk_widget_set_sensitive( label
, enable
);
97 void wxRadioButton::SetFont( const wxFont
&font
)
99 if (((wxFont
*)&font
)->Ok())
102 m_font
= *wxSWISS_FONT
;
104 GtkButton
*bin
= GTK_BUTTON( m_widget
);
105 GtkWidget
*label
= bin
->child
;
107 GtkStyle
*style
= (GtkStyle
*) NULL
;
110 m_hasOwnStyle
= TRUE
;
111 style
= gtk_style_copy( gtk_widget_get_style( label
) );
115 style
= gtk_widget_get_style( label
);
118 gdk_font_unref( style
->font
);
119 style
->font
= gdk_font_ref( m_font
.GetInternalFont( 1.0 ) );
121 gtk_widget_set_style( label
, style
);