![]() |
![]() |
![]() |
![]() |
![]() |
This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Create a file-selector dialog
int PtFileSelection( PtWidget_t *parent,
PhPoint_t const *pos,
char const *title,
char const *root_dir,
char const *file_spec,
char const *btn1,
char const *btn2,
char const *format,
PtFileSelectionInfo_t *info,
int flags );
If pos is NULL, the function centers the dialog on the screen; if parent is NULL, the function places the dialog at the absolute coordinates of pos; otherwise it places the dialog at the relative offset of pos within parent.
You can pass a directory or a full path for a file. PtFileSelection() parses the string and uses the longest existing path as the root directory. The function uses rest of the string as a suggested path to be displayed in the Name field.
If you want to have a hotkey for this button, place an ampersand (&) in front of the appropriate character in the string. For example, to have the string Select with s as a hotkey, pass &Select as btn1.
The Pt_FSR_CONFIRM_EXISTING flag is ignored when you've set the Pt_FSR_MULTIPLE flag, however you can supply your own confirm_selection function as described later.
You can also OR in the following bits, which affect the appearance and behavior of the PtFileSel widget in the dialog. Each of these bits corresponds to a flag in the Pt_ARG_FS_FLAGS resource of the PtFileSel widget:
ph
This function creates a file-selector dialog that lets the user browse files and directories. The dialog allows the selection of a file and/or directory and fills a PtFileSelectionInfo_t structure with information about the selected item and the dialog.

An example of the dialog created by PtFileSelection().
![]() |
Be sure to initialize the PtFileSelectionInfo_t structure pointed to by info before calling this function. This structure includes some pointers that must be set to NULL if you don't want to provide callback functions. For more information, see "PtFileSelectionInfo_t structure," below. |
You can specify the dimensions of the dialog by setting the info->dim field before calling this function.
This function can select directories as well as files. Enable directory selection with the Pt_FSR_SELECT_DIRS flag. Existing directories can be selected with btn1 (the Open button).
PtFileSelection() can create and delete directories and delete files. You can create new directories at any time by pressing the New button. When the PtFileSel widget has focus, these hotkeys are activated:
PtFileSelection() has its own event-processing loop.
The PtFileSelectionInfo_t structure includes at least the following members:
If you haven't set Pt_FSR_MULTIPLE, minfo is NULL, and the selected item's path is returned in the path member of PtFileSelectionInfo_t.
The members of the PtCallbackInfo_t structure are used as follows:
This function should return Pt_CONTINUE or Pt_END to indicate whether or not the item should be displayed in the file selector.
The members of the PtCallbackInfo_t structure are used as follows:
If reason_subtype is Pt_FSR_MULTIPLE, the following members of the PtFileSelectorInfo_t structure are valid:
If confirm_selection returns Pt_CONTINUE, PtFileSelection() exits. If confirm_selection returns Pt_END, PtFileSelection() doesn't exit, the selector stays on the screen, and the user must choose another file or directory.
Applications can use this function to screen selections and avoid having to call PtFileSelection() repeatedly.
The members of the PtCallbackInfo_t structure are used as follows:
The function should return Pt_CONTINUE.
You can't use this field to set the widget's Pt_ARG_SELECTION_MODE resource. If you set Pt_FSR_MULTIPLE in the flags argument to PtFileSelection(), Pt_ARG_SELECTION_MODE is set to Pt_EXTENDED_MODE.
PtFileSelection() defines the following "pseudo resources" for PtFileSel:
![]() |
When PtFileSelection() returns, you have to clean up the
PtFileSelectionInfo_t structure because it can contain allocated
members and strings.
You can do the cleanup by calling:
int PtFSFreeInfo( PtFileSelectionInfo_t *fs ); If you haven't set Pt_FSR_MULTIPLE, you don't have to call PtFSFreeInfo(). |
PtFileSelection() passes the PtFileSelectorInfo_t structure as a parameter to the confirm_display, confirm_selection and new_directory functions.
![]() |
Some of the members of PtFileSelectorInfo_t are valid in the confirm-selection callback, and others are valid when PtFileSelection() returns. |
The PtFileSelectorInfo_t structure contains at least these members:
/*************************************
* fsel.c
*
* Sample program that illustrates usage of
* the PtFileSelection() convenience function.
*
* Compile as follows:
* $ qcc -lph -o fsel fsel.c
*
* Run as follows:
* $ ./fsel
*
**************************************/
#include <stdio.h>
#include <stdlib.h>
#include <Ph.h>
#include <Pt.h>
int main(int argc, char **argv )
{
PtFileSelectionInfo_t info;
PtArg_t args[1];
int k;
/* Initialize the widget library and connect to Photon. */
PtInit( NULL );
/* Initialize the file-select info structure */
memset( &info, 0x0, sizeof(PtFileSelectionInfo_t) );
/* Change the name-column label of the PtFileSel widget
in the filesel dialog from the default "Name" to "Nom" */
PtSetArg( args, Pt_ARG_FS_LBL_NAME, "Nom:", 0 );
info.args = args;
info.num_args = 1;
/* Invoke the convenience function. */
k = PtFileSelection( NULL, /* parent */
NULL, /* pos */
"PtFileSelection Example", /* title */
"~", /* root_dir, tilde is the home directory
specified by $HOME */
NULL, /* file_spec filter */
NULL, /* label of btn1, the Open button,
default is "Open" */
NULL, /* label of btn2, the Cancel button,
default is "Cancel" */
NULL, /* Pt_ARG_FS_FORMAT resource of the
PtFileSel widget, default is "nsd" */
&info, /* PtFileSelectionInfo_t *info
structure, must be specified */
Pt_FSR_CONFIRM_EXISTING |
Pt_FSR_SHOW_HIDDEN |
Pt_FSR_NO_FCHECK /* PtFileSelection flags */
);
if ( k ) {
fprintf( stderr, "\nPtFileSelection failed." );
PtExit( -1 );
}
if ( info.ret == Pt_FSDIALOG_BTN1 )
fprintf( stderr,
"\nOpen button was pressed. The selected file is:\n\t%s\n",
info.path );
else
fprintf( stderr, "\nCancel button was pressed.\n" );
PtExit( 0 );
return EXIT_SUCCESS;
}
Photon
| Safety: | |
|---|---|
| Interrupt handler | No |
| Signal handler | No |
| Thread | No |
PtFileSel in the Photon Widget Reference
"Dialog modules" in the Working with Modules chapter of the Photon Programmer's Guide
![]() |
![]() |
![]() |
![]() |