[Previous] [Contents] [Index] [Next]

PtCreateWidgetClass()

Create a widget class

Synopsis:

PtWidgetClass_t *PtCreateWidgetClass( 
                   PtWidgetClassRef_t *superclass_ref, 
                   unsigned int size, 
                   unsigned int num_args, 
                   PtArg_t const *args );

Description:

This function creates a new widget class based on superclass_ref. If the specified superclass hasn't yet been created, it's created now.

The arguments are as follows:

superclass_ref
The class reference of the superclass this class is to be a subclass of.
size
The size of the new widget class. If this is 0, the size of the superclass is used; if nonzero, it must be at least as large as the superclass.
num_args
The number of entries in the arg array.
args
The array of class attributes and member functions to be applied when creating the new class.

If the size parameter is zero, the new class is the same size as the specified superclass. Otherwise size bytes are allocated for the new class. The specified superclass is then copied into the newly allocated class (inheritance). The version, resources, num_resources, callbacks, dflts_f, connect_f, init_f, unrealize_f, and destroy_f members are cleared because they shouldn't be inherited.

Returns:

A pointer to the newly created class:

base->superclass = superclass ? superclass->wclass:NULL;

Examples:

This example is from the ShadowedBox sample widget.

//
// ShadowedBox class-creation function
//
PtWidgetClass_t *PtCreateBasicClass( void )
{
    static const PtResourceRec_t resources[] = 
    {
    {   SBW_SHADOW_COLOR, Pt_CHANGE_REDRAW, 0,    
        Pt_ARG_IS_NUMBER( ShadowedBoxWidget, shadow_color ) },
    {   SBW_SHADOW_OFFSET, Pt_CHANGE_REDRAW, 0, 
        Pt_ARG_IS_NUMBER( ShadowedBoxWidget, shadow_offset ) }
    };
        
    static const PtArg_t args[] = 
        {
        { Pt_SET_VERSION, 110},
        { Pt_SET_STATE_LEN, sizeof( ShadowedBoxWidget ) },
        { Pt_SET_DFLTS_F, (long)shadowbox_dflts },
        { Pt_SET_DRAW_F, (long)shadowedbox_draw },
        { Pt_SET_FLAGS, 0, Pt_RECTANGULAR },
        { Pt_SET_RESOURCES, (long) resources },
        { Pt_SET_NUM_RESOURCES, 
          sizeof( resources )/sizeof( resources[0] ) }
        };

    return( ShadowedBox->wclass = PtCreateWidgetClass(  
        PtBasic, 0, sizeof( args )/sizeof( args[0] ), args ) );
}

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

[Previous] [Contents] [Index] [Next]