home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 May / macformat-050.iso / Shareware Plus / Developers / Find_icon folder / Sources / Find_generic_icon_id.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-25  |  3.0 KB  |  109 lines  |  [TEXT/CWIE]

  1. /*    ---------------------------------------------------------------------------------------------
  2.     Find_icon, code for constructing icon suites for files and folders
  3.     
  4.     by James W. Walker
  5.     preferred e-mail: <mailto:jwwalker@kagi.com>
  6.     alternate e-mail: <mailto:jwwalker@aol.com>, <jim@nisus-soft.com>
  7.     web: <http://users.aol.com/jwwalker/>
  8.     
  9.     File: Find_generic_icon_id.c
  10.     
  11.     Copyright ©1997 by James W. Walker
  12.     
  13.     You may incorporate this sample code into your applications without
  14.     restriction, though the sample code has been provided "AS IS" and the
  15.     responsibility for its operation is 100% yours.
  16.     If you're going to re-distribute the source, please make it clear
  17.     that the code was descended from James W. Walker's code,
  18.     but that you've made changes.
  19.     ---------------------------------------------------------------------------------------------
  20. */
  21. #include <Finder.h>
  22. #include <Icons.h>
  23. #include "Find_generic_icon_id.h"
  24.  
  25. typedef struct
  26. {
  27.     OSType file_type;
  28.     long icon_id;    // long for nicer alignment
  29. } FilePair;
  30.  
  31. static const FilePair sSysFileIconPair[] =
  32. {
  33.     { kContainerFolderAliasType, kGenericFolderIconResource },
  34.     { kContainerTrashAliasType, kTrashIconResource },
  35.     { kSystemFolderAliasType, kSystemFolderIconResource },
  36.     { 'INIT', kGenericExtensionIconResource },
  37.     { 'APPL', kGenericApplicationIconResource },
  38.     { 'dfil', kGenericDeskAccessoryIconResource },
  39.     { 'pref', kGenericPreferencesIconResource },
  40.     { kAppleMenuFolderAliasType, kAppleMenuFolderIconResource },
  41.     { kControlPanelFolderAliasType, kControlPanelFolderIconResource },
  42.     { kExtensionFolderAliasType, kExtensionsFolderIconResource },
  43.     { kPreferencesFolderAliasType, kPreferencesFolderIconResource },
  44.     { kStartupFolderAliasType, kStartupFolderIconResource },
  45.     { kApplicationAliasType, kGenericApplicationIconResource },
  46.     { kExportedFolderAliasType, kOwnedFolderIconResource },
  47.     { kDropFolderAliasType, kDropFolderIconResource },
  48.     { kSharedFolderAliasType, kSharedFolderIconResource },
  49.     { kMountedFolderAliasType, kMountedFolderIconResource },
  50.     { 'thng', kGenericExtensionIconResource },
  51.     { 'shlb', -3967 }
  52. };
  53.  
  54. static const FilePair sFndrFileIconPair[] =
  55. {
  56.     { 'ifil', 12500 },
  57.     { 'ffil', 14500 },
  58.     { 'sfil', 14000 },
  59.     { 'tfil', 14501 },
  60.     { 'FFIL', 15500 },
  61.     { 'DFIL', 15750 },
  62.     { 'kfil', 14750 }
  63. };
  64.  
  65.  
  66. short    Find_generic_icon_id(
  67. /* --> */    OSType the_type,
  68. /* <-- */    EGenericIconLocation    *inWhere )
  69. {
  70.     short    id;
  71.     short        index;
  72.     short        tableSize;
  73.     
  74.     id = kGenericDocumentIconResource;    // default
  75.     
  76.     tableSize = sizeof(sFndrFileIconPair) / sizeof(FilePair);
  77.     
  78.     for (index = tableSize - 1; index >= 0; --index)
  79.     {
  80.         if (the_type == sFndrFileIconPair[index].file_type)
  81.         {
  82.             id = sFndrFileIconPair[index].icon_id;
  83.             break;
  84.         }
  85.     }
  86.     if (index >= 0)    // i.e. we found the type in that table
  87.     {
  88.         *inWhere = kGenericIconInFinder;
  89.     }
  90.     else
  91.     {
  92.         *inWhere = kGenericIconInSystem;
  93.         
  94.         tableSize = sizeof(sSysFileIconPair) / sizeof(FilePair);
  95.         
  96.         for (index = tableSize - 1; index >= 0; --index)
  97.         {
  98.             if (the_type == sSysFileIconPair[index].file_type)
  99.             {
  100.                 id = sSysFileIconPair[index].icon_id;
  101.                 break;
  102.             }
  103.         }
  104.         
  105.     }
  106.  
  107.     return id;
  108. }
  109.