home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / macgzip_022-src / macos / think / ThePrefs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-26  |  19.3 KB  |  661 lines  |  [TEXT/KAHL]

  1. /*            SpinCursors by
  2.  *            America Online: LISPer
  3.  *             Internet: tree@uvm.edu
  4. */
  5. #ifndef _FOLDERS_
  6. #include <Folders.h>
  7. #endif
  8. #include <Script.h>
  9. #include <Balloons.h>
  10.  
  11. #include "ThePrefs.h"
  12. #include "MacErrors.h"
  13. #include "PopUp.h"
  14.  
  15.  
  16. /************************************************************************************/
  17.  
  18. #define kPrefsDialogID        130
  19. #define kSaveButtonItem        1
  20. #define kCancelButtonItem    2
  21.  
  22. #define    kKeepOrig            16
  23. #define kBeepWD                14
  24. #define kQuitWD                5
  25.  
  26. #define kForce                7
  27. #define    kBHelp                8
  28. #define kHelp                15
  29.  
  30. #define kCStKeys            26
  31. #define kUStKeys            27
  32. #define    kAltStKeys            30
  33.  
  34. #define kTEXTsuffix            3
  35. #define kTEXTcreator        4
  36. #define kTEXTbcreator        23
  37. #define kTEXTbtype            28
  38.  
  39. #define kTEXTlevel            10
  40.  
  41. #define kUpArrow            11
  42. #define kDownArrow            12
  43.  
  44. #define    kAsciiGzip            17
  45. #define    kAsciiGunzip        18
  46. #define    kGzip                19
  47.  
  48.  
  49. #define    kAsciiGzipMenu        128
  50. #define    kAsciiGunzipMenu    129
  51. #define    kGzipMenu            130
  52.  
  53. /* prefs file constants */
  54. #define kPrefsNameStrID            128
  55. #define kPrefsCreatorType        '\?\?\?\?'
  56. #define kPrefsFileType            'pref'
  57. #define kPrefsResourceType        'Pref'
  58. #define kPrefsResourceID        128
  59.  
  60. #define kFetchPrefsNameStrID    129
  61. #define kFetchPrefsResourceType    'SUFX'
  62. #define kFetchPrefsResourceID    1
  63.  
  64. #define kFinderMessageStrID    -16397 /* ID of STR for default finder message */
  65.                                    /* see Inside Mac VI, page 9-22         */
  66. #define kStrType            'STR '
  67.  
  68. #define CmdKeyMask            0x0100
  69.  
  70. /*
  71.  * From DialogBits,C.K. Haun
  72.  * Apple Developer Tech Support
  73.  */
  74.  
  75.  /* key equates */
  76. enum  {
  77.     kEnterKey        = 0x03, 
  78.     kTabKey            = 9, 
  79.     kReturnKey        = 0x0D, 
  80.     kBackSpace        = 8, 
  81.     kEscKey            = 0x1B, 
  82.     kLeftArrowKey    = 0x1C, 
  83.     kRightArrowKey, 
  84.     kUpArrowKey,
  85.     kDownArrowKey, 
  86.     kDeleteKey        = 0x7F
  87. };
  88.  
  89. pascal Boolean filterIt(DialogPtr inputDialog, EventRecord *myDialogEvent, short *theDialogItem);
  90.  
  91. pascal OSErr GetStdFilterProc(ModalFilterProcPtr *theProc) = 
  92. {
  93.     0x303C, 0x0203, 0xAA68
  94. };
  95.  
  96. /* Indicates to the dialog manager which item is default.  Will then alias the return key */
  97. /* to this item, and also bold border it for you (yaaaaa!) */
  98. pascal OSErr SetDialogDefaultItem(DialogPtr theDialog, short newItem)
  99. {
  100.     0x303C, 0x0304, 0xAA68
  101. };
  102.  
  103. /* Indicates which item should be aliased to escape or Command - . */
  104. pascal OSErr SetDialogCancelItem(DialogPtr theDialog, short newItem)
  105. {
  106.     0x303C, 0x0305, 0xAA68
  107. };
  108. /* End From DialogBits */
  109.  
  110. /* these constants may be stored in the fields of the prefs struct */
  111.  
  112. OSErr GetPrefsName (StringPtr prefName, short StrID);
  113.  
  114. PrefsType    currPrefs;
  115. Boolean        prefsChangedFlag;
  116.  
  117. Handle        FPrefs;
  118. Size        FPrefsSize=0;
  119.  
  120.  
  121.  
  122. short OpenPrefsResFile(SignedByte prefsPerm, Boolean createFlag, short StrID)
  123. /* open the preferences file with the given permission; if createFlag is set,
  124.    create a preferences file if necessary */
  125. {
  126.     OSErr retCode;
  127.     short prefsVRefNum;
  128.     long prefsDirID;
  129.     Str255 prefsNameStr;
  130.     FSSpec prefsFSSpec;
  131.     short prefsResRefNum;
  132.     
  133.     prefsResRefNum = -1;
  134.     /* get the name of the prefs file */
  135.     retCode = GetPrefsName(prefsNameStr, StrID);
  136.     if (retCode == noErr) {
  137.     
  138.         /* Use FindFolder to locate the Preferences folder.
  139.         
  140.            MPW 3.2 and some other compilers provide the
  141.            glue necessary to use FindFolder (and Gestalt) safely
  142.            under System 6 and earlier.  Under System 6, the dirID
  143.            returned for the Preferences folder request will be
  144.            the System folder's dirID */
  145.  
  146.         retCode = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
  147.             &prefsVRefNum, &prefsDirID);
  148.         if (retCode == noErr) {
  149.         
  150.             /* make a file spec for the prefs file */
  151.             
  152.             retCode = FSMakeFSSpec(prefsVRefNum, prefsDirID, prefsNameStr,
  153.                 &prefsFSSpec);
  154.                 
  155.             if (retCode == fnfErr && createFlag) {
  156.                 /* prefs file doesn't already exist, so create it */
  157.                 FSpCreateResFile(&prefsFSSpec, kPrefsCreatorType, kPrefsFileType,
  158.                     smSystemScript);
  159.                 retCode = ResError();
  160.             }
  161.             
  162.             /* open the prefs file */
  163.             if (retCode == noErr) {
  164.                 prefsResRefNum = FSpOpenResFile(&prefsFSSpec, prefsPerm);
  165.             }
  166.         }
  167.     }
  168.     return prefsResRefNum;
  169. }
  170.  
  171. OSErr GetPrefsName (StringPtr prefName, short StrID)
  172. /* get the name of the preferences file from a resource in the application */
  173. {
  174.     StringHandle prefStrHandle;
  175.     OSErr retCode = noErr;
  176.     
  177.     prefStrHandle = GetString(StrID);
  178.     if (prefStrHandle != nil) 
  179.         BlockMove(*prefStrHandle, prefName, (Size) (**prefStrHandle) + 1);
  180.     else retCode = resNotFound;
  181.     
  182.     return retCode;
  183. }
  184.  
  185. Boolean GetOrGeneratePrefs( PrefsType * thePrefsTypePtr, long wantedVers )
  186. /* fill in the prefs structure from the resource file or from scratch */
  187. {
  188.     short                prefsResRefNum;
  189.     Handle                tempHandle;
  190.     extern    Boolean        gSavedPos;
  191.     extern    Point        gSavedPoint;
  192.     
  193.     /* initialize prefs structure in case we can't get a valid set */
  194.     thePrefsTypePtr->prefsTypeVers =        wantedVers;
  195.     thePrefsTypePtr->compress =                false;
  196.     thePrefsTypePtr->ascii =                false;
  197.     thePrefsTypePtr->force =                false;
  198.     thePrefsTypePtr->level =                6;
  199.     thePrefsTypePtr->suffix[0] =            0x00;
  200.     BlockMove("\pttxt", thePrefsTypePtr->textcreator, 5);
  201.     BlockMove("\p\?\?\?\?", thePrefsTypePtr->bincreator, 5);
  202.     BlockMove("\p\?\?\?\?", thePrefsTypePtr->bintype, 5);
  203.     thePrefsTypePtr->KeepOriginals =        false;
  204.     thePrefsTypePtr->QuitWhenDone =            true;
  205.     thePrefsTypePtr->BeepWhenDone =            false;
  206.  
  207.     thePrefsTypePtr->AsciiCompress =        OnlyText;
  208.     thePrefsTypePtr->AsciiUnCompress =        UseMenu;
  209.     thePrefsTypePtr->ResourceCompress =        Ask;
  210.     thePrefsTypePtr->WhenCompress =            NonMacGzip;
  211.  
  212.     thePrefsTypePtr->DecodeHQX =    false;
  213.     thePrefsTypePtr->StKeysComp =    true;
  214.     thePrefsTypePtr->StKeysUnComp =    true;
  215.     thePrefsTypePtr->StKeysAlt =     true;
  216.  
  217.     thePrefsTypePtr->SavedPos = false;
  218.     thePrefsTypePtr->SavedPoint.h = 0;
  219.     thePrefsTypePtr->SavedPoint.v = 0;
  220.     
  221.     
  222.     /* open (but don't create) the prefs file */
  223.     prefsResRefNum = OpenPrefsResFile(fsRdPerm, false, kPrefsNameStrID);
  224.     if (prefsResRefNum != -1) {
  225.     
  226.         /* file opened successfully, get the prefs resource */
  227.         tempHandle = Get1Resource(kPrefsResourceType, kPrefsResourceID);
  228.         
  229.         /* if the resource is there and it's the right size and version, copy it */
  230.         /* (in C these can be combined with &&, but don't use AND in Pascal)     */
  231.         
  232.         if (tempHandle != nil)
  233.             if (GetHandleSize(tempHandle) == sizeof(PrefsType)) 
  234.                 if ((*(PrefsType *)*tempHandle).prefsTypeVers == wantedVers) {
  235.                 
  236.                     /* copy the prefs struct */
  237.                     *thePrefsTypePtr = *(PrefsType *)*tempHandle;
  238.                     
  239.                 }
  240.         /* release the pref resource and close the file */
  241.         CloseResFile(prefsResRefNum);
  242.         
  243.     /* Get Fetch Prefs */
  244.     if( thePrefsTypePtr->AsciiUnCompress == Fetch )
  245.     {
  246.     if((prefsResRefNum = OpenPrefsResFile(fsRdPerm, false, kFetchPrefsNameStrID))!=-1)
  247.         {
  248.             tempHandle = GetResource('SUFX',1);
  249.             FPrefs = tempHandle;
  250.             HandToHand( &FPrefs );
  251.             FPrefsSize = GetHandleSize(FPrefs);
  252.             ReleaseResource( tempHandle );
  253.             CloseResFile(prefsResRefNum);
  254.         }
  255.         else
  256.         {
  257.             /* Fetch Prefs not found; set to menu */
  258.             Calert("Warning: 'Fetch Prefs' not found. Check your Prefs. folder");
  259.             thePrefsTypePtr->AsciiUnCompress = UseMenu;
  260.         }
  261.     }
  262.     
  263.         gSavedPos = thePrefsTypePtr->SavedPos;
  264.         gSavedPoint.h = thePrefsTypePtr->SavedPoint.h;
  265.         gSavedPoint.v = thePrefsTypePtr->SavedPoint.v;
  266.  
  267.     return true;
  268.     
  269.     }
  270.     else
  271.         return false;
  272. }
  273. OSErr SavePrefs(PrefsType * thePrefsTypePtr )
  274. /* save the prefs structure in the prefs resource file */
  275. {
  276.     OSErr retCode;
  277.     short prefsResRefNum;
  278.     Handle prefHandle, finderMessageHandle;
  279.     
  280.     /* open (and, if necessary, create) the prefs file */
  281.     prefsResRefNum = OpenPrefsResFile(fsRdWrPerm, true, kPrefsNameStrID);
  282.     if (prefsResRefNum != -1) {
  283.     
  284.         /* file opened successfully, get the prefs resource */
  285.         prefHandle = Get1Resource(kPrefsResourceType, kPrefsResourceID);
  286.         
  287.         if (prefHandle == nil) {
  288.         
  289.             /* create a new resource */
  290.             prefHandle = NewHandle(sizeof(PrefsType));
  291.             if (prefHandle != nil) {
  292.             
  293.                 /* copy the prefs struct into the handle
  294.                    and make it into a resource */
  295.                 
  296.                 *(PrefsType *)*prefHandle = *thePrefsTypePtr;
  297.                 AddResource(prefHandle, kPrefsResourceType, kPrefsResourceID, 
  298.                     "\pPrefsType");
  299.                 retCode = ResError();
  300.                 if (retCode != noErr) DisposHandle(prefHandle);
  301.             } 
  302.             
  303.             else retCode = MemError(); /* NewHandle failed */
  304.         }
  305.         
  306.         else {  /* prefHandle != nil */
  307.         
  308.             /* update the existing resource */
  309.             SetHandleSize(prefHandle, sizeof(PrefsType));
  310.             retCode = MemError();
  311.             if (retCode == noErr) {
  312.  
  313.                 /* copy the prefs struct into the handle and tell the rsrc manager */
  314.                 *(PrefsType *)*prefHandle = *thePrefsTypePtr;
  315.                 ChangedResource(prefHandle);
  316.             }
  317.         }
  318.         if (retCode == noErr) {
  319.         
  320.             /* add the message to be displayed if the user tries
  321.                to open the prefs file in the Finder (but don't add it
  322.                if it's already in the preferences file) */
  323.                
  324.             finderMessageHandle = (Handle) GetString(kFinderMessageStrID);
  325.             if (finderMessageHandle != nil &&
  326.                 HomeResFile((Handle) finderMessageHandle) != prefsResRefNum) {
  327.             
  328.                 /* copy the resource into the prefs file */
  329.                 DetachResource(finderMessageHandle);
  330.                 AddResource(finderMessageHandle, kStrType, kFinderMessageStrID,
  331.                     "\pFinder message");
  332.                     
  333.                 /* if AddResource failed, dispose of the handle */
  334.                 retCode = ResError();
  335.                 if (retCode != noErr) DisposHandle(finderMessageHandle);
  336.             }
  337.         }
  338.         
  339.         /* update and close the preference resource file, 
  340.            releasing its resources from memory */
  341.         CloseResFile(prefsResRefNum);
  342.     }
  343.     
  344.     else {
  345.         /* couldn't open the res file */
  346.         retCode = ResError();
  347.         if (retCode == noErr) retCode = resFNotFound;
  348.     }
  349.     
  350.     return retCode;
  351. }
  352. /***********************Dialog*************/
  353. Boolean DoPrefsDialog(PrefsType * thePrefsTypePtr)
  354. /* display the prefs dialog; returns true if change made to prefs record */
  355. {
  356.     GrafPtr savePort;
  357.     DialogPtr prefDialogPtr;
  358.     short item;
  359.     Boolean doneFlag = false;
  360.     Boolean    SaveBalloons;
  361.     OSErr retCode;
  362.  
  363.     /* keep the new preference settings only in local variables
  364.        in case the user cancels */
  365.        
  366.     PrefsType newPrefsType;
  367.  
  368.     short        itemType;
  369.     Handle        itemHandle;
  370.     Rect        itemRect;
  371.     Str255        sTemp;
  372.     
  373.     Boolean changedFlag;
  374.  
  375.  
  376.     /* the old settings are our starting point, so copy them */
  377.     newPrefsType = *thePrefsTypePtr;
  378.     
  379.     /* throw up the dialog */
  380.     prefDialogPtr = GetNewDialog(kPrefsDialogID, nil, (WindowPtr) -1);
  381.     if (prefDialogPtr == nil) ExitToShell();  /* hurtin’ bad */
  382.     
  383.     SetDialogDefaultItem( prefDialogPtr, kSaveButtonItem);
  384.     SetDialogCancelItem( prefDialogPtr, kCancelButtonItem);
  385.  
  386.     /* set up the dialog to the initial values */
  387.     SaveBalloons = HMGetBalloons();
  388.  
  389.     GetDItem(prefDialogPtr, kForce, &itemType, &itemHandle, &itemRect);
  390.     SetCtlValue((ControlHandle) itemHandle, ( newPrefsType.force ? 1 : 0));
  391.  
  392.     GetDItem(prefDialogPtr,kTEXTlevel, &itemType, &itemHandle, &itemRect);
  393.     NumToString( (long)thePrefsTypePtr->level, sTemp );
  394.     SetIText(itemHandle,sTemp);
  395.  
  396.  
  397.  
  398.     GetDItem(prefDialogPtr, kTEXTsuffix, &itemType, &itemHandle, &itemRect);
  399.     SetIText(itemHandle,thePrefsTypePtr->suffix);
  400.  
  401.     
  402.     
  403.     GetDItem(prefDialogPtr, kTEXTcreator, &itemType, &itemHandle, &itemRect);
  404.     SetIText(itemHandle,thePrefsTypePtr->textcreator);
  405.     
  406.     GetDItem(prefDialogPtr, kTEXTbcreator, &itemType, &itemHandle, &itemRect);
  407.     SetIText(itemHandle,thePrefsTypePtr->bincreator);
  408.  
  409.     GetDItem(prefDialogPtr, kTEXTbtype, &itemType, &itemHandle, &itemRect);
  410.     SetIText(itemHandle,thePrefsTypePtr->bintype);
  411.  
  412.     SelIText(prefDialogPtr, kTEXTbcreator, 0, 32767);
  413.  
  414.     GetDItem(prefDialogPtr, kKeepOrig, &itemType, &itemHandle, &itemRect);
  415.     SetCtlValue((ControlHandle) itemHandle, ( newPrefsType.KeepOriginals ? 1 : 0));
  416.  
  417.     GetDItem(prefDialogPtr, kBeepWD, &itemType, &itemHandle, &itemRect);
  418.     SetCtlValue((ControlHandle) itemHandle, ( newPrefsType.BeepWhenDone ? 1 : 0));
  419.  
  420.     GetDItem(prefDialogPtr, kQuitWD, &itemType, &itemHandle, &itemRect);
  421.     SetCtlValue((ControlHandle) itemHandle, ( newPrefsType.QuitWhenDone ? 1 : 0));
  422.  
  423.  
  424.     GetDItem(prefDialogPtr, kAsciiGzip, &itemType, &itemHandle, &itemRect);
  425.     PopUp[kAsciiGzip-PopUpBaseItem].MenuRect = itemRect;
  426.     PopUp[kAsciiGzip-PopUpBaseItem].MenuID = kAsciiGzipMenu;
  427.     PopUp[kAsciiGzip-PopUpBaseItem].Menu = GetMenu(kAsciiGzipMenu);
  428.     PopUp[kAsciiGzip-PopUpBaseItem].Selection = newPrefsType.AsciiCompress;
  429.     SetItemMark(PopUp[kAsciiGzip-PopUpBaseItem].Menu,PopUp[kAsciiGzip-PopUpBaseItem].Selection,checkMark);
  430.     SetDItem(prefDialogPtr, kAsciiGzip, itemType, &DrawPopUp, &itemRect);
  431.  
  432.     GetDItem(prefDialogPtr, kAsciiGunzip, &itemType, &itemHandle, &itemRect);
  433.     PopUp[kAsciiGunzip-PopUpBaseItem].MenuRect = itemRect;
  434.     PopUp[kAsciiGunzip-PopUpBaseItem].MenuID = kAsciiGunzipMenu;
  435.     PopUp[kAsciiGunzip-PopUpBaseItem].Menu = GetMenu(kAsciiGunzipMenu);
  436.     PopUp[kAsciiGunzip-PopUpBaseItem].Selection = newPrefsType.AsciiUnCompress;
  437.     SetItemMark(PopUp[kAsciiGunzip-PopUpBaseItem].Menu,PopUp[kAsciiGunzip-PopUpBaseItem].Selection,checkMark);
  438.     SetDItem(prefDialogPtr, kAsciiGunzip, itemType, &DrawPopUp, &itemRect);
  439.  
  440.     GetDItem(prefDialogPtr, kGzip, &itemType, &itemHandle, &itemRect);
  441.     PopUp[kGzip-PopUpBaseItem].MenuRect = itemRect;
  442.     PopUp[kGzip-PopUpBaseItem].MenuID = kGzipMenu;
  443.     PopUp[kGzip-PopUpBaseItem].Menu = GetMenu(kGzipMenu);
  444.     PopUp[kGzip-PopUpBaseItem].Selection = newPrefsType.WhenCompress;
  445.     SetItemMark(PopUp[kGzip-PopUpBaseItem].Menu,PopUp[kGzip-PopUpBaseItem].Selection,checkMark);
  446.     SetDItem(prefDialogPtr, kGzip, itemType, &DrawPopUp, &itemRect);
  447.  
  448.     GetDItem(prefDialogPtr, kCStKeys, &itemType, &itemHandle, &itemRect);
  449.     SetCtlValue((ControlHandle) itemHandle, ( newPrefsType.StKeysComp ? 1 : 0));
  450.     
  451.     GetDItem(prefDialogPtr, kUStKeys, &itemType, &itemHandle, &itemRect);
  452.     SetCtlValue((ControlHandle) itemHandle, ( newPrefsType.StKeysUnComp ? 1 : 0));
  453.     
  454.     GetDItem(prefDialogPtr, kAltStKeys, &itemType, &itemHandle, &itemRect);
  455.     SetCtlValue((ControlHandle) itemHandle, ( newPrefsType.StKeysAlt ? 1 : 0));
  456.  
  457.     GetDItem(prefDialogPtr, kHelp, &itemType, &itemHandle, &itemRect);
  458.     SetCtlValue((ControlHandle) itemHandle, SaveBalloons);
  459.  
  460.     do {
  461.         GetPort(&savePort);
  462.         SetPort(prefDialogPtr);
  463.  
  464.         ModalDialog((ModalFilterProcPtr)filterIt, &item);
  465.         switch(item) {
  466.         
  467.             
  468.             case kSaveButtonItem:
  469.                 /* user wants to save the current or new settings */
  470.                 
  471.                 /* copy the editText string into the new prefs record */
  472.                 GetDItem(prefDialogPtr, kTEXTcreator, &itemType, &itemHandle, &itemRect);
  473.                 GetIText(itemHandle, newPrefsType.textcreator);
  474.                 
  475.                 GetDItem(prefDialogPtr, kTEXTbcreator, &itemType, &itemHandle, &itemRect);
  476.                 GetIText(itemHandle, newPrefsType.bincreator);
  477.                 
  478.                 GetDItem(prefDialogPtr, kTEXTbtype, &itemType, &itemHandle, &itemRect);
  479.                 GetIText(itemHandle, newPrefsType.bintype);
  480.  
  481.                 GetDItem(prefDialogPtr, kTEXTsuffix, &itemType, &itemHandle, &itemRect);
  482.                 GetIText(itemHandle, newPrefsType.suffix);
  483.                 
  484.                 if(newPrefsType.textcreator[0]!=0x04)
  485.                 {
  486.                     Calert( "Text creator not valid (Only 4 chars!)" );
  487.                     SelIText(prefDialogPtr, kTEXTcreator, 0, 32767);
  488.                 }
  489.                 else if (newPrefsType.bincreator[0]!=0x04)
  490.                 {
  491.                     Calert( "Binary creator not valid (Only 4 chars!)" );
  492.                     SelIText(prefDialogPtr, kTEXTbcreator, 0, 32767);
  493.                 }
  494.                 else if (newPrefsType.bintype[0]!=0x04)
  495.                 {
  496.                     Calert( "Binary type not valid (Only 4 chars!)" );
  497.                     SelIText(prefDialogPtr, kTEXTbtype, 0, 32767);
  498.                 }
  499.                 else
  500.                 {
  501.                         /* replace the old record with the new record */
  502.                         
  503.                         newPrefsType.AsciiCompress = PopUp[kAsciiGzip-PopUpBaseItem].Selection;
  504.                         newPrefsType.AsciiUnCompress = PopUp[kAsciiGunzip-PopUpBaseItem].Selection;
  505.                         newPrefsType.WhenCompress = PopUp[kGzip-PopUpBaseItem].Selection;
  506.                         
  507.                         *thePrefsTypePtr = newPrefsType;
  508.                         doneFlag = true;
  509.                 }
  510.                 
  511.                 if (( FPrefsSize==0) && (newPrefsType.AsciiUnCompress==Fetch))
  512.                 {
  513.                     Calert("You must restart MacGzip for your changes to take effect");
  514.                 }
  515.                 break;
  516.                 
  517.             case kCancelButtonItem:
  518.                 /* abandon the new preferences structure */
  519.                 doneFlag = true;
  520.                 break;
  521.                 
  522.             case kForce:
  523.             
  524.                 newPrefsType.force = !newPrefsType.force;
  525.                 GetDItem(prefDialogPtr, kForce, &itemType, &itemHandle, &itemRect);
  526.                 SetCtlValue((ControlHandle) itemHandle, ( newPrefsType.force ? 1 : 0));
  527.                 break;
  528.                 
  529.             case kUpArrow:
  530.             
  531.                 if ( newPrefsType.level < 9 )
  532.                 {
  533.                     newPrefsType.level++;
  534.                     GetDItem(prefDialogPtr,kUpArrow, &itemType, &itemHandle, &itemRect);
  535.                     InvertRect(&itemRect);
  536.                     while (StillDown())
  537.                     ;
  538.                     InvertRect(&itemRect);
  539.                     GetDItem(prefDialogPtr,kTEXTlevel, &itemType, &itemHandle, &itemRect);
  540.                     NumToString( (long)newPrefsType.level, sTemp );
  541.                     SetIText(itemHandle,sTemp);
  542.                 }
  543.                 break;
  544.                 
  545.             case kDownArrow:
  546.             
  547.                 if ( newPrefsType.level > 1 )
  548.                 {
  549.                     newPrefsType.level--;
  550.                     GetDItem(prefDialogPtr,kDownArrow, &itemType, &itemHandle, &itemRect);
  551.                     InvertRect(&itemRect);
  552.                     while (StillDown())
  553.                     ;
  554.                     InvertRect(&itemRect);
  555.                     GetDItem(prefDialogPtr,kTEXTlevel, &itemType, &itemHandle, &itemRect);
  556.                     NumToString( (long)newPrefsType.level, sTemp );
  557.                     SetIText(itemHandle,sTemp);
  558.                 }
  559.                 break;
  560.                 
  561.             case kKeepOrig:
  562.             
  563.                 newPrefsType.KeepOriginals = !newPrefsType.KeepOriginals;
  564.                 GetDItem(prefDialogPtr, kKeepOrig, &itemType, &itemHandle, &itemRect);
  565.                 SetCtlValue((ControlHandle) itemHandle, ( newPrefsType.KeepOriginals ? 1 : 0));
  566.                 break;
  567.  
  568.             case kQuitWD:
  569.             
  570.                 newPrefsType.QuitWhenDone = !newPrefsType.QuitWhenDone;
  571.                 GetDItem(prefDialogPtr, kQuitWD, &itemType, &itemHandle, &itemRect);
  572.                 SetCtlValue((ControlHandle) itemHandle, ( newPrefsType.QuitWhenDone ? 1 : 0));
  573.                 break;
  574.                 
  575.             case kBeepWD:
  576.             
  577.                 newPrefsType.BeepWhenDone = !newPrefsType.BeepWhenDone;
  578.                 GetDItem(prefDialogPtr, kBeepWD, &itemType, &itemHandle, &itemRect);
  579.                 SetCtlValue((ControlHandle) itemHandle, ( newPrefsType.BeepWhenDone ? 1 : 0));
  580.                 break;
  581.                 
  582.             case kAsciiGzip:
  583.             case kAsciiGunzip:
  584.             case kGzip:
  585.             
  586.                 DoPopUp(prefDialogPtr, item);
  587.                 break;
  588.             
  589.             case kCStKeys:
  590.             
  591.                 newPrefsType.StKeysComp = !newPrefsType.StKeysComp;
  592.                 GetDItem(prefDialogPtr, kCStKeys, &itemType, &itemHandle, &itemRect);
  593.                 SetCtlValue((ControlHandle) itemHandle, ( newPrefsType.StKeysComp ? 1 : 0));
  594.                 break;
  595.                 
  596.             case kUStKeys:
  597.             
  598.                 newPrefsType.StKeysUnComp = !newPrefsType.StKeysUnComp;
  599.                 GetDItem(prefDialogPtr, kUStKeys, &itemType, &itemHandle, &itemRect);
  600.                 SetCtlValue((ControlHandle) itemHandle, ( newPrefsType.StKeysUnComp ? 1 : 0));
  601.                 break;
  602.  
  603.             case kAltStKeys:
  604.             
  605.                 newPrefsType.StKeysAlt = !newPrefsType.StKeysAlt;
  606.                 GetDItem(prefDialogPtr, kAltStKeys, &itemType, &itemHandle, &itemRect);
  607.                 SetCtlValue((ControlHandle) itemHandle, ( newPrefsType.StKeysAlt ? 1 : 0));
  608.                 break;
  609.  
  610.             case kHelp:
  611.             case kBHelp:
  612.             
  613.                 HMSetBalloons(!HMGetBalloons());
  614.                 GetDItem(prefDialogPtr, kHelp, &itemType, &itemHandle, &itemRect);
  615.                 SetCtlValue((ControlHandle) itemHandle, HMGetBalloons());
  616.                 break;
  617.  
  618.                 
  619.         }
  620.     } while (!doneFlag);
  621.     
  622.     HMSetBalloons(SaveBalloons);
  623.     DisposDialog(prefDialogPtr);
  624.     
  625.     SetPort(savePort);
  626.  
  627.     /* if the user clicked Save, return true */
  628.     return (item == kSaveButtonItem);
  629. }
  630.  
  631. pascal Boolean filterIt(DialogPtr inputDialog, EventRecord *myDialogEvent, short *theDialogItem)
  632. {
  633.     ModalFilterProcPtr theModalProc;
  634.     Boolean returnVal = false;
  635.     char theKey;
  636.     
  637.     if (((myDialogEvent->what == keyDown) || (myDialogEvent->what == autoKey)) &&
  638.         (myDialogEvent->modifiers & CmdKeyMask))
  639.     {
  640.         theKey = myDialogEvent->message & charCodeMask;
  641.         switch (theKey)
  642.         {
  643.             case kUpArrowKey:
  644.                             *theDialogItem = kUpArrow;
  645.                             returnVal = true;
  646.                             break;
  647.             case kDownArrowKey:
  648.                             *theDialogItem = kDownArrow;
  649.                             returnVal = true;
  650.                             break;
  651.         }
  652.     }
  653.     
  654.     if (!returnVal)
  655.         if (GetStdFilterProc(&theModalProc) == noErr)
  656.             returnVal=theModalProc(inputDialog, myDialogEvent, theDialogItem);
  657.  
  658.     return(returnVal);
  659. }