home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 November / PCO_1198.ISO / filesbbs / os2 / tspg202s.arj / TSPG202S.ZIP / Scripts / CALENDAR.CWX < prev    next >
Encoding:
Text File  |  1997-05-11  |  4.6 KB  |  200 lines

  1. /*
  2.   
  3.   calendar.cwx
  4.   
  5.   This script writes the given date onto a calendar template (such as calendar.gdo).
  6.   If no template has been loaded, it attempts to load "calendar.gdo".
  7.   
  8.  Copyright 1997 by TrueSpectra Inc.                                  
  9.                                                                      
  10.  This code is provided purely for demonstration purposes and is not  
  11.  supported or under warranty.  Feel free to modify and examine this  
  12.  example script for your own purposes.                               
  13.  
  14.   */
  15.  
  16.  
  17. /* Load utility functions. */
  18. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  19. call SysLoadFuncs
  20.  
  21.  
  22.  
  23. /* Verify that we have a template installed. */
  24. call setupTemplate
  25.  
  26.  
  27. /* Determine the year/month to do.  We do this by reading the caption of a hidden object. */
  28. dh = CwGetHandleFromObjectName(CwGetCurrentView(), 'TARGDATE' )
  29. dah = CwGetRegion( dh )
  30. targetdate = CwGetProperty( dah, 'caption')
  31.  
  32. /* Find out important details about the month: */
  33.  
  34. /*      The year. */
  35. year = datergf( targetdate, "Y" )
  36.  
  37. /*      Name of the month.*/
  38. monthname = datergf( targetdate, "MN")
  39.  
  40. call CwMsg 'Calendar for' targetdate||', ' monthname year
  41.  
  42.  
  43. /* Day of the week.  datergf() gives us 1=Monday .. 7=Sunday, which I have to
  44.    shift a bit to fit my GDO. */
  45. wday = datergf( datergf( targetdate, "MB"), "DI") + 1
  46. IF wday > 7 THEN wday = 1
  47.  
  48. /* Determine the number of days in the month. */
  49. lastday = datergf( datergf( targetdate, "ME"), "D")
  50.  
  51.  
  52. /* Now, clear the previous day numbers. */
  53. h = 0
  54. DO day = 1 TO 7
  55.     DO week = 1 TO 6
  56.         name = n||week||day
  57.         CALL SetText name, ''
  58.         END
  59.     END
  60.  
  61.  
  62.  
  63. /* Write in the current month and year. */
  64. CALL SetText 'month', monthname
  65. CALL SetText 'year', year
  66.  
  67. /* Finally, write in the dates. */
  68. week = 1
  69. DO day = 1 TO lastday
  70.     CALL SetText 'n'||week||wday, day
  71.     wday = wday + 1
  72.     IF wday > 7 THEN DO
  73.         wday = 1
  74.         week = week + 1
  75.         end
  76.     end
  77.  
  78.  
  79. /* Exit politely.*/
  80. exit
  81.  
  82.  
  83.  
  84.  
  85.  
  86. /* Set the text of a text object. */
  87. SetText: PROCEDURE
  88. ARG object, text
  89.  
  90. dh = CwGetHandleFromObjectName(CwGetCurrentView(), object )
  91. dah = CwGetRegion( dh )
  92. CALL CwSetProperty dah, 'caption', text
  93.  
  94. return
  95.  
  96.  
  97.  
  98.  
  99.  
  100. /* Call out to the datergf.cmd script to do date calculations.*/
  101. datergf:procedure
  102. parse arg date, operation
  103.  
  104. /* Find exact path of the date routine. */
  105. settings = CwGetAppHandle("Preferences")
  106. scriptPath = CwGetProperty(settings, "Macro Directory")
  107.  
  108. if substr(scriptPath, length(scriptPath)) \= '\' then 
  109.     scriptPath = scriptPath||'\'
  110. scriptPath = scriptPath||"datergf.cmd"
  111.  
  112. /* Verify that the date routine is, in fact, there. */
  113. if 0 \= SysFileTree(scriptPath, file, "F") then do
  114.     call CwMsg "Fatal error: out of memory."
  115.     exit
  116.     end
  117.  
  118. if file.0 \= 1 then do
  119.     call CwMsg "Error: Unable to find 'datergf.cmd'.  This script MUST be in" ,
  120.         "the macro directory for this script to work."
  121.     exit
  122.     end
  123.  
  124. expr = "result = '"||scriptPath||"'(" date "," operation ")"
  125. interpret expr
  126.  
  127. return result
  128.  
  129.  
  130.  
  131.  
  132. /* Determine if the current GDO is a valid calendar template. */
  133. isTemplate:procedure
  134.  
  135. if \checkFor('TARGDATE') | \checkFor('Month') then
  136.     return 0
  137.  
  138. valid = 1
  139. do day = 1 to 7
  140.     do week = 1 to 6
  141.         name = n||week||day
  142.         if \checkFor(name) then
  143.             valid = 0
  144.         end
  145.     end
  146. return valid
  147.  
  148.  
  149.  
  150.  
  151. /* Return true if an object with the given name exists, false otherwise. */
  152. checkFor:procedure
  153. parse arg name
  154.  
  155. s = CwIsHandleValid(CwGetHandleFromObjectName(CwGetCurrentView(), name))
  156. return s
  157.  
  158.  
  159. /* Load a calendar template GDO or die trying. */
  160. setupTemplate:procedure
  161.  
  162. /* If the current project isn't a template, we have to try to load one.*/
  163. if \isTemplate() then do
  164.  
  165.     /* If there's a project in the current view, we ask the user if
  166.        it's OK to stomp on it. */
  167.     if CwGetObjectCount(CwGetCurrentView()) \= 0 then do
  168.         ok = RxMessageBox("There's no calendar template loaded.  Should", 
  169.             "I load one over the current project?", "Warning!!!","yesno")
  170.         if ok \= 6 then
  171.             exit
  172.         end
  173.  
  174.     /* the template will be found in the script directory */
  175.     pref = CwGetAppHandle( "preferences" );
  176.     scriptdir = CwGetProperty( pref, "macro directory" );
  177.     filename = scriptdir || "\calendar.gdo";
  178.     say "loading " filename;
  179.  
  180.     /* Try to load the new gdo. */
  181.     signal on syntax name cantImportTemplate
  182.     call CwImportProject filename
  183.     signal off syntax
  184.     return
  185.  
  186.     /* If we couldn't load it, exit gracefully.*/
  187.     cantImportTemplate:
  188.     signal off syntax
  189.     call CwMsg "I can't load a calendar template (e.g. calendar.gdo)." ,
  190.         "Please load one manually."
  191.     exit
  192.     end
  193.  
  194. return 
  195.  
  196.  
  197.     
  198.  
  199.     
  200.