appleticons.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appleticons.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include <Icons.h>
00008 #include "appletdefs.h"
00009 #include "appletmemory.h"
00010 #include "appleticons.h"
00011 
00012 unsigned short ttLabel [8] = {0x0000, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, 0x0700};
00013 
00014 #ifndef __ICONS__
00015 #define svAllAvailableData 0xFFFFFFFF
00016 
00017 
00018 pascal OSErr NewIconSuite (Handle *iconsuite) = {
00019     
00020     0x303C, 0x0207, 0xABC9};
00021     /*NewIconSuite*/
00022     
00023     
00024 pascal OSErr AddIconToSuite (Handle iconbits, Handle iconsuite, ResType resid) = {
00025 
00026     0x303C, 0x0608, 0xABC9};
00027     /*AddIconToSuite*/
00028     
00029     
00030 pascal OSErr DisposeIconSuite (Handle iconsuite, Boolean disposeData) = {
00031     
00032     0x303C, 0x0302, 0xABC9};
00033     /*DisposeIconSuite*/
00034     
00035     
00036 pascal OSErr PlotIconSuite (const Rect *r, short align, short transform, Handle iconsuite) = {
00037 
00038     0x303C, 0x0603, 0xABC9};
00039     /*PlotIconSuite*/
00040     
00041     
00042 pascal OSErr GetIconFromSuite (Handle *iconbits, Handle iconsuite, ResType resid) = {
00043     
00044     0x303C, 0x0609, 0xABC9};
00045     /*GetIconFromSuite*/
00046 
00047 
00048 pascal OSErr PlotIconID (Rect *r, short align, short transform, short resid) = {
00049 
00050     0x303C, 0x0500, 0xABC9}; 
00051     /*PlotIconID*/
00052 
00053 
00054 pascal OSErr GetIconSuite (Handle *theSuite, short theID, long theSelector) = {
00055 
00056     0x303C, 0x0501, 0xABC9}; 
00057     /*GetIconSuite*/
00058 #endif
00059 
00060 boolean geticonsuite (short id, Handle *iconsuite) {
00061 
00062     return (GetIconSuite (iconsuite, id, svAllAvailableData) == noErr);
00063     } /*geticonsuite*/
00064     
00065     
00066 boolean newiconsuite (Handle *iconsuite) {
00067 
00068     return (NewIconSuite (iconsuite) == noErr);
00069     } /*newiconsuite*/
00070     
00071     
00072 boolean addicontosuite (Handle iconbits, Handle iconsuite, ResType resid) {
00073 
00074     return (AddIconToSuite (iconbits, iconsuite, resid) == noErr);
00075     } /*addicontosuite*/
00076     
00077     
00078 boolean disposeiconsuite (Handle iconsuite, Boolean disposeData) {
00079     
00080     if (iconsuite == nil)
00081         return (true);
00082         
00083     return (DisposeIconSuite (iconsuite, disposeData) == noErr);
00084     } /*disposeiconsuite*/
00085     
00086     
00087 boolean ploticonsuite (Rect *r, short align, short transform, Handle iconsuite) {
00088 
00089     return (PlotIconSuite (r, align, transform, iconsuite) == noErr);
00090     } /*ploticonsuite*/
00091     
00092     
00093 boolean geticonfromsuite (Handle *iconbits, Handle iconsuite, ResType resid) {
00094     
00095     return (GetIconFromSuite (iconbits, iconsuite, resid) == noErr);
00096     } /*geticonfromsuite*/
00097 
00098 
00099 boolean ploticonresource (Rect *r, short align, short transform, short resid) {
00100     
00101     /*
00102     1.0b20 dmb: try plotting cicn if icon family isn't found. This 
00103     allows all of the stand system icons to be used.
00104     
00105     1.0b21 dmb: try geting normal b&w icon if all else fails
00106     */
00107     
00108     OSErr ec;
00109     CIconHandle hcicon;
00110     Handle hicon;
00111     
00112     ec = PlotIconID (r, align, transform, resid);
00113     
00114     if (ec == noErr)
00115         return (true);
00116     
00117     hcicon = GetCIcon (resid);
00118     
00119     if (hcicon != nil) {
00120         
00121         PlotCIcon (r, hcicon);
00122         
00123         DisposeCIcon (hcicon);
00124         
00125         return (true);
00126         }
00127     
00128     hicon = GetIcon (resid);
00129     
00130     if (hicon != nil) {
00131         
00132         PlotIcon (r, hicon);
00133         
00134         /*ReleaseResource (hicon);*/ /*dmb 1.0b21 - don't need to*/
00135         
00136         return (true);
00137         }
00138     
00139     return (false);
00140     } /*ploticonresource*/
00141 
00142 
00143 ResType icontypetorestype (short icontype) { 
00144     
00145     ResType restype = 0;
00146     
00147     switch (icontype) {
00148     
00149         case kLargeIcon:
00150             restype = 'ICN#'; break;
00151             
00152         case kLarge4BitIcon:
00153             restype = 'icl4'; break;
00154             
00155         case kLarge8BitIcon:
00156             restype = 'icl8'; break;
00157             
00158         case kSmallIcon:
00159             restype = 'ics#'; break;
00160             
00161         case kSmall4BitIcon:
00162             restype = 'ics4'; break;
00163             
00164         case kSmall8BitIcon:
00165             restype = 'ics8'; break;
00166         } /*switch*/
00167         
00168     return (restype);
00169     } /*icontypetorestype*/
00170     
00171     
00172 #ifndef coderesource /*DW 11/16/93: let the standalone IOA component build without link errors*/
00173     
00174 
00175     static boolean packone (Handle iconsuite, ResType type, Handle hpacked) {
00176         
00177         Handle iconbits;
00178         long handlesize;
00179         
00180         if (!geticonfromsuite (&iconbits, iconsuite, type))
00181             return (true);
00182             
00183         handlesize = GetHandleSize (iconbits);
00184             
00185         if (!enlargehandle (hpacked, longsizeof (type), &type))
00186             return (false);
00187             
00188         if (!enlargehandle (hpacked, longsizeof (handlesize), &handlesize))
00189             return (false);
00190             
00191         return (pushhandleonhandle (iconbits, hpacked));
00192         } /*packone*/
00193         
00194         
00195     boolean packiconsuite (Handle iconsuite, Handle *hpacked) {
00196         
00197         Handle h;
00198         
00199         if (!newclearhandle (0, &h))
00200             return (false);
00201         
00202         if (!packone (iconsuite, 'ICN#', h))
00203             goto error;
00204         
00205         if (!packone (iconsuite, 'icl4', h))
00206             goto error;
00207         
00208         if (!packone (iconsuite, 'icl8', h))
00209             goto error;
00210         
00211         if (!packone (iconsuite, 'ics#', h))
00212             goto error;
00213         
00214         if (!packone (iconsuite, 'ics4', h))
00215             goto error;
00216         
00217         if (!packone (iconsuite, 'ics8', h))
00218             goto error;
00219         
00220         *hpacked = h;
00221         
00222         return (true);
00223         
00224         error:
00225         
00226         disposehandle (h);
00227         
00228         return (false);
00229         } /*packiconsuite*/
00230         
00231         
00232     boolean unpackiconsuite (Handle hpacked, Handle *iconsuite) {
00233         
00234         Handle hsuite;
00235         long packedhandlesize;
00236         long ctbytes = 0;
00237         char *p;
00238         OSType type;
00239         long handlesize;
00240         Handle iconbits;
00241         
00242         if (!newiconsuite (&hsuite))
00243             return (false);
00244         
00245         packedhandlesize = GetHandleSize (hpacked);
00246         
00247         lockhandle (hpacked);
00248         
00249         p = *hpacked;
00250         
00251         while (true) {
00252             
00253             if (ctbytes >= packedhandlesize)
00254                 break;
00255                 
00256             BlockMove (p, &type, longsizeof (type));
00257             
00258             p += longsizeof (type);
00259             
00260             BlockMove (p, &handlesize, longsizeof (handlesize));
00261             
00262             p += longsizeof (handlesize);
00263             
00264             if (!newfilledhandle (p, handlesize, &iconbits))
00265                 goto error;
00266             
00267             if (!addicontosuite (iconbits, hsuite, type))
00268                 goto error;
00269             
00270             p += handlesize;
00271             
00272             ctbytes += longsizeof (type) + longsizeof (handlesize) + handlesize;
00273             } /*while*/
00274         
00275         unlockhandle (hpacked);
00276         
00277         *iconsuite = hsuite;
00278         
00279         return (true);
00280         
00281         error:
00282         
00283         disposeiconsuite (hsuite, true);
00284         
00285         return (false);
00286         } /*unpackiconsuite*/
00287         
00288 #endif
00289     
00290     
00291             
00292     

Generated on Wed May 31 18:19:42 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6