]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/radiobut.cpp
Fix stc doxygen warnings and regen stc files.
[wxWidgets.git] / src / gtk / radiobut.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/gtk/radiobut.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
f96aa4d9 5// Copyright: (c) 1998 Robert Roebling
65571936 6// Licence: wxWindows licence
c801d85f
KB
7/////////////////////////////////////////////////////////////////////////////
8
14f355c2
VS
9// For compilers that support precompilation, includes "wx.h".
10#include "wx/wxprec.h"
dcf924a3 11
d968078a 12#if wxUSE_RADIOBTN
dcf924a3 13
1e6feb95
VZ
14#include "wx/radiobut.h"
15
9dc44eff 16#include <gtk/gtk.h>
9e691f46 17#include "wx/gtk/private.h"
9dc44eff 18#include "wx/gtk/private/gtk2-compat.h"
c801d85f 19
6de97a3b
RR
20//-----------------------------------------------------------------------------
21// data
22//-----------------------------------------------------------------------------
23
d7fa7eaa 24extern bool g_blockEventsOnDrag;
6de97a3b
RR
25
26//-----------------------------------------------------------------------------
bb4549de 27// "clicked"
6de97a3b
RR
28//-----------------------------------------------------------------------------
29
865bb325 30extern "C" {
b2ff89d6 31static
e2762ff0 32void gtk_radiobutton_clicked_callback( GtkToggleButton *button, wxRadioButton *rb )
6de97a3b 33{
f5d29b39 34 if (g_blockEventsOnDrag) return;
b2ff89d6 35
385e8575 36 if (!gtk_toggle_button_get_active(button)) return;
b2ff89d6 37
ce7fe42e 38 wxCommandEvent event( wxEVT_RADIOBUTTON, rb->GetId());
f5d29b39
RR
39 event.SetInt( rb->GetValue() );
40 event.SetEventObject( rb );
937013e0 41 rb->HandleWindowEvent( event );
6de97a3b 42}
865bb325 43}
6de97a3b 44
bb4549de
RR
45//-----------------------------------------------------------------------------
46// wxRadioButton
47//-----------------------------------------------------------------------------
48
2b4f3c9f
VZ
49bool wxRadioButton::Create( wxWindow *parent,
50 wxWindowID id,
51 const wxString& label,
52 const wxPoint& pos,
53 const wxSize& size,
54 long style,
55 const wxValidator& validator,
56 const wxString& name )
6de97a3b 57{
4dcaf11a
RR
58 if (!PreCreation( parent, pos, size ) ||
59 !CreateBase( parent, id, pos, size, style, validator, name ))
60 {
223d09f6 61 wxFAIL_MSG( wxT("wxRadioButton creation failed") );
e8375af8 62 return false;
4dcaf11a 63 }
953704c1 64
a45c6a89
VZ
65 // Check if this radio button should be put into an existing group. This
66 // shouldn't be done if it's given a style to explicitly start a new group
67 // or if it's not meant to be a part of a group at all.
739b7529 68 GSList* radioButtonGroup = NULL;
f938aa99 69 if (!HasFlag(wxRB_GROUP) && !HasFlag(wxRB_SINGLE))
953704c1 70 {
9864c56d 71 // search backward for last group start
222ed1d6 72 wxWindowList::compatibility_iterator node = parent->GetChildren().GetLast();
d968078a 73 for (; node; node = node->GetPrevious())
e2762ff0
RR
74 {
75 wxWindow *child = node->GetData();
a45c6a89
VZ
76
77 // We stop at the first previous radio button in any case as it
78 // wouldn't make sense to put this button in a group with another
79 // one if there is a radio button that is not part of the same
80 // group between them.
81 if (wxIsKindOf(child, wxRadioButton))
e2762ff0 82 {
a45c6a89
VZ
83 // Any preceding radio button can be used to get its group, not
84 // necessarily one with wxRB_GROUP style, but exclude
85 // wxRB_SINGLE ones as their group should never be shared.
86 if (!child->HasFlag(wxRB_SINGLE))
87 {
88 radioButtonGroup = gtk_radio_button_get_group(
89 GTK_RADIO_BUTTON(child->m_widget));
90 }
91
d968078a 92 break;
e2762ff0 93 }
e2762ff0 94 }
953704c1
RR
95 }
96
739b7529 97 m_widget = gtk_radio_button_new_with_label( radioButtonGroup, wxGTK_CONV( label ) );
9ff9d30c 98 g_object_ref(m_widget);
b2ff89d6 99
f5d29b39 100 SetLabel(label);
6de97a3b 101
e9a7fde5
RR
102 g_signal_connect_after (m_widget, "clicked",
103 G_CALLBACK (gtk_radiobutton_clicked_callback), this);
b2ff89d6 104
f03fc89f 105 m_parent->DoAddChild( this );
b2ff89d6 106
abdeb9e7 107 PostCreation(size);
6de97a3b 108
d968078a 109 return true;
6de97a3b
RR
110}
111
112void wxRadioButton::SetLabel( const wxString& label )
113{
223d09f6 114 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobutton") );
b2ff89d6 115
6ea2bc50
VZ
116 // save the original label
117 wxControlBase::SetLabel(label);
118
385e8575 119 GTKSetLabelForLabel(GTK_LABEL(gtk_bin_get_child(GTK_BIN(m_widget))), label);
6de97a3b
RR
120}
121
122void wxRadioButton::SetValue( bool val )
123{
223d09f6 124 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobutton") );
f6bcfd97 125
953704c1 126 if (val == GetValue())
0659e7ee
RR
127 return;
128
d968078a
PC
129 g_signal_handlers_block_by_func(
130 m_widget, (void*)gtk_radiobutton_clicked_callback, this);
953704c1 131
f5d29b39 132 if (val)
953704c1 133 {
e2762ff0 134 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(m_widget), TRUE );
953704c1 135 }
f5d29b39 136 else
953704c1
RR
137 {
138 // should give an assert
f6bcfd97
BP
139 // RL - No it shouldn't. A wxGenericValidator might try to set it
140 // as FALSE. Failing silently is probably TRTTD here.
953704c1 141 }
f6bcfd97 142
d968078a
PC
143 g_signal_handlers_unblock_by_func(
144 m_widget, (void*)gtk_radiobutton_clicked_callback, this);
6de97a3b
RR
145}
146
eb082a08 147bool wxRadioButton::GetValue() const
6de97a3b 148{
d968078a 149 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobutton") );
b2ff89d6 150
385e8575 151 return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_widget)) != 0;
6de97a3b
RR
152}
153
f03fc89f 154bool wxRadioButton::Enable( bool enable )
d3904ceb 155{
b545684e 156 if (!base_type::Enable(enable))
d968078a 157 return false;
b2ff89d6 158
385e8575 159 gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(m_widget)), enable);
f03fc89f 160
b545684e 161 if (enable)
ad60f9e7 162 GTKFixSensitivity();
ad60f9e7 163
d968078a 164 return true;
d3904ceb
RR
165}
166
f40fdaa3 167void wxRadioButton::DoApplyWidgetStyle(GtkRcStyle *style)
868a2826 168{
9dc44eff
PC
169 GTKApplyStyle(m_widget, style);
170 GTKApplyStyle(gtk_bin_get_child(GTK_BIN(m_widget)), style);
f96aa4d9 171}
dcf924a3 172
ef5c70f9
VZ
173GdkWindow *
174wxRadioButton::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
2f073eb2 175{
9dc44eff 176 return gtk_button_get_event_window(GTK_BUTTON(m_widget));
2f073eb2
RR
177}
178
9d522606
RD
179// static
180wxVisualAttributes
181wxRadioButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
182{
7fff16b8 183 return GetDefaultAttributesFromGTKWidget(gtk_radio_button_new_with_label(NULL, ""));
9d522606
RD
184}
185
186
dcf924a3 187#endif