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

  1. /* ------------------------------------------------------------------ */
  2. /* Macro:        CALENDAR.AML                                         */
  3. /* Written by:   nuText Systems                                       */
  4. /*                                                                    */
  5. /* Description:  This macro displays a popup calendar window for the  */
  6. /*               current year and 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_client_color   color black       on gray
  25.     set cal_border_color   color white       on gray
  26.     set cal_bordera_color  color brightgreen on gray
  27.     set cal_title_color    color brightblue  on gray
  28.     set cal_today_color    color brightgreen on gray
  29.     set cal_control_color  color yellow
  30.   end
  31.  
  32.   // current year and month
  33.   var year
  34.   var month
  35.  
  36.   // keep this object resident
  37.   stayresident
  38.   inheritfrom "win"
  39.  
  40.   // function to redraw the calendar for any year and month
  41.   function  draw
  42.     var monthdays
  43.  
  44.     // set the calendar title based on the year and month
  45.     settitle (case month
  46.                 when 1 "January"    when 7  "July"
  47.                 when 2 "February"   when 8  "August"
  48.                 when 3 "March"      when 9  "September"
  49.                 when 4 "April"      when 10 "October"
  50.                 when 5 "May"        when 11 "November"
  51.                 when 6 "June"       when 12 "December"
  52.               end) + " " + year  'c'
  53.  
  54.     // get the day in which the year starts using a perpetual
  55.     // calendar (0-6, 0=sunday)
  56.     startday = "5012356013456123460124560234" [year mod 28 + 1]
  57.  
  58.     // string indicating the days over 28 for each month
  59.     over28 = concat (if? (not (year mod 4)) "31" "30") "3232332323"
  60.  
  61.     // get total days in the month
  62.     maxdays = 28 + over28 [month]
  63.  
  64.     // get the number of days in previous months
  65.     i = 1
  66.     while i < month do
  67.       monthdays = monthdays + 28 + over28 [i]
  68.       i = i + 1
  69.     end
  70.  
  71.     // calculate the starting day for the month (0-6, 0=sunday)
  72.     startday = (startday + monthdays) mod 7
  73.  
  74.     // set 'today' to today's day number if it's the right
  75.     // year and month
  76.     rawtime = getrawtime
  77.     today = if rawtime [5:2] == month and rawtime [1:4] == year then
  78.               rawtime [7:2]
  79.             end
  80.  
  81.     // clear the window and draw the header
  82.     gotoxy 1 1
  83.     fillrect (getviewcols) (getviewrows)
  84.     writeline " Sun  Mon  Tue  Wed  Thu  Fri  Sat  "  (color cal_title_color)
  85.  
  86.     // move the video cursor to the start-day position
  87.     gotoxy 2 + startday * 5
  88.  
  89.     // write the calendar days
  90.     day = 1
  91.     while day <= maxdays do
  92.       writestr (pad day 3) + "  "
  93.         (if? day == today  cal_today_color  cal_client_color)
  94.       if getx > 34 then
  95.         writeline
  96.         writestr ' '
  97.       end
  98.       day = day + 1
  99.     end
  100.  
  101.   end
  102.  
  103.   // create the calendar window
  104.   createwindow
  105.   setframe ">b"
  106.   setwinctrl '≡'
  107.   setshadow 2 1
  108.  
  109.   width = 35
  110.   height = 6
  111.  
  112.   // center the window
  113.   ox = (getvidcols - width) / 2
  114.   oy = (getvidrows - height) / 2
  115.   sizewindow ox oy ox + width oy + height "ad"
  116.  
  117.   setborder "1i"
  118.   setcolor  border_color         cal_border_color
  119.   setcolor  border_flash_color   cal_bordera_color
  120.   setcolor  text_color           cal_client_color
  121.   setcolor  control_color        cal_control_color
  122.  
  123.   // current year and month
  124.   year  = getrawtime [1:4]
  125.   month = getrawtime [5:2]
  126.  
  127.   // redraw the calendar window
  128.   draw
  129.  
  130.   function close
  131.     // call 'close' in object 'win'
  132.     pass
  133.     destroyobject
  134.   end
  135.  
  136.   function "≡"
  137.     close
  138.   end
  139.  
  140.   key <esc>
  141.     close
  142.   end
  143.  
  144.   // mouse click
  145.   key <lbutton>
  146.     case getregion
  147.       // close icon
  148.       when 51
  149.         close
  150.       otherwise
  151.         pass
  152.     end
  153.   end
  154.  
  155.   // forward one month
  156.   key <pgdn>
  157.     month = month + 1
  158.     if month > 12 then
  159.       month = 1
  160.       year = year + 1
  161.     end
  162.     draw
  163.   end
  164.  
  165.   // backward one month
  166.   key <pgup>
  167.     month = month - 1
  168.     if not month then
  169.       month = 12
  170.       year = year - 1
  171.     end
  172.     draw
  173.   end
  174.  
  175.   // goto january
  176.   key <ctrl pgup>
  177.     month = 1
  178.     draw
  179.   end
  180.  
  181.   // goto december
  182.   key <ctrl pgdn>
  183.     month = 12
  184.     draw
  185.   end
  186.  
  187.   // forward one year
  188.   key <right>
  189.     year = year + 1
  190.     draw
  191.   end
  192.  
  193.   // backward one year
  194.   key <left>
  195.     if year then
  196.       year = year - 1
  197.     end
  198.     draw
  199.   end
  200.  
  201.