home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / BoxMaker++ / Touch ƒ / touchshell.cp < prev    next >
Encoding:
Text File  |  1995-01-20  |  2.5 KB  |  129 lines  |  [TEXT/KAHL]

  1. #include <Types.h>
  2. #include <Memory.h>
  3. #include <QuickDraw.h>
  4. #include <OSUtils.h>
  5. #include <ToolUtils.h>
  6. #include <Menus.h>
  7. #include <Packages.h>
  8. #include <Traps.h>
  9. #include <Files.h>
  10. #include <Aliases.h>
  11. #include <AppleEvents.h>
  12. #include <GestaltEqu.h>
  13. #include <Processes.h>
  14. #include <Fonts.h>
  15. #include <OSEvents.h>
  16. #include <Resources.h>
  17. #include <Desk.h>
  18.  
  19. #include "boxmaker constants.h"
  20. #include "boxmaker.h"
  21. #include "preferences.cp"
  22. #include "touchshell.h"
  23.  
  24. #pragma template_access public
  25.  
  26. void main();
  27.  
  28. void main()
  29. {
  30.     touchsettings defaultSettings =
  31.     {
  32.         touchshell::kSecondButton,
  33.         touchshell::kModDate
  34.     };
  35.     StringHandle prefsFileHandle = GetString( 128);
  36.     touchshell it( *(Str255 *)*prefsFileHandle, defaultSettings);
  37.     it.run();
  38. }
  39.  
  40. touchshell::touchshell( Str255 prefsFileName, touchsettings &defaultsettings)
  41.         : boxmaker()
  42.         , touchprefs( prefsFileName, defaultsettings)
  43. {    
  44.     Handle times = Get1Resource( 'tims', 128);
  45.     
  46.     MoveHHi( times);
  47.     HLock( times);
  48.     
  49.     theGrains = (long *)*times;
  50.     
  51.     GetDateTime( &starting_time);
  52.     ChangeGrain( whichGrain);
  53.     ChangeDate( whichDate);
  54. }
  55.  
  56. void touchshell::OpenDoc( Boolean opening)
  57. {
  58.     if( opening)
  59.     {
  60.         if( whichDate != kModDate)
  61.         {
  62.             theCInfoPBRec.hFileInfo.ioFlCrDat = time_to_set;
  63.         }
  64.         if( whichDate != kCreatDate)
  65.         {
  66.             theCInfoPBRec.hFileInfo.ioFlMdDat = time_to_set;
  67.         }
  68.         theCInfoPBRec.hFileInfo.ioFDirIndex = 0;
  69.         const OSErr result = PBSetCatInfoSync( &theCInfoPBRec);
  70.         if( result != noErr)
  71.         {
  72.             SysBeep( 9);
  73.         }
  74.     }
  75. }
  76.  
  77. void touchshell::HandleDialogEvent( short itemHit, DialogPtr theDialog)
  78. {
  79.     switch( itemHit)
  80.     {
  81.         case kSecondButton:
  82.         case kMinuteButton:
  83.         case kHourButton:
  84.         case kHalfDayButton:
  85.         case kDayButton:
  86.         case kGroundZeroButton:
  87.             ChangeGrain( itemHit);
  88.             break;
  89.             
  90.         case kCreatDate:
  91.         case kModDate:
  92.         case kBothDates:
  93.             ChangeDate( itemHit);
  94.             break;
  95.     }
  96. }
  97.  
  98. void touchshell::ChangeGrain( int newGrain)
  99. {
  100.     short    iType;
  101.     Handle    iHandle;
  102.     Rect    iRect;
  103.  
  104.     for( int i = kSecondButton; i <= kGroundZeroButton; i++)
  105.     {
  106.         GetDItem( gMainDialog, i, &iType, &iHandle, &iRect);
  107.         SetCtlValue( (ControlHandle)iHandle, (i == newGrain));
  108.     }
  109.     whichGrain = newGrain;
  110.     const long granularity = theGrains[ whichGrain - 1];
  111.     
  112.     time_to_set = granularity *
  113.         ((starting_time + granularity - 1) / granularity);
  114. }
  115.  
  116. void touchshell::ChangeDate( int newDate)
  117. {
  118.     short    iType;
  119.     Handle    iHandle;
  120.     Rect    iRect;
  121.  
  122.     for( int i = kCreatDate; i <= kBothDates; i++)
  123.     {
  124.         GetDItem( gMainDialog, i, &iType, &iHandle, &iRect);
  125.         SetCtlValue( (ControlHandle)iHandle, (i == newDate));
  126.     }
  127.     whichDate = newDate;
  128. }
  129.