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

PtAddCallback()

Add a single callback entry to a callback list

Synopsis:

void PtAddCallback( PtWidget_t *widget,
                    unsigned long callback_type,
                    PtCallbackF_t *callback,
                    void *data );

Description:

This function adds a callback to the callback list indicated by callback_type (e.g. Pt_CB_ACTIVATE).


Note: Some types of callback resources have special routines that you should use instead of this one:
Pt_CB_HOTKEY
PtAddHotkeyHandler()
Pt_CB_RAW
PtAddEventHandler() or PtAddEventHandlers()

The callback argument points to a function that takes this form:

int (*callback)(PtWidget_t *, void *, PtCallbackInfo_t *)

Examples:

activated( PtWidget_t *widget, void *data, 
           PtCallbackInfo_t *info)
{
    //suppress compiler warnings concerning unused arguments.
    widget = widget, data = data, info = info;
    
    exit( 0 );
}

main()
{
    PtArg_t argt;
    PtWidget_t *window, *widget;

    window = PtAppInit( NULL, NULL, NULL, 0, NULL );
    PtSetArg( &argt, Pt_ARG_TEXT_STRING, 
              "Press Me To Quit", 0 );
    button = PtCreateWidget( PtButton, NULL, 1, &args );

    //add an activate callback to the button.
    PtAddCallback( button, Pt_CB_ACTIVATE, 
                       activated, NULL ); 
        
    PtRealizeWidget( window );
    PtMainLoop();
    //unnecessary
    PtRemoveCallback( button, Pt_CB_ACTIVATE, 
                      activated, NULL );
}

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

PtAddCallbacks(), PtAddEventHandler(), PtAddEventHandlers(), PtAddHotkeyHandler(), PtRemoveCallback(), PtRemoveCallbacks()

Creating Widgets in Application Code chapter of the Photon Programmer's Guide


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