/** * @file XTPChartNumberFormat.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 * */ /** @cond */ #if !defined(__XTPCHARTNUMBERFORMAT_H__) # define __XTPCHARTNUMBERFORMAT_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPChartColor; class CXTPChartDeviceCommand; class CXTPPropExchange; class CXTPChartSeriesPoint; /** * @brief * Format category used by CXTPChartNumberFormat. */ enum XTPChartNumberFormatCategory { xtpChartGeneral, /**< General (100000.123)*/ xtpChartNumber, /**< Number (10,000,000.12)*/ xtpChartCurrency, /**< Currency ($10,000,000.12)*/ xtpChartPercentage, /**< Percent (99.12%)*/ xtpChartScientific /**< Scientific (12.12e+005)*/ }; /** * @brief * DateTime Format category used by CXTPChartNumberFormat. */ enum XTPChartDateTimeFormatCategory { xtpChartDateTimeGeneral, /**< Specifies general date time format */ xtpChartDateTimeLongDate, /**< Specifies long date format */ xtpChartDateTimeShortDate, /**< Specifies short date format */ xtpChartDateTimeLongTime, /**< Specifies long time format */ xtpChartDateTimeShortTime, /**< Specifies short time format */ xtpChartDateTimeMonthAndDay, /**< Specifies month and day format */ xtpChartDateTimeMonthAndYear, /**< Specifies month and year format */ xtpChartDateTimeCustom, /**< Specifies custom date time format */ }; /** * @brief * This class helper is used to format number to string. */ class _XTP_EXT_CLASS CXTPChartNumberFormat : public CXTPChartElement { public: /** * @brief * Constructs a CXTPChartNumberFormat object. * * @param pOwner The owner element of this element. */ CXTPChartNumberFormat(CXTPChartElement* pOwner); /** * @brief * Destroys a CXTPChartNumberFormat object, handles cleanup. */ virtual ~CXTPChartNumberFormat(); public: /** * @return * Returns string representing format pattern. */ CString GetPattern() const; /** * @brief * Call this method to set a new pattern. * * @param lpszPattern new pattern to be set. * * @details * You can specify C++ kind of format pattern: %lf, %g or {V} to use Active Locale. * * Example: * pFormat->SetPattern(_T("Wasted {V} Dollars"); */ void SetPattern(LPCTSTR lpszPattern); /** * @return * Returns format category. */ XTPChartNumberFormatCategory GetCategory() const; /** * @brief * Call this method to specify format category of double value (Number, Currency, Percent, * Scientific, etc.). * * @param nCategory New category to be set. */ void SetCategory(XTPChartNumberFormatCategory nCategory); /** * @return * Returns number of digits after decimal point. * * @details * This method returns -1 if locale specified number should be used. */ int GetDecimalPlaces() const; /** * @brief * Call this method to set number of digits after decimal points. * * @param nDecimalPlaces Non-negative number specified number of digits after decimal points, or * -1 to use locale value. */ void SetDecimalPlaces(int nDecimalPlaces); /** * @return * Returns TRUE if Thousand Separator (, or ' ') should be used. */ BOOL GetUseThousandSeparator() const; /** * @brief * Call this method to use thousand separator for xtpChartNumber category of numbers. * * @param bThousandSeparator TRUE to use thousand separator. */ void SetUseThousandSeparator(BOOL bThousandSeparator); /** * @return * Returns active locale to be used to format numbers. */ LCID GetLocale() const; /** * @brief * Call this method to specify locale that will be used to format numbers. * * @param nLocale New locale to be set. */ void SetLocale(LCID nLocale); /** * @return * Returns used currency symbol for xtpChartCurrency category. */ CString GetCurrencySymbol() const; /** * @brief * Call this method to set a new currency symbol for the xtpChartCurrency category. * * @param lpszCurrencySymbol New currency symbol. Can be empty string to use active locale. */ void SetCurrencySymbol(LPCTSTR lpszCurrencySymbol); XTPChartDateTimeFormatCategory GetDateTimeCategory() const; void SetDateTimeCategory(XTPChartDateTimeFormatCategory category); CString GetDateTimeFormat() const; void SetDateTimeFormat(LPCTSTR lpszDateTimeFormat); public: /** * @brief * Determines which locale is to be used as an active locale: current user locale * or resource file locale. * * @return TRUE if a resource file locale is used as an active locale, FALSE otherwise. * * @see * SetUseResourceFileLocale, CXTPResourceManager::GetResourcesLangID, * GetActiveLCID, LOCALE_USER_DEFAULT */ static BOOL AFX_CDECL IsUseResourceFileLocale(); /** * @brief * Used to set which locale is to be used as an the active locale: current user locale * or resource file locale. * * @param bUseResourceFileLocale If TRUE, the resource file locale will be used, * if FALSE, the current user locale will be used. * * @return If TRUE, the resource file locale will be used, if FALSE, the current user locale * will be used * @see * IsUseResourceFileLocale, CXTPResourceManager::GetResourcesLangID, * GetActiveLCID, LOCALE_USER_DEFAULT */ static void AFX_CDECL SetUseResourceFileLocale(BOOL bUseResourceFileLocale); /** * @brief * Returns active locale ID (current user locale or resource file locale). * * @return LOCALE_USER_DEFAULT or resource file locale ID. * * @see * IsUseResourceFileLocale, SetUseResourceFileLocale, * CXTPResourceManager::GetResourcesLangID, LOCALE_USER_DEFAULT */ static LCID AFX_CDECL GetActiveLCID(); /** * @brief * Call this method to format number to string. * * @param dValue Value to format. * @return Returns number to string */ virtual CString FormatNumber(double dValue) const; /** * @brief * Call this method to format string. * * @param lpszValue Value to format. * @return Returns formatted string */ virtual CString FormatString(LPCTSTR lpszValue) const; /** * @brief * Call this method to format COleDateTime value to string * * @param dt Value to format. * @return Returns COleDateTime value as a string */ virtual CString FormatDate(COleDateTime& dt) const; /** * @brief * Call this method to format value to string. * * @param pSeriesPoint Series Point. * @param dValue Value to format. * @return Returns value as a string */ virtual CString FormatPoint(CXTPChartSeriesPoint* pSeriesPoint, double dValue) const; public: /** * @brief * Call this member function to store/Load the properties of chart boundary * object using the specified data object. * * @param pPX Source or destination CXTPPropExchange data object reference. * * @details * This member function is used to store property data to or load property * data from storage. */ void DoPropExchange(CXTPPropExchange* pPX); protected: CString DoubleToString(double dMark) const; void CreateNumberFormat(); void CreateCurrencyFormat(); void CreateDateTimeFormat(); int GetLocaleLong(LCTYPE LCType) const; CString GetLocaleString(LCTYPE LCType, int nMaxLength); protected: CString m_strPattern; /**< Format pattern*/ XTPChartNumberFormatCategory m_nCategory; /**< Format category*/ int m_nDecimalPlaces; /**< Number of digits after decimal places. -1 to use default*/ BOOL m_bUseThousandSeparator; /**< TRUE to separate thousands.*/ LCID m_nLocale; /**< Current locale*/ CString m_strCurrencySymbol; /**< Currency symbol*/ XTPChartDateTimeFormatCategory m_nDateTimeCategory; NUMBERFMT m_fmtNumber; CURRENCYFMT m_fmtCurrency; CString m_strDateTimeFormat; CString m_strActiveDateTimeFormat; # ifdef _XTP_ACTIVEX public: /** @cond */ DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPChartNumberFormat); afx_msg BSTR OleGetPattern(); afx_msg void OleSetPattern(LPCTSTR lpszValue); afx_msg BSTR OleGetCurrencySymbol(); afx_msg void OleSetCurrencySymbol(LPCTSTR lpszValue); afx_msg BSTR OleGetDateDateTimeFormat(); /** @endcond */ # endif private: static BOOL s_bUseResourceFileLocale; }; AFX_INLINE CString CXTPChartNumberFormat::GetPattern() const { return m_strPattern; } AFX_INLINE void CXTPChartNumberFormat::SetPattern(LPCTSTR lpszPattern) { m_strPattern = lpszPattern; OnChartChanged(); } AFX_INLINE XTPChartNumberFormatCategory CXTPChartNumberFormat::GetCategory() const { return m_nCategory; } AFX_INLINE void CXTPChartNumberFormat::SetCategory(XTPChartNumberFormatCategory nCategory) { m_nCategory = nCategory; OnChartChanged(); } AFX_INLINE int CXTPChartNumberFormat::GetDecimalPlaces() const { return m_nDecimalPlaces; } AFX_INLINE void CXTPChartNumberFormat::SetDecimalPlaces(int nDecimalPlaces) { m_nDecimalPlaces = nDecimalPlaces; CreateNumberFormat(); CreateCurrencyFormat(); OnChartChanged(); } AFX_INLINE BOOL CXTPChartNumberFormat::GetUseThousandSeparator() const { return m_bUseThousandSeparator; } AFX_INLINE void CXTPChartNumberFormat::SetUseThousandSeparator(BOOL bThousandSeparator) { m_bUseThousandSeparator = bThousandSeparator; CreateNumberFormat(); CreateCurrencyFormat(); OnChartChanged(); } AFX_INLINE LCID CXTPChartNumberFormat::GetLocale() const { return m_nLocale; } AFX_INLINE void CXTPChartNumberFormat::SetLocale(LCID nLocale) { m_nLocale = nLocale; CreateNumberFormat(); CreateCurrencyFormat(); CreateDateTimeFormat(); OnChartChanged(); } AFX_INLINE void CXTPChartNumberFormat::SetCurrencySymbol(LPCTSTR lpszCurrencySymbol) { m_strCurrencySymbol = lpszCurrencySymbol; CreateCurrencyFormat(); OnChartChanged(); } AFX_INLINE CString CXTPChartNumberFormat::GetCurrencySymbol() const { return m_strCurrencySymbol; } AFX_INLINE void CXTPChartNumberFormat::SetDateTimeCategory(XTPChartDateTimeFormatCategory category) { m_nDateTimeCategory = category; CreateDateTimeFormat(); OnChartChanged(); } AFX_INLINE XTPChartDateTimeFormatCategory CXTPChartNumberFormat::GetDateTimeCategory() const { return m_nDateTimeCategory; } AFX_INLINE CString CXTPChartNumberFormat::GetDateTimeFormat() const { return m_strDateTimeFormat; } AFX_INLINE void CXTPChartNumberFormat::SetDateTimeFormat(LPCTSTR lpszDateTimeFormat) { m_strDateTimeFormat = lpszDateTimeFormat; CreateDateTimeFormat(); OnChartChanged(); } /** @cond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif //#if !defined(__XTPCHARTNUMBERFORMAT_H__) /** @endcond */