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: Find_icon.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 <A4Stuff.h>
- #include <Icons.h>
- #include "Find_icon.h"
- #include "cheap-exceptions.h"
- #include <Finder.h>
- #include "Get_custom_folder_icon.h"
- #include "Get_normal_folder_icon.h"
- #include "Get_volume_icon.h"
- #include "Get_custom_file_icon.h"
- #include "Get_normal_file_icon.h"
- #include "Is_vol_ejected.h"
-
- #if __MC68K__ && !__A5__ // 68K code resource, I assume standalone
- #define Find_icon main
- #endif
-
- /* ------------------------------------------------------------------
- Find_icon Given a file specification for a file, folder, or
- volume, create an appropriate icon suite
- and find its label color.
- ------------------------------------------------------------------
- */
- pascal OSErr Find_icon(
- /* --> */ const FSSpec *thing,
- /* --> */ MetaSelectorValue icon_selector,
- /* <-- */ Handle *the_suite
- )
- {
- CInfoPBRec cpb;
- Str31 name;
- OSErr err;
- #if __MC68K__ && !__A5__
- EnterCodeResource(); // set up A4 register
- #endif
-
- *the_suite = NULL;
-
- forbid_action( Is_vol_ejected( thing->vRefNum ), ejected,
- err = volOffLinErr );
-
- BlockMoveData( thing->name, name, sizeof(name) );
- cpb.hFileInfo.ioVRefNum = thing->vRefNum;
- cpb.hFileInfo.ioDirID = thing->parID;
- cpb.hFileInfo.ioNamePtr = name;
- cpb.hFileInfo.ioFDirIndex = 0;
- err = PBGetCatInfoSync( &cpb );
- forbid( err, PBGetCatInfoSync );
-
- if ( (cpb.hFileInfo.ioFlAttrib & ioDirMask) == 0 ) // file
- {
- if (cpb.hFileInfo.ioFlFndrInfo.fdFlags & kHasCustomIcon)
- {
- err = Get_custom_file_icon( thing,
- icon_selector, the_suite );
- }
- else // no custom icon
- {
- err = Get_normal_file_icon( &cpb,
- icon_selector, the_suite );
- }
- }
- else // directory
- {
- if ( ((cpb.hFileInfo.ioFlFndrInfo.fdFlags & kHasCustomIcon) == 0)
- ||
- (noErr != Get_custom_folder_icon( thing->vRefNum,
- cpb.hFileInfo.ioDirID, icon_selector,
- the_suite ))
- ) // failed to find a custom icon, try normal kind
- {
- if (cpb.hFileInfo.ioDirID == fsRtDirID) // a volume
- {
- err = Get_volume_icon( thing->vRefNum, the_suite );
- }
- else // a folder
- {
- err = Get_normal_folder_icon( &cpb,
- icon_selector, the_suite );
- }
- }
- }
-
- if (*the_suite != NULL)
- {
- SetSuiteLabel( *the_suite,
- (cpb.hFileInfo.ioFlFndrInfo.fdFlags & kColor) >> 1 );
- }
- goto getout;
- // ----------- end of normal case --------------
-
- ejected:
- PBGetCatInfoSync: // ------- error handler ---------
- if (thing->parID == fsRtParID) // a volume
- {
- err = Get_volume_icon( thing->vRefNum, the_suite );
- }
-
- getout:
- #if __MC68K__ && !__A5__
- ExitCodeResource(); // restore A4 register
- #endif
-
- return err;
- }
-