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_generic_icon_id.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 <Finder.h>
- #include <Icons.h>
- #include "Find_generic_icon_id.h"
-
- typedef struct
- {
- OSType file_type;
- long icon_id; // long for nicer alignment
- } FilePair;
-
- static const FilePair sSysFileIconPair[] =
- {
- { kContainerFolderAliasType, kGenericFolderIconResource },
- { kContainerTrashAliasType, kTrashIconResource },
- { kSystemFolderAliasType, kSystemFolderIconResource },
- { 'INIT', kGenericExtensionIconResource },
- { 'APPL', kGenericApplicationIconResource },
- { 'dfil', kGenericDeskAccessoryIconResource },
- { 'pref', kGenericPreferencesIconResource },
- { kAppleMenuFolderAliasType, kAppleMenuFolderIconResource },
- { kControlPanelFolderAliasType, kControlPanelFolderIconResource },
- { kExtensionFolderAliasType, kExtensionsFolderIconResource },
- { kPreferencesFolderAliasType, kPreferencesFolderIconResource },
- { kStartupFolderAliasType, kStartupFolderIconResource },
- { kApplicationAliasType, kGenericApplicationIconResource },
- { kExportedFolderAliasType, kOwnedFolderIconResource },
- { kDropFolderAliasType, kDropFolderIconResource },
- { kSharedFolderAliasType, kSharedFolderIconResource },
- { kMountedFolderAliasType, kMountedFolderIconResource },
- { 'thng', kGenericExtensionIconResource },
- { 'shlb', -3967 }
- };
-
- static const FilePair sFndrFileIconPair[] =
- {
- { 'ifil', 12500 },
- { 'ffil', 14500 },
- { 'sfil', 14000 },
- { 'tfil', 14501 },
- { 'FFIL', 15500 },
- { 'DFIL', 15750 },
- { 'kfil', 14750 }
- };
-
-
- short Find_generic_icon_id(
- /* --> */ OSType the_type,
- /* <-- */ EGenericIconLocation *inWhere )
- {
- short id;
- short index;
- short tableSize;
-
- id = kGenericDocumentIconResource; // default
-
- tableSize = sizeof(sFndrFileIconPair) / sizeof(FilePair);
-
- for (index = tableSize - 1; index >= 0; --index)
- {
- if (the_type == sFndrFileIconPair[index].file_type)
- {
- id = sFndrFileIconPair[index].icon_id;
- break;
- }
- }
- if (index >= 0) // i.e. we found the type in that table
- {
- *inWhere = kGenericIconInFinder;
- }
- else
- {
- *inWhere = kGenericIconInSystem;
-
- tableSize = sizeof(sSysFileIconPair) / sizeof(FilePair);
-
- for (index = tableSize - 1; index >= 0; --index)
- {
- if (the_type == sSysFileIconPair[index].file_type)
- {
- id = sSysFileIconPair[index].icon_id;
- break;
- }
- }
-
- }
-
- return id;
- }
-