Mac OS 9
ColorPicker.h
Go to the documentation of this file.
1 
19 #ifndef __COLORPICKER__
20 #define __COLORPICKER__
21 
22 #ifndef __MIXEDMODE__
23 #include <MixedMode.h>
24 #endif
25 
26 #ifndef __QUICKDRAW__
27 #include <Quickdraw.h>
28 #endif
29 
30 #ifndef __CMAPPLICATION__
31 #include <CMApplication.h>
32 #endif
33 
34 #ifndef __EVENTS__
35 #include <Events.h>
36 #endif
37 
38 #if PRAGMA_ONCE
39 #pragma once
40 #endif
41 
42 #ifdef __cplusplus
43 extern "C"
44 {
45 #endif
46 
47 #if PRAGMA_IMPORT
48 #pragma import on
49 #endif
50 
51 #if PRAGMA_STRUCT_ALIGN
52 #pragma options align = mac68k
53 #elif PRAGMA_STRUCT_PACKPUSH
54 #pragma pack(push, 2)
55 #elif PRAGMA_STRUCT_PACK
56 #pragma pack(2)
57 #endif
58 
59  enum
60  {
61  /*Maximum small fract value, as long*/
62  kMaximumSmallFract = 0x0000FFFF
63  };
64 
65  enum
66  {
67  kDefaultColorPickerWidth = 383,
68  kDefaultColorPickerHeight = 238
69  };
70 
71  typedef SInt16 DialogPlacementSpec;
72  enum
73  {
74  kAtSpecifiedOrigin = 0,
75  kDeepestColorScreen = 1,
76  kCenterOnMainScreen = 2
77  };
78 
79  /* These are for the flags field in the structs below (for example
80  * ColorPickerInfo). */
81  enum
82  {
83  kColorPickerDialogIsMoveable = 1,
84  kColorPickerDialogIsModal = 2,
85  kColorPickerCanModifyPalette = 4,
86  kColorPickerCanAnimatePalette = 8,
87  kColorPickerAppIsColorSyncAware = 16,
88  kColorPickerInSystemDialog = 32,
89  kColorPickerInApplicationDialog = 64,
90  kColorPickerInPickerDialog = 128,
91  kColorPickerDetachedFromChoices = 256,
92  kColorPickerCallColorProcLive = 512
93  };
94 
95 #if OLDROUTINENAMES
96  enum
97  {
98  /*Maximum small fract value, as long*/
99  MaxSmallFract = 0x0000FFFF
100  };
101 
102  enum
103  {
104  kDefaultWidth = 383,
105  kDefaultHeight = 238
106  };
107 
108  /* These are for the flags field in the structs below (for example
109  * ColorPickerInfo). */
110  enum
111  {
112  DialogIsMoveable = 1,
113  DialogIsModal = 2,
114  CanModifyPalette = 4,
115  CanAnimatePalette = 8,
116  AppIsColorSyncAware = 16,
117  InSystemDialog = 32,
118  InApplicationDialog = 64,
119  InPickerDialog = 128,
120  DetachedFromChoices = 256,
121  CallColorProcLive = 512
122  };
123 
124 #endif /* OLDROUTINENAMES */
125 
126  /* A SmallFract value is just the fractional part of a Fixed number,
127  which is the low order word. SmallFracts are used to save room,
128  and to be compatible with Quickdraw's RGBColor. They can be
129  assigned directly to and from INTEGERs. */
130  /* Unsigned fraction between 0 and 1 */
131  typedef unsigned short SmallFract;
132  /* For developmental simplicity in switching between the HLS and HSV
133  models, HLS is reordered into HSL. Thus both models start with
134  hue and saturation values; value/lightness/brightness is last. */
135 
136  struct HSVColor
137  {
138  SmallFract hue; /*Fraction of circle, red at 0*/
139  SmallFract saturation; /*0-1, 0 for gray, 1 for pure color*/
140  SmallFract value; /*0-1, 0 for black, 1 for max intensity*/
141  };
142  typedef struct HSVColor HSVColor;
143  struct HSLColor
144  {
145  SmallFract hue; /*Fraction of circle, red at 0*/
146  SmallFract saturation; /*0-1, 0 for gray, 1 for pure color*/
147  SmallFract lightness; /*0-1, 0 for black, 1 for white*/
148  };
149  typedef struct HSLColor HSLColor;
150  struct CMYColor
151  {
152  SmallFract cyan;
153  SmallFract magenta;
154  SmallFract yellow;
155  };
156  typedef struct CMYColor CMYColor;
157  struct PMColor
158  {
160  CMColor color;
161  };
162  typedef struct PMColor PMColor;
163  typedef PMColor *PMColorPtr;
164  struct NPMColor
165  {
166  CMProfileRef profile;
167  CMColor color;
168  };
169  typedef struct NPMColor NPMColor;
170  typedef NPMColor *NPMColorPtr;
171  typedef struct OpaquePicker *Picker;
172  typedef Picker picker;
174  {
175  short editMenuID;
176  short cutItem;
177  short copyItem;
178  short pasteItem;
179  short clearItem;
180  short undoItem;
181  };
182  typedef struct PickerMenuItemInfo PickerMenuItemInfo;
183  /* Structs related to deprecated API's have been pulled from this file. */
184  /* Those structs necessary for developers writing their own color pickers... */
185  /* have been moved to ColorPickerComponents.h. */
186 
187  typedef CALLBACK_API(void, ColorChangedProcPtr)(long userData,
188  PMColor *newColor);
189  typedef CALLBACK_API(void, NColorChangedProcPtr)(long userData,
190  NPMColor *newColor);
191  typedef CALLBACK_API(Boolean, UserEventProcPtr)(EventRecord *event);
192  typedef STACK_UPP_TYPE(ColorChangedProcPtr) ColorChangedUPP;
193  typedef STACK_UPP_TYPE(NColorChangedProcPtr) NColorChangedUPP;
194  typedef STACK_UPP_TYPE(UserEventProcPtr) UserEventUPP;
196  {
197  PMColor theColor;
198  CMProfileHandle dstProfile;
199  UInt32 flags;
200  DialogPlacementSpec placeWhere;
201  Point dialogOrigin;
202  OSType pickerType;
203  UserEventUPP eventProc;
204  ColorChangedUPP colorProc;
205  UInt32 colorProcData;
206  Str255 prompt;
207  PickerMenuItemInfo mInfo;
208  Boolean newColorChosen;
209  SInt8 filler;
210  };
211  typedef struct ColorPickerInfo ColorPickerInfo;
213  {
214  NPMColor theColor;
215  CMProfileRef dstProfile;
216  UInt32 flags;
217  DialogPlacementSpec placeWhere;
218  Point dialogOrigin;
219  OSType pickerType;
220  UserEventUPP eventProc;
221  NColorChangedUPP colorProc;
222  UInt32 colorProcData;
223  Str255 prompt;
224  PickerMenuItemInfo mInfo;
225  Boolean newColorChosen;
226  UInt8 reserved; /*Must be 0*/
227  };
228  typedef struct NColorPickerInfo NColorPickerInfo;
229 
230  /* Below are the color conversion routines.*/
239  SmallFract
241 
250  Fixed
251  SmallFract2Fix(SmallFract s);
252 
261  void
262  CMY2RGB(const CMYColor *cColor, RGBColor *rColor);
263 
272  void
273  RGB2CMY(const RGBColor *rColor, CMYColor *cColor);
274 
283  void
284  HSL2RGB(const HSLColor *hColor, RGBColor *rColor);
285 
294  void
295  RGB2HSL(const RGBColor *rColor, HSLColor *hColor);
296 
305  void
306  HSV2RGB(const HSVColor *hColor, RGBColor *rColor);
307 
316  void
317  RGB2HSV(const RGBColor *rColor, HSVColor *hColor);
318 
319  /* GetColor() works with or without the Color Picker extension.*/
328  Boolean
329  GetColor(Point where, ConstStr255Param prompt, const RGBColor *inColor,
330  RGBColor *outColor);
331 
332  /* PickColor() requires the Color Picker extension (version 2.0 or greater).*/
341  OSErr
342  PickColor(ColorPickerInfo *theColorInfo);
343 
344  /* NPickColor() requires the Color Picker extension (version 2.1 or greater).*/
353  OSErr
354  NPickColor(NColorPickerInfo *theColorInfo);
355 
356  /* A suite of mid-level API calls have been deprecated. Likely you never... */
357  /* used them anyway. They were removed from this file and should not be... */
358  /* used in the future as they are not gauranteed to be supported. */
367  ColorChangedUPP
368  NewColorChangedUPP(ColorChangedProcPtr userRoutine);
369 #if !OPAQUE_UPP_TYPES
370  enum
371  {
372  uppColorChangedProcInfo = 0x000003C0
373  }; /* pascal no_return_value Func(4_bytes, 4_bytes) */
374 #ifdef __cplusplus
375  inline ColorChangedUPP NewColorChangedUPP(ColorChangedProcPtr userRoutine)
376  {
377  return (ColorChangedUPP)NewRoutineDescriptor((ProcPtr)(userRoutine),
378  uppColorChangedProcInfo,
379  GetCurrentArchitecture());
380  }
381 #else
382 #define NewColorChangedUPP(userRoutine) \
383  (ColorChangedUPP) \
384  NewRoutineDescriptor((ProcPtr)(userRoutine), uppColorChangedProcInfo, \
385  GetCurrentArchitecture())
386 #endif
387 #endif
388 
397  NColorChangedUPP
398  NewNColorChangedUPP(NColorChangedProcPtr userRoutine);
399 #if !OPAQUE_UPP_TYPES
400  enum
401  {
402  uppNColorChangedProcInfo = 0x000003C0
403  }; /* pascal no_return_value Func(4_bytes, 4_bytes) */
404 #ifdef __cplusplus
405  inline NColorChangedUPP NewNColorChangedUPP(NColorChangedProcPtr userRoutine)
406  {
407  return (NColorChangedUPP)NewRoutineDescriptor((ProcPtr)(userRoutine),
408  uppNColorChangedProcInfo,
409  GetCurrentArchitecture());
410  }
411 #else
412 #define NewNColorChangedUPP(userRoutine) \
413  (NColorChangedUPP) \
414  NewRoutineDescriptor((ProcPtr)(userRoutine), uppNColorChangedProcInfo, \
415  GetCurrentArchitecture())
416 #endif
417 #endif
418 
427  UserEventUPP
428  NewUserEventUPP(UserEventProcPtr userRoutine);
429 #if !OPAQUE_UPP_TYPES
430  enum
431  {
432  uppUserEventProcInfo = 0x000000D0
433  }; /* pascal 1_byte Func(4_bytes) */
434 #ifdef __cplusplus
435  inline UserEventUPP NewUserEventUPP(UserEventProcPtr userRoutine)
436  {
437  return (UserEventUPP)NewRoutineDescriptor(
438  (ProcPtr)(userRoutine), uppUserEventProcInfo, GetCurrentArchitecture());
439  }
440 #else
441 #define NewUserEventUPP(userRoutine) \
442  (UserEventUPP) NewRoutineDescriptor( \
443  (ProcPtr)(userRoutine), uppUserEventProcInfo, GetCurrentArchitecture())
444 #endif
445 #endif
446 
455  void
456  DisposeColorChangedUPP(ColorChangedUPP userUPP);
457 #if !OPAQUE_UPP_TYPES
458 #ifdef __cplusplus
459  inline void DisposeColorChangedUPP(ColorChangedUPP userUPP)
460  {
461  DisposeRoutineDescriptor((UniversalProcPtr)userUPP);
462  }
463 #else
464 #define DisposeColorChangedUPP(userUPP) DisposeRoutineDescriptor(userUPP)
465 #endif
466 #endif
467 
476  void
477  DisposeNColorChangedUPP(NColorChangedUPP userUPP);
478 #if !OPAQUE_UPP_TYPES
479 #ifdef __cplusplus
480  inline void DisposeNColorChangedUPP(NColorChangedUPP userUPP)
481  {
482  DisposeRoutineDescriptor((UniversalProcPtr)userUPP);
483  }
484 #else
485 #define DisposeNColorChangedUPP(userUPP) DisposeRoutineDescriptor(userUPP)
486 #endif
487 #endif
488 
497  void
498  DisposeUserEventUPP(UserEventUPP userUPP);
499 #if !OPAQUE_UPP_TYPES
500 #ifdef __cplusplus
501  inline void DisposeUserEventUPP(UserEventUPP userUPP)
502  {
503  DisposeRoutineDescriptor((UniversalProcPtr)userUPP);
504  }
505 #else
506 #define DisposeUserEventUPP(userUPP) DisposeRoutineDescriptor(userUPP)
507 #endif
508 #endif
509 
518  void
520  ColorChangedUPP userUPP);
521 #if !OPAQUE_UPP_TYPES
522 #ifdef __cplusplus
523  inline void InvokeColorChangedUPP(long userData, PMColor *newColor,
524  ColorChangedUPP userUPP)
525  {
526  CALL_TWO_PARAMETER_UPP(userUPP, uppColorChangedProcInfo, userData, newColor);
527  }
528 #else
529 #define InvokeColorChangedUPP(userData, newColor, userUPP) \
530  CALL_TWO_PARAMETER_UPP((userUPP), uppColorChangedProcInfo, (userData), \
531  (newColor))
532 #endif
533 #endif
534 
543  void
545  NColorChangedUPP userUPP);
546 #if !OPAQUE_UPP_TYPES
547 #ifdef __cplusplus
548  inline void InvokeNColorChangedUPP(long userData, NPMColor *newColor,
549  NColorChangedUPP userUPP)
550  {
551  CALL_TWO_PARAMETER_UPP(userUPP, uppNColorChangedProcInfo, userData, newColor);
552  }
553 #else
554 #define InvokeNColorChangedUPP(userData, newColor, userUPP) \
555  CALL_TWO_PARAMETER_UPP((userUPP), uppNColorChangedProcInfo, (userData), \
556  (newColor))
557 #endif
558 #endif
559 
568  Boolean
569  InvokeUserEventUPP(EventRecord *event, UserEventUPP userUPP);
570 #if !OPAQUE_UPP_TYPES
571 #ifdef __cplusplus
572  inline Boolean InvokeUserEventUPP(EventRecord *event, UserEventUPP userUPP)
573  {
574  return (Boolean)CALL_ONE_PARAMETER_UPP(userUPP, uppUserEventProcInfo, event);
575  }
576 #else
577 #define InvokeUserEventUPP(event, userUPP) \
578  (Boolean) CALL_ONE_PARAMETER_UPP((userUPP), uppUserEventProcInfo, (event))
579 #endif
580 #endif
581 
582 #if CALL_NOT_IN_CARBON || OLDROUTINENAMES
583 /* support for pre-Carbon UPP routines: New...Proc and Call...Proc */
584 #define NewColorChangedProc(userRoutine) NewColorChangedUPP(userRoutine)
585 #define NewNColorChangedProc(userRoutine) NewNColorChangedUPP(userRoutine)
586 #define NewUserEventProc(userRoutine) NewUserEventUPP(userRoutine)
587 #define CallColorChangedProc(userRoutine, userData, newColor) \
588  InvokeColorChangedUPP(userData, newColor, userRoutine)
589 #define CallNColorChangedProc(userRoutine, userData, newColor) \
590  InvokeNColorChangedUPP(userData, newColor, userRoutine)
591 #define CallUserEventProc(userRoutine, event) \
592  InvokeUserEventUPP(event, userRoutine)
593 #endif /* CALL_NOT_IN_CARBON */
594 
595 #if PRAGMA_STRUCT_ALIGN
596 #pragma options align = reset
597 #elif PRAGMA_STRUCT_PACKPUSH
598 #pragma pack(pop)
599 #elif PRAGMA_STRUCT_PACK
600 #pragma pack()
601 #endif
602 
603 #ifdef PRAGMA_IMPORT_OFF
604 #pragma import off
605 #elif PRAGMA_IMPORT
606 #pragma import reset
607 #endif
608 
609 #ifdef __cplusplus
610 }
611 #endif
612 
613 #endif /* __COLORPICKER__ */
Color Matching Interfaces.
Fixed SmallFract2Fix(SmallFract s)
void DisposeColorChangedUPP(ColorChangedUPP userUPP)
void InvokeNColorChangedUPP(long userData, NPMColor *newColor, NColorChangedUPP userUPP)
SmallFract Fix2SmallFract(Fixed f)
OSErr NPickColor(NColorPickerInfo *theColorInfo)
Boolean InvokeUserEventUPP(EventRecord *event, UserEventUPP userUPP)
void InvokeColorChangedUPP(long userData, PMColor *newColor, ColorChangedUPP userUPP)
void HSL2RGB(const HSLColor *hColor, RGBColor *rColor)
void RGB2CMY(const RGBColor *rColor, CMYColor *cColor)
NColorChangedUPP NewNColorChangedUPP(NColorChangedProcPtr userRoutine)
void HSV2RGB(const HSVColor *hColor, RGBColor *rColor)
ColorChangedUPP NewColorChangedUPP(ColorChangedProcPtr userRoutine)
void CMY2RGB(const CMYColor *cColor, RGBColor *rColor)
void DisposeUserEventUPP(UserEventUPP userUPP)
void DisposeNColorChangedUPP(NColorChangedUPP userUPP)
UserEventUPP NewUserEventUPP(UserEventProcPtr userRoutine)
Boolean GetColor(Point where, ConstStr255Param prompt, const RGBColor *inColor, RGBColor *outColor)
void RGB2HSV(const RGBColor *rColor, HSVColor *hColor)
OSErr PickColor(ColorPickerInfo *theColorInfo)
void RGB2HSL(const RGBColor *rColor, HSLColor *hColor)
Event Manager Interfaces.
long Fixed
Definition: MacTypes.h:153
unsigned char Boolean
Definition: MacTypes.h:318
Mixed Mode Manager Interfaces.
void DisposeRoutineDescriptor(UniversalProcPtr theUPP)
#define STACK_UPP_TYPE(name)
Definition: MixedMode.h:734
UniversalProcPtr NewRoutineDescriptor(ProcPtr theProc, ProcInfoType theProcInfo, ISAType theISA)
Interface to Quickdraw Graphics.
Definition: CMICCProfile.h:821
Definition: ColorPicker.h:151
Definition: ColorPicker.h:196
Definition: Events.h:224
Definition: ColorPicker.h:144
Definition: ColorPicker.h:137
Definition: ColorPicker.h:213
Definition: ColorPicker.h:165
Definition: ColorPicker.h:158
Definition: ColorPicker.h:174
Definition: MacTypes.h:520
Definition: Quickdraw.h:1710
Definition: CMApplication.h:330