]> Pileus Git - ~andy/gtk/blob - tests/widget-factory.c
testgtk: Move paned example from GtkTable to GtkGrid
[~andy/gtk] / tests / widget-factory.c
1 /* widget-factory: a collection of widgets in a single page, for easy
2  *                 theming
3  *
4  * Copyright (C) 2011 Canonical Ltd
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
8  * License  as published  by the Free  Software  Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library 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 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
18  * Software Foundation, Inc., 51  Franklin St, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  *
21  * Authored by Andrea Cimitan <andrea.cimitan@canonical.com>
22  *
23  */
24
25 #include <gtk/gtk.h>
26
27 static void
28 dark_toggled (GtkCheckMenuItem *item, gpointer data)
29 {
30   gboolean dark;
31
32   dark = gtk_check_menu_item_get_active (item);
33   g_object_set (gtk_settings_get_default (),
34                 "gtk-application-prefer-dark-theme", dark,
35                 NULL);
36 }
37
38 int
39 main (int argc, char *argv[])
40 {
41   GtkBuilder *builder;
42   GtkWidget  *window;
43   GtkWidget  *widget;
44   gboolean    dark = FALSE;
45
46   gtk_init (&argc, &argv);
47
48   if (argc > 1 && (g_strcmp0 (argv[1], "--dark") == 0))
49     dark = TRUE;
50
51   builder = gtk_builder_new ();
52   gtk_builder_add_from_file (builder, "./widget-factory.ui", NULL);
53
54   window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
55   gtk_builder_connect_signals (builder, NULL);
56
57   widget = (GtkWidget*) gtk_builder_get_object (builder, "darkmenuitem");
58   g_signal_connect (widget, "toggled", G_CALLBACK (dark_toggled), NULL);
59   gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), dark);
60
61   g_object_unref (G_OBJECT (builder));
62
63   gtk_widget_show (window);
64   gtk_main ();
65
66   return 0;
67 }