1 /* example-start rulers rulers.c */
5 #define EVENT_METHOD(i, x) GTK_WIDGET_CLASS(GTK_OBJECT(i)->klass)->x
10 /* This routine gets control when the close button is clicked */
11 void close_application( GtkWidget *widget, GdkEvent *event, gpointer data ) {
15 /* The main routine */
16 int main( int argc, char *argv[] ) {
17 GtkWidget *window, *table, *area, *hrule, *vrule;
19 /* Initialize GTK and create the main window */
20 gtk_init( &argc, &argv );
22 window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
23 gtk_signal_connect (GTK_OBJECT (window), "delete_event",
24 GTK_SIGNAL_FUNC( close_application ), NULL);
25 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
27 /* Create a table for placing the ruler and the drawing area */
28 table = gtk_table_new( 3, 2, FALSE );
29 gtk_container_add( GTK_CONTAINER(window), table );
31 area = gtk_drawing_area_new();
32 gtk_drawing_area_size( (GtkDrawingArea *)area, XSIZE, YSIZE );
33 gtk_table_attach( GTK_TABLE(table), area, 1, 2, 1, 2,
34 GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0 );
35 gtk_widget_set_events( area, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK );
37 /* The horizontal ruler goes on top. As the mouse moves across the drawing area,
38 * a motion_notify_event is passed to the appropriate event handler for the ruler. */
39 hrule = gtk_hruler_new();
40 gtk_ruler_set_metric( GTK_RULER(hrule), GTK_PIXELS );
41 gtk_ruler_set_range( GTK_RULER(hrule), 7, 13, 0, 20 );
42 gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event",
43 (GtkSignalFunc)EVENT_METHOD(hrule, motion_notify_event),
45 /* GTK_WIDGET_CLASS(GTK_OBJECT(hrule)->klass)->motion_notify_event, */
46 gtk_table_attach( GTK_TABLE(table), hrule, 1, 2, 0, 1,
47 GTK_EXPAND|GTK_SHRINK|GTK_FILL, GTK_FILL, 0, 0 );
49 /* The vertical ruler goes on the left. As the mouse moves across the drawing area,
50 * a motion_notify_event is passed to the appropriate event handler for the ruler. */
51 vrule = gtk_vruler_new();
52 gtk_ruler_set_metric( GTK_RULER(vrule), GTK_PIXELS );
53 gtk_ruler_set_range( GTK_RULER(vrule), 0, YSIZE, 10, YSIZE );
54 gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event",
56 GTK_WIDGET_CLASS(GTK_OBJECT(vrule)->klass)->motion_notify_event,
58 gtk_table_attach( GTK_TABLE(table), vrule, 0, 1, 1, 2,
59 GTK_FILL, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0 );
61 /* Now show everything */
62 gtk_widget_show( area );
63 gtk_widget_show( hrule );
64 gtk_widget_show( vrule );
65 gtk_widget_show( table );
66 gtk_widget_show( window );