Re: how are interfaces created? (talking about the Java-like "interface")



Le vendredi 28 janvier 2005 �5:22 -0800, Ben Johnson a �it :
> I want to understand how interfaces are defined and used/implemented.
> The docs say, for instance:
> 
> "GtkButton implements AtkImplementorIface"
> 
> Is AtkImplementorIface a real thing?  How does the GtkButton implement
> it?  I haven't been able to find docs about this.  Can someone point me
> in the right direction?  Are interfaces often or ever defined by GTK+
> users like me?

It's a GInterface object. When creating a new class of object, you
derive it from an existing class and you can add one or several
interfaces to enrich your class.
Here is a sample code I used to add printing support to the gnome canvas
(this code is used by GChemPaint).

GType
gnome_canvas_group_ext_get_type (void)
{
	static GType group_ext_type;

	if (!group_ext_type) {
		static const GTypeInfo object_info = {
			sizeof (GnomeCanvasGroupExtClass),
			(GBaseInitFunc) NULL,
			(GBaseFinalizeFunc) NULL,
			(GClassInitFunc) gnome_canvas_group_ext_class_init,
			(GClassFinalizeFunc) NULL,
			NULL,			/* class_data */
			sizeof (GnomeCanvasGroupExt),
			0,			/* n_preallocs */
			(GInstanceInitFunc) gnome_canvas_group_ext_init,
			NULL			/* value_table */
		};

		static const GInterfaceInfo print_info = {
			(GInterfaceInitFunc) gnome_canvas_group_print_init,
			NULL, NULL
		};

		group_ext_type = g_type_register_static (GNOME_TYPE_CANVAS_GROUP_EXT,
"GnomeCanvasGroupExt",
						    &object_info, 0);

		g_type_add_interface_static (group_ext_type, G_TYPE_PRINTABLE,
&print_info);
	}

	return group_ext_type;
}

Hope this helps,

Best regards,
Jean




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