/packages/univint/src/CFAttributedString.pas

https://github.com/slibre/freepascal · Pascal · 332 lines · 29 code · 42 blank · 261 comment · 0 complexity · d5dd38f7c37dd82c22c68aad76d1c624 MD5 · raw file

  1. { CFAttributedString.h
  2. Copyright (c) 2004-2012, Apple Inc. All rights reserved.
  3. }
  4. { Pascal Translation: Peter N Lewis, <peter@stairways.com.au>, August 2005 }
  5. { Pascal Translation Updated: Gorazd Krosl, <gorazd_1957@yahoo.ca>, October 2009 }
  6. { Pascal Translation Updated: Jonas Maebe, <jonas@freepascal.org>, October 2009 }
  7. { Pascal Translation Updated: Jonas Maebe <jonas@freepascal.org>, September 2012 }
  8. {
  9. Modified for use with Free Pascal
  10. Version 308
  11. Please report any bugs to <gpc@microbizz.nl>
  12. }
  13. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  14. {$mode macpas}
  15. {$packenum 1}
  16. {$macro on}
  17. {$inline on}
  18. {$calling mwpascal}
  19. unit CFAttributedString;
  20. interface
  21. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  22. {$setc GAP_INTERFACES_VERSION := $0308}
  23. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  24. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  25. {$endc}
  26. {$ifc defined CPUPOWERPC and defined CPUI386}
  27. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  28. {$endc}
  29. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  30. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  31. {$endc}
  32. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  33. {$setc __ppc__ := 1}
  34. {$elsec}
  35. {$setc __ppc__ := 0}
  36. {$endc}
  37. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  38. {$setc __ppc64__ := 1}
  39. {$elsec}
  40. {$setc __ppc64__ := 0}
  41. {$endc}
  42. {$ifc not defined __i386__ and defined CPUI386}
  43. {$setc __i386__ := 1}
  44. {$elsec}
  45. {$setc __i386__ := 0}
  46. {$endc}
  47. {$ifc not defined __x86_64__ and defined CPUX86_64}
  48. {$setc __x86_64__ := 1}
  49. {$elsec}
  50. {$setc __x86_64__ := 0}
  51. {$endc}
  52. {$ifc not defined __arm__ and defined CPUARM}
  53. {$setc __arm__ := 1}
  54. {$elsec}
  55. {$setc __arm__ := 0}
  56. {$endc}
  57. {$ifc defined cpu64}
  58. {$setc __LP64__ := 1}
  59. {$elsec}
  60. {$setc __LP64__ := 0}
  61. {$endc}
  62. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  63. {$error Conflicting definitions for __ppc__ and __i386__}
  64. {$endc}
  65. {$ifc defined __ppc__ and __ppc__}
  66. {$setc TARGET_CPU_PPC := TRUE}
  67. {$setc TARGET_CPU_PPC64 := FALSE}
  68. {$setc TARGET_CPU_X86 := FALSE}
  69. {$setc TARGET_CPU_X86_64 := FALSE}
  70. {$setc TARGET_CPU_ARM := FALSE}
  71. {$setc TARGET_OS_MAC := TRUE}
  72. {$setc TARGET_OS_IPHONE := FALSE}
  73. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  74. {$setc TARGET_OS_EMBEDDED := FALSE}
  75. {$elifc defined __ppc64__ and __ppc64__}
  76. {$setc TARGET_CPU_PPC := FALSE}
  77. {$setc TARGET_CPU_PPC64 := TRUE}
  78. {$setc TARGET_CPU_X86 := FALSE}
  79. {$setc TARGET_CPU_X86_64 := FALSE}
  80. {$setc TARGET_CPU_ARM := FALSE}
  81. {$setc TARGET_OS_MAC := TRUE}
  82. {$setc TARGET_OS_IPHONE := FALSE}
  83. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  84. {$setc TARGET_OS_EMBEDDED := FALSE}
  85. {$elifc defined __i386__ and __i386__}
  86. {$setc TARGET_CPU_PPC := FALSE}
  87. {$setc TARGET_CPU_PPC64 := FALSE}
  88. {$setc TARGET_CPU_X86 := TRUE}
  89. {$setc TARGET_CPU_X86_64 := FALSE}
  90. {$setc TARGET_CPU_ARM := FALSE}
  91. {$ifc defined(iphonesim)}
  92. {$setc TARGET_OS_MAC := FALSE}
  93. {$setc TARGET_OS_IPHONE := TRUE}
  94. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  95. {$elsec}
  96. {$setc TARGET_OS_MAC := TRUE}
  97. {$setc TARGET_OS_IPHONE := FALSE}
  98. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  99. {$endc}
  100. {$setc TARGET_OS_EMBEDDED := FALSE}
  101. {$elifc defined __x86_64__ and __x86_64__}
  102. {$setc TARGET_CPU_PPC := FALSE}
  103. {$setc TARGET_CPU_PPC64 := FALSE}
  104. {$setc TARGET_CPU_X86 := FALSE}
  105. {$setc TARGET_CPU_X86_64 := TRUE}
  106. {$setc TARGET_CPU_ARM := FALSE}
  107. {$setc TARGET_OS_MAC := TRUE}
  108. {$setc TARGET_OS_IPHONE := FALSE}
  109. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  110. {$setc TARGET_OS_EMBEDDED := FALSE}
  111. {$elifc defined __arm__ and __arm__}
  112. {$setc TARGET_CPU_PPC := FALSE}
  113. {$setc TARGET_CPU_PPC64 := FALSE}
  114. {$setc TARGET_CPU_X86 := FALSE}
  115. {$setc TARGET_CPU_X86_64 := FALSE}
  116. {$setc TARGET_CPU_ARM := TRUE}
  117. { will require compiler define when/if other Apple devices with ARM cpus ship }
  118. {$setc TARGET_OS_MAC := FALSE}
  119. {$setc TARGET_OS_IPHONE := TRUE}
  120. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  121. {$setc TARGET_OS_EMBEDDED := TRUE}
  122. {$elsec}
  123. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ is defined.}
  124. {$endc}
  125. {$ifc defined __LP64__ and __LP64__ }
  126. {$setc TARGET_CPU_64 := TRUE}
  127. {$elsec}
  128. {$setc TARGET_CPU_64 := FALSE}
  129. {$endc}
  130. {$ifc defined FPC_BIG_ENDIAN}
  131. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  132. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  133. {$elifc defined FPC_LITTLE_ENDIAN}
  134. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  135. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  136. {$elsec}
  137. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  138. {$endc}
  139. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  140. {$setc CALL_NOT_IN_CARBON := FALSE}
  141. {$setc OLDROUTINENAMES := FALSE}
  142. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  143. {$setc OPAQUE_UPP_TYPES := TRUE}
  144. {$setc OTCARBONAPPLICATION := TRUE}
  145. {$setc OTKERNEL := FALSE}
  146. {$setc PM_USE_SESSION_APIS := TRUE}
  147. {$setc TARGET_API_MAC_CARBON := TRUE}
  148. {$setc TARGET_API_MAC_OS8 := FALSE}
  149. {$setc TARGET_API_MAC_OSX := TRUE}
  150. {$setc TARGET_CARBON := TRUE}
  151. {$setc TARGET_CPU_68K := FALSE}
  152. {$setc TARGET_CPU_MIPS := FALSE}
  153. {$setc TARGET_CPU_SPARC := FALSE}
  154. {$setc TARGET_OS_UNIX := FALSE}
  155. {$setc TARGET_OS_WIN32 := FALSE}
  156. {$setc TARGET_RT_MAC_68881 := FALSE}
  157. {$setc TARGET_RT_MAC_CFM := FALSE}
  158. {$setc TARGET_RT_MAC_MACHO := TRUE}
  159. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  160. {$setc TYPE_BOOL := FALSE}
  161. {$setc TYPE_EXTENDED := FALSE}
  162. {$setc TYPE_LONGLONG := TRUE}
  163. uses MacTypes,CFBase,CFString,CFDictionary;
  164. {$endc} {not MACOSALLINCLUDE}
  165. {$ALIGN POWER}
  166. {! @header CFAttributedString
  167. Instances of CFAttributedString manage character strings and associated sets of attributes (for example, font and kerning) that apply to individual characters or ranges of characters in the string. CFAttributedString as defined in CoreFoundation provides the basic container functionality, while higher levels provide definitions for standard attributes, their values, and additional behaviors involving these.
  168. CFAttributedString is not a "subclass" of CFString; that is, it does not respond to CFString function calls. CFAttributedString conceptually contains a CFString to which it applies attributes. This protects users of attributed strings from ambiguities caused by the semantic differences between simple and attributed strings.
  169. Attributes are identified by key/value pairs stored in CFDictionaryRefs. Keys must be CFStrings, while the values are arbitrary CFTypeRefs.
  170. }
  171. { CFAttributedString comes in immutable and mutable flavors.
  172. }
  173. type
  174. CFAttributedStringRef = ^__CFAttributedString; { an opaque type }
  175. __CFAttributedString = record end;
  176. CFMutableAttributedStringRef = ^__CFMutableAttributedString; { an opaque type }
  177. __CFMutableAttributedString = record end;
  178. {! @function CFAttributedStringGetTypeID
  179. Returns the type identifier of all CFAttributedString instances.
  180. }
  181. function CFAttributedStringGetTypeID: CFTypeID; external name '_CFAttributedStringGetTypeID';
  182. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  183. {** CFAttributedString **}
  184. {! @function CFAttributedStringCreate
  185. Creates an attributed string with the specified string and attributes (both copied).
  186. }
  187. function CFAttributedStringCreate( alloc: CFAllocatorRef; str: CFStringRef; attributes: CFDictionaryRef ): CFAttributedStringRef; external name '_CFAttributedStringCreate';
  188. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  189. {! @function CFAttributedStringCreateWithSubstring
  190. Creates a sub-attributed string from the specified range. It's a programming error for range to specify characters outside the bounds of aStr.
  191. }
  192. function CFAttributedStringCreateWithSubstring( alloc: CFAllocatorRef; aStr: CFAttributedStringRef; range: CFRange ): CFAttributedStringRef; external name '_CFAttributedStringCreateWithSubstring';
  193. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  194. {! @function CFAttributedStringCreateCopy
  195. Creates an immutable attributed string copy.
  196. }
  197. function CFAttributedStringCreateCopy( alloc: CFAllocatorRef; aStr: CFAttributedStringRef ): CFAttributedStringRef; external name '_CFAttributedStringCreateCopy';
  198. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  199. {! @function CFAttributedStringGetString
  200. Returns the string for the attributed string. For performance reasons, this will often point at the backing store of the attributed string, and it might change if the attributed string is edited. However, this is an implementation detail, and definitely not something that should be counted on.
  201. }
  202. function CFAttributedStringGetString( aStr: CFAttributedStringRef ): CFStringRef; external name '_CFAttributedStringGetString';
  203. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  204. {! @function CFAttributedStringGetLength
  205. Returns the length of the attributed string in characters; same as CFStringGetLength(CFAttributedStringGetString(aStr))
  206. }
  207. function CFAttributedStringGetLength( aStr: CFAttributedStringRef ): CFIndex; external name '_CFAttributedStringGetLength';
  208. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  209. {! @function CFAttributedStringGetAttributes
  210. Returns the attributes at the specified location. If effectiveRange is not NULL, upon return *effectiveRange contains a range over which the exact same set of attributes apply. Note that for performance reasons, the returned effectiveRange is not necessarily the maximal range - for that, use CFAttributedStringGetAttributesAndLongestEffectiveRange(). It's a programming error for loc to specify a location outside the bounds of the attributed string.
  211. Note that the returned attribute dictionary might change in unpredictable ways from under the caller if the attributed string is edited after this call. If you wish to hang on to the dictionary long-term, you should make an actual copy of it rather than just retaining it. Also, no assumptions should be made about the relationship of the actual CFDictionaryRef returned by this call and the dictionary originally used to set the attributes, other than the fact that the values stored in the dictionary will be identical (that is, ==) to those originally specified.
  212. }
  213. function CFAttributedStringGetAttributes( aStr: CFAttributedStringRef; loc: CFIndex; effectiveRange: CFRangePtr ): CFDictionaryRef; external name '_CFAttributedStringGetAttributes';
  214. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  215. {! @function CFAttributedStringGetAttribute
  216. Returns the value of a single attribute at the specified location. If the specified attribute doesn't exist at the location, returns NULL. If effectiveRange is not NULL, upon return *effectiveRange contains a range over which the exact same attribute value applies. Note that for performance reasons, the returned effectiveRange is not necessarily the maximal range - for that, use CFAttributedStringGetAttributeAndLongestEffectiveRange(). It's a programming error for loc to specify a location outside the bounds of the attributed string.
  217. }
  218. function CFAttributedStringGetAttribute( aStr: CFAttributedStringRef; loc: CFIndex; attrName: CFStringRef; effectiveRange: CFRangePtr ): CFTypeRef; external name '_CFAttributedStringGetAttribute';
  219. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  220. {! @function CFAttributedStringGetAttributesAndLongestEffectiveRange
  221. Returns the attributes at the specified location. If longestEffectiveRange is not NULL, upon return *longestEffectiveRange contains the maximal range within inRange over which the exact same set of attributes apply. The returned range is clipped to inRange. It's a programming error for loc or inRange to specify locations outside the bounds of the attributed string.
  222. }
  223. function CFAttributedStringGetAttributesAndLongestEffectiveRange( aStr: CFAttributedStringRef; loc: CFIndex; inRange: CFRange; longestEffectiveRange: CFRangePtr ): CFDictionaryRef; external name '_CFAttributedStringGetAttributesAndLongestEffectiveRange';
  224. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  225. {! @function CFAttributedStringGetAttributeAndLongestEffectiveRange
  226. Returns the value of a single attribute at the specified location. If longestEffectiveRange is not NULL, upon return *longestEffectiveRange contains the maximal range within inRange over which the exact same attribute value applies. The returned range is clipped to inRange. It's a programming error for loc or inRange to specify locations outside the bounds of the attributed string.
  227. }
  228. function CFAttributedStringGetAttributeAndLongestEffectiveRange( aStr: CFAttributedStringRef; loc: CFIndex; attrName: CFStringRef; inRange: CFRange; longestEffectiveRange: CFRangePtr ): CFTypeRef; external name '_CFAttributedStringGetAttributeAndLongestEffectiveRange';
  229. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  230. {** CFMutableAttributedString **}
  231. {! @function CFAttributedStringCreateMutableCopy
  232. Creates a mutable attributed string copy. maxLength, if not 0, is a hard bound on the length of the attributed string; exceeding this size limit during any editing operation is a programming error. If 0, there is no limit on the length.
  233. }
  234. function CFAttributedStringCreateMutableCopy( alloc: CFAllocatorRef; maxLength: CFIndex; aStr: CFAttributedStringRef ): CFMutableAttributedStringRef; external name '_CFAttributedStringCreateMutableCopy';
  235. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  236. {! @function CFAttributedStringCreateMutable
  237. Creates a mutable empty attributed string. maxLength, if not 0, is a hard bound on the length of the attributed string; exceeding this size limit during any editing operation is a programming error. If 0, there is no limit on the length.
  238. }
  239. function CFAttributedStringCreateMutable( alloc: CFAllocatorRef; maxLength: CFIndex ): CFMutableAttributedStringRef; external name '_CFAttributedStringCreateMutable';
  240. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  241. {! @function CFAttributedStringReplaceString
  242. Modifies the string for the attributed string, much like CFStringReplace(). It's an error for range to specify characters outside the bounds of aStr.
  243. (Note: This function is a convenience on CFAttributedStringGetMutableString(); however, until CFAttributedStringGetMutableString() is implemented, it remains the only way to edit the string of the attributed string.)
  244. }
  245. procedure CFAttributedStringReplaceString( aStr: CFMutableAttributedStringRef; range: CFRange; replacement: CFStringRef ); external name '_CFAttributedStringReplaceString';
  246. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  247. {! @function CFAttributedStringGetMutableString
  248. Gets the string for the attributed string as a mutable string, allowing editing the character contents of the string as if it were an CFMutableString. Attributes corresponding to the edited range are appropriately modified. If, as a result of the edit, new characters are introduced into the string, they inherit the attributes of the first replaced character from range. If no existing characters are replaced by the edit, the new characters inherit the attributes of the character preceding range if it has any, otherwise of the character following range. If the initial string is empty, the attributes for the new characters are also empty.
  249. (Note: This function is not yet implemented and will return NULL except for toll-free bridged instances.)
  250. }
  251. function CFAttributedStringGetMutableString( aStr: CFMutableAttributedStringRef ): CFMutableStringRef; external name '_CFAttributedStringGetMutableString';
  252. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  253. {! @function CFAttributedStringSetAttributes
  254. Sets the value of multiple attributes over the specified range, which should be valid. If clearOtherAttributes is false, existing attributes (which aren't being replaced) are left alone; otherwise they are cleared. The dictionary should be setup for "usual" CF type usage --- CFString keys, and arbitrary CFType values. Note that after this call, further mutations to the replacement dictionary argument by the caller will not affect the contents of the attributed string.
  255. }
  256. procedure CFAttributedStringSetAttributes( aStr: CFMutableAttributedStringRef; range: CFRange; replacement: CFDictionaryRef; clearOtherAttributes: Boolean ); external name '_CFAttributedStringSetAttributes';
  257. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  258. {! @function CFAttributedStringSetAttribute
  259. Sets the value of a single attribute over the specified range, which should be valid. value should not be NULL.
  260. }
  261. procedure CFAttributedStringSetAttribute( aStr: CFMutableAttributedStringRef; range: CFRange; attrName: CFStringRef; value: CFTypeRef ); external name '_CFAttributedStringSetAttribute';
  262. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  263. {! @function CFAttributedStringRemoveAttribute
  264. Removes the value of a single attribute over the specified range, which should be valid. It's OK for the attribute not the exist over the specified range.
  265. }
  266. procedure CFAttributedStringRemoveAttribute( aStr: CFMutableAttributedStringRef; range: CFRange; attrName: CFStringRef ); external name '_CFAttributedStringRemoveAttribute';
  267. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  268. {! @function CFAttributedStringReplaceAttributedString
  269. Replaces the attributed substring over the specified range with the attributed string specified in replacement. range should be valid. To delete a range of the attributed string, call CFAttributedStringReplaceString() with empty string and specified range.
  270. }
  271. procedure CFAttributedStringReplaceAttributedString( aStr: CFMutableAttributedStringRef; range: CFRange; replacement: CFAttributedStringRef ); external name '_CFAttributedStringReplaceAttributedString';
  272. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  273. {! @function CFAttributedStringBeginEditing
  274. In cases where attributed string might do a bunch of work to assure self-consistency, CFAttributedStringBeginEditing/CFAttributedStringEndEditing allow disabling that to allow deferring and coalescing any work. It's a good idea to call these around a set of related mutation calls which don't require the string to be in consistent state in between. These calls can be nested.
  275. }
  276. procedure CFAttributedStringBeginEditing( aStr: CFMutableAttributedStringRef ); external name '_CFAttributedStringBeginEditing';
  277. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  278. {! @function CFAttributedStringEndEditing
  279. In cases where attributed string might do a bunch of work to assure self-consistency, CFAttributedStringBeginEditing/CFAttributedStringEndEditing allow disabling that to allow deferring and coalescing any work. It's a good idea to call these around a set of related mutation calls which don't require the string to be in consistent state in between. These calls can be nested.
  280. }
  281. procedure CFAttributedStringEndEditing( aStr: CFMutableAttributedStringRef ); external name '_CFAttributedStringEndEditing';
  282. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  283. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  284. end.
  285. {$endc} {not MACOSALLINCLUDE}