//////////////////////////////////////////////////////////////////////
// XTPPropExchange.h: interface for the CXTPPropExchange class.
//
// This file is a part of the XTREME TOOLKIT PRO MFC class library.
// (c)1998-2012 Codejock Software, All Rights Reserved.
//
// THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
// RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
// CONSENT OF CODEJOCK SOFTWARE.
//
// THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
// IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
// YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
// SINGLE COMPUTER.
//
// CONTACT INFORMATION:
// support@codejock.com
// http://www.codejock.com
//
/////////////////////////////////////////////////////////////////////////////
//{{AFX_CODEJOCK_PRIVATE
#if !defined(__XTPPROPEXCHANGE_H__)
#define __XTPPROPEXCHANGE_H__
//}}AFX_CODEJOCK_PRIVATE
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "XTPXMLHelpers.h"
#include "XTPPropExchange.inc"
#pragma warning(disable:4510)
#pragma warning(disable:4610)
#define XTP_LOCALE_ISO8601 ((LCID)-1)
class CXTPPropExchange;
//===========================================================================
// Summary:
// CXTPPropExchangeEnumerator is standalone class. It used by CXTPPropExchange to enumerate child sections.
//
// Example:
//
// extern CXTPPropExchange* pPX;
//
// CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("Icon")));
// POSITION posEnum = pEnumerator->GetPosition();
//
// while (posEnum)
// {
// CXTPPropExchangeSection secIcon(pEnumerator->GetNext(posEnum));
// }
//
// See Also: CXTPPropExchange, CXTPPropExchange::GetEnumerator
//===========================================================================
class _XTP_EXT_CLASS CXTPPropExchangeEnumerator
{
public:
//-------------------------------------------------------------------------
// Summary:
// Constructs a CXTPPropExchangeEnumerator object.
// Parameters:
// pContainer - Parent section of enumerator
// lpszSection - Enumerator section name
//-------------------------------------------------------------------------
CXTPPropExchangeEnumerator(CXTPPropExchange* pContainer, LPCTSTR lpszSection);
//-------------------------------------------------------------------------
// Destroys a CXTPPropExchangeEnumerator object, handles cleanup and de-
// allocation.
//-------------------------------------------------------------------------
virtual ~CXTPPropExchangeEnumerator();
public:
//-------------------------------------------------------------------------
// Summary:
// Call this method to init enumerable section
// Parameters:
// dwCount - Count of items to be stored.
// bCompactMode - TRUE to use "compact mode" of XML nodes.
// Returns:
// A POSITION value that can be used for iteration; NULL if the section is empty.
//-------------------------------------------------------------------------
virtual POSITION GetPosition(DWORD dwCount = 0, BOOL bCompactMode = TRUE);
//-------------------------------------------------------------------------
// Summary:
// Call this method to get next enumerable section to load.
// Parameters:
// pos - A reference to a POSITION value returned by a previous GetNext, GetPosition, or other member function call.
//-------------------------------------------------------------------------
virtual CXTPPropExchange* GetNext(POSITION& pos);
CXTPPropExchange* GetContainer() const;
virtual int GetCount() const;
protected:
CXTPPropExchange* m_pContainer; // Parent section of enumerator
CString m_strSectionName; // Enumerator section name
DWORD m_nCount; // Count of items to load.
};
//===========================================================================
// Summary:
// CXTPPropExchange is standalone pure class.
// The CXTPPropExchange class allows you to save a complex network of objects in a permanent binary or text form (usually disk storage) that persists after those objects are deleted. Later you can load the objects from persistent storage, reconstituting them in memory. This process of making data persistent is called 'serialization.'
//
// You can use one of derived classes:
// * CXTPPropExchangeArchive to serialize to archive,
// * CXTPPropExchangeRegistry to serialize to registry key,
// * CXTPPropExchangeXMLNode to serialize to XML node.
// Example:
//
// CXTPPropExchangeXMLNode px(TRUE, 0, _T("Settings"));
// if (px.LoadFromFile(m_strIniFileName))
// {
// m_wndTaskPanel.GetGroups()->DoPropExchange(&px);
// }
//
//===========================================================================
class _XTP_EXT_CLASS CXTPPropExchange : public CXTPCmdTarget
{
DECLARE_DYNAMIC(CXTPPropExchange)
public:
//-------------------------------------------------------------------------
// Summary:
// Constructs a CXTPPropExchange object.
//-------------------------------------------------------------------------
CXTPPropExchange();
//-------------------------------------------------------------------------
// Summary:
// Destroys a CXTPPropExchange object, handles cleanup and de-
// allocation.
//-------------------------------------------------------------------------
virtual ~CXTPPropExchange();
public:
//-----------------------------------------------------------------------
// Summary:
// This method determines whether properties are being loaded to
// the class or stored from it.
// Returns:
// Nonzero if properties are being loaded; otherwise, it is zero.
//-----------------------------------------------------------------------
BOOL IsLoading() const;
//-----------------------------------------------------------------------
// Summary:
// This method determines whether properties are being loaded to
// the class or stored from it.
// Returns:
// Nonzero if the properties are currently being used for storing; otherwise 0.
//-----------------------------------------------------------------------
BOOL IsStoring() const;
//-----------------------------------------------------------------------
// Summary:
// Call this method to use default values specified in PX_* functions while load process.
// Parameters:
// bUseDefaultOnLoad - TRUE to use default value; FALSE to ignore it.
// See Also: UseDefaultOnSave, PX_String, PX_Int, PX_Bool
//-----------------------------------------------------------------------
void UseDefaultOnLoad(BOOL bUseDefaultOnLoad = TRUE);
//-----------------------------------------------------------------------
// Summary:
// Call this method to use default values specified in PX_* functions while save process.
// Parameters:
// bUseDefaultOnSave - TRUE to use default value; FALSE to ignore it.
// See Also: UseDefaultOnLoad, PX_String, PX_Int, PX_Bool
//-----------------------------------------------------------------------
void UseDefaultOnSave(BOOL bUseDefaultOnSave = TRUE);
//-----------------------------------------------------------------------
// Summary:
// Determines if CXTPPropExchange is used as root section
// Returns:
// TRUE if CXTPPropExchange object it root section.
// Remarks:
// Used only in CXTPPropExchangeXMLNode and CXTPPropExchangeRegistry classes
// See Also: GetSection
//-----------------------------------------------------------------------
BOOL IsRootSection() const;
//-----------------------------------------------------------------------
// Summary:
// Call this function from the DoPropExchange function to determine the version of the object that is currently being de-serialized
// Returns:
// During de-serialization, the version of the object being read.
//-----------------------------------------------------------------------
UINT GetSchema() const;
//-----------------------------------------------------------------------
// Summary:
// Exchanges a property between a storage and the class.
// Parameters:
// pszPropName - The name of the property being exchanged.
// vtProp - A symbol specifying the type of the property being
// exchanged.
// pvProp - A pointer to the property's value.
// pvDefault - Pointer to a default value for the property.
// Remarks:
// Possible values of properties are:
//
// CXTPPropExchangeSection pxTaskPanel(px.GetSection(_T("TaskPanel")));
// m_wndTaskPanel.GetGroups()->DoPropExchange(&pxTaskPanel);
//
//-----------------------------------------------------------------------
virtual CXTPPropExchange* GetSection(LPCTSTR lpszSection) = 0;
//-------------------------------------------------------------------------
// Summary:
// Call this method to free section information before storing
//-------------------------------------------------------------------------
virtual void EmptySection();
//-----------------------------------------------------------------------
// Summary:
// Use this member function to Write DWORD number to storage
// Parameters:
// dwCount - DWORD number
// See Also: ReadCount
//-----------------------------------------------------------------------
virtual void WriteCount (DWORD dwCount);
//-----------------------------------------------------------------------
// Summary:
// Use this member function to read DWORD number from storage
// Returns:
// DWORD number
// See Also: WriteCount
//-----------------------------------------------------------------------
virtual DWORD ReadCount ();
//-----------------------------------------------------------------------
// Summary:
// Writes a specified number of bytes.
// Parameters:
// pszPropName - The name of the property being exchanged.
// lpBuf - A pointer to a user-supplied buffer that contains the data to be written.
// nCount - An integer that specifies the number of bytes to be written.
//-----------------------------------------------------------------------
virtual void Write (LPCTSTR pszPropName, const void* lpBuf, UINT nCount);
//-----------------------------------------------------------------------
// Summary:
// Reads a specified number of bytes.
// Parameters:
// pszPropName - The name of the property being exchanged.
// lpBuf - A pointer to a user-supplied buffer that is to receive the data
// nCount - An unsigned integer specifying the number of bytes to be read from the archive.
// Returns:
// An unsigned integer containing the number of bytes actually read.
//-----------------------------------------------------------------------
virtual UINT Read (LPCTSTR pszPropName, void* lpBuf, UINT nCount);
//-----------------------------------------------------------------------
// Summary:
// Call this method to determine if storage supported default values.
// Returns:
// TRUE if storage allows default values
//-----------------------------------------------------------------------
virtual BOOL IsAllowDefaultValues() const;
//-----------------------------------------------------------------------
// Summary:
// Call this method to determine if storage allows exchange plain blob values.
// Returns:
// TRUE if storage allows exchange plain blob values.
//-----------------------------------------------------------------------
virtual BOOL IsAllowBlobValues() const;
//-----------------------------------------------------------------------
// Summary:
// This method is called before exchange properties.
// Returns:
// TRUE if storage ready to exchange properties.
//-----------------------------------------------------------------------
virtual BOOL OnBeforeExchange();
//-----------------------------------------------------------------------
// Summary:
// Call this method to enumerate child sections.
// Parameters:
// lpszSection - child section name.
// Returns:
// Returns an enumerator for child sections.
// Example:
//
// extern CXTPPropExchange* pPX;
//
// CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("Icon")));
// POSITION posEnum = pEnumerator->GetPosition();
//
// while (posEnum)
// {
// CXTPPropExchangeSection secIcon(pEnumerator->GetNext(posEnum));
// }
//
// See Also: CXTPPropExchangeEnumerator
//-----------------------------------------------------------------------
virtual CXTPPropExchangeEnumerator* GetEnumerator(LPCTSTR lpszSection);
public:
static void AFX_CDECL BinToString(BYTE* pData, DWORD nBytes, CString& str);
static BOOL AFX_CDECL StringToBin(const CString& str, BYTE*& pData, DWORD& nBytes);
protected:
//-----------------------------------------------------------------------
// Summary:
// This methods is called to copy internal data from root section.
// Parameters:
// pRootSection - Parent section
//-----------------------------------------------------------------------
void InitSection(CXTPPropExchange* pRootSection);
//{{AFX_CODEJOCK_PRIVATE
public:
static void AFX_CDECL PreformatString(CString& strValue, BOOL bLoading);
virtual void ExchangeSchemaSafe();
protected:
DWORD GetSizeOfVarType(VARTYPE vt);
BOOL IsSamePropValue(VARTYPE vtProp, const void* pv1, const void* pv2);
BOOL CopyPropValue(VARTYPE vtProp, void* pvDest, const void* pvSrc);
BOOL ExchangePropStringHelper(CString& strValue, VARTYPE vtProp, void* pvProp, const void* pvDefault);
BOOL ExchangePropDateHelper(CString& strValue, COleDateTime& dt);
void PreformatString(CString& strValue);
void PreformatString(BSTR bstrValue);
public:
static CRuntimeClass* FindRuntimeClass(LPCSTR szClassName);
//}}AFX_CODEJOCK_PRIVATE
public:
DWORD_PTR m_dwData; // User defined 32-bit value.
CObject* m_pOwner; // User defined Owner value.
static LCID m_lcidDateTime; // User regional language
protected:
BOOL m_bLoading; // TRUE if properties are being loaded to the class.
UINT m_nSchema; // Schema of object.
BOOL m_bChildSection; // TRUE if section is child
BOOL m_bEmptySection; // TRUE if EmptySection method was called.
BOOL m_bInitialized; // TRUE if section was initialized.
BOOL m_bUseDefaultOnLoad; // TRUE if default values must be used in load process.
BOOL m_bUseDefaultOnSave; // TRUE if default values must be used in save process.
};
//===========================================================================
// Summary:
// CXTPPropExchangeArchive is CXTPPropExchange derived class.
// The CXTPPropExchangeArchive class allows you to save a complex network of objects in a permanent binary form (usually disk storage) that persists after those objects are deleted. Later you can load the objects from persistent storage, reconstituting them in memory. This process of making data persistent is called 'serialization.'
// Example:
//
// CFile myFile("myfile", CFile::modeCreate | CFile::modeWrite);
//
// // Create a storing archive.
// CArchive arStore(&myFile, CArchive::store);
// CXTPPropExchangeArchive px(arStore);
// PX_String(&px, _T("Caption"), m_strCaption);
//
//===========================================================================
class _XTP_EXT_CLASS CXTPPropExchangeArchive : public CXTPPropExchange
{
DECLARE_DYNAMIC(CXTPPropExchangeArchive)
public:
//-----------------------------------------------------------------------
// Summary:
// Constructs a CXTPPropExchangeArchive object.
// Parameters:
// ar - A reference to the CArchive object that is the ultimate source or destination of the persistent data.
//-----------------------------------------------------------------------
CXTPPropExchangeArchive(CArchive& ar);
//-----------------------------------------------------------------------
// Summary:
// Exchanges a property between a storage medium and the control.
// Parameters:
// pszPropName - The name of the property being exchanged.
// vtProp - A symbol specifying the type of the property being
// exchanged.
// pvProp - A pointer to the property's value.
// pvDefault - Pointer to a default value for the property.
// Remarks:
// Possible values of properties are:
//
// CXTPPropExchangeSection pxTaskPanel(px.GetSection(_T("TaskPanel")));
// m_wndTaskPanel.GetGroups()->DoPropExchange(&pxTaskPanel);
//
//-----------------------------------------------------------------------
CXTPPropExchange* GetSection(LPCTSTR lpszSection);
//-----------------------------------------------------------------------
// Summary:
// Use this member function to write DWORD number to storage
// Parameters:
// dwCount - DWORD number
// See Also: ReadCount
//-----------------------------------------------------------------------
virtual void WriteCount(DWORD dwCount);
//-----------------------------------------------------------------------
// Summary:
// Use this member function to read DWORD number from storage
// Returns:
// DWORD number
// See Also: WriteCount
//-----------------------------------------------------------------------
virtual DWORD ReadCount();
private:
CXTPPropExchangeArchive& operator=(const CXTPPropExchangeArchive &) { ASSERT(FALSE); return *this; }
protected:
//{{AFX_CODEJOCK_PRIVATE
virtual void ExchangeSchemaSafe();
class CSelfArchive : public CArchive
{
friend class CXTPPropExchangeArchive;
};
//}}AFX_CODEJOCK_PRIVATE
CSelfArchive& m_ar; // Contains the underlying CArchive for this CXTPPropExchangeArchive object.
};
//===========================================================================
// Summary:
// CXTPPropExchangeRegistry is CXTPPropExchange derived class.
// The CXTPPropExchangeRegistry class allows you to save a complex network of objects in a system registry that persists after those objects are deleted. Later you can load the objects from persistent storage, reconstituting them in memory. This process of making data persistent is called 'serialization.'
// Example:
//
// HKEY hKey = AfxGetApp()->GetAppRegistryKey();
// CXTPPropExchangeRegistry px(FALSE, hKey, szSection);
// DoPropExchange(&px);
// RegCloseKey(hKey);
//
//===========================================================================
class _XTP_EXT_CLASS CXTPPropExchangeRegistry : public CXTPPropExchange
{
DECLARE_DYNAMIC(CXTPPropExchangeRegistry)
public:
//-----------------------------------------------------------------------
// Summary:
// Constructs CXTPPropExchangeRegistry a object.
// Parameters:
// bLoading - A flag that specifies whether objects will be loaded from or stored.
// hParentKey - Root HKEY
// lpszSection - Points to a null-terminated string that specifies the section containing the entry.
//-----------------------------------------------------------------------
CXTPPropExchangeRegistry(BOOL bLoading, HKEY hParentKey, LPCTSTR lpszSection);
//-------------------------------------------------------------------------
// Summary:
// Destroys a CXTPPropExchangeRegistry object, handles cleanup and de-
// allocation.
//-------------------------------------------------------------------------
~CXTPPropExchangeRegistry();
//-----------------------------------------------------------------------
// Summary:
// Exchanges a property between a storage medium and the control.
// Parameters:
// pszPropName - The name of the property being exchanged.
// vtProp - A symbol specifying the type of the property being
// exchanged.
// pvProp - A pointer to the property's value.
// pvDefault - Pointer to a default value for the property.
// Remarks:
// Possible values of properties are:
//
// CXTPPropExchangeSection pxTaskPanel(px.GetSection(_T("TaskPanel")));
// m_wndTaskPanel.GetGroups()->DoPropExchange(&pxTaskPanel);
//
//-----------------------------------------------------------------------
virtual CXTPPropExchange* GetSection(LPCTSTR lpszSection);
//-------------------------------------------------------------------------
// Summary:
// Call this method to free section information before storing
//-------------------------------------------------------------------------
virtual void EmptySection();
//-----------------------------------------------------------------------
// Summary:
// This method is called before exchange properties.
// Returns:
// TRUE if storage ready to exchange properties.
//-----------------------------------------------------------------------
virtual BOOL OnBeforeExchange();
//-----------------------------------------------------------------------
// Summary:
// Call this method to determine if storage allows exchange plain blob values.
// Returns:
// TRUE if storage allows exchange plain blob values.
//-----------------------------------------------------------------------
virtual BOOL IsAllowBlobValues() const;
private:
LONG DelRegTreeHelper(HKEY hParentKey, LPCTSTR lpszKeyName);
protected:
HKEY m_hSectionKey; // Current registry key
HKEY m_hParentKey; // Parent registry key
CString m_strSectionName; // Section name
BOOL m_bCloseParentKey; // TRUE to automatically close parent key
};
#ifndef _XTP_EXCLUDE_XML
//===========================================================================
// Summary:
// CXTPPropExchangeXMLNode is CXTPPropExchange derived class.
// The CXTPPropExchangeXMLNode class allows you to save a complex network of objects in a XML file that persists after those objects are deleted. Later you can load the objects from persistent storage, reconstituting them in memory. This process of making data persistent is called 'serialization.'
// Example:
//
// CXTPPropExchangeXMLNode px(TRUE, 0, _T("Settings"));
// if (px.LoadFromFile(m_strIniFileName))
// {
// m_wndTaskPanel.GetGroups()->DoPropExchange(&px);
// }
//
//===========================================================================
class _XTP_EXT_CLASS CXTPPropExchangeXMLNode : public CXTPPropExchange
{
class CXMLEnumerator;
DECLARE_DYNAMIC(CXTPPropExchangeXMLNode)
public:
//-----------------------------------------------------------------------
// Summary:
// Constructs CXTPPropExchangeXMLNode a object.
// Parameters:
// bLoading - A flag that specifies whether objects will be loaded from or stored.
// xmlParentNode - Parent node element. Can be NULL.
// lpszSection - Points to a null-terminated string that specifies the section containing the entry.
//-----------------------------------------------------------------------
CXTPPropExchangeXMLNode(BOOL bLoading, CXTPDOMNodePtr xmlParentNode, LPCTSTR lpszSection);
public:
//-----------------------------------------------------------------------
// Summary:
// Determines if XML installed in System (IE 4.0)
//-----------------------------------------------------------------------
static BOOL AFX_CDECL IsXMLSupported();
public:
//-----------------------------------------------------------------------
// Summary:
// Exchanges a property between a storage medium and the control.
// Parameters:
// pszPropName - The name of the property being exchanged.
// vtProp - A symbol specifying the type of the property being
// exchanged.
// pvProp - A pointer to the property's value.
// pvDefault - Pointer to a default value for the property.
// Remarks:
// Possible values of properties are:
//
// CXTPPropExchangeSection pxTaskPanel(px.GetSection(_T("TaskPanel")));
// m_wndTaskPanel.GetGroups()->DoPropExchange(&pxTaskPanel);
//
//-----------------------------------------------------------------------
virtual CXTPPropExchange* GetSection(LPCTSTR lpszSection);
//-------------------------------------------------------------------------
// Summary:
// Call this method to free section information before storing
//-------------------------------------------------------------------------
virtual void EmptySection();
//-----------------------------------------------------------------------
// Summary:
// Call this method to enumerate child sections.
// Parameters:
// lpszSection - child section name.
// Returns:
// Returns an enumerator for child sections.
// Example:
//
// extern CXTPPropExchange* pPX;
//
// CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("Icon")));
// POSITION posEnum = pEnumerator->GetPosition();
//
// while (posEnum)
// {
// CXTPPropExchangeSection secIcon(pEnumerator->GetNext(posEnum));
// }
//
// See Also: CXTPPropExchangeEnumerator
//-----------------------------------------------------------------------
virtual CXTPPropExchangeEnumerator* GetEnumerator(LPCTSTR lpszSection);
public:
//-----------------------------------------------------------------------
// Summary:
// Call this method to check if property entry exists.
// Parameters:
// pszPropName - The name of the property being checked.
//-----------------------------------------------------------------------
BOOL IsPropertyExists(LPCTSTR pszPropName);
//-----------------------------------------------------------------------
// Summary:
// Call this method to check if section exists.
// Parameters:
// lpszSection - The name of the section being checked.
//-----------------------------------------------------------------------
BOOL IsSectionExists(LPCTSTR lpszSection);
// Summary:
// Retrieves section name of the XML node.
// Returns:
// Name of the XML node.
//-----------------------------------------------------------------------
CString GetSectionName();
//-----------------------------------------------------------------------
// Summary:
// Call this method to store data in compact mode (To use node attributes instead nodes)
// Parameters:
// bCompactMode - TRUE to use compact mode (default)
//-----------------------------------------------------------------------
void SetCompactMode(BOOL bCompactMode);
//-----------------------------------------------------------------------
// Summary:
// Loads the contents of an existing file into a XML.
// Parameters:
// lpszFileName - A CString value that contains the name of a file to be loaded into the XML
// Returns:
// TRUE if successful; otherwise 0.
//-----------------------------------------------------------------------
BOOL LoadFromFile(LPCTSTR lpszFileName);
//-----------------------------------------------------------------------
// Summary:
// Loads the contents of string to XML.
// Parameters:
// lpszState - A pointer to a value that contains XML nodes
// bstrState - BSTR value that contains XML nodes
// Returns:
// TRUE if successful; otherwise 0.
//-----------------------------------------------------------------------
BOOL LoadFromString(LPCSTR lpszState);
BOOL LoadFromString(LPCWSTR lpszState);
BOOL LoadFromString(BSTR bstrState); // px.SetEncoding(_T("windows-1251"));
//-----------------------------------------------------------------------
void SetEncoding(LPCTSTR lpszEncoding);
//-----------------------------------------------------------------------
// Summary:
// Call this member to get access to dom xml node for current section
//-----------------------------------------------------------------------
CXTPDOMNodePtr GetSectionNode() const {
return m_xmlSectionNode;
}
//-----------------------------------------------------------------------
// Summary:
// Creates new XML node and put it as Child
// Parameters
// pszSection - New section name
//-----------------------------------------------------------------------
CXTPPropExchangeXMLNode* CreateSection(LPCTSTR pszSection);
public:
CXTPDOMDocumentPtr GetDocumentPtr() const;
CString GetEncoding() const;
protected:
//-----------------------------------------------------------------------
// Summary:
// Retrieves profile node.
// Parameters:
// lpszSection - Section name of profile node
// Returns:
// Profile node.to be used
//-----------------------------------------------------------------------
CXTPDOMNodePtr GetProfileNode(LPCTSTR lpszSection);
//-----------------------------------------------------------------------
// Summary:
// Retrieves entry node which the value is to be written.
// Parameters:
// lpszEntry - Points to a null-terminated string that contains the entry into which the value is to be written.
// bCreate - TRUE to create if doesn't exist;
// Returns:
// Entry node to be used
//-----------------------------------------------------------------------
CXTPDOMNodePtr GetEntryNode(LPCTSTR lpszEntry, BOOL bCreate);
private:
void UpdateDocumentEncoding();
BOOL CreateDocumentInstance();
void FormatFile(LPCTSTR lpszFileName);
void TraceParseError();
CString BstrToString(BSTR bstrVal);
void FormatString(CString& str);
protected:
CXTPDOMDocumentPtr m_xmlDocPtr; // XML Document pointer
CXTPDOMNodePtr m_xmlParentNode; // XML Parent node pointer
CXTPDOMNodePtr m_xmlSectionNode; // XML Section node pointer
CString m_strSectionName; // Section name
CString m_strEncoding; // XML encoding.
BOOL m_bCompactMode; // TRUE to use compact mode.
friend class CXMLEnumerator;
friend class CPropExchangeCtrl;
};
#endif
//===========================================================================
// Summary:
// CXTPPropExchangeIniFile is CXTPPropExchange derived class.
// The CXTPPropExchangeIniFile class allows you to save a complex network of objects in a ini file that persists after those objects are deleted. Later you can load the objects from persistent storage, reconstituting them in memory. This process of making data persistent is called 'serialization.'
// Example:
//
// CXTPPropExchangeIniFile px(TRUE, 0, _T("Settings"));
// if (px.LoadFromFile(m_strIniFileName))
// {
// m_wndTaskPanel.GetGroups()->DoPropExchange(&px);
// }
//
//===========================================================================
class _XTP_EXT_CLASS CXTPPropExchangeIniFile : public CXTPPropExchange
{
DECLARE_DYNAMIC(CXTPPropExchangeIniFile)
public:
//-----------------------------------------------------------------------
// Summary:
// Constructs CXTPPropExchangeIniFile a object.
// Parameters:
// bLoading - A flag that specifies whether objects will be loaded from or stored.
// lpszParentSection - Root section. Can be NULL.
// lpszSection - Points to a null-terminated string that specifies the section containing the entry.
//-----------------------------------------------------------------------
CXTPPropExchangeIniFile(BOOL bLoading, LPCTSTR lpszParentSection, LPCTSTR lpszSection);
//-------------------------------------------------------------------------
// Summary:
// Destroys a CXTPPropExchangeIniFile object, handles cleanup and de-
// allocation.
//-------------------------------------------------------------------------
~CXTPPropExchangeIniFile();
//-----------------------------------------------------------------------
// Summary:
// Exchanges a property between a storage medium and the control.
// Parameters:
// pszPropName - The name of the property being exchanged.
// vtProp - A symbol specifying the type of the property being
// exchanged.
// pvProp - A pointer to the property's value.
// pvDefault - Pointer to a default value for the property.
// Remarks:
// Possible values of properties are:
//
// CXTPPropExchangeSection pxTaskPanel(px.GetSection(_T("TaskPanel")));
// m_wndTaskPanel.GetGroups()->DoPropExchange(&pxTaskPanel);
//
//-----------------------------------------------------------------------
virtual CXTPPropExchange* GetSection(LPCTSTR lpszSection);
//-----------------------------------------------------------------------
// Summary:
// This method is called before exchange properties.
// Returns:
// TRUE if storage ready to exchange properties.
//-----------------------------------------------------------------------
virtual BOOL OnBeforeExchange();
//-----------------------------------------------------------------------
// Summary:
// Saves an ini file to the specified location.
// Parameters:
// strFileName - Destination file name.
//-----------------------------------------------------------------------
void SaveToFile(LPCTSTR strFileName);
//-----------------------------------------------------------------------
// Summary:
// Loads the contents of an existing ini file.
// Parameters:
// lpszFileName - A CString value that contains the name of a file to be loaded
// Returns:
// TRUE if successful; otherwise 0.
//-----------------------------------------------------------------------
BOOL LoadFromFile(LPCTSTR lpszFileName);
//-----------------------------------------------------------------------
// Summary:
// Assign ini file to CXTPPropExchangeIniFile class.
// Parameters:
// lpszFileName - A CString value that contains the name of a file to be loaded/saved
//-----------------------------------------------------------------------
void AssignFile(LPCTSTR lpszFileName);
//-------------------------------------------------------------------------
// Summary:
// Call this method to free section information before storing
//-------------------------------------------------------------------------
virtual void EmptySection();
protected:
CString m_strSectionName; // Section name.
CString m_strFileName; // Temporary file name.
BOOL m_bTempFile; // TRUE if temporary file was created.
};
//===========================================================================
// Summary:
// CXTPPropExchangeSection is standalone class. It is used to delete memory allocated by CXTPPropExchange::GetSection.
// Example:
//
// CXTPPropExchangeSection pxTaskPanel(px.GetSection(_T("TaskPanel")));
//
//===========================================================================
class _XTP_EXT_CLASS CXTPPropExchangeSection
{
public:
//-----------------------------------------------------------------------
// Summary:
// Constructs CXTPPropExchangeSection a object.
// Parameters:
// pPX - pointer to the CXTPPropExchange object that is the ultimate source or destination of the persistent data.
//-----------------------------------------------------------------------
explicit CXTPPropExchangeSection(CXTPPropExchange* pPX)
: m_pPX(pPX) {
}
//-----------------------------------------------------------------------
// Summary:
// Constructs CXTPPropExchangeSection object and automatically assign m_pPX .
// Parameters:
// bLoading - TRUE to load
// lpszSection - Section of registry
//-----------------------------------------------------------------------
CXTPPropExchangeSection(BOOL bLoading, LPCTSTR lpszSection)
{
if (AfxGetApp()->m_pszRegistryKey)
{
m_pPX = new CXTPPropExchangeRegistry(bLoading, 0, lpszSection);
}
else
{
CXTPPropExchangeIniFile *pPX = new CXTPPropExchangeIniFile(bLoading, 0, lpszSection);
pPX->AssignFile(AfxGetApp()->m_pszProfileName);
m_pPX = pPX;
}
}
//-------------------------------------------------------------------------
// Summary:
// Destroys a CXTPPropExchangeSection object, handles cleanup and de-
// allocation.
//-------------------------------------------------------------------------
~CXTPPropExchangeSection() {
if (m_pPX) {
m_pPX->InternalRelease();
}
}
//{{AFX_CODEJOCK_PRIVATE
CXTPPropExchange& operator*() const {
return *m_pPX;
}
CXTPPropExchange *operator->() const {
return m_pPX;
}
CXTPPropExchange *operator&() const {
return m_pPX;
}
//}}AFX_CODEJOCK_PRIVATE
private:
CXTPPropExchange *m_pPX;
};
//{{AFX_CODEJOCK_PRIVATE
class CXTPPropExchangeEnumeratorPtr
{
public:
//-----------------------------------------------------------------------
// Summary:
// Constructs CXTPPropExchangeEnumeratorPtr a object.
// Parameters:
// pPX - pointer to the CXTPPropExchangeEnumerator object that is the ultimate source or destination of the persistent data.
//-----------------------------------------------------------------------
explicit CXTPPropExchangeEnumeratorPtr(CXTPPropExchangeEnumerator* pPX)
: m_pPX(pPX) {
}
//-------------------------------------------------------------------------
// Summary:
// Destroys a CXTPPropExchangeEnumeratorPtr object, handles cleanup and de-
// allocation.
//-------------------------------------------------------------------------
~CXTPPropExchangeEnumeratorPtr() {
delete m_pPX;
}
CXTPPropExchangeEnumerator& operator*() const {
return *m_pPX;
}
CXTPPropExchangeEnumerator *operator->() const {
return m_pPX;
}
CXTPPropExchangeEnumerator *operator&() const {
return m_pPX;
}
private:
CXTPPropExchangeEnumerator *m_pPX;
};
//}}AFX_CODEJOCK_PRIVATE
//---------------------------------------------------------------------------
// Summary:
// Call this function within your class's DoPropExchange member function to serialize or initialize a property of type BYTE.
// The property's value is read from or written to the variable referenced by nValue, as appropriate. If nDefault is specified, it will be used as the property's default value. This value is used if, for any reason, the serialization process fails.
// Parameters:
// pPX - Pointer to the CXTPPropExchange object (typically passed as a parameter to DoPropExchange).
// pszPropName - The name of the property being exchanged.
// nValue - Reference to the variable where the property is stored (typically a member variable of your class).
// nDefault - Default value for the property
// Returns:
// Nonzero if the exchange was successful; 0 if unsuccessful.
//---------------------------------------------------------------------------
_XTP_EXT_CLASS BOOL AFX_CDECL PX_Byte(CXTPPropExchange* pPX, LPCTSTR pszPropName, BYTE& nValue, BYTE nDefault);
//---------------------------------------------------------------------------
// Summary:
// Call this function within your class's DoPropExchange member function to serialize or initialize a property of type short.
// The property's value is read from or written to the variable referenced by sValue, as appropriate. If sDefault is specified, it will be used as the property's default value. This value is used if, for any reason, the serialization process fails.
// Parameters:
// pPX - Pointer to the CXTPPropExchange object (typically passed as a parameter to DoPropExchange).
// pszPropName - The name of the property being exchanged.
// sValue - Reference to the variable where the property is stored (typically a member variable of your class).
// sDefault - Default value for the property
// Returns:
// Nonzero if the exchange was successful; 0 if unsuccessful.
//---------------------------------------------------------------------------
_XTP_EXT_CLASS BOOL AFX_CDECL PX_Short(CXTPPropExchange* pPX, LPCTSTR pszPropName, short& sValue);
_XTP_EXT_CLASS BOOL AFX_CDECL PX_Short(CXTPPropExchange* pPX, LPCTSTR pszPropName, short& sValue, short sDefault);//