home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Frameworks / Extension Shell 1.3 / Sample Extensions / WhatKey ƒ / WhatKey.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-06  |  6.9 KB  |  273 lines  |  [TEXT/R*ch]

  1. /*    NAME:
  2.         WhatKey.c 
  3.  
  4.     WRITTEN BY:
  5.         Dair Grant
  6.  
  7.     DESCRIPTION:
  8.         This file contains a CODE resource to be used as a handler by
  9.         Extension Shell.
  10.  
  11.     ___________________________________________________________________________
  12.  
  13.     VERSION HISTORY:
  14.         (Jan 1994, dg)
  15.             •    First publicly distributed version.
  16.  
  17.  
  18.     ___________________________________________________________________________
  19. */
  20. //=============================================================================
  21. //        Include files                                                                     
  22. //-----------------------------------------------------------------------------
  23. #include <GestaltEqu.h>
  24. #include "ParamBlock.h"
  25. #include "StandaloneCode.h"
  26. #include "ESConstants.h"
  27. #include "WhatKey.h"
  28. #include "CodeConstants.h"
  29.  
  30.  
  31.  
  32.  
  33.  
  34. //=============================================================================
  35. //        Private function prototypes                                                                     
  36. //-----------------------------------------------------------------------------
  37. void    main(short theMsg, ESParamBlock *theParamBlock);
  38. void    InitialiseParamBlock(void);
  39. void    InitialiseAddrsTable(void);
  40. void    HandleTheError(void);
  41. void    SetUpIcons(int animDelay, int numIcons, int firstIcon);
  42.  
  43.  
  44.  
  45.  
  46.  
  47. //=============================================================================
  48. //        Global variables                                                                 
  49. //-----------------------------------------------------------------------------
  50. ESParamBlock    *gTheParamBlock;
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. //=============================================================================
  62. //        main : Entry point to our code resource.                                                                 
  63. //-----------------------------------------------------------------------------
  64. //        Note :    Extension Shell communicates with us via a message constant,
  65. //                and a pointer to a structure it owns. Our job is to fill in
  66. //                the details, depending on what it wants us to do. It takes
  67. //                care of the rest.
  68. //-----------------------------------------------------------------------------
  69. void main(short theMsg, ESParamBlock *theParamBlock)
  70. {
  71.  
  72.  
  73.  
  74.  
  75.     // Set up A4 so that we can access our globals, and initialise them.
  76.     GetGlobals();
  77.     gTheParamBlock = theParamBlock;
  78.  
  79.  
  80.  
  81.     // Case out on what we have to do
  82.     switch(theMsg) {
  83.         case kInitialiseParamBlock:
  84.              InitialiseParamBlock();
  85.              break;
  86.              
  87.         case kInitialiseAddrsTable:
  88.              InitialiseAddrsTable();
  89.              break;
  90.  
  91.         case kHandleError:
  92.              HandleTheError();
  93.              break;
  94.     
  95.         default:
  96.              ;
  97.     }
  98.  
  99.  
  100.  
  101.     // Restore A4.
  102.     UngetGlobals();
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. //=============================================================================
  115. //        InitialiseParamBlock : Initialises the ParamBlock.                                                                 
  116. //-----------------------------------------------------------------------------
  117. //        Note :    We have three things we want to do:
  118. //                    • Check to see if we can still run
  119. //                    • Set up the icons we want to display
  120. //                    • Set up the code we want installed.
  121. //-----------------------------------------------------------------------------
  122. void InitialiseParamBlock(void)
  123. {    int        i;
  124.  
  125.  
  126.  
  127.  
  128.     // Check for System 7. We depend on having System 7, and won't
  129.     // run if we don't have it. We beep, and post a relevent
  130.     // error message.
  131.     if (gTheParamBlock->systemVersion < 0x0700)
  132.         {
  133.         gTheParamBlock->beepNow                = true;
  134.         gTheParamBlock->postError            = true;
  135.         gTheParamBlock->errorStringsID        = kErrorStrings;
  136.         gTheParamBlock->errorStringIndex    = kNeedSystemSeven;
  137.  
  138.  
  139.         // Icon details
  140.         SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  141.         }
  142.     
  143.     
  144.     
  145.     // If a shift key, or the mouse button, is down, we don't load either.
  146.     // We don't post an error, but just show our disabled icon(s).
  147.     else if ((*gTheParamBlock->UserForcedDisable)(kShiftKey, true))
  148.         {
  149.         // Icon details
  150.         SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  151.         }
  152.     
  153.     
  154.     
  155.     // Otherwise, we're allowed to run so we show our icon(s) as normal,
  156.     // and install the code we have to install.
  157.     else
  158.         {
  159.         // Icon details
  160.         SetUpIcons(kEnabledAnimDelay, kMyNumEnabledIcons, kMyFirstEnabledIcon);
  161.         
  162.         
  163.         // We install one code resource, and use an address table.
  164.         gTheParamBlock->installAddressTable        = true;
  165.         gTheParamBlock->addressTableSelector    = kWhatKeyAddressTable;
  166.         gTheParamBlock->numCodeResources        = 1;
  167.  
  168.  
  169.         // Details for our jGNEFilter routine.
  170.         gTheParamBlock->theCodeResources[kWhatKey].resType        = kWhatKeyResType;
  171.         gTheParamBlock->theCodeResources[kWhatKey].resID        = kWhatKeyResID;
  172.         gTheParamBlock->theCodeResources[kWhatKey].codeType        = kLowMemFilterType;
  173.         gTheParamBlock->theCodeResources[kWhatKey].theCodeThing.theLowMemFilter.theEntryPoint = kJGNEFilterAddress;
  174.         }
  175. }
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186. //=============================================================================
  187. //        InitialiseAddrsTable : Initialise the address table.                                                     
  188. //-----------------------------------------------------------------------------
  189. //        Note :    If we are being used in a Control Panel, we will probably have
  190. //                implemented the address table code with a custom code resource
  191. //                that returns a structure with an address table embedded at the
  192. //                start. This function's job is to correctly initialise the
  193. //                extended fields of that structure. If we're not using a
  194. //                (custom) address table then we don't do anything.
  195. //
  196. //                The message for this routine will only arrive if we've
  197. //                requested an address table.
  198. //-----------------------------------------------------------------------------
  199. void InitialiseAddrsTable(void)
  200. {
  201.  
  202.  
  203.  
  204. }
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215. //=============================================================================
  216. //        HandleTheError : Handle any errors                                                             
  217. //-----------------------------------------------------------------------------
  218. //        Note :    If any error occurs, we beep, post an error, and remove our
  219. //                code. We also have to reset the icon details to show our
  220. //                disabled icons.
  221. //-----------------------------------------------------------------------------
  222. void HandleTheError(void)
  223. {
  224.  
  225.  
  226.  
  227.  
  228.     // General error handling settings
  229.     gTheParamBlock->removeInstalledCode    = true;
  230.     gTheParamBlock->beepNow                = true;
  231.     gTheParamBlock->postError            = true;
  232.     gTheParamBlock->errorStringsID        = kErrorStrings;
  233.  
  234.  
  235.  
  236.     // Icon details
  237.     SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  238.  
  239.  
  240.  
  241.     // Just give a general error.
  242.     gTheParamBlock->errorStringIndex = kUnknownError;
  243. }
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254. //=============================================================================
  255. //        SetUpIcons : Set up our icons accordingly.                                                         
  256. //-----------------------------------------------------------------------------
  257. //        Note :    We are passed in the resource ID of the first icon, the number
  258. //                of icons, and a delay for animation. We just fill in the fields
  259. //                in the paramBlock.
  260. //-----------------------------------------------------------------------------
  261. void SetUpIcons(int animDelay, int numIcons, int firstIcon)
  262. {    int        i;
  263.  
  264.  
  265.  
  266.  
  267.     // Fill in the fields
  268.     gTheParamBlock->animationDelay    = animDelay;
  269.     gTheParamBlock->numIcons        = numIcons;
  270.     for (i = 1; i <= numIcons; i++)
  271.         gTheParamBlock->theIcons[i] = firstIcon + i - 1;
  272. }
  273.