[Gtk-sharp-list] CanvasItems and event handling

Peter Johanson latexer@gentoo.org
Sun, 6 Jun 2004 11:24:55 -0400

Content-Type: multipart/mixed; boundary="cz6wLo+OExbGG7q/"
Content-Disposition: inline

Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

I'm working on an application using Gnome.Canvas, and I'm looking to
have quite a few smaller CanvasItems above a big "base" CanvasItem. The
"base" canvas item i'd like to have receiving all the events, and let
them be handled there. The docs for the gnomecanvas library say the
handler should return false if it wants the parent canvasitem to handle
the event, and AFAIK, this should be done by doing something like:

void OnCanvasEvent(object obj, CanvasEventArgs args) {
	args.RetVal =3D false;

But trying this any events are always caught by the upper-most
CanvasItem... Suggestions? Is this the proper way to get events handed
up the hierarchy?

Attached is a small sample demonstrating the current behavior. Idealy,
we'd see a call from the C.WL in the handler for the rear item no matter
where on the canvas your clicked, moved, etc. Thanks in advance.

Peter Johanson

Key ID =3D 0x6EFA3917
Key fingerprint =3D A90A 2518 57B1 9D20 9B71  A2FF 8649 439B 6EFA 3917

Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="CanvasItemEvents.cs"
Content-Transfer-Encoding: quoted-printable

using System;
using Gdk;
using Gtk;
using Gnome;

class CanvasItemEvents {
	private int width =3D 400, height =3D 400;

	public CanvasItemEvents() {
		Gtk.Window win =3D new Gtk.Window("Canvas Event Test");
		win.DeleteEvent +=3D new DeleteEventHandler(OnWindowDelete);

		VBox vbox =3D new VBox (false, 0);
		win.Add (vbox);

		Canvas canvas =3D new Canvas ();
		canvas.SetSizeRequest (width, height);
		canvas.SetScrollRegion (0.0, 0.0, (double) width, (double) height);
		vbox.PackStart (canvas, false, false, 0);

		CanvasRect rect_back =3D new CanvasRect(canvas.Root());

		rect_back.X1 =3D 0;
		rect_back.Y1 =3D 0;
		rect_back.X2 =3D width;
		rect_back.Y2 =3D height;

		rect_back.FillColor =3D "blue";
		rect_back.CanvasEvent +=3D new CanvasEventHandler(OnCanvasEvent1);

		CanvasRect rect_forward =3D new CanvasRect(canvas.Root());

		rect_forward.X1 =3D width/4;
		rect_forward.Y1 =3D height/4;
		rect_forward.X2 =3D 3 * width/4;
		rect_forward.Y2 =3D 3 * height/4;

		rect_forward.FillColor =3D "red";
		rect_forward.CanvasEvent +=3D new CanvasEventHandler(OnCanvasEvent2);


	void OnCanvasEvent1 (object obj, CanvasEventArgs args) {
		Console.WriteLine("Saw an event in the rear box");
		args.RetVal =3D true;

	void OnCanvasEvent2 (object obj, CanvasEventArgs args) {
		Console.WriteLine("Saw an event in the forward box, trying not to handle =
		args.RetVal =3D false;

	void OnWindowDelete (object obj, DeleteEventArgs args) {
	public static int Main (string[] args)
	{      =20
		Application.Init ();
		CanvasItemEvents example =3D new CanvasItemEvents ();                    =
		Application.Run ();                                                      =
		return 0;


Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.2.4 (GNU/Linux)