Hello,
in the glib/GObject model, when a class is defines with G_DECLARE_DERIVABLE_TYPE(), the macros expand to several other macros, so at the end less code needs to be written. Also struct …ZZZ {ParentName parent_instarce; } is defined and it does not include private data.
The file gtk/a11y/gtkarrowaccessible.h contains:
#define GTK_ARROW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ARROW_ACCESSIBLE, GtkArrowAccessible))
#define GTK_ARROW_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_ARROW_ACCESSIBLE, GtkArrowAccessibleClass))
#define GTK_IS_ARROW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ARROW_ACCESSIBLE))
#define GTK_IS_ARROW_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ARROW_ACCESSIBLE))
#define GTK_ARROW_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ARROW_ACCESSIBLE, GtkArrowAccessibleClass))
typedef struct _GtkArrowAccessible GtkArrowAccessible;
typedef struct _GtkArrowAccessibleClass GtkArrowAccessibleClass;
typedef struct _GtkArrowAccessiblePrivate GtkArrowAccessiblePrivate;
struct _GtkArrowAccessible
{
GtkWidgetAccessible parent;
GtkArrowAccessiblePrivate *priv;
};
struct _GtkArrowAccessibleClass
{
GtkWidgetAccessibleClass parent_class;
};
GDK_AVAILABLE_IN_ALL
GType gtk_arrow_accessible_get_type (void);
Providing that g_autoptr works with GtkArrow, this can be rewritten as:
G_DECLARE_DERIVABLE_TYPE(GtkArrowAccessible, gtk_arrow_accessible, GTK, ARROW_ACCESSIBLE, GtkWidget)
typedef struct _GtkArrowAccessiblePrivate GtkArrowAccessiblePrivate;
struct _GtkArrowAccessibleClass
{
GtkWidgetAccessibleClass parent_class;
};
and _GtkArrowAccessible will not have member priv. To my understanding in this case, all accesses to
GtkArrowAccessibe *arrow=…;
arrow->priv, shall be replaced with
GtkArrowAccessiblePrivate priv = gtk_arrow_accessible_get_instance_private(arrow);
Gtk uses G_DECLARE_DERIVABLE_TYPE only for GtkNativeDialog and G_DECLARE_FINAL_TYPE.
Is there any particular reason why G_DECLARE_DERIVABLE_TYPE and G_DECLARE_FINAL_TYPE are not used more extensively within the gtk codebase, in order to get the code smaller, other the lack of time to rewrite the code?