CFTree.pas 17 KB

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