CFNumberFormatter.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. { CFNumberFormatter.h
  2. Copyright (c) 2003-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]>, September 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 CFNumberFormatter;
  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,CFNumber,CFLocale;
  87. {$ALIGN POWER}
  88. {#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3}
  89. type
  90. CFNumberFormatterRef = ^SInt32; { an opaque 32-bit type }
  91. // CFNumberFormatters are not thread-safe. Do not use one from multiple threads!
  92. function CFNumberFormatterGetTypeID: CFTypeID; external name '_CFNumberFormatterGetTypeID';
  93. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  94. // number format styles
  95. type
  96. CFNumberFormatterStyle = SInt32;
  97. const
  98. kCFNumberFormatterNoStyle = 0;
  99. kCFNumberFormatterDecimalStyle = 1;
  100. kCFNumberFormatterCurrencyStyle = 2;
  101. kCFNumberFormatterPercentStyle = 3;
  102. kCFNumberFormatterScientificStyle = 4;
  103. kCFNumberFormatterSpellOutStyle = 5;
  104. function CFNumberFormatterCreate( allocator: CFAllocatorRef; locale: CFLocaleRef; style: CFNumberFormatterStyle ): CFNumberFormatterRef; external name '_CFNumberFormatterCreate';
  105. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  106. // Returns a CFNumberFormatter, localized to the given locale, which
  107. // will format numbers to the given style.
  108. function CFNumberFormatterGetLocale( formatter: CFNumberFormatterRef ): CFLocaleRef; external name '_CFNumberFormatterGetLocale';
  109. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  110. function CFNumberFormatterGetStyle( formatter: CFNumberFormatterRef ): CFNumberFormatterStyle; external name '_CFNumberFormatterGetStyle';
  111. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  112. // Get the properties with which the number formatter was created.
  113. function CFNumberFormatterGetFormat( formatter: CFNumberFormatterRef ): CFStringRef; external name '_CFNumberFormatterGetFormat';
  114. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  115. procedure CFNumberFormatterSetFormat( formatter: CFNumberFormatterRef; formatString: CFStringRef ); external name '_CFNumberFormatterSetFormat';
  116. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  117. // Set the format description string of the number formatter. This
  118. // overrides the style settings. The format of the format string
  119. // is as defined by the ICU library, and is similar to that found
  120. // in Microsoft Excel and NSNumberFormatter (and Java I believe).
  121. // The number formatter starts with a default format string defined
  122. // by the style argument with which it was created.
  123. function CFNumberFormatterCreateStringWithNumber( allocator: CFAllocatorRef; formatter: CFNumberFormatterRef; number: CFNumberRef ): CFStringRef; external name '_CFNumberFormatterCreateStringWithNumber';
  124. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  125. function CFNumberFormatterCreateStringWithValue( allocator: CFAllocatorRef; formatter: CFNumberFormatterRef; numberType: CFNumberType; valuePtr: {const} UnivPtr ): CFStringRef; external name '_CFNumberFormatterCreateStringWithValue';
  126. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  127. // Create a string representation of the given number or value
  128. // using the current state of the number formatter.
  129. type
  130. CFNumberFormatterOptionFlags = SInt32;
  131. const
  132. kCFNumberFormatterParseIntegersOnly = 1; { only parse integers }
  133. function CFNumberFormatterCreateNumberFromString( allocator: CFAllocatorRef; formatter: CFNumberFormatterRef; strng: CFStringRef; rangep: CFRangePtr; options: CFOptionFlags ): CFNumberRef; external name '_CFNumberFormatterCreateNumberFromString';
  134. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  135. function CFNumberFormatterGetValueFromString( formatter: CFNumberFormatterRef; strng: CFStringRef; rangep: CFRangePtr; numberType: CFNumberType; valuePtr: UnivPtr ): Boolean; external name '_CFNumberFormatterGetValueFromString';
  136. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  137. // Parse a string representation of a number using the current state
  138. // of the number formatter. The range parameter specifies the range
  139. // of the string in which the parsing should occur in input, and on
  140. // output indicates the extent that was used; this parameter can
  141. // be NULL, in which case the whole string may be used. The
  142. // return value indicates whether some number was computed and
  143. // (if valuePtr is not NULL) stored at the location specified by
  144. // valuePtr. The numberType indicates the type of value pointed
  145. // to by valuePtr.
  146. procedure CFNumberFormatterSetProperty( formatter: CFNumberFormatterRef; key: CFStringRef; value: CFTypeRef ); external name '_CFNumberFormatterSetProperty';
  147. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  148. function CFNumberFormatterCopyProperty( formatter: CFNumberFormatterRef; key: CFStringRef ): CFTypeRef; external name '_CFNumberFormatterCopyProperty';
  149. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  150. // Set and get various properties of the number formatter, the set of
  151. // which may be expanded in the future.
  152. var kCFNumberFormatterCurrencyCode: CFStringRef; external name '_kCFNumberFormatterCurrencyCode'; (* attribute const *)
  153. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFString
  154. var kCFNumberFormatterDecimalSeparator: CFStringRef; external name '_kCFNumberFormatterDecimalSeparator'; (* attribute const *)
  155. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFString
  156. var kCFNumberFormatterCurrencyDecimalSeparator: CFStringRef; external name '_kCFNumberFormatterCurrencyDecimalSeparator'; (* attribute const *)
  157. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFString
  158. var kCFNumberFormatterAlwaysShowDecimalSeparator: CFStringRef; external name '_kCFNumberFormatterAlwaysShowDecimalSeparator'; (* attribute const *)
  159. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFBoolean
  160. var kCFNumberFormatterGroupingSeparator: CFStringRef; external name '_kCFNumberFormatterGroupingSeparator'; (* attribute const *)
  161. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFString
  162. var kCFNumberFormatterUseGroupingSeparator: CFStringRef; external name '_kCFNumberFormatterUseGroupingSeparator'; (* attribute const *)
  163. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFBoolean
  164. var kCFNumberFormatterPercentSymbol: CFStringRef; external name '_kCFNumberFormatterPercentSymbol'; (* attribute const *)
  165. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFString
  166. var kCFNumberFormatterZeroSymbol: CFStringRef; external name '_kCFNumberFormatterZeroSymbol'; (* attribute const *)
  167. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFString
  168. var kCFNumberFormatterNaNSymbol: CFStringRef; external name '_kCFNumberFormatterNaNSymbol'; (* attribute const *)
  169. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFString
  170. var kCFNumberFormatterInfinitySymbol: CFStringRef; external name '_kCFNumberFormatterInfinitySymbol'; (* attribute const *)
  171. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFString
  172. var kCFNumberFormatterMinusSign: CFStringRef; external name '_kCFNumberFormatterMinusSign'; (* attribute const *)
  173. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFString
  174. var kCFNumberFormatterPlusSign: CFStringRef; external name '_kCFNumberFormatterPlusSign'; (* attribute const *)
  175. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFString
  176. var kCFNumberFormatterCurrencySymbol: CFStringRef; external name '_kCFNumberFormatterCurrencySymbol'; (* attribute const *)
  177. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFString
  178. var kCFNumberFormatterExponentSymbol: CFStringRef; external name '_kCFNumberFormatterExponentSymbol'; (* attribute const *)
  179. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFString
  180. var kCFNumberFormatterMinIntegerDigits: CFStringRef; external name '_kCFNumberFormatterMinIntegerDigits'; (* attribute const *)
  181. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFNumber
  182. var kCFNumberFormatterMaxIntegerDigits: CFStringRef; external name '_kCFNumberFormatterMaxIntegerDigits'; (* attribute const *)
  183. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFNumber
  184. var kCFNumberFormatterMinFractionDigits: CFStringRef; external name '_kCFNumberFormatterMinFractionDigits'; (* attribute const *)
  185. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFNumber
  186. var kCFNumberFormatterMaxFractionDigits: CFStringRef; external name '_kCFNumberFormatterMaxFractionDigits'; (* attribute const *)
  187. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFNumber
  188. var kCFNumberFormatterGroupingSize: CFStringRef; external name '_kCFNumberFormatterGroupingSize'; (* attribute const *)
  189. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFNumber
  190. var kCFNumberFormatterSecondaryGroupingSize: CFStringRef; external name '_kCFNumberFormatterSecondaryGroupingSize'; (* attribute const *)
  191. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFNumber
  192. var kCFNumberFormatterRoundingMode: CFStringRef; external name '_kCFNumberFormatterRoundingMode'; (* attribute const *)
  193. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFNumber
  194. var kCFNumberFormatterRoundingIncrement: CFStringRef; external name '_kCFNumberFormatterRoundingIncrement'; (* attribute const *)
  195. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFNumber
  196. var kCFNumberFormatterFormatWidth: CFStringRef; external name '_kCFNumberFormatterFormatWidth'; (* attribute const *)
  197. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFNumber
  198. var kCFNumberFormatterPaddingPosition: CFStringRef; external name '_kCFNumberFormatterPaddingPosition'; (* attribute const *)
  199. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFNumber
  200. var kCFNumberFormatterPaddingCharacter: CFStringRef; external name '_kCFNumberFormatterPaddingCharacter'; (* attribute const *)
  201. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFString
  202. var kCFNumberFormatterDefaultFormat: CFStringRef; external name '_kCFNumberFormatterDefaultFormat'; (* attribute const *)
  203. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *) // CFString
  204. var kCFNumberFormatterMultiplier: CFStringRef; external name '_kCFNumberFormatterMultiplier'; (* attribute const *)
  205. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *) // CFNumber
  206. var kCFNumberFormatterPositivePrefix: CFStringRef; external name '_kCFNumberFormatterPositivePrefix'; (* attribute const *)
  207. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *) // CFString
  208. var kCFNumberFormatterPositiveSuffix: CFStringRef; external name '_kCFNumberFormatterPositiveSuffix'; (* attribute const *)
  209. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *) // CFString
  210. var kCFNumberFormatterNegativePrefix: CFStringRef; external name '_kCFNumberFormatterNegativePrefix'; (* attribute const *)
  211. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *) // CFString
  212. var kCFNumberFormatterNegativeSuffix: CFStringRef; external name '_kCFNumberFormatterNegativeSuffix'; (* attribute const *)
  213. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *) // CFString
  214. var kCFNumberFormatterPerMillSymbol: CFStringRef; external name '_kCFNumberFormatterPerMillSymbol'; (* attribute const *)
  215. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *) // CFString
  216. var kCFNumberFormatterInternationalCurrencySymbol: CFStringRef; external name '_kCFNumberFormatterInternationalCurrencySymbol'; (* attribute const *)
  217. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *) // CFString
  218. type
  219. CFNumberFormatterRoundingMode = SInt32;
  220. const
  221. kCFNumberFormatterRoundCeiling = 0;
  222. kCFNumberFormatterRoundFloor = 1;
  223. kCFNumberFormatterRoundDown = 2;
  224. kCFNumberFormatterRoundUp = 3;
  225. kCFNumberFormatterRoundHalfEven = 4;
  226. kCFNumberFormatterRoundHalfDown = 5;
  227. kCFNumberFormatterRoundHalfUp = 6;
  228. type
  229. CFNumberFormatterPadPosition = SInt32;
  230. const
  231. kCFNumberFormatterPadBeforePrefix = 0;
  232. kCFNumberFormatterPadAfterPrefix = 1;
  233. kCFNumberFormatterPadBeforeSuffix = 2;
  234. kCFNumberFormatterPadAfterSuffix = 3;
  235. function CFNumberFormatterGetDecimalInfoForCurrencyCode( currencyCode: CFStringRef; defaultFractionDigits: SInt32Ptr; roundingIncrement: Float64Ptr ): Boolean; external name '_CFNumberFormatterGetDecimalInfoForCurrencyCode';
  236. (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  237. // Returns the number of fraction digits that should be displayed, and
  238. // the rounding increment (or 0.0 if no rounding is done by the currency)
  239. // for the given currency. Returns false if the currency code is unknown
  240. // or the information is not available.
  241. // Not localized because these are properties of the currency.
  242. {#endif}
  243. end.