Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: More Macintosh Toolbox /
Chapter 5 - Icon Utilities


Summary of the Icon Utilities

Pascal Summary

Constants

CONST
   gestaltIconUtilitiesAttr   = 'icon'; {Icon Utilities attributes}
   gestaltIconUtilitiesPresent= 0;      {check this bit in the }
                                        { response parameter}
   {types for icon families}
   large1BitMask              = 'ICN#'; {icon list resource for large icons}
   large4BitData              = 'icl4'; {large 4-bit color icon resource}
   large8BitData              = 'icl8'; {large 8-bit color icon resource}
   small1BitMask              = 'ics#'; {icon list resource for small icons}
   small4BitData              = 'ics4'; {small 4-bit color icon resource}
   small8BitData              = 'ics8'; {small 8-bit color icon resource}
   mini1BitMask               = 'icm#'; {icon list resource for mini icons}
   mini4BitData               = 'icm4'; {4-bit color mini icon}
   mini8BitData               = 'icm8'; {8-bit color mini icon resource}
   {IconAlignmentType values}
   atNone                     = $0;     {no alignment}
   atVerticalCenter           = $1;     {centered vertically}
   atTop                      = $2;     {top aligned}
   atBottom                   = $3;     {bottom aligned}
   atHorizontalCenter         = $4;     {centered horizontally}
   atLeft                     = $8;     {left aligned}
   atRight                    = $C;     {right aligned}
   atAbsoluteCenter           = (atVerticalCenter + atHorizontalCenter);
   atCenterTop                = (atTop + atHorizontalCenter);
   atCenterBottom             = (atBottom + atHorizontalCenter);
   atCenterLeft               = (atVerticalCenter + atLeft);
   atTopLeft                  = (atTop + atLeft);
   atBottomLeft               = (atBottom + atLeft);
   atCenterRight              = (atVerticalCenter + atRight);
   atTopRight                 = (atTop + atRight);
   atBottomRight              = (atBottom + atRight);
   {IconTransformType values}
   ttNone                     =  $0;
   ttDisabled                 =  $1;
   ttOffline                  =  $2;
   ttOpen                     =  $3;
   ttLabel1                   =  $0100;
   ttLabel2                   =  $0200;
   ttLabel3                   =  $0300;
   ttLabel4                   =  $0400;
   ttLabel5                   =  $0500;
   ttLabel6                   =  $0600;
   ttLabel7                   =  $0700;
   ttSelected                 =  $4000;
   ttSelectedDisabled         =  (ttSelected + ttDisabled);
   ttSelectedOffline          =  (ttSelected + ttOffline);
   ttSelectedOpen             =  (ttSelected + ttOpen);
   
   {IconSelectorValue masks}
   svLarge1Bit                = $00000001; {'ICN#' resource}
   svLarge4Bit                = $00000002; {'icl4' resource}
   svLarge8Bit                = $00000004; {'icl8' resource}
   svSmall1Bit                = $00000100; {'ics#' resource}
   svSmall4Bit                = $00000200; {'ics4' resource}
   svSmall8Bit                = $00000400; {'ics8' resource}
   svMini1Bit                 = $00010000; {'icm#' resource}
   svMini4Bit                 = $00020000; {'icm4' resource}
   svMini8Bit                 = $00040000; {'icm8' resource}
   svAllLargeData             = $000000FF; {'ICN#', 'icl4', and 'icl8' }
                                           { resources}

   svAllSmallData             = $0000FF00; {'ics#', 'ics4', and 'ics8' }
                                           { resources}
   svAllMiniData              = $00FF0000; {'icm#', 'icm4', and 'icm8' }
                                           { resources}
   svAll1BitData              = (svLarge1Bit + svSmall1Bit + svMini1Bit);
   svAll4BitData              = (svLarge4Bit + svSmall4Bit + svMini4Bit);
   svAll8BitData              = (svLarge8Bit + svSmall8Bit + svMini8Bit);
   svAllAvailableData         = $FFFFFFFF; {all resources of given ID}

Data Types

TYPE
   CIcon =
   RECORD
      iconPMap:      PixMap;           {the icon's pixel map}
      iconMask:      BitMap;           {the icon's mask}
      iconBMap:      BitMap;           {the icon's bitmap}
      iconData:      Handle;           {handle to the icon's data}
      iconMaskData:                    {the data for the icon's mask}
                     ARRAY[0..0] OF Integer;
   END;

   CIconPtr          = ^CIcon;         {pointer to color icon record}
   CIconHandle       = ^CIconPtr;      {handle to color icon record}

   IconSelectorValue = LongInt;        {icon selector type}
   IconAlignmentType = Integer;        {icon alignment type}
   IconTransformType = Integer;        {icon transform type}

   IconAction        = ProcPtr;        {pointer to action function}
   IconGetter        = ProcPtr;        {pointer to icon getter function}

Icon Utilities Routines

Drawing Icons From Resources

FUNCTION PlotIconID         (theRect: Rect; align: IconAlignmentType;
                             transform: IconTransformType; 
                             theResID: Integer): OSErr;
FUNCTION PlotIconMethod     (theRect: Rect; align: IconAlignmentType;
                             transform: IconTransformType;
                             theMethod: IconGetter;
                             yourDataPtr: UNIV Ptr): OSErr;
PROCEDURE PlotIcon          (theRect: Rect; theIcon: Handle);
FUNCTION PlotIconHandle     (theRect: Rect; align: IconAlignmentType;
                             transform: IconTransformType; 
                             theIcon: Handle): OSErr;
PROCEDURE PlotCIcon         (theRect: Rect; theIcon: CIconHandle);
FUNCTION PlotCIconHandle    (theRect: Rect; align: IconAlignmentType;
                             transform: IconTransformType; 
                             theCIcon: CIconHandle): OSErr;
FUNCTION PlotSICNHandle     (theRect: Rect; align: IconAlignmentType;
                             transform: IconTransformType; 
                             theSICN: Handle): OSErr;

Getting Icons From Resources That Don't Belong to an Icon Family

FUNCTION GetIcon            (iconID: Integer): Handle;
FUNCTION GetCIcon           (iconID: Integer): CIconHandle;

Disposing of Icons

PROCEDURE DisposeCIcon      (theIcon: CIconHandle);

Creating an Icon Suite

FUNCTION GetIconSuite       (VAR theIconSuite: Handle; theResID: Integer;
                             selector: IconSelectorValue): OSErr;
FUNCTION NewIconSuite       (VAR theIconSuite: Handle): OSErr;
FUNCTION AddIconToSuite     (theIconData: Handle; theSuite: Handle;
                             theType: ResType): OSErr;

Getting Icons From an Icon Suite

FUNCTION GetIconFromSuite   (VAR theIconData: Handle; theSuite: Handle;
                             theType: ResType): OSErr;

Drawing Icons From an Icon Suite

FUNCTION PlotIconSuite      (theRect: Rect; align: IconAlignmentType;
                             transform: IconTransformType;
                             theIconSuite: Handle): OSErr;

Performing Operations on Icons in an Icon Suite

FUNCTION ForEachIconDo       (theSuite: Handle; selector: IconSelectorValue;
                              action: IconAction; yourDataPtr: Ptr): OSErr;

Getting and Setting the Label for an Icon Suite

FUNCTION GetSuiteLabel       (theSuite: Handle): Integer; 
FUNCTION SetSuiteLabel       (theSuite: Handle; theLabel: Integer): OSErr;

Getting Label Information

FUNCTION GetLabel            (labelNumber: Integer; VAR labelColor: RGBColor; 
                              VAR labelString: Str255): OSErr;

Disposing of Icon Suites

FUNCTION DisposeIconSuite    (theIconSuite: Handle; 
                              disposeData: Boolean): OSErr;

Converting an Icon Mask to a Region

FUNCTION IconSuiteToRgn      (theRgn: RgnHandle; iconRect: Rect; 
                              align: IconAlignmentType; 
                              theIconSuite: Handle): OSErr;
FUNCTION IconIDToRgn         (theRgn: RgnHandle; iconRect: Rect; 
                              align: IconAlignmentType; 
                              iconID: Integer): OSErr;
FUNCTION IconMethodToRgn     (theRgn: RgnHandle; iconRect: Rect;
                              align: IconAlignmentType; 
                              theMethod: IconGetter;
                              yourDataPtr: Ptr): OSErr;

Determining Whether a Point or Rectangle Is Within an Icon

FUNCTION PtInIconSuite       (testPt: Point; iconRect: Rect; 
                              align: IconAlignmentType; 
                              theIconSuite: Handle): Boolean;
FUNCTION PtInIconID          (testPt: Point; iconRect: Rect; 
                              align: IconAlignmentType;
                              iconID: Integer): Boolean;
FUNCTION PtInIconMethod      (testPt: Point; iconRect: Rect;
                              align: IconAlignmentType; 
                              theMethod: IconGetter;
                              yourDataPtr: Ptr): Boolean;
FUNCTION RectInIconSuite     (testRect: Rect; iconRect: Rect;
                              align: IconAlignmentType;
                              theIconSuite: Handle): Boolean;
FUNCTION RectInIconID        (testRect: Rect; iconRect: Rect;
                              align: IconAlignmentType;
                              iconID: Integer): Boolean;
FUNCTION RectInIconMethod    (testRect: Rect; iconRect: Rect;
                              align: IconAlignmentType;
                              theMethod: IconGetter;
                              yourDataPtr: Ptr): Boolean;

Working With Icon Caches

FUNCTION MakeIconCache       (VAR theHandle: Handle; 
                              makeIcon: IconGetter; 
                              yourDataPtr: UNIV Ptr): OSErr;
FUNCTION LoadIconCache       (theRect: Rect; align: IconAlignmentType;
                              transform: IconTransformType;
                              theIconCache: Handle): OSErr;
FUNCTION GetIconCacheData    (theCache: Handle; VAR theData: Ptr): OSErr;
FUNCTION SetIconCacheData    (theCache: Handle; theData: Ptr): OSErr;
FUNCTION GetIconCacheProc    (theCache: Handle; 
                              VAR theProc: IconGetter): OSErr;
FUNCTION SetIconCacheProc    (theCache: Handle; theProc: IconGetter): OSErr;

Application-Defined Routines

Icon Action Functions

FUNCTION MyIconAction        (theType: ResType; VAR theIcon: Handle;
                              yourDataPtr: Ptr): OSErr;

Icon Getter Functions

FUNCTION MyIconGetter        (theType: ResType; yourDataPtr: Ptr): Handle;

C Summary

Constants

enum {
   #define gestaltIconUtilitiesAttr 'icon'   /*Icon Utilities attributes*/
   gestaltIconUtilitiesPresent      = 0      /*check this bit in the */
                                             /* response parameter*/
};
/*types for icon families*/
#define large1BitMask         'ICN#' /*icon list resource for large icons*/
#define large4BitData         'icl4' /*large 4-bit color icon resource*/
#define large8BitData         'icl8' /*large 8-bit color icon resource*/
#define small1BitMask         'ics#' /*icon list resource for small icons*/
#define small4BitData         'ics4' /*small 4-bit color icon resource*/
#define small8BitData         'ics8' /*small 8-bit color icon resource*/
#define mini1BitMask          'icm#' /*icon list resource for mini icons*/
#define mini4BitData          'icm4' /*mini 4-bit color icon resource*/
#define mini8BitData          'icm8' /*mini 4-bit color icon resource*/


enum { /*IconAlignmentType values*/
   atNone                     = 0x0,               /*no alignment*/
   atVerticalCenter           = 0x1,               /*centered vertically*/
   atTop                      = 0x2,               /*top aligned*/
   atBottom                   = 0x3,               /*bottom aligned*/
   atHorizontalCenter         = 0x4,               /*centered horizontally*/
   atAbsoluteCenter           = (atVerticalCenter | atHorizontalCenter),
   atCenterTop                = (atTop | atHorizontalCenter),
   atCenterBottom             = (atBottom | atHorizontalCenter),
   atLeft                     = 0x8,               /*left aligned*/
   atCenterLeft               = (atVerticalCenter | atLeft),
   atTopLeft                  = (atTop | atLeft),
   atBottomLeft               = (atBottom | atLeft),
   atRight                    = 0xC,               /*right aligned*/
   atCenterRight              = (atVerticalCenter | atRight),
   atTopRight                 = (atTop | atRight),
   atBottomRight              = (atBottom | atRight),
};

enum { /*IconTransformType values*/
   ttNone                     =  0x0,
   ttDisabled                 =  0x1,
   ttOffline                  =  0x2,
   ttOpen                     =  0x3,
   ttLabel1                   =  0x0100,
   ttLabel2                   =  0x0200,
   ttLabel3                   =  0x0300,
   ttLabel4                   =  0x0400,
   ttLabel5                   =  0x0500,
   ttLabel6                   =  0x0600,
   ttLabel7                   =  0x0700,
   ttSelected                 =  0x4000,
   ttSelectedDisabled         =  (ttSelected | ttDisabled),
   ttSelectedOffline          =  (ttSelected | ttOffline),
   ttSelectedOpen             =  (ttSelected | ttOpen),
};

enum { /*IconSelectorValue masks*/
   svLarge1Bit                = 0x00000001, /*'ICN#' resource*/
   svLarge4Bit                = 0x00000002, /*'icl4' resource*/
   svLarge8Bit                = 0x00000004, /*'icl8' resource*/
   svSmall1Bit                = 0x00000100, /*'ics#' resource*/
   svSmall4Bit                = 0x00000200, /*'ics4' resource*/
   svSmall8Bit                = 0x00000400, /*'ics8' resource*/
   svMini1Bit                 = 0x00010000, /*'icm#' resource*/
   svMini4Bit                 = 0x00020000, /*'icm4' resource*/
   svMini8Bit                 = 0x00040000, /*'icm8' resource*/
   svAllLargeData             = 0x000000FF, /*'ICN#', 'icl4', and 'icl8' */
                                            /* resources*/
   svAllSmallData             = 0x0000FF00, /*'ics#', 'ics4', and 'ics8' */
                                            /* resources*/
   svAllMiniData              = 0x00FF0000, /*'icm#', 'icm4', and 'icm8' */
                                            /* resources*/
   svAll1BitData              = (svLarge1Bit | svSmall1Bit | svMini1Bit),
   svAll4BitData              = (svLarge4Bit | svSmall4Bit | svMini4Bit),
   svAll8BitData              = (svLarge8Bit | svSmall8Bit | svMini8Bit),
   svAllAvailableData         = (long)0xFFFFFFFF /*all resources of given ID*/
};

Data Types

struct CIcon {
   PixMap iconPMap;                     /*the icon's pixel map*/
   BitMap iconMask;                     /*the icon's mask*/
   BitMap iconBMap;                     /*the icon's bitmap*/
   Handle iconData;                     /*handle to the icon's data*/
   short iconMaskData:                  /*the data for the icon's mask*/
};

typedef struct CIcon CIcon;             
typedef Cicon *CIconPtr, **CIconHandle; /*ptr, handle to color icon record*/

typedef unsigned long IconSelectorValue;/*icon selector type*/
typedef short IconAlignmentType;        /*icon alignment type*/
typedef short IconTransformType;        /*icon transform type*/

/*pointer to action function*/
typedef pascal OSErr (*IconActionProcPtr)(ResType theType, Handle *theIcon, 
                                          void *yourDataPtr);
typedef IconActionProcPtr IconAction;

/*pointer to icon getter function*/
typedef pascal Handle (*IconGetterProcPtr)(ResType theType, 
                                           void *yourDataPtr);
typedef IconGetterProcPtr IconGetter;

Icon Utilities Routines

Drawing Icons From Resources

pascal OSErr PlotIconID          (const Rect *theRect, IconAlignmentType align,
                                  IconTransformType transform, short theResID);
pascal OSErr PlotIconMethod
                                 (const Rect *theRect, IconAlignmentType align,
                                  IconTransformType transform,
                                  IconGetterProcPtr theMethod, 
                                  void *yourDataPtr);
pascal void PlotIcon             (const Rect *theRect, Handle theIcon);
pascal OSErr PlotIconHandle
                                 (const Rect *theRect, IconAlignmentType align,
                                  IconTransformType transform, Handle theIcon);
pascal OSErr PlotCIcon           (const Rect *theRect, CIconHandle theIcon);
pascal OSErr PlotCIconHandle
                                 (const Rect *theRect, IconAlignmentType align,
                                  IconTransformType transform, 
                                  CIconHandle theCIcon);
pascal OSErr PlotSICNHandle
                                 (const Rect *theRect, IconAlignmentType align,
                                  IconTransformType transform, Handle theSICN);

Getting Icons From Resources That Don't Belong to an Icon Family

pascal Handle GetIcon            (short iconID);
pascal CIconHandle GetCIcon
                                 (short iconID);

Disposing of Icons

pascal OSErr DisposeCIcon        (CIconHandle theIcon); 

Creating an Icon Suite

pascal OSErr GetIconSuite        (Handle *theIconSuite, short theResID,
                                  IconSelectorValue selector);
pascal OSErr NewIconSuite        (Handle *theIconSuite);
pascal OSErr AddIconToSuite
                                 (Handle theIconData, Handle theSuite,
                                  ResType theType);

Getting Icons From an Icon Suite

pascal OSErr GetIconFromSuite
                                 (Handle *theIconData, Handle theSuite,
                                  ResType theType);

Drawing Icons From an Icon Suite

pascal OSErr PlotIconSuite       (const Rect *theRect, IconAlignmentType align,
                                  IconTransformType transform,
                                  Handle theIconSuite);

Performing Operations on Icons in an Icon Suite

pascal OSErr ForEachIconDo       (Handle theSuite, IconSelectorValue selector,
                                  IconActionProcPtr action, void *yourDataPtr);

Getting and Setting the Label for an Icon Suite

pascal short GetSuiteLabel       (Handle theSuite); 
pascal OSErr SetSuiteLabel       (Handle theSuite, short theLabel);

Getting Label Information

pascal OSErr GetLabel            (short labelNumber, RGBColor *labelColor, 
                                  Str255 labelString);

Disposing of Icon Suites

pascal OSErr DisposeIconSuite
                                 (Handle theIconSuite, Boolean disposeData);

Converting an Icon Mask to a Region

pascal OSErr IconSuiteToRgn
                                 (RgnHandle theRgn, const Rect *iconRect, 
                                  IconAlignmentType align, Handle theIconSuite);
pascal OSErr IconIDToRgn         (RgnHandle theRgn, const Rect *iconRect, 
                                  IconAlignmentType align, short iconID);
pascal OSErr IconMethodToRgn
                                 (RgnHandle theRgn, const Rect *iconRect,
                                  IconAlignmentType align, 
                                  IconGetterProcPtr theMethod, 
                                  void *yourDataPtr);

Determining Whether a Point or Rectangle Is Within an Icon

pascal Boolean PtInIconSuite
                                 (Point testPt, const Rect *iconRect, 
                                  IconAlignmentType align, Handle theIconSuite);
pascal Boolean PtInIconID        (Point testPt, const Rect *iconRect, 
                                  IconAlignmentType align, short iconID);
pascal Boolean PtInIconMethod
                                 (Point testPt, const Rect *iconRect,
                                  IconAlignmentType align, 
                                  IconGetterProcPtr theMethod,
                                  void *yourDataPtr);
pascal Boolean RectInIconSuite
                                 (const Rect *testRect, const Rect *iconRect,
                                  IconAlignmentType align, Handle theIconSuite);
pascal Boolean RectInIconID
                                 (const Rect *testRect, const Rect *iconRect,
                                  IconAlignmentType align, short iconID);
pascal Boolean RectInIconMethod
                                 (const Rect *testRect, const Rect *iconRect,
                                  IconAlignmentType align, 
                                  IconGetterProcPtr theMethod,
                                  void *yourDataPtr);

Working With Icon Caches

pascal OSErr MakeIconCache       (Handle *theHandle, IconGetterProcPtr makeIcon, 
                                  void *yourDataPtr);
pascal OSErr LoadIconCache       (const Rect *theRect, IconAlignmentType align,
                                  IconTransformType transform,
                                  Handle theIconCache);
pascal OSErr GetIconCacheData
                                 (Handle theCache, void **theData);
pascal OSErr SetIconCacheData
                                 (Handle theCache, void *theData);
pascal OSErr GetIconCacheProc
                                 (Handle theCache, IconGetter *theProc);
pascal OSErr SetIconCacheProc
                                 (Handle theCache, IconGetter theProc);

Application-Defined Routines

Icon Action Functions

pascal OSErr MyIconAction        (ResType theType, Handle *theIcon,
                                  void *yourDataPtr);

Icon Getter Functions

pascal Handle MyIconGetter (ResType theType, void *yourDataPtr);

Assembly-Language Summary

Data Structure

Color Icon Data Structure
0iconPMap60 bytesicon's pixel map
50iconMask14 bytesicon's mask
64iconBMap14 bytesicon's bitmap
78iconData4 byteshandle to icon's data
82iconMaskDatavariabledata for icon's mask

Trap Macros

Trap Macros Requiring Routine Selectors

_IconDispatch 
SelectorRoutine
$0702NewIconSuite
$1702GetSuiteLabel
$0203DisposeIconSuite
$1603SetSuiteLabel
$1904GetIconCacheData
$1A04SetIconCacheData
$1B04GetIconCacheProc
$1C04SetIconCacheProc
$0005PlotIconID
$0105GetIconSuite
$0B05GetLabel
$0306PlotIconSuite
$0406MakeIconCache
$0606LoadIconCache
$0806AddIconToSuite
$0906GetIconFromSuite
$0D06PtInIconID
$1006RectInIconID
$1306IconIDToRgn
$1D06PlotIconHandle
$1E06PlotSICNHandle
$1F06PlotCIconHandle
$0E07PtInIconSuite
$1107RectInIconSuite
$1407IconSuiteToRgn
$0A08ForEachIconDo
$0508PlotIconMethod
$0F09PtInIconMethod
$1209RectInIconMethod
$1509IconMethodToRgn

Result Codes
noErr0No error
paramErr-50Error in parameter list
memFullErr-108Not enough memory in heap zone
memWZErr-111Attempt to operate on a free block
resNotFound-192Resource not found
noMaskFoundErr-1000Cannot find or create mask for the icon family


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996