

|
Version 2.3 © 2000 K. J. Bricknell
IntroductionThe FinderThe Finder is an application which works with the system software to keep track of files and manage the user's desktop display. On the desktop, the Finder displays icons representing your application and the documents it creates. An icon is an image that the Finder displays to graphically represent some object that the user can manipulate.The Finder needs quick access to some key information about your application, such as which icons to use when displaying your application and its documents. You supply most of this information in the resource fork of your application file. The Finder extracts this information and uses it to maintain its own database of the resources it needs.
The Finder uses certain high-level events known as Apple events to communicate certain instructions and information to your application. Accordingly, this chapter should be read in conjunction with the Chapter 10 - Apple Events
The Catalog FileWhen the user creates or installs a file, the File Manager initially stores some of the information provided by these resources in the volume's catalog file. The catalog file is a special file located on the volume which contains information about the hierarchical organisation of files and folders on that volume. Although it is mostly used by the File Manager, the catalog file also contains information used by the Finder.The DeskTop DatabaseThe Finder extracts from the catalog file the information provided by your resources and, for quick access to that information, uses it to build either a desktop database (for all volumes over 2 MB) or a desktop file (for volumes under 2MB). The desktop database is a Finder-maintained database of icons, file types, applications, version data, and comments. The desktop file is a resource file in which the Finder stores this information for volumes under 2MB. The Finder updates the database when files are added, moved, renamed or deleted. The desktop database:
Application Signature, File Creator, and File TypesApplication SignatureThe Finder identifies your application through its signature. A signature is a unique four-character sequence which must not conflict with that of any other application.2
You must include in your resource file a special resource which has your application's signature as its resource type. By convention, the signature resource has a resource ID of 0. The signature resource is typically defined to be a string resource (that is, a resource of type 'STR ') which specifies the name, version number, and release date of your application.
Your application must have a file type of 'APPL'. The standard file type 'TEXT' should be assigned to files that consist only of text, that is, a stream of characters with return characters at the end of paragraphs. A document of type 'TEXT' can be opened or printed by any application that accepts such file types. Use of the File Type by the Finder. Another way for a user to open a document created by your application, as well as a document not created by your application but which is of a file type supported by your application, is to select its icon and drag the selected icon to your application's icon. Because the document's file type is stored in the catalog file, and the Finder stores a list of your application's supported file types in the desktop database, the Finder can determine whether it should launch your application. If the document's file type is supported by your application, the Finder calls the Process Manager to launch your application and then sends your application a required Apple event containing the information it needs to open the document.
Use of File Type by Your Application. Your application also relies on file types to determine which files to allow the user to open when your application is running. When your application calls the Standard File Package or Navigation Services to open a file, your application supplies either a list of the file types that your application can open or a filter function for those types. The Open dialog box then displays files of the specified types only.
However, to distinguish your product for the user, you should design your own icons for all the files associated with your application, including:
The Icon FamilyFor the most effective display, you should create an icon family for each of your files. An icon family is a set of icons which represent a single object. The following icons make up the icon family for a single file:
The small icons appear in the Application menu, and in the Apple menu if the user places the application or an alias to it in the Apple Menu Items folder.
The Finder uses the icon's mask (see Fig 3) to crop the icon's outline into whatever background colour or pattern is on the desktop. The Finder then draws the icon into this shape. It is therefore important that the mask be exactly the same shape as the icon. Because the mask also defines the region that users need to click to select the icon, it is best not to have any holes in the icon and thus in its mask.
Good icon design requires that one graphic element be repeated in all icons created for the application. This allows the user to quickly identify the files associated with your product. Also, colours for colour icons should ideally be chosen from the 34 recommended icon colours in the system palette. (See the Apple Icon Colors items in the IconFamily menu in Resorcerer.)
The four icon sizes are mini, small, large, and huge, the latter being a new size of 48 by 48 pixels. Four colour depths (1-bit, 4-bit, 8-bit, and 32-bit) and two kind of masks (1-bit and 8-bit) are supported. The deep (8 bit) mask means that masks can have 256 different levels of transparency. Icon Services checks for an 'icns' resource of the specified ID before it checks for the older resource types ('ics#', 'icl4', 'icm8', etc.) of the same ID. If an 'icns' resource is found, Icon Services obtains all icon data exclusively from that resource.
As of Version 2.2, Resorcerer had no pixel editor for 'icns' resources. However, a command available in the Icon Family editor will take all icons currently being shown and build an 'icns' resource with the same resource ID as those icons. (Choose Build/Update 'icns' from the IconFamily menu.)
Users are able to customise individual icons. By selecting a file and choosing Get Info from the File menu, the user can select the displayed icon and use the Paste command to replace it with a picture from the clipboard. The Finder creates a family of icons (Mac OS 8.1 or earlier) or an 'icns' resource (Mac OS 8.5 or later) based on the user's customised icon, assigns a resource ID number of -16455 to each resource in the icon family, or to the 'icns' resource, stores these resources in the resource fork of the file that the icon represents and sets the hasCustomIcon bit in the file's Finder flags field (see below). Your can use the same procedure to provide customised icons for your document.
Note that, although an application can assign icons to all of its documents by associating their icons with the document's file type in a bundle resource, a customised icon can represent only one specific file, that is, that file which has an 'ICN#' resource or 'icns' resource with an ID of -16455 in its resource fork.
You create a 'FREF' resource for your application file itself and you create separate 'FREF' resources for each file type that your application can open.
If your application supports file types for which it does not provide icons, you can still define 'FREF' resources for them, allowing users to launch your application by dragging these document icons to your application icon. For example, you could create a 'FREF' resource for the document file type 'ttxt', which is used by documents which have SimpleText as their creator. (The Finder uses SimpleText's icon family resources for these documents.) The user can then open these documents in your application by dragging the document icon to your application's icon.
When the Finder displays your application on the user's desktop, it checks the catalog file to see if your application has a 'BNDL' resource. If it does not, the Finder displays the default icons. If it does, the Finder installs the information from the 'BNDL' resource and all its bundled resources into either the desktop database (hard disk) or the desktop file (floppy disk) and uses this information to display icons for the file types associated with your application.
Note that you also assign local IDs to 'FREF' resources within the 'BNDL' resource. This assignment is, in fact, superfluous because the Finder does not map these local IDs to any other resources. It was implemented for the earliest versions of the system software, and it remains this way today for backward compatibility.
In the desktop database, the Finder renumbers the resource IDs that you have assigned to your resources to avoid conflicts with the resources of other applications. Therefore, the 'BNDL' resource has to rely on these local IDs to map 'ICN#' resources to their 'FREF' resources, that is, the 'BNDL' resource uses the local ID you assign to an 'ICN#' resource to map it to the 'FREF' resource that has specified the same local ID. For example, the 'FREF' resource with resource ID 208 at Fig 4 shows that the file type 'APPL' is assigned a local ID of 0. At Fig 5, you will see that local ID 0 is assigned to the 'ICN#' resource with resource ID 128. This maps the icon defined by this resource to the application file. Fig 6 illustrates how the 'BNDL' resource uses local IDs to map 'ICN#' resources to 'FREF' resources. This figure illustrates two main concepts:
In Fig 6, the application file's 'ICN#' resource has a resource ID of 128 while its 'FREF' resource has a resource ID of 208. For easier code maintenance, you should probably assign the same resource ID to a file's 'FREF' resource that you assign to its 'ICN#' resource.
You can use 'vers' resources to assign version information to an individual file and, if it is a part of a larger collection of files, to the entire superset of files. The 'vers' resource with ID 1 specifies the version of the file; the 'vers' resource with ID 2 specifies the version of the set of files.
The following describes the main fields of a compiled 'vers' resource:
Fig 8 shows a 'hfdr' resource being created using Resorcerer.
The Finder then sends your application a required Apple event (called an Open Application event) before relinquishing control to your application. In response to the Open Application event, your application should then perform its usual startup actions, such as opening an untitled document window.
In these cases, the Finder reads the creator field of each selected file to find the document's creator. If the document's creator matches your application's signature, the Finder calls the Process Manager, which launches your application, and then sends your application a required Apple event (called an Open Documents or Print Documents event) before relinquishing control to your application. These events contain the name, or names, of the document, or documents, to open or print. Your application should then open the documents in titled windows or print them, as appropriate.
In this case, the Finder determines whether to launch your application by comparing the document's file type (stored in the catalog file) against the list of your application's file types. If the document's type appears in the 'FREF' resource list for your application, the Finder calls the Process Manager, which launches your application, and passes your application the name of the selected document, or selected multiple documents, in an Open Documents event. Your application should then open the documents in titled windows.
The following applies to the situation where the user has selected Automatic document translation off in the Macintosh Easy Open control panel.
Missing ApplicationAssuming that the document's name is "Document A", the alert box at Fig 9 is displayed if the file does not contain a missing application name string resource and either the document is not of type 'TEXT' or 'PICT' or the document is of type 'TEXT' or 'PICT' and SimpleText is not available. If the document is of type 'TEXT' or 'PICT' and SimpleText is available, the alert box at Fig 10 is displayed.
The file must have a unique signature that no other file application known to the finder is likely to have. This ensures that the Finder will display your message, instead of launching the application with that signature, when the user double clicks on the file's icon.
Normally, your application sets the file type and creator information in fields of the file's file information structure when your application creates a new file. For example, the File Manager function FSpCreate takes a creator and a file type as parameters (see Chapter 17 - Files). The Finder manipulates the other fields of the file information structure. The file information structure is as follows:
struct FInfo
{
OSType fdType; // Type of file.
OSType fdCreator; // File's creator.
unsigned short fdFlags; // Finder flags (invisible, stationery, etc).
Point fdLocation; // File's location in folder.
short fdFldr; // Folder containing file.
};
typedef struct FInfo FInfo;
After you have created a file, you can use the File Manager function FSpGetInfo to return the file information structure, and you can set the type, creator and flags fields using FSpSetFInfo.
Finder FlagsIndividual bits of the fdFlags field of the file information structure may be examined and set using constants defined in the header file Finder.h. The bits of most interest to an application, and the associated constants, are as follows:
Additional folders, such as the Temporary Items and Desktop folders (which are both invisible to the user), are maintained at the root level of the volume. The Trash directory also exists at the root level of the volume.
You can use the FindFolder function to get the volume reference number and directory ID of these folders. Folder type constants are passed in the folderType parameter of FindFolder to specify the folder type. The only system-related folders you are ever likely to need are:
Supporting Stationery PadsWhen the user opens a stationery pad from the Finder, the Finder first checks your application's 'SIZE' resource to see if your application supports stationery. If the isStationeryAware bit is not set, the Finder creates a new document from the template and prompts the user for a name. The Finder then starts up your application as usual, passing it the name of the new document. If the isStationeryAware bit is set, the Finder informs your application that the user has opened a document and passes your application the name of the stationery pad.To support stationery, your application should specify the isStationeryAware constant in its 'SIZE' resource and always check the isStationeryAware bit of a document before opening it. The following is an example function which takes a file system specification structure and returns true or false according to whether the file is a stationery document or not.
Boolean isStationeryDoc(FSSpec fileSSpec)
{
OSErr osErr;
FInfo fInfo;
Boolean result;
osErr = FSpGetFInfo(&fileSSpec,&fInfo);
if(osErr == noErr)
result = ((fInfo.fdFlags & kIsStationary) == kIsStationary);
else
result = false;
return(result);
}
Unlike the Finder, the Standard File Package always passes your application the stationery pad itself, not a copy of it, regardless of the setting of the isStationeryAware bit. When the user opens a stationery pad from within your application, the Standard File Package checks your application's 'SIZE' resource. If the application does not support stationery, the Standard File Package displays an alert box warning the user that the stationery pad itself, not a copy of it, is being opened. This means that the user can thus mistakenly write over the stationery pad by choosing Save without assigning a new name. This problem can be avoided by making your application stationery-aware.
Using AliasesAn alias is an object that represents some other file, directory or volume.Ordinarily, when the user wants to open or print files, your application does not need to be concerned with whether they are aliases because both the Finder and the Standard File Package resolve aliases before passing them to your application. However, if your application opens a file or directory without going through the Finder or Standard File Package, your application should always call ResolveAlias just before opening the file.
kIsOnDesk = 0x1 kColor = 0xE kIsShared = 0x40 kHasBeenInited = 0x100 kHasCustomIcon = 0x400 kIsStationary = 0x800 kNameLocked = 0x1000 kHasBundle = 0x2000 kIsInvisible = 0x4000 kIsAlias = 0x8000 Folder Type Constants
kTrashFolderType = FOUR_CHAR_CODE('trsh')
kPreferencesFolderType = FOUR_CHAR_CODE('pref')
kTemporaryFolderType = FOUR_CHAR_CODE('temp')
Data TypesFile Information Structure
struct FInfo
{
OSType fdType; // Type of the file.
OSType fdCreator; // File's creator
unsigned short fdFlags; // Flags, for example, hasbundle, locked, etc.
Point fdLocation; // File's location in folder.
short fdFldr; // Folder containing file.
};
typedef struct FInfo FInfo;
Directory Information Structure
struct DInfo
{
Rect frRect; // Folder rect.
unsigned short frFlags; // Flags.
Point frLocation; // Folder location.
short frView; // Folder view.
};
typedef struct DInfo DInfo;
Functions
OSErr FSpGetFInfo(const FSSpec *spec,FInfo *fndrInfo);
OSErr FSpSetFInfo(const FSSpec *spec,const FInfo *fndrInfo);
OSErr ResolveAliasFile(FSSpec *theSpec,Boolean resolveAliasChains,
Boolean *targetIsFolder,Boolean *wasAliased);
OSErr FindFolder(short vRefNum,OSType folderType,Boolean createFolder,
short *foundVRefNum,long *foundDirID);
The demonstration program at Chapter 17 - More On Resources shows how to copy an application-missing string resource to the resource fork of a Preferences file.
The demonstration program at Chapter 17 - More on Resources shows how to create and access a Preferences file in the Preferences folder.
|



- SPREAD THE WORD:

- Slashdot

- Digg

- Del.icio.us


- Newsvine



