diff options
author | Shawn Amundson <amundson@src.gnome.org> | 1998-03-31 23:43:49 +0000 |
---|---|---|
committer | Shawn Amundson <amundson@src.gnome.org> | 1998-03-31 23:43:49 +0000 |
commit | c36ca76bb84879ed1e2ba51541c95eacd56e550e (patch) | |
tree | 8a01644357246180f22165e28d7f0cdf8cf67afe /examples/rulers | |
parent | 30f22e0208593dba5ca5d3b824d8d03519414296 (diff) | |
download | gtk+-c36ca76bb84879ed1e2ba51541c95eacd56e550e.tar.gz |
Tue Mar 31 15:41:57 PST 1998 Shawn T. Amundson
* Makefile.am:
* examples/*: added the rest of the tutorial examples
Diffstat (limited to 'examples/rulers')
-rw-r--r-- | examples/rulers/Makefile | 8 | ||||
-rw-r--r-- | examples/rulers/rulers.c | 75 |
2 files changed, 83 insertions, 0 deletions
diff --git a/examples/rulers/Makefile b/examples/rulers/Makefile new file mode 100644 index 0000000000..f304afcd9b --- /dev/null +++ b/examples/rulers/Makefile @@ -0,0 +1,8 @@ + +CC = gcc + +rulers: rulers.c + $(CC) `gtk-config --cflags` `gtk-config --libs` rulers.c -o rulers + +clean: + rm -f *.o rulers diff --git a/examples/rulers/rulers.c b/examples/rulers/rulers.c new file mode 100644 index 0000000000..ebefa14776 --- /dev/null +++ b/examples/rulers/rulers.c @@ -0,0 +1,75 @@ +/* This file extracted from the GTK tutorial. */ + +/* rulers.c */ + +#include <gtk/gtk.h> + +#define EVENT_METHOD(i, x) GTK_WIDGET_CLASS(GTK_OBJECT(i)->klass)->x + +#define XSIZE 600 +#define YSIZE 400 + +/* this routine gets control when the close button is clicked + */ +void close_application( GtkWidget *widget, gpointer *data ) { + gtk_main_quit(); +} + + +/* the main routine + */ +int main( int argc, char *argv[] ) { + GtkWidget *window, *table, *area, *hrule, *vrule; + + /* initialize gtk and create the main window */ + gtk_init( &argc, &argv ); + + window = gtk_window_new( GTK_WINDOW_TOPLEVEL ); + gtk_signal_connect (GTK_OBJECT (window), "delete_event", + GTK_SIGNAL_FUNC( close_application ), NULL); + gtk_container_border_width (GTK_CONTAINER (window), 10); + + /* create a table for placing the ruler and the drawing area */ + table = gtk_table_new( 3, 2, FALSE ); + gtk_container_add( GTK_CONTAINER(window), table ); + + area = gtk_drawing_area_new(); + gtk_drawing_area_size( (GtkDrawingArea *)area, XSIZE, YSIZE ); + gtk_table_attach( GTK_TABLE(table), area, 1, 2, 1, 2, + GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0 ); + gtk_widget_set_events( area, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK ); + + /* The horizontal ruler goes on top. As the mouse moves across the drawing area, + a motion_notify_event is passed to the appropriate event handler for the ruler. */ + hrule = gtk_hruler_new(); + gtk_ruler_set_metric( GTK_RULER(hrule), GTK_PIXELS ); + gtk_ruler_set_range( GTK_RULER(hrule), 7, 13, 0, 20 ); + gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event", + (GtkSignalFunc)EVENT_METHOD(hrule, motion_notify_event), + GTK_OBJECT(hrule) ); + /* GTK_WIDGET_CLASS(GTK_OBJECT(hrule)->klass)->motion_notify_event, */ + gtk_table_attach( GTK_TABLE(table), hrule, 1, 2, 0, 1, + GTK_EXPAND|GTK_SHRINK|GTK_FILL, GTK_FILL, 0, 0 ); + + /* The vertical ruler goes on the left. As the mouse moves across the drawing area, + a motion_notify_event is passed to the appropriate event handler for the ruler. */ + vrule = gtk_vruler_new(); + gtk_ruler_set_metric( GTK_RULER(vrule), GTK_PIXELS ); + gtk_ruler_set_range( GTK_RULER(vrule), 0, YSIZE, 10, YSIZE ); + gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event", + (GtkSignalFunc) + GTK_WIDGET_CLASS(GTK_OBJECT(vrule)->klass)->motion_notify_event, + GTK_OBJECT(vrule) ); + gtk_table_attach( GTK_TABLE(table), vrule, 0, 1, 1, 2, + GTK_FILL, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0 ); + + /* now show everything */ + gtk_widget_show( area ); + gtk_widget_show( hrule ); + gtk_widget_show( vrule ); + gtk_widget_show( table ); + gtk_widget_show( window ); + gtk_main(); + + return 0; +} |