Important: The information in this document is obsolete and should not be used for new development.
How and When the Finder Launches Your Application
The previous sections in this chapter explain the resources that the Finder uses to display and launch your application. This section provides a brief summary of how the Finder--using the previously described resources--starts up your application whenever the user requests the Finder to launch your application or to open or print a document supported by your application.The simplest scenarios under which the Finder launches your application occur when the user double-clicks your application icon or selects it and chooses Open from the Finder's File menu. In these cases, the Finder calls the Process Manager to start your application. As explained in Inside Macintosh: Processes, the Process Manager creates a partition of memory for your application, loads your code into this partition, and sets up the stack, heap, and A5 world for your application. The Process Manager returns control to the Finder.
If your application supports the required Apple events (as explained in Inside Macintosh: Interapplication Communication), the Finder sends your application an Open
Application event and then relinquishes control to your application. Your application then performs the tasks necessary to open itself--displaying an untitled document window, for example.When the user requests the Finder to open or print a document supported by your application, the Finder calls the Process Manager and launches your application in the same way, except that the Finder sets up the information your application needs to open or print the document and passes this information to your application. This information includes a list of files to open or print. In System 7, applications receive this information through Apple events, which are described in Inside Macintosh: Interapplication Communication.
The user can request the Finder to open documents created by your application by double-clicking one of their icons, and the user can request the Finder to open or print documents by selecting one or more icons and choosing Open or Print from the Finder's File menu. The Finder reads the creator field of each selected file to find the document's creator. Typically (as described in "Using Finder Information in the Catalog File" beginning on page 7-30), your application sets the four-character string specified in its signature resource as the creator of its documents. The Finder searches for the applica- tion whose signature matches each document's creator. If the document's creator matches your application's signature, the Finder calls the Process Manager, launches your application, and then passes your application the name of the selected document
or selected multiple documents in an Open Documents or a Print Documents event.
Your application should then open the documents in titled windows or print them, as appropriate. (See Inside Macintosh: Files for detailed information about opening documents; see Inside Macintosh: Imaging for detailed information about printing them.)If the user tries to open documents created by your application and your application is missing, the Finder displays an alert box telling the user that your application is missing. The Finder displays the name of your application in this alert box if you provide your documents with a missing-application name string resource, as described in "Displaying Messages When the Finder Can't Find Your Application" beginning on page 7-25.
Sometimes when your application is already running, the user might double-click a document created by your application. In this case, the Finder sends your application
the Open Documents event.The user can also request the Finder to launch your application by dragging one icon or several icons to your application's icon. The Finder determines whether to launch your application by comparing the document's file type (which is stored in the catalog file) against the list of your application's supported file types. The Finder compiles this list from the file reference resources you create for your application; the Finder stores this
list in the desktop database. If the document's file type appears in the file reference resource list for your application, the Finder calls the Process Manager, launches your application, and passes it 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.You can also specify disks, folders, and a wildcard file type for all other files in your file reference resources so that users can launch your application by dragging their icons to your application icon, in which case the Finder launches your application and sends it an Open Documents event. An Open Documents event includes a list of alias records for objects that the application should open. It is up to your application to open disks, folders, or all possible file types in a manner appropriate to the needs of the user. (Alias records are described in "Using Aliases" beginning on page 7-37.)
To support stationery, your application should specify the
isStationeryAware
constant in its'SIZE'
resource and always check theisStationery
bit of a document passed to it by the Finder. If theisStationery
bit is set for a file that the user wants to open, your application should copy the stationery pad's contents into a new document and open the document in an untitled window. This is described in "Supporting Stationery Pads" beginning on page 7-32.In System 7, users can create aliases, which are objects that represent other files, directories, or volumes. If the user opens an alias that represents a document created by your application, the Finder resolves the alias for you; that is, it passes your application the name and location of the document itself, not the alias.