File: GtkRadioButton.xs

package info (click to toggle)
libgtk2-perl 2:1.2499-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,668 kB
  • ctags: 594
  • sloc: perl: 22,100; ansic: 122; makefile: 17
file content (199 lines) | stat: -rw-r--r-- 6,334 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
 * Copyright (c) 2003, 2010 by the gtk2-perl team (see the file AUTHORS)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
 * Boston, MA  02111-1307  USA.
 *
 * $Id$
 */

#include "gtk2perl.h"

MODULE = Gtk2::RadioButton	PACKAGE = Gtk2::RadioButton	PREFIX = gtk_radio_button_

=for position SYNOPSIS

=head1 SYNOPSIS

  # first group
  $foo1 = Gtk2::RadioButton->new (undef, 'Foo One');
  $foo2 = Gtk2::RadioButton->new ($foo1, 'Foo Two');
  $foo3 = Gtk2::RadioButton->new ($foo2, 'Foo Three');

  # second group, using the group reference
  $bar1 = Gtk2::RadioButton->new (undef, 'Bar One');
  $group = $bar1->get_group;
  $bar2 = Gtk2::RadioButton->new ($group, 'Bar Two');
  $bar3 = Gtk2::RadioButton->new ($group, 'Bar Three');

  # move bar3 from the bar group to the foo group.
  $bar->set_group ($foo->get_group);

  # iterate over the widgets in the group
  $group = $foo1->get_group;
  foreach my $r (@$group) {
      $r->set_sensitive ($whatever);
  }

=cut

=for position DESCRIPTION

=head1 DESCRIPTION

A single radio button performs the same basic function as a Gtk2::CheckButton,
as its position in the object hierarchy reflects.  It is only when multiple
radio buttons are grouped together that they become a different user interface
component in their own right.

Every radio button is a member of some group of radio buttons.  When one is
selected, all other radio buttons in the same group are deselected.  A
Gtk2::RadioButton is one way of giving the user a choice from many options;
Gtk2::OptionMenu and Gtk2::ComboBox (added in gtk+ 2.4) are alternatives.

Each constructor can take either a group or widget from that group where the
group is wanted; this is an enhancement over the C API.  Nevertheless, the
_from_widget forms are provided for completeness.

=cut

=for apidoc Gtk2::RadioButton::new_with_mnemonic
=for arg member_or_listref reference to radiobutton group or a Gtk2::RadioButton belonging to that group.
Create a radio button with a mnemonic; this is an alias for C<new>.
=cut

=for apidoc Gtk2::RadioButton::new_with_label
=for arg member_or_listref reference to radiobutton group or a Gtk2::RadioButton belonging to that group.
Create a radio button with a plain text label, which will not be interpreted
as a mnemonic.
=cut

=for apidoc
=for arg member_or_listref reference to radiobutton group or a Gtk2::RadioButton belonging to that group.
Create a radio button.  If I<$label> is provided, it will be interpreted
as a mnemonic.  If I<$member_or_listref> is undef, the radio button will
be created in a new group.
=cut
GtkWidget *
gtk_radio_button_new (class, member_or_listref=NULL, label=NULL)
	SV          * member_or_listref
	const gchar * label
    ALIAS:
	Gtk2::RadioButton::new_with_mnemonic = 1
	Gtk2::RadioButton::new_with_label = 2
    PREINIT:
	GSList         * group = NULL;
	GtkRadioButton * member = NULL;
    CODE:
	if( gperl_sv_is_defined (member_or_listref)
	    && SvROK (member_or_listref)
	    && SvRV (member_or_listref) != &PL_sv_undef )
	{
		if( gperl_sv_is_array_ref (member_or_listref) )
		{
			AV * av = (AV*)SvRV(member_or_listref);
			SV ** svp = av_fetch(av, 0, 0);
			if( svp && gperl_sv_is_defined(*svp) )
				member = SvGtkRadioButton(*svp);
		}
		else
			member = SvGtkRadioButton_ornull(member_or_listref);
		if( member )
			group = member->group;
	}

	if (label) {
		if (ix == 2)
			RETVAL = gtk_radio_button_new_with_label (group, label);
		else
			RETVAL = gtk_radio_button_new_with_mnemonic (group, label);
	} else
		RETVAL = gtk_radio_button_new (group);
    OUTPUT:
	RETVAL


GtkWidget *
gtk_radio_button_new_from_widget (class, group, label=NULL)
	GtkRadioButton_ornull * group
	const gchar           * label
    ALIAS:
	Gtk2::RadioButton::new_with_mnemonic_from_widget = 1
	Gtk2::RadioButton::new_with_label_from_widget = 2
    CODE:
	if (label) {
		if (ix == 2)
			RETVAL = gtk_radio_button_new_with_label_from_widget (group, label);
		else
			RETVAL = gtk_radio_button_new_with_mnemonic_from_widget (group, label);
	} else
		RETVAL = gtk_radio_button_new_from_widget (group);
    OUTPUT:
	RETVAL

=for apidoc
=for arg member_or_listref reference to the group or a Gtk2::RadioButton belonging to that group.
Assign I<$radio_button> to a new group.
=cut
void
gtk_radio_button_set_group (radio_button, member_or_listref)
	GtkRadioButton * radio_button
	SV             * member_or_listref
    PREINIT:
	GSList         * group = NULL;
	GtkRadioButton * member = NULL;
    CODE:
	if( gperl_sv_is_defined (member_or_listref) )
	{
		if( gperl_sv_is_array_ref (member_or_listref) )
		{
			AV * av = (AV*)SvRV(member_or_listref);
			SV ** svp = av_fetch(av, 0, 0);
			if( svp && gperl_sv_is_defined(*svp) )
			{
				member = SvGtkRadioButton(*svp);
			}
		}
		else
			member = SvGtkRadioButton_ornull(member_or_listref);
		if( member )
			group = member->group;
	}
	gtk_radio_button_set_group(radio_button, group);

# GSList * gtk_radio_button_get_group (GtkRadioButton *radio_button)
=for apidoc
Return a reference to the radio group to which I<$radio_button> belongs.
The group is a reference to an array of widget references; the array is B<not>
magical, that is, it will not be updated automatically if the group changes;
call C<get_group> each time you want to use the group.
=cut
AV *
gtk_radio_button_get_group (radio_button)
	GtkRadioButton * radio_button
    PREINIT:
	GSList * group;
	GSList * i;
    CODE:
	group = gtk_radio_button_get_group (radio_button);
	RETVAL = newAV();
	sv_2mortal ((SV*) RETVAL);  /* typemap expects RETVAL mortalized */
	for( i = group; i ; i = i->next )
	{
		av_push(RETVAL, newSVGtkRadioButton(GTK_RADIO_BUTTON(i->data)));
	}
    OUTPUT:
	RETVAL