On Thu, 6 Sep 2018 23:10:24 +0200, Mike Wey wrote:
On 9/6/18 8:29 PM, Russel Winder wrote:
[…]
The problem is that GtkBuilder doesn't instantiate a new
PresentationTreeView
but only aTreeView
.
And as it should really, that is what is in the Glade file. :-)
One way around this is to make the
PresentationTreeView
a proper Gtk
class by using gtkd.Implement.ImplementClass, and then usePresentationTreeView
in the builder file.The type name would be the fully qualified name in pascal case, and you
would need to callPresentationTreeView.getType()
atleast once before
using GtkBuilder.
Whilst this has a great appeal, I suspect Glade itself would have problems with this, it would require using TreeView
in Glade and then editing after the fact. Feasible certainly, but annoying.
As for workarounds you could add a constructor to
PresentationTreeView
that passes the gtk handle from the treeview tosuper
.
I initially started down this road but wasn't sure what to actually put in the constructor to avoid having an extra field.
Or add this to
PresentationTreeView
://Should be the first field in the class. protected GtkTreeView* handle; public static GType getType() { return TreeView.getType(); } public this (GtkTreeView* gtkTreeView, bool ownedRef = false) { this.gtkTreeView = gtkTreeView; super(cast(GtkContainer*)gtkTreeView, ownedRef); }
With that in place the opCast defined for ObjectG should recognize you
class as one that is part of GtkD/Gtk and allow you to cast the TreeView
to it.
So this makes the PresentationTreeView
masquerade as a TreeView
as far as GtkD is concerned?
I guess having the explicit extra field is something I am not immediately comfortable with, but mostly as I am a beginner at this.
I do have a need to instantiate PresentationTreeView
explicitly as well as having this one Gtk.Builder instantiated one. This leads me back to the simpler form of constructor workaround which I think avoids having the getType()
and the extra field.
Thanks for taking the time to answer this so fully, it really is very much appreciated.