home *** CD-ROM | disk | FTP | other *** search
- /*
- @BMakeCalendar @P@Iby Robin Evans, April/August, 1992
- Creates a calendar for the specified month and year
- */
-
- signal on halt
- signal on break_c
- signal on break_e
- signal on break_d
-
- call ppm_ShowStatus("MakeCalendar")
- call SafeEndEdit.rexx()
- call ppm_AutoUpdate(0)
- cr = '0a'x
-
- units = ppm_GetUnits()
- call ppm_SetUnits(2)
-
- page = ppm_CurrentPage()
- if page = 0 then
- exit_msg("Create Page First")
-
- IsBox = ppm_PageFirstBox(page)
- if IsBox == 0 then
- exit_msg("Create box to hold calendar")
-
- OrgBox = ppm_ClickOnBox("Click on box to contain calendar")
- if box = 0 then
- exit_msg()
- else
- if upper(word(ppm_GetBoxInfo(OrgBox), 1)) ~= 'EMPTY' then
- exit_msg("Box must be empty.")
-
-
- PrefForm = ppm_GetForm("Calendar preferences", 10, SetPrefs())
- if PrefForm = '' then
- exit_msg('Aborted.')
- else
- PrefStore = PrefForm
-
-
- call ppm_ShowStatus("MakeCalendar.")
-
- /* Color lists are used to check input on the requester */
- parse value ppm_GetColorList() with . '0a'x ColorList
- ColorStr = translate(upper(ColorList), ' ', '0a'x)
-
- do i = 1 to PrefType.NumPrefs
- parse var PrefForm value '0a'x PrefForm
- interpret word(PrefType.i.com, 2) '=' word(PrefType.i.com, 1)'("'value'",'i')'
- end
-
- if year < 51 then
- year = year + 2000
- else
- if year < 100 & year > 49 then year = 1900 + year
-
-
- call ppm_ShowStatus("MakeCalendar..")
-
- parse value ppm_getboxsize(OrgBox) with bWid OrgHi .
- parse value ppm_getboxposition(OrgBox) with bLeft OrgTop .
-
- /* Calculate size of font for month/year Title bar and of Calendar box*/
- FTitleSize = OrgHi/18
-
- bHi = OrgHi - FTitleSize
- bTop = OrgTop + FTitleSize
- bRight = bLeft + bWid
- bBot = bTop + bHi
- cwidth = bWid / 7
- rheight = bHi / 5
-
- if bHi < 8 & MemoFld then do
- if ppm_Inform(2, "Box is too small"'0a'x"for memos", ' Cancel ', ' Okay ') == 1 then
- MemoFld = 0
- else
- exit_msg('Aborted.')
- end
-
- DateFont = ppm_SelectFromList("Choose font for dates", 32, 8, 0, FontList.rexx(ppm_GetFont()))
- if DateFont = '' then exit_msg()
- if memoFld then
- MemoFont = ppm_SelectFromList("Choose font for memos", 32, 8, 0, FontList.rexx(ppm_GetFont()))
-
- /* Create box for month/year Title bar */
- TitleBox = CreateBox(bLeft, OrgTop, bWid, FTitleSize + FTitleSize * .9, 0, 'TitleBox')
-
- /* reset the original box below the title box */
- call ppm_setboxsize(OrgBox, bWid, bHi)
- call ppm_setboxposition(OrgBox, bLeft, bTop)
-
- /* Add month & year to title bar */
- call ppm_ShowStatus("MakeCalendar...")
- call ppm_BoxNum(TitleBox) /* Make it the active box */
- TSize = ppm_SetSize(PPtoPoints(ppm_ConvertUnits(2,3, FTitleSize)))
- call ppm_SetFont(DateFont)
- call ppm_SetTextColor(TColor)
- call ppm_SetLineSpacing(0, -TSize)
- if TBold then
- setB = '\B'
- else
- setB = '\b'
- call ppm_TextIntoBox(TitleBox, setB'\jl' || word(monthWords, IntMonth) || '0a'x'\jr'Year)
-
-
- /* Prepare original box for date numerals */
-
- call ppm_ShowStatus("MakeCalendar....")
-
- call ppm_BoxNum(OrgBox) /* Make it the active box */
- call ppm_SetBoxFrame(OrgBox, 0)
-
- /* Calculate and set text size and leading for dates */
- FontMeasure = min(rheight, cwidth)
- LittleFont = max(.3528, FontMeasure / 4)
- BigFont = max(.3528, FontMeasure / 1.5)
- if SmallFont then
- DSizeCM = LittleFont
- else
- DSizeCM = BigFont
-
- DSize = ppm_SetSize(PPtoPoints(ppm_ConvertUnits(2,3, DSizeCM)))
- call ppm_SetFont(DateFont)
-
- Dlead = PPtoPoints(ppm_ConvertUnits(2,3, rheight - DSizeCM)) + 1
- call ppm_SetLineSpacing(0, DLead)
-
- call ppm_SetTextColor(DColor)
-
- /* Set the left margin (which will come close to centering most fonts) */
- if SmallFont then do
- TMarg = max(.0705, DSizeCM / 15)
- LMarg = TMarg
- end
- else do
- TMarg = DSizeCM / 2.8
- LMarg = max(min(.3, CWidth / 6), CWidth - DSizeCM * 1.4)
- call ppm_setboxsize(OrgBox, bWid + TMarg, bHi + TMarg)
- end
- call ppm_SetBoxMargins(OrgBox, LMarg, TMarg, 0, 0)
- call ppm_SetBoxName(OrgBox, "Calendar dates")
-
- DateTabs = cwidth
- do i = 2 to 16
- DateTabs = DateTabs cWidth * i
- end
- call ppm_SetBoxTabs(OrgBox, DateTabs)
-
- /* Calculate the date and build a string. Prepare original box for date
- string and insert it.
- */
-
- call ppm_ShowStatus("MakeCalendar.....")
- oFlow = CalendarText(IntMonth Year)
-
- call ppm_ShowStatus("Adding dates to calendar.")
-
- if DBold then
- setB = '\B'
- else
- setB = '\b'
- call ppm_TextIntoBox(OrgBox, setB'\jl'DayStr)
-
- /* Create a grid the size of the chosen box */
-
- call ppm_ShowStatus("Creating calendar grid.")
-
- columns = 6
- rows = 4 /* Count from 0 */
- oldlc = ppm_GetLineColor()
- call ppm_SetLineColor(GColor)
- /* error */
- call ppm_SetLineWeight(LineWeight)
- call ppm_SetFillPattern(0)
-
- call ppm_NewGroup()
- firstbox = ppm_DrawRect(bLeft, bTop, bRight, bBot)
- call ppm_AddToGroup(firstbox)
- call ppm_SetBoxFrame(firstbox, 0)
-
- /* Now put the grid lines into the rectangle */
- do i = 1 to columns
- xLine = bLeft + (cWidth * i)
- box = ppm_DrawLine(xLine, bTop, xLine, bBot)
- call ppm_AddToGroup(box)
- end
- do i = 1 to rows
- yLine = bTop + (rHeight * i)
- box = ppm_DrawLine(bLeft, yLine, bRight, yLine)
- call ppm_AddToGroup(box)
- end
-
- oTop = bTop + rHeight * 4
- do i = 1 for oFlow /* Add diagonal & text for overflow days */
- call ppm_SetLineColor(GColor) /* Loses color on second line */
- oleft = bLeft + (i - 1) * cWidth
- box = ppm_DrawLine(oLeft, oTop + rHeight, oleft + cWidth, oTop)
- call ppm_AddToGroup(box)
- OFlowBox.i = ppm_CreateBox(oLeft, oTop, cWidth, rHeight, 0, 'OFlow' i)
- OFSize = ppm_SetSize(DSize/1.8)
- call ppm_SetFont(DateFont)
- /* Calculate and set leading */
- call ppm_BoxNum(OFlowBox.i)
- Olead = PPtoPoints(ppm_ConvertUnits(2,3, rheight)) - (OFSize * 2 + PPtoPoints(ppm_ConvertUnits(2,3,TMarg))) - 2
- call ppm_SetLineSpacing(0, OLead)
- call ppm_SetBoxMargins(OFlowBox.i, LMarg/2, TMarg, LMarg/2, 0)
- if DBold then
- setB = '\B'
- else
- setB = '\b'
- call ppm_TextIntoBox(OFlowBox.i, setB'\jl' || months.IntMonth.days - oFlow + i - 7 '0a'x'\jr' || months.IntMonth.days - oFlow + i)
- end
-
- call ppm_SetLineColor(oldlc)
- GridBox = ppm_MergeGroup()
- call ppm_BoxToBack(GridBox)
- /* call ppm_SetBoxLock(GridBox, 1)*/
- call ppm_SetBoxName(GridBox, "Calendar grid")
-
- /* Add boxes for memos to each date */
- if MemoFld then do
- call ppm_ShowStatus("Adding memo boxes.")
-
- OrgMemo = ppm_CreateBox(bLeft, bTop, cWidth, rHeight, 0,)
- call ppm_SetBoxFrame(OrgMemo, 0)
- call ppm_SetSize(max(9, DSize/2))
- call ppm_SetFont(MemoFont)
- call ppm_SetLineSpacing(2, 110)
- call ppm_SetBoxMargins(OrgMemo, .0705, DSizeCM, .0705, 0)
- call ppm_SetTextColor('Black')
-
- xoffset = 0
- yoffset = 0
- MonthShort = left(months.IntMonth, 3)
-
- do i = 0 to rows
- do col = 0 to columns
- MemNum = (i * 7) + col + 1
- MemoBox.MemNum = ppm_CloneBox(OrgMemo, xoffset, yoffset)
- date = max(0, memNum - firstdaynum)
- call ppm_SetBoxName(MemoBox.MemNum, daynames.col MonthShort date)
- xoffset = xoffset + cWidth
- end
- yoffset = yoffset + rheight
- xoffset = 0
- end
- call ppm_DeleteBox(OrgMemo) /* we've put another one on top w/ name */
- end
-
- call setclip('ppg_CalPrefs', PrefStore)
- exit_msg()
-
-
- /*******************************************************************
- Functions
- ==================================================================*/
-
- Calendar functions.
- Most of the calendar functions below are borrowed from the program
- calendar.rexx by
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-
- /**
- *
- * This subroutine, borrowed from code written by Mike Meyer and
- * distributed on an early ARexx disk, creates textstring used in
- * the calendar
- *
- **/
-
- CalendarText: procedure expose firstdaynum DayStr Daynames. Months. year
- arg mymonth myyear
- /*
- * Call the subroutine jan1() to get the day of the week
- * that the year started on.
- */
- call ppm_ShowStatus("Calculating dates.")
- call setdefs
- firstday = jan1(myyear)
- /*
- * Now fix up the months. array to reflect the correct
- * number of days in February for this year.
- * This is done by getting the day of the week on
- * which jan1 occurs for the next year and doing
- * some simple arithmetic to calculate a fudge factor.
- * NOTE the use of REXX's modular arithmetic operator //
- * and that something funny happens in 1752 when the calendar
- * changes:
- *
- * fudge = 1 --> regular year
- * fudge = 2 --> leap year
- * otherwise --> 1752
- */
- fudge = (jan1(myyear + 1) + 7 - firstday) // 7
-
- select
- when fudge = 1 then months.2.days = 28
- when fudge = 2 then months.2.days = 29
- otherwise
- months.2.days = 29
- months.9.days = 19
- end
-
- do i = 1 to mymonth - 1
- firstday = firstday + months.i.days
- end
- /*
- * Next compute the day of the week and its name
- */
- firstdaynum = firstday // 7
- /* Get number of days in this month */
- days = months.mymonth.days
-
- /* Will the days take more than 5 rows? */
- overflow = max(0, (firstdaynum + days) - 35)
-
- /* Build a tab-delimited string of the dates in the month */
- dayStr = ''
- do for firstdaynum
- dayStr = dayStr || '09'x /* Blanks at start of calendar */
- end
- do i = 1 to 9
- dayStr = dayStr || '\T' i || '09'x /* Add space to justify */
- end
- do i = 10 to 28 - firstdaynum /* first 4 rows */
- dayStr = dayStr || i || '09'x
- end
- do for overflow
- dayStr = dayStr || '09'x
- end
- i = i + overflow
- lday = days - overflow
- do li = i to lday
- dayStr = dayStr || li || '09'x
- end
-
- return overflow
-
- /**
- * returns the day of the week that january first falls on for
- * any specific year, 1 through 9999 (assuming they don't change
- * the rules again).
- **/
- jan1: procedure
- arg year
-
- /*
- * Julian calendar; one extra day every four years
- * Gregorian calendar - lose three days over four centuries
- * And there was an instant changeover in 1752
- * Note the use of REXX's % and // operators to do modular
- * arithmetic.
- */
- day = 4 + year + (year + 3) % 4
- if year > 1800 then
- do
- day = day - (year - 1701) % 100
- day = day + (year - 1601) % 400
- end
- if year > 1752 then
- day = day + 3
- return day // 7
-
- /*
- * Set up a stem variable to contain info about
- * months used to format the calendar.
- * Also set up a stem variable which contains strings
- * used as day names
- */
- SetDefs:
- months.1 = 'January'
- months.1.days = 31
- months.2 = 'February'
- months.2.days = 1 /* Fixed later */
- months.3 = 'March'
- months.3.days = 31
- months.4 = 'April'
- months.4.days = 30
- months.5 = 'May'
- months.5.days = 31
- months.6 = 'June'
- months.6.days = 30
- months.7 = 'July'
- months.7.days = 31
- months.8 = 'August'
- months.8.days = 31
- months.9 = 'September'
- months.9.days = 30
- months.10 = 'October'
- months.10.days = 31
- months.11 = 'November'
- months.11.days = 30
- months.12 = 'December'
- months.12.days = 31
-
- daynames.0 = 'Sun'
- daynames.1 = 'Mon'
- daynames.2 = 'Tue'
- daynames.3 = 'Wed'
- daynames.4 = 'Thu'
- daynames.5 = 'Fri'
- daynames.6 = 'Sat'
- return
-
- /* Find the integer value for the specified month */
- TranMonth: procedure expose monthWords units
- arg monthV, pnum
- monthWords = 'JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER OCTOBER NOVEMBER DECEMBER'
- if ~datatype(MonthV, 'N') & length(MonthV) ~== 0 then do
- Month = find(monthWords, MonthV)
- if Month == 0 then do
- Month = index(monthWords, MonthV)
- /* Now get the whole name of month from the abbreviation */
- if Month > 0 then do
- parse value substr(monthWords, Month, 12) with MonthV .
- Month = find(monthWords, MonthV)
- end
- end
- end
- else
- Month = MonthV
- if Month > 0 & Month < 13 then
- return Month
- else
- exit_Msg('Improper format: Month')
-
- VerifyNumber: procedure expose PrefType. units
- arg number, pnum
-
- if ~datatype(number, n) then exit_msg("Invalid input:" PrefType.pnum)
- return(number)
-
-
- YNtoNumber: procedure expose PrefType. units
- arg value, pnum
-
- select
- when value = '' then return(0)
- when abbrev(value,'Y') then return(1)
- when abbrev(value,'N') then return(0)
- otherwise call exit_msg("Invalid entry:" PrefType.pnum)
- end
-
- CheckColor: procedure expose PrefType. units ColorList ColorStr PrefStore
-
- parse arg value, pnum
- /* need 'parse above and 'upper' below to keep value correct case for
- the parse command when storing a new value */
- if value == '' | pos(upper(value), ColorStr) == 0 then do
- OldVal = '0a'x || Value || '0a'x
- Value = ppm_selectFromList('Pick' Preftype.pnum, 25, 15, 0, ColorList)
- if Value = '' then
- exit_msg('Aborted.')
- else do
- /* Store the new value */
- interpret 'parse var PrefStore PreStore' pos(OldVal, PrefStore) '. +'length(OldVal) 'PostStore'
- PrefStore = PreStore || '0a'x || Value || '0a'x || PostStore
- end
- end
- return Value
-
- SetPrefs: procedure expose PrefType.
-
- cr = '0a'x
- PrefForm = ''
- PrefType = ''
- PrefType.NumPrefs = 10
- PrefType.1 = 'Month'
- PrefType.1.com = 'TranMonth IntMonth'
- PrefType.2 = 'Year'
- PrefType.2.com = 'verifynumber Year'
- PrefType.3 = 'Title color'
- PrefType.3.com = 'CheckColor TColor'
- PrefType.4= 'Date color'
- PrefType.4.com= 'CheckColor DColor'
- PrefType.5 = 'Grid Color'
- PrefType.5.com = 'CheckColor GColor'
- PrefType.6 = 'Line weight'
- PrefType.6.com = 'verifynumber LineWeight'
- PrefType.7 = 'Bold dates (y/n)?'
- PrefType.7.com = 'yntonumber DBold'
- PrefType.8 = 'Bold title (y/n)?'
- PrefType.8.com = 'yntonumber TBold'
- PrefType.9 = 'Memo boxes (y/n)?'
- PrefType.9.com = 'yntonumber MemoFld'
- PrefType.10 = 'Small font (y/n)?'
- PrefType.10.com = 'yntonumber SmallFont'
-
- PrefVal = getclip('ppg_CalPrefs')
- if PrefVal == '' then
- PrefVal = cr||cr||'Black'cr'Black'cr'Black'cr'1.0'cr'n'cr'n'cr'n'cr'n'
- do i = 1 to PrefType.NumPrefs
- parse var PrefVal Val '0a'x PrefVal
- PrefForm = PrefForm || PrefType.i' :'Val || cr
- end
-
-
- return strip(PrefForm,T, cr) /* take off trailing cr */
-
- PPtoPoints: procedure /* convert points and picas to points */
- arg PPs
- parse var PPs Picas '.' Points
- Points = Points + Picas * 12
- return points
-
- break_d:
- break_e:
- break_c:
- halt:
- call exit_msg("User aborted Genie!")
-
- exit_msg:
- parse arg message
-
- call ppm_ClearStatus()
-
- if message ~= '' then
- call ppm_Inform(1, message,)
-
- call ppm_SetUnits(units)
- call ppm_ClearStatus()
- call ppm_AutoUpdate(1)
- exit
-