CFUserNotification.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. { CFUserNotification.h
  2. Copyright (c) 2000-2005, Apple, Inc. All rights reserved.
  3. }
  4. { Pascal Translation: Peter N Lewis, <[email protected]>, 2004 }
  5. { Pascal Translation Updated: Peter N Lewis, <[email protected]>, November 2005 }
  6. {
  7. Modified for use with Free Pascal
  8. Version 200
  9. Please report any bugs to <[email protected]>
  10. }
  11. {$mode macpas}
  12. {$packenum 1}
  13. {$macro on}
  14. {$inline on}
  15. {$CALLING MWPASCAL}
  16. unit CFUserNotification;
  17. interface
  18. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  19. {$setc GAP_INTERFACES_VERSION := $0200}
  20. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  21. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  22. {$endc}
  23. {$ifc defined CPUPOWERPC and defined CPUI386}
  24. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  25. {$endc}
  26. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  27. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  28. {$endc}
  29. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  30. {$setc __ppc__ := 1}
  31. {$elsec}
  32. {$setc __ppc__ := 0}
  33. {$endc}
  34. {$ifc not defined __i386__ and defined CPUI386}
  35. {$setc __i386__ := 1}
  36. {$elsec}
  37. {$setc __i386__ := 0}
  38. {$endc}
  39. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  40. {$error Conflicting definitions for __ppc__ and __i386__}
  41. {$endc}
  42. {$ifc defined __ppc__ and __ppc__}
  43. {$setc TARGET_CPU_PPC := TRUE}
  44. {$setc TARGET_CPU_X86 := FALSE}
  45. {$elifc defined __i386__ and __i386__}
  46. {$setc TARGET_CPU_PPC := FALSE}
  47. {$setc TARGET_CPU_X86 := TRUE}
  48. {$elsec}
  49. {$error Neither __ppc__ nor __i386__ is defined.}
  50. {$endc}
  51. {$setc TARGET_CPU_PPC_64 := FALSE}
  52. {$ifc defined FPC_BIG_ENDIAN}
  53. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  54. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  55. {$elifc defined FPC_LITTLE_ENDIAN}
  56. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  57. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  58. {$elsec}
  59. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  60. {$endc}
  61. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  62. {$setc CALL_NOT_IN_CARBON := FALSE}
  63. {$setc OLDROUTINENAMES := FALSE}
  64. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  65. {$setc OPAQUE_UPP_TYPES := TRUE}
  66. {$setc OTCARBONAPPLICATION := TRUE}
  67. {$setc OTKERNEL := FALSE}
  68. {$setc PM_USE_SESSION_APIS := TRUE}
  69. {$setc TARGET_API_MAC_CARBON := TRUE}
  70. {$setc TARGET_API_MAC_OS8 := FALSE}
  71. {$setc TARGET_API_MAC_OSX := TRUE}
  72. {$setc TARGET_CARBON := TRUE}
  73. {$setc TARGET_CPU_68K := FALSE}
  74. {$setc TARGET_CPU_MIPS := FALSE}
  75. {$setc TARGET_CPU_SPARC := FALSE}
  76. {$setc TARGET_OS_MAC := TRUE}
  77. {$setc TARGET_OS_UNIX := FALSE}
  78. {$setc TARGET_OS_WIN32 := FALSE}
  79. {$setc TARGET_RT_MAC_68881 := FALSE}
  80. {$setc TARGET_RT_MAC_CFM := FALSE}
  81. {$setc TARGET_RT_MAC_MACHO := TRUE}
  82. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  83. {$setc TYPE_BOOL := FALSE}
  84. {$setc TYPE_EXTENDED := FALSE}
  85. {$setc TYPE_LONGLONG := TRUE}
  86. uses MacTypes,CFBase,CFDate,CFDictionary,CFString,CFURL,CFRunLoop;
  87. {$ALIGN POWER}
  88. type
  89. CFUserNotificationRef = ^SInt32; { an opaque 32-bit type }
  90. { A CFUserNotification is a notification intended to be presented to a
  91. user at the console (if one is present). This is for the use of processes
  92. that do not otherwise have user interfaces, but may need occasional
  93. interaction with a user. There is a parallel API for this functionality
  94. at the System framework level, described in UNCUserNotification.h.
  95. The contents of the notification can include a header, a message, textfields,
  96. a popup button, radio buttons or checkboxes, a progress indicator, and up to
  97. three ordinary buttons. All of these items are optional, but a default
  98. button will be supplied even if not specified unless the
  99. kCFUserNotificationNoDefaultButtonFlag is set.
  100. The contents of the notification are specified in the dictionary used to
  101. create the notification, whose keys should be taken from the list of constants
  102. below, and whose values should be either strings or arrays of strings
  103. (except for kCFUserNotificationProgressIndicatorValueKey, in which case the
  104. value should be a number between 0 and 1, for a "definite" progress indicator,
  105. or a boolean, for an "indefinite" progress indicator). Additionally, URLs can
  106. optionally be supplied for an icon, a sound, and a bundle whose Localizable.strings
  107. files will be used to localize strings.
  108. Certain request flags are specified when a notification is created.
  109. These specify an alert level for the notification, determine whether
  110. radio buttons or check boxes are to be used, specify which if any of these
  111. are checked by default, specify whether any of the textfields are to
  112. be secure textfields, and determine which popup item should be selected
  113. by default. A timeout is also specified, which determines how long the
  114. notification should be supplied to the user (if zero, it will not timeout).
  115. A CFUserNotification is dispatched for presentation when it is created.
  116. If any reply is required, it may be awaited in one of two ways: either
  117. synchronously, using CFUserNotificationReceiveResponse, or asynchronously,
  118. using a run loop source. CFUserNotificationReceiveResponse has a timeout
  119. parameter that determines how long it will block (zero meaning indefinitely)
  120. and it may be called as many times as necessary until a response arrives.
  121. If a notification has not yet received a response, it may be updated with
  122. new information, or it may be cancelled. Notifications may not be reused.
  123. When a response arrives, it carries with it response flags that describe
  124. which button was used to dismiss the notification, which checkboxes or
  125. radio buttons were checked, and what the selection of the popup was.
  126. It also carries a response dictionary, which describes the contents
  127. of the textfields. }
  128. type
  129. CFUserNotificationCallBack = procedure( userNotification: CFUserNotificationRef; responseFlags: CFOptionFlags );
  130. function CFUserNotificationGetTypeID: CFTypeID; external name '_CFUserNotificationGetTypeID';
  131. function CFUserNotificationCreate( allocator: CFAllocatorRef; timeout: CFTimeInterval; flags: CFOptionFlags; var error: SInt32; dictionary: CFDictionaryRef ): CFUserNotificationRef; external name '_CFUserNotificationCreate';
  132. function CFUserNotificationReceiveResponse( userNotification: CFUserNotificationRef; timeout: CFTimeInterval; var responseFlags: CFOptionFlags ): SInt32; external name '_CFUserNotificationReceiveResponse';
  133. function CFUserNotificationGetResponseValue( userNotification: CFUserNotificationRef; key: CFStringRef; idx: CFIndex ): CFStringRef; external name '_CFUserNotificationGetResponseValue';
  134. function CFUserNotificationGetResponseDictionary( userNotification: CFUserNotificationRef ): CFDictionaryRef; external name '_CFUserNotificationGetResponseDictionary';
  135. function CFUserNotificationUpdate( userNotification: CFUserNotificationRef; timeout: CFTimeInterval; flags: CFOptionFlags; dictionary: CFDictionaryRef ): SInt32; external name '_CFUserNotificationUpdate';
  136. function CFUserNotificationCancel( userNotification: CFUserNotificationRef ): SInt32; external name '_CFUserNotificationCancel';
  137. function CFUserNotificationCreateRunLoopSource( allocator: CFAllocatorRef; userNotification: CFUserNotificationRef; callout: CFUserNotificationCallBack; order: CFIndex ): CFRunLoopSourceRef; external name '_CFUserNotificationCreateRunLoopSource';
  138. { Convenience functions for handling the simplest and most common cases:
  139. a one-way notification, and a notification with up to three buttons. }
  140. function CFUserNotificationDisplayNotice( timeout: CFTimeInterval; flags: CFOptionFlags; iconURL: CFURLRef; soundURL: CFURLRef; localizationURL: CFURLRef; alertHeader: CFStringRef; alertMessage: CFStringRef; defaultButtonTitle: CFStringRef ): SInt32; external name '_CFUserNotificationDisplayNotice';
  141. function CFUserNotificationDisplayAlert( timeout: CFTimeInterval; flags: CFOptionFlags; iconURL: CFURLRef; soundURL: CFURLRef; localizationURL: CFURLRef; alertHeader: CFStringRef; alertMessage: CFStringRef; defaultButtonTitle: CFStringRef; alternateButtonTitle: CFStringRef; otherButtonTitle: CFStringRef; var responseFlags: CFOptionFlags ): SInt32; external name '_CFUserNotificationDisplayAlert';
  142. { Flags }
  143. const
  144. kCFUserNotificationStopAlertLevel = 0;
  145. kCFUserNotificationNoteAlertLevel = 1;
  146. kCFUserNotificationCautionAlertLevel = 2;
  147. kCFUserNotificationPlainAlertLevel = 3;
  148. const
  149. kCFUserNotificationDefaultResponse = 0;
  150. kCFUserNotificationAlternateResponse = 1;
  151. kCFUserNotificationOtherResponse = 2;
  152. kCFUserNotificationCancelResponse = 3;
  153. const
  154. kCFUserNotificationNoDefaultButtonFlag = 1 shl 5;
  155. kCFUserNotificationUseRadioButtonsFlag = 1 shl 6;
  156. function CFUserNotificationCheckBoxChecked( i: CFIndex ): CFOptionFlags; inline;
  157. function CFUserNotificationSecureTextField( i: CFIndex ): CFOptionFlags; inline;
  158. function CFUserNotificationPopUpSelection( n: CFIndex ): CFOptionFlags; inline;
  159. { Keys }
  160. var kCFUserNotificationIconURLKey: CFStringRef; external name '_kCFUserNotificationIconURLKey'; (* attribute const *)
  161. var kCFUserNotificationSoundURLKey: CFStringRef; external name '_kCFUserNotificationSoundURLKey'; (* attribute const *)
  162. var kCFUserNotificationLocalizationURLKey: CFStringRef; external name '_kCFUserNotificationLocalizationURLKey'; (* attribute const *)
  163. var kCFUserNotificationAlertHeaderKey: CFStringRef; external name '_kCFUserNotificationAlertHeaderKey'; (* attribute const *)
  164. var kCFUserNotificationAlertMessageKey: CFStringRef; external name '_kCFUserNotificationAlertMessageKey'; (* attribute const *)
  165. var kCFUserNotificationDefaultButtonTitleKey: CFStringRef; external name '_kCFUserNotificationDefaultButtonTitleKey'; (* attribute const *)
  166. var kCFUserNotificationAlternateButtonTitleKey: CFStringRef; external name '_kCFUserNotificationAlternateButtonTitleKey'; (* attribute const *)
  167. var kCFUserNotificationOtherButtonTitleKey: CFStringRef; external name '_kCFUserNotificationOtherButtonTitleKey'; (* attribute const *)
  168. var kCFUserNotificationProgressIndicatorValueKey: CFStringRef; external name '_kCFUserNotificationProgressIndicatorValueKey'; (* attribute const *)
  169. var kCFUserNotificationPopUpTitlesKey: CFStringRef; external name '_kCFUserNotificationPopUpTitlesKey'; (* attribute const *)
  170. var kCFUserNotificationTextFieldTitlesKey: CFStringRef; external name '_kCFUserNotificationTextFieldTitlesKey'; (* attribute const *)
  171. var kCFUserNotificationCheckBoxTitlesKey: CFStringRef; external name '_kCFUserNotificationCheckBoxTitlesKey'; (* attribute const *)
  172. var kCFUserNotificationTextFieldValuesKey: CFStringRef; external name '_kCFUserNotificationTextFieldValuesKey'; (* attribute const *)
  173. {#if MAC_OS_X_VERSION_10_3 <= MAC_OS_X_VERSION_MAX_ALLOWED}
  174. var kCFUserNotificationPopUpSelectionKey: CFStringRef; external name '_kCFUserNotificationPopUpSelectionKey'; (* attribute const *)
  175. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  176. {#endif}
  177. implementation
  178. {$R-}
  179. function CFUserNotificationCheckBoxChecked( i: CFIndex ): CFOptionFlags; inline;
  180. begin
  181. CFUserNotificationCheckBoxChecked := CFOptionFlags(1 shl (8+i));
  182. end;
  183. function CFUserNotificationSecureTextField( i: CFIndex ): CFOptionFlags; inline;
  184. begin
  185. CFUserNotificationSecureTextField := CFOptionFlags(1 shl (16+i));
  186. end;
  187. function CFUserNotificationPopUpSelection( n: CFIndex ): CFOptionFlags; inline;
  188. begin
  189. CFUserNotificationPopUpSelection := CFOptionFlags(n shl 24);
  190. end;
  191. end.