/** * @file XTPCalendarRemindersManager.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(_XTP_CALENDAR_REMINDERS_MANAGER_H__) # define _XTP_CALENDAR_REMINDERS_MANAGER_H__ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 ////////////////////// class CXTPCalendarData; class CXTPCalendarResources; class CXTPCalendarResourcesNf; class CXTPCalendarRemindersManager; class CXTPNotifyConnection; class CXTPCalendarEvent; class CXTPCalendarEvents; class CXTPNotifySink; # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" /** @cond */ XTP_DEFINE_SMART_PTR_INTERNAL(CXTPCalendarEvent) XTP_DEFINE_SMART_PTR_INTERNAL(CXTPCalendarEvents) /** @endcond */ /** * @brief * This class describes a reminder for a calendar event and implements base * properties for and operations on the reminder. */ class _XTP_EXT_CLASS CXTPCalendarReminder : public CXTPCmdTarget { /** @cond */ DECLARE_DYNAMIC(CXTPCalendarReminder) friend class CXTPCalendarRemindersManager; friend class CXTPCalendarReminders; /** @endcond */ public: /** * @brief * Default object constructor. * * @param pOwnerMan A pointer to the reminders manager which owns this object. * * @see ~CXTPCalendarReminder() */ CXTPCalendarReminder(CXTPCalendarRemindersManager* pOwnerMan = NULL); /** * @brief * Default class destructor. * * @details * Handles member items deallocation. * * @see CXTPCalendarReminder() */ virtual ~CXTPCalendarReminder(); /** * @brief * Retrieve the calendar event for which this reminder is related. * * @return A pointer to a calendar event object. */ virtual CXTPCalendarEventPtr GetEvent() const; /** * @brief * Call this member function to retrieve the date and time when a reminder * is scheduled to be activated. * * @details * This value for non-snoozed event is: * EventStartTime - MinutesBeforeStart. * For snoozed event this value is set when Snooze() method is called. * * @return Reminder activation date and time. * * @see GetMinutesBeforeStart * @see Snooze * @see GetEvent */ virtual COleDateTime GetNextReminderTime() const; /** * @brief * Call this member function to determine the number of minutes * before the start of an event. * * @return An int that contains the number of Minutes before the start of * an event. * * @see CXTPCalendarEvent::GetReminderMinutesBeforeStart * @see GetEvent */ virtual int GetMinutesBeforeStart() const; /** * @brief * Call this member function to Snooze an active reminder. * * @param nMinutesAfterNow A value in minutes to activate reminder again. * * @return TRUE if operation is successful, FALSE otherwise. * * @see Dismiss * @see GetNextReminderTime * @see GetEvent * @see CXTPCalendarRemindersManager::Snooze */ virtual BOOL Snooze(int nMinutesAfterNow); /** * @brief * Call this member function to Dismiss an active reminder. * * @details * Reminder flag for corresponding event object is set to FALSE. * * @return TRUE if operation is successful, FALSE otherwise. * * @see Snooze * @see GetEvent * @see CXTPCalendarRemindersManager::Dismiss */ virtual BOOL Dismiss(); /** * @brief * Call this member function to determine if reminders objects have * equal IDs (or are they represent the same reminder). * * @param pReminder2 A pointer to reminder object to compare. * * @return TRUE if reminders objects have equal IDs, FALSE otherwise. */ virtual BOOL IsEqualID(const CXTPCalendarReminder* pReminder2) const; protected: COleDateTime m_dtNextReminderTime; /**< Store reminder activation date and time. */ int m_nMinutesBeforeStart; /**< Store minutes before start event to activate reminder.*/ /** * @brief * Set a calendar event for which this reminder is related. * * @param pEvent A pointer to calendar event. * * @see GetEvent */ virtual void SetEvent(CXTPCalendarEvent* pEvent); /** * @brief * This enum define the event type: recurrence or non-recurrence. */ enum EventType { evtNormal = 1, /**< event type is recurrence. */ evtRecurrence = 2, /**< event type is non-recurrence. */ }; /** * @brief * This structure contains data members to unambiguously define related * recurrence event occurrence. * * @see EventType */ struct RecurrenceEventInfo { DWORD m_dwMasterEventID; /**< Recurrence master event ID.*/ DATE m_dtOccurrenceStartTime; /**< Recurrence occurrence start time or recurrence exception original start time.*/ DATE m_dtOccurrenceEndTime; /**< Recurrence occurrence end time or recurrence exception original end time.*/ }; COleDateTime m_dtEventStartTime; /**< Store related event start time. */ CXTPCalendarData* m_pEventDataProvider; /**< Store related event data provider. */ EventType m_eEventType; /**< Define related event type: recurrence or non-recurrence. */ /** * @brief * This union contains data members to unambiguously define a related * event. * * @see RecurrenceEventInfo * @see m_eEventType */ union { DWORD m_dwNormalEventID; /**< Non-recurrence event ID.*/ RecurrenceEventInfo m_RecurrenceEventInfo; /**< Recurrence event information (instead of ID).*/ }; private: CXTPCalendarRemindersManager* m_pOwnerMan; protected: # ifdef _XTP_ACTIVEX DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPCalendarReminder); LPDISPATCH OleGetEvent(); DATE OleGetNextReminderTime(); long OleGetMinutesBeforeStart(); BOOL OleSnooze(long nMinutesAfterNow); BOOL OleDismiss(); # endif }; /** * @brief * This class represents a simple array collection of CXTPCalendarReminder * objects. */ class _XTP_EXT_CLASS CXTPCalendarReminders : public CXTPCalendarPtrCollectionT { public: /** * @brief * Finds a specified reminder object in the collection. * * @details * CXTPCalendarReminder::IsEqualID method is used to compare reminders. * * @param pReminder A pointer to the reminder object to find. * * @return Index of the equal reminder object in the collection or -1 if such * object is not present. * * @see CXTPCalendarEvent */ virtual int Find(const CXTPCalendarReminder* pReminder) const; /** * @brief * Finds a reminder object in the collection which is related to * the event specified. * * @param pEvent A pointer to the event. * * @return Index of the related reminder object in the collection or * -1 if such object is not present. * * @see CXTPCalendarReminder */ virtual int Find(CXTPCalendarEvent* pEvent) const; /** * @brief * Finds a reminder object in the collection which is related to * the specified event ID. * * @param dwEventID Event ID of a normal event or Master event. * @param pDP A pointer to the event data provider. * * @return Index of the related reminder object in the collection or * -1 if such object is not present. * * @see CXTPCalendarReminder * @see CXTPCalendarEvent */ virtual int Find(DWORD dwEventID, CXTPCalendarData* pDP = NULL) const; /** * @brief * Try to find and remove reminder object which is related to * the event specified. * * @param pEvent A pointer to the event. * * @return TRUE if the related reminder object is removed from the collection, * FALSE otherwise. */ virtual BOOL RemoveDataForEvent(CXTPCalendarEvent* pEvent); /** * @brief * Sort reminders by the event start time field. */ virtual void Sort(); protected: /** * @brief * Try to find and remove reminder(s) object(s) which are related to * the recurrence master event specified. * * @param pEvent A pointer to the master event. * * @return TRUE if the related reminder(s) object(s) was removed from * the collection, FALSE otherwise. */ virtual BOOL _RemoveDataForMasterEvent(CXTPCalendarEvent* pEvent); }; /** * @brief * This class is used to monitor and manage calendar events reminders. * It will send notifications when the active reminders list * is changed - new reminder(s) come or some reminder(s) goes away. * * @details * When Reminder manager starts, it checks all events which have a Reminder * flag set. * Reminder for event is added to active reminders list when: * Event->StartTime - Event->ReminderMinutesBeforeStart \<= Now * * There are 2 actions with reminder: * Dismiss - reset Reminder flag for the event and remove reminder. * Reminder never comes back; * * Snooze - set new NextReminderTime value and remove reminder. * Reminder will come back when NextReminderTime \<= Now. * * Some Reminder manager data is stored in CalendarEvent custom properties * (or RecurrencePattern custom properties). This means if your own events * storage is used, you have to save/load custom properties too. * * StartMonitoring/StopMonitoring are used to start/stop reminders manager. * These methods are called by the calendar control automatically when * CXTPCalendarControl::EnableReminders() method is called. * * GetActiveReminders is used to retrieve collection of active reminders. */ class _XTP_EXT_CLASS CXTPCalendarRemindersManager : public CWnd { /** @cond */ DECLARE_DYNAMIC(CXTPCalendarRemindersManager) /** @endcond */ friend class CXTPCalendarReminder; public: /** * @brief * Default object constructor. * * @see ~CXTPCalendarRemindersManager() */ CXTPCalendarRemindersManager(); /** * @brief * Default object destructor. * * @see CXTPCalendarRemindersManager() */ virtual ~CXTPCalendarRemindersManager(); /** * @brief * Call this method to retrieve reminders count in the active * reminders collection. * * @details * Can be useful to quickly determine if the active reminders collection * is empty without copy collection. * * @return Active reminders count. * * @see GetActiveReminders */ virtual int GetActiveRemindersCount() const; /** * @brief * Call this method to retrieve the active reminders collection. * * @param rarActiveReminders A reference to an array to retrieve active * reminders. * * @see GetActiveRemindersCount */ virtual void GetActiveReminders(CXTPCalendarReminders& rarActiveReminders) const; /** * @brief * Call this member function to Snooze a specified reminder. * * @param pReminder A pointer to a reminder object. * @param nMinutesAfterNow A value in minutes to activate the reminder again. * * @return TRUE if operation is successful, FALSE otherwise. * * @see Dismiss * @see CXTPCalendarReminder::Snooze * @see CXTPCalendarReminder::Dismiss * @see CXTPCalendarReminder::GetNextReminderTime */ virtual BOOL Snooze(CXTPCalendarReminder* pReminder, int nMinutesAfterNow); /** * @brief * Call this member function to Dismiss a specified reminder. * * @details * Reminder flag for the corresponding event object is set to FALSE. * * @param pReminder A pointer to a reminder object. * * @return TRUE if the operation is successful, FALSE otherwise. * * @see Snooze * @see CXTPCalendarReminder::Snooze * @see CXTPCalendarReminder::Dismiss */ virtual BOOL Dismiss(CXTPCalendarReminder* pReminder); /** * @brief * Call this member function to Dismiss all active reminders. * * @details * Reminder flag for each event object is set to FALSE. * * @return TRUE if operation is successful, FALSE otherwise. * * @see Snooze * @see Dismiss * @see CXTPCalendarReminder::Snooze * @see CXTPCalendarReminder::Dismiss */ virtual BOOL DismissAll(); /** * @brief * Obtain a pointer to the notification connection object. * * @details * Used to subscribe (Advice) for notification events from the * reminders manager. * * @return Connection object pointer. * * @see CXTPNotifyConnection overview * @see IXTPNotificationSink overview */ CXTPNotifyConnection* GetConnection() const; /** * @brief * This method is used to attach to calendar resources (data provider) * and start reminders monitoring. * * @param pResources A pointer to a calendar resources collection. * @param spPeriod2Cache A time period for which reminder manager will read * reminders from calendar resources (data provider). * * @details * To retrieve reminders, the CXTPCalendarData::GetUpcomingEvents() method * is used. This can be a slow operation and by using the spPeriod2Cache * parameter value we can control how often this method will be called. * * For example calendar control use spPeriod2Cache = 2 hours by default. * This means than GetUpcomingEvents will be called only once per 2 hours. * * @return TRUE if operation is successful, FALSE otherwise. * * @see StopMonitoring */ virtual BOOL StartMonitoring(CXTPCalendarResources* pResources, COleDateTimeSpan spPeriod2Cache); /** * @brief * This method is used to detach from calendar resources (data provider) * and and to clear all reminders in reminders manager. * * @return TRUE if operation is successful, FALSE otherwise. * * @see StartMonitoring */ virtual BOOL StopMonitoring(); /** * @brief * Call this method to determine if StartMonitoring was successfully * called and if the reminders manager is monitoring reminders. * * @return TRUE if reminders manager is active (started/running), FALSE otherwise. * * @see StartMonitoring * @see StopMonitoring */ virtual BOOL IsMonitoringRunning() const; protected: /** * @brief * This method is used to send an XTP_NC_CALENDAR_ON_REMINDERS notification * via connection object. * * @param eAction A reminders action. Value from enum XTPCalendarRemindersAction. * @param lParam Reserved. Set to 0. * * @see XTP_NC_CALENDAR_ON_REMINDERS * @see XTPCalendarRemindersAction */ virtual void NotifyReminders(int eAction, LPARAM lParam = 0); /** * @brief * Schedule to call NotifyReminders(xtpCalendarRemindersFire) in 500 ms. * * @see NotifyReminders * @see XTP_NC_CALENDAR_ON_REMINDERS * @see XTPCalendarRemindersAction */ virtual void PostNotify_RemindersFire(); /** * @brief * This method clears all reminders in reminders manager collections. * * @see StopMonitoring */ virtual void RemoveAll(); CXTPNotifySink* m_pSink; afx_msg void OnTimeChange(); afx_msg void OnTimer(UINT_PTR uTimerID); virtual BOOL _Dismiss(CXTPCalendarReminder* pReminder); virtual BOOL UpdateDataFromDP(COleDateTime dtFrom, COleDateTimeSpan spPeriod); virtual BOOL GetUpcomingEventsAll(COleDateTime dtFrom, COleDateTimeSpan spPeriod, CXTPCalendarEventsPtr& rptrEvents); virtual BOOL ProcessActiveReminders(COleDateTime dtTime); virtual void OnEventChanged(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam); virtual BOOL ProcessNewEvent(CXTPCalendarEvent* pEvent, COleDateTime dtFrom, COleDateTimeSpan spPeriod); virtual BOOL ProcessChangedEvent(CXTPCalendarEvent* pEvent); virtual BOOL _ProcessNewSingleEvent(CXTPCalendarEvent* pEvent, COleDateTime dtFrom, COleDateTimeSpan spPeriod); virtual BOOL _ProcessNewMasterEvent(CXTPCalendarEvent* pEvent, COleDateTime dtFrom, COleDateTimeSpan spPeriod); virtual BOOL _GetMaxExceptionReminder(CXTPCalendarRecurrencePattern* pPattern, int& rnMinutes); virtual BOOL _RemoveSnoozeData(CXTPCalendarReminder* pRmd); virtual BOOL _CreateWnd(); virtual void OnFinalRelease(); /** @cond */ DECLARE_MESSAGE_MAP() /** @endcond */ protected: CXTPNotifyConnection* m_pConnection; /**< A pointer to the notification connection object.*/ CXTPCalendarResourcesNf* m_pResourcesNf; /**< A collection of calendar resources to be monitored. */ COleDateTimeSpan m_spPeriod2Cache; /**< Time period to cache data from the calendar resources. */ COleDateTime m_dtLastUpdateTime; /**< Store last time when reminders data was loaded from the calendar resources.*/ CXTPCalendarReminders m_arWaitingReminders; /**< Waiting reminders collection. */ CXTPCalendarReminders m_arActiveReminders; /**< Active reminders collection. */ BOOL m_bMonitoringRunning; /**< Flag indicate that reminders manager is started;*/ BOOL m_bSkipOnEventChanged; protected: # ifdef _XTP_ACTIVEX DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() XTP_DECLARE_CMDTARGETPROVIDER_INTERFACE() DECLARE_OLETYPELIB_EX(CXTPCalendarRemindersManager); DECLARE_ENUM_VARIANT(CXTPCalendarRemindersManager); int OleGetItemCount(); LPDISPATCH OleGetItem(long nIndex); void OleDismissAll(); # endif }; //////////////////////////////////////////////////////////////////////////// AFX_INLINE COleDateTime CXTPCalendarReminder::GetNextReminderTime() const { return m_dtNextReminderTime; } AFX_INLINE int CXTPCalendarReminder::GetMinutesBeforeStart() const { return m_nMinutesBeforeStart; } AFX_INLINE BOOL CXTPCalendarReminder::Snooze(int nMinutesAfterNow) { _ASSERTE(m_pOwnerMan); return m_pOwnerMan ? m_pOwnerMan->Snooze(this, nMinutesAfterNow) : FALSE; } AFX_INLINE BOOL CXTPCalendarReminder::Dismiss() { _ASSERTE(m_pOwnerMan); return m_pOwnerMan ? m_pOwnerMan->Dismiss(this) : FALSE; } //=========================================================================== AFX_INLINE CXTPNotifyConnection* CXTPCalendarRemindersManager::GetConnection() const { return m_pConnection; } AFX_INLINE BOOL CXTPCalendarRemindersManager::IsMonitoringRunning() const { return m_bMonitoringRunning; } # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif // !defined(_XTP_CALENDAR_REMINDERS_MANAGER_H__)