No need to include empty default signal handlers
[projects/chimara/chimara.git] / tests / csstest.c
1 #include <gtk/gtk.h>
2 #include <libchimara/chimara-glk.h>
3
4 /* This is a test program for CSS styling of the Glk program, which is not
5 implemented so far. */
6
7 /* Style the GUI funky */
8 void
9 style1(GtkButton *button, GtkStyleProvider *funky_provider)
10 {
11         gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), funky_provider, GTK_STYLE_PROVIDER_PRIORITY_USER);
12 }
13
14 /* Style the GUI nicely */
15 void
16 style2(GtkButton *button, GtkStyleProvider *funky_provider)
17 {
18         gtk_style_context_remove_provider_for_screen(gdk_screen_get_default(), funky_provider);
19 }
20
21 int
22 main(int argc, char **argv)
23 {
24         gdk_threads_init();
25         gtk_init(&argc, &argv);
26
27         /* Create widgets */
28         GtkWidget *win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
29         GtkWidget *grid = gtk_grid_new();
30         GtkWidget *glk = chimara_glk_new();
31         GtkWidget *stylebutton1 = gtk_button_new_with_label("Style 1");
32         GtkWidget *stylebutton2 = gtk_button_new_with_label("Style 2");
33         GtkCssProvider *funky_provider = gtk_css_provider_new();
34
35         /* Set properties on widgets */
36         gtk_widget_set_size_request(win, 400, 400);
37         g_object_set(glk, "expand", TRUE, NULL);
38         GError *error = NULL;
39         gboolean res = gtk_css_provider_load_from_data(funky_provider,
40                 ".glk grid {"
41                 "  font-size: 14;"
42                 "  color: #303030;"
43                 "  font-family: \"Andale Mono\";"
44                 "}\n"
45                 ".glk buffer {"
46                 "  color: #303030;"
47                 "  font-size: 14;"
48                 "  margin-bottom: 5px;"
49                 "  font-family: \"Book Antiqua\";"
50                 "}\n"
51                 ".glk buffer.header { font-weight: bold; }\n"
52                 ".glk buffer.alert {"
53                 "  color: #aa0000;"
54                 "  font-weight: bold;"
55                 "}\n"
56                 ".glk buffer.note {"
57                 "  color: #aaaa00;"
58                 "  font-weight: bold;"
59                 "}\n"
60                 ".glk buffer.block-quote {"
61                 "  /*text-align: center;*/"
62                 "  font-style: italic;"
63                 "}\n"
64                 ".glk buffer.input {"
65                 "  color: #0000aa;"
66                 "  font-style: italic;"
67                 "}\n"
68                 ".glk blank { background-color: #4e702a; }\n"
69                 ".glk graphics {"
70                 "  background-image: -gtk-gradient(linear, 0 0, 0 1,"
71                 "       color-stop(0, @yellow),"
72                 "   color-stop(0.2, @blue),"
73                 "   color-stop(1, #0f0));"
74                 "}",
75                 -1, &error);
76         if(!res)
77                 g_printerr("Error: %s\n", error->message);
78
79         /* Put widgets together */
80         gtk_grid_attach(GTK_GRID(grid), stylebutton1, 0, 0, 1, 1);
81         gtk_grid_attach_next_to(GTK_GRID(grid), stylebutton2, NULL, GTK_POS_RIGHT, 1, 1);
82         gtk_grid_attach(GTK_GRID(grid), glk, 0, 1, 2, 1);
83         gtk_container_add(GTK_CONTAINER(win), grid);
84
85         /* Connect signals */
86         g_signal_connect(win, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
87         g_signal_connect(stylebutton1, "clicked", G_CALLBACK(style1), funky_provider);
88         g_signal_connect(stylebutton2, "clicked", G_CALLBACK(style2), funky_provider);
89
90         /* Go! */
91         gtk_widget_show_all(win);
92         g_object_ref(glk);
93         char *plugin_argv[] = { "styletest" };
94         chimara_glk_run(CHIMARA_GLK(glk), ".libs/styletest.so", 1, plugin_argv, NULL);
95
96         gdk_threads_enter();
97         gtk_main();
98         gdk_threads_leave();
99
100         chimara_glk_stop(CHIMARA_GLK(glk));
101         chimara_glk_wait(CHIMARA_GLK(glk));
102         g_object_unref(glk);
103         g_object_unref(funky_provider);
104         return 0;
105 }