1d5ffdc631df5397f9d1cddd3556cc2e5019fe36
[sgt/puzzles] / gtk.c
1 /*
2 * gtk.c: GTK front end for my puzzle collection.
3 */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <stdarg.h>
8
9 #include <gtk/gtk.h>
10
11 #include "puzzles.h"
12
13 /* ----------------------------------------------------------------------
14 * Error reporting functions used elsewhere.
15 */
16
17 void fatal(char *fmt, ...)
18 {
19 va_list ap;
20
21 fprintf(stderr, "fatal error: ");
22
23 va_start(ap, fmt);
24 vfprintf(stderr, fmt, ap);
25 va_end(ap);
26
27 fprintf(stderr, "\n");
28 exit(1);
29 }
30
31 /* ----------------------------------------------------------------------
32 * GTK front end to puzzles.
33 */
34
35 /*
36 * This structure holds all the data relevant to a single window.
37 * In principle this would allow us to open multiple independent
38 * puzzle windows, although I can't currently see any real point in
39 * doing so. I'm just coding cleanly because there's no
40 * particularly good reason not to.
41 */
42 struct window_data {
43 GtkWidget *window;
44 };
45
46 static void destroy(GtkWidget *widget, gpointer data)
47 {
48 gtk_main_quit();
49 }
50
51 static struct window_data *new_window(void)
52 {
53 struct window_data *wdata;
54
55 wdata = snew(struct window_data);
56
57 wdata->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
58 gtk_signal_connect(GTK_OBJECT(wdata->window), "destroy",
59 GTK_SIGNAL_FUNC(destroy), wdata);
60 gtk_widget_show(wdata->window);
61 return wdata;
62 }
63
64 int main(int argc, char **argv)
65 {
66 gtk_init(&argc, &argv);
67 (void) new_window();
68 gtk_main();
69
70 return 0;
71 }