home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / dos / tools / aurora21 / calen4.aml < prev    next >
Text File  |  1995-08-10  |  7KB  |  255 lines

  1. /* ------------------------------------------------------------------ */
  2. /* Macro:        CALEN4.AML                                           */
  3. /* Written by:   nuText Systems                                       */
  4. /*                                                                    */
  5. /* Description:  This macro displays a calendar window with four      */
  6. /*               months, starting with the previous month.            */
  7. /*                                                                    */
  8. /* Usage:        You can move to other months and years with the      */
  9. /*               following keys:                                      */
  10. /*                                                                    */
  11. /*                 <pgdn>       - next month                          */
  12. /*                 <pgup>       - prev month                          */
  13. /*                 <right>      - same month, next year               */
  14. /*                 <left>       - same month, prev year               */
  15. /*                 <ctrl pgdn>  - december of the current year        */
  16. /*                 <ctrl pgup>  - january of the current year         */
  17. /*                 <esc>        - exit the calendar                   */
  18. /* ------------------------------------------------------------------ */
  19.  
  20.   include bootpath "define.aml"
  21.  
  22.   // define the colors to use
  23.   define
  24.     set cal_border_color   color white       on gray
  25.     set cal_bordera_color  color brightgreen on gray
  26.     set cal_title_color    color brightblue  on gray
  27.     set cal_client_color   color black       on gray
  28.     set cal_today_color    color brightgreen on gray
  29.     set cal_control_color  color yellow
  30.   end
  31.  
  32.  
  33.   var year
  34.   var month
  35.  
  36.   // create the calendar window
  37.   createwindow
  38.   setframe ">b"
  39.   setwinctrl '≡'
  40.   setshadow 2 1
  41.   sizewindow 3 4 75 20 "ad"
  42.   setborder "1i"
  43.   settitle "Four Month Calendar" 'c'
  44.   setcolor  border_color         cal_border_color
  45.   setcolor  border_flash_color   cal_bordera_color
  46.   setcolor  text_color           cal_client_color
  47.   setcolor  control_color        cal_control_color
  48.  
  49.   // current year and month
  50.   year  = getrawtime [1:4]
  51.   month = getrawtime [5:2]
  52.  
  53.   // keep this object resident
  54.   stayresident
  55.   inheritfrom "win"
  56.  
  57.  
  58.   // function to redraw the calendar at x,y on the screen
  59.   function  draw (x y)
  60.     var monthdays
  61.  
  62.     // save the x coordinate
  63.     xleft = x
  64.  
  65.     // set the calendar title based on the year and month
  66.     title = (case month
  67.                when 1 "January"    when 7  "July"
  68.                when 2 "February"   when 8  "August"
  69.                when 3 "March"      when 9  "September"
  70.                when 4 "April"      when 10 "October"
  71.                when 5 "May"        when 11 "November"
  72.                when 6 "June"       when 12 "December"
  73.              end) + " " + year
  74.  
  75.     writestr (pad (copystr ' ' (35 - (sizeof title)) / 2) + title 35 'l')
  76.             cal_border_color x y
  77.  
  78.     y = y + 1
  79.  
  80.     // get the day in which the year starts using a perpetual
  81.     // calendar (0-6, 0=sunday)
  82.     startday = "5012356013456123460124560234" [year mod 28 + 1]
  83.  
  84.     // string indicating the days over 28 for each month
  85.     over28 = concat (if? (not (year mod 4)) "31" "30") "3232332323"
  86.  
  87.     // get total days in the month
  88.     maxdays = 28 + over28 [month]
  89.  
  90.     // get the number of days in previous months
  91.     i = 1
  92.     while i < month do
  93.       monthdays = monthdays + 28 + over28 [i]
  94.       i = i + 1
  95.     end
  96.  
  97.     // calculate the starting day for the month (0-6, 0=sunday)
  98.     startday = (startday + monthdays) mod 7
  99.  
  100.     // set 'today' to today's day number if it's the right
  101.     // year and month
  102.     rawtime = getrawtime
  103.     today = if rawtime [5:2] == month and rawtime [1:4] == year then
  104.               rawtime [7:2]
  105.             end
  106.  
  107.     // draw the header
  108.     writestr " Sun  Mon  Tue  Wed  Thu  Fri  Sat "  (color cal_title_color) x y
  109.     y = y + 1
  110.  
  111.     // move the video cursor to the start-day position
  112.     daystr = copystr ' ' startday * 5
  113.     xrem = 0
  114.     yfirst = y
  115.  
  116.     // write the calendar body
  117.     day = 1
  118.     while day <= maxdays do
  119.  
  120.       if (sizeof daystr) + xrem >= 35 then
  121.         writestr daystr cal_client_color x y
  122.         x = xleft
  123.         y = y + 1
  124.         daystr = ''
  125.         xrem = 0
  126.       end
  127.  
  128.       // highlight today
  129.       if day == today then
  130.         if daystr then
  131.           writestr daystr cal_client_color x y
  132.         end
  133.         todaystr = concat ' ' (pad day 3) ' '
  134.         writestr todaystr cal_today_color xleft + (sizeof daystr) y
  135.         xrem = (sizeof daystr) + (sizeof todaystr)
  136.         x = x + xrem
  137.         daystr = ''
  138.       else
  139.         daystr = concat daystr ' '(pad day 3) ' '
  140.       end
  141.  
  142.       day = day + 1
  143.     end
  144.  
  145.     // write last incomplete calendar line, if any
  146.     if daystr then
  147.       writestr (pad daystr 35 'l') cal_client_color x y
  148.       y = y + 1
  149.     end
  150.  
  151.     // write last blank line, if any
  152.     if y - yfirst < 6 then
  153.       writestr (copystr ' ' 35) cal_client_color x y
  154.     end
  155.  
  156.     // set month and year for next time around
  157.     month = month + 1
  158.     if month > 12 then
  159.       month = 1
  160.       year = year + 1
  161.     end
  162.  
  163.   end
  164.  
  165.   // draw four calander windows
  166.   function  draw4
  167.     fillrect (getviewcols) (getviewrows) ' ' 1 1
  168.  
  169.     month2 = month
  170.     year2 = year
  171.  
  172.     draw  1  1
  173.     draw 38  1
  174.     draw  1 10
  175.     draw 38 10
  176.  
  177.     month = month2
  178.     year = year2
  179.   end
  180.  
  181.   // get the current year and month
  182.   year  = getrawtime [1:4]
  183.   month = getrawtime [5:2]
  184.  
  185.   // get the previous month
  186.   month = month - 1
  187.   if not month then
  188.     month = 12
  189.     year = year - 1
  190.   end
  191.  
  192.  
  193.   draw4
  194.  
  195.   function close
  196.     // call 'close' in object 'win'
  197.     pass
  198.     destroyobject
  199.   end
  200.  
  201.   function "≡"
  202.     close
  203.   end
  204.  
  205.   key <esc>
  206.     close
  207.   end
  208.  
  209.   // forward one month
  210.   key <pgdn>
  211.     month = month + 1
  212.     if month > 12 then
  213.       month = 1
  214.       year = year + 1
  215.     end
  216.     draw4
  217.   end
  218.  
  219.   // backward one month
  220.   key <pgup>
  221.     month = month - 1
  222.     if not month then
  223.       month = 12
  224.       year = year - 1
  225.     end
  226.     draw4
  227.   end
  228.  
  229.   // goto january
  230.   key <ctrl pgup>
  231.     month = 1
  232.     draw4
  233.   end
  234.  
  235.   // goto december
  236.   key <ctrl pgdn>
  237.     month = 12
  238.     draw4
  239.   end
  240.  
  241.   // forward one year
  242.   key <right>
  243.     year = year + 1
  244.     draw4
  245.   end
  246.  
  247.   // backward one year
  248.   key <left>
  249.     if year then
  250.       year = year - 1
  251.     end
  252.     draw4
  253.   end
  254.  
  255.