Important: The information in this document is obsolete and should not be used for new development.
Translating Files
If your translation extension identifies a document as one that it can translate and the user chooses to use your translation extension, your extension is called with thekTranslateTranslateFile
request code to translate the document. TheTranslateEntry
extension (shown in Listing 7-5 on page 7-25) dispatches to itsDoTranslateFile
function when it receives this request code. Listing 7-8 shows the skeleton of aDoTranslateFile
function.Listing 7-8 Translating a document
FUNCTION DoTranslateFile (self: ComponentInstance; refNum: TranslationRefNum; srcDoc: FSSpec; srcType: FileType; srcTypeHint: LongInt; dstDoc: FSSpec; dstType: FileType; dstTypeHint: LongInt): ComponentResult; VAR myAdvert: Handle; myResFile: Integer; myResult: OSErr; CONST rProgressAdvertismentResID = 150; BEGIN myResFile := OpenComponentResFile(Component(self)); IF myResFile <> -1 THEN BEGIN {get advertisement} myAdvert := Get1Resource('PICT', rProgressAdvertismentResID); DetachResource(myAdvert); {display progress dialog box and show advertisement} myResult := SetTranslationAdvertisement(refNum, PicHandle(myAdvert)); myResult := CloseComponentResFile(myResFile); END; {now call your routine to translate the file} DoTranslateFile := MyDoTranslation (refNum, srcDoc, srcType, dstDoc, dstType); DisposeHandle(myAdvert); END;By the time theDoTranslateFile
routine is called, the file specified by thedstDoc
parameter already exists. The destination file has a data fork; it also has a resource fork if theflags
field in the appropriate destination file type specification (in your extension's file translation list) has thetaDstDocNeedsResourceFork
bit set. Your extension should open the destination file and fill it with the translated data.In Listing 7-8, the
DoTranslateFile
function calls theSetTranslationAdvertisement
function to install an advertisement in the progress dialog box. The routine that does the actual data translation (MyDoTranslation
) should periodically callUpdateTranslationProgress
to update the progress bar in the dialog box.If an error occurs during the translation, you should make sure to close any files you might have opened (for instance, the destination file's data fork and resource fork), do any other necessary cleaning up, and then return a nonzero result code through your component selector dispatcher. When Macintosh Easy Open receives a nonzero result code, it automatically deletes the destination file.