Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: composite Icon getting applied to all files with same extension.Anyone from Apple listening?



...and from today's ADC news, as if by magic:

[9] New Carbon Reference Library Document

Sample Code: SetCustomIcon
<http://developer.apple.com/samplecode/SetCustomIcon/SetCustomIcon.html>

Jerry

On 10 Jan 2005, at 18:02, Laurence Harris wrote:

No one from Apple needs to be listening and requesting help from Apple
employees for stuff like this is inappropriate on this list. You simply
don't understand how custom icons are implemented. We've had custom icons
for over 10 years and its not rocket science, and relatively easy to figure
out if you actually look at a file with a custom icon. Lots of applications
use them.


To add a custom icon to a file, you have to add an 'icns' resource with ID
-16455 to the file's resource fork. If it doesn't have a resource fork, then
you have to add one and then add the resource. The contents of the resource
are an IconFamilyHandle. See Icons.h for everything you'll need.


To add a custom icon to a folder, you have to create an invisible file named
"Icon\r" to the folder and do the above to this file.


Then you have to set the file or folder's custom icon Finder bit.

Larry


On 1/10/05 4:30 AM, Manish Pattath didst favor us with:

I have a contextual menu plugin (XYZ.plugin) located
at "/Library/Contextual Menu Items/". This
is invoked when the user right-clicks on a
file/folder. There are custom items in the contextual
menu. Depending on the selection i need to provide a
custom icon to  the file/folder.

In the Plugin Code i do something like this: I have a
file abc.txt to which I need to give a custom icon.
Now I get the IconRef of the file abc.txt and get the
IconRef of the "bsd.icns" [Icon file] file and form a
composite IconRef and apply this composite IconRef to
abc.txt file.

In my plugin i am forcing the finder to call my
overrided function -
SCFinderIconOverlayGetIconRefFromFileInfo when it
makes a call to  "GetIconRefFromFileInfo" by using

mach_override("_GetIconRefFromFileInfo", NULL,
SCFinderIconOverlayGetIconRefFromFileInfo,
(void**) &gGetIconRefFromFileInfo);

and the code for
SCFinderIconOverlayGetIconRefFromFileInfo is here:

static OSStatus
SCFinderIconOverlayGetIconRefFromFileInfo(
const FSRef *            inRef,                          UniCharCount
inFileNameLength,
const UniChar *          inFileName,
FSCatalogInfoBitmap      inWhichInfo,
const FSCatalogInfo *    inCatalogInfo,
IconServicesUsageFlags   inUsageFlags,
IconRef *                outIconRef,
SInt16 *                 outLabel)
{
osStat = FSRefMakePath(inRef,szBuffer,MAX_PATH);
osStat = FSPathMakeRef(szBuffer,&fsRef1,&bDir);


if(strcmp(szBuffer,"/Users/Username/Desktop/Finder_OverlayIcon/abc. txt")!=0)
{
printf("FILE NOT MATCHING RET DEFAULT\n");
err = gGetIconRefFromFileInfo(inRef,
inFileNameLength,
inFileName,
inWhichInfo,
inCatalogInfo,
inUsageFlags,
outIconRef,
outLabel);


return noErr;
}


osStat = FSGetCatalogInfo (&fsRef1, inWhichInfo, &fsInfo1, &hfsUni1, &fsSpec1, NULL);

//finder info for incoming file
finderInfo.fdCreator = kUnknownType;
finderInfo.fdType = kUnknownType;
newErr = FSpGetFInfo( &fsSpec1, &finderInfo );

//Incoming file's icon for background.
err = gGetIconRefFromFileInfo(inRef,
inFileNameLength,
inFileName,
inWhichInfo,
inCatalogInfo,
inUsageFlags,
&backgroundIconRef,
outLabel);

//bsd.icns file's icon for foreground.
osStat =
FSPathMakeRef("/Users/Username/Desktop/Finder_OverlayIcon/bsd.icns", &fsRef,&bD
ir);
osStat = FSGetCatalogInfo (&fsRef,
inWhichInfo,
&fsInfo,
&hfsUni,
&fsSpec,
NULL );


//even using the finderInfo.fdtype &
finderInfo.fdCreator is not useful.
newErr =
RegisterIconRefFromFSRef(kUnknownType,kUnknownType,&fsRef, &foregroundIconRef);


//the composite of the foreground and the background
icons.
newErr = CompositeIconRef(backgroundIconRef,
foregroundIconRef, &compositeIconRef);

*outIconRef = compositeIconRef; //send the composite
as the icon to be displayed for the abc.txt file

//decrement the reference count of back & foreground
Icons.
//cleanup

return noErr;
}

On testing, to my astonishment, all the files with
file extension ".txt" have a composite Icon while only
abc.txt should have the composite and the rest of the
.txt files should have their original icon. What wrong
am i doing here? Pls note that in the
SCFinderIconOverlayGetIconRefFromFileInfo function of
the plugin, i return the original icon if the file is
not abc.txt.
When i log the results, for all other files other than
abc.txt the SCFinderIconOverlayGetIconRefFromFileInfo
returns the default icon and composite icon for
abc.txt correctly.

Can any one point what mistake am i doing? I have lost
sufficient time on this. Also any one from Apple could
help me?

Thanks In advance.

_______________________________________________ Do not post admin requests to the list. They will be ignored. Carbon-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: composite Icon getting applied to all files with same extension.Anyone from Apple listening? (From: Laurence Harris <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.