home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / database / pk4pak.zip / CALENDAR.SC < prev    next >
Text File  |  1993-03-15  |  30KB  |  747 lines

  1. ;==============================================================================
  2. ; (c) Copyright Elect Software International Inc., 1992, Toronto. Anyone can
  3. ; use this code for anything as long as it is not resold as a software
  4. ; development resource, as long as the copyright notice isn't removed, as
  5. ; long as changes are clearly marked as to authorship, and as long as users
  6. ; indemnify Elect from any liability.
  7. ; Comments welcome. Henrik Bechmann, CIS:72701,3717; Tel:416-534-8176.
  8. ;==============================================================================
  9.  
  10. ;==============================================================================
  11. ;                             CALENDAR INTERFACE
  12. ;==============================================================================
  13. ; DESCRIPTION:
  14. ; The Calendar allows the user to select a day of the month, a month of the
  15. ; year, or a year from 100 to 9999 A.D. If the user selects a date from the
  16. ; calendar, then the Calendar.Dialog() returns true, otherwise it returns
  17. ; false. If Calendar.Dialog returns true, then pick up the date that the user
  18. ; selected from the property Calendar.Date. To override the default date
  19. ; (today()) set the property Calendar.Date *before* calling Calendar.Dialog().
  20. ;
  21. ; METHODS:
  22. ; Calendar.Constructor() ; called at start of session in which calendar will be
  23. ;                        ; used.
  24. ; Calendar.Destructor()  ; called after session in which calendar is used, to
  25. ;                        ; clean up.
  26. ; Calendar.Dialog()      ; Displays the calendar to the user.
  27. ;                        ; Returns true if a date was selected, otherwise
  28. ;                        ; returns false. If it returns true, then get the
  29. ;                        ; date selected from the property Calendar.Date.
  30. ;
  31. ; PROPERTIES: (alter these after constructor call and before dialog call)...
  32. ; Calendar.Date          ; the date. Overrides default if set before
  33. ;                        ; Calendar.Dialog(), and contains the selected date
  34. ;                        ; if Calendar.Dialog() returns true.
  35. ; Calendar.DisplayTime   ; If true, displays time (with annoying cursor
  36. ;                        ; flicker if the cursor is on the PickArray),
  37. ;                        ; otherwise doesn't display time
  38. ; Calendar.ColorBag[]    ; assign colors by Window SetColors convention
  39. ; Calendar.FrameShadow   ; The color for the dark sides of the raised frames
  40. ; Calendar.FrameHighlight; The color for the light sides of the raised frames
  41. ; Calendar.WindowBag[]; assign attributes by Window SetAttributes
  42. ;                        ; convention
  43. ; Analagous properties for the sub-dialogs...
  44. ; Calendar.YearColorBag[]
  45. ; Calendar.YearFrameShadow
  46. ; Calendar.YearFrameHighlight
  47. ; Calendar.YearWindowBag[]
  48. ; Calendar.MonthColorBag[]
  49. ; Calendar.MonthFrameShadow
  50. ; Calendar.MonthFrameHighlight
  51. ; Calendar.MonthWindowBag[]
  52. ;
  53. ; Calendar.IsActive ; (readonly) indicates if Calendar.Constructor has
  54. ;                   ; been run
  55. ;==============================================================================
  56. ;                          CALENDAR IMPLEMENTATION
  57. ;==============================================================================
  58. Proc Calendar.Constructor()
  59.    Private
  60.       i,j,k
  61.  
  62.    Message "Initializing calendar"
  63.  
  64.    Dynarray Calendar_DOWNum[]
  65.    Calendar_DOWNum["Sun"] = 1
  66.    Calendar_DOWNum["Mon"] = 2
  67.    Calendar_DOWNum["Tue"] = 3
  68.    Calendar_DOWNum["Wed"] = 4
  69.    Calendar_DOWNum["Thu"] = 5
  70.    Calendar_DOWNum["Fri"] = 6
  71.    Calendar_DOWNum["Sat"] = 7
  72.  
  73.    Array Calendar_MonthName[12]
  74.    Calendar_MonthName[1]  = "Jan"
  75.    Calendar_MonthName[2]  = "Feb"
  76.    Calendar_MonthName[3]  = "Mar"
  77.    Calendar_MonthName[4]  = "Apr"
  78.    Calendar_MonthName[5]  = "May"
  79.    Calendar_MonthName[6]  = "Jun"
  80.    Calendar_MonthName[7]  = "Jul"
  81.    Calendar_MonthName[8]  = "Aug"
  82.    Calendar_MonthName[9]  = "Sep"
  83.    Calendar_MonthName[10] = "Oct"
  84.    Calendar_MonthName[11] = "Nov"
  85.    Calendar_MonthName[12] = "Dec"
  86.  
  87.    Array Calendar_MonthFullName[12]
  88.    Calendar_MonthFullName[1]  = "January"
  89.    Calendar_MonthFullName[2]  = "February"
  90.    Calendar_MonthFullName[3]  = "March"
  91.    Calendar_MonthFullName[4]  = "April"
  92.    Calendar_MonthFullName[5]  = "May"
  93.    Calendar_MonthFullName[6]  = "June"
  94.    Calendar_MonthFullName[7]  = "July"
  95.    Calendar_MonthFullName[8]  = "August"
  96.    Calendar_MonthFullName[9]  = "September"
  97.    Calendar_MonthFullName[10] = "October"
  98.    Calendar_MonthFullName[11] = "November"
  99.    Calendar_MonthFullName[12] = "December"
  100.  
  101.    ;---------------------------------------------------------------------------
  102.    ; A map is set up as follows: bracketed numbers ([]) represent
  103.    ; Calendar_Picklist cells, unbracketed numbers represent
  104.    ; Calendar_MapToPickList cells. Calendar_MapToPickList cells contain
  105.    ; pointers to the Calendar_PickList cells. The current calendar month is
  106.    ; mapped onto the Calendar_MapToPickList array with an offset, being the
  107.    ; number of cells of the month that are blank. The first cell
  108.    ; of the Calendar_MapToPickList array that points to a day value in picklist
  109.    ; is the first Calendar_DOWNum of the month.
  110.    ;
  111.    ;  1[ 1]   2[ 7]   3[13]   4[19]   5[25]   6[31]   7[37]
  112.    ;  8[ 2]   9[ 8]  10[14]  11[20]  12[26]  13[32]  14[38]
  113.    ; 15[ 3]  16[ 9]  17[15]  18[21]  19[27]  20[33]  21[39]
  114.    ; 22[ 4]  23[10]  24[16]  25[22]  26[28]  27[34]  28[40]
  115.    ; 29[ 5]  30[11]  31[17]  32[23]  33[29]  34[35]  35[41]
  116.    ; 36[ 6]  37[12]  38[18]  39[24]  40[30]  41[36]  42[42]
  117.    ;                   ┌──────────────────────────────────────────────────────┐
  118.    ; For June of 1992: │        Calendar_Offset: 1──────┐                     │
  119.    ; PickList[1]  =    │        MapToPickList[1]  = 1   │   MapToMap[1]  = 1  │
  120.    ; PickList[2]  = 7──┘   ┌────MapToPickList[2]  = 7 ─┘ ┌─MapToMap[2]  = 8─┘
  121.    ; PickList[3]  = 14     │┌───MapToPickList[3]  = 13    │ MapToMap[3]  = 15
  122.    ; PickList[4]  = 21     ││┌──MapToPickList[4]  = 19    │ MapToMap[4]  = 22
  123.    ; PickList[5]  = 28     │││┌─MapToPickList[5]  = 25    │ MapToMap[5]  = 29
  124.    ; PickList[6]  =        ││││ MapToPickList[6]  = 31    │ MapToMap[6]  = 36
  125.    ; PickList[7]  = 1  ───┘│││ MapToPickList[7]  = 37    │ MapToMap[7]  = 2
  126.    ; PickList[8]  = 8       │││ MapToPickList[8]  = 2────┘ MapToMap[8]  = 9
  127.    ; PickList[9]  = 15      │││ MapToPickList[9]  = 8       MapToMap[9]  = 16
  128.    ; PickList[10] = 22      │││ MapToPickList[10] = 14      MapToMap[10] = 23
  129.    ; PickList[11] = 29      │││ MapToPickList[11] = 20      MapToMap[11] = 30
  130.    ; PickList[12] =         │││ MapToPickList[12] = 26      MapToMap[12] = 37
  131.    ; PickList[13] = 2 ─────┘││ MapToPickList[13] = 32      MapToMap[13] = 3
  132.    ; PickList[14] = 9        ││ MapToPickList[14] = 38      MapToMap[14] = 10
  133.    ; PickList[15] = 16       ││ MapToPickList[15] = 3       MapToMap[15] = 17
  134.    ; PickList[16] = 23       ││ MapToPickList[16] = 9       MapToMap[16] = 24
  135.    ; PickList[17] = 30       ││ MapToPickList[17] = 15      MapToMap[17] = 31
  136.    ; PickList[18] =          ││ MapToPickList[18] = 21      MapToMap[18] = 38
  137.    ; PickList[19] = 3───────┘│ MapToPickList[19] = 27      MapToMap[19] = 4
  138.    ; PickList[20] = 10        │ MapToPickList[20] = 33      MapToMap[20] = 11
  139.    ; PickList[21] = 17        │ MapToPickList[21] = 39      MapToMap[21] = 18
  140.    ; PickList[22] = 24        │ MapToPickList[22] = 4       MapToMap[22] = 25
  141.    ; PickList[23] =           │ MapToPickList[23] = 10      MapToMap[23] = 32
  142.    ; PickList[24] =           │ MapToPickList[24] = 16      MapToMap[24] = 39
  143.    ; PickList[25] = 4────────┘ MapToPickList[25] = 22      MapToMap[25] = 5
  144.    ; PickList[26] = 11          MapToPickList[26] = 28      MapToMap[26] = 12
  145.    ; PickList[27] = 18          MapToPickList[27] = 34      MapToMap[27] = 19
  146.    ; PickList[28] = 25          MapToPickList[28] = 40      MapToMap[28] = 26
  147.    ; PickList[29] =             MapToPickList[29] = 5       MapToMap[29] = 33
  148.    ; PickList[30] =             MapToPickList[30] = 11      MapToMap[30] = 40
  149.    ; PickList[31] = 5           MapToPickList[31] = 17      MapToMap[31] = 6
  150.    ; PickList[32] = 12          MapToPickList[32] = 23      MapToMap[32] = 13
  151.    ; PickList[33] = 19          MapToPickList[33] = 29      MapToMap[33] = 20
  152.    ; PickList[34] = 26          MapToPickList[34] = 35      MapToMap[34] = 27
  153.    ; PickList[35] =             MapToPickList[35] = 41      MapToMap[35] = 34
  154.    ; PickList[36] =             MapToPickList[36] = 6       MapToMap[36] = 42
  155.    ; PickList[37] = 6           MapToPickList[37] = 12      MapToMap[37] = 7
  156.    ; PickList[38] = 13          MapToPickList[38] = 18      MapToMap[38] = 14
  157.    ; PickList[39] = 20          MapToPickList[39] = 24      MapToMap[39] = 21
  158.    ; PickList[40] = 27          MapToPickList[40] = 30      MapToMap[40] = 28
  159.    ; PickList[41] =             MapToPickList[41] = 36      MapToMap[41] = 35
  160.    ; PickList[42] =             MapToPickList[42] = 42      MapToMap[42] = 42
  161.    ;
  162.    ; Therefore:
  163.    ; - To get the picklist number for the current day of the month, choose the
  164.    ; pointer in Calendar_MapToPickList with an index of the day of the month
  165.    ; plus the month offset.
  166.    ; - To get the date value from the Calendar_Picklist index, simply choose
  167.    ; the value pointed to in Calendar_PickList by the index.
  168.    ;---------------------------------------------------------------------------
  169.    Array Calendar_MapToPickList[42]
  170.    k = 1
  171.    For i From 0 to 6
  172.       For j From  1 to 42 step 7
  173.          Calendar_MapToPickList[i + j] = k
  174.          k = k + 1
  175.       EndFor
  176.    EndFor
  177.    ;---------------------------------------------------------------------------
  178.    ; Generate an array that allows easy lookup of the implied index of
  179.    ; Calendar_MapToPickList given an index of Calendar_PickList. This
  180.    ; allows resynchronization from a pointer into Picklist that points to a
  181.    ; blank, to a pointer that points to a date within range. (See
  182.    ; Calendar!ResyncDatePick())
  183.    ;---------------------------------------------------------------------------
  184.    Array Calendar_MapToMap[42]
  185.    For i From 1 to 42
  186.       Calendar_MapToMap[Calendar_MapToPickList[i]] = i
  187.    EndFor
  188.    ;---------------------------------------------------------------------------
  189.    ; Set defaults for properties...
  190.    ;---------------------------------------------------------------------------
  191.    Calendar.FrameHighlight = 11 + 48
  192.    Calendar.FrameShadow = 1 + 48
  193.    Dynarray Calendar.ColorBag[]
  194.    Calendar.ColorBag[1]  = Calendar.FrameShadow ; active frame
  195.    Calendar.ColorBag[2]  = Calendar.FrameShadow ; dragging frame
  196.    Calendar.ColorBag[5]  = 0 + 48   ; text
  197.    Calendar.ColorBag[9]  = 7 + 64   ; push button label
  198.    Calendar.ColorBag[10] = 15 + 64  ; default push button label
  199.    Calendar.ColorBag[11] = 15 + 64  ; default push button label
  200.    Calendar.ColorBag[13] = 14 + 64  ; push button hot key
  201.    Calendar.ColorBag[14] = 0 + 48   ; pushbutton shadow
  202.    Calendar.ColorBag[26] = 15 + 64  ; active picklist selection
  203.    Calendar.ColorBag[27] = 15 + 64  ; inactive picklist selection
  204.    Dynarray Calendar.WindowBag[]
  205.    ;---------------------------------------------------------------------------
  206.    ; The Calendar is initialized off screen (@500,500) to hide the
  207.    ; initialization flicker from the user. OriginRow and Col are specified
  208.    ; here to tell the calendar where to move to after the initialization is
  209.    ; complete.
  210.    ;---------------------------------------------------------------------------
  211.    Calendar.WindowBag["OriginRow"] = 3
  212.    Calendar.WindowBag["OriginCol"] = 5
  213.    Calendar_WindowHandle = BlankNum()
  214.  
  215.    Calendar.YearFrameHighlight = 15 + 112
  216.    Calendar.YearFrameShadow  = 8 + 112
  217.    Dynarray Calendar.YearColorBag[]
  218.    Calendar.YearColorBag[1]  = Calendar.YearFrameShadow ; active frame
  219.    Calendar.YearColorBag[2]  = Calendar.YearFrameShadow ; dragging frame
  220.    Calendar.YearColorBag[6]  = 0 + 112  ; inactive label
  221.    Calendar.YearColorBag[7]  = 0 + 112  ; active label
  222.    Calendar.YearColorBag[9]  = 7 + 64   ; push button label
  223.    Calendar.YearColorBag[10] = 15 + 64  ; default push button label
  224.    Calendar.YearColorBag[11] = 15 + 64  ; default push button label
  225.    Calendar.YearColorBag[13] = 14 + 64  ; push button hot key
  226.    Calendar.YearColorBag[18] = 0 + 112  ; normal typein box
  227.    Calendar.YearColorBag[19] = 0 + 32   ; selected typein box
  228.    Calendar.YearColorBag[26] = 15 + 64  ; active picklist selection
  229.    Dynarray Calendar.YearWindowBag[]
  230.    Calendar.YearWindowBag["OriginRow"] = 8
  231.    Calendar.YearWindowBag["OriginCol"] = 30
  232.    Calendar_YearWindowHandle = BlankNum()
  233.  
  234.    Calendar.MonthFrameHighlight = 15 + 112
  235.    Calendar.MonthFrameShadow = 8 + 112
  236.    Dynarray Calendar.MonthColorBag[]
  237.    Calendar.MonthColorBag[1]  = Calendar.MonthFrameShadow ; active frame
  238.    Calendar.MonthColorBag[2]  = Calendar.MonthFrameShadow ; dragging frame
  239.    Calendar.MonthColorBag[9]  = 7 + 64   ; push button label
  240.    Calendar.MonthColorBag[10] = 15 + 64  ; default push button label
  241.    Calendar.MonthColorBag[11] = 15 + 64  ; default push button label
  242.    Calendar.MonthColorBag[13] = 14 + 64  ; push button hot key
  243.    Calendar.MonthColorBag[25] = 0 + 112  ; Normal pick list item text
  244.    Calendar.MonthColorBag[26] = 15 + 64  ; active picklist selection
  245.    Calendar.MonthColorBag[27] = 15 + 112 ; inactive picklist selection
  246.    Calendar.MonthColorBag[28] = 8 + 112  ; Column dividers
  247.    Dynarray Calendar.MonthWindowBag[]
  248.    Calendar.MonthWindowBag["OriginRow"] = 8
  249.    Calendar.MonthWindowBag["OriginCol"] = 30
  250.    Calendar_MonthWindowHandle = BlankNum()
  251.  
  252.    Calendar.IsActive = True
  253.    Calendar.Date = today()
  254.    Calendar.DisplayTime = True
  255.    Message "" ; clear message
  256. EndProc ; Calendar.Constructor
  257.  
  258. Proc Calendar.Destructor()
  259.    Release Vars
  260.       Calendar_DOWNum,
  261.       Calendar_MonthName,
  262.       Calendar_MonthFullName,
  263.       Calendar_MapToPickList,
  264.       Calendar_MapToMap,
  265.       Calendar.FrameHighlight,
  266.       Calendar.FrameShadow,
  267.       Calendar.ColorBag,
  268.       Calendar.WindowBag,
  269.       Calendar_WindowHandle,
  270.       Calendar.YearFrameHighlight,
  271.       Calendar.YearFrameShadow,
  272.       Calendar.YearColorBag,
  273.       Calendar.YearWindowBag,
  274.       Calendar_YearWindowHandle,
  275.       Calendar.MonthFrameHighlight,
  276.       Calendar.MonthFrameShadow,
  277.       Calendar.MonthColorBag,
  278.       Calendar.MonthWindowBag,
  279.       Calendar_MonthWindowHandle,
  280.       Calendar.IsActive,
  281.       Calendar.Date,
  282.       Calendar.DisplayTime
  283. EndProc ; Calendar.Destructor
  284.  
  285. Proc Calendar.Dialog()
  286.    Private
  287.       Calendar_Day,
  288.       Calendar_Month,
  289.       Calendar_Year,
  290.       Calendar_PickList,
  291.       Calendar_Offset,
  292.       Calendar_HighDay,
  293.       Calendar_Prompt,
  294.       Calendar_TimeVar,
  295.       DatePick,
  296.       CalendarVar,
  297.       ControlVar,
  298.       i,
  299.       OK
  300.    Calendar_TimeVar = ""
  301.    If IsBlank(Calendar.Date) Then
  302.       Calendar.Date = today()
  303.    Endif
  304.    Calendar_Day = Day(Calendar.Date)
  305.    Calendar_Month = Month(Calendar.Date)
  306.    Calendar_Year = Year(Calendar.Date)
  307.    Calendar!GeneratePickList()
  308.    ShowDialog "ESI PD40B Calendar"
  309.       Proc "Calendar!CatchEvents"
  310.          Trigger "Open"
  311.       @500,500 Height 19 Width 38
  312.       ;------------------------------------------------------------------------
  313.       ; Draw raised frames...
  314.       ;------------------------------------------------------------------------
  315.       Frame Single ; titles and header
  316.          From 0,0 To 2,35
  317.       Frame Single ; the calendar
  318.          From 3,0 To 12,35
  319.       PaintCanvas
  320.          Attribute Calendar.FrameShadow
  321.          0,0,16,35
  322.       Style Attribute Calendar.ColorBag[5]
  323.       @1,2 ?? Format("W33,AL",Calendar_Prompt)
  324.       @1,26 ?? IIf(Calendar.DisplayTime,Time(),"")
  325.       Style Attribute Calendar.FrameShadow
  326.       @4,1 ?? "Sun │Mon │Tue │Wed │Thu │Fri │Sat "
  327.       @5,1 ?? "────┼────┼────┼────┼────┼────┼────"
  328.       Style
  329.       ;------------------------------------------------------------------------
  330.       ; Highlight the titles and header frame...
  331.       ;------------------------------------------------------------------------
  332.       PaintCanvas
  333.          Attribute Calendar.FrameHighlight
  334.          0,0,0,34
  335.       PaintCanvas
  336.          Attribute Calendar.FrameHighlight
  337.          0,0,2,0
  338.       ;------------------------------------------------------------------------
  339.       ; Highlight the calendar frame...
  340.       ;------------------------------------------------------------------------
  341.       PaintCanvas
  342.          Attribute Calendar.FrameHighlight
  343.          3,0,3,34
  344.       PaintCanvas
  345.          Attribute Calendar.FrameHighlight
  346.          3,0,12,0
  347.       ;------------------------------------------------------------------------
  348.       ; Draw the dialog box elements...
  349.       ;------------------------------------------------------------------------
  350.       PickArray
  351.          @6,1 Height 6 Width 34
  352.          Columns 7
  353.          Calendar_PickList
  354.          Tag "Pick"
  355.          To DatePick
  356.       PushButton
  357.          @13,1 Width 10
  358.          "~M~onth"
  359.          Value Calendar!ChangeMonth()
  360.          Tag "Month"
  361.          To CalendarVar
  362.       PushButton
  363.          @13,13 Width 10
  364.          "~Y~ear"
  365.          Value Calendar!ChangeYear()
  366.          Tag "Year"
  367.          To CalendarVar
  368.       PushButton
  369.          @13,25 Width 10
  370.          "~T~oday"
  371.          Value Calendar!MovetoToday()
  372.          Tag "Today"
  373.          To CalendarVar
  374.       PushButton
  375.          @15,8 Width 10
  376.          "~O~K"
  377.          OK
  378.          Default
  379.          Value "OK"
  380.          Tag "OK"
  381.          To ControlVar
  382.       PushButton
  383.          @15,20 Width 10
  384.          "~C~ancel"
  385.          Cancel
  386.          Value "Cancel"
  387.          Tag "Cancel"
  388.          To ControlVar
  389.    EndDialog
  390.    OK = Retval
  391.    If OK Then
  392.       Calendar.Date = Calendar!GetDate(Calendar_PickList[DatePick],
  393.                Calendar_Month,Calendar_Year)
  394.    Endif
  395.    Return OK
  396. EndProc ; Calendar.Dialog
  397.  
  398. ;----------------------------------------------------------------------------
  399. ; Calendar!GeneratePickList() expects three global variables to be set:
  400. ; Calendar_Day, Calendar_Month, and Calendar_Year. If Calendar_Day is greater
  401. ; than the last day of the current month, it will be set to the highest day of
  402. ; the month.
  403. ; In any case DatePick is set to the index value of Calendar_Picklist that
  404. ; points to Calendar_Day
  405. ;----------------------------------------------------------------------------
  406. Proc Calendar!GeneratePickList()
  407.    Array Calendar_PickList[42]
  408.    Calendar_HighDay = Calendar!GetHighDay(Calendar_Month,Calendar_Year)
  409.    If Calendar_Day > Calendar_HighDay Then
  410.       Calendar_Day = Calendar_HighDay
  411.    Endif
  412.    Calendar_Offset =
  413.       Calendar_DOWNum[
  414.          DOW(Calendar!GetDate(
  415.             1,Calendar_Month,Calendar_Year))] - 1
  416.    For i From 1 To Calendar_HighDay
  417.       Calendar_PickList[Calendar_MapToPickList[i + Calendar_Offset]] = i
  418.    EndFor
  419.    For i From 1 To Calendar_Offset
  420.       Calendar_PickList[Calendar_MapToPickList[i]] = BlankNum()
  421.    EndFor
  422.    For i From Calendar_HighDay + Calendar_Offset + 1 To 42
  423.       Calendar_PickList[Calendar_MapToPickList[i]] = BlankNum()
  424.    EndFor
  425.    DatePick = Calendar_MapToPickList[Calendar_Day + Calendar_Offset]
  426.    Calendar_Prompt = Calendar_MonthFullName[Calendar_Month] + ", " +
  427.       StrVal(Calendar_Year)
  428. EndProc ; Calendar!GeneratePickList
  429.  
  430. Proc Calendar!CatchEvents(EventType,TagValue,EventValue,ElementValue)
  431.    Private
  432.       Key,
  433.       OK
  434.    Switch
  435.       Case EventType = "ACCEPT":
  436.          If Not IsBlank(Calendar_PickList[DatePick]) Then
  437.             OK = True
  438.          Else
  439.             Beep
  440.             OK = false
  441.             SelectControl "Pick"
  442.          Endif
  443.       Case EventType = "EVENT":
  444.          Switch
  445.             Case EventValue["Type"] = "IDLE":
  446.                If Calendar_TimeVar <> Time() Then
  447.                   Calendar_TimeVar = Time()
  448.                   SetCanvas Calendar_WindowHandle
  449.                   @1,26
  450.                   Style Attribute Calendar.ColorBag[5]
  451.                   ?? Calendar_TimeVar
  452.                   Style
  453.                Endif
  454.                OK = True
  455.             Case EventValue["Type"] = "KEY":
  456.                Key = EventValue["KeyCode"]
  457.                Switch
  458.                   Case Key = Asc("PgUp"):
  459.                      If (Calendar_Month = 1) Then
  460.                         If (Calendar_Year > 100) Then
  461.                            Calendar_Month = 12
  462.                            Calendar_Year = Calendar_Year - 1
  463.                         Endif
  464.                      Else
  465.                         Calendar_Month = Calendar_Month - 1
  466.                      Endif
  467.                      Calendar!ResyncDatePick()
  468.                      Calendar!GeneratePickList()
  469.                   Case Key = Asc("PgDn"):
  470.                      If (Calendar_Month = 12) Then
  471.                         If (Calendar_Year < 9999) Then
  472.                            Calendar_Month = 1
  473.                            Calendar_Year = Calendar_Year + 1
  474.                         Endif
  475.                      Else
  476.                         Calendar_Month = Calendar_Month + 1
  477.                      Endif
  478.                      Calendar!ResyncDatePick()
  479.                      Calendar!GeneratePickList()
  480.                   Case Key = Asc("CtrlPgUp"):
  481.                      If (Calendar_Year > 100) Then
  482.                         Calendar_Year = Calendar_Year - 1
  483.                         Calendar!ResyncDatePick()
  484.                         Calendar!GeneratePickList()
  485.                      Else
  486.                         Beep
  487.                      Endif
  488.                   Case Key = Asc("CtrlPgDn"):
  489.                      If (Calendar_Year < 9999) Then
  490.                         Calendar_Year = Calendar_Year + 1
  491.                         Calendar!ResyncDatePick()
  492.                         Calendar!GeneratePickList()
  493.                      Else
  494.                         Beep
  495.                      Endif
  496.                   Case Key = Asc("Home"):
  497.                      DatePick = Calendar_MapToPickList[Calendar_Offset + 1]
  498.                   Case Key = Asc("End"):
  499.                      DatePick = Calendar_MapToPickList[Calendar_Offset + Calendar_HighDay]
  500.                EndSwitch
  501.                RefreshControl "Pick"
  502.                OK = False
  503.          EndSwitch
  504.       Case EventType = "OPEN":
  505.          If Calendar.DisplayTime Then
  506.             NewDialogSpec
  507.                Key "PgUp","PgDn","CtrlPgUp","CtrlPgDn","Home","End"
  508.                Idle
  509.                Trigger "Accept"
  510.          Else
  511.             NewDialogSpec
  512.                Key "PgUp","PgDn","CtrlPgUp","CtrlPgDn","Home","End"
  513.                Trigger "Accept"
  514.          Endif
  515.          Window Handle Dialog to Calendar_WindowHandle
  516.          Window SetColors Calendar_WindowHandle From Calendar.ColorBag
  517.          Window GetColors Calendar_WindowHandle To Calendar.ColorBag
  518.          Window SetAttributes Calendar_WindowHandle From Calendar.WindowBag
  519.          OK = True
  520.    EndSwitch
  521.    Return OK
  522. EndProc ; Calendar!CatchEvents
  523.  
  524. Proc Calendar!MovetoToday()
  525.    Private
  526.       Date
  527.    Date = Today()
  528.    Calendar_Day = Day(Date)
  529.    Calendar_Month = Month(Date)
  530.    Calendar_Year = Year(Date)
  531.    Calendar!GeneratePickList()
  532.    SelectControl "Pick"
  533.    RefreshControl "Pick"
  534.    Return True
  535. EndProc ; Calendar!MovetoToday
  536.  
  537. Proc Calendar!ChangeMonth()
  538.    Private
  539.       MonthPick,
  540.       ControlVar
  541.    MonthPick = Calendar_Month
  542.    ShowDialog "Select month"
  543.       Proc "Calendar!CatchMonthEvents"
  544.          Trigger "Open"
  545.       @500,500 Height 9 Width 28
  546.       Frame Single
  547.          From 0,0 To 4,25
  548.       PaintCanvas
  549.          Attribute Calendar.MonthFrameShadow
  550.          0,0,4,25
  551.       PaintCanvas
  552.          Attribute Calendar.MonthFrameHighlight
  553.          0,0,4,0
  554.       PaintCanvas
  555.          Attribute Calendar.MonthFrameHighlight
  556.          0,0,0,24
  557.       PickArray
  558.          @1,1 Height 3 Width 23
  559.          Columns 4
  560.          Calendar_MonthName
  561.          Tag "Pick"
  562.          To MonthPick
  563.       PushButton
  564.          @5,2 Width 10
  565.          "~O~K"
  566.          OK
  567.          Default
  568.          Value "OK"
  569.          Tag "OK"
  570.          To ControlVar
  571.       PushButton
  572.          @5,14 Width 10
  573.          "~C~ancel"
  574.          Cancel
  575.          Value "Cancel"
  576.          Tag "Cancel"
  577.          To ControlVar
  578.    EndDialog
  579.    If retval Then
  580.       Calendar_Month = MonthPick
  581.       Calendar!ResyncDatePick()
  582.       Calendar!GeneratePickList()
  583.       RefreshControl "Pick"
  584.    Endif
  585.    SelectControl "Pick"
  586.    Return True
  587. EndProc ; Calendar!ChangeMonth
  588.  
  589. Proc Calendar!CatchMonthEvents(EventType,TagValue,EventValue,ElementValue)
  590.    Private
  591.       OK
  592.    Switch
  593.       Case EventType = "OPEN":
  594.          Window Handle Dialog to Calendar_MonthWindowHandle
  595.          Window SetColors Calendar_MonthWindowHandle From Calendar.MonthColorBag
  596.          Window GetColors Calendar_MonthWindowHandle To Calendar.MonthColorBag
  597.          Window SetAttributes Calendar_MonthWindowHandle From
  598.             Calendar.MonthWindowBag
  599.          OK = True
  600.    EndSwitch
  601. EndProc
  602.  
  603. Proc Calendar!ChangeYear()
  604.    Private
  605.       ControlVar,
  606.       InputYear
  607.    RefreshControl "Pick"
  608.    InputYear = Calendar_Year
  609.    ShowDialog "Select year"
  610.       Proc "Calendar!CatchYearEvents"
  611.          Key "PgUp","PgDn"
  612.          Trigger "Open"
  613.       @500,500 Height 7 Width 27
  614.       Frame Single
  615.          From 0,0 To 2,24
  616.       PaintCanvas
  617.          Attribute Calendar.YearFrameShadow
  618.          0,0,2,24
  619.       PaintCanvas
  620.          Attribute Calendar.YearFrameHighlight
  621.          0,0,0,23
  622.       PaintCanvas
  623.          Attribute Calendar.YearFrameHighlight
  624.          0,0,2,0
  625.       Label @1,1 "~E~nter year: " For "Accept"
  626.       Accept
  627.          @1,13 Width 7
  628.          "S" Min 100 Max 9999 Required
  629.          Tag "Accept"
  630.          To InputYear
  631.       PushButton
  632.          @3,2 Width 10
  633.          "~O~K"
  634.          OK
  635.          Default
  636.          Value "OK"
  637.          Tag "OK"
  638.          To ControlVar
  639.       PushButton
  640.          @3,14 Width 10
  641.          "~C~ancel"
  642.          Cancel
  643.          Value "Cancel"
  644.          Tag "Cancel"
  645.          To ControlVar
  646.    EndDialog
  647.    If RetVal Then
  648.       Calendar_Year = InputYear
  649.       Calendar!ResyncDatePick()
  650.       Calendar!GeneratePickList()
  651.       RefreshControl "Pick"
  652.    Endif
  653.    SelectControl "Pick"
  654.    Return True
  655. EndProc ; Calendar!ChangeYear
  656.  
  657. Proc Calendar!CatchYearEvents(EventType,TagValue,EventValue,ElementValue)
  658.    Private
  659.       OK
  660.    Switch
  661.       Case EventType = "EVENT":
  662.          InputYear = ControlValue("Accept")
  663.          Switch
  664.             Case EventValue["Keycode"] = Asc("PgDn"):
  665.                If InputYear < 9999 Then
  666.                   InputYear = InputYear + 1
  667.                Endif
  668.             Case EventValue["Keycode"] = Asc("PgUp"):
  669.                If InputYear > 100 Then
  670.                   InputYear = InputYear - 1
  671.                Endif
  672.          EndSwitch
  673.          ResyncControl "Accept"
  674.          OK = False
  675.       Case EventType = "OPEN":
  676.          Window Handle Dialog to Calendar_YearWindowHandle
  677.          Window SetColors Calendar_YearWindowHandle From Calendar.YearColorBag
  678.          Window GetColors Calendar_YearWindowHandle To Calendar.YearColorBag
  679.          Window SetAttributes Calendar_YearWindowHandle From
  680.             Calendar.YearWindowBag
  681.          OK = True
  682.    EndSwitch
  683. EndProc ; Calendar!CatchYearEvents
  684.  
  685. Proc Calendar!ResyncDatePick()
  686.    Private
  687.       MapPointer
  688.    If IsBlank(Calendar_PickList[DatePick]) Then
  689.       MapPointer = Calendar_MapToMap[DatePick]
  690.       If MapPointer > 15 Then
  691.          DatePick = Calendar_MapToPickList[Calendar_Offset + Calendar_HighDay]
  692.          Calendar_Day = Calendar_HighDay
  693.       Else
  694.          DatePick = Calendar_MapToPickList[Calendar_Offset + 1]
  695.          Calendar_Day = 1
  696.       Endif
  697.    Else
  698.       Calendar_Day = Calendar_PickList[DatePick]
  699.    Endif
  700. EndProc ; Calendar!ResyncDatePick
  701.  
  702. Proc Calendar!GetDate(DayOfMonth,MonthOfYear,CalendarYear)
  703.    Return DateVal(StrVal(MonthOfYear) + "/" +
  704.                   StrVal(DayOfMonth) + "/" +
  705.                   StrVal(CalendarYear))
  706. EndProc ; Calendar!GetDate
  707.  
  708. Proc Calendar!GetHighDay(MonthOfYear,CalendarYear)
  709.    Private
  710.       MonthOfYear
  711.    If MonthOfYear = 12 Then
  712.       Return 31 ; December
  713.    Else
  714.       MonthOfYear = MonthOfYear + 1
  715.       Return Day(Calendar!GetDate(1,MonthOfYear,CalendarYear) - 1)
  716.    Endif
  717. EndProc ; Calendar!GetHighDay
  718.  
  719. Proc Closed Calendar.Show()
  720.    useVArs autolib
  721.    Calendar.Constructor()
  722.    Calendar.DisplayTime = False
  723.    ; Calendar.WindowBag["HasFrame"] = False
  724.    ; Calendar.YearWindowBag["HasFrame"] = False
  725.    ; Calendar.MonthWindowBag["HasFrame"] = False
  726.    If Calendar.Dialog() Then
  727.       If (SysMode() = "Edit" or SysMode() = "CoEdit") And
  728.          ImageType() = "Display" Then
  729.          If (Not IsFieldView()) And
  730.             FieldType() = "D" Then
  731.             [] = Calendar.Date
  732.          Endif
  733.          If IsFieldView() And
  734.             Substr(FieldType(),1,1) = "M" Then
  735.             Editor Insert Calendar.Date
  736.          Endif
  737.          If Substr(FieldType(),1,1) = "A" Then
  738.             Typein Calendar.Date
  739.          Endif
  740.       Endif
  741.    EndIf
  742.    Calendar.Destructor()
  743. EndProc ; Calendar.Show
  744.  
  745. If Not IsAssigned(Librarian.HasControl) Then
  746.    Calendar.Show()
  747. Endif