ColorPicker.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. {
  2. File: ColorPicker.p
  3. Contains: Color Picker package Interfaces.
  4. Version: Technology: System 7.5
  5. Release: Universal Interfaces 3.4.2
  6. Copyright: © 1987-2002 by Apple Computer, Inc., all rights reserved
  7. Bugs?: For bug reports, consult the following page on
  8. the World Wide Web:
  9. http://www.freepascal.org/bugs.html
  10. }
  11. {
  12. Modified for use with Free Pascal
  13. Version 200
  14. Please report any bugs to <[email protected]>
  15. }
  16. {$mode macpas}
  17. {$packenum 1}
  18. {$macro on}
  19. {$inline on}
  20. {$CALLING MWPASCAL}
  21. unit ColorPicker;
  22. interface
  23. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  24. {$setc GAP_INTERFACES_VERSION := $0200}
  25. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  26. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  27. {$endc}
  28. {$ifc defined CPUPOWERPC and defined CPUI386}
  29. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  30. {$endc}
  31. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  32. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  33. {$endc}
  34. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  35. {$setc __ppc__ := 1}
  36. {$elsec}
  37. {$setc __ppc__ := 0}
  38. {$endc}
  39. {$ifc not defined __i386__ and defined CPUI386}
  40. {$setc __i386__ := 1}
  41. {$elsec}
  42. {$setc __i386__ := 0}
  43. {$endc}
  44. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  45. {$error Conflicting definitions for __ppc__ and __i386__}
  46. {$endc}
  47. {$ifc defined __ppc__ and __ppc__}
  48. {$setc TARGET_CPU_PPC := TRUE}
  49. {$setc TARGET_CPU_X86 := FALSE}
  50. {$elifc defined __i386__ and __i386__}
  51. {$setc TARGET_CPU_PPC := FALSE}
  52. {$setc TARGET_CPU_X86 := TRUE}
  53. {$elsec}
  54. {$error Neither __ppc__ nor __i386__ is defined.}
  55. {$endc}
  56. {$setc TARGET_CPU_PPC_64 := FALSE}
  57. {$ifc defined FPC_BIG_ENDIAN}
  58. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  59. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  60. {$elifc defined FPC_LITTLE_ENDIAN}
  61. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  62. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  63. {$elsec}
  64. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  65. {$endc}
  66. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  67. {$setc CALL_NOT_IN_CARBON := FALSE}
  68. {$setc OLDROUTINENAMES := FALSE}
  69. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  70. {$setc OPAQUE_UPP_TYPES := TRUE}
  71. {$setc OTCARBONAPPLICATION := TRUE}
  72. {$setc OTKERNEL := FALSE}
  73. {$setc PM_USE_SESSION_APIS := TRUE}
  74. {$setc TARGET_API_MAC_CARBON := TRUE}
  75. {$setc TARGET_API_MAC_OS8 := FALSE}
  76. {$setc TARGET_API_MAC_OSX := TRUE}
  77. {$setc TARGET_CARBON := TRUE}
  78. {$setc TARGET_CPU_68K := FALSE}
  79. {$setc TARGET_CPU_MIPS := FALSE}
  80. {$setc TARGET_CPU_SPARC := FALSE}
  81. {$setc TARGET_OS_MAC := TRUE}
  82. {$setc TARGET_OS_UNIX := FALSE}
  83. {$setc TARGET_OS_WIN32 := FALSE}
  84. {$setc TARGET_RT_MAC_68881 := FALSE}
  85. {$setc TARGET_RT_MAC_CFM := FALSE}
  86. {$setc TARGET_RT_MAC_MACHO := TRUE}
  87. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  88. {$setc TYPE_BOOL := FALSE}
  89. {$setc TYPE_EXTENDED := FALSE}
  90. {$setc TYPE_LONGLONG := TRUE}
  91. uses MacTypes,CMTypes,CMICCProfile,MixedMode,Quickdraw,CMApplication,Events;
  92. {$ALIGN MAC68K}
  93. const
  94. { Maximum small fract value, as long }
  95. kMaximumSmallFract = $0000FFFF;
  96. kDefaultColorPickerWidth = 383;
  97. kDefaultColorPickerHeight = 238;
  98. type
  99. DialogPlacementSpec = SInt16;
  100. const
  101. kAtSpecifiedOrigin = 0;
  102. kDeepestColorScreen = 1;
  103. kCenterOnMainScreen = 2;
  104. { These are for the flags field in the structs below (for example ColorPickerInfo). }
  105. kColorPickerDialogIsMoveable = 1;
  106. kColorPickerDialogIsModal = 2;
  107. kColorPickerCanModifyPalette = 4;
  108. kColorPickerCanAnimatePalette = 8;
  109. kColorPickerAppIsColorSyncAware = 16;
  110. kColorPickerInSystemDialog = 32;
  111. kColorPickerInApplicationDialog = 64;
  112. kColorPickerInPickerDialog = 128;
  113. kColorPickerDetachedFromChoices = 256;
  114. kColorPickerCallColorProcLive = 512;
  115. {$ifc OLDROUTINENAMES}
  116. { Maximum small fract value, as long }
  117. MaxSmallFract = $0000FFFF;
  118. kDefaultWidth = 383;
  119. kDefaultHeight = 238;
  120. { These are for the flags field in the structs below (for example ColorPickerInfo). }
  121. DialogIsMoveable = 1;
  122. DialogIsModal = 2;
  123. CanModifyPalette = 4;
  124. CanAnimatePalette = 8;
  125. AppIsColorSyncAware = 16;
  126. InSystemDialog = 32;
  127. InApplicationDialog = 64;
  128. InPickerDialog = 128;
  129. DetachedFromChoices = 256;
  130. CallColorProcLive = 512;
  131. {$endc} {OLDROUTINENAMES}
  132. { A SmallFract value is just the fractional part of a Fixed number,
  133. which is the low order word. SmallFracts are used to save room,
  134. and to be compatible with Quickdraw's RGBColor. They can be
  135. assigned directly to and from INTEGERs. }
  136. { Unsigned fraction between 0 and 1 }
  137. type
  138. SmallFract = UInt16;
  139. { For developmental simplicity in switching between the HLS and HSV
  140. models, HLS is reordered into HSL. Thus both models start with
  141. hue and saturation values; value/lightness/brightness is last. }
  142. HSVColorPtr = ^HSVColor;
  143. HSVColor = record
  144. hue: SmallFract; { Fraction of circle, red at 0 }
  145. saturation: SmallFract; { 0-1, 0 for gray, 1 for pure color }
  146. value: SmallFract; { 0-1, 0 for black, 1 for max intensity }
  147. end;
  148. HSLColorPtr = ^HSLColor;
  149. HSLColor = record
  150. hue: SmallFract; { Fraction of circle, red at 0 }
  151. saturation: SmallFract; { 0-1, 0 for gray, 1 for pure color }
  152. lightness: SmallFract; { 0-1, 0 for black, 1 for white }
  153. end;
  154. CMYColorPtr = ^CMYColor;
  155. CMYColor = record
  156. cyan: SmallFract;
  157. magenta: SmallFract;
  158. yellow: SmallFract;
  159. end;
  160. PMColorPtr = ^PMColor;
  161. PMColor = record
  162. profile: CMProfileHandle;
  163. color: CMColor;
  164. end;
  165. NPMColorPtr = ^NPMColor;
  166. NPMColor = record
  167. profile: CMProfileRef;
  168. color: CMColor;
  169. end;
  170. Picker = ^SInt32; { an opaque 32-bit type }
  171. PickerPtr = ^Picker; { when a var xx:Picker parameter can be nil, it is changed to xx: PickerPtr }
  172. PickerMenuItemInfoPtr = ^PickerMenuItemInfo;
  173. PickerMenuItemInfo = record
  174. editMenuID: SInt16;
  175. cutItem: SInt16;
  176. copyItem: SInt16;
  177. pasteItem: SInt16;
  178. clearItem: SInt16;
  179. undoItem: SInt16;
  180. end;
  181. { Structs related to deprecated API's have been pulled from this file. }
  182. { Those structs necessary for developers writing their own color pickers... }
  183. { have been moved to ColorPickerComponents.h. }
  184. {$ifc TYPED_FUNCTION_POINTERS}
  185. ColorChangedProcPtr = procedure(userData: SInt32; var newColor: PMColor);
  186. {$elsec}
  187. ColorChangedProcPtr = ProcPtr;
  188. {$endc}
  189. {$ifc TYPED_FUNCTION_POINTERS}
  190. NColorChangedProcPtr = procedure(userData: SInt32; var newColor: NPMColor);
  191. {$elsec}
  192. NColorChangedProcPtr = ProcPtr;
  193. {$endc}
  194. {$ifc TYPED_FUNCTION_POINTERS}
  195. UserEventProcPtr = function(var event: EventRecord): boolean;
  196. {$elsec}
  197. UserEventProcPtr = ProcPtr;
  198. {$endc}
  199. {$ifc OPAQUE_UPP_TYPES}
  200. ColorChangedUPP = ^SInt32; { an opaque UPP }
  201. {$elsec}
  202. ColorChangedUPP = UniversalProcPtr;
  203. {$endc}
  204. {$ifc OPAQUE_UPP_TYPES}
  205. NColorChangedUPP = ^SInt32; { an opaque UPP }
  206. {$elsec}
  207. NColorChangedUPP = UniversalProcPtr;
  208. {$endc}
  209. {$ifc OPAQUE_UPP_TYPES}
  210. UserEventUPP = ^SInt32; { an opaque UPP }
  211. {$elsec}
  212. UserEventUPP = UniversalProcPtr;
  213. {$endc}
  214. ColorPickerInfoPtr = ^ColorPickerInfo;
  215. ColorPickerInfo = record
  216. theColor: PMColor;
  217. dstProfile: CMProfileHandle;
  218. flags: UInt32;
  219. placeWhere: DialogPlacementSpec;
  220. dialogOrigin: Point;
  221. pickerType: OSType;
  222. eventProc: UserEventUPP;
  223. colorProc: ColorChangedUPP;
  224. colorProcData: UInt32;
  225. prompt: Str255;
  226. mInfo: PickerMenuItemInfo;
  227. newColorChosen: boolean;
  228. filler: SInt8;
  229. end;
  230. NColorPickerInfoPtr = ^NColorPickerInfo;
  231. NColorPickerInfo = record
  232. theColor: NPMColor;
  233. dstProfile: CMProfileRef;
  234. flags: UInt32;
  235. placeWhere: DialogPlacementSpec;
  236. dialogOrigin: Point;
  237. pickerType: OSType;
  238. eventProc: UserEventUPP;
  239. colorProc: NColorChangedUPP;
  240. colorProcData: UInt32;
  241. prompt: Str255;
  242. mInfo: PickerMenuItemInfo;
  243. newColorChosen: boolean;
  244. reserved: SInt8; { Must be 0 }
  245. end;
  246. { Below are the color conversion routines. }
  247. {
  248. * Fix2SmallFract()
  249. *
  250. * Availability:
  251. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  252. * CarbonLib: in CarbonLib 1.0 and later
  253. * Mac OS X: not available
  254. }
  255. function Fix2SmallFract(f: Fixed): SmallFract; external name '_Fix2SmallFract';
  256. {
  257. * SmallFract2Fix()
  258. *
  259. * Availability:
  260. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  261. * CarbonLib: in CarbonLib 1.0 and later
  262. * Mac OS X: not available
  263. }
  264. function SmallFract2Fix(s: SmallFract): Fixed; external name '_SmallFract2Fix';
  265. {
  266. * CMY2RGB()
  267. *
  268. * Availability:
  269. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  270. * CarbonLib: in CarbonLib 1.0 and later
  271. * Mac OS X: not available
  272. }
  273. procedure CMY2RGB(const (*var*) cColor: CMYColor; var rColor: RGBColor); external name '_CMY2RGB';
  274. {
  275. * RGB2CMY()
  276. *
  277. * Availability:
  278. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  279. * CarbonLib: in CarbonLib 1.0 and later
  280. * Mac OS X: not available
  281. }
  282. procedure RGB2CMY(const (*var*) rColor: RGBColor; var cColor: CMYColor); external name '_RGB2CMY';
  283. {
  284. * HSL2RGB()
  285. *
  286. * Availability:
  287. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  288. * CarbonLib: in CarbonLib 1.0 and later
  289. * Mac OS X: not available
  290. }
  291. procedure HSL2RGB(const (*var*) hColor: HSLColor; var rColor: RGBColor); external name '_HSL2RGB';
  292. {
  293. * RGB2HSL()
  294. *
  295. * Availability:
  296. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  297. * CarbonLib: in CarbonLib 1.0 and later
  298. * Mac OS X: not available
  299. }
  300. procedure RGB2HSL(const (*var*) rColor: RGBColor; var hColor: HSLColor); external name '_RGB2HSL';
  301. {
  302. * HSV2RGB()
  303. *
  304. * Availability:
  305. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  306. * CarbonLib: in CarbonLib 1.0 and later
  307. * Mac OS X: not available
  308. }
  309. procedure HSV2RGB(const (*var*) hColor: HSVColor; var rColor: RGBColor); external name '_HSV2RGB';
  310. {
  311. * RGB2HSV()
  312. *
  313. * Availability:
  314. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  315. * CarbonLib: in CarbonLib 1.0 and later
  316. * Mac OS X: not available
  317. }
  318. procedure RGB2HSV(const (*var*) rColor: RGBColor; var hColor: HSVColor); external name '_RGB2HSV';
  319. { GetColor() works with or without the Color Picker extension. }
  320. {
  321. * GetColor()
  322. *
  323. * Availability:
  324. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  325. * CarbonLib: in CarbonLib 1.0 and later
  326. * Mac OS X: not available
  327. }
  328. function GetColor(where: Point; const (*var*) prompt: Str255; const (*var*) inColor: RGBColor; var outColor: RGBColor): boolean; external name '_GetColor';
  329. { PickColor() requires the Color Picker extension (version 2.0 or greater). }
  330. {
  331. * PickColor()
  332. *
  333. * Availability:
  334. * Non-Carbon CFM: in ColorPickerLib 2.0 and later
  335. * CarbonLib: in CarbonLib 1.0 and later
  336. * Mac OS X: not available
  337. }
  338. function PickColor(var theColorInfo: ColorPickerInfo): OSErr; external name '_PickColor';
  339. { NPickColor() requires the Color Picker extension (version 2.1 or greater). }
  340. {
  341. * NPickColor()
  342. *
  343. * Availability:
  344. * Non-Carbon CFM: in ColorPickerLib 2.1 and later
  345. * CarbonLib: in CarbonLib 1.0 and later
  346. * Mac OS X: not available
  347. }
  348. function NPickColor(var theColorInfo: NColorPickerInfo): OSErr; external name '_NPickColor';
  349. { A suite of mid-level API calls have been deprecated. Likely you never... }
  350. { used them anyway. They were removed from this file and should not be... }
  351. { used in the future as they are not gauranteed to be supported. }
  352. const
  353. uppColorChangedProcInfo = $000003C0;
  354. uppNColorChangedProcInfo = $000003C0;
  355. uppUserEventProcInfo = $000000D0;
  356. {
  357. * NewColorChangedUPP()
  358. *
  359. * Availability:
  360. * Non-Carbon CFM: available as macro/inline
  361. * CarbonLib: in CarbonLib 1.0 and later
  362. * Mac OS X: not available
  363. }
  364. function NewColorChangedUPP(userRoutine: ColorChangedProcPtr): ColorChangedUPP; external name '_NewColorChangedUPP'; { old name was NewColorChangedProc }
  365. {
  366. * NewNColorChangedUPP()
  367. *
  368. * Availability:
  369. * Non-Carbon CFM: available as macro/inline
  370. * CarbonLib: in CarbonLib 1.0 and later
  371. * Mac OS X: not available
  372. }
  373. function NewNColorChangedUPP(userRoutine: NColorChangedProcPtr): NColorChangedUPP; external name '_NewNColorChangedUPP'; { old name was NewNColorChangedProc }
  374. {
  375. * NewUserEventUPP()
  376. *
  377. * Availability:
  378. * Non-Carbon CFM: available as macro/inline
  379. * CarbonLib: in CarbonLib 1.0 and later
  380. * Mac OS X: not available
  381. }
  382. function NewUserEventUPP(userRoutine: UserEventProcPtr): UserEventUPP; external name '_NewUserEventUPP'; { old name was NewUserEventProc }
  383. {
  384. * DisposeColorChangedUPP()
  385. *
  386. * Availability:
  387. * Non-Carbon CFM: available as macro/inline
  388. * CarbonLib: in CarbonLib 1.0 and later
  389. * Mac OS X: not available
  390. }
  391. procedure DisposeColorChangedUPP(userUPP: ColorChangedUPP); external name '_DisposeColorChangedUPP';
  392. {
  393. * DisposeNColorChangedUPP()
  394. *
  395. * Availability:
  396. * Non-Carbon CFM: available as macro/inline
  397. * CarbonLib: in CarbonLib 1.0 and later
  398. * Mac OS X: not available
  399. }
  400. procedure DisposeNColorChangedUPP(userUPP: NColorChangedUPP); external name '_DisposeNColorChangedUPP';
  401. {
  402. * DisposeUserEventUPP()
  403. *
  404. * Availability:
  405. * Non-Carbon CFM: available as macro/inline
  406. * CarbonLib: in CarbonLib 1.0 and later
  407. * Mac OS X: not available
  408. }
  409. procedure DisposeUserEventUPP(userUPP: UserEventUPP); external name '_DisposeUserEventUPP';
  410. {
  411. * InvokeColorChangedUPP()
  412. *
  413. * Availability:
  414. * Non-Carbon CFM: available as macro/inline
  415. * CarbonLib: in CarbonLib 1.0 and later
  416. * Mac OS X: not available
  417. }
  418. procedure InvokeColorChangedUPP(userData: SInt32; var newColor: PMColor; userRoutine: ColorChangedUPP); external name '_InvokeColorChangedUPP'; { old name was CallColorChangedProc }
  419. {
  420. * InvokeNColorChangedUPP()
  421. *
  422. * Availability:
  423. * Non-Carbon CFM: available as macro/inline
  424. * CarbonLib: in CarbonLib 1.0 and later
  425. * Mac OS X: not available
  426. }
  427. procedure InvokeNColorChangedUPP(userData: SInt32; var newColor: NPMColor; userRoutine: NColorChangedUPP); external name '_InvokeNColorChangedUPP'; { old name was CallNColorChangedProc }
  428. {
  429. * InvokeUserEventUPP()
  430. *
  431. * Availability:
  432. * Non-Carbon CFM: available as macro/inline
  433. * CarbonLib: in CarbonLib 1.0 and later
  434. * Mac OS X: not available
  435. }
  436. function InvokeUserEventUPP(var event: EventRecord; userRoutine: UserEventUPP): boolean; external name '_InvokeUserEventUPP'; { old name was CallUserEventProc }
  437. {$ALIGN MAC68K}
  438. end.