1 #include <gtk/gtk.h>
2 
3 /* signal handler for "toggled" signal of the CheckButton */
4 static void
toggled_cb(GtkToggleButton * toggle_button,gpointer user_data)5 toggled_cb (GtkToggleButton *toggle_button,
6             gpointer         user_data)
7 {
8   GtkWindow *window = user_data;
9 
10   if (gtk_toggle_button_get_active (toggle_button))
11       gtk_window_set_title (window, "CheckButton Example");
12   else
13       gtk_window_set_title (window, "");
14 }
15 
16 static void
activate(GtkApplication * app,gpointer user_data)17 activate (GtkApplication *app,
18           gpointer        user_data)
19 {
20   GtkWidget *window;
21   GtkWidget *checkbutton;
22 
23   window = gtk_application_window_new (app);
24   gtk_window_set_title (GTK_WINDOW (window), "CheckButton Example");
25   gtk_window_set_default_size (GTK_WINDOW (window), 300, 100);
26 
27   checkbutton = gtk_check_button_new_with_label ("Show Title");
28   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton), TRUE);
29   g_signal_connect (GTK_TOGGLE_BUTTON (checkbutton), "toggled", G_CALLBACK (toggled_cb), window);
30   gtk_container_add (GTK_CONTAINER (window), checkbutton);
31   gtk_widget_show_all (window);
32 }
33 
34 int
main(int argc,char ** argv)35 main (int argc, char **argv)
36 {
37   GtkApplication *app;
38   int status;
39 
40   app = gtk_application_new ("org.example.checkbutton", G_APPLICATION_FLAGS_NONE);
41   g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
42   status = g_application_run (G_APPLICATION (app), argc, argv);
43   g_object_unref (app);
44 
45   return status;
46 }
47