Mac OS 9
Translation.h
Go to the documentation of this file.
1 
19 #ifndef __TRANSLATION__
20 #define __TRANSLATION__
21 
22 #ifndef __MACTYPES__
23 #include <MacTypes.h>
24 #endif
25 
26 #ifndef __FILES__
27 #include <Files.h>
28 #endif
29 
30 #ifndef __COMPONENTS__
31 #include <Components.h>
32 #endif
33 
34 #ifndef __TRANSLATIONEXTENSIONS__
35 #include <TranslationExtensions.h>
36 #endif
37 
38 #if PRAGMA_ONCE
39 #pragma once
40 #endif
41 
42 #ifdef __cplusplus
43 extern "C"
44 {
45 #endif
46 
47 #if PRAGMA_IMPORT
48 #pragma import on
49 #endif
50 
51 #if PRAGMA_STRUCT_ALIGN
52 #pragma options align = mac68k
53 #elif PRAGMA_STRUCT_PACKPUSH
54 #pragma pack(push, 2)
55 #elif PRAGMA_STRUCT_PACK
56 #pragma pack(2)
57 #endif
58 
59  /* enumerated types on how a document can be opened*/
60  typedef short DocOpenMethod;
61  enum
62  {
63  domCannot = 0,
64  domNative = 1,
65  domTranslateFirst = 2,
66  domWildcard = 3
67  };
68 
69  /* 0L terminated array of OSTypes, or FileTypes*/
70  typedef OSType TypesBlock[64];
71  typedef OSType *TypesBlockPtr;
72  /* Progress dialog resource ID*/
73  enum
74  {
75  kTranslationScrapProgressDialogID = -16555
76  };
77 
78  /* block of data that describes how to translate*/
80  {
81  OSType componentSignature;
82  const void *translationSystemInfo;
83  FileTypeSpec src;
84  FileTypeSpec dst;
85  };
89 
90  /*****************************************************************************************
91  *
92  * GetFileTypesThatAppCanNativelyOpen
93  *
94  * This routine returns a list of all FileTypes that an application can open by
95  * itself
96  *
97  * Enter: appVRefNumHint volume where application resides (can be wrong,
98  * and if is, will be used as a starting point) appSignature signature
99  * (creator) of application nativeTypes pointer to a buffer to be filled
100  * with up to 64 FileTypes
101  *
102  * Exit: nativeTypes zero terminated array of FileTypes that can be
103  * opened by app
104  */
113  OSErr
114  GetFileTypesThatAppCanNativelyOpen(short appVRefNumHint, OSType appSignature,
115  FileType *nativeTypes);
116 
117  /*****************************************************************************************
118  *
119  * ExtendFileTypeList
120  *
121  * This routine makes a new list of file types that can be translated into a
122  * type in the given list Used by StandardFile
123  *
124  * Enter: originalTypeList pointer to list of file types that can be
125  * opened numberOriginalTypes number of file types in orgTypeList
126  * extendedTypeList pointer to a buffer to be filled with file
127  * types numberExtendedTypes max number of file types that can be put in
128  * extendedTypeList
129  *
130  * Exit: extendedTypeList buffer filled in with file types that can
131  * be translated numberExtendedTypes number of file types put in
132  * extendedTypeList
133  */
142  OSErr
143  ExtendFileTypeList(const FileType *originalTypeList, short numberOriginalTypes,
144  FileType *extendedTypeList, short *numberExtendedTypes);
145 
146  /*****************************************************************************************
147  *
148  *
149  * This routine checks if a file can be opened by a particular application.
150  * If so, it returns if it needs to be translated first, and if so then how.
151  * The FileTypes that the app can open are specified by nativelyOpenableTypes,
152  * or if it is NULL, GetFileTypesThatAppCanNativelyOpen is called.
153  *
154  * Enter: targetDocument document to check if it can be opened
155  * appVRefNumHint vRefNum of application to open doc ( can be
156  * wrong, and if is, will be used as a starting point) appSignature signature
157  * (creator) of application to open doc nativeTypes zero terminated list
158  * of FileTypes app can open natively, or NULL to use default list onlyNative
159  * whether to consider if document can be translated before opening howToOpen
160  * pointer to buffer in which to put how the document can be opened
161  * howToTranslate pointer to buffer in which to put a
162  * FileTranslationSpec record
163  *
164  * Exit: howToOpen whether file needs to be translated to be read
165  * howToTranslate if file can be translated, buffer filled in
166  * with how to translate returns noErr, noPrefAppErr
167  */
176  OSErr
177  CanDocBeOpened(const FSSpec *targetDocument, short appVRefNumHint,
178  OSType appSignature, const FileType *nativeTypes,
179  Boolean onlyNative, DocOpenMethod *howToOpen,
180  FileTranslationSpec *howToTranslate);
181 
182  /*****************************************************************************************
183  *
184  * GetFileTranslationPaths
185  *
186  * This routine returns a list of all ways a translation can occure to or from
187  * a FileType. The app is checked to exist. The hint for each app is the
188  * VRefNum and DTRefNum
189  *
190  * Enter: srcDoc source file or NULL for all matches
191  * dstDoc destination FileType or 0 for all matches
192  * maxResultCount
193  * resultBuffer
194  * Exit: number of paths
195  */
204  short
205  GetFileTranslationPaths(const FSSpec *srcDocument, FileType dstDocType,
206  unsigned short maxResultCount,
207  FileTranslationSpecArrayPtr resultBuffer);
208 
209  /*****************************************************************************************
210  *
211  * GetPathFromTranslationDialog
212  *
213  * This routine, with a given document, application, and a passed typelist will
214  * display the Macintosh Easy Open translation dialog allowing the user to make
215  * a choice. The choice made will be written as a preference (so the next call
216  * to CanDocBeOpened() will work). The routine returns the translation path
217  * information.
218  *
219  * Enter: theDocument FSSpec to document to open
220  * theApplication FSSpec to application to open document
221  * typeList Nil terminated list of FileType's (e.g.
222  * SFTypeList-like) of types you would like the documented translated to. Order
223  * most perferred to least.
224  *
225  * Exit: howToOpen Translation method needed to open document
226  * howToTranslate Translation specification
227  * returns Any errors that might occur.
228  */
237  OSErr
238  GetPathFromTranslationDialog(const FSSpec *theDocument,
239  const FSSpec *theApplication,
240  TypesBlockPtr typeList, DocOpenMethod *howToOpen,
241  FileTranslationSpec *howToTranslate);
242 
243  /*****************************************************************************************
244  *
245  * TranslateFile
246  *
247  * This routine reads a file of one format and writes it to another file in
248  * another format. The information on how to translated is generated by the
249  * routine CanDocBeOpened. TranslateFile calls through to the TranslateFile
250  * Extension's DoTranslateFile routine. The destination file must not exist. It
251  * is created by this routine.
252  *
253  * Enter: sourceDocument input file to translate
254  * destinationDocument output file of translation
255  * howToTranslate pointer to info on how to translate
256  * Exit: returns noErr, badTranslationSpecErr
257  */
266  OSErr
267  TranslateFile(const FSSpec *sourceDocument, const FSSpec *destinationDocument,
268  const FileTranslationSpec *howToTranslate);
269 
270  /*****************************************************************************************
271  *
272  * GetDocumentKindString
273  *
274  * This routine returns the string the Finder should show for the "kind" of a
275  * document in the GetInfo window and in the kind column of a list view.
276  *
277  * Enter: docVRefNum The volume containing the document
278  * docType The catInfo.fdType of the document
279  * docCreator The catInfo.fdCreator of the document
280  * kindString pointer to where to return the string
281  *
282  * Exit: kindString pascal string. Ex: "\pSurfCalc spreadsheet"
283  * returns noErr, or afpItemNoFound if kind could not be
284  * determined
285  */
294  OSErr
295  GetDocumentKindString(short docVRefNum, OSType docType, OSType docCreator,
296  Str63 kindString);
297 
298  /*****************************************************************************************
299  *
300  * GetTranslationExtensionName
301  *
302  * This routine returns the translation system name from a specified
303  * TranslationSpec
304  *
305  * Enter: translationMethod The translation path to get the translation
306  * name from
307  *
308  * Exit: extensionName The name of the translation system
309  * returns Any errors that might occur
310  */
319  OSErr
321  Str31 extensionName);
322 
323  /*****************************************************************************************
324  *
325  * GetScrapDataProcPtr
326  *
327  * This is a prototype for the function you must supply to TranslateScrap. It
328  * is called to get the data to be translated. The first call TranslateScrap
329  * will make to this is to ask for the 'fmts' data. That is a special. You
330  * should resize and fill in the handle with a list all the formats that you
331  * have available to be translated, and the length of each. (See I.M. VI 4-23
332  * for details of 'fmts'). It will then be called again asking for one of the
333  * formats that 'fmts' list said was available.
334  *
335  * Enter: requestedFormat Format of data that TranslateScrap needs.
336  * dataH Handle in which to put the requested data
337  * srcDataGetterRefCon Extra parameter for you passed to
338  * TranslateScrap
339  *
340  * Exit: dataH Handle is resized and filled with data in
341  * requested format
342  */
343  typedef CALLBACK_API(OSErr, GetScrapDataProcPtr)(ScrapType requestedFormat,
344  Handle dataH,
345  void *srcDataGetterRefCon);
346  typedef STACK_UPP_TYPE(GetScrapDataProcPtr) GetScrapDataUPP;
355  GetScrapDataUPP
356  NewGetScrapDataUPP(GetScrapDataProcPtr userRoutine);
357 #if !OPAQUE_UPP_TYPES
358  enum
359  {
360  uppGetScrapDataProcInfo = 0x00000FE0
361  }; /* pascal 2_bytes Func(4_bytes, 4_bytes, 4_bytes) */
362 #ifdef __cplusplus
363  inline GetScrapDataUPP NewGetScrapDataUPP(GetScrapDataProcPtr userRoutine)
364  {
365  return (GetScrapDataUPP)NewRoutineDescriptor((ProcPtr)(userRoutine),
366  uppGetScrapDataProcInfo,
367  GetCurrentArchitecture());
368  }
369 #else
370 #define NewGetScrapDataUPP(userRoutine) \
371  (GetScrapDataUPP) \
372  NewRoutineDescriptor((ProcPtr)(userRoutine), uppGetScrapDataProcInfo, \
373  GetCurrentArchitecture())
374 #endif
375 #endif
376 
385  void
386  DisposeGetScrapDataUPP(GetScrapDataUPP userUPP);
387 #if !OPAQUE_UPP_TYPES
388 #ifdef __cplusplus
389  inline void DisposeGetScrapDataUPP(GetScrapDataUPP userUPP)
390  {
391  DisposeRoutineDescriptor((UniversalProcPtr)userUPP);
392  }
393 #else
394 #define DisposeGetScrapDataUPP(userUPP) DisposeRoutineDescriptor(userUPP)
395 #endif
396 #endif
397 
406  OSErr
407  InvokeGetScrapDataUPP(ScrapType requestedFormat, Handle dataH,
408  void *srcDataGetterRefCon, GetScrapDataUPP userUPP);
409 #if !OPAQUE_UPP_TYPES
410 #ifdef __cplusplus
411  inline OSErr InvokeGetScrapDataUPP(ScrapType requestedFormat, Handle dataH,
412  void *srcDataGetterRefCon,
413  GetScrapDataUPP userUPP)
414  {
415  return (OSErr)CALL_THREE_PARAMETER_UPP(userUPP, uppGetScrapDataProcInfo,
416  requestedFormat, dataH,
417  srcDataGetterRefCon);
418  }
419 #else
420 #define InvokeGetScrapDataUPP(requestedFormat, dataH, srcDataGetterRefCon, \
421  userUPP) \
422  (OSErr) CALL_THREE_PARAMETER_UPP((userUPP), uppGetScrapDataProcInfo, \
423  (requestedFormat), (dataH), \
424  (srcDataGetterRefCon))
425 #endif
426 #endif
427 
428 #if CALL_NOT_IN_CARBON || OLDROUTINENAMES
429 /* support for pre-Carbon UPP routines: New...Proc and Call...Proc */
430 #define NewGetScrapDataProc(userRoutine) NewGetScrapDataUPP(userRoutine)
431 #define CallGetScrapDataProc(userRoutine, requestedFormat, dataH, \
432  srcDataGetterRefCon) \
433  InvokeGetScrapDataUPP(requestedFormat, dataH, srcDataGetterRefCon, \
434  userRoutine)
435 #endif /* CALL_NOT_IN_CARBON */
436 
437  typedef GetScrapDataUPP GetScrapData;
438  /*****************************************************************************************
439  *
440  * TranslateScrap
441  *
442  * This routine resizes the destination handle and fills it with data of the
443  * requested format. The data is generated by translated one or more source
444  * formats of data supplied by the procedure srcDataGetter. This routine is
445  * automatically called by GetScrap and ReadEdition. You only need to call this
446  * if you need to translated scrap style data, but are not using the ScrapMgr or
447  * EditionMgr.
448  *
449  * Enter: sourceDataGetter Pointer to routine that can get src
450  * data sourceDataGetterRefCon Extra parameter for dataGetter
451  * destinationFormat Format of data desired
452  * destinationData Handle in which to store translated
453  * data
454  *
455  * Exit: dstData Handle is resized and filled with data
456  * in requested format
457  */
466  OSErr
467  TranslateScrap(GetScrapDataUPP sourceDataGetter, void *sourceDataGetterRefCon,
468  ScrapType destinationFormat, Handle destinationData,
469  short progressDialogID);
470 
471 #if PRAGMA_STRUCT_ALIGN
472 #pragma options align = reset
473 #elif PRAGMA_STRUCT_PACKPUSH
474 #pragma pack(pop)
475 #elif PRAGMA_STRUCT_PACK
476 #pragma pack()
477 #endif
478 
479 #ifdef PRAGMA_IMPORT_OFF
480 #pragma import off
481 #elif PRAGMA_IMPORT
482 #pragma import reset
483 #endif
484 
485 #ifdef __cplusplus
486 }
487 #endif
488 
489 #endif /* __TRANSLATION__ */
Component Manager Interfaces.
File Manager (MFS, HFS, and HFS+) Interfaces.
Basic Macintosh data types.
unsigned char Boolean
Definition: MacTypes.h:318
void DisposeRoutineDescriptor(UniversalProcPtr theUPP)
#define STACK_UPP_TYPE(name)
Definition: MixedMode.h:734
UniversalProcPtr NewRoutineDescriptor(ProcPtr theProc, ProcInfoType theProcInfo, ISAType theISA)
Macintosh Easy Open Translation Extension Interfaces.
OSType FileType
Definition: TranslationExtensions.h:68
OSErr InvokeGetScrapDataUPP(ScrapType requestedFormat, Handle dataH, void *srcDataGetterRefCon, GetScrapDataUPP userUPP)
OSErr GetDocumentKindString(short docVRefNum, OSType docType, OSType docCreator, Str63 kindString)
void DisposeGetScrapDataUPP(GetScrapDataUPP userUPP)
short GetFileTranslationPaths(const FSSpec *srcDocument, FileType dstDocType, unsigned short maxResultCount, FileTranslationSpecArrayPtr resultBuffer)
OSErr TranslateFile(const FSSpec *sourceDocument, const FSSpec *destinationDocument, const FileTranslationSpec *howToTranslate)
GetScrapDataUPP NewGetScrapDataUPP(GetScrapDataProcPtr userRoutine)
OSErr TranslateScrap(GetScrapDataUPP sourceDataGetter, void *sourceDataGetterRefCon, ScrapType destinationFormat, Handle destinationData, short progressDialogID)
OSErr GetFileTypesThatAppCanNativelyOpen(short appVRefNumHint, OSType appSignature, FileType *nativeTypes)
OSErr CanDocBeOpened(const FSSpec *targetDocument, short appVRefNumHint, OSType appSignature, const FileType *nativeTypes, Boolean onlyNative, DocOpenMethod *howToOpen, FileTranslationSpec *howToTranslate)
OSErr GetTranslationExtensionName(const FileTranslationSpec *translationMethod, Str31 extensionName)
OSErr ExtendFileTypeList(const FileType *originalTypeList, short numberOriginalTypes, FileType *extendedTypeList, short *numberExtendedTypes)
OSErr GetPathFromTranslationDialog(const FSSpec *theDocument, const FSSpec *theApplication, TypesBlockPtr typeList, DocOpenMethod *howToOpen, FileTranslationSpec *howToTranslate)
Definition: Translation.h:80
Definition: TranslationExtensions.h:80