Revert "Make HildonCheckButton derive from GtkToggleButton"
[hildon] / examples / hildon-check-button-example.c
1 /*
2  * This file is a part of hildon examples
3  *
4  * Copyright (C) 2008 Nokia Corporation, all rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; version 2.1 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19  * 02110-1301 USA
20  *
21  */
22
23 #include                                        <hildon/hildon.h>
24
25 static void
26 button_toggled_cb                               (HildonCheckButton *button,
27                                                  GtkLabel          *label)
28 {
29     gboolean active = hildon_check_button_get_active (button);
30     const gchar *labeltext = gtk_button_get_label (GTK_BUTTON (button));
31     char *text = g_strconcat (labeltext, active ? " (checked)" : " (unchecked)", NULL);
32     gtk_label_set_text (label, text);
33     g_free (text);
34 }
35
36 int
37 main                                            (int    argc,
38                                                  char **argv)
39 {
40     GtkWidget *win;
41     GtkBox *vbox;
42     GtkWidget *label;
43     GtkWidget *table;
44     int i;
45
46     hildon_gtk_init (&argc, &argv);
47
48     win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
49     vbox = GTK_BOX (gtk_vbox_new (FALSE, 10));
50     table = gtk_table_new (3, 2, TRUE);
51     label = gtk_label_new ("none");
52
53     gtk_table_set_row_spacings (GTK_TABLE (table), 10);
54     gtk_table_set_col_spacings (GTK_TABLE (table), 10);
55
56     gtk_box_pack_start (vbox, gtk_label_new ("Hildon check button example"), TRUE, TRUE, 0);
57
58     for (i = 0; i < 6; i++) {
59         char *text;
60         GtkWidget *button = hildon_check_button_new (HILDON_SIZE_HALFSCREEN_WIDTH | HILDON_SIZE_FINGER_HEIGHT);
61         text = g_strdup_printf ("Button %d", i+1);
62         gtk_button_set_label (GTK_BUTTON (button), text);
63         g_free (text);
64         gtk_table_attach_defaults (GTK_TABLE (table), button, i/2, (i/2) + 1, i%2, (i%2) + 1);
65         g_signal_connect (button, "toggled", G_CALLBACK (button_toggled_cb), label);
66     }
67
68     gtk_box_pack_start (vbox, table, TRUE, TRUE, 0);
69     gtk_box_pack_start (vbox, gtk_label_new ("Last toggled:"), TRUE, TRUE, 0);
70     gtk_box_pack_start (vbox, label, TRUE, TRUE, 0);
71
72     gtk_container_set_border_width (GTK_CONTAINER (win), 20);
73     gtk_container_add (GTK_CONTAINER (win), GTK_WIDGET (vbox));
74
75     g_signal_connect (win, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
76
77     gtk_widget_show_all (win);
78
79     gtk_main ();
80
81     return 0;
82 }