[Gtk-sharp-list] events and TextView/Buffer

Lee Mallabone gnome@fonicmonkey.net
09 Sep 2002 18:00:17 +0100

Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Sun, 2002-09-08 at 18:36, Miguel de Icaza wrote:
> > and then I try and hook in the event handler with:
> > 
> > view.InsertAtCursor += new InsertAtCursorHandler(TextWasInserted);
> > 
> > However, nothing happens. Should this work? Is this the wrong approach?
> > I've tried similar things and attempted event handling on the TextBuffer
> > as well, but events on the TextBuffer give Glib-GObject-CRITICAL
> > messages on the console.
> Please provide more information about the error.


Nothing at all happens when I have an InsertAtCursorHandler (seemingly)
connected, so it's difficult to describe in more detail. When I have a
Changed handler connected to the TextBuffer I get:

(test-text:1515): GLib-GObject-WARNING **: invalid (NULL) pointer

(test-text:1515): GLib-GObject-CRITICAL **: file gsignal.c: line 1601
(g_signal_connect_data): assertion `G_TYPE_CHECK_INSTANCE (instance)'

on the console.

I've attached a small test case that demonstrates the problem on my
machine. I've tested against mono 0.15, gtk-sharp 0.4 and the problems
I've described occur. I compiled it with:

 mcs  -o test.exe testTextevents.cs -r glib-sharp.dll -r pango-sharp.dll
-r atk-sharp.dll -r gdk-sharp.dll -r gtk-sharp.dll -r art-sharp.dll -r

To get the warnings to appear I just have to run it.

> I believe this is invoked only when you call the functions from the C
> code.  What are you trying to do? 
> My guess is that you want the "changed" signal, and not really the
> insert one.

All I really wanted to do was detect what the user has just typed into a
text widget, and depending on what they typed, insert text
automatically. It sounded like the InsertAtCursor event would be just


Lee Mallabone.

Content-Disposition: attachment; filename=testTextevents.cs
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=testTextevents.cs; charset=ANSI_X3.4-1968

using System;
using Gtk;
using GtkSharp;
using Gnome;
using Pango;

public class testTextevents : App
    private TextView view;
    private TextBuffer buffer;
    private void TextWasInserted(object sender, InsertAtCursorArgs e)
     	Console.WriteLine("Insert Event handled");

    private void TextChanged(object sender, EventArgs e)
     	Console.WriteLine("Standard Event handled");
    public testTextevents(): base ("text-test", "Test of textview/buffer ev=
ent handling")
     	ScrolledWindow scroller =3D new ScrolledWindow();
	buffer =3D new TextBuffer();
	view =3D new TextView(buffer);
	view.Indent =3D 10;
//	view.InsertAtCursor +=3D new InsertAtCursorHandler(TextWasInserted);
	buffer.Changed +=3D new EventHandler(TextChanged);
	FontDescription editorFont =3D FontDescription.FromString("Sans Italic 48"=
	if (editorFont !=3D null)
	 	Console.WriteLine("Setting font...");
	Contents =3D scroller;

   public static int Main (string[] args)
	Program ed =3D new Program("test-text", "0.1",
				 Modules.UI, args);
	new testTextevents().ShowAll();

	return 0;