home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------------------------------------------ */
- /* Macro: CALEN4.AML */
- /* Written by: nuText Systems */
- /* */
- /* Description: This macro displays a calendar window with four */
- /* months, starting with the previous month. */
- /* */
- /* Usage: You can move to other months and years with the */
- /* following keys: */
- /* */
- /* <pgdn> - next month */
- /* <pgup> - prev month */
- /* <right> - same month, next year */
- /* <left> - same month, prev year */
- /* <ctrl pgdn> - december of the current year */
- /* <ctrl pgup> - january of the current year */
- /* <esc> - exit the calendar */
- /* ------------------------------------------------------------------ */
-
- include bootpath "define.aml"
-
- // define the colors to use
- define
- set cal_border_color color white on gray
- set cal_bordera_color color brightgreen on gray
- set cal_title_color color brightblue on gray
- set cal_client_color color black on gray
- set cal_today_color color brightgreen on gray
- set cal_control_color color yellow
- end
-
-
- var year
- var month
-
- // create the calendar window
- createwindow
- setframe ">b"
- setwinctrl '≡'
- setshadow 2 1
- sizewindow 3 4 75 20 "ad"
- setborder "1i"
- settitle "Four Month Calendar" 'c'
- setcolor border_color cal_border_color
- setcolor border_flash_color cal_bordera_color
- setcolor text_color cal_client_color
- setcolor control_color cal_control_color
-
- // current year and month
- year = getrawtime [1:4]
- month = getrawtime [5:2]
-
- // keep this object resident
- stayresident
- inheritfrom "win"
-
-
- // function to redraw the calendar at x,y on the screen
- function draw (x y)
- var monthdays
-
- // save the x coordinate
- xleft = x
-
- // set the calendar title based on the year and month
- title = (case month
- when 1 "January" when 7 "July"
- when 2 "February" when 8 "August"
- when 3 "March" when 9 "September"
- when 4 "April" when 10 "October"
- when 5 "May" when 11 "November"
- when 6 "June" when 12 "December"
- end) + " " + year
-
- writestr (pad (copystr ' ' (35 - (sizeof title)) / 2) + title 35 'l')
- cal_border_color x y
-
- y = y + 1
-
- // get the day in which the year starts using a perpetual
- // calendar (0-6, 0=sunday)
- startday = "5012356013456123460124560234" [year mod 28 + 1]
-
- // string indicating the days over 28 for each month
- over28 = concat (if? (not (year mod 4)) "31" "30") "3232332323"
-
- // get total days in the month
- maxdays = 28 + over28 [month]
-
- // get the number of days in previous months
- i = 1
- while i < month do
- monthdays = monthdays + 28 + over28 [i]
- i = i + 1
- end
-
- // calculate the starting day for the month (0-6, 0=sunday)
- startday = (startday + monthdays) mod 7
-
- // set 'today' to today's day number if it's the right
- // year and month
- rawtime = getrawtime
- today = if rawtime [5:2] == month and rawtime [1:4] == year then
- rawtime [7:2]
- end
-
- // draw the header
- writestr " Sun Mon Tue Wed Thu Fri Sat " (color cal_title_color) x y
- y = y + 1
-
- // move the video cursor to the start-day position
- daystr = copystr ' ' startday * 5
- xrem = 0
- yfirst = y
-
- // write the calendar body
- day = 1
- while day <= maxdays do
-
- if (sizeof daystr) + xrem >= 35 then
- writestr daystr cal_client_color x y
- x = xleft
- y = y + 1
- daystr = ''
- xrem = 0
- end
-
- // highlight today
- if day == today then
- if daystr then
- writestr daystr cal_client_color x y
- end
- todaystr = concat ' ' (pad day 3) ' '
- writestr todaystr cal_today_color xleft + (sizeof daystr) y
- xrem = (sizeof daystr) + (sizeof todaystr)
- x = x + xrem
- daystr = ''
- else
- daystr = concat daystr ' '(pad day 3) ' '
- end
-
- day = day + 1
- end
-
- // write last incomplete calendar line, if any
- if daystr then
- writestr (pad daystr 35 'l') cal_client_color x y
- y = y + 1
- end
-
- // write last blank line, if any
- if y - yfirst < 6 then
- writestr (copystr ' ' 35) cal_client_color x y
- end
-
- // set month and year for next time around
- month = month + 1
- if month > 12 then
- month = 1
- year = year + 1
- end
-
- end
-
- // draw four calander windows
- function draw4
- fillrect (getviewcols) (getviewrows) ' ' 1 1
-
- month2 = month
- year2 = year
-
- draw 1 1
- draw 38 1
- draw 1 10
- draw 38 10
-
- month = month2
- year = year2
- end
-
- // get the current year and month
- year = getrawtime [1:4]
- month = getrawtime [5:2]
-
- // get the previous month
- month = month - 1
- if not month then
- month = 12
- year = year - 1
- end
-
-
- draw4
-
- function close
- // call 'close' in object 'win'
- pass
- destroyobject
- end
-
- function "≡"
- close
- end
-
- key <esc>
- close
- end
-
- // forward one month
- key <pgdn>
- month = month + 1
- if month > 12 then
- month = 1
- year = year + 1
- end
- draw4
- end
-
- // backward one month
- key <pgup>
- month = month - 1
- if not month then
- month = 12
- year = year - 1
- end
- draw4
- end
-
- // goto january
- key <ctrl pgup>
- month = 1
- draw4
- end
-
- // goto december
- key <ctrl pgdn>
- month = 12
- draw4
- end
-
- // forward one year
- key <right>
- year = year + 1
- draw4
- end
-
- // backward one year
- key <left>
- if year then
- year = year - 1
- end
- draw4
- end
-
-