GTK's interfaces and language bindings

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

GTK's interfaces and language bindings

Stefan Salewski-2
Recently someone tried to style a widget using CSS,

https://github.com/StefanSalewski/gintro/issues/2#issuecomment-316167963

and so I discovered that there is still some labor for me...

Before I start coding, maybe it is better to verify my understanding of
the gobject interfaces...


For example, we have

https://developer.gnome.org/gtk3/stable/GtkStyleContext.html#gtk-style-context-add-provider

which may be called from C like

gtk_style_context_add_provider(gtk_widget_get_style_context(window),
                                   GTK_STYLE_PROVIDER(cssProvider),
                                   GTK_STYLE_PROVIDER_PRIORITY_USER);

So the second parameter is of type GtkStyleProvider, which is an
interface. GtkCssProvider provides that interface, so we can pass a
variable of that type. GTK_STYLE_PROVIDER() is basically only a cast, a
re-interpretation of the bit pattern, maybe with additional security
checks.

As we generally do not want such casts in higher level languages, we
may just provide an additional function with the same name which
accepts a GtkCssProvider.

For this special case that is clear, and already tested. So I assume,
that for all functions which has interfaces as parameters, I can just
pass all objects (gobjects) which provides that interface?

I even guess hat interfaces are fully abstract entities, so we will
never pass an instance of an interface, but always only objects
providing the interface. So we have only to provide functions which can
accepts all the objects providing the that interface, but we do not
really need functions which would accepts the interface parameter type
itself?

_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GTK's interfaces and language bindings

Nicola Fontana-3
Il Tue, 18 Jul 2017 22:00:52 +0200 Stefan Salewski <[hidden email]> scrisse:

> ...
> So the second parameter is of type GtkStyleProvider, which is an
> interface. GtkCssProvider provides that interface, so we can pass a
> variable of that type. GTK_STYLE_PROVIDER() is basically only a cast, a
> re-interpretation of the bit pattern, maybe with additional security
> checks.

Hi Stefan,

I'll give you my view that will not necessarily match the view of
who wrote GInterface.

Although GTK_STYLE_PROVIDER() is similar to e.g. G_OBJECT(), they
are fundamentally different. While the latter matches exactly your
description (a GtkCssProvider is also a GObject), the former
should be considered only a check.

If you dig enough in that macro you will discover this function:

https://git.gnome.org/browse/glib/tree/gobject/gtype.c?h=2.52.3#n3440

G_OBJECT() is matched by the first branch (support_inheritance)
while GTK_STYLE_PROVIDER() by the second one (support_interfaces).

This difference is purely theorethical though, because
GtkStyleProvider is not even defined. In other words one could
argue that GTK_STYLE_PROVIDER() is a real cast to an undefined
type.

> ...
> So I assume,
> that for all functions which has interfaces as parameters, I can just
> pass all objects (gobjects) which provides that interface?

Yes.

> I even guess hat interfaces are fully abstract entities, so we will
> never pass an instance of an interface, but always only objects
> providing the interface. So we have only to provide functions which can
> accepts all the objects providing the that interface, but we do not
> really need functions which would accepts the interface parameter type
> itself?

Correct. As pointed out before, even in C interface instances are
only dummy typedefs.

I see interfaces as a "contract" that (1) enforces an object
to implement some feature (properties and/or methods) and
consequently (2) gives the users a common API that can be used
across unrelated objects.

Ciao.
--
Nicola
_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GTK's interfaces and language bindings

Stefan Salewski-2
On Thu, 2017-07-20 at 13:44 +0200, Nicola Fontana wrote:
> I see interfaces as a "contract" that (1) enforces an object
> to implement some feature (properties and/or methods) and
> consequently (2) gives the users a common API that can be used
> across unrelated objects.

Thanks for your explanations.

I have just uploaded the extended Nim binding generator -- an example
for styling widgets with CSS is located at the bottom of the README.

https://github.com/StefanSalewski/gintro

http://ssalewski.de/gintroreadme.html

_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Loading...