home *** CD-ROM | disk | FTP | other *** search
- /*
-
- calendar.cwx
-
- This script writes the given date onto a calendar template (such as calendar.gdo).
- If no template has been loaded, it attempts to load "calendar.gdo".
-
- Copyright 1997 by TrueSpectra Inc.
-
- This code is provided purely for demonstration purposes and is not
- supported or under warranty. Feel free to modify and examine this
- example script for your own purposes.
-
- */
-
-
- /* Load utility functions. */
- call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
- call SysLoadFuncs
-
-
-
- /* Verify that we have a template installed. */
- call setupTemplate
-
-
- /* Determine the year/month to do. We do this by reading the caption of a hidden object. */
- dh = CwGetHandleFromObjectName(CwGetCurrentView(), 'TARGDATE' )
- dah = CwGetRegion( dh )
- targetdate = CwGetProperty( dah, 'caption')
-
- /* Find out important details about the month: */
-
- /* The year. */
- year = datergf( targetdate, "Y" )
-
- /* Name of the month.*/
- monthname = datergf( targetdate, "MN")
-
- call CwMsg 'Calendar for' targetdate||', ' monthname year
-
-
- /* Day of the week. datergf() gives us 1=Monday .. 7=Sunday, which I have to
- shift a bit to fit my GDO. */
- wday = datergf( datergf( targetdate, "MB"), "DI") + 1
- IF wday > 7 THEN wday = 1
-
- /* Determine the number of days in the month. */
- lastday = datergf( datergf( targetdate, "ME"), "D")
-
-
- /* Now, clear the previous day numbers. */
- h = 0
- DO day = 1 TO 7
- DO week = 1 TO 6
- name = n||week||day
- CALL SetText name, ''
- END
- END
-
-
-
- /* Write in the current month and year. */
- CALL SetText 'month', monthname
- CALL SetText 'year', year
-
- /* Finally, write in the dates. */
- week = 1
- DO day = 1 TO lastday
- CALL SetText 'n'||week||wday, day
- wday = wday + 1
- IF wday > 7 THEN DO
- wday = 1
- week = week + 1
- end
- end
-
-
- /* Exit politely.*/
- exit
-
-
-
-
-
- /* Set the text of a text object. */
- SetText: PROCEDURE
- ARG object, text
-
- dh = CwGetHandleFromObjectName(CwGetCurrentView(), object )
- dah = CwGetRegion( dh )
- CALL CwSetProperty dah, 'caption', text
-
- return
-
-
-
-
-
- /* Call out to the datergf.cmd script to do date calculations.*/
- datergf:procedure
- parse arg date, operation
-
- /* Find exact path of the date routine. */
- settings = CwGetAppHandle("Preferences")
- scriptPath = CwGetProperty(settings, "Macro Directory")
-
- if substr(scriptPath, length(scriptPath)) \= '\' then
- scriptPath = scriptPath||'\'
- scriptPath = scriptPath||"datergf.cmd"
-
- /* Verify that the date routine is, in fact, there. */
- if 0 \= SysFileTree(scriptPath, file, "F") then do
- call CwMsg "Fatal error: out of memory."
- exit
- end
-
- if file.0 \= 1 then do
- call CwMsg "Error: Unable to find 'datergf.cmd'. This script MUST be in" ,
- "the macro directory for this script to work."
- exit
- end
-
- expr = "result = '"||scriptPath||"'(" date "," operation ")"
- interpret expr
-
- return result
-
-
-
-
- /* Determine if the current GDO is a valid calendar template. */
- isTemplate:procedure
-
- if \checkFor('TARGDATE') | \checkFor('Month') then
- return 0
-
- valid = 1
- do day = 1 to 7
- do week = 1 to 6
- name = n||week||day
- if \checkFor(name) then
- valid = 0
- end
- end
- return valid
-
-
-
-
- /* Return true if an object with the given name exists, false otherwise. */
- checkFor:procedure
- parse arg name
-
- s = CwIsHandleValid(CwGetHandleFromObjectName(CwGetCurrentView(), name))
- return s
-
-
- /* Load a calendar template GDO or die trying. */
- setupTemplate:procedure
-
- /* If the current project isn't a template, we have to try to load one.*/
- if \isTemplate() then do
-
- /* If there's a project in the current view, we ask the user if
- it's OK to stomp on it. */
- if CwGetObjectCount(CwGetCurrentView()) \= 0 then do
- ok = RxMessageBox("There's no calendar template loaded. Should",
- "I load one over the current project?", "Warning!!!","yesno")
- if ok \= 6 then
- exit
- end
-
- /* the template will be found in the script directory */
- pref = CwGetAppHandle( "preferences" );
- scriptdir = CwGetProperty( pref, "macro directory" );
- filename = scriptdir || "\calendar.gdo";
- say "loading " filename;
-
- /* Try to load the new gdo. */
- signal on syntax name cantImportTemplate
- call CwImportProject filename
- signal off syntax
- return
-
- /* If we couldn't load it, exit gracefully.*/
- cantImportTemplate:
- signal off syntax
- call CwMsg "I can't load a calendar template (e.g. calendar.gdo)." ,
- "Please load one manually."
- exit
- end
-
- return
-
-
-
-
-
-