home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / Argus Clock 1.2 / Clock.c next >
Encoding:
C/C++ Source or Header  |  1994-05-03  |  15.2 KB  |  731 lines  |  [TEXT/KAHL]

  1. /*
  2.     CLOCK
  3.     
  4.     by
  5.     Argus Software Engineering
  6.     21 Oct 93
  7.     
  8.     Revision 1.1 (4 Mar 94)
  9.     - Changed minimum sleep variable from 15L to 60L
  10.       to help speed up background tasks (if any).
  11.     - Changed UPDATE_PARAM from 60 to 90 so you can
  12.       read date a little easier.
  13.     - Added military time option.
  14.     
  15.     Revision 1.2 (3 May 94)
  16.     - Cleaned up code and added more error checks.
  17.     
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <time.h>
  24.  
  25. #define CLOCK_TOP            10
  26. #define CLOCK_SIZE            9
  27. #define CLOCK_FONT            1
  28. #define CLOCK_TITLE            "\pClock"
  29. #define WIN_HEIGHT            12
  30. #define WIN_LENGTH            55
  31. #define FROM_RIGHT            13
  32. #define FROM_TOP            23
  33. #define REF_CON                0
  34. #define PROC_ID                2
  35. #define UPDATE_PARAM        90
  36. #define DELTA                1
  37. #define MAX_LINE_LENGTH        80
  38.  
  39. #define MAX_DELIMITERS   10
  40. #define LINE_FEED        10
  41. #define RETURN           13
  42. #define SPACE            32
  43. #define TAB              9
  44.  
  45. #define DEFAULTX            -100
  46. #define DEFAULTY            -100
  47. #define DEFAULTDATE            1
  48. #define DEFAULTMILITARY        0
  49.  
  50. #define BASE_RES_ID            400
  51. #define NIL_POINTER            0L
  52. #define MOVE_TO_FRONT        -1L
  53. #define REMOVE_ALL_EVENTS    0
  54.  
  55. #define APPLE_MENU_ID        400
  56. #define FILE_MENU_ID        401
  57. #define EDIT_MENU_ID        402
  58. #define SETUP_MENU_ID        403
  59.  
  60. #define ABOUT_ITEM            1
  61. #define ABOUT_ALERT            400
  62. #define ERROR_ALERT_ID        401
  63.  
  64. #define NO_MBAR                BASE_RES_ID
  65. #define NO_MENU                BASE_RES_ID+1
  66. #define WRITE_ERROR            BASE_RES_ID+2
  67. #define PREF_ERROR            BASE_RES_ID+3
  68. #define PREFERENCES            500
  69.  
  70. #define QUIT_ITEM            1
  71.  
  72. #define UNDO_ITEM            1
  73. #define CUT_ITEM            3
  74. #define COPY_ITEM            4
  75. #define PASTE_ITEM            5
  76. #define CLEAR_ITEM            6
  77.  
  78. #define SET_ITEM            1
  79. #define DATE_ITEM            2
  80. #define MILITARY_ITEM        3
  81. #define DEFAULT_ITEM        5
  82.  
  83. #define DRAG_THRESHOLD        5
  84.  
  85. #define MIN_SLEEP            60L
  86. #define NIL_MOUSE_REGION    0L
  87.  
  88. #define LEAVE_WHERE_IT_IS    FALSE
  89.  
  90. #define WNE_TRAP_NUM        0x60
  91. #define UNIMPL_TRAP_NUM        0x9F
  92.  
  93. #define NIL_STRING            "\p"
  94. #define FATAL_ERROR            "\pFatal Error."
  95.  
  96. Boolean            gDone, gWNEImplemented;
  97. EventRecord        gTheEvent;
  98. MenuHandle        gAppleMenu, gFileMenu, gEditMenu, gSetupMenu;
  99. Rect            gDragRect;
  100.  
  101. time_t            now;
  102. long int        ticksNow, ticksOld;
  103. struct             tm    *date;
  104. WindowPtr        clockWindow;
  105. int                winX, winY, dateItem, militaryItem;
  106. char            delimiters[MAX_DELIMITERS];
  107. StringHandle    preferencesStringH;
  108. StringHandle    tempH;
  109. char            *preferencesString;
  110. char            oldstring[80] = "Old time";
  111.  
  112. /* Prototypes - minimum required */
  113. int        IsDAWindow        ( WindowPtr whichWindow );
  114.  
  115. /******************************** main *********/
  116.  
  117. main()
  118. {
  119.     ToolBoxInit();
  120.     MenuBarInit();
  121.     SetUpDragRect();
  122.     ReadPreferences();
  123.     CreateWindow();
  124.     MainLoop();
  125. }
  126.  
  127.  
  128. /*********************************** ToolBoxInit */
  129.  
  130. ToolBoxInit()
  131. {
  132.     InitGraf( &thePort );
  133.     InitFonts();
  134.     FlushEvents( everyEvent, REMOVE_ALL_EVENTS );
  135.     InitWindows();
  136.     InitMenus();
  137.     TEInit();
  138.     InitDialogs( NIL_POINTER );
  139.     InitCursor();
  140. }
  141.  
  142.  
  143. /***********************************    MenuBarInit    */
  144.  
  145. MenuBarInit()
  146. {
  147.     Handle        myMenuBar;
  148.     WindowPtr    temp;
  149.  
  150.     if ( ( myMenuBar = GetNewMBar( BASE_RES_ID ) ) == NIL_POINTER )
  151.         ErrorHandler( NO_MBAR );
  152.     SetMenuBar( myMenuBar );
  153.     if ( ( gAppleMenu = GetMHandle( APPLE_MENU_ID ) ) == NIL_POINTER )
  154.         ErrorHandler( NO_MENU );
  155.     if ( ( gFileMenu = GetMHandle( FILE_MENU_ID ) ) == NIL_POINTER )
  156.         ErrorHandler( NO_MENU );
  157.     if ( ( gEditMenu = GetMHandle( EDIT_MENU_ID ) ) == NIL_POINTER )
  158.         ErrorHandler( NO_MENU );
  159.     if ( ( gSetupMenu = GetMHandle( SETUP_MENU_ID ) ) == NIL_POINTER )
  160.         ErrorHandler( NO_MENU );
  161.  
  162.     AddResMenu( gAppleMenu, 'DRVR' );
  163.     DrawMenuBar();
  164. }
  165.  
  166.  
  167. /******************************** SetUpDragRect *********/
  168.  
  169. SetUpDragRect()
  170. {
  171.     gDragRect = screenBits.bounds;
  172.     gDragRect.left += DRAG_THRESHOLD;
  173.     gDragRect.right -= DRAG_THRESHOLD;
  174.     gDragRect.bottom -= DRAG_THRESHOLD;
  175. }
  176.  
  177.  
  178. /******************************** ReadPreferences *********/
  179.  
  180. ReadPreferences()
  181. {
  182.   char         *str_ptr;
  183.   char         buffer[MAX_LINE_LENGTH];
  184.   char         string[MAX_LINE_LENGTH];
  185.   int            i;
  186.     
  187.     sprintf(delimiters,"%c%c%c%c",LINE_FEED,SPACE,RETURN,TAB);
  188.     if( ( preferencesStringH = GetString(PREFERENCES) ) == NULL )
  189.     {    /* Use default settings if can't read resource */
  190.         winX = DEFAULTX;
  191.         winY = DEFAULTY;
  192.         dateItem = DEFAULTDATE;
  193.         militaryItem = DEFAULTMILITARY;
  194.     }
  195.     else
  196.     {    /* Use settings read from resource file */
  197.         HLock( preferencesStringH);
  198.         preferencesString = *preferencesStringH;
  199.         for( i = 0; i < MAX_LINE_LENGTH - 2; i++ )
  200.         {
  201.             string[i] = *(preferencesString + i);
  202.         }
  203.         str_ptr = PtoCstr( (char *)string );
  204.         
  205.         if( strlen( str_ptr ) < 20 )
  206.             ErrorHandler( PREF_ERROR );        
  207.         
  208.         strcpy(buffer, str_ptr);
  209.         str_ptr = strtok(buffer,delimiters);
  210.            strcpy(string,str_ptr);      
  211.            winX = atoi(string);
  212.            str_ptr = strtok(NULL,delimiters);
  213.            strcpy(string,str_ptr);      
  214.            winY = atoi(string);
  215.            str_ptr = strtok(NULL,delimiters);
  216.            strcpy(string,str_ptr);      
  217.            dateItem = atoi(string);
  218.            str_ptr = strtok(NULL,delimiters);
  219.            strcpy(string,str_ptr);      
  220.            militaryItem = atoi(string);
  221.     }
  222.  
  223.   if( dateItem )
  224.     CheckItem( gSetupMenu, DATE_ITEM, TRUE );
  225.   else
  226.     CheckItem( gSetupMenu, DATE_ITEM, FALSE );
  227.     
  228.   if( militaryItem )
  229.     CheckItem( gSetupMenu, MILITARY_ITEM, TRUE );
  230.   else
  231.     CheckItem( gSetupMenu, MILITARY_ITEM, FALSE );
  232.     
  233.   ticksNow = TickCount();
  234.   ticksOld = ticksNow;
  235. }
  236.  
  237.  
  238. /******************************** MainLoop *********/
  239.  
  240. MainLoop()
  241. {
  242.     gDone = FALSE;
  243.     gWNEImplemented = ( NGetTrapAddress( WNE_TRAP_NUM, ToolTrap ) !=
  244.                         NGetTrapAddress( UNIMPL_TRAP_NUM, ToolTrap ) );
  245.     while ( gDone == FALSE )
  246.     {
  247.         HandleEvent();
  248.     }
  249. }
  250.  
  251.  
  252. /************************************* HandleEvent     */
  253.  
  254. HandleEvent()
  255. {
  256.     char    theChar;
  257.     GrafPtr    oldPort;
  258.             
  259.     if ( gWNEImplemented )
  260.         WaitNextEvent( everyEvent, &gTheEvent, MIN_SLEEP, NIL_MOUSE_REGION );
  261.     else
  262.     {
  263.         SystemTask();
  264.         GetNextEvent( everyEvent, &gTheEvent );
  265.     }
  266.  
  267.     switch ( gTheEvent.what )
  268.     {
  269.         case nullEvent:
  270.             HandleNull();
  271.             break;
  272.         case mouseDown: 
  273.             HandleMouseDown();
  274.             break;
  275.         case keyDown:
  276.         case autoKey:
  277.             theChar = gTheEvent.message & charCodeMask;
  278.             if (( gTheEvent.modifiers & cmdKey ) != 0)
  279.             {
  280.                 AdjustMenus(); 
  281.                 HandleMenuChoice( MenuKey( theChar ) );
  282.             }
  283.             break;
  284.         case updateEvt:
  285.             if (!IsDAWindow( (WindowPtr)gTheEvent.message ) )
  286.             {
  287.                 strcpy( oldstring, "Update me" );
  288.                 GetPort( &oldPort );
  289.                 SetPort( (WindowPtr)gTheEvent.message );
  290.                 BeginUpdate( (WindowPtr)gTheEvent.message );
  291.                 DrawClock( clockWindow );
  292.                 EndUpdate( (WindowPtr)gTheEvent.message );
  293.                 SetPort( oldPort );
  294.             }
  295.             break;
  296.     }
  297. }
  298.  
  299.  
  300. /************************************* HandleMouseDown */
  301.  
  302. HandleMouseDown()
  303. {
  304.     WindowPtr    whichWindow;
  305.     short int    thePart;
  306.     long int    menuChoice, windSize;
  307.     
  308.     thePart = FindWindow( gTheEvent.where, &whichWindow );
  309.     switch ( thePart )
  310.     {
  311.         case inMenuBar:
  312.             AdjustMenus();
  313.             menuChoice = MenuSelect( gTheEvent.where );
  314.             HandleMenuChoice( menuChoice );
  315.             break;
  316.         case inSysWindow: 
  317.             SystemClick( &gTheEvent, whichWindow );
  318.             break;
  319.         case inDrag: 
  320.             DragWindow( whichWindow, gTheEvent.where, &gDragRect );
  321.             break;
  322.         case inGoAway: 
  323.             DisposeWindow( whichWindow );
  324.             break;
  325.         case inContent:
  326.             /* SelectWindow( whichWindow );  Don't need - only 1 window */
  327.             if( dateItem )
  328.                 DrawDate( clockWindow );
  329.             else
  330.                 DrawMyString( clockWindow );
  331.             DragWindow( whichWindow, gTheEvent.where, &gDragRect );    
  332.             ticksOld = TickCount();        
  333.             break;
  334.     }
  335. }
  336.  
  337. /************************************* AdjustMenus */
  338.  
  339. AdjustMenus()
  340. {
  341.     WindowPtr    currentWindow;
  342.     
  343.     currentWindow = FrontWindow();
  344.     if (IsDAWindow( currentWindow ) )
  345.     {
  346.         EnableItem(gEditMenu, UNDO_ITEM );
  347.         EnableItem(gEditMenu, CUT_ITEM );
  348.         EnableItem(gEditMenu, COPY_ITEM );
  349.         EnableItem(gEditMenu, PASTE_ITEM );
  350.         EnableItem(gEditMenu, CLEAR_ITEM );
  351.     }
  352.     else
  353.     {
  354.         DisableItem(gEditMenu, UNDO_ITEM );
  355.         DisableItem(gEditMenu, CUT_ITEM );
  356.         DisableItem(gEditMenu, COPY_ITEM );
  357.         DisableItem(gEditMenu, PASTE_ITEM );
  358.         DisableItem(gEditMenu, CLEAR_ITEM );
  359.     }
  360. }
  361.  
  362.  
  363. /************************************* IsDAWindow */
  364.  
  365. int    IsDAWindow( whichWindow )
  366. WindowPtr    whichWindow;
  367. {
  368.     if ( whichWindow == NIL_POINTER )
  369.         return( FALSE );
  370.     else /* DA windows have negative windowKinds */
  371.         return( ( (WindowPeek)whichWindow )->windowKind < 0 );
  372. }
  373.  
  374.  
  375. /************************************* HandleMenuChoice */
  376.  
  377. HandleMenuChoice( menuChoice )
  378. long int    menuChoice;
  379. {
  380.     int    theMenu;
  381.     int    theItem;
  382.     
  383.     if ( menuChoice != 0 )
  384.     {
  385.         theMenu = HiWord( menuChoice );
  386.         theItem = LoWord( menuChoice );
  387.         switch ( theMenu )
  388.         {
  389.             case APPLE_MENU_ID :
  390.                 HandleAppleChoice( theItem );
  391.                 break;
  392.             case FILE_MENU_ID :
  393.                 HandleFileChoice( theItem );
  394.                 break;
  395.             case EDIT_MENU_ID :
  396.                 HandleEditChoice( theItem );
  397.                 break;
  398.             case SETUP_MENU_ID :
  399.                 HandleSetupChoice( theItem );
  400.                 break;
  401.         }
  402.         HiliteMenu( 0 );
  403.     }
  404. }
  405.  
  406.  
  407. /********************************    HandleAppleChoice    *******/
  408.  
  409. HandleAppleChoice( theItem )
  410. int    theItem;
  411. {
  412.     Str255        accName;
  413.     int            accNumber;
  414.     
  415.     switch ( theItem )
  416.     {
  417.         case ABOUT_ITEM : 
  418.             Alert( ABOUT_ALERT, NIL_POINTER );
  419.             break;
  420.         default :
  421.             GetItem( gAppleMenu, theItem, accName );
  422.             accNumber = OpenDeskAcc( accName );
  423.             break;
  424.     }
  425. }
  426.  
  427.  
  428. /********************************    HandleFileChoice    *******/
  429.  
  430. HandleFileChoice( theItem )
  431. int    theItem;
  432. {
  433.     switch ( theItem )
  434.     {
  435.         case QUIT_ITEM :
  436.             gDone = TRUE;
  437.             break;
  438.     }
  439. }
  440.  
  441.  
  442. /********************************    HandleEditChoice    *******/
  443.  
  444. HandleEditChoice( theItem )
  445. int    theItem;
  446. {
  447.     SystemEdit( theItem - 1 );
  448. }
  449.  
  450.  
  451. /********************************    HandleSetupChoice    *******/
  452.  
  453. HandleSetupChoice( theItem )
  454. int    theItem;
  455. {
  456.     switch ( theItem )
  457.     {
  458.         case SET_ITEM :
  459.             SaveSettings();
  460.             break;
  461.         case DATE_ITEM :
  462.             if( dateItem )
  463.             {
  464.                 CheckItem( gSetupMenu, DATE_ITEM, FALSE );
  465.                 dateItem = 0;
  466.             }
  467.             else
  468.             {
  469.                 CheckItem( gSetupMenu, DATE_ITEM, TRUE );
  470.                 dateItem = 1;
  471.             }
  472.             break;
  473.         case MILITARY_ITEM :
  474.             if( militaryItem )
  475.             {
  476.                 CheckItem( gSetupMenu, MILITARY_ITEM, FALSE );
  477.                 militaryItem = 0;
  478.             }
  479.             else
  480.             {
  481.                 CheckItem( gSetupMenu, MILITARY_ITEM, TRUE );
  482.                 militaryItem = 1;
  483.             }
  484.             break;                    
  485.         case DEFAULT_ITEM :
  486.             winX = DEFAULTX;
  487.             winY = DEFAULTY;
  488.             dateItem = DEFAULTDATE;
  489.             if( dateItem )
  490.                 CheckItem( gSetupMenu, DATE_ITEM, TRUE );
  491.             else
  492.                 CheckItem( gSetupMenu, DATE_ITEM, FALSE );
  493.             DisposeWindow( clockWindow );
  494.             CreateWindow();
  495.             /* ? SaveSettings(); ? */
  496.             break;
  497.     }
  498. }
  499.  
  500.  
  501. /************************************ CreateWindow  */
  502.  
  503. CreateWindow()
  504. {
  505.     WindowRecord    *myWinRec;
  506.     Rect            myWinRect;
  507.     Str255             myTitle = CLOCK_TITLE;
  508.     int                myprocID = PROC_ID;
  509.     Ptr                myBehind = (Ptr)MOVE_TO_FRONT;
  510.     long            myrefCon = REF_CON;
  511.  
  512.     myWinRect = screenBits.bounds;
  513.     myWinRect.left = myWinRect.right - WIN_LENGTH - FROM_RIGHT;
  514.     myWinRect.right = myWinRect.left + WIN_LENGTH;
  515.     myWinRect.top = myWinRect.top + FROM_TOP;
  516.     myWinRect.bottom = myWinRect.top + WIN_HEIGHT;
  517.     
  518.     if( ( (winX > 0) && (winX < screenBits.bounds.right) ) &&
  519.           ( (winY > 0) && (winY < screenBits.bounds.bottom) ) )
  520.     {
  521.         myWinRect.left = winX;
  522.         myWinRect.right = myWinRect.left + WIN_LENGTH;
  523.         myWinRect.top = winY;
  524.         myWinRect.bottom = myWinRect.top + WIN_HEIGHT;
  525.     }
  526.     
  527.     myWinRec = NIL_POINTER;
  528.     clockWindow = NewWindow(    myWinRec, &myWinRect, myTitle, 
  529.                                 TRUE, myprocID, myBehind, FALSE, myrefCon        );
  530.     
  531.     ShowWindow( clockWindow );
  532.     SetPort( clockWindow );
  533.     TextFont( CLOCK_FONT );
  534.     TextSize( CLOCK_SIZE );
  535. }
  536.  
  537.  
  538. /******************************** ErrorHandler *********/
  539.  
  540. ErrorHandler( stringNum )
  541. int    stringNum;
  542. {
  543.     StringHandle    errorStringH;
  544.     
  545.     if ( ( errorStringH = GetString( stringNum ) ) == NIL_POINTER )
  546.         ParamText( FATAL_ERROR, NIL_STRING, NIL_STRING, NIL_STRING );
  547.     else
  548.     {
  549.         HLock( errorStringH );
  550.         ParamText( *errorStringH, NIL_STRING, NIL_STRING, NIL_STRING );
  551.         HUnlock( errorStringH );
  552.     }
  553.     StopAlert( ERROR_ALERT_ID, NIL_POINTER );
  554.     ExitToShell();
  555. }
  556.  
  557.  
  558. /******************************** DisplayError *********/
  559.  
  560. DisplayError( stringNum )
  561. int    stringNum;
  562. {
  563.     StringHandle    errorStringH;
  564.     
  565.     if ( ( errorStringH = GetString( stringNum ) ) == NIL_POINTER )
  566.     {
  567.         ParamText( FATAL_ERROR, NIL_STRING, NIL_STRING, NIL_STRING );
  568.         StopAlert( ERROR_ALERT_ID, NIL_POINTER );
  569.         ExitToShell();
  570.     }
  571.     else
  572.     {
  573.         HLock( errorStringH );
  574.         ParamText( *errorStringH, NIL_STRING, NIL_STRING, NIL_STRING );
  575.         HUnlock( errorStringH );
  576.         CautionAlert( ERROR_ALERT_ID, NIL_POINTER );
  577.     }
  578.     
  579. }
  580.  
  581.  
  582. /******************************** HandleNull *********/
  583.  
  584. HandleNull( )
  585. {
  586.     ticksNow = TickCount();
  587.     if( (ticksNow - ticksOld) >= UPDATE_PARAM )
  588.         DrawClock( clockWindow );
  589. }
  590.  
  591.  
  592. /******************************** SaveSettings *********/
  593.  
  594. SaveSettings( )
  595. {
  596.       Point        temp;
  597.     GrafPtr        portHolder;
  598.     int            myResult = 0;
  599.     long int     i;
  600.     int            errorCode;    
  601.     char        *myStrPtr;
  602.     char        myArr[MAX_LINE_LENGTH] = "                                        ";
  603.     
  604.     temp.h = 1;
  605.     temp.v = 1;
  606.     GetPort( &portHolder );
  607.     SetPort( clockWindow );
  608.     LocalToGlobal( &temp );
  609.     SetPort( portHolder );
  610.     winX = temp.h;
  611.     winY = temp.v;
  612.     
  613.     /* String length = 22 */
  614.     sprintf( myArr, "%5d %5d %1d %1d       ", winX - 1, winY - 1, dateItem, militaryItem );
  615.     
  616.     HUnlock( preferencesStringH );
  617.     HPurge( preferencesStringH );
  618.     LoadResource( preferencesStringH );
  619.     HLock( preferencesStringH );      
  620.     HNoPurge( preferencesStringH );
  621.     
  622.     myStrPtr = (char *)*preferencesStringH;
  623.     myStrPtr = myStrPtr + 1;
  624.     for( i = 0; i < 30; i++ )
  625.     {
  626.         *myStrPtr = myArr[i];
  627.         myStrPtr = myStrPtr + 1;
  628.     }
  629.     ChangedResource( preferencesStringH );
  630.     errorCode = ResError();
  631.     if( errorCode != 0 )
  632.         myResult = 1;
  633.     WriteResource( preferencesStringH );
  634.     errorCode = ResError();
  635.     if( errorCode != 0 )
  636.         myResult = 1;
  637.     if( myResult )
  638.         DisplayError( WRITE_ERROR );
  639. }
  640.  
  641.  
  642. /******************************** DrawClock *********/
  643.  
  644. DrawClock( theWindow )
  645. WindowPtr    theWindow;
  646. {
  647.     char        s[80];
  648.     GrafPtr        portHolder;
  649.     int            horizontal_position;
  650.     int            string_length;
  651.     
  652.     time( &now );
  653.     date = localtime( &now );
  654.     if( militaryItem )
  655.         strftime( s, 80, "%H:%M", date );
  656.     else
  657.         strftime( s, 80, "%X", date );
  658.         
  659.     if( strcmp( s, oldstring ) == 0 )
  660.     {
  661.         /* Do nothing, same time. */
  662.     }
  663.     else
  664.     {
  665.         strcpy( oldstring, s );
  666.         CtoPstr( s );
  667.         string_length = StringWidth ( s );
  668.         horizontal_position = (WIN_LENGTH / 2) - (string_length / 2);
  669.         GetPort( &portHolder );
  670.         SetPort( theWindow );
  671.         EraseRect( &( theWindow->portRect ) );
  672.         MoveTo( horizontal_position, CLOCK_TOP );
  673.         DrawString( s );
  674.         SetPort( portHolder );
  675.     }
  676.     ticksOld = ticksNow;
  677.     
  678. }
  679.  
  680.  
  681. /******************************** DrawDate *********/
  682.  
  683. DrawDate( theWindow )
  684. WindowPtr    theWindow;
  685. {
  686.     char        s[80];
  687.     GrafPtr        portHolder;
  688.     int            horizontal_position;
  689.     int            string_length;
  690.     
  691.     time( &now );
  692.     date = localtime( &now );
  693.     strftime( s, 80, "%x", date );
  694.     CtoPstr( s );
  695.     string_length = StringWidth ( s );
  696.     horizontal_position = (WIN_LENGTH / 2) - (string_length / 2);
  697.  
  698.     GetPort( &portHolder );
  699.     SetPort( theWindow );
  700.     EraseRect( &( theWindow->portRect ) );
  701.     MoveTo( horizontal_position, CLOCK_TOP );
  702.     DrawString( s );
  703.     ticksOld = ticksNow;
  704.     SetPort( portHolder );
  705.     strcpy( oldstring, "Update me" );
  706. }
  707.  
  708.  
  709. /******************************** DrawMyString *********/
  710.  
  711. DrawMyString( theWindow )
  712. WindowPtr    theWindow;
  713. {
  714.     Str255        myString = "\pARGUS";
  715.     GrafPtr        portHolder;
  716.     int            horizontal_position;
  717.     int            string_length;
  718.     
  719.     string_length = StringWidth ( myString );
  720.     horizontal_position = (WIN_LENGTH / 2) - (string_length / 2) + DELTA;
  721.  
  722.     GetPort( &portHolder );
  723.     SetPort( theWindow );
  724.     EraseRect( &( theWindow->portRect ) );
  725.     MoveTo( horizontal_position, CLOCK_TOP );
  726.     DrawString( myString );
  727.     ticksOld = ticksNow;
  728.     SetPort( portHolder );
  729.     strcpy( oldstring, "Update me" );
  730. }
  731.