/** * @file XTPCalendarResource.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(_XTPCALENDARRESOURCE_H_) # define _XTPCALENDARRESOURCE_H_ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPCalendarControl; class CXTPCalendarData; class CXTPNotifyConnection; class CXTPCalendarCustomProperties; class CXTPPropExchange; class CXTPCalendarEvents; class CXTPCalendarEvent; /** @cond */ XTP_DEFINE_SMART_PTR_INTERNAL(CXTPCalendarEvents) /** @endcond */ /** * @brief * Calendar Schedule is a characteristic of the Calendar Event, which * describes a belonging of the Event to a particular Schedule (which * could be people schedule, common resource schedule, etc). * * This class implements base properties of the Schedule and operations * on it. */ class _XTP_EXT_CLASS CXTPCalendarSchedule : public CXTPCmdTarget { /** @cond */ DECLARE_DYNAMIC(CXTPCalendarSchedule) /** @endcond */ public: /** * @brief * Default object constructor. * Constructs a CXTPCalendarSchedule object. * * @param uScheduleID A numeric positive ID of the schedule. * @param pcszScheduleName A string name of the schedule (could be a name * of the person, etc) * * @see ~CXTPCalendarSchedule */ CXTPCalendarSchedule(UINT uScheduleID = 0, LPCTSTR pcszScheduleName = _T("")); /** * @brief * Default class destructor. * * @details * Handles member items deallocation. * * @see CXTPCalendarSchedule */ virtual ~CXTPCalendarSchedule(); /** * @brief * This member function is used to obtain a unique schedule ID. * * @return A UINT unique id. * * @see CXTPCalendarSchedule * @see SetID */ UINT GetID() const; /** * @brief * This member function is used to obtain the schedule name. * * @return A CString object that contains the schedule name text. * * @see SetName */ CString GetName() const; /** * @brief * This member function is used to set a new ID value for a schedule. * * @param uScheduleID A DWORD that contains the id value. * * @see GetID */ void SetID(UINT uScheduleID); # ifdef _BUSINESS_MODEL_ UINT GetSecType() const; void SetSecType(UINT uScheduleSec); # endif /** * @brief * This member function is used to set the schedule name text. * * @param pcszScheduleName An LPCTSTR object that contains the string of text. * * @see GetName */ void SetName(LPCTSTR pcszScheduleName); /** * @brief * Get custom (named, user-defined) properties collection. * * @return A pointer to CXTPCalendarCustomProperties object. * * @see CXTPCalendarCustomProperties */ CXTPCalendarCustomProperties* GetCustomProperties() const; protected: CString m_strScheduleName; /**< Stores Schedule Name*/ UINT m_uScheduleID; /**< Stores numeric positive ID of the schedule*/ # ifdef _BUSINESS_MODEL_ UINT m_uScheduleSec; /**< Stores Schedule Security Type*/ # endif CXTPCalendarCustomProperties* m_pCustomProperties; /**< Stores custom properties collection for this Schedule*/ protected: # ifdef _XTP_ACTIVEX DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPCalendarSchedule); afx_msg LPDISPATCH OleCustomProperties(); # endif }; /** * @brief * This class represents a simple array collection of CXTPCalendarSchedule * objects. * * @details * Array indexes always start at position 0. * * As with a C array, the access time for indexed element of this * array is constant and is independent of the array size. * * @see CArray overview * @see CXTPCalendarSchedule overview */ class _XTP_EXT_CLASS CXTPCalendarSchedules : public CXTPCalendarPtrCollectionT { /** @cond */ DECLARE_DYNAMIC(CXTPCalendarSchedules) /** @endcond */ public: /** * @brief * Default collection constructor. * * @see ~CXTPCalendarSchedules() */ CXTPCalendarSchedules(); /** * @brief * Default collection destructor. * * @details * Handles member item deallocation. Decreases reference of all * stored CXTPCalendarSchedule objects. * * @see RemoveAll() */ virtual ~CXTPCalendarSchedules(); /** * @brief * Creates and adds a new schedule object by its name. * * @param pcszScheduleName String with the schedule name. * * @return TRUE if added successfully; FALSE otherwise. * * @see RemoveSchedule */ virtual BOOL AddNewSchedule(LPCTSTR pcszScheduleName); /** * @brief * Removes a schedule object from the array by its ID. * * @param uScheduleID The ID for the schedule. * * @return TRUE if object was found and removed from the array; * FALSE otherwise. * * @see AddNewSchedule */ virtual BOOL RemoveSchedule(UINT uScheduleID); /** * @brief * Returns a name of the schedule by its numeric ID. * * @param uScheduleID The ID for the schedule. * * @return A LPCTSTR value specifying the schedule name. * * @see SetScheduleName */ virtual LPCTSTR GetScheduleName(UINT uScheduleID) const; /** * @brief * Finds schedule index in the internal array by its ID. * * @param uScheduleID Label ID. * * @return Schedule index in the internal label array. */ virtual int FindIndex(UINT uScheduleID) const; /** * @brief * Sets a new schedule name by its numeric ID. * * @param uScheduleID The ID for the schedule. * @param pcszNewName String of text for the new name of the schedule. * * @see GetScheduleName */ virtual void SetScheduleName(UINT uScheduleID, LPCTSTR pcszNewName); /** * @brief * Call this member function to Store/Load a schedule using the * specified data object. * * @param pPX Source or destination CXTPPropExchange data object reference. * * @details * This member function is used to store schedule data to * or load schedule data from storage. */ virtual void DoPropExchange(CXTPPropExchange* pPX); protected: /** * @brief * Finds the next available ID which does not exist in the array. * * @return Available ID which does not exist in the array. * * @details * Function found max ID and returns it incremented by one. */ virtual UINT _GetNextID() const; /** * @brief * Call this member function to Load a schedule from the * specified data object. * * @param pPX Source CXTPPropExchange data object reference. * * @details * This member function is used to load schedule data * from a specified storage. */ virtual void _Load(CXTPPropExchange* pPX); /** * @brief * Call this member function to Store a schedule to the * specified data object. * * @param pPX Destination CXTPPropExchange data object reference. * * @details * This member function is used to store schedule data to * a storage. */ virtual void _Save(CXTPPropExchange* pPX); # ifdef _XTP_ACTIVEX DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPCalendarSchedules); DECLARE_ENUM_VARIANT(CXTPCalendarSchedules) BSTR OleGetScheduleName(UINT uScheduleID); # endif }; /** * @brief * Class CXTPCalendarResource represents a calendar for some subject like * a person, a shared resource, or even a group of people or resources. * * @details * Each resource is to be drawn in the separate column on the calendar view. * Each resource should have its own DataProvider. For example, events * for people could be stored inside the Memory data provider (somebody's * own or temporary events), and for other resources - inside a Database * data provider (those events are not changed by the user). So, there is * a possibility to use any combination of data providers in the same control. * * @see CXTPCalendarControl * @see CXTPCalendarData */ class _XTP_EXT_CLASS CXTPCalendarResource : public CXTPCmdTarget { /** @cond */ DECLARE_DYNCREATE(CXTPCalendarResource) /** @endcond */ public: /** * @brief * Default object constructor. * Constructs a CXTPCalendarResource object. * * @param pCalendarCtrl Pointer to the parent Calendar control. * * @see ~CXTPCalendarResource */ CXTPCalendarResource(CXTPCalendarControl* pCalendarCtrl = NULL); /** * @brief * Default class destructor. * * @details * Handles member items deallocation. * * @see XTPCalendarResource */ virtual ~CXTPCalendarResource(); ///////////////////////////////////////////////////////////////////////// // data provider related /** * @brief * This member function obtains a pointer to the current data * provider instance. * * @details * Call this member function to obtain the data provider object * currently used by this calendar control. * * @return A CXTPCalendarData pointer to the associated data provider object. * * @see CXTPCalendarData overview * @see SetDataProvider */ CXTPCalendarData* GetDataProvider() const; /** * @brief * This member function sets the custom data provider for the control. * * @param pDataProvider Pointer to the custom data provider object. * @param bCloseDataProviderWhenDestroy If this parameter is TRUE, the Close method * of the data provided will be called on this * resource destruction. * * @details * Call this member function to set the custom data provider * that is currently used by this calendar control. Note that * custom data provider must be a descendant of CXTPCalendarData. * * @see CXTPCalendarData overview * @see GetDataProvider */ void SetDataProvider(CXTPCalendarData* pDataProvider, BOOL bCloseDataProviderWhenDestroy = FALSE); /** * @brief * Call this member function to get the collection of the day's * events for this resource. All events from the applied schedules * will be included. * * @param dtDay A COleDateTime object that contains the day's date. * * @return A pointer to a CXTPCalendarEvents object that contains the * collection of the day's events. * * @see * CXTPCalendarEvents */ virtual CXTPCalendarEventsPtr RetrieveDayEvents(COleDateTime dtDay); /** * @brief * Call this member function to get the collection of all schedule * IDs for this resource. * * @return A pointer to the CUIntArray collection which contains numeric IDs * for all schedules existing in this resource. * * @see CUIntArray overview * @see IsSchedulesSetEmpty * @see ExistsScheduleID */ virtual CUIntArray* GetSchedules(); /** * @brief * This member function determines whether a schedule with the * specified ID exists or not. * * @param uScheduleID A numeric ID of the schedule to check. * @param bReturnTrueIfSchedulesSetEmpty TRUE by default. * If there are not any schedules specified inside this resource, * the Calendar will show all available events. * * @return TRUE if a schedule ID exists in the Schedules collection for * this resource; FALSE otherwise. * * @see GetSchedules * @see IsSchedulesSetEmpty */ virtual BOOL ExistsScheduleID(UINT uScheduleID, BOOL bReturnTrueIfSchedulesSetEmpty = TRUE); /** * @brief * This member function is used to remove events which are not from this * resource. * * @param pEvents An events collection to be filtered. * * @see ExistsScheduleID */ void FilterEventsByScheduleID(CXTPCalendarEvents* pEvents); /** * @brief * Call this member function to determine if the schedules set in this * resource is empty or not. * * @return TRUE if the schedules set is empty for this resource; * FALSE if at least 1 schedule exists. * * @see GetSchedules * @see ExistsScheduleID */ virtual BOOL IsSchedulesSetEmpty() const; /** * @brief * This member function returns a string name of this resource object. * * @return A string with the name of the resource object. * * @see SetName */ virtual CString GetName() const; /** * @brief * This member function applies a new name to the resource object. * * @param pcszResourceName A string with the new name for the resource. * * @see GetName */ virtual void SetName(LPCTSTR pcszResourceName); /** * @brief * This member function returns a color of this resource object. * * @return A COLORREF with the color of the resource object. * * @see SetColor */ virtual COLORREF GetColor() const; /** * @brief * This member function applies a new color to the resource object. * * @param color A COLORREF with the new color for the resource. * * @see GetColor */ virtual void SetColor(COLORREF color); protected: CString m_strResourceName; /**< Text name of the resource */ CXTPCalendarControl* m_pCalendarCtrl; /**< Parent Calendar control */ CXTPCalendarData* m_pDataProvider; /**< Associated data provider */ CUIntArray m_arScheduleIDs; /**< which schedules are used for this resource.*/ COLORREF m_Color; /**< color of resource */ BOOL m_bCloseDataProviderWhenDestroy; /**< If TRUE - call Close() method for the data provider when control is destroyed.*/ protected: # ifdef _XTP_ACTIVEX DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPCalendarResource); DECLARE_OLECREATE_EX(CXTPCalendarResource); LPDISPATCH OleGetDataProvider(); LPDISPATCH OleGetScheduleIDs(); void OleSetDataProvider(LPDISPATCH pDispDataProvider, BOOL bCloseDataProviderWhenDestroy); void OleSetDataProvider2(LPCTSTR pcszConnectionString, BOOL bCloseDataProviderWhenDestroy); LPDISPATCH OleRetrieveDayEvents(DATE dtDay); # endif }; /** * @brief * This class represents a simple array collection of CXTPCalendarResource * objects. * * @see CXTPCalendarPtrCollectionT */ class _XTP_EXT_CLASS CXTPCalendarResources : public CXTPCalendarPtrCollectionT { /** @cond */ DECLARE_DYNCREATE(CXTPCalendarResources) /** @endcond */ public: /** * @brief * Default collection constructor. * * @see ~CXTPCalendarResources() */ CXTPCalendarResources(); /** * @brief * Default collection destructor. * * @details * Handles member item deallocation. Decreases reference of all * stored CXTPCalendarResource objects. * * @see RemoveAll() */ virtual ~CXTPCalendarResources(); /** * @brief * This member function is used to remove events which are not from this * resource. * * @param pEvent A pointer to a CXTPCalendarEvent. * * @return A pointer to the calendar resource. * * @see ExistsScheduleID */ CXTPCalendarResource* Find(CXTPCalendarEvent* pEvent) const; using CXTPCalendarPtrCollectionT::Find; /** * @brief * This member function is used to remove events which are not from this * resource. * * @param dtDay COleDateTime. * * @return A calendar events pointer object. * * @see ExistsScheduleID */ CXTPCalendarEventsPtr RetrieveDayEvents(COleDateTime dtDay) const; protected: # ifdef _XTP_ACTIVEX DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPCalendarResources) DECLARE_ENUM_VARIANT(CXTPCalendarResources) DECLARE_OLECREATE_EX(CXTPCalendarResources) void OleAdd(LPDISPATCH pResourceDisp); # endif }; /** * @brief * This class implements CXTPCalendarResource functionality with the addition * of a notifications mechanism implemented by CXTPNotifySink. * * @see CXTPCalendarResource overview * @see CXTPNotifySink overview */ class _XTP_EXT_CLASS CXTPCalendarResourcesNf : public CXTPCalendarResources , private CXTPNotifySinkBase { public: /** * @brief * Default object constructor. * Constructs a CXTPCalendarResourcesNf object. * * @see ~CXTPCalendarResourcesNf */ CXTPCalendarResourcesNf(); /** * @brief * Default class destructor. * * @details * Handles member items deallocation. * * @see CXTPCalendarResourcesNf */ virtual ~CXTPCalendarResourcesNf(); /** * @brief * Obtain a pointer to the notification connection object. * * @details * Used to subscribe (Advice) for notification events from the * control. * * @return Connection object pointer. * * @see CXTPNotifyConnection overview * @see IXTPNotificationSink overview */ CXTPNotifyConnection* GetConnection() const; /** * @brief * Rebuilds notification connection objects after changes in resources * configuration. * Call this member function after advising to notifications from * connection pointers of the CXTPCalendarResourcesNf object. * * @see GetConnection * @see GetResourcesGroupedByDP */ virtual void ReBuildInternalData(); /** * @brief * Call this member function to retrieve a resources collection * only for unique data providers. * * @details * This method returns a collection of temporary resources objects * having only unique data providers. * It could be useful to retrieve a complete collection of events for * further processing from all data providers in scope of resources * collection, and in order not to retrieve duplicate events. * * @return A pointer to the internal resources collection which is rebuilt * during the ReBuildInternalData method execution. * * @see ReBuildInternalData */ virtual const CXTPCalendarResources* GetResourcesGroupedByDP() const; /** * @brief * Call this member function to retrieve a resource object for a specified * data provider. * * @details * This method returns a resource from a temporary internal collection. * * @param pData pointer to CXTPCalendarData. * * @return A pointer to the internal resource from collection which is rebuilt * during the ReBuildInternalData method execution. * * @see GetResourcesGroupedByDP * @see ReBuildInternalData */ CXTPCalendarResource* FindByDataProvider(CXTPCalendarData* pData) const; protected: /** * @brief * This member function catches all the events from the associated * data provider and forwards it to CXTPCalendarResourcesNf * subscribers. * * @param dwNotifyCode Events notification code. * @param wParam First user's parameter. * @param lParam Second user's parameter. * @param dwFlags Unused parameter. */ virtual void OnEvent(XTP_NOTIFY_CODE dwNotifyCode, WPARAM wParam, LPARAM lParam, DWORD dwFlags); private: static CXTPCalendarResource* AFX_CDECL FindByDataProvider(const CXTPCalendarResources* pResources, CXTPCalendarData* pData); CXTPCalendarResources m_arResourcesGroupedByDP; class CXTPNotifyConnection_internal : public CXTPNotifyConnection { public: using CXTPNotifyConnection::CONNECTION_DESCRIPTOR; using CXTPNotifyConnection::m_arrConnections; }; CXTPNotifyConnection_internal* m_pConnection; }; ////////////////////////////////////////////////////////////////////////// AFX_INLINE UINT CXTPCalendarSchedule::GetID() const { return m_uScheduleID; } AFX_INLINE CString CXTPCalendarSchedule::GetName() const { return m_strScheduleName; } AFX_INLINE void CXTPCalendarSchedule::SetID(UINT uScheduleID) { m_uScheduleID = uScheduleID; } AFX_INLINE void CXTPCalendarSchedule::SetName(LPCTSTR pcszScheduleName) { _ASSERTE(pcszScheduleName); m_strScheduleName = pcszScheduleName ? pcszScheduleName : _T(""); } # ifdef _BUSINESS_MODEL_ AFX_INLINE UINT CXTPCalendarSchedule::GetSecType() const { return m_uScheduleSec; } AFX_INLINE void CXTPCalendarSchedule::SetSecType(UINT uScheduleSec) { m_uScheduleSec = uScheduleSec; } # endif AFX_INLINE CUIntArray* CXTPCalendarResource::GetSchedules() { return &m_arScheduleIDs; } AFX_INLINE BOOL CXTPCalendarResource::IsSchedulesSetEmpty() const { return m_arScheduleIDs.GetSize() == 0; } AFX_INLINE CXTPCalendarData* CXTPCalendarResource::GetDataProvider() const { _ASSERTE(this); return this ? m_pDataProvider : NULL; } AFX_INLINE CString CXTPCalendarResource::GetName() const { return m_strResourceName; } AFX_INLINE void CXTPCalendarResource::SetName(LPCTSTR pcszResourceName) { _ASSERTE(NULL != pcszResourceName); m_strResourceName = (NULL != pcszResourceName ? CString(pcszResourceName) : m_strResourceName); } AFX_INLINE COLORREF CXTPCalendarResource::GetColor() const { return m_Color; } AFX_INLINE void CXTPCalendarResource::SetColor(COLORREF color) { m_Color = color; } AFX_INLINE CXTPNotifyConnection* CXTPCalendarResourcesNf::GetConnection() const { return m_pConnection; } AFX_INLINE const CXTPCalendarResources* CXTPCalendarResourcesNf::GetResourcesGroupedByDP() const { return &m_arResourcesGroupedByDP; } AFX_INLINE CXTPCalendarResource* CXTPCalendarResourcesNf::FindByDataProvider(CXTPCalendarData* pData) const { return FindByDataProvider(GetResourcesGroupedByDP(), pData); } AFX_INLINE CXTPCalendarCustomProperties* CXTPCalendarSchedule::GetCustomProperties() const { return m_pCustomProperties; } # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif // !defined(_XTPCALENDARRESOURCE_H_)