// **************************************************************************** // // ** ** // // ** Class : cMonthCalendar ** // // ** ** // // ** Purpose : Wrapper class for monthcalendar control ** // // ** ** // // ** Author : Ulbe Stellema ** // // ** Data Access Europe ** // // ** ** // // ** Date : januari 25, 2002 ** // // ** ** // // **************************************************************************** // Use cGrid.h Use cMonthCalendar.h Use GlobDate.pkg Class cMonthCalendar Is a cWinControl // Procedure : Construct_Object // Purpose : Object constructor Procedure Construct_Object Set External_Class_Name "DFUlbeMonthCalendar" To "SysMonthCal32" Forward Send Construct_Object Property Boolean pbHilightDays True Property Boolean pbDisplayToday False Property Boolean pbCircleToday False Property Boolean pbWeekNumbers True Property Date pdInitialDate Property Integer Private.peSelectionRange srDay // srWorkWeek Set External_Message WM_SETFOCUS To msg_OnSetFocus Set External_Message WM_KILLFOCUS To msg_OnKillFocus Set External_Message WM_LBUTTONDBLCLK To msg_OnLButtonDblClick Set Window_Style To WS_BORDER True Set Window_Style To WS_CHILD True Set Window_Style To WS_VISIBLE True Set Window_Style To CS_DBLCLKS True Set Window_Style To MCS_DAYSTATE (pbHilightDays(Self)) Set Window_Style To MCS_MULTISELECT True Set Window_Style To MCS_NOTODAY (Not(pbDisplayToday(Self))) Set Window_Style To MCS_NOTODAYCIRCLE (Not(pbCircleToday(Self))) Set Window_Style To MCS_WEEKNUMBERS (pbWeekNumbers(Self)) Set Extended_Window_Style To WS_EX_CLIENTEDGE True Set Extended_Window_Style To CS_DBLCLKS True On_Key kEnter Send OnEnter Set Focus_Mode To Focusable // Pointer_Only End_Procedure // Construct_Object // Function : ContainerFocusWillNotChange // Purpose : Allows cList to take focus Function ContainerFocusWillNotChange Returns Integer Function_Return False End_Function // ContainerFocusWillNotChange // Function : ContainsFocus // Purpose : Tell DF cList doesn't have the focus Function ContainsFocus Returns Integer Function_Return True End_Function // ContainsFocus // Function : Date2SysTime // Purpose : Returns a SYSTEMTIME structure Function Date2SysTime Date dDate Returns String String sSysTime ZeroType SYSTEMTIME To sSysTime Put (YearFromDate(ghoDateHandler,dDate)) To sSysTime at SYSTEMTIME.wYear Put (MonthFromDate(ghoDateHandler,dDate)) To sSysTime at SYSTEMTIME.wMonth Put (DayFromDate(ghoDateHandler,dDate)) To sSysTime at SYSTEMTIME.wDay Function_Return sSysTime End_Function // Date2SysTime // Function : SysTime2Date // Purpose : Returns Date Function SysTime2Date String sSysTime Returns Date Integer iYear iMonth iDay GetBuff From sSysTime at SYSTEMTIME.wYear To iYear GetBuff From sSysTime at SYSTEMTIME.wMonth To iMonth GetBuff From sSysTime at SYSTEMTIME.wDay To iDay Function_Return (ComposeDate(ghoDateHandler,iYear,iMonth,iDay)) End_Function // SysTime2Date // Function : StartDate // Purpose : Returns first date of current selection Function StartDate Returns Date Integer iResult iYear iMonth iDay String sTime sArray Date dDay // If (Not(pbMultiSelect(Self))) Begin // ZeroType SYSTEMTIME To sTime // Move (SendMessage(Window_Handle(Self),MCM_GETCURSEL,0,AddressOf(sTime))) To iResult // Get ShowLastError To iResult // GetBuff From sTime at SYSTEMTIME.wYear To iYear // GetBuff From sTime at SYSTEMTIME.wMonth To iMonth // GetBuff From sTime at SYSTEMTIME.wDay To iDay // Move (ComposeDate(ghoDateHandler,iYear,iMonth,iDay)) To dDay // Function_Return dDay // End // If (Private.peSelectionRange(Self) = srDay) Begin // Else Begin ZeroType SYSTEMTIME To sTime Move (Repeat(Character(0),SYSTEMTIME_Size*2)) To sArray Move (SendMessage(Window_Handle(Self),MCM_GETSELRANGE,0,AddressOf(sArray))) To iResult Move (CopyMemory(AddressOf(sTime),AddressOf(sArray),SYSTEMTIME_Size)) To iResult GetBuff From sTime at SYSTEMTIME.wYear To iYear GetBuff From sTime at SYSTEMTIME.wMonth To iMonth GetBuff From sTime at SYSTEMTIME.wDay To iDay Move (ComposeDate(ghoDateHandler,iYear,iMonth,iDay)) To dDay Function_Return dDay // End // Else Begin End_Function // StartDate // Procedure : Set peSelectionRange // Purpose : Sets the maximum (and minimum) number of selectable days Procedure Set peSelectionRange Integer iRange Integer iResult Set Private.peSelectionRange To iRange If (Window_Handle(Self)) ; Move (SendMessage(Window_Handle(Self),MCM_SETMAXSELCOUNT,iRange,0)) To iResult End_Procedure // Set peSelectionRange // Function : peSelectionRange // Purpose : Returns the maximum number of selectable days Function peSelectionRange Returns Integer Function_Return (Private.peSelectionRange(Self)) End_Function // peSelectionRange // Procedure : Private.SetColors // Purpose : Sets the colors of the calendar Procedure SetColors Integer iColor iResult // Get colors Get APIBackgroundColor To iColor Move (SendMessage(Window_Handle(Self),MCM_SETCOLOR,MCSC_BACKGROUND,iColor)) To iResult Get APIMonthBackgroundColor To iColor Move (SendMessage(Window_Handle(Self),MCM_SETCOLOR,MCSC_MONTHBK,iColor)) To iResult Get APITitleBackgroundColor To iColor Move (SendMessage(Window_Handle(Self),MCM_SETCOLOR,MCSC_TITLEBK,iColor)) To iResult Get APITextColor To iColor Move (SendMessage(Window_Handle(Self),MCM_SETCOLOR,MCSC_TEXT,iColor)) To iResult Get APITitleTextColor To iColor Move (SendMessage(Window_Handle(Self),MCM_SETCOLOR,MCSC_TITLETEXT,iColor)) To iResult Get APITrailingTextColor To iColor Move (SendMessage(Window_Handle(Self),MCM_SETCOLOR,MCSC_TRAILINGTEXT,iColor)) To iResult End_Procedure // SetColors // Procedure : Page_Object // Purpose : Sets the minimum size for the MonthCalendar control Procedure Page_Object Integer iState Integer iResult iLeft iTop iRight iBottom iColor iYear iMonth iDay iWeekDay String sRect sTime sArray sSystemTime Date dFrom dTo Forward Send Page_Object iState If (iState) Begin // Set maximum selection range Set peSelectionRange To (Private.peSelectionRange(Self)) // Set class style Move (SetClassLong(Window_Handle(Self),GCL_STYLE,CS_DBLCLKS iOr CS_GLOBALCLASS)) To iResult Send SetColors // Change selection if needed ZeroType SYSTEMTIME To sSystemTime ZeroType SYSTEMTIME To sTime Move (Repeat(Character(0),SYSTEMTIME_Size*2)) To sArray Move (SendMessage(Window_Handle(Self),MCM_GETSELRANGE,0,AddressOf(sArray))) To iResult Move (CopyMemory(AddressOf(sTime),AddressOf(sArray),SYSTEMTIME_Size)) To iResult GetBuff From sTime at SYSTEMTIME.wYear To iYear GetBuff From sTime at SYSTEMTIME.wMonth To iMonth GetBuff From sTime at SYSTEMTIME.wDay To iDay Move (ComposeDate(ghoDateHandler,iYear,iMonth,iDay)) To dFrom If (peSelectionRange(Self) = srDay) Send OnSelectionChanged dFrom dFrom If (peSelectionRange(Self) = srWorkWeek) Begin GetBuff From sTime at SYSTEMTIME.wDayOfWeek To iWeekDay If (WeekdayNumberFromDate(ghoDateHandler,dFrom) = 0) Move (dFrom+1) To dFrom Move (dFrom - (WeekdayNumberFromDate(ghoDateHandler,dFrom)-1)) To dFrom Put (YearFromDate(ghoDateHandler,dFrom)) To sSystemTime at SYSTEMTIME.wYear Put (MonthFromDate(ghoDateHandler,dFrom)) To sSystemTime at SYSTEMTIME.wMonth Put (DayFromDate(ghoDateHandler,dFrom)) To sSystemTime at SYSTEMTIME.wDay Move (sSystemTime) To sArray Move (dFrom+4) To dFrom Put (YearFromDate(ghoDateHandler,dFrom)) To sSystemTime at SYSTEMTIME.wYear Put (MonthFromDate(ghoDateHandler,dFrom)) To sSystemTime at SYSTEMTIME.wMonth Put (DayFromDate(ghoDateHandler,dFrom)) To sSystemTime at SYSTEMTIME.wDay Move (sArray+sSystemTime) To sArray Move (SendMessage(Window_Handle(Self),MCM_SETSELRANGE,0,AddressOf(sArray))) To iResult Send OnSelectionChanged (dFrom-4) (dFrom) End // If (peSelectionRange(Self) = srWorkWeek) Begin If (pdInitialDate(Self)) Begin Move (Date2SysTime(Self,pdInitialDate(Self))) To sSystemTime //Move (sSystemTime+sSystemTime) To sArray //Move (SendMessage(Window_Handle(Self),MCM_SETSELRANGE,0,AddressOf(sArray))) To iResult Move (SendMessage(Window_Handle(Self),MCM_SETTODAY,0,AddressOf(sSystemTime))) To iResult End // If (pdInitialDate(Self)) Begin End // If (iState) Begin End_Procedure // Page_Object // Procedure : OnSetFocus // Purpose : Event method Procedure OnSetFocus End_Procedure // OnSetFocus // Procedure : OnKillFocus // Purpose : Event method Procedure OnKillFocus End_Procedure // OnKillFocus // Procedure : OnSelectionChanged // Purpose : Event method Procedure OnSelectionChanged Date dFrom Date dTo End_Procedure // OnSelectionChanged // Procedure : OnSelect // Purpose : Event method Procedure OnSelect Date dFrom Date dTo End_Procedure // OnSelect // Procedure : OnDoubleClick // Purpose : Event method Procedure OnDoubleClick Date dDate End_Procedure // OnDoubleClick // Procedure : OnLButtonDblClick // Purpose : Handles WM_LBUTTONDBLCLICK Procedure OnLButtonDblClick Integer iResult String sSysTime sArray Date dDate // Where did the double-click occur Get HitTest To iResult If (iResult = MCHT_CALENDARDATE) Begin ZeroType SYSTEMTIME To sSysTime Move (Repeat(Character(0),SYSTEMTIME_Size*2)) To sArray Move (SendMessage(Window_Handle(Self),MCM_GETSELRANGE,0,AddressOf(sArray))) To iResult Move (CopyMemory(AddressOf(sSysTime),AddressOf(sArray),SYSTEMTIME_Size)) To iResult Move (SendMessage(Window_Handle(Self),MCM_GETCURSEL,0,AddressOf(sSysTime))) To iResult Get SysTime2Date sSysTime To dDate Send OnDoubleClick dDate End // If (iResult = MCHT_CALENDARDATE) Begin End_Procedure // OnLButtonDblClick // Procedure : OnEnter // Purpose : Handles ENTER key Procedure OnEnter Integer iResult String sSysTime sArray Date dDate ZeroType SYSTEMTIME To sSysTime Move (Repeat(Character(0),SYSTEMTIME_Size*2)) To sArray Move (SendMessage(Window_Handle(Self),MCM_GETSELRANGE,0,AddressOf(sArray))) To iResult Move (CopyMemory(AddressOf(sSysTime),AddressOf(sArray),SYSTEMTIME_Size)) To iResult Move (SendMessage(Window_Handle(Self),MCM_GETCURSEL,0,AddressOf(sSysTime))) To iResult Get SysTime2Date sSysTime To dDate Send OnDoubleClick dDate Send Close_Panel End_Procedure // OnEnter // Function : APIHilightDay // Purpose : This API function is called for every day in the month-calendar, // return TRUE if the day should be highlighted (bold), FALSE if // it should be normal. This function is only called if the pbHilightDays // property is True. Function APIHilightDay Date dDay Returns Integer // Boolean Function_Return 0 End_Function // APIHilightDay // Function : APIBackgroundColor // Purpose : Returns background color Function APIBackgroundColor Returns Integer Function_Return clWhite // clWindow End_Function // APIBackgroundColor // Function : APIMonthBackgroundColor // Purpose : Returns background color for month Function APIMonthBackgroundColor Returns Integer Function_Return clWhite End_Function // APIMonthBackgroundColor // Function : APITitleBackgroundColor // Purpose : Returns background color for title Function APITitleBackgroundColor Returns Integer Function_Return clDkGray End_Function // APITitleBackgroundColor // Function : APITextColor // Purpose : Returns text color Function APITextColor Returns Integer Function_Return clBlack End_Function // APITextColor // Function : APITitleTextColor // Purpose : Returns text color for title Function APITitleTextColor Returns Integer Function_Return clBlack End_Function // APITitleTextColor // Function : APITralingTextColor // Purpose : Returns trailing text color Function APITrailingTextColor Returns Integer Function_Return clLtGray End_Function // APITrailingTextColor // Procedure : Notify // Purpose : Handle WM_NOTIFY Procedure Notify Integer wParam Integer lParam Integer iResult iCode iYear iMonth iDay iMonths iCounter iLoop iWeekDay String sHdr sDayState sSystemTime sArray UInteger iFlags iFlag Date dDay dFrom dTo Integer bResult ZeroType tNMHDR To sHdr Move (CopyMemory(AddressOf(sHdr),lParam,tNMHDR_Size)) To iResult GetBuff From sHdr at tNMHDR.code To iCode If (iCode = MCN_SELCHANGE) Begin ZeroType NMSELCHANGE To sHdr Move (CopyMemory(AddressOf(sHdr),lParam,NMSELCHANGE_Size)) To iResult GetBuff From sHdr at NMSELCHANGE.stSelStart.wYear To iYear GetBuff From sHdr at NMSELCHANGE.stSelStart.wMonth To iMonth GetBuff From sHdr at NMSELCHANGE.stSelStart.wDay To iDay Move (ComposeDate(ghoDateHandler,iYear,iMonth,iDay)) To dFrom GetBuff From sHdr at NMSELCHANGE.stSelEnd.wYear To iYear GetBuff From sHdr at NMSELCHANGE.stSelEnd.wMonth To iMonth GetBuff From sHdr at NMSELCHANGE.stSelEnd.wDay To iDay Move (ComposeDate(ghoDateHandler,iYear,iMonth,iDay)) To dTo // Change selection if needed ZeroType SYSTEMTIME To sSystemTime If (peSelectionRange(Self) = srDay) Begin GetBuff From sHdr at NMSELCHANGE.stSelStart.wYear To iYear GetBuff From sHdr at NMSELCHANGE.stSelStart.wMonth To iMonth GetBuff From sHdr at NMSELCHANGE.stSelStart.wDay To iDay Move (ComposeDate(ghoDateHandler,iYear,iMonth,iDay)) To dFrom Put iYear To sSystemTime at SYSTEMTIME.wYear Put iMonth To sSystemTime at SYSTEMTIME.wMonth Put iDay To sSystemTime at SYSTEMTIME.wDay Move (sSystemTime+sSystemTime) To sArray Move (SendMessage(Window_Handle(Self),MCM_SETSELRANGE,0,AddressOf(sArray))) To iResult Send OnSelectionChanged dFrom dFrom End // If (peSelectionRange(Self) = srDay) Begin If (peSelectionRange(Self) = srWorkWeek) Begin ZeroType SYSTEMTIME To sSystemTime GetBuff From sHdr at NMSELCHANGE.stSelStart.wYear To iYear GetBuff From sHdr at NMSELCHANGE.stSelStart.wMonth To iMonth GetBuff From sHdr at NMSELCHANGE.stSelStart.wDay To iDay GetBuff From sHdr at NMSELCHANGE.stSelStart.wDayOfWeek To iWeekDay Move (ComposeDate(ghoDateHandler,iYear,iMonth,iDay)) To dFrom If (WeekdayNumberFromDate(ghoDateHandler,dFrom) = 0) Move (dFrom+1) To dFrom Move (dFrom - (WeekdayNumberFromDate(ghoDateHandler,dFrom)-1)) To dFrom Put (YearFromDate(ghoDateHandler,dFrom)) To sSystemTime at SYSTEMTIME.wYear Put (MonthFromDate(ghoDateHandler,dFrom)) To sSystemTime at SYSTEMTIME.wMonth Put (DayFromDate(ghoDateHandler,dFrom)) To sSystemTime at SYSTEMTIME.wDay Move (sSystemTime) To sArray Move (dFrom+4) To dFrom Put (YearFromDate(ghoDateHandler,dFrom)) To sSystemTime at SYSTEMTIME.wYear Put (MonthFromDate(ghoDateHandler,dFrom)) To sSystemTime at SYSTEMTIME.wMonth Put (DayFromDate(ghoDateHandler,dFrom)) To sSystemTime at SYSTEMTIME.wDay Move (sArray+sSystemTime) To sArray Move (SendMessage(Window_Handle(Self),MCM_SETSELRANGE,0,AddressOf(sArray))) To iResult Send OnSelectionChanged (dFrom-4) (dFrom) End // If (peSelectionRange(Self) = srWorkWeek) Begin If (peSelectionRange(Self) = srWeek) Begin Move (SendMessage(Window_Handle(Self),MCM_SETSELRANGE,0,AddressOf(sArray))) To iResult End // If (peSelectionRange(Self) = srWeek) Begin // Windows periodically sends MCN_SELCHANGE !!! just for fun //Send OnSelectionChanged dFrom dTo //If (peSelectionRange(Self) = srDay And (dTo-dFrom) = 1) Send OnSelectionChanged dFrom dTo //If (peSelectionRange(Self) = srWorkWeek And (dTo-dFrom) = 5 And ) End // If (iCode = MCN_SELCHANGE) Begin If (iCode = MCN_SELECT) Begin ZeroType NMSELCHANGE To sHdr Move (CopyMemory(AddressOf(sHdr),lParam,NMSELCHANGE_Size)) To iResult GetBuff From sHdr at NMSELCHANGE.stSelStart.wYear To iYear GetBuff From sHdr at NMSELCHANGE.stSelStart.wMonth To iMonth GetBuff From sHdr at NMSELCHANGE.stSelStart.wDay To iDay Move (ComposeDate(ghoDateHandler,iYear,iMonth,iDay)) To dFrom GetBuff From sHdr at NMSELCHANGE.stSelEnd.wYear To iYear GetBuff From sHdr at NMSELCHANGE.stSelEnd.wMonth To iMonth GetBuff From sHdr at NMSELCHANGE.stSelEnd.wDay To iDay Move (ComposeDate(ghoDateHandler,iYear,iMonth,iDay)) To dTo //Send OnSelectionChanged dFrom dTo End // If (iCode = MCN_SELECT) Begin If (iCode = MCN_GETDAYSTATE) Begin ZeroType NMDAYSTATE To sHdr Move (CopyMemory(AddressOf(sHdr),lParam,NMDAYSTATE_Size)) To iResult GetBuff From sHdr at NMDAYSTATE.stStart.wYear To iYear GetBuff From sHdr at NMDAYSTATE.stStart.wMonth To iMonth GetBuff From sHdr at NMDAYSTATE.stStart.wDay To iDay GetBuff From sHdr at NMDAYSTATE.cDayState To iMonths // Call API function for every single requested day For iLoop From iMonth To (iMonth+iMonths-1) Move 0 To iFlags If (iLoop > 12) Begin Move (iYear+1) To iYear Move (iLoop-12) To iLoop Move (iMonth-12) To iMonth End // If (iLoop > 12) Move (ComposeDate(ghoDateHandler,iYear,iLoop,1)) To dFrom Move (LastMonthDayDate(ghoDateHandler,iYear,iLoop)) To dTo For dDay From dFrom To dTo Get APIHilightDay dDay To bResult If (bResult = 1) Begin Move (DayFromDate(ghoDateHandler,dDay)-1) To iFlag Move (Integer(2^iFlag)) To iFlag Move (iFlags iOr iFlag) To iFlags End // If (bResult = 1) Begin Loop // For dDay From dFrom To dTo Move (sDayState+dWordToBytes(iFlags)) To sDayState Loop // For iLoop From iMonth To (iMonth+iMonths) Put (AddressOf(sDayState)) To sHdr at NMDAYSTATE.prgDayState Move (CopyMemory(lParam,AddressOf(sHdr),NMDAYSTATE_Size)) To iResult End // If (iCode = MCN_GETDAYSTATE) Begin End_Procedure // Notify Procedure RebuildList Integer iResult iYear iMonth iDay iMonths iLoop Integer iFlags iFlag bResult String sArray sTime sDayState Date dDay dFrom dTo Move (Repeat(Character(0),SYSTEMTIME_Size*2)) To sArray Move (SendMessage(Window_Handle(Self),MCM_GETMONTHRANGE,GMR_DAYSTATE,AddressOf(sArray))) To iMonths ZeroType SYSTEMTIME To sTime Move (CopyMemory(AddressOf(sTime),AddressOf(sArray),SYSTEMTIME_Size)) To iResult GetBuff From sTime at SYSTEMTIME.wYear To iYear GetBuff From sTime at SYSTEMTIME.wMonth To iMonth GetBuff From sTime at SYSTEMTIME.wDay To iDay // Call API function for every single requested day For iLoop From iMonth To (iMonth+iMonths-1) Move 0 To iFlags If (iLoop > 12) Begin Move (iYear+1) To iYear Move (iLoop-12) To iLoop Move (iMonth-12) To iMonth End // If (iLoop > 12) Move (ComposeDate(ghoDateHandler,iYear,iLoop,1)) To dFrom Move (LastMonthDayDate(ghoDateHandler,iYear,iLoop)) To dTo For dDay From dFrom To dTo Get APIHilightDay dDay To bResult If (bResult = 1) Begin Move (DayFromDate(ghoDateHandler,dDay)-1) To iFlag Move (Integer(2^iFlag)) To iFlag Move (iFlags iOr iFlag) To iFlags End // If (bResult = 1) Begin Loop // For dDay From dFrom To dTo Move (sDayState+dWordToBytes(iFlags)) To sDayState Loop // For iLoop From iMonth To (iMonth+iMonths) Move (SendMessage(Window_Handle(Self),MCM_SETDAYSTATE,iMonths,AddressOf(sDayState))) To iResult Send SetColors End_Procedure // RebuildList // Function : HitTest // Purpose : Returns item under cursor Function HitTest Returns Integer Integer iResult iX iY String sPoint sType ZeroType POINT To sPoint Move (GetCursorPos(AddressOf(sPoint))) To iResult Move (ScreenToClient(Window_Handle(Self),AddressOf(sPoint))) To iResult GetBuff From sPoint at POINT.x To iX GetBuff From sPoint at POINT.y To iY ZeroType MCHITTESTINFO To sType Put MCHITTESTINFO_Size To sType at MCHITTESTINFO.cbSize Put iX To sType at MCHITTESTINFO.pt.x Put iY To sType at MCHITTESTINFO.pt.y Move (SendMessage(Window_Handle(Self),MCM_HITTEST,0,AddressOf(sType))) To iResult GetBuff From sType At MCHITTESTINFO.UHit To iResult Function_Return iResult End_Function // HitTest End_Class // cMonthCalendar