SFGetFile
SFGetFile Initiate a standard file Open... dialog
#include <StandardFile.h> Standard File Package
void SFGetFile(where, prompt, fileFilter, numTypes, typeList, dlgHook,
reply);
Point where ; coordinates for top left of dialog window
Str255 prompt ; (unused, just pass NIL)
ProcPtr fileFilter ; filters filenames; NIL= standard filtering
short numTypes ; -1 = all types; else = number of elements in typeList
SFTypeList typeList ; address of list of file types to include
ProcPtr dlgHook ; NIL= standard; else=addr of custom routine
SFReply *reply ; address of structure; receives return info
This is the normal way to ask the user for the name of a file to be opened (as
in processing an Open..." menu selection). It presents a dialog window,
handles events until the user selects a file or cancels the operation, and
provides all information you need to open the selected file.
where is a screen location, expressed in global ( screen) coordinates. The
top-left corner of the dialog window is positioned at this point.
prompt exists for symmetry with SFPutFile. Just pass a NIL (0) for this.
fileFilter is the address of a pascal type function that will be called once for
each file matching the types in typeList . It will receive a pointer to
some file information and must return a Boolean (TRUE means don't
show the file). Use fileFilter =NIL to use the default filtering action.
The filter function should be declared as:
pascal Boolean myFileFilter(fileParam * pbp )
numTypes is the number of elements in typeList . Use -1 to allow all types of
files to be listed in the display area.
typeList is the address of an array of OSType values (an SFTypeList data type
consists of an array of 4 such elements). It specifies which file
types (e.g., 'TEXT', 'APPL', etc.) should be displayed. If numTypes is
0 or -1, this parameter is ignored. See the example, below.
dlgHook is the address of a custom procedure that handles the dialog. Use
dlgHook =NIL to employ standard dialog handling. Your custom
handling function should be declared as:
pascal short myDlgProc( short item, DialogPtr theDialog )
It should return a dialog item number if you want Standard File to
process the item OR return 0 (or any non-standard item number) if
you have already processed the user action.
reply is the address of a variable-length SFReply structure. On entry, its
contents are ignored. Upon return, it contains the results of the
dialog, including the name of the file selected by the user.
Returns: none

Notes: This is a high-level function that handles all the user interaction needed
for obtaining a volume reference number (or working directory reference
number) and filename to use in opening a file. It presents a list of files,
sorted alphabetically, and lets the user pick one by pointing and clicking.
The standard dialog window occupies a 348 x 136 rectangle that looks like:
If the user chooses to open a file, the SFReply structure will contain TRUE
in the good field, the filename will be stored as a Pascal-style string in the
fName field, and the other fields of the structure will identify all the other
information needed to open the file and begin processing it. If the user
selects "Cancel", the good field will be FALSE (0).
The fileFilter, numTypes, and typeList parameters affect which files are
listed. To list all files, set
fileFilter = NIL
numTypes = 0
typeList = NIL
To be more selective, fill an SFTypeList structure with up to four file
types and pass the address of that list in typeList and the number of
elements in numTypes . See the example, below.
Note: The SFTypeList is an artifact of the Mac's Pascal heritage. In C,
you can just create an array of OSType values, set typeList to point to the
first element of the array, and set numTypes to the number of elements in
the array.
Reference numbers and working directory reference numbers change from
run to run. In order to know what directory a file is in, you must use the
directory's dirID. If you use standard file to open a file, the low memory
global CurDirStore contains a long that is the dirID of the last directory
using standard file.
For the most complete control, you can create a filtering function and pass
its address in fileFilter . For each potential file in the file list, the filter
will receive a ParmBlkPtr ( pointing to a FileParam structure) that it can
examine to determine if it likes the file. It should return FALSE to indicate
that the filename should be shown; TRUE means that the filename should be
filtered ( removed) from the display. This technique is illustrated in the
example, below.
Example
#include <StandardFile.h>
#include <OSUtils.h> /* needed for DateTimeRec */
pascal Boolean oldFileFilter( fileParam* thePB );
/* filter must be 'pascal Boolean' */
DateTimeRec dtr = {1988, 4, 15, 0,0,0,0 };
long targetDate;
Date2Secs( &dtr, & targetDate ); /* convert YMD date to secs */
/* this function filters the SFGetFile list to include only */
/* 'TEXT' files created/modified after a selected date */
GetOldTextFile()
{
SFReply theReply;
Point where;
SFTypeList typeList;
typeList[0]='TEXT'; /* file type to search for */
where.h=20; where.v=90; /* SF dialog window position */
SFGetFile(where, /* put topLeft corner of dialog box here */
0, /* always 0 on SFGetFile() */
oldFileFilter, /* address of custom filter */
1, /* only looking for one file type */
&typeList, /* start of list of file types */
0, /* use standard dialog handler */
&theReply); /* put results here */
if ( theReply.good == TRUE ) { ... user selected Open" ... }
else { /* ... user canceled the open operation ... */ }
}
/* This filters out (discards) files older than targetDate */
/* This and other filter functions MUST be declared pascal */
pascal Boolean oldFileFilter(fileParam* thePB )
{
if ( thePB->ioFlMdDat >= targetDate )
return( FALSE ); [TOKEN:12074] new file, keep it in the list */
else
return( TRUE ); [TOKEN:12074] too old, filter it from the list */
}