1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef _FXFA_WIDGETVALUE_H 8 #define _FXFA_WIDGETVALUE_H 9 class IFX_Locale; 10 class CFX_Unitime; 11 class CXFA_LocaleMgr; 12 #define XFA_VT_NULL 0 13 #define XFA_VT_BOOLEAN 1 14 #define XFA_VT_INTEGER 2 15 #define XFA_VT_DECIMAL 4 16 #define XFA_VT_FLOAT 8 17 #define XFA_VT_TEXT 16 18 #define XFA_VT_DATE 32 19 #define XFA_VT_TIME 64 20 #define XFA_VT_DATETIME 128 21 class CXFA_LocaleValue { 22 public: 23 CXFA_LocaleValue(); 24 CXFA_LocaleValue(const CXFA_LocaleValue& value); 25 CXFA_LocaleValue(FX_DWORD dwType, CXFA_LocaleMgr* pLocaleMgr); 26 CXFA_LocaleValue(FX_DWORD dwType, 27 const CFX_WideString& wsValue, 28 CXFA_LocaleMgr* pLocaleMgr); 29 CXFA_LocaleValue(FX_DWORD dwType, 30 const CFX_WideString& wsValue, 31 const CFX_WideString& wsFormat, 32 IFX_Locale* pLocale, 33 CXFA_LocaleMgr* pLocaleMgr); 34 ~CXFA_LocaleValue(); 35 CXFA_LocaleValue& operator=(const CXFA_LocaleValue& value); 36 37 FX_BOOL ValidateValue(const CFX_WideString& wsValue, 38 const CFX_WideString& wsPattern, 39 IFX_Locale* pLocale, 40 CFX_WideString* pMatchFormat = NULL); 41 FX_BOOL FormatPatterns(CFX_WideString& wsResult, 42 const CFX_WideString& wsFormat, 43 IFX_Locale* pLocale, 44 XFA_VALUEPICTURE eValueType) const; 45 FX_BOOL FormatSinglePattern(CFX_WideString& wsResult, 46 const CFX_WideString& wsFormat, 47 IFX_Locale* pLocale, 48 XFA_VALUEPICTURE eValueType) const; 49 FX_BOOL ValidateCanonicalValue(const CFX_WideString& wsValue, 50 FX_DWORD dwVType); 51 FX_BOOL ValidateCanonicalDate(const CFX_WideString& wsDate, 52 CFX_Unitime& unDate); 53 FX_BOOL ValidateCanonicalTime(const CFX_WideString& wsTime); 54 FX_BOOL ValidateCanonicalDateTime(const CFX_WideString& wsDateTime); 55 void GetNumbericFormat(CFX_WideString& wsFormat, 56 int32_t nIntLen, 57 int32_t nDecLen, 58 FX_BOOL bSign = TRUE); 59 FX_BOOL ValidateNumericTemp(CFX_WideString& wsNumeric, 60 CFX_WideString& wsFormat, 61 IFX_Locale* pLocale = NULL, 62 int32_t* pos = NULL); 63 64 CFX_WideString GetValue() const; 65 FX_DWORD GetType() const; 66 void SetValue(const CFX_WideString& wsValue, FX_DWORD dwType); 67 CFX_WideString GetText() const; 68 FX_FLOAT GetNum() const; 69 FX_DOUBLE GetDoubleNum() const; 70 CFX_Unitime GetDate() const; 71 CFX_Unitime GetTime() const; 72 CFX_Unitime GetDateTime() const; 73 FX_BOOL SetText(const CFX_WideString& wsText); 74 FX_BOOL SetText(const CFX_WideString& wsText, 75 const CFX_WideString& wsFormat, 76 IFX_Locale* pLocale); 77 FX_BOOL SetNum(FX_FLOAT fNum); 78 FX_BOOL SetNum(const CFX_WideString& wsNum, 79 const CFX_WideString& wsFormat, 80 IFX_Locale* pLocale); 81 FX_BOOL SetDate(const CFX_Unitime& d); 82 FX_BOOL SetDate(const CFX_WideString& wsDate, 83 const CFX_WideString& wsFormat, 84 IFX_Locale* pLocale); 85 FX_BOOL SetTime(const CFX_Unitime& t); 86 FX_BOOL SetTime(const CFX_WideString& wsTime, 87 const CFX_WideString& wsFormat, 88 IFX_Locale* pLocale); 89 FX_BOOL SetDateTime(const CFX_Unitime& dt); 90 FX_BOOL SetDateTime(const CFX_WideString& wsDateTime, 91 const CFX_WideString& wsFormat, 92 IFX_Locale* pLocale); IsNull()93 inline FX_BOOL IsNull() const { return m_dwType == XFA_VT_NULL; } IsEmpty()94 inline FX_BOOL IsEmpty() const { return m_wsValue.IsEmpty(); } IsValid()95 inline FX_BOOL IsValid() const { return m_bValid; } 96 97 protected: 98 FX_BOOL ParsePatternValue(const CFX_WideString& wsValue, 99 const CFX_WideString& wsPattern, 100 IFX_Locale* pLocale); 101 CXFA_LocaleMgr* m_pLocaleMgr; 102 CFX_WideString m_wsValue; 103 FX_DWORD m_dwType; 104 FX_BOOL m_bValid; 105 }; 106 #endif 107