home *** CD-ROM | disk | FTP | other *** search
- /* ---------------------------------------------------------------------------------------------
- Find_icon, code for constructing icon suites for files and folders
-
- by James W. Walker
- preferred e-mail: <mailto:jwwalker@kagi.com>
- alternate e-mail: <mailto:jwwalker@aol.com>, <jim@nisus-soft.com>
- web: <http://users.aol.com/jwwalker/>
-
- File: Get1IconSuite.c
-
- Copyright ©1997 by James W. Walker
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours.
- If you're going to re-distribute the source, please make it clear
- that the code was descended from James W. Walker's code,
- but that you've made changes.
- ---------------------------------------------------------------------------------------------
- */
- #include "cheap-exceptions.h"
- #include <Errors.h>
- #include <Resources.h>
- #include "Get1IconSuite.h"
-
- /* --------------------------------------------------------------------
- Get1IconSuite Like GetIconSuite, but only looks in
- the current resource file.
-
- In case you're wondering why it would be necessary to ensure that
- icons come from only one file, suppose you're looking at a
- file that has its custom icon bit set, but for some reason does
- not contain a custom icon, or at least not a full family.
- Way down the resource chain, there may be another file, say a
- font file, that does have a full family of custom icons.
- So you get an unexpected icon.
- --------------------------------------------------------------------
- */
-
- typedef struct {
- short res_ID;
- Boolean has_mask;
- } Loop_data;
-
- static pascal OSErr Get_1_icon(
- /* --> */ ResType the_type,
- /* <-> */ Handle *the_icon,
- /* --> */ Loop_data *data );
-
-
- pascal OSErr Get1IconSuite(
- /* <-- */ Handle *theSuite,
- /* --> */ short theID,
- /* --> */ IconSelectorValue theSelector
- )
- {
- OSErr err;
- Loop_data data;
- IconActionUPP get_icon_UPP;
-
- err = NewIconSuite( theSuite );
- forbid( err, NewIconSuite );
-
- data.res_ID = theID;
- data.has_mask = false;
- get_icon_UPP = NewIconActionProc( Get_1_icon );
-
- err = ForEachIconDo( *theSuite, theSelector,
- get_icon_UPP, &data );
-
- DisposeRoutineDescriptor( get_icon_UPP );
- if ( (err == noErr) && (data.has_mask == false) )
- {
- err = noMaskFoundErr;
- DisposeIconSuite( *theSuite, false );
- *theSuite = NULL;
- }
-
- NewIconSuite:
- return err;
- }
-
- static pascal OSErr Get_1_icon(
- /* --> */ ResType the_type,
- /* <-> */ Handle *the_icon,
- /* <-> */ Loop_data *data )
- {
- *the_icon = Get1Resource( the_type, data->res_ID );
-
- if ( (*the_icon != NULL)
- && ((the_type == 'ICN#') || (the_type == 'ics#') ))
- {
- data->has_mask = true;
- }
-
- return noErr;
- }
-