2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "vikradiogroup.h"
26 static GObjectClass
*parent_class
;
28 static void radio_group_finalize ( GObject
*gob
);
29 static void radio_group_class_init ( VikRadioGroupClass
*klass
);
31 struct _VikRadioGroup
{
37 GType
vik_radio_group_get_type (void)
39 static GType vrg_type
= 0;
43 static const GTypeInfo vrg_info
=
45 sizeof (VikRadioGroupClass
),
47 NULL
, /* base_finalize */
48 (GClassInitFunc
) radio_group_class_init
, /* class init */
49 NULL
, /* class_finalize */
50 NULL
, /* class_data */
51 sizeof (VikRadioGroup
),
53 NULL
/* instance init */
55 vrg_type
= g_type_register_static ( GTK_TYPE_VBOX
, "VikRadioGroup", &vrg_info
, 0 );
61 static void radio_group_class_init ( VikRadioGroupClass
*klass
)
64 GObjectClass
*object_class
;
66 object_class
= G_OBJECT_CLASS (klass
);
68 object_class
->finalize
= radio_group_finalize
;
70 parent_class
= g_type_class_peek_parent (klass
);
73 GtkWidget
*vik_radio_group_new ( GList
*options
)
78 GList
*option
= options
;
83 vrg
= VIK_RADIO_GROUP ( g_object_new ( VIK_RADIO_GROUP_TYPE
, NULL
) );
85 label
= g_list_nth_data(options
, 0);
86 t
= gtk_radio_button_new_with_label ( NULL
, label
);
87 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(t
), TRUE
);
88 gtk_box_pack_start ( GTK_BOX(vrg
), t
, FALSE
, FALSE
, 0 );
90 vrg
->radios
= g_slist_append ( NULL
, t
);
91 vrg
->options_count
= 1;
93 while ( ( option
= g_list_next(option
) ) != NULL
)
96 t
= gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(vrg
->radios
->data
), label
);
97 vrg
->radios
= g_slist_append( vrg
->radios
, t
);
98 gtk_box_pack_start ( GTK_BOX(vrg
), GTK_WIDGET(t
), FALSE
, FALSE
, 0 );
102 return GTK_WIDGET(vrg
);
105 void vik_radio_group_set_selected ( VikRadioGroup
*vrg
, guint8 i
)
107 if ( i
< vrg
->options_count
)
108 gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(g_slist_nth_data(vrg
->radios
,i
)), TRUE
);
111 guint8
vik_radio_group_get_selected ( VikRadioGroup
*vrg
)
114 GSList
*iter
= vrg
->radios
;
117 if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(iter
->data
) ) )
125 static void radio_group_finalize ( GObject
*gob
)
127 VikRadioGroup
*vrg
= VIK_RADIO_GROUP ( gob
);
129 g_slist_free ( vrg
->radios
);
130 G_OBJECT_CLASS(parent_class
)->finalize(gob
);