TranslationServices.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. {
  2. File: HIServices/TranslationServices.h
  3. Contains: Translation Services Interfaces.
  4. Version: HIServices-169~377
  5. Copyright: © 2003-2006 by Apple Computer, Inc., all rights reserved.
  6. }
  7. { Pascal Translation: Gale R Paeper, <[email protected]>, 2006 }
  8. {
  9. Modified for use with Free Pascal
  10. Version 200
  11. Please report any bugs to <[email protected]>
  12. }
  13. {$mode macpas}
  14. {$packenum 1}
  15. {$macro on}
  16. {$inline on}
  17. {$CALLING MWPASCAL}
  18. unit TranslationServices;
  19. interface
  20. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  21. {$setc GAP_INTERFACES_VERSION := $0200}
  22. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  23. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  24. {$endc}
  25. {$ifc defined CPUPOWERPC and defined CPUI386}
  26. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  27. {$endc}
  28. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  29. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  30. {$endc}
  31. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  32. {$setc __ppc__ := 1}
  33. {$elsec}
  34. {$setc __ppc__ := 0}
  35. {$endc}
  36. {$ifc not defined __i386__ and defined CPUI386}
  37. {$setc __i386__ := 1}
  38. {$elsec}
  39. {$setc __i386__ := 0}
  40. {$endc}
  41. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  42. {$error Conflicting definitions for __ppc__ and __i386__}
  43. {$endc}
  44. {$ifc defined __ppc__ and __ppc__}
  45. {$setc TARGET_CPU_PPC := TRUE}
  46. {$setc TARGET_CPU_X86 := FALSE}
  47. {$elifc defined __i386__ and __i386__}
  48. {$setc TARGET_CPU_PPC := FALSE}
  49. {$setc TARGET_CPU_X86 := TRUE}
  50. {$elsec}
  51. {$error Neither __ppc__ nor __i386__ is defined.}
  52. {$endc}
  53. {$setc TARGET_CPU_PPC_64 := FALSE}
  54. {$ifc defined FPC_BIG_ENDIAN}
  55. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  56. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  57. {$elifc defined FPC_LITTLE_ENDIAN}
  58. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  59. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  60. {$elsec}
  61. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  62. {$endc}
  63. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  64. {$setc CALL_NOT_IN_CARBON := FALSE}
  65. {$setc OLDROUTINENAMES := FALSE}
  66. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  67. {$setc OPAQUE_UPP_TYPES := TRUE}
  68. {$setc OTCARBONAPPLICATION := TRUE}
  69. {$setc OTKERNEL := FALSE}
  70. {$setc PM_USE_SESSION_APIS := TRUE}
  71. {$setc TARGET_API_MAC_CARBON := TRUE}
  72. {$setc TARGET_API_MAC_OS8 := FALSE}
  73. {$setc TARGET_API_MAC_OSX := TRUE}
  74. {$setc TARGET_CARBON := TRUE}
  75. {$setc TARGET_CPU_68K := FALSE}
  76. {$setc TARGET_CPU_MIPS := FALSE}
  77. {$setc TARGET_CPU_SPARC := FALSE}
  78. {$setc TARGET_OS_MAC := TRUE}
  79. {$setc TARGET_OS_UNIX := FALSE}
  80. {$setc TARGET_OS_WIN32 := FALSE}
  81. {$setc TARGET_RT_MAC_68881 := FALSE}
  82. {$setc TARGET_RT_MAC_CFM := FALSE}
  83. {$setc TARGET_RT_MAC_MACHO := TRUE}
  84. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  85. {$setc TYPE_BOOL := FALSE}
  86. {$setc TYPE_EXTENDED := FALSE}
  87. {$setc TYPE_LONGLONG := TRUE}
  88. uses MacTypes, CFArray, CFBase, CFData, CFDictionary, CFURL, Files;
  89. {$ALIGN POWER}
  90. {
  91. * TranslationServices
  92. *
  93. * Discussion:
  94. * Translation Services provides tools for conversion of data and
  95. * file contents from one format to another. All information for
  96. * performing a translation is contained within a TranslationRef.
  97. * These include source and destination data types, flags indicating
  98. * what type of translation can be performed and references to the
  99. * system services which execute the translation. TranslationRefs
  100. * are CFTypes which must be released after they are created. Source
  101. * and destination formats as well as translation flags can be
  102. * queried from the TranslationRef. TranslationRefs are generated
  103. * either by requesting a specific translation via TranslationCreate
  104. * or during discovery of all possible translations via
  105. * TranslationCreateWithSourceArray. It is possible to request
  106. * TranslationRefs which perform either data or file conversions or
  107. * both by using TranslationFlags. When requesting a translation be
  108. * executed via TranslationPerformForData, TranslationPerformForFile
  109. * or TranslationPerformForURL it is important for the source and
  110. * destination data formats to match those found in the
  111. * TranslationRef.
  112. *
  113. * It is possible to extend the set of system services which provide
  114. * translations by creating what is called a filter service. Filter
  115. * services are applications similar to those which provide the
  116. * services available in the application menu but with a few
  117. * modifications in the application plist. Filter services provide
  118. * an "NSFilter" entry instead of "NSMessage". Filter Services must
  119. * also provide an array of both "NSSendTypes" and "NSReturnTypes"
  120. * containing Uniform Type Identifiers indicating from which formats
  121. * a filter services translates to what format. Each filter service
  122. * may translate multiple send types into a single return type.
  123. * Finally, a filter service must indicate what type of translations
  124. * it supports via the "NSSupportsDataTranslation" and
  125. * "NSSupportsFileTranslation" entries. In the end, a filter
  126. * service's plist may look like the following,
  127. *
  128. *
  129. *
  130. * <key>NSServices</key>
  131. * <array>
  132. * <dict>
  133. * <key>NSFilter</key>
  134. * <string>ExampleTranslation</string>
  135. * <key>NSReturnTypes</key>
  136. * <array>
  137. * <string>com.example.returntype</string>
  138. * </array>
  139. * <key>NSSendTypes</key>
  140. * <array>
  141. * <string>com.example.sourcetype1</string>
  142. * <string>com.example.sourcetype2</string>
  143. * </array>
  144. * <key>NSSupportsDataTranslation</key>
  145. * <string></string>
  146. * <key>NSSupportsFileTranslation</key>
  147. * <string></string>
  148. * </dict>
  149. <array>
  150. *
  151. *
  152. *
  153. * All filter services must handle the kEventServicePerform Carbon
  154. * Event. The filter service will be automatically launched when
  155. * necessary and it will receive the kEventServicePerform event with
  156. * the message indicated by the NSFilter tag in the plist as well as
  157. * a Pasteboard Manager pasteboard containing flavors indicating
  158. * what type of translation must be performed. If a filter service
  159. * only supports data translations a flavor on the pasteboard will
  160. * correspond to one of the type identifiers listed in your plist's
  161. * send types. Upon translation of the data, the filter service
  162. * must clear the pasteboard, add the return identifier and
  163. * translated data to the pasteboard, and return from the event. For
  164. * a filter service which provides file translations,
  165. * "public.file-url" and "com.apple.file-contents-type" will be
  166. * available on the pasteboard indicating the file location and
  167. * contents format from which to translate. Upon translation, the
  168. * filter service should place a "public.file-url" flavor on the
  169. * pasteboard indicating where the translated file has been placed,
  170. * typically next to the orignal named "<filename> (converted)"
  171. * (ala. Finder's "<filename> copy" behavior for duplicated files).
  172. }
  173. type
  174. TranslationRef = ^SInt32; { an opaque 32-bit type }
  175. { Translation Services error codes}
  176. const
  177. {invalidTranslationPathErr = -3025}
  178. {couldNotParseSourceFileErr = -3026}
  179. {noTranslationPathErr = -3030 // no translation for source and destination provided}
  180. {badTranslationSpecErr = -3031}
  181. {noPrefAppErr = -3032}
  182. badTranslationRefErr = -3031; { TranslationRef does not perform translation requested}
  183. {
  184. * TranslationFlags
  185. *
  186. * Summary:
  187. * The following constants are used by the translation creation
  188. * routines to indicate which types of translations are requested.
  189. * The flags are cumulative (ie. when passing both
  190. * kTranslationDataTranslation and kTranslationFileTranslation the
  191. * client is requesting only those translations which support both
  192. * data AND file translations).
  193. }
  194. type
  195. TranslationFlags = UInt32;
  196. const
  197. {
  198. * Indicates that the client is interested in translations which
  199. * provide data translations.
  200. }
  201. kTranslationDataTranslation = 1 shl 0;
  202. {
  203. * Indicates that the client is interested in translations which
  204. * provide file translations.
  205. }
  206. kTranslationFileTranslation = 1 shl 1;
  207. {
  208. * TranslationGetTypeID()
  209. *
  210. * Summary:
  211. * Returns the CFType identifier for a translation object.
  212. *
  213. * Mac OS X threading:
  214. * Not thread safe
  215. *
  216. * Result:
  217. * A CFTypeID unique to translation instances.
  218. *
  219. * Availability:
  220. * Mac OS X: in version 10.3 and later in ApplicationServices.framework
  221. * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.3 and later
  222. * Non-Carbon CFM: not available
  223. }
  224. function TranslationGetTypeID: CFTypeID; external name '_TranslationGetTypeID';
  225. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  226. {
  227. * TranslationCreate()
  228. *
  229. * Summary:
  230. * Creates a translation reference describing a system service
  231. * providing translations of data from the source type to the
  232. * destination type.
  233. *
  234. * Mac OS X threading:
  235. * Not thread safe
  236. *
  237. * Parameters:
  238. *
  239. * inSourceType:
  240. * A Uniform Type Identifier specifying the format of source data
  241. * to be translated.
  242. *
  243. * inDestinationType:
  244. * A Uniform Type Identifier specifying the destination format to
  245. * which the source data should be translated.
  246. *
  247. * inTranslationFlags:
  248. * A set of TranslationFlags indicating what type of translation
  249. * is requested.
  250. *
  251. * outTranslation:
  252. * A TranslationRef reference which receives the requested
  253. * translation if a system service providing the translation
  254. * exists.
  255. *
  256. * Result:
  257. * An operating system result code.
  258. *
  259. * Availability:
  260. * Mac OS X: in version 10.3 and later in ApplicationServices.framework
  261. * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.3 and later
  262. * Non-Carbon CFM: not available
  263. }
  264. function TranslationCreate( inSourceType: CFStringRef; inDestinationType: CFStringRef; inTranslationFlags: TranslationFlags; var outTranslation: TranslationRef ): OSStatus; external name '_TranslationCreate';
  265. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  266. {
  267. * TranslationCreateWithSourceArray()
  268. *
  269. * Summary:
  270. * Creates a list of destination flavors translation references
  271. * describing various system services providing translations of data
  272. * from the source types to the destination types.
  273. *
  274. * Mac OS X threading:
  275. * Not thread safe
  276. *
  277. * Parameters:
  278. *
  279. * inSourceTypes:
  280. * An array of Uniform Type Identifiers specifying the formats of
  281. * source data to be translated.
  282. *
  283. * inTranslationFlags:
  284. * A set of TranslationFlags indicating what type of translations
  285. * are requested.
  286. *
  287. * outDestinationTypes:
  288. * A CFArrayRef reference which receives an array of Uniform Type
  289. * Identifiers specifying what destination formats are available
  290. * as translations of the provided source formats. Any destination
  291. * formats already represented as a format in the source array are
  292. * excluded from the returned list. The search for destination
  293. * formats is performed in the order of source formats. This array
  294. * must be released by the client.
  295. *
  296. * outTranslations:
  297. * A CFDictionaryRef reference which receives a dictionary of
  298. * TranslationRefs representing all translations provided by
  299. * system services. The dictionary is keyed by destination flavor.
  300. * Any translations with destination formats already represented
  301. * as a format in the source array are excluded from the returned
  302. * dictionary. This dictionary must be released by the client.
  303. *
  304. * Result:
  305. * An operating system result code.
  306. *
  307. * Availability:
  308. * Mac OS X: in version 10.3 and later in ApplicationServices.framework
  309. * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.3 and later
  310. * Non-Carbon CFM: not available
  311. }
  312. function TranslationCreateWithSourceArray( inSourceTypes: CFArrayRef; inTranslationFlags: TranslationFlags; var outDestinationTypes: CFArrayRef; var outTranslations: CFDictionaryRef ): OSStatus; external name '_TranslationCreateWithSourceArray';
  313. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  314. {
  315. * TranslationPerformForData()
  316. *
  317. * Summary:
  318. * Executes the translation of source data into destination data.
  319. * The formats of the source and destination data are contained
  320. * within the TranslationRef.
  321. *
  322. * Mac OS X threading:
  323. * Not thread safe
  324. *
  325. * Parameters:
  326. *
  327. * inTranslation:
  328. * A TranslationRef containing information on the source and
  329. * destination data formats and how to execute a translation from
  330. * one to the other. The formats of the source and destination
  331. * data must correspond to those indicated by the TranslationRef.
  332. *
  333. * inSourceData:
  334. * A CFDataRef containing data to be translated.
  335. *
  336. * outDestinationData:
  337. * A CFDataRef reference which receives the translated data.
  338. *
  339. * Result:
  340. * An operating system result code.
  341. *
  342. * Availability:
  343. * Mac OS X: in version 10.3 and later in ApplicationServices.framework
  344. * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.3 and later
  345. * Non-Carbon CFM: not available
  346. }
  347. function TranslationPerformForData( inTranslation: TranslationRef; inSourceData: CFDataRef; var outDestinationData: CFDataRef ): OSStatus; external name '_TranslationPerformForData';
  348. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  349. {
  350. * TranslationPerformForFile()
  351. *
  352. * Summary:
  353. * Executes the translation of source file contents to a destination
  354. * file content format. The formats of the source and destination
  355. * file contents are held within the TranslationRef.
  356. *
  357. * Mac OS X threading:
  358. * Not thread safe
  359. *
  360. * Parameters:
  361. *
  362. * inTranslation:
  363. * A TranslationRef containing information on the source and
  364. * destination file content formats and how to execute a
  365. * translation from one to the other. The formats of the source
  366. * and destination file contents must correspond to those
  367. * indicated by the TranslationRef.
  368. *
  369. * inSourceFile:
  370. * A FSRef reference pointing to a file whose contents are to be
  371. * translated.
  372. *
  373. * inDestinationDirectory:
  374. * An optional FSRef reference pointing to the desired directory
  375. * for the translation. By default the destination directory is
  376. * the same as the source file.
  377. *
  378. * inDestinationName:
  379. * An optional CFStringRef indicating the desired name for the
  380. * translated file. By default the translated file's name will be
  381. * "<filename> (converted)" (ala. Finder's "<filename> copy"
  382. * behavior for duplicated files).
  383. *
  384. * outTranslatedFile:
  385. * A FSRef reference which receives a new file with the translated
  386. * contents. It is possible for the translated file to not have
  387. * been created in the directory or with the name requested by the
  388. * client due to disk space or translator limitations. It is
  389. * important to rely only on the file reference returned in this
  390. * parameter.
  391. *
  392. * Result:
  393. * An operating system result code.
  394. *
  395. * Availability:
  396. * Mac OS X: in version 10.3 and later in ApplicationServices.framework
  397. * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.3 and later
  398. * Non-Carbon CFM: not available
  399. }
  400. function TranslationPerformForFile( inTranslation: TranslationRef; const (*var*) inSourceFile: FSRef; {const} inDestinationDirectory: FSRefPtr { can be NULL }; inDestinationName: CFStringRef { can be NULL }; var outTranslatedFile: FSRef ): OSStatus; external name '_TranslationPerformForFile';
  401. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  402. {
  403. * TranslationPerformForURL()
  404. *
  405. * Summary:
  406. * Executes the translation of source data pointed to a URL to a
  407. * destination format. The formats of the source and destination URL
  408. * contents are held within the TranslationRef. Currently, only file
  409. * URLs are accepted for URL translations.
  410. *
  411. * Mac OS X threading:
  412. * Not thread safe
  413. *
  414. * Parameters:
  415. *
  416. * inTranslation:
  417. * A TranslationRef containing information on the source and
  418. * destination URL content formats and how to execute a
  419. * translation from one to the other. The formats of the source
  420. * and destination URL contents must correspond to those indicated
  421. * by the TranslationRef.
  422. *
  423. * inSourceURL:
  424. * A CFURLRef pointing to source data whose contents are to be
  425. * translated. Currently, only file URLs are accepted for URL
  426. * translations.
  427. *
  428. * inDestinationURL:
  429. * An optional CFURLRef indicating the desired location for the
  430. * translated data. File URLs may either indicate the desired
  431. * destination directory or directory and name for the translated
  432. * file. By default for file URLs, the translated file's name will
  433. * be "<filename> (converted)" (ala. Finder's "<filename> copy"
  434. * behavior for duplicated files).
  435. *
  436. * outTranslatedURL:
  437. * A FSRef reference which receives a new file with the translated
  438. * contents. For file URLs, it is possible for the translated file
  439. * to not have been created in the directory or with the name
  440. * requested by the client due to disk space or translator
  441. * limitations. It is important to rely only on the URL returned
  442. * in this parameter.
  443. *
  444. * Result:
  445. * An operating system result code.
  446. *
  447. * Availability:
  448. * Mac OS X: in version 10.3 and later in ApplicationServices.framework
  449. * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.3 and later
  450. * Non-Carbon CFM: not available
  451. }
  452. function TranslationPerformForURL( inTranslation: TranslationRef; inSourceURL: CFURLRef; inDestinationURL: CFURLRef { can be NULL }; var outTranslatedURL: CFURLRef ): OSStatus; external name '_TranslationPerformForURL';
  453. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  454. {
  455. * TranslationCopySourceType()
  456. *
  457. * Summary:
  458. * Accesses a translation's source type.
  459. *
  460. * Mac OS X threading:
  461. * Not thread safe
  462. *
  463. * Parameters:
  464. *
  465. * inTranslation:
  466. * A TranslationRef containing the requested source type.
  467. *
  468. * outSourceType:
  469. * A CFStringRef which receives the TranslationRef's source type.
  470. *
  471. * Result:
  472. * An operating system result code.
  473. *
  474. * Availability:
  475. * Mac OS X: in version 10.3 and later in ApplicationServices.framework
  476. * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.3 and later
  477. * Non-Carbon CFM: not available
  478. }
  479. function TranslationCopySourceType( inTranslation: TranslationRef; var outSourceType: CFStringRef ): OSStatus; external name '_TranslationCopySourceType';
  480. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  481. {
  482. * TranslationCopyDestinationType()
  483. *
  484. * Summary:
  485. * Accesses a translation's destination type.
  486. *
  487. * Mac OS X threading:
  488. * Not thread safe
  489. *
  490. * Parameters:
  491. *
  492. * inTranslation:
  493. * A TranslationRef containing the requested destination type.
  494. *
  495. * outDestinationType:
  496. * A CFStringRef which receives the TranslationRef's destination
  497. * type.
  498. *
  499. * Result:
  500. * An operating system result code.
  501. *
  502. * Availability:
  503. * Mac OS X: in version 10.3 and later in ApplicationServices.framework
  504. * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.3 and later
  505. * Non-Carbon CFM: not available
  506. }
  507. function TranslationCopyDestinationType( inTranslation: TranslationRef; var outDestinationType: CFStringRef ): OSStatus; external name '_TranslationCopyDestinationType';
  508. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  509. {
  510. * TranslationGetTranslationFlags()
  511. *
  512. * Summary:
  513. * Accesses a translation's flags.
  514. *
  515. * Mac OS X threading:
  516. * Not thread safe
  517. *
  518. * Parameters:
  519. *
  520. * inTranslation:
  521. * A TranslationRef containing the requested flags.
  522. *
  523. * outTranslationFlags:
  524. * A TranslationFlags which receives the TranslationRef's flags.
  525. *
  526. * Result:
  527. * An operating system result code.
  528. *
  529. * Availability:
  530. * Mac OS X: in version 10.3 and later in ApplicationServices.framework
  531. * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.3 and later
  532. * Non-Carbon CFM: not available
  533. }
  534. function TranslationGetTranslationFlags( inTranslation: TranslationRef; var outTranslationFlags: TranslationFlags ): OSStatus; external name '_TranslationGetTranslationFlags';
  535. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  536. end.