[Gtk-sharp-list] Custom cellrenderer

Adam Lofts adam@negligible.co.uk
Sat, 17 Jul 2004 16:28:29 +0100


Hi,

I am trying to implement a custom cellrenderer as follows:

class MyClass {
 ...
}

class MyCellRenderer {
	MyClass TheClass {
		set { ... }
	}
}

class MyWindow {

MyWindow() {
	MyTreeView.AppendColumn( 
			new TreeViewColumn("Channel", 
				new MyCellRenderer, 
				new TreeCellDataFunc (TreeChannelData))
				);
	}

	void TreeChannelData (TreeViewColumn tree_column, CellRenderer cell,
TreeModel tree_model, TreeIter iter) {
		(cell as MyCellRenderer).TheClass = (tree_model.GetValue(iter, 1) as
MyClass);
	}
}

And get the following error:

Unhandled Exception: GLib.MissingIntPtrCtorException: GLib.Object
subclass MyCellRenderer must provide a protected or public IntPtr ctor
to support wrapping of native object handles.
in <0x001e3> GLib.ObjectManager:CreateObject (intptr)
in <0x000e3> GLib.Object:GetObject (intptr,bool)
in <0x00036> Gtk.CellRenderer:GetSize_cb
(intptr,intptr,intptr,intptr,intptr,intptr,intptr)
in <0x000e8> (wrapper native-to-managed) Gtk.CellRenderer:GetSize_cb
(intptr,intptr,intptr,intptr,intptr,intptr,intptr)
in (unmanaged) (wrapper managed-to-native) Gtk.Application:gtk_main ()
in <0x00004> (wrapper managed-to-native) Gtk.Application:gtk_main ()
in <0x00007> Gtk.Application:Run ()

Adding an empty constuctor avoids this error, eg.

protected MyCellRenderer(IntPtr i) {

}

but this seems to create a bug. Also, the sample custom cellrenderer
does not need a IntPtr constructor.

Any help appreciated,

Adam