Hi List,

I have problems with triggering several TreeView signals.  I know that
many widgets don't receive lots of signals by default.  I tried to
change that behaviour by manipulatating the event mask using:

tv.Events = EventMask.AllEventsMask; or
tv.AddEvents((int)EventMask.ButtonPressMask);

but none of them worked.

I've modified the GTK# ManagedTreeViewDemo.cs example to try this out
and demonstrate this problem.

ButtonReleaseEvent triggers, but ButtonPressEvent doesn't, even after
manipulating the event mask.  I've both attached and included the code
here.

----8<----

// ManagedTreeViewDemo.cs - Another TreeView demo
//
// Author: Rachel Hestilow <[EMAIL PROTECTED]>
//
// (c) 2003 Rachel Hestilow

namespace GtkSamples {
        using System;
        using System.Runtime.InteropServices;

        using Gtk;
        using Gdk;

        public class TreeViewDemo {
                private static ListStore store = null;
                
                private class Pair {
                        public string a, b;
                        public Pair (string a, string b) {
                                this.a = a;
                                this.b = b;
                        }
                }

                private static void PopulateStore ()
                {
                        store = new ListStore (typeof (Pair));
                        string[] combs = {"foo", "bar", "baz", "quux"};
                        foreach (string a in combs) {
                                foreach (string b in combs) {
                                        store.AppendValues (new Pair (a, b));
                                }
                        }
                }

                private static void CellDataA (Gtk.TreeViewColumn tree_column,
Gtk.CellRenderer cell, Gtk.TreeModel tree_model, Gtk.TreeIter iter)
                {
                        Pair val = (Pair) store.GetValue (iter, 0);
                        ((CellRendererText) cell).Text = val.a;
                }
                
                private static void CellDataB (Gtk.TreeViewColumn tree_column,
Gtk.CellRenderer cell, Gtk.TreeModel tree_model, Gtk.TreeIter iter)
                {
                        Pair val = (Pair) store.GetValue (iter, 0);
                        ((CellRendererText) cell).Text = val.b;
                }
                
                public static void Main (string[] args)
                {
                        Application.Init ();

                        PopulateStore ();

                        Gtk.Window win = new Gtk.Window ("TreeView demo");
                        win.DeleteEvent += new DeleteEventHandler (DeleteCB);
                        win.DefaultWidth = 320;
                        win.DefaultHeight = 480;

                        ScrolledWindow sw = new ScrolledWindow ();
                        win.Add (sw);

                        TreeView tv = new TreeView (store);
                        //tv.Events = EventMask.AllEventsMask;
                        //tv.AddEvents((int)EventMask.ButtonPressMask);
                        tv.ButtonPressEvent += new 
ButtonPressEventHandler(OnButtonPressEvent);
                        tv.ButtonReleaseEvent += new 
ButtonReleaseEventHandler(OnButtonReleaseEvent);
                        tv.HeadersVisible = true;

                        tv.AppendColumn ("One", new CellRendererText (), new
TreeCellDataFunc (CellDataA));
                        tv.AppendColumn ("Two", new CellRendererText (), new
TreeCellDataFunc (CellDataB));

                        sw.Add (tv);
                        win.ShowAll ();

                        Application.Run ();
                }

                public static void OnButtonPressEvent(object o, 
ButtonPressEventArgs args)
                {
                    Console.WriteLine("Button pressed.");
                }

                public static void OnButtonReleaseEvent(object o, 
ButtonReleaseEventArgs args)
                {
                    Console.WriteLine("Button released.");
                }

                private static void DeleteCB (System.Object o, DeleteEventArgs 
args)
                {
                        Application.Quit ();
                }
        }
}

----8<----

Anyone could drop some knowledge on this issue?

Thanks in advance!

--
Laci

    Blog: http://monda.hu/~laci/blog
    Home: http://mondalaci.objectis.net
// ManagedTreeViewDemo.cs - Another TreeView demo
//
// Author: Rachel Hestilow <[EMAIL PROTECTED]>
//
// (c) 2003 Rachel Hestilow

namespace GtkSamples {
	using System;
	using System.Runtime.InteropServices;

	using Gtk;
	using Gdk;

	public class TreeViewDemo {
		private static ListStore store = null;
		
		private class Pair {
			public string a, b;
			public Pair (string a, string b) {
				this.a = a;
				this.b = b;
			}
		}

		private static void PopulateStore ()
		{
			store = new ListStore (typeof (Pair));
			string[] combs = {"foo", "bar", "baz", "quux"};
			foreach (string a in combs) {
				foreach (string b in combs) {
					store.AppendValues (new Pair (a, b));
				}
			}
		}

		private static void CellDataA (Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel tree_model, Gtk.TreeIter iter)
		{
			Pair val = (Pair) store.GetValue (iter, 0);
			((CellRendererText) cell).Text = val.a;
		}
		
		private static void CellDataB (Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel tree_model, Gtk.TreeIter iter)
		{
			Pair val = (Pair) store.GetValue (iter, 0);
			((CellRendererText) cell).Text = val.b;
		}
		
		public static void Main (string[] args)
		{
			Application.Init ();

			PopulateStore ();

			Gtk.Window win = new Gtk.Window ("TreeView demo");
			win.DeleteEvent += new DeleteEventHandler (DeleteCB);
			win.DefaultWidth = 320;
			win.DefaultHeight = 480;

			ScrolledWindow sw = new ScrolledWindow ();
			win.Add (sw);

			TreeView tv = new TreeView (store);
			//tv.Events = EventMask.AllEventsMask;
			//tv.AddEvents((int)EventMask.ButtonPressMask);
			tv.ButtonPressEvent += new ButtonPressEventHandler(OnButtonPressEvent);
			tv.ButtonReleaseEvent += new ButtonReleaseEventHandler(OnButtonReleaseEvent);
			tv.HeadersVisible = true;

			tv.AppendColumn ("One", new CellRendererText (), new TreeCellDataFunc (CellDataA));
			tv.AppendColumn ("Two", new CellRendererText (), new TreeCellDataFunc (CellDataB));

			sw.Add (tv);
			win.ShowAll ();

			Application.Run ();
		}

		public static void OnButtonPressEvent(object o, ButtonPressEventArgs args)
		{
		    Console.WriteLine("Button pressed.");
		}

		public static void OnButtonReleaseEvent(object o, ButtonReleaseEventArgs args)
		{
		    Console.WriteLine("Button released.");
		}

		private static void DeleteCB (System.Object o, DeleteEventArgs args)
		{
			Application.Quit ();
		}
	}
}

_______________________________________________
Gtk-sharp-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Reply via email to