/packages/univint/src/ABPeoplePicker.pas

https://github.com/slibre/freepascal · Pascal · 357 lines · 55 code · 49 blank · 253 comment · 0 complexity · fe055c8c650e5ed50843c7c3b03ef384 MD5 · raw file

  1. {
  2. //
  3. // ABPeoplePickerC.h
  4. // AddressBook Framework
  5. //
  6. // Copyright (c) 2003-2007 Apple Inc. All rights reserved.
  7. //
  8. }
  9. { Pascal Translation: Peter N Lewis, <peter@stairways.com.au>, 2004 }
  10. { Pascal Translation Updated: Gorazd Krosl, <gorazd_1957@yahoo.ca>, November 2009 }
  11. {
  12. Modified for use with Free Pascal
  13. Version 308
  14. Please report any bugs to <gpc@microbizz.nl>
  15. }
  16. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  17. {$mode macpas}
  18. {$packenum 1}
  19. {$macro on}
  20. {$inline on}
  21. {$calling mwpascal}
  22. unit ABPeoplePicker;
  23. interface
  24. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  25. {$setc GAP_INTERFACES_VERSION := $0308}
  26. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  27. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  28. {$endc}
  29. {$ifc defined CPUPOWERPC and defined CPUI386}
  30. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  31. {$endc}
  32. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  33. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  34. {$endc}
  35. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  36. {$setc __ppc__ := 1}
  37. {$elsec}
  38. {$setc __ppc__ := 0}
  39. {$endc}
  40. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  41. {$setc __ppc64__ := 1}
  42. {$elsec}
  43. {$setc __ppc64__ := 0}
  44. {$endc}
  45. {$ifc not defined __i386__ and defined CPUI386}
  46. {$setc __i386__ := 1}
  47. {$elsec}
  48. {$setc __i386__ := 0}
  49. {$endc}
  50. {$ifc not defined __x86_64__ and defined CPUX86_64}
  51. {$setc __x86_64__ := 1}
  52. {$elsec}
  53. {$setc __x86_64__ := 0}
  54. {$endc}
  55. {$ifc not defined __arm__ and defined CPUARM}
  56. {$setc __arm__ := 1}
  57. {$elsec}
  58. {$setc __arm__ := 0}
  59. {$endc}
  60. {$ifc defined cpu64}
  61. {$setc __LP64__ := 1}
  62. {$elsec}
  63. {$setc __LP64__ := 0}
  64. {$endc}
  65. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  66. {$error Conflicting definitions for __ppc__ and __i386__}
  67. {$endc}
  68. {$ifc defined __ppc__ and __ppc__}
  69. {$setc TARGET_CPU_PPC := TRUE}
  70. {$setc TARGET_CPU_PPC64 := FALSE}
  71. {$setc TARGET_CPU_X86 := FALSE}
  72. {$setc TARGET_CPU_X86_64 := FALSE}
  73. {$setc TARGET_CPU_ARM := FALSE}
  74. {$setc TARGET_OS_MAC := TRUE}
  75. {$setc TARGET_OS_IPHONE := FALSE}
  76. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  77. {$setc TARGET_OS_EMBEDDED := FALSE}
  78. {$elifc defined __ppc64__ and __ppc64__}
  79. {$setc TARGET_CPU_PPC := FALSE}
  80. {$setc TARGET_CPU_PPC64 := TRUE}
  81. {$setc TARGET_CPU_X86 := FALSE}
  82. {$setc TARGET_CPU_X86_64 := FALSE}
  83. {$setc TARGET_CPU_ARM := FALSE}
  84. {$setc TARGET_OS_MAC := TRUE}
  85. {$setc TARGET_OS_IPHONE := FALSE}
  86. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  87. {$setc TARGET_OS_EMBEDDED := FALSE}
  88. {$elifc defined __i386__ and __i386__}
  89. {$setc TARGET_CPU_PPC := FALSE}
  90. {$setc TARGET_CPU_PPC64 := FALSE}
  91. {$setc TARGET_CPU_X86 := TRUE}
  92. {$setc TARGET_CPU_X86_64 := FALSE}
  93. {$setc TARGET_CPU_ARM := FALSE}
  94. {$ifc defined(iphonesim)}
  95. {$setc TARGET_OS_MAC := FALSE}
  96. {$setc TARGET_OS_IPHONE := TRUE}
  97. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  98. {$elsec}
  99. {$setc TARGET_OS_MAC := TRUE}
  100. {$setc TARGET_OS_IPHONE := FALSE}
  101. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  102. {$endc}
  103. {$setc TARGET_OS_EMBEDDED := FALSE}
  104. {$elifc defined __x86_64__ and __x86_64__}
  105. {$setc TARGET_CPU_PPC := FALSE}
  106. {$setc TARGET_CPU_PPC64 := FALSE}
  107. {$setc TARGET_CPU_X86 := FALSE}
  108. {$setc TARGET_CPU_X86_64 := TRUE}
  109. {$setc TARGET_CPU_ARM := FALSE}
  110. {$setc TARGET_OS_MAC := TRUE}
  111. {$setc TARGET_OS_IPHONE := FALSE}
  112. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  113. {$setc TARGET_OS_EMBEDDED := FALSE}
  114. {$elifc defined __arm__ and __arm__}
  115. {$setc TARGET_CPU_PPC := FALSE}
  116. {$setc TARGET_CPU_PPC64 := FALSE}
  117. {$setc TARGET_CPU_X86 := FALSE}
  118. {$setc TARGET_CPU_X86_64 := FALSE}
  119. {$setc TARGET_CPU_ARM := TRUE}
  120. { will require compiler define when/if other Apple devices with ARM cpus ship }
  121. {$setc TARGET_OS_MAC := FALSE}
  122. {$setc TARGET_OS_IPHONE := TRUE}
  123. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  124. {$setc TARGET_OS_EMBEDDED := TRUE}
  125. {$elsec}
  126. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ is defined.}
  127. {$endc}
  128. {$ifc defined __LP64__ and __LP64__ }
  129. {$setc TARGET_CPU_64 := TRUE}
  130. {$elsec}
  131. {$setc TARGET_CPU_64 := FALSE}
  132. {$endc}
  133. {$ifc defined FPC_BIG_ENDIAN}
  134. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  135. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  136. {$elifc defined FPC_LITTLE_ENDIAN}
  137. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  138. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  139. {$elsec}
  140. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  141. {$endc}
  142. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  143. {$setc CALL_NOT_IN_CARBON := FALSE}
  144. {$setc OLDROUTINENAMES := FALSE}
  145. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  146. {$setc OPAQUE_UPP_TYPES := TRUE}
  147. {$setc OTCARBONAPPLICATION := TRUE}
  148. {$setc OTKERNEL := FALSE}
  149. {$setc PM_USE_SESSION_APIS := TRUE}
  150. {$setc TARGET_API_MAC_CARBON := TRUE}
  151. {$setc TARGET_API_MAC_OS8 := FALSE}
  152. {$setc TARGET_API_MAC_OSX := TRUE}
  153. {$setc TARGET_CARBON := TRUE}
  154. {$setc TARGET_CPU_68K := FALSE}
  155. {$setc TARGET_CPU_MIPS := FALSE}
  156. {$setc TARGET_CPU_SPARC := FALSE}
  157. {$setc TARGET_OS_UNIX := FALSE}
  158. {$setc TARGET_OS_WIN32 := FALSE}
  159. {$setc TARGET_RT_MAC_68881 := FALSE}
  160. {$setc TARGET_RT_MAC_CFM := FALSE}
  161. {$setc TARGET_RT_MAC_MACHO := TRUE}
  162. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  163. {$setc TYPE_BOOL := FALSE}
  164. {$setc TYPE_EXTENDED := FALSE}
  165. {$setc TYPE_LONGLONG := TRUE}
  166. uses MacTypes,ABAddressBook,CFBase,CFArray,CGGeometry,HIGeometry,CarbonEventsCore;
  167. {$endc} {not MACOSALLINCLUDE}
  168. {$ifc TARGET_OS_MAC}
  169. {$ALIGN POWER}
  170. type
  171. ABPickerRef = ^OpaqueABPicker; { an opaque type }
  172. OpaqueABPicker = record end;
  173. {
  174. * Picker creation and manipulation
  175. }
  176. // Creates an ABPickerRef. Release with CFRelease(). The window is created hidden. Call
  177. // ABPickerSetVisibility() to show it.
  178. function ABPickerCreate: ABPickerRef; external name '_ABPickerCreate';
  179. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  180. // Change the structural frame of the window.
  181. procedure ABPickerSetFrame( inPicker: ABPickerRef; const (*var*) inFrame: HIRect ); external name '_ABPickerSetFrame';
  182. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  183. procedure ABPickerGetFrame( inPicker: ABPickerRef; var outFrame: HIRect ); external name '_ABPickerGetFrame';
  184. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  185. procedure ABPickerSetVisibility( inPicker: ABPickerRef; visible: CBool ); external name '_ABPickerSetVisibility';
  186. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  187. function ABPickerIsVisible( inPicker: ABPickerRef ): CBool; external name '_ABPickerIsVisible';
  188. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  189. {
  190. * Look and Feel
  191. }
  192. const
  193. // Choose the selection behavior for the value column. If multiple behaviors are selected,
  194. // the most restrictive behavior will be used. Defaults to kABPickerSingleValueSelection set
  195. // to TRUE.
  196. kABPickerSingleValueSelection = 1 shl 0; // Allow user to choose a single value for a person.
  197. kABPickerMultipleValueSelection = 1 shl 1; // Allow user to choose multiple values for a person.
  198. // Allow the user to select entire groups in the group column. If false, at least one
  199. // person in the group will be selected. Defaults to FALSE.
  200. kABPickerAllowGroupSelection = 1 shl 2;
  201. // Allow the user to select more than one group/record at a time. Defaults to TRUE.
  202. kABPickerAllowMultipleSelection = 1 shl 3;
  203. type
  204. ABPickerAttributes = OptionBits;
  205. function ABPickerGetAttributes( inPicker: ABPickerRef ): ABPickerAttributes; external name '_ABPickerGetAttributes';
  206. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  207. procedure ABPickerChangeAttributes( inPicker: ABPickerRef; inAttributesToSet: ABPickerAttributes; inAttributesToClear: ABPickerAttributes ); external name '_ABPickerChangeAttributes';
  208. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  209. {
  210. * Value column
  211. }
  212. // These methods control what data (if any) is shown in the values column. The column will only
  213. // display if an AB property is added. A popup button in the column header will be used if more
  214. // than one property is added. Titles for built in properties will localized automatically. A
  215. // list of AB properties can be found in <AddressBook/ABGlobals.h>.
  216. procedure ABPickerAddProperty( inPicker: ABPickerRef; inProperty: CFStringRef ); external name '_ABPickerAddProperty';
  217. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  218. procedure ABPickerRemoveProperty( inPicker: ABPickerRef; inProperty: CFStringRef ); external name '_ABPickerRemoveProperty';
  219. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  220. // Returns an array of AB Properties as CFStringRefs.
  221. function ABPickerCopyProperties( inPicker: ABPickerRef ): CFArrayRef; external name '_ABPickerCopyProperties';
  222. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  223. // Localized titles for third party properties should be set with these methods.
  224. procedure ABPickerSetColumnTitle( inPicker: ABPickerRef; inTitle: CFStringRef; inProperty: CFStringRef ); external name '_ABPickerSetColumnTitle';
  225. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  226. function ABPickerCopyColumnTitle( inPicker: ABPickerRef; inProperty: CFStringRef ): CFStringRef; external name '_ABPickerCopyColumnTitle';
  227. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  228. // Display one of the properties added above in the values column.
  229. procedure ABPickerSetDisplayedProperty( inPicker: ABPickerRef; inProperty: CFStringRef ); external name '_ABPickerSetDisplayedProperty';
  230. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  231. function ABPickerCopyDisplayedProperty( inPicker: ABPickerRef ): CFStringRef; external name '_ABPickerCopyDisplayedProperty';
  232. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  233. {
  234. * Selection
  235. }
  236. // Returns group column selection as an array of ABGroupRef objects.
  237. function ABPickerCopySelectedGroups( inPicker: ABPickerRef ): CFArrayRef; external name '_ABPickerCopySelectedGroups';
  238. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  239. // Returns names column selection as an array of ABGroupRef or ABPersonRef objects.
  240. function ABPickerCopySelectedRecords( inPicker: ABPickerRef ): CFArrayRef; external name '_ABPickerCopySelectedRecords';
  241. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  242. // This method returns an array of selected multi-value identifiers. Returns nil if the displayed
  243. // property is a single value type.
  244. function ABPickerCopySelectedIdentifiers( inPicker: ABPickerRef; inPerson: ABPersonRef ): CFArrayRef; external name '_ABPickerCopySelectedIdentifiers';
  245. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  246. // Returns an array containing CFStringRefs for each item selected in the values column.
  247. function ABPickerCopySelectedValues( inPicker: ABPickerRef ): CFArrayRef; external name '_ABPickerCopySelectedValues';
  248. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  249. // Select group/name/value programatically.
  250. procedure ABPickerSelectGroup( inPicker: ABPickerRef; inGroup: ABGroupRef; inExtendSelection: CBool ); external name '_ABPickerSelectGroup';
  251. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  252. procedure ABPickerSelectRecord( inPicker: ABPickerRef; inRecord: ABRecordRef; inExtendSelection: CBool ); external name '_ABPickerSelectRecord';
  253. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  254. // Individual values contained within an multi-value property can be selected with this method.
  255. procedure ABPickerSelectIdentifier( inPicker: ABPickerRef; inPerson: ABPersonRef; inIdentifier: CFStringRef; inExtendSelection: CBool ); external name '_ABPickerSelectIdentifier';
  256. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  257. // Remove selection
  258. procedure ABPickerDeselectGroup( inPicker: ABPickerRef; inGroup: ABGroupRef ); external name '_ABPickerDeselectGroup';
  259. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  260. procedure ABPickerDeselectRecord( inPicker: ABPickerRef; inRecord: ABRecordRef ); external name '_ABPickerDeselectRecord';
  261. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  262. procedure ABPickerDeselectIdentifier( inPicker: ABPickerRef; inPerson: ABPersonRef; inIdentifier: CFStringRef ); external name '_ABPickerDeselectIdentifier';
  263. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  264. procedure ABPickerDeselectAll( inPicker: ABPickerRef ); external name '_ABPickerDeselectAll';
  265. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  266. {
  267. * Events and Actions
  268. *
  269. * Your delegate will be notified when the user changes the selection or displayed property of the picker.
  270. * Picker events have an event class of kEventClassABPeoplePicker and one of the kinds listed below. Picker
  271. * events contain an event parameter which contains the ABPickerRef. To obtain this:
  272. *
  273. * GetEventParameter(inEvent, kEventParamABPickerRef,
  274. * typeCFTypeRef, NULL, sizeof(ABPickerRef),
  275. * NULL, &outPickerRef);
  276. *
  277. }
  278. const
  279. // Carbon Event class for People Picker
  280. kEventClassABPeoplePicker = FourCharCode('abpp');
  281. const
  282. // Carbon Event kinds for People Picker
  283. kEventABPeoplePickerGroupSelectionChanged = 1;
  284. kEventABPeoplePickerNameSelectionChanged = 2;
  285. kEventABPeoplePickerValueSelectionChanged = 3;
  286. kEventABPeoplePickerDisplayedPropertyChanged = 4;
  287. kEventABPeoplePickerGroupDoubleClicked = 5;
  288. kEventABPeoplePickerNameDoubleClicked = 6;
  289. const
  290. // Carbon Event parameter name
  291. kEventParamABPickerRef = FourCharCode('abpp');
  292. // Set the event handler for People Picker events.
  293. procedure ABPickerSetDelegate( inPicker: ABPickerRef; inDelegate: EventTargetRef ); external name '_ABPickerSetDelegate';
  294. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  295. function ABPickerGetDelegate( inPicker: ABPickerRef ): EventTargetRef; external name '_ABPickerGetDelegate';
  296. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  297. // Clear the search field and reset the list of displayed names.
  298. procedure ABPickerClearSearchField( inPicker: ABPickerRef ); external name '_ABPickerClearSearchField';
  299. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  300. // Launch AddressBook and edit the current selection
  301. procedure ABPickerEditInAddressBook( inPicker: ABPickerRef ); external name '_ABPickerEditInAddressBook';
  302. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  303. procedure ABPickerSelectInAddressBook( inPicker: ABPickerRef ); external name '_ABPickerSelectInAddressBook';
  304. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  305. {$endc} {TARGET_OS_MAC}
  306. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  307. end.
  308. {$endc} {not MACOSALLINCLUDE}