pascal OSErr SafeGetIconSuite(IconSuiteRef *theIconSuite, short theResID, IconSelectorValue selector)
{
	ASBool foundAnIcon = false;
	
	*theIconSuite = NULL;
	OSErr err = noErr;
	
	err = NewIconSuite(theIconSuite);
	if (err == noErr)
	{
		if (selector & kSelectorLarge1Bit)
			if (SafeGetIconSuitePart(*theIconSuite, theResID, 'ICN#'))
				foundAnIcon = true;
		
		if (selector & kSelectorLarge4Bit)
			if (SafeGetIconSuitePart(*theIconSuite, theResID, 'icl4'))
				foundAnIcon = true;
		
		if (selector & kSelectorLarge8Bit)
			if (SafeGetIconSuitePart(*theIconSuite, theResID, 'icl8'))
				foundAnIcon = true;
		
		if (selector & kSelectorSmall1Bit)
			if (SafeGetIconSuitePart(*theIconSuite, theResID, 'ics#'))
				foundAnIcon = true;
		
		if (selector & kSelectorSmall4Bit)
			if (SafeGetIconSuitePart(*theIconSuite, theResID, 'ics4'))
				foundAnIcon = true;
		
		if (selector & kSelectorSmall8Bit)
			if (SafeGetIconSuitePart(*theIconSuite, theResID, 'ics8'))
				foundAnIcon = true;
		
		if (IconFamilyToIconSuite != NULL)
		{
			Handle iconFamily = SafeGet1Resource('icns', theResID);
			if (iconFamily)
			{
				IconSuiteRef icnsIconSuite = NULL;
				IconFamilyToIconSuite((IconFamilyHandle)iconFamily, selector, &icnsIconSuite);
				if (icnsIconSuite)
				{
					IconActionUPP AddIconsToSuiteUPP = NewIconActionUPP(AddIconsToSuite);
					ForEachIconDo(icnsIconSuite, selector, AddIconsToSuiteUPP, *theIconSuite);
					DisposeIconActionUPP(AddIconsToSuiteUPP);
					foundAnIcon = true;
				}
				
				ReleaseResource(iconFamily);
			}
		}
		
		if (!foundAnIcon)
		{
			DisposeIconSuite(*theIconSuite, true);
			*theIconSuite = NULL;
			err = noSuchIconErr;
		}
	}
	
	return err;
}
Esempio n. 2
0
OSErr IconFamilyToIPIconWithSelector(IconFamilyHandle theIconFamily,
	const IPIconSelector *ipSelector,IPIconRec *ipIcon)
{
	OSErr		err=noErr;
	Handle		dataHandle;
	long		dataSize;
	
	if (ipSelector->selector != 0)
    {
		err=IconFamilyToIconSuite(theIconFamily,ipSelector->selector,&ipIcon->iconSuite);
        if (err==noErr) {
            /* Mac OS X 10.8 (Mavericks) で動作させると、32ビットデータがコピーされないので、
             手作業でコピーする */
            if (ipSelector->selector|kLarge32BitData)
            {
                Handle  dummyHandle;
                dummyHandle = NewHandle(0);
                err=GetIconFamilyData(theIconFamily,kLarge32BitData,dummyHandle);
                if (err==noErr) {
                    dataSize=GetHandleSize(dummyHandle);
                    err=AddIconToSuite(dummyHandle,ipIcon->iconSuite,kLarge32BitData);
                } else {
                    DisposeHandle(dummyHandle);
                    err=noErr;
                }
            }
            if (ipSelector->selector|kSmall32BitData)
            {
                Handle  dummyHandle;
                dummyHandle = NewHandle(0);
                err=GetIconFamilyData(theIconFamily,kSmall32BitData,dummyHandle);
                if (err==noErr) {
                    dataSize=GetHandleSize(dummyHandle);
                    err=AddIconToSuite(dummyHandle,ipIcon->iconSuite,kSmall32BitData);
                } else {
                    DisposeHandle(dummyHandle);
                    err=noErr;
                }
            }
        }
    }
	else
		ipIcon->iconSuite = NULL;
	
	if (err==noErr)
	{
		if (isThumbnailIconsAvailable)
		{
			/* the others */
			if (ipSelector->it32)
			{
				dataHandle=NewHandle(0);
				err=GetIconFamilyData(theIconFamily,kThumbnail32BitData,dataHandle);
				if (err==noErr)
				{
					dataSize = GetHandleSize(dataHandle);
					if (dataSize > 0)
					{
						ipIcon->it32Data = dataHandle;
						HandToHand(&ipIcon->it32Data);
					}
					else
						ipIcon->it32Data = NULL;
				}
				else if (err == noIconDataAvailableErr || err == paramErr) // 1.20b14
				{
					err = noErr;
					ipIcon->it32Data = NULL;
				}
				
				DisposeHandle(dataHandle);
			}
			else
				ipIcon->it32Data = NULL;
			
			if (ipSelector->t8mk)
			{
				dataHandle=NewHandle(0);
				err=GetIconFamilyData(theIconFamily,kThumbnail8BitMask,dataHandle);
				if (err==noErr)
				{
					dataSize = GetHandleSize(dataHandle);
					if (dataSize > 0)
					{
						ipIcon->t8mkData = dataHandle;
						HandToHand(&ipIcon->t8mkData);
					}
					else
						ipIcon->t8mkData = NULL;
				}
				else if (err == noIconDataAvailableErr || err == paramErr) // 1.20b14
				{
					err = noErr;
					ipIcon->t8mkData = NULL;
				}
				
				DisposeHandle(dataHandle);
			}
			else
				ipIcon->t8mkData = NULL;
		}
		else
		{
			ipIcon->it32Data = NULL;
			ipIcon->t8mkData = NULL;
		}
	}
	return err;
}