[Gtk-sharp-list] CanvasItems and event handling

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


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


--cz6wLo+OExbGG7q/
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;
	return;
}

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.

-pete
--=20
Peter Johanson
<latexer@gentoo.org>

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

--cz6wLo+OExbGG7q/
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);

		win.ShowAll();
	}

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

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

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


--cz6wLo+OExbGG7q/--

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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAwzdHhklDm276ORcRAqD5AJ9ulZ2xpiqbidd02PMnSIswbEE/IwCg1rhb
2ZVXkQBuNsJCqXT78HsJ7MA=
=KLFj
-----END PGP SIGNATURE-----

--8bBEDOJVaa9YlTAt--