C stdio trickery for read/write mode
[projects/chimara/chimara.git] / tests / test-multisession.c
1 /* Program for testing multisessionality, i.e. whether two ChimaraGlk widgets
2  can run in the same application. */
3
4 #include <glib.h>
5 #include <gtk/gtk.h>
6 #include <libchimara/chimara-glk.h>
7
8 static void
9 on_started(ChimaraGlk *glk, const gchar *data)
10 {
11     g_printerr("%s started!\n", data);
12 }
13
14 static void
15 on_stopped(ChimaraGlk *glk, const gchar *data)
16 {
17     g_printerr("%s stopped!\n", data);
18 }
19
20 static gboolean
21 on_delete_event(void)
22 {
23         gtk_main_quit();
24         return TRUE;
25 }
26
27 int
28 main(int argc, char **argv)
29 {
30         if( !g_thread_supported() )
31                 g_thread_init(NULL);
32         gdk_threads_init();
33         gtk_init(&argc, &argv);
34
35         GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
36         gtk_widget_set_size_request(window, 800, 500);
37         g_signal_connect(window, "delete_event", G_CALLBACK(on_delete_event), NULL);
38         
39         GtkWidget *hpaned = gtk_hpaned_new();
40         gtk_paned_set_position(GTK_PANED(hpaned), 400);
41         
42         GtkWidget *frotz = chimara_glk_new();
43         chimara_glk_set_css_from_string(CHIMARA_GLK(frotz),
44             "buffer.normal { font-family: 'Lucida Sans'; font-size: 12; }"
45             "grid.normal { font-family: 'Lucida Console'; font-size: 12; }");
46         g_signal_connect(frotz, "started", G_CALLBACK(on_started), "Frotz");
47         g_signal_connect(frotz, "stopped", G_CALLBACK(on_stopped), "Frotz");
48         
49         GtkWidget *nitfol = chimara_glk_new();
50         chimara_glk_set_css_from_string(CHIMARA_GLK(frotz),
51             "buffer.normal { font-family: 'Bitstream Charter'; font-size: 12; }"
52             "grid.normal { font-family: 'Luxi Mono'; font-size: 12; }");
53         g_signal_connect(nitfol, "started", G_CALLBACK(on_started), "Nitfol");
54         g_signal_connect(nitfol, "stopped", G_CALLBACK(on_stopped), "Nitfol");
55
56         gtk_paned_pack1(GTK_PANED(hpaned), frotz, TRUE, TRUE);
57         gtk_paned_pack2(GTK_PANED(hpaned), nitfol, TRUE, TRUE);
58         gtk_container_add(GTK_CONTAINER(window), hpaned);
59
60         gtk_widget_show_all(window);
61
62         if(!chimara_glk_run(CHIMARA_GLK(frotz), "../interpreters/frotz/.libs/frotz.so", argc, argv, NULL))
63                 return 1;
64         if(!chimara_glk_run(CHIMARA_GLK(nitfol), "../interpreters/nitfol/.libs/nitfol.so", argc, argv, NULL))
65                 return 1;
66         
67     gdk_threads_enter();
68         gtk_main();
69         gdk_threads_leave();
70         
71         chimara_glk_stop(CHIMARA_GLK(frotz));
72         chimara_glk_stop(CHIMARA_GLK(nitfol));
73
74         return 0;
75 }
76         
77