Reference material on GTK+ object system?



Hello,

    I am looking for good reference material on using the GTK+ object
system.  Havoc's book gave me a decent introduction, but doesn't seem
very in depth about actually making full use of the object system (forgive
me if this is just from not reading something I should have in the book).

    My specific task at the moment is to create an abstract class with
various concrete subclasses that actually do the work.  When using these
classes, I would create an instantiation of one of the subclasses, then
would make calls to the abstract class passing it that instantiation.  I
have a working model now, but it seems very kludgy and I'm hoping I can
find documentation on the propery way to do this.

    My current solution is something like this, where the abstract class
is called "FoxAbstract", and the subclass is called "FoxConcrete".  Note
that, in fox_concrete_do_something_real(), I had to use FoxAbstract in
the argument list to match the prototype in the FoxAbstract class.


----  CODE SEGMENT BEGINS  ----

/***    FoxAbstract    ***/

/*  the class structure  */
struct _FoxAbstractClass
{
/*  include the parent class structure  */
    GtkObjectClass parent_class;
/*  methods that must be overridden to provide functionality  */
    void (*method_do_something) (FoxAbstract *fabs)
}


/*  the calling function in the abstract class  */
void
fox_abstract_do_something (FoxAbstract *fabs)
{
    FoxAbstractClass *klass;

    g_return_if_fail (fabs != NULL);
    g_return_if_fail (FOX_IS_ABSTRACT (fabs));

    klass = FOX_ABSTRACT_CLASS( GTK_OBJECT(fabs)->klass );

    if (klass->method_do_something != NULL)
    {
        (*klass->method_do_something) (fabs);
    }
}



/***    FoxConcrete    ***/

/*  the class structure  */
struct _FoxConcreteClass
{
/*  include the parent class structure  */
    FoxAbstractClass parent_class;
}


/*  the class init code, to set up the real method  */
static void
fox_concrete_class_init (FoxConcreteClass *fconc)
{
/*  set up object method handlers  */
    fconc->parent_class.method_do_something = fox_concrete_do_something_real;
}


/*  equivalent calling function to the one in the abstract class  */
#define fox_concrete_do_something(fcon) fox_abstract_do_something (FOX_ABSTRACT(fcon))


/*  the real do_something method  */
void
fox_concrete_do_something (FoxAbstract *fabs)
{
    FoxConcrete *fconc;

    g_return_if_fail (fabs != NULL);
    g_return_if_fail (FOX_IS_CONCRETE (fabs));

    fconc = FOX_CONCRETE (fabs);

/*  do something with fconc here  */
}

----  CODE SEGMENT ENDS  ----





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