Re: Subclassing in Gtk+ 3.0



2009/12/8 A. Walton <awalton gnome org>:
> 2009/12/8 David Nečas <yeti physics muni cz>:
>> On Mon, Dec 07, 2009 at 04:17:40PM -0200, Tristan Van Berkom wrote:
>>> 2009/12/7 David Nečas <yeti physics muni cz>:
>>> >
>>> > Hello, how is subclassing intended to work in Gtk+ 3.0?

> * GSEAL() bridges the gap between 2.9x.x and 3.0 by making it easier
> to port and see where we're missing accessors.
> * Widgets are patched during the 3.0 ABI break so their currently
> public struct members are moved to GtkFooPrivate.
> * g_type_class_add_private() the GtkFooPrivate struct to prevent some
> fragmentation.
> * Add a GtkFooPrivate* to the object's public struct, populate it
> during gtk_foo_init() with
> a single G_TYPE_INSTANCE_GET_PRIVATE() call to speed up access and prevent
> duplicate GtkFooPrivate *priv = G_TYPE_INSTANCE_... lines.
> + roughly as fast as before, low memory overhead
> + code is future-proof and much easier to maintain with proper encapsulation
> - accessors are now mandatory, even for subclasses
> - code's a bit more ugly (when implementing a widget, 'widget->foo' is
> now 'widget->priv->foo').
>
> AFAIK this is the 'state of the art' way to write new GObjects, and
> it's been the way I've been coding for a while (out of habit).
> I believe this is also the way that Vala currently outputs objects.

Yes, this is the actual approach.

FYI, here an example of migration in the 2.90 branch:
http://git.gnome.org/cgit/gtk+/commit/?h=gtk-2-90&id=3451c804c9145cc9f598e6bff0fd8c6aac79923f

Regards


-- 
Javier Jardón Cabezas


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]