Set application-level resources
int PtAppSetResources(int n_args, PtArg_t const *args);
ph
This function sets the resources specified in the args array for the application. This function operates identically to its widget counterpart, PtSetResources(), except it doesn't have a widget argument.
If you are setting a single callback resource, it is easier to use PtAppAddCallback().
For more information, see the Manipulating Resources in Application Code chapter of the Photon Programmer's Guide.
The following resources can be set for an application:
Resource | C type | Pt type | Default |
---|---|---|---|
Pt_CB_APP_EXIT | PtAppCallback_t* | Link | NULL |
Pt_CB_APP_WCLASS_CREATED | PtAppCallback_t* | Link | NULL |
Pt_CB_FILTER | PtAppRawCallback_t* | Link | NULL |
Pt_CB_HOTKEY | PtAppHotkeyCallback_t* | Link | NULL |
Pt_CB_RAW | PtAppRawCallback_t* | Link | NULL |
C type | Pt type | Default |
---|---|---|
PtAppCallback_t* | Link | NULL |
A list of PtAppCallback_t structures that define the callbacks invoked when the application is exiting via a call to PtExit(). All exit points from the library call PtExit(), but it is up to the application designer to exit via this method also. Callbacks should unconditionally return Pt_CONTINUE — other return values may be interpreted differently in future versions.
Although an application might call PtExit() more than once (for example, from different threads in a multi-threaded application), the callbacks in this list are invoked only once. |
Each callback is passed a PtCallbackInfo_t structure that contains at least the following members:
C type | Pt type | Default |
---|---|---|
PtAppCallback_t* | Link | NULL |
A list of PtAppCallback_t structures that define the callbacks invoked immediately after a new widget class is created.
Each callback is passed a PtCallbackInfo_t structure that contains at least the following members:
C type | Pt type | Default |
---|---|---|
PtAppRawCallback_t* | Link | NULL |
A list of PtAppRawCallback_t structures that define the callbacks invoked when an event that matches the provided event mask is to be passed to the application. Application-level event filters are invoked prior to any widget processing (including the widget event filters), and can preempt events in a similar fashion
Your application must have at least one region open for this resource to work. |
Each callback is passed a PtCallbackInfo_t structure. See the Pt_CB_FILTER resource for PtWidget for a description of what this structure contains.
C type | Pt type | Default |
---|---|---|
PtAppRawCallback_t* | Link | NULL |
A list of PtAppRawCallback_t structures that define the callbacks that the application invokes if the event it receives matches the event mask provided in the PtAppRawCallback_t structure. Application-level raw callbacks are invoked after all widget processing has been done, if the event has not been consumed.
Your application must have at least one region open for this resource to work. |
Each callback is passed a PtCallbackInfo_t structure. See the Pt_CB_RAW resource for PtWidget for a description of what this structure contains.
C type | Pt type | Default |
---|---|---|
PtAppHotkeyCallback_t* | Link | NULL |
A list of PtAppHotkeyCallback_t structures. If the application receives a key event that matches a structure's key cap and key modifiers, the application calls the function specified in that structure.
Application-level hotkey handlers are invoked after widget processing is completed, and after any application-level Pt_CB_FILTER callbacks.
Your application must have at least one window for this resource to work. Also, you cannot bind application-level hotkey handlers to widgets. Therefore you must supply a callback function (this is different from the widget-level hotkey handlers). |
Each callback is passed a PtCallbackInfo_t structure. See the Pt_CB_HOTKEY resource for PtWidget for a description of what this structure contains.
An application callback structure.
typedef struct Pt_app_callback { int (*event_f)( void *, PtCallbackInfo_t * ), void *data; } PtAppCallback_t;
The PtAppCallback_t structure lets you specify an application's callbacks. This structure contains at least:
The callback function takes the following arguments:
Callback functions should return Pt_CONTINUE unless the description of the widget's callback resource tells you to return something else.
The PtAppRawCallback_t structure lets you specify event handlers (raw and filter callbacks) for your application. You use this structure when setting the Pt_CB_RAW or Pt_CB_FILTER resource of your application.
typedef struct Pt_app_raw_callback { unsigned long event_mask; int (*event_f)( void *, PtCallbackInfo_t * ); void *data; } PtAppRawCallback_t;
The structure contains at least the following members:
An application hotkey callback structure.
typedef struct Pt_app_hotkey_callback { unsigned short key_sym_cap; short flags; unsigned long key_mods; void *data; int (*event_f)( void *, PtCallbackInfo_t * ); } PtAppHotkeyCallback_t;
The PtAppHotkeyCallback_t structure lets you specify hotkeys or hotkey handlers, or both, for your application. It contains at least the following members:
Set the Pt_CB_APP_EXIT callback resource for an application:
int exit_cb(void *data, PtCallbackInfo_t *cbinfo) { printf( "I\'m exiting\n" ); return( Pt_CONTINUE ); }; ... PtAppCallback_t exit_callbacks[] = {{exit_cb, NULL}}; PtArg_t args[1]; PtSetArg( &args[0], Pt_CB_APP_EXIT, exit_callbacks, sizeof(exit_callbacks)/sizeof(exit_callbacks[0])); PtAppSetResources( 1, args );
Photon
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |
PtAppAddCallback(), PtAppGetResources(), PtAppGetResource(), PtAppRemoveCallback(), PtAppSetResource(), PtSetArg().