1 /* This file extracted from the GTK tutorial. */
7 #define EVENT_METHOD(i, x) GTK_WIDGET_CLASS(GTK_OBJECT(i)->klass)->x
12 /* this routine gets control when the close button is clicked
14 void close_application( GtkWidget *widget, GdkEvent *event, gpointer *data ) {
21 int main( int argc, char *argv[] ) {
22 GtkWidget *window, *table, *area, *hrule, *vrule;
24 /* initialize gtk and create the main window */
25 gtk_init( &argc, &argv );
27 window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
28 gtk_signal_connect (GTK_OBJECT (window), "delete_event",
29 GTK_SIGNAL_FUNC( close_application ), NULL);
30 gtk_container_border_width (GTK_CONTAINER (window), 10);
32 /* create a table for placing the ruler and the drawing area */
33 table = gtk_table_new( 3, 2, FALSE );
34 gtk_container_add( GTK_CONTAINER(window), table );
36 area = gtk_drawing_area_new();
37 gtk_drawing_area_size( (GtkDrawingArea *)area, XSIZE, YSIZE );
38 gtk_table_attach( GTK_TABLE(table), area, 1, 2, 1, 2,
39 GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0 );
40 gtk_widget_set_events( area, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK );
42 /* The horizontal ruler goes on top. As the mouse moves across the drawing area,
43 a motion_notify_event is passed to the appropriate event handler for the ruler. */
44 hrule = gtk_hruler_new();
45 gtk_ruler_set_metric( GTK_RULER(hrule), GTK_PIXELS );
46 gtk_ruler_set_range( GTK_RULER(hrule), 7, 13, 0, 20 );
47 gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event",
48 (GtkSignalFunc)EVENT_METHOD(hrule, motion_notify_event),
50 /* GTK_WIDGET_CLASS(GTK_OBJECT(hrule)->klass)->motion_notify_event, */
51 gtk_table_attach( GTK_TABLE(table), hrule, 1, 2, 0, 1,
52 GTK_EXPAND|GTK_SHRINK|GTK_FILL, GTK_FILL, 0, 0 );
54 /* The vertical ruler goes on the left. As the mouse moves across the drawing area,
55 a motion_notify_event is passed to the appropriate event handler for the ruler. */
56 vrule = gtk_vruler_new();
57 gtk_ruler_set_metric( GTK_RULER(vrule), GTK_PIXELS );
58 gtk_ruler_set_range( GTK_RULER(vrule), 0, YSIZE, 10, YSIZE );
59 gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event",
61 GTK_WIDGET_CLASS(GTK_OBJECT(vrule)->klass)->motion_notify_event,
63 gtk_table_attach( GTK_TABLE(table), vrule, 0, 1, 1, 2,
64 GTK_FILL, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0 );
66 /* now show everything */
67 gtk_widget_show( area );
68 gtk_widget_show( hrule );
69 gtk_widget_show( vrule );
70 gtk_widget_show( table );
71 gtk_widget_show( window );