Re: how are interfaces created? (talking about the Java-like "interface")
- From: Jean Bréfort <jean brefort normalesup org>
- To: Ben Johnson <ben blarg net>
- Cc: gtk-list gnome org
- Subject: Re: how are interfaces created? (talking about the Java-like "interface")
- Date: Sat, 29 Jan 2005 19:47:08 +0100
Le samedi 29 janvier 2005 �0:10 -0800, Ben Johnson a �it :
> On Sat, Jan 29, 2005 at 08:27:55AM +0100, Jean Br?fort wrote:
> > Le vendredi 28 janvier 2005 ?? 15:22 -0800, Ben Johnson a ??crit :
> > > I want to understand how interfaces are defined and used/implemented.
> ...
> >
> > 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,
>
> It does help *very* much. Thank you. I hope you don't answering a
> couple questions.
>
> Once an object of GnomeCanvasGroupExtClass is instantiated, can it be
> cast as something else having to do with the print_info (Printable?)?
> How is that done? And, when the cast is performed, what functionality
> is exposed?
Yes, you can cast it either to a GPrintable or a GnomeCanvasExtGroup. As
a sample, I reproduce the function which prints the group:
void gnome_canvas_group_ext_print (GPrintable *printable,
GnomePrintContext *pc)
{
GList *list;
double affine[6];
GnomeCanvasItem *item;
g_return_if_fail (GNOME_IS_CANVAS_GROUP_EXT (printable));
for (list = GNOME_CANVAS_GROUP (printable) ->item_list; list; list =
list->next) {
item = GNOME_CANVAS_ITEM (list->data);
if (!(item->object.flags & GNOME_CANVAS_ITEM_VISIBLE))
continue;
if (GNOME_IS_CANVAS_GROUP_EXT(item))
gnome_canvas_group_ext_print (G_PRINTABLE (item), pc);
else if (G_IS_PRINTABLE (item))
{
gnome_canvas_item_i2w_affine (item, affine);
gnome_print_gsave(pc);
gnome_print_concat(pc, affine);
g_printable_print (G_PRINTABLE (item), pc);
gnome_print_grestore(pc);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]