4 #define EVENT_METHOD(i, x) GTK_WIDGET_GET_CLASS(i)->x
9 /* This routine gets control when the close button is clicked */
10 static gboolean close_application( GtkWidget *widget,
18 /* The main routine */
21 GtkWidget *window, *table, *area, *hrule, *vrule;
23 /* Initialize GTK and create the main window */
24 gtk_init (&argc, &argv);
26 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
27 g_signal_connect (window, "delete-event",
28 G_CALLBACK (close_application), NULL);
29 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
31 /* Create a table for placing the ruler and the drawing area */
32 table = gtk_table_new (3, 2, FALSE);
33 gtk_container_add (GTK_CONTAINER (window), table);
35 area = gtk_drawing_area_new ();
36 gtk_widget_set_size_request (GTK_WIDGET (area), XSIZE, YSIZE);
37 gtk_table_attach (GTK_TABLE (table), area, 1, 2, 1, 2,
38 GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
39 gtk_widget_set_events (area, GDK_POINTER_MOTION_MASK |
40 GDK_POINTER_MOTION_HINT_MASK);
42 /* The horizontal ruler goes on top. As the mouse moves across the
43 * drawing area, a motion_notify_event is passed to the
44 * appropriate event handler for the ruler. */
45 hrule = gtk_hruler_new ();
46 gtk_ruler_set_metric (GTK_RULER (hrule), GTK_PIXELS);
47 gtk_ruler_set_range (GTK_RULER (hrule), 7, 13, 0, 20);
48 g_signal_connect_swapped (area, "motion-notify-event",
49 G_CALLBACK (EVENT_METHOD (hrule,
50 motion_notify_event)),
52 gtk_table_attach (GTK_TABLE (table), hrule, 1, 2, 0, 1,
53 GTK_EXPAND|GTK_SHRINK|GTK_FILL, GTK_FILL, 0, 0);
55 /* The vertical ruler goes on the left. As the mouse moves across
56 * the drawing area, a motion_notify_event is passed to the
57 * appropriate event handler for the ruler. */
58 vrule = gtk_vruler_new ();
59 gtk_ruler_set_metric (GTK_RULER (vrule), GTK_PIXELS);
60 gtk_ruler_set_range (GTK_RULER (vrule), 0, YSIZE, 10, YSIZE );
61 g_signal_connect_swapped (area, "motion-notify-event",
62 G_CALLBACK (EVENT_METHOD (vrule,
63 motion_notify_event)),
65 gtk_table_attach (GTK_TABLE (table), vrule, 0, 1, 1, 2,
66 GTK_FILL, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0);
68 /* Now show everything */
69 gtk_widget_show (area);
70 gtk_widget_show (hrule);
71 gtk_widget_show (vrule);
72 gtk_widget_show (table);
73 gtk_widget_show (window);