I'm trying to implement a Gtk.StyleProvider
in Vala. The "base class" (in C) looks like:
GtkIconFactory * gtk_style_provider_get_icon_factory ()
GtkStyleProperties * gtk_style_provider_get_style ()
gboolean gtk_style_provider_get_style_property ()
and in VAPI:
[CCode (cheader_filename = "gtk/gtk.h")]
public interface StyleProvider {
public abstract unowned Gtk.IconFactory get_icon_factory (Gtk.WidgetPath path);
public abstract unowned Gtk.StyleProperties get_style (Gtk.WidgetPath path);
public abstract bool get_style_property (Gtk.WidgetPath path, Gtk.StateFlags state, GLib.ParamSpec pspec, GLib.Value value);
}
Where the first two methods should only return NULL
according to the documentation for GtkStyleProvider
.
Thus, I wrote some Vala like this:
public class DerivedStyleProvider : Gtk.StyleProvider
{
public Gtk.IconFactory? get_icon_factory (Gtk.WidgetPath path)
{
return null;
}
public Gtk.StyleProperties? get_style (Gtk.WidgetPath path)
{
return null;
}
bool get_style_property (Gtk.WidgetPath path,
Gtk.StateFlags state,
GLib.ParamSpec pspec,
out GLib.Value value)
{
return false; //TODO
}
}
I have a problem with the first two methods. If I have them as written here (with a ?
), then I get the following error:
error: overriding method `DerivedStyleProvider.get_icon_factory' is incompatible
with base method `Gtk.StyleProvider.get_icon_factory': Base method expected
return type `Gtk.IconFactory', but `Gtk.IconFactory?' was provided.
public Gtk.IconFactory? get_icon_factory (Gtk.WidgetPath path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The gtk_style_provider_get_style()
method is the same.
If I remove the ?
, I get the following two errors per method:
error: overriding method `DerivedsStyleProvider.get_icon_factory'
is incompatible with base method `Gtk.StyleProvider.get_icon_factory': Base
method expected return type `Gtk.IconFactory', but `Gtk.IconFactory' was provided.
public Gtk.IconFactory get_icon_factory (Gtk.WidgetPath path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/Preferences.vala:138.3-138.14: warning: `null' incompatible with
return type `Gtk.IconFactory`
return null;
^^^^^^^^^^^
The first error especially is a bit strange to me, as the upshot is "error: expected TYPE, got TYPE"!
Adding unowned
to the first two methods still results in similar errors.
How should I implement a Gtk.StyleProvider
interface in Vala?
This compiles without errors or warnings on my system (Vala 0.32.1):
I made these changes:
GLib.Object
in addition to the interface.unowned
on the first method.