home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Interfaces / PInterfaces / Translation.p < prev    next >
Encoding:
Text File  |  1994-11-11  |  11.6 KB  |  315 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        Translation.p
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a3  ETO #16, MPW prerelease.  Friday, November 11, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. }
  16.  
  17. {$IFC UNDEFINED UsingIncludes}
  18. {$SETC UsingIncludes := 0}
  19. {$ENDC}
  20.  
  21. {$IFC NOT UsingIncludes}
  22.  UNIT Translation;
  23.  INTERFACE
  24. {$ENDC}
  25.  
  26. {$IFC UNDEFINED __TRANSLATION__}
  27. {$SETC __TRANSLATION__ := 1}
  28.  
  29. {$I+}
  30. {$SETC TranslationIncludes := UsingIncludes}
  31. {$SETC UsingIncludes := 1}
  32.  
  33.  
  34. {$IFC UNDEFINED __TYPES__}
  35. {$I Types.p}
  36. {$ENDC}
  37. {    ConditionalMacros.p                                            }
  38.  
  39. {$IFC UNDEFINED __FILES__}
  40. {$I Files.p}
  41. {$ENDC}
  42. {    MixedMode.p                                                    }
  43. {    OSUtils.p                                                    }
  44. {        Memory.p                                                }
  45.  
  46. {$IFC UNDEFINED __COMPONENTS__}
  47. {$I Components.p}
  48. {$ENDC}
  49.  
  50. {$IFC UNDEFINED __TRANSLATIONEXTENSIONS__}
  51. {$I TranslationExtensions.p}
  52. {$ENDC}
  53. {    Quickdraw.p                                                    }
  54. {        QuickdrawText.p                                            }
  55.  
  56. {$PUSH}
  57. {$ALIGN MAC68K}
  58. {$LibExport+}
  59.     
  60. TYPE
  61.     DocOpenMethod = INTEGER;
  62.  
  63.  
  64. CONST
  65.     domCannot                    = 0;
  66.     domNative                    = 1;
  67.     domTranslateFirst            = 2;
  68.     domWildcard                    = 3;
  69.  
  70. { 0L terminated array of OSTypes, or FileTypes}
  71.     
  72. TYPE
  73.     TypesBlock = ARRAY [0..63] OF OSType;
  74.  
  75.     TypesBlockPtr = ^OSType;
  76.  
  77. { Progress dialog resource ID}
  78.  
  79. CONST
  80.     kTranslationScrapProgressDialogID = -16555;
  81.  
  82. { block of data that describes how to translate}
  83.  
  84. TYPE
  85.     FileTranslationSpec = RECORD
  86.         componentSignature:        OSType;
  87.         translationSystemInfo:    Ptr;
  88.         src:                    FileTypeSpec;
  89.         dst:                    FileTypeSpec;
  90.     END;
  91.     FileTranslationSpecArrayPtr = ^FileTranslationSpec;
  92.  
  93. {****************************************************************************************
  94. *   GetFileTypesThatAppCanNativelyOpen
  95. *  This routine returns a list of all FileTypes that an application can open by itself
  96. *  Enter:    appVRefNumHint        volume where application resides (can be wrong, and if is, will be used as a starting point)
  97. *             appSignature        signature (creator) of application
  98. *             nativeTypes            pointer to a buffer to be filled with up to 64 FileTypes
  99. *  Exit:    nativeTypes            zero terminated array of FileTypes that can be opened by app
  100. }
  101.  
  102. FUNCTION GetFileTypesThatAppCanNativelyOpen(appVRefNumHint: INTEGER; appSignature: OSType; VAR nativeTypes: FileType): OSErr;
  103.     {$IFC NOT GENERATINGCFM}
  104.     INLINE $701C, $ABFC;
  105.     {$ENDC}
  106. {****************************************************************************************
  107. *  ExtendFileTypeList
  108. *  This routine makes a new list of file types that can be translated into a type in the given list
  109. *  Used by StandardFile
  110. *  Enter:    originalTypeList        pointer to list of file types that can be opened
  111. *             numberOriginalTypes        number of file types in orgTypeList
  112. *              extendedTypeList        pointer to a buffer to be filled with file types
  113. *             numberExtendedTypes        max number of file types that can be put in extendedTypeList
  114. *  Exit:    extendedTypeList        buffer filled in with file types that can be translated
  115. *             numberExtendedTypes        number of file types put in extendedTypeList
  116. }
  117. FUNCTION ExtendFileTypeList({CONST}VAR originalTypeList: FileType; numberOriginalTypes: INTEGER; VAR extendedTypeList: FileType; VAR numberExtendedTypes: INTEGER): OSErr;
  118.     {$IFC NOT GENERATINGCFM}
  119.     INLINE $7009, $ABFC;
  120.     {$ENDC}
  121. {****************************************************************************************
  122. *  This routine checks if a file can be opened by a particular application.
  123. *  If so, it returns if it needs to be translated first, and if so then how.
  124. *  The FileTypes that the app can open are specified by nativelyOpenableTypes,
  125. *  or if it is NULL, GetFileTypesThatAppCanNativelyOpen is called.
  126. *  Enter:    targetDocument        document to check if it can be opened
  127. *             appVRefNumHint        vRefNum of application to open doc ( can be wrong, and if is, will be used as a starting point)
  128. *             appSignature        signature (creator) of application to open doc
  129. *             nativeTypes            zero terminated list of FileTypes app can open natively, or NULL to use default list
  130. *             onlyNative            whether to consider if document can be translated before opening
  131. *             howToOpen            pointer to buffer in which to put how the document can be opened
  132. *             howToTranslate        pointer to buffer in which to put a FileTranslationSpec record
  133. *  Exit:    howToOpen            whether file needs to be translated to be read
  134. *             howToTranslate        if file can be translated, buffer filled in with how to translate
  135. *             returns                noErr, noPrefAppErr
  136. }
  137. FUNCTION CanDocBeOpened({CONST}VAR targetDocument: FSSpec; appVRefNumHint: INTEGER; appSignature: OSType; {CONST}VAR nativeTypes: FileType; onlyNative: BOOLEAN; VAR howToOpen: DocOpenMethod; VAR howToTranslate: FileTranslationSpec): OSErr;
  138.     {$IFC NOT GENERATINGCFM}
  139.     INLINE $701E, $ABFC;
  140.     {$ENDC}
  141. {****************************************************************************************
  142. *  GetFileTranslationPaths
  143. *  This routine returns a list of all ways a translation can occure to or from a FileType.
  144. *  The app is checked to exist.  The hint for each app is the VRefNum and DTRefNum
  145. *  Enter:    srcDoc            source file or NULL for all matches
  146. *             dstDoc            destination FileType or NULL for all matches
  147. *             maxResultCount
  148. *             resultBuffer
  149. *  Exit:    number of paths
  150. }
  151. FUNCTION GetFileTranslationPaths(VAR srcDocument: FSSpec; dstDocType: FileType; maxResultCount: INTEGER; resultBuffer: FileTranslationSpecArrayPtr): INTEGER;
  152.     {$IFC NOT GENERATINGCFM}
  153.     INLINE $7038, $ABFC;
  154.     {$ENDC}
  155. {****************************************************************************************
  156. *  GetPathFromTranslationDialog
  157. *  This routine, with a given document, application, and a passed typelist will display the
  158. *  Macintosh Easy Open translation dialog allowing the user to make a choice.  The choice
  159. *  made will be written as a preference (so the next call to CanDocBeOpened() will work).
  160. *  The routine returns the translation path information.
  161. *  Enter:    theDocument            FSSpec to document to open
  162. *             theApplication        FSSpec to application to open document
  163. *             typeList            Nil terminated list of FileType's (e.g. SFTypeList-like) of types
  164. *                                 you would like the documented translated to.  Order most perferred
  165. *                                 to least.
  166. *  Exit:    howToOpen            Translation method needed to open document
  167. *             howToTranslate        Translation specification
  168. *             returns                Any errors that might occur.
  169. }
  170. FUNCTION GetPathFromTranslationDialog({CONST}VAR theDocument: FSSpec; {CONST}VAR theApplication: FSSpec; typeList: TypesBlockPtr; VAR howToOpen: DocOpenMethod; VAR howToTranslate: FileTranslationSpec): OSErr;
  171.     {$IFC NOT GENERATINGCFM}
  172.     INLINE $7037, $ABFC;
  173.     {$ENDC}
  174. {****************************************************************************************
  175. *   TranslateFile
  176. *  This routine reads a file of one format and writes it to another file in another format. 
  177. *  The information on how to translated is generated by the routine CanDocBeOpened.
  178. *  TranslateFile calls through to the TranslateFile Extension's DoTranslateFile routine.  
  179. *  The destination file must not exist.  It is created by this routine.  
  180. *  Enter:    sourceDocument            input file to translate
  181. *             destinationDocument        output file of translation
  182. *             howToTranslate            pointer to info on how to translate
  183. *  Exit:    returns                    noErr, badTranslationSpecErr 
  184. }
  185. FUNCTION TranslateFile({CONST}VAR sourceDocument: FSSpec; {CONST}VAR destinationDocument: FSSpec; {CONST}VAR howToTranslate: FileTranslationSpec): OSErr;
  186.     {$IFC NOT GENERATINGCFM}
  187.     INLINE $700C, $ABFC;
  188.     {$ENDC}
  189. {****************************************************************************************
  190. *   GetDocumentKindString
  191. *  This routine returns the string the Finder should show for the "kind" of a document
  192. *  in the GetInfo window and in the kind column of a list view.  
  193. *  Enter:    docVRefNum        The volume containing the document
  194. *             docType            The catInfo.fdType of the document
  195. *             docCreator        The catInfo.fdCreator of the document
  196. *             kindString        pointer to where to return the string
  197. *  Exit:    kindString        pascal string.  Ex: "\pSurfCalc spreadsheet"
  198. *             returns            noErr, or afpItemNoFound if kind could not be determined
  199. }
  200. FUNCTION GetDocumentKindString(docVRefNum: INTEGER; docType: OSType; docCreator: OSType; VAR kindString: Str63): OSErr;
  201.     {$IFC NOT GENERATINGCFM}
  202.     INLINE $7016, $ABFC;
  203.     {$ENDC}
  204. {****************************************************************************************
  205. *  GetTranslationExtensionName
  206. *  This routine returns the translation system name from a specified TranslationSpec
  207. *  Enter:    translationMethod    The translation path to get the translation name from
  208. *  Exit:    extensionName        The name of the translation system
  209. *             returns                Any errors that might occur
  210. }
  211. FUNCTION GetTranslationExtensionName({CONST}VAR translationMethod: FileTranslationSpec; VAR extensionName: Str31): OSErr;
  212.     {$IFC NOT GENERATINGCFM}
  213.     INLINE $7036, $ABFC;
  214.     {$ENDC}
  215. {****************************************************************************************
  216. *  GetScrapDataProcPtr
  217. *  This is a prototype for the function you must supply to TranslateScrap. It is called to 
  218. *  get the data to be translated.  The first call TranslateScrap will make to this is to
  219. *  ask for the 'fmts' data.  That is a special.   You should resize and fill in the handle
  220. *  with a list all the formats that you have available to be translated, and the length of each.
  221. *  (See I.M. VI 4-23 for details of 'fmts').  It will then be called again asking for one of  
  222. *  the formats that 'fmts' list said was available.
  223. *  Enter:    requestedFormat            Format of data that TranslateScrap needs.
  224. *             dataH                    Handle in which to put the requested data
  225. *             srcDataGetterRefCon        Extra parameter for you passed to TranslateScrap
  226. *             
  227. *  Exit:    dataH                    Handle is resized and filled with data in requested format
  228. }
  229. TYPE
  230.     GetScrapDataProcPtr = ProcPtr;  { FUNCTION GetScrapData(requestedFormat: ScrapType; dataH: Handle; srcDataGetterRefCon: UNIV Ptr): OSErr; }
  231.     GetScrapDataUPP = UniversalProcPtr;
  232.  
  233. CONST
  234.     uppGetScrapDataProcInfo = $00000FE0; { FUNCTION (4 byte param, 4 byte param, 4 byte param): 2 byte result; }
  235.  
  236. FUNCTION NewGetScrapDataProc(userRoutine: GetScrapDataProcPtr): GetScrapDataUPP;
  237.     {$IFC NOT GENERATINGCFM }
  238.     INLINE $2E9F;
  239.     {$ENDC}
  240.  
  241. FUNCTION CallGetScrapDataProc(requestedFormat: ScrapType; dataH: Handle; srcDataGetterRefCon: UNIV Ptr; userRoutine: GetScrapDataUPP): OSErr;
  242.     {$IFC NOT GENERATINGCFM}
  243.     INLINE $205F, $4E90;
  244.     {$ENDC}
  245.     
  246. TYPE
  247.     GetScrapData = GetScrapDataUPP;
  248.  
  249. {****************************************************************************************
  250. *  TranslateScrap
  251. *  This routine resizes the destination handle and fills it with data of the requested format.
  252. *  The data is generated by translated one or more source formats of data supplied by
  253. *  the procedure srcDataGetter.  
  254. *  This routine is automatically called by GetScrap and ReadEdition.  You only need to call
  255. *  this if you need to translated scrap style data, but are not using the ScrapMgr or EditionMgr.
  256. *  Enter:    sourceDataGetter            Pointer to routine that can get src data
  257. *             sourceDataGetterRefCon        Extra parameter for dataGetter
  258. *             destinationFormat            Format of data desired
  259. *             destinationData                Handle in which to store translated data
  260. *             
  261. *  Exit:    dstData                        Handle is resized and filled with data in requested format
  262. }
  263.  
  264. FUNCTION TranslateScrap(sourceDataGetter: GetScrapData; sourceDataGetterRefCon: UNIV Ptr; destinationFormat: ScrapType; destinationData: Handle; progressDialogID: INTEGER): OSErr;
  265.     {$IFC NOT GENERATINGCFM}
  266.     INLINE $700E, $ABFC;
  267.     {$ENDC}
  268.  
  269. {$ALIGN RESET}
  270. {$POP}
  271.  
  272. {$SETC UsingIncludes := TranslationIncludes}
  273.  
  274. {$ENDC} {__TRANSLATION__}
  275.  
  276. {$IFC NOT UsingIncludes}
  277.  END.
  278. {$ENDC}
  279.