/** * @file XTPCalendarController.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ #if !defined(_XTPCALENDARCONTROLLER_H__) # define _XTPCALENDARCONTROLLER_H__ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPDatePickerControl; class CXTPCalendarControl; class CXTPCalendarResourcesNf; class CXTPNotifySink; struct XTP_DAYITEM_METRICS; /** * @brief * Class CXTPCalendarController provides a connection between a * CXTPCalendarControl object and a CXTPDatePickerControl object. * * @details * A CXTPCalendarController object provides synchronization * facilities between CXTPCalendarControl and CXTPDatePickerControl * controls. It works as a "glue" between both controls and * reflects changes on one of them to the corresponded changes on the * second one. * * @see CXTPCalendarControl * @see CXTPDatePickerControl */ class _XTP_EXT_CLASS CXTPCalendarController : public CXTPCmdTarget { /** @cond */ DECLARE_DYNCREATE(CXTPCalendarController) /** @endcond */ public: /** * @brief * Constructs a CXTPCalendarController object. * * @details * Construction of the CXTPCalendarController object defines * a point of synchronization between CXTPCalendarControl and * CXTPDatePickerControl controls. It can be constructed both * in the same scope with controls which would provide us with * full live objects time synchronization, and in the local scope * for short time synchronization. * * Example: *
	 * Declare a local CXTPCalendarController object.
	 * CXTPCalendarController myCalendarController;
	 *
	 * // Assigns CXTPCalendarControl instance to the object.
	 * myCalendarController.SetCalendar(&m_wndCalendar);
	 *
	 * // Assigns CXTPDatePickerControl instance to the object.
	 * myCalendarController.SetDatePicker(&m_wndDatePicker);
	 * 
* * @see SetCalendar * @see SetDatePicker */ CXTPCalendarController(); /** * @brief * Destroys a CXTPCalendarController object, handles cleanup and * deallocation. */ virtual ~CXTPCalendarController(); // Attributes public: /** * @brief * This member function associates a custom calendar control * with the controller. * * @param pCalendarCtrl A pointer to the user's CXTPCalendarControl object. * * @details * Call this member function to associate your CXTPCalendarControl * object with this calendar controller. * * @see CXTPCalendarControl overview * @see SetDatePicker */ virtual void SetCalendar(CXTPCalendarControl* pCalendarCtrl); /** * @brief * This member function associates a custom date picker control * with the controller. * * @param pDatePickerCtrl Pointer to the user's CXTPDatePickerControl object. * * @details * Call this member function to associate your CXTPDatePickerControl * object with this calendar controller. * * @see CXTPDatePickerControl overview * @see SetCalendar */ virtual void SetDatePicker(CXTPDatePickerControl* pDatePickerCtrl); /** * @brief * Gets a calendar control object associated with the controller. * * @return A pointer to calendar control. * * @details * A pointer to calendar control object associated with the * controller or NULL. * * @see SetCalendar * @see SetDatePicker * @see GetDatePicker */ virtual CXTPCalendarControl* GetCalendar() const; /** * @brief * Gets a date picker control object associated with the controller. * * @return A pointer to the date picker control. * * @details * A pointer to date picker control object associated with the * controller or NULL. * * @see SetCalendar * @see SetDatePicker * @see GetCalendar */ virtual CXTPDatePickerControl* GetDatePicker() const; public: /** * @brief * This member function is used to determine whether Bold font is used * for days in DatePicker which have corresponding Calendar events. * * @return TRUE when Bold font is used, FALSE otherwise. * * @see SetBoldDaysWithEvents */ virtual BOOL IsBoldDaysWithEvents() const; /** * @brief * This member function enables or disables Bold font usage for * displaying days in DatePicker which have corresponding Calendar * events. * * @param bBold TRUE to enable; FALSE to disable. * * @details * Disabling this parameter could be useful in cases when determining * whether a particular day has events takes a long time. * * @see IsBoldDaysWithEvents */ virtual void SetBoldDaysWithEvents(BOOL bBold); /** * @brief * Is BoldDaysOnIdle option enabled or disabled. * * @return TRUE if enabled retrieve days state (bold or regular) * on idle (by timer) for the associated DatePicker. * * @see SetBoldDaysOnIdle * @see GetBoldDaysPerIdleStep * @see GetBoldDaysIdleStepTime_ms * @see SetBoldDaysPerIdleStep * @see SetBoldDaysIdleStepTime_ms */ virtual BOOL IsBoldDaysOnIdle() const; /** * @brief * Enable or Disable retrieve days state (bold or regular) * on idle (by timer) for the associated DatePicker. * * @param bBoldDaysOnIdle Set as TRUE to Enable or FALSE to Disable retrieve * days state on idle. * * @see IsBoldDaysOnIdle * @see GetBoldDaysPerIdleStep * @see GetBoldDaysIdleStepTime_ms * @see SetBoldDaysPerIdleStep * @see SetBoldDaysIdleStepTime_ms */ virtual void SetBoldDaysOnIdle(BOOL bBoldDaysOnIdle); /** * @brief * Returns Amount of days for the associated DatePicker to update state * in one idle step. * * @return Amount of days for the associated DatePicker to update state in one * idle step. * * @see SetBoldDaysOnIdle * @see IsBoldDaysOnIdle * @see GetBoldDaysIdleStepTime_ms * @see SetBoldDaysPerIdleStep * @see SetBoldDaysIdleStepTime_ms */ virtual long GetBoldDaysPerIdleStep() const; /** * @brief * Returns time between idle steps to update days state (bold or regular) * for the associated DatePicker. * * @return Time between idle steps in milliseconds. * * @see SetBoldDaysOnIdle * @see IsBoldDaysOnIdle * @see GetBoldDaysPerIdleStep * @see SetBoldDaysPerIdleStep * @see SetBoldDaysIdleStepTime_ms */ virtual long GetBoldDaysIdleStepTime_ms() const; /** * @brief * Set amount of days for the associated DatePicker to update state * in one idle step. * * @param nDaysPerStep An amount of days to update in one step. * * @see SetBoldDaysOnIdle * @see IsBoldDaysOnIdle * @see GetBoldDaysIdleStepTime_ms * @see GetBoldDaysPerIdleStep * @see SetBoldDaysIdleStepTime_ms */ virtual void SetBoldDaysPerIdleStep(long nDaysPerStep); /** * @brief * Set time (in milliseconds) between idle steps to update days state * (bold or regular) for the associated DatePicker. * * @param nStepTime_ms An idle step in milliseconds. * * @see SetBoldDaysOnIdle * @see IsBoldDaysOnIdle * @see GetBoldDaysPerIdleStep * @see SetBoldDaysPerIdleStep * @see GetBoldDaysIdleStepTime_ms */ virtual void SetBoldDaysIdleStepTime_ms(long nStepTime_ms); // Implementation protected: CXTPNotifySink* m_pSink; /** * @brief * This member function subscribes itself for all necessary notifications. * * @details * This member function is called when controller object wants to * reinitialize its event subscriptions from associated controls. * * @see CXTPCalendarController overview */ virtual void AdviseToNotifications(); /** * @brief * This member function gets the first day of week from the calendar control * and set the same value to the date picker control. * * @see OnEvent_CalendarOptionsChanged() * @see CXTPCalendarController overview */ virtual void SetFirstDayOfWeekToDatePicker(); /** * @brief * This member function is used to determine if Compressed Weekend Day - * Sunday, is used as the first day of week in the active calendar view. * * @details * It means that first day of week is automatically shifted from * Sunday to Monday because Sunday is compressed with Saturday and * it cannot be shown as first day of week in the active calendar view. * * @see CXTPCalendarWeekView * @see CXTPCalendarMonthView, * @see CXTPCalendarControl::MonthView_IsCompressWeekendDays() * @see CXTPCalendarControl::GetFirstDayOfWeek() */ // virtual BOOL IsFirstDayOfWeekShifted_FromSun2Mon(); /** * @brief * This member function catches all the events from the associated * calendar control and its view. * * @param Event Events code. * @param wParam First user's parameter. * @param lParam Second user's parameter. * * @details * This member function is called when an event is fired from the * associated CXTPCalendarControl object or from its view. * * @see AdviseToNotifications */ virtual void OnEvent_CalendarView(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam); /** * @brief * This member function catches all the events when calendar control * options were changed. * * @param Event Events code. * @param wParam First user's parameter. * @param lParam Second user's parameter. * * @details * This member function is called when an event is fired when calendar * control options where changed. * * @see AdviseToNotifications */ virtual void OnEvent_CalendarOptionsChanged(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam); /** * @brief * This member function catches all the events when resource * configuration is changed in the CalendarControl. * * @param Event Events code. * @param wParam First user's parameter. * @param lParam Second user's parameter. * * @see AdviseToNotifications */ virtual void OnEvent_CalendarResourcesChanged(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam); /** * @brief * This member function catches the XTP_NC_CALENDAR_THEME_CHANGED event. * * @param Event Events code. * @param wParam First user's parameter. * @param lParam Second user's parameter. * * @see AdviseToNotifications */ virtual void OnEvent_CalendarThemeChanged(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam); /** * @brief * This member function catches all the events from the associated * date picker control. * * @param Event Events code. * @param wParam First user's parameter. * @param lParam Second user's parameter. * * @details * This member function is called when an event is fired from the * associated CXTPDatePickerControl object. * * @see AdviseToNotifications */ virtual void OnEvent_DatePicker(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam); /** * @brief * This member function catches all the events from the associated * date picker control. * * @param Event Events code. * @param wParam First user's parameter. * @param lParam Second user's parameter. * * @details * This member function is called when an event is fired from the * associated CXTPDatePickerControl object. * * @see AdviseToNotifications */ virtual void OnEvent_DtPickGetItemMetrics(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam); protected: CXTPCalendarControl* m_pCalendarCtrl; /**< Pointer to the associated Calendar control.*/ CXTPDatePickerControl* m_pDatePickerCtrl; /**< Pointer to the associated DatePicker control.*/ BOOL m_bBoldDaysWithEvents; /**< TRUE to use Bold for days with events in the associated DatePicker.*/ BOOL m_bUseActiveViewResoucesForBold; /**< If true - active view resources are used, if FALSE - calendar control Resources are used.*/ BOOL m_bBoldDaysOnIdle; /**< TRUE to retrieve days state (bold or regular) on idle (by timer) for the associated DatePicker.*/ long m_nBoldDaysPerIdleStep; /**< Amount of days for the associated DatePicker to update state in one idle step.*/ long m_nBoldDaysIdleStepTime_ms; /**< Time between idle steps to update days state (bold or regular) for the associated DatePicker.*/ /** * @brief * This member function is used to determine if the specified day has events or not. * * @param dtDay A COleDateTime object that contains the day's date. * * @return TRUE if the specified day has events, FALSE otherwise. */ BOOL _HasEvents(COleDateTime dtDay); private: void _AdviseToDataChanged(); void _UnadviseFromDataChanged(); virtual void OnEvent_CalendarDataChanged(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam); BOOL m_bAdjustingView; CXTPCalendarResourcesNf* m_pResourcesNf; int m_eLastActiveView; XTP_CONNECTION_ID m_cnidEventAdded; XTP_CONNECTION_ID m_cnidEventChanged; XTP_CONNECTION_ID m_cnidEventDeleted; // class CXTPDayInfoCache { struct XTPDayInfo { BOOL bHasEvents; DATE dtLastAccessTime; }; CMap m_mapDaysInfo; CMap m_mapDaysToRefresh; CXTPCalendarController* m_pOwner; UINT_PTR m_uTimerID; DWORD m_dwLastRedrawTime; DWORD m_dwLastSelfClearTime; DWORD m_dwWaitingDataTime; UINT m_uActivePriority; public: CXTPDayInfoCache(); virtual ~CXTPDayInfoCache(); BOOL HasEvents(DATE dtDay); void Init(CXTPCalendarController* pOwner); void Clear(); void ClearDays(COleDateTime dtDayFrom, COleDateTime dtDayTo); void RequestToRefreshDays(COleDateTime dtDayFrom, COleDateTime dtDayTo); UINT UpActivePriority(); protected: void UpdateDayInfo(DATE dtDay, BOOL bHasEvents); void KillTimer(); void _RequestToRefreshDays(COleDateTime dtDayFrom, COleDateTime dtDayTo, UINT uPriority = 0); void OnRefreshDays(int nDaysCountToRefresh = 1); void OnSelfClearOld(); static VOID CALLBACK OnTimerCallback(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime); typedef CMap CXTPMapTimers; static CXTPMapTimers m_mapTimers; }; friend class CXTPDayInfoCache; CXTPDayInfoCache m_DayInfoCache; }; ///////////////////////////////////////////////////////////////////////////// AFX_INLINE BOOL CXTPCalendarController::IsBoldDaysWithEvents() const { return m_bBoldDaysWithEvents; } AFX_INLINE BOOL CXTPCalendarController::IsBoldDaysOnIdle() const { return m_bBoldDaysOnIdle; } AFX_INLINE void CXTPCalendarController::SetBoldDaysOnIdle(BOOL bBoldDaysOnIdle) { m_bBoldDaysOnIdle = bBoldDaysOnIdle; m_DayInfoCache.Clear(); } AFX_INLINE long CXTPCalendarController::GetBoldDaysPerIdleStep() const { return m_nBoldDaysPerIdleStep; } AFX_INLINE void CXTPCalendarController::SetBoldDaysPerIdleStep(long nDaysPerStep) { m_nBoldDaysPerIdleStep = nDaysPerStep; } AFX_INLINE long CXTPCalendarController::GetBoldDaysIdleStepTime_ms() const { return m_nBoldDaysIdleStepTime_ms; } AFX_INLINE void CXTPCalendarController::SetBoldDaysIdleStepTime_ms(long nStepTime_ms) { m_nBoldDaysIdleStepTime_ms = nStepTime_ms; } # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif // !defined(_XTPCALENDARCONTROLLER_H__)