Re: radio_button behavior with toggle_button style ?
- From: Alain D'EURVEILHER <deurveia esiee fr>
- To: gtk-list gnome org
- Subject: Re: radio_button behavior with toggle_button style ?
- Date: Sat, 10 Jan 2004 15:13:47 +0100
I tried but... i cannot make it do what i want...
AlaiN.
Le Samedi 10 Janvier 2004 10:31, Olexiy Avramchenko a écrit :
> Alain D'EURVEILHER wrote:
> >Hi,
> >
> >Is it possible to make a group of toggle button, but behavioring as the
> >radiobuttons ??
> >
> >Here it is... : have for example 3 toggle_button and, pressing one down
> >release (up) the other ones...
>
> Hello, here's one of the possible solutions:
>
> static void button_toggled(GtkToggleButton *toggle, GSlist **list)
> {
> GSlist *node;
>
> g_return_if_fail(*list != NULL); /* this is for debugging only */
>
> if (!toggle->active) /* skip the code below if button is depressed
> */ return;
>
> for (node=*list; node!=NULL; node=node->next)
> if (node->data != toggle) /* iterate through the list and
> deactivate all buttons other than pressed */
>
> gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON((*list)->data), FALSE);
> }
>
> /* helper function, saves some lines of code */
> static GtkWidget *toggle_new(GSList **list, const gchar *label)
> {
> GtkWidget *button;
>
> button = gtk_toggle_button_new_with_label(label);
> g_signal_connect(button, "toggle", G_CALLBACK(button_toggled), list);
> *list = g_slist_prepend(*list, button); /* adding button to the
> list (prepend is faster than append) */
> }
>
> void setup()
> {
> GtkWidget *button1, *button2, *button3;
> static GSList *list; /* this var SHOULD be static */
>
> /* creating 3 widgets */
> button1 = toggle_new(&list, "toggle 1");
> button2 = toggle_new(&list, "toggle 2");
> button3 = toggle_new(&list, "toggle 3");
> }
>
> PS: I just typed some C lines here, so some typos/bugs can be found
>
> Olexiy
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]