CFTree.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. { CFTree.h
  2. Copyright (c) 1998-2009, Apple Inc. All rights reserved.
  3. }
  4. { Pascal Translation Updated: Peter N Lewis, <[email protected]>, November 2005 }
  5. { Pascal Translation Updated: Jonas Maebe, <[email protected]>, October 2009 }
  6. {
  7. Modified for use with Free Pascal
  8. Version 308
  9. Please report any bugs to <[email protected]>
  10. }
  11. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  12. {$mode macpas}
  13. {$packenum 1}
  14. {$macro on}
  15. {$inline on}
  16. {$calling mwpascal}
  17. unit CFTree;
  18. interface
  19. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  20. {$setc GAP_INTERFACES_VERSION := $0308}
  21. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  22. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  23. {$endc}
  24. {$ifc defined CPUPOWERPC and defined CPUI386}
  25. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  26. {$endc}
  27. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  28. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  29. {$endc}
  30. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  31. {$setc __ppc__ := 1}
  32. {$elsec}
  33. {$setc __ppc__ := 0}
  34. {$endc}
  35. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  36. {$setc __ppc64__ := 1}
  37. {$elsec}
  38. {$setc __ppc64__ := 0}
  39. {$endc}
  40. {$ifc not defined __i386__ and defined CPUI386}
  41. {$setc __i386__ := 1}
  42. {$elsec}
  43. {$setc __i386__ := 0}
  44. {$endc}
  45. {$ifc not defined __x86_64__ and defined CPUX86_64}
  46. {$setc __x86_64__ := 1}
  47. {$elsec}
  48. {$setc __x86_64__ := 0}
  49. {$endc}
  50. {$ifc not defined __arm__ and defined CPUARM}
  51. {$setc __arm__ := 1}
  52. {$elsec}
  53. {$setc __arm__ := 0}
  54. {$endc}
  55. {$ifc defined cpu64}
  56. {$setc __LP64__ := 1}
  57. {$elsec}
  58. {$setc __LP64__ := 0}
  59. {$endc}
  60. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  61. {$error Conflicting definitions for __ppc__ and __i386__}
  62. {$endc}
  63. {$ifc defined __ppc__ and __ppc__}
  64. {$setc TARGET_CPU_PPC := TRUE}
  65. {$setc TARGET_CPU_PPC64 := FALSE}
  66. {$setc TARGET_CPU_X86 := FALSE}
  67. {$setc TARGET_CPU_X86_64 := FALSE}
  68. {$setc TARGET_CPU_ARM := FALSE}
  69. {$setc TARGET_OS_MAC := TRUE}
  70. {$setc TARGET_OS_IPHONE := FALSE}
  71. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  72. {$elifc defined __ppc64__ and __ppc64__}
  73. {$setc TARGET_CPU_PPC := FALSE}
  74. {$setc TARGET_CPU_PPC64 := TRUE}
  75. {$setc TARGET_CPU_X86 := FALSE}
  76. {$setc TARGET_CPU_X86_64 := FALSE}
  77. {$setc TARGET_CPU_ARM := FALSE}
  78. {$setc TARGET_OS_MAC := TRUE}
  79. {$setc TARGET_OS_IPHONE := FALSE}
  80. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  81. {$elifc defined __i386__ and __i386__}
  82. {$setc TARGET_CPU_PPC := FALSE}
  83. {$setc TARGET_CPU_PPC64 := FALSE}
  84. {$setc TARGET_CPU_X86 := TRUE}
  85. {$setc TARGET_CPU_X86_64 := FALSE}
  86. {$setc TARGET_CPU_ARM := FALSE}
  87. {$ifc defined(iphonesim)}
  88. {$setc TARGET_OS_MAC := FALSE}
  89. {$setc TARGET_OS_IPHONE := TRUE}
  90. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  91. {$elsec}
  92. {$setc TARGET_OS_MAC := TRUE}
  93. {$setc TARGET_OS_IPHONE := FALSE}
  94. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  95. {$endc}
  96. {$elifc defined __x86_64__ and __x86_64__}
  97. {$setc TARGET_CPU_PPC := FALSE}
  98. {$setc TARGET_CPU_PPC64 := FALSE}
  99. {$setc TARGET_CPU_X86 := FALSE}
  100. {$setc TARGET_CPU_X86_64 := TRUE}
  101. {$setc TARGET_CPU_ARM := FALSE}
  102. {$setc TARGET_OS_MAC := TRUE}
  103. {$setc TARGET_OS_IPHONE := FALSE}
  104. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  105. {$elifc defined __arm__ and __arm__}
  106. {$setc TARGET_CPU_PPC := FALSE}
  107. {$setc TARGET_CPU_PPC64 := FALSE}
  108. {$setc TARGET_CPU_X86 := FALSE}
  109. {$setc TARGET_CPU_X86_64 := FALSE}
  110. {$setc TARGET_CPU_ARM := TRUE}
  111. { will require compiler define when/if other Apple devices with ARM cpus ship }
  112. {$setc TARGET_OS_MAC := FALSE}
  113. {$setc TARGET_OS_IPHONE := TRUE}
  114. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  115. {$elsec}
  116. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ is defined.}
  117. {$endc}
  118. {$ifc defined __LP64__ and __LP64__ }
  119. {$setc TARGET_CPU_64 := TRUE}
  120. {$elsec}
  121. {$setc TARGET_CPU_64 := FALSE}
  122. {$endc}
  123. {$ifc defined FPC_BIG_ENDIAN}
  124. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  125. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  126. {$elifc defined FPC_LITTLE_ENDIAN}
  127. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  128. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  129. {$elsec}
  130. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  131. {$endc}
  132. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  133. {$setc CALL_NOT_IN_CARBON := FALSE}
  134. {$setc OLDROUTINENAMES := FALSE}
  135. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  136. {$setc OPAQUE_UPP_TYPES := TRUE}
  137. {$setc OTCARBONAPPLICATION := TRUE}
  138. {$setc OTKERNEL := FALSE}
  139. {$setc PM_USE_SESSION_APIS := TRUE}
  140. {$setc TARGET_API_MAC_CARBON := TRUE}
  141. {$setc TARGET_API_MAC_OS8 := FALSE}
  142. {$setc TARGET_API_MAC_OSX := TRUE}
  143. {$setc TARGET_CARBON := TRUE}
  144. {$setc TARGET_CPU_68K := FALSE}
  145. {$setc TARGET_CPU_MIPS := FALSE}
  146. {$setc TARGET_CPU_SPARC := FALSE}
  147. {$setc TARGET_OS_UNIX := FALSE}
  148. {$setc TARGET_OS_WIN32 := FALSE}
  149. {$setc TARGET_RT_MAC_68881 := FALSE}
  150. {$setc TARGET_RT_MAC_CFM := FALSE}
  151. {$setc TARGET_RT_MAC_MACHO := TRUE}
  152. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  153. {$setc TYPE_BOOL := FALSE}
  154. {$setc TYPE_EXTENDED := FALSE}
  155. {$setc TYPE_LONGLONG := TRUE}
  156. uses MacTypes,CFBase;
  157. {$endc} {not MACOSALLINCLUDE}
  158. {$ALIGN POWER}
  159. {!
  160. @header CFTree
  161. CFTree implements a container which stores references to other CFTrees.
  162. Each tree may have a parent, and a variable number of children.
  163. }
  164. {!
  165. @typedef CFTreeRetainCallBack
  166. Type of the callback function used to add a retain to the user-specified
  167. info parameter. This callback may returns the value to use whenever the
  168. info parameter is retained, which is usually the value parameter passed
  169. to this callback, but may be a different value if a different value
  170. should be used.
  171. @param info A user-supplied info parameter provided in a CFTreeContext.
  172. @result The retained info parameter.
  173. }
  174. type
  175. CFTreeRetainCallBack = function( info: {const} UnivPtr ): UnivPtr;
  176. {!
  177. @typedef CFTreeReleaseCallBack
  178. Type of the callback function used to remove a retain previously
  179. added to the user-specified info parameter.
  180. @param info A user-supplied info parameter provided in a CFTreeContext.
  181. }
  182. type
  183. CFTreeReleaseCallBack = procedure( info: {const} UnivPtr );
  184. {!
  185. @typedef CFTreeCopyDescriptionCallBack
  186. Type of the callback function used to provide a description of the
  187. user-specified info parameter.
  188. @param info A user-supplied info parameter provided in a CFTreeContext.
  189. @result A description of the info parameter.
  190. }
  191. type
  192. CFTreeCopyDescriptionCallBack = function( info: {const} UnivPtr ): CFStringRef;
  193. {!
  194. @typedef CFTreeContext
  195. Structure containing user-specified data and callbacks for a CFTree.
  196. @field version The version number of the structure type being passed
  197. in as a parameter to the CFTree creation function.
  198. This structure is version 0.
  199. @field info A C pointer to a user-specified block of data.
  200. @field retain The callback used to add a retain for the info field.
  201. If this parameter is not a pointer to a function of the correct
  202. prototype, the behavior is undefined. The value may be NULL.
  203. @field release The calllback used to remove a retain previously added
  204. for the info field. If this parameter is not a pointer to a
  205. function of the correct prototype, the behavior is undefined.
  206. The value may be NULL.
  207. @field copyDescription The callback used to provide a description of
  208. the info field.
  209. }
  210. type
  211. CFTreeContext = record
  212. version: CFIndex;
  213. info: UnivPtr;
  214. retain: CFTreeRetainCallBack;
  215. release: CFTreeReleaseCallBack;
  216. copyDescription: CFTreeCopyDescriptionCallBack;
  217. end;
  218. CFTreeContextPtr = ^CFTreeContext;
  219. {!
  220. @typedef CFTreeApplierFunction
  221. Type of the callback function used by the apply functions of
  222. CFTree.
  223. @param value The current value from the CFTree
  224. @param context The user-defined context parameter give to the apply
  225. function.
  226. }
  227. type
  228. CFTreeApplierFunction = procedure( value: {const} UnivPtr; context: UnivPtr );
  229. {!
  230. @typedef CFTreeRef
  231. This is the type of a reference to CFTrees.
  232. }
  233. type
  234. CFTreeRef = ^SInt32; { an opaque type }
  235. CFTreeRefPtr = ^CFTreeRef;
  236. {!
  237. @function CFTreeGetTypeID
  238. Returns the type identifier of all CFTree instances.
  239. }
  240. function CFTreeGetTypeID: CFTypeID; external name '_CFTreeGetTypeID';
  241. {!
  242. @function CFTreeCreate
  243. Creates a new mutable tree.
  244. @param allocator The CFAllocator which should be used to allocate
  245. memory for the tree and storage for its children. This
  246. parameter may be NULL in which case the current default
  247. CFAllocator is used. If this reference is not a valid
  248. CFAllocator, the behavior is undefined.
  249. @param context A C pointer to a CFTreeContext structure to be copied
  250. and used as the context of the new tree. The info parameter
  251. will be retained by the tree if a retain function is provided.
  252. If this value is not a valid C pointer to a CFTreeContext
  253. structure-sized block of storage, the result is undefined.
  254. If the version number of the storage is not a valid CFTreeContext
  255. version number, the result is undefined.
  256. @result A reference to the new CFTree.
  257. }
  258. function CFTreeCreate( allocator: CFAllocatorRef; const (*var*) context: CFTreeContext ): CFTreeRef; external name '_CFTreeCreate';
  259. {!
  260. @function CFTreeGetParent
  261. Returns the parent of the specified tree.
  262. @param tree The tree to be queried. If this parameter is not a valid
  263. CFTree, the behavior is undefined.
  264. @result The parent of the tree.
  265. }
  266. function CFTreeGetParent( tree: CFTreeRef ): CFTreeRef; external name '_CFTreeGetParent';
  267. {!
  268. @function CFTreeGetNextSibling
  269. Returns the sibling after the specified tree in the parent tree's list.
  270. @param tree The tree to be queried. If this parameter is not a valid
  271. CFTree, the behavior is undefined.
  272. @result The next sibling of the tree.
  273. }
  274. function CFTreeGetNextSibling( tree: CFTreeRef ): CFTreeRef; external name '_CFTreeGetNextSibling';
  275. {!
  276. @function CFTreeGetFirstChild
  277. Returns the first child of the tree.
  278. @param tree The tree to be queried. If this parameter is not a valid
  279. CFTree, the behavior is undefined.
  280. @result The first child of the tree.
  281. }
  282. function CFTreeGetFirstChild( tree: CFTreeRef ): CFTreeRef; external name '_CFTreeGetFirstChild';
  283. {!
  284. @function CFTreeGetContext
  285. Returns the context of the specified tree.
  286. @param tree The tree to be queried. If this parameter is not a valid
  287. CFTree, the behavior is undefined.
  288. @param context A C pointer to a CFTreeContext structure to be filled in with
  289. the context of the specified tree. If this value is not a valid C
  290. pointer to a CFTreeContext structure-sized block of storage, the
  291. result is undefined. If the version number of the storage is not
  292. a valid CFTreeContext version number, the result is undefined.
  293. }
  294. procedure CFTreeGetContext( tree: CFTreeRef; var context: CFTreeContext ); external name '_CFTreeGetContext';
  295. {!
  296. @function CFTreeGetChildCount
  297. Returns the number of children of the specified tree.
  298. @param tree The tree to be queried. If this parameter is not a valid
  299. CFTree, the behavior is undefined.
  300. @result The number of children.
  301. }
  302. function CFTreeGetChildCount( tree: CFTreeRef ): CFIndex; external name '_CFTreeGetChildCount';
  303. {!
  304. @function CFTreeGetChildAtIndex
  305. Returns the nth child of the specified tree.
  306. @param tree The tree to be queried. If this parameter is not a valid
  307. CFTree, the behavior is undefined.
  308. @param idx The index of the child tree to be returned. If this parameter
  309. is less than zero or greater than the number of children of the
  310. tree, the result is undefined.
  311. @result A reference to the specified child tree.
  312. }
  313. function CFTreeGetChildAtIndex( tree: CFTreeRef; idx: CFIndex ): CFTreeRef; external name '_CFTreeGetChildAtIndex';
  314. {!
  315. @function CFTreeGetChildren
  316. Fills the buffer with children from the tree.
  317. @param tree The tree to be queried. If this parameter is not a valid
  318. CFTree, the behavior is undefined.
  319. @param children A C array of pointer-sized values to be filled with
  320. children from the tree. If this parameter is not a valid pointer to a
  321. C array of at least CFTreeGetChildCount() pointers, the behavior is undefined.
  322. @result A reference to the specified child tree.
  323. }
  324. procedure CFTreeGetChildren( tree: CFTreeRef; var children: CFTreeRef ); external name '_CFTreeGetChildren';
  325. {!
  326. @function CFTreeApplyFunctionToChildren
  327. Calls a function once for each child of the tree. Note that the applier
  328. only operates one level deep, and does not operate on descendents further
  329. removed than the immediate children of the tree.
  330. @param heap The tree to be operated upon. If this parameter is not a
  331. valid CFTree, the behavior is undefined.
  332. @param applier The callback function to call once for each child of
  333. the given tree. If this parameter is not a pointer to a
  334. function of the correct prototype, the behavior is undefined.
  335. If there are values in the tree which the applier function does
  336. not expect or cannot properly apply to, the behavior is undefined.
  337. @param context A pointer-sized user-defined value, which is passed
  338. as the second parameter to the applier function, but is
  339. otherwise unused by this function. If the context is not
  340. what is expected by the applier function, the behavior is
  341. undefined.
  342. }
  343. procedure CFTreeApplyFunctionToChildren( tree: CFTreeRef; applier: CFTreeApplierFunction; context: UnivPtr ); external name '_CFTreeApplyFunctionToChildren';
  344. {!
  345. @function CFTreeFindRoot
  346. Returns the root tree of which the specified tree is a descendent.
  347. @param tree The tree to be queried. If this parameter is not a valid
  348. CFTree, the behavior is undefined.
  349. @result A reference to the root of the tree.
  350. }
  351. function CFTreeFindRoot( tree: CFTreeRef ): CFTreeRef; external name '_CFTreeFindRoot';
  352. {!
  353. @function CFTreeSetContext
  354. Replaces the context of a tree. The tree releases its retain on the
  355. info of the previous context, and retains the info of the new context.
  356. @param tree The tree to be operated on. If this parameter is not a valid
  357. CFTree, the behavior is undefined.
  358. @param context A C pointer to a CFTreeContext structure to be copied
  359. and used as the context of the new tree. The info parameter
  360. will be retained by the tree if a retain function is provided.
  361. If this value is not a valid C pointer to a CFTreeContext
  362. structure-sized block of storage, the result is undefined.
  363. If the version number of the storage is not a valid CFTreeContext
  364. version number, the result is undefined.
  365. }
  366. procedure CFTreeSetContext( tree: CFTreeRef; const (*var*) context: CFTreeContext ); external name '_CFTreeSetContext';
  367. {!
  368. @function CFTreePrependChild
  369. Adds the newChild to the specified tree as the first in its list of children.
  370. @param tree The tree to be operated on. If this parameter is not a valid
  371. CFTree, the behavior is undefined.
  372. @param newChild The child to be added.
  373. If this parameter is not a valid CFTree, the behavior is undefined.
  374. If this parameter is a tree which is already a child of any tree,
  375. the behavior is undefined.
  376. }
  377. procedure CFTreePrependChild( tree: CFTreeRef; newChild: CFTreeRef ); external name '_CFTreePrependChild';
  378. {!
  379. @function CFTreeAppendChild
  380. Adds the newChild to the specified tree as the last in its list of children.
  381. @param tree The tree to be operated on. If this parameter is not a valid
  382. CFTree, the behavior is undefined.
  383. @param newChild The child to be added.
  384. If this parameter is not a valid CFTree, the behavior is undefined.
  385. If this parameter is a tree which is already a child of any tree,
  386. the behavior is undefined.
  387. }
  388. procedure CFTreeAppendChild( tree: CFTreeRef; newChild: CFTreeRef ); external name '_CFTreeAppendChild';
  389. {!
  390. @function CFTreeInsertSibling
  391. Inserts newSibling into the the parent tree's linked list of children after
  392. tree. The newSibling will have the same parent as tree.
  393. @param tree The tree to insert newSibling after. If this parameter is not a valid
  394. CFTree, the behavior is undefined. If the tree does not have a
  395. parent, the behavior is undefined.
  396. @param newSibling The sibling to be added.
  397. If this parameter is not a valid CFTree, the behavior is undefined.
  398. If this parameter is a tree which is already a child of any tree,
  399. the behavior is undefined.
  400. }
  401. procedure CFTreeInsertSibling( tree: CFTreeRef; newSibling: CFTreeRef ); external name '_CFTreeInsertSibling';
  402. {!
  403. @function CFTreeRemove
  404. Removes the tree from its parent.
  405. @param tree The tree to be removed. If this parameter is not a valid
  406. CFTree, the behavior is undefined.
  407. }
  408. procedure CFTreeRemove( tree: CFTreeRef ); external name '_CFTreeRemove';
  409. {!
  410. @function CFTreeRemoveAllChildren
  411. Removes all the children of the tree.
  412. @param tree The tree to remove all children from. If this parameter is not a valid
  413. CFTree, the behavior is undefined.
  414. }
  415. procedure CFTreeRemoveAllChildren( tree: CFTreeRef ); external name '_CFTreeRemoveAllChildren';
  416. {!
  417. @function CFTreeSortChildren
  418. Sorts the children of the specified tree using the specified comparator function.
  419. @param tree The tree to be operated on. If this parameter is not a valid
  420. CFTree, the behavior is undefined.
  421. @param comparator The function with the comparator function type
  422. signature which is used in the sort operation to compare
  423. children of the tree with the given value. If this parameter
  424. is not a pointer to a function of the correct prototype, the
  425. the behavior is undefined. The children of the tree are sorted
  426. from least to greatest according to this function.
  427. @param context A pointer-sized user-defined value, which is passed
  428. as the third parameter to the comparator function, but is
  429. otherwise unused by this function. If the context is not
  430. what is expected by the comparator function, the behavior is
  431. undefined.
  432. }
  433. procedure CFTreeSortChildren( tree: CFTreeRef; comparator: CFComparatorFunction; context: UnivPtr ); external name '_CFTreeSortChildren';
  434. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  435. end.
  436. {$endc} {not MACOSALLINCLUDE}