1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
15 #include "wx/radiobut.h"
17 #include "wx/gtk/private.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 extern bool g_blockEventsOnDrag
;
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
31 void gtk_radiobutton_clicked_callback( GtkToggleButton
*button
, wxRadioButton
*rb
)
33 if (!rb
->m_hasVMT
) return;
35 if (g_blockEventsOnDrag
) return;
37 if (!button
->active
) return;
39 wxCommandEvent
event( wxEVT_COMMAND_RADIOBUTTON_SELECTED
, rb
->GetId());
40 event
.SetInt( rb
->GetValue() );
41 event
.SetEventObject( rb
);
42 rb
->HandleWindowEvent( event
);
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
50 bool wxRadioButton::Create( wxWindow
*parent
,
52 const wxString
& label
,
56 const wxValidator
& validator
,
57 const wxString
& name
)
59 if (!PreCreation( parent
, pos
, size
) ||
60 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
62 wxFAIL_MSG( wxT("wxRadioButton creation failed") );
66 GSList
* radioButtonGroup
= NULL
;
67 if (!HasFlag(wxRB_GROUP
) && !HasFlag(wxRB_SINGLE
))
69 // search backward for last group start
70 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetLast();
71 for (; node
; node
= node
->GetPrevious())
73 wxWindow
*child
= node
->GetData();
74 if (child
->HasFlag(wxRB_GROUP
) && wxIsKindOf(child
, wxRadioButton
))
76 radioButtonGroup
= gtk_radio_button_get_group(
77 GTK_RADIO_BUTTON(child
->m_widget
));
83 m_widget
= gtk_radio_button_new_with_label( radioButtonGroup
, wxGTK_CONV( label
) );
84 g_object_ref(m_widget
);
88 g_signal_connect_after (m_widget
, "clicked",
89 G_CALLBACK (gtk_radiobutton_clicked_callback
), this);
91 m_parent
->DoAddChild( this );
98 void wxRadioButton::SetLabel( const wxString
& label
)
100 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid radiobutton") );
102 GTKSetLabelForLabel(GTK_LABEL(GTK_BIN(m_widget
)->child
), label
);
105 void wxRadioButton::SetValue( bool val
)
107 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid radiobutton") );
109 if (val
== GetValue())
112 g_signal_handlers_block_by_func(
113 m_widget
, (void*)gtk_radiobutton_clicked_callback
, this);
117 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(m_widget
), TRUE
);
121 // should give an assert
122 // RL - No it shouldn't. A wxGenericValidator might try to set it
123 // as FALSE. Failing silently is probably TRTTD here.
126 g_signal_handlers_unblock_by_func(
127 m_widget
, (void*)gtk_radiobutton_clicked_callback
, this);
130 bool wxRadioButton::GetValue() const
132 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid radiobutton") );
134 return GTK_TOGGLE_BUTTON(m_widget
)->active
;
137 bool wxRadioButton::Enable( bool enable
)
139 if (!base_type::Enable(enable
))
142 gtk_widget_set_sensitive(GTK_BIN(m_widget
)->child
, enable
);
150 void wxRadioButton::DoApplyWidgetStyle(GtkRcStyle
*style
)
152 gtk_widget_modify_style(m_widget
, style
);
153 gtk_widget_modify_style(GTK_BIN(m_widget
)->child
, style
);
157 wxRadioButton::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
159 return GTK_BUTTON(m_widget
)->event_window
;
164 wxRadioButton::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
166 wxVisualAttributes attr
;
167 // NB: we need toplevel window so that GTK+ can find the right style
168 GtkWidget
*wnd
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
169 GtkWidget
* widget
= gtk_radio_button_new_with_label(NULL
, "");
170 gtk_container_add(GTK_CONTAINER(wnd
), widget
);
171 attr
= GetDefaultAttributesFromGTKWidget(widget
);
172 gtk_widget_destroy(wnd
);