diff options
-rw-r--r-- | fxjs/cjx_node.cpp | 10 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_widgetacc.cpp | 20 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_validatedata.cpp | 81 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_validatedata.h | 34 |
4 files changed, 77 insertions, 68 deletions
diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp index 9da9cf0ce1..3d8a6ecdc7 100644 --- a/fxjs/cjx_node.cpp +++ b/fxjs/cjx_node.cpp @@ -1385,13 +1385,13 @@ void CJX_Node::Script_Som_Message(CFXJSE_Value* pValue, WideString wsMessage; switch (iMessageType) { case XFA_SOM_ValidationMessage: - validateData.GetScriptMessageText(wsMessage); + wsMessage = validateData.GetScriptMessageText(); break; case XFA_SOM_FormatMessage: - validateData.GetFormatMessageText(wsMessage); + wsMessage = validateData.GetFormatMessageText(); break; case XFA_SOM_MandatoryMessage: - validateData.GetNullMessageText(wsMessage); + wsMessage = validateData.GetNullMessageText(); break; default: break; @@ -1805,8 +1805,8 @@ void CJX_Node::Script_Som_Mandatory(CFXJSE_Value* pValue, return; } - const XFA_ATTRIBUTEENUMINFO* pInfo = GetAttributeEnumByID( - static_cast<XFA_ATTRIBUTEENUM>(validateData.GetNullTest())); + const XFA_ATTRIBUTEENUMINFO* pInfo = + GetAttributeEnumByID(validateData.GetNullTest()); if (!pInfo) { pValue->SetString(""); return; diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index fcc1e69762..644b1688c0 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -356,10 +356,8 @@ void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_ValidateData validateData, return; WideString wsTitle = pAppProvider->GetAppTitle(); - WideString wsScriptMsg; - validateData.GetScriptMessageText(wsScriptMsg); - int32_t eScriptTest = validateData.GetScriptTest(); - if (eScriptTest == XFA_ATTRIBUTEENUM_Warning) { + WideString wsScriptMsg = validateData.GetScriptMessageText(); + if (validateData.GetScriptTest() == XFA_ATTRIBUTEENUM_Warning) { if (GetNode()->IsUserInteractive()) return; if (wsScriptMsg.IsEmpty()) @@ -386,8 +384,7 @@ int32_t CXFA_WidgetAcc::ProcessFormatTestValidate( bool bVersionFlag) { WideString wsRawValue = GetRawValue(); if (!wsRawValue.IsEmpty()) { - WideString wsPicture; - validateData.GetPicture(wsPicture); + WideString wsPicture = validateData.GetPicture(); if (wsPicture.IsEmpty()) return XFA_EVENTERROR_NotExist; @@ -402,11 +399,9 @@ int32_t CXFA_WidgetAcc::ProcessFormatTestValidate( if (!pAppProvider) return XFA_EVENTERROR_NotExist; - WideString wsFormatMsg; - validateData.GetFormatMessageText(wsFormatMsg); + WideString wsFormatMsg = validateData.GetFormatMessageText(); WideString wsTitle = pAppProvider->GetAppTitle(); - int32_t eFormatTest = validateData.GetFormatTest(); - if (eFormatTest == XFA_ATTRIBUTEENUM_Error) { + if (validateData.GetFormatTest() == XFA_ATTRIBUTEENUM_Error) { if (wsFormatMsg.IsEmpty()) wsFormatMsg = GetValidateMessage(true, bVersionFlag); pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK); @@ -442,9 +437,8 @@ int32_t CXFA_WidgetAcc::ProcessNullTestValidate(CXFA_ValidateData validateData, if (m_bIsNull && (m_bPreNull == m_bIsNull)) return XFA_EVENTERROR_Success; - int32_t eNullTest = validateData.GetNullTest(); - WideString wsNullMsg; - validateData.GetNullMessageText(wsNullMsg); + XFA_ATTRIBUTEENUM eNullTest = validateData.GetNullTest(); + WideString wsNullMsg = validateData.GetNullMessageText(); if (iFlags & 0x01) { int32_t iRet = XFA_EVENTERROR_Success; if (eNullTest != XFA_ATTRIBUTEENUM_Disabled) diff --git a/xfa/fxfa/parser/cxfa_validatedata.cpp b/xfa/fxfa/parser/cxfa_validatedata.cpp index 94c5829288..8b3f539d48 100644 --- a/xfa/fxfa/parser/cxfa_validatedata.cpp +++ b/xfa/fxfa/parser/cxfa_validatedata.cpp @@ -9,35 +9,42 @@ #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/xfa_utils.h" +namespace { + +constexpr wchar_t kFormatTest[] = L"formatTest"; +constexpr wchar_t kNullTest[] = L"nullTest"; +constexpr wchar_t kScriptTest[] = L"scriptTest"; + +} // namespace + CXFA_ValidateData::CXFA_ValidateData(CXFA_Node* pNode) : CXFA_DataData(pNode) {} -int32_t CXFA_ValidateData::GetFormatTest() { +XFA_ATTRIBUTEENUM CXFA_ValidateData::GetFormatTest() const { return m_pNode->JSNode()->GetEnum(XFA_Attribute::FormatTest); } -bool CXFA_ValidateData::SetNullTest(WideString wsValue) { +void CXFA_ValidateData::SetNullTest(const WideString& wsValue) { const XFA_ATTRIBUTEENUMINFO* pInfo = XFA_GetAttributeEnumByName(wsValue.AsStringView()); m_pNode->JSNode()->SetEnum(XFA_Attribute::NullTest, pInfo ? pInfo->eName : XFA_ATTRIBUTEENUM_Disabled, false); - return true; } -int32_t CXFA_ValidateData::GetNullTest() { +XFA_ATTRIBUTEENUM CXFA_ValidateData::GetNullTest() const { return m_pNode->JSNode()->GetEnum(XFA_Attribute::NullTest); } -int32_t CXFA_ValidateData::GetScriptTest() { +XFA_ATTRIBUTEENUM CXFA_ValidateData::GetScriptTest() const { return m_pNode->JSNode()->GetEnum(XFA_Attribute::ScriptTest); } -void CXFA_ValidateData::GetMessageText(WideString& wsMessage, - const WideString& wsMessageType) { +WideString CXFA_ValidateData::GetMessageText( + const WideString& wsMessageType) const { CXFA_Node* pNode = m_pNode->JSNode()->GetProperty(0, XFA_Element::Message, false); if (!pNode) - return; + return L""; for (CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pItemNode; @@ -46,38 +53,45 @@ void CXFA_ValidateData::GetMessageText(WideString& wsMessage, continue; WideString wsName = pItemNode->JSNode()->GetCData(XFA_Attribute::Name); - if (wsName.IsEmpty() || wsName == wsMessageType) { - wsMessage = pItemNode->JSNode()->GetContent(false); - return; - } + if (wsName.IsEmpty() || wsName == wsMessageType) + return pItemNode->JSNode()->GetContent(false); } + return L""; +} + +void CXFA_ValidateData::SetFormatMessageText(const WideString& wsMessage) { + SetMessageText(kFormatTest, wsMessage); } -void CXFA_ValidateData::SetFormatMessageText(WideString wsMessage) { - SetMessageText(wsMessage, L"formatTest"); +WideString CXFA_ValidateData::GetFormatMessageText() const { + return GetMessageText(kFormatTest); } -void CXFA_ValidateData::GetFormatMessageText(WideString& wsMessage) { - GetMessageText(wsMessage, L"formatTest"); +void CXFA_ValidateData::SetNullMessageText(const WideString& wsMessage) { + SetMessageText(kNullTest, wsMessage); } -void CXFA_ValidateData::SetNullMessageText(WideString wsMessage) { - SetMessageText(wsMessage, L"nullTest"); +WideString CXFA_ValidateData::GetNullMessageText() const { + return GetMessageText(kNullTest); } -void CXFA_ValidateData::GetNullMessageText(WideString& wsMessage) { - GetMessageText(wsMessage, L"nullTest"); +WideString CXFA_ValidateData::GetScriptMessageText() const { + return GetMessageText(kScriptTest); } -void CXFA_ValidateData::SetMessageText(WideString& wsMessage, - const WideString& wsMessageType) { +void CXFA_ValidateData::SetScriptMessageText(const WideString& wsMessage) { + SetMessageText(kScriptTest, wsMessage); +} + +void CXFA_ValidateData::SetMessageText(const WideString& wsMessageType, + const WideString& wsMessage) { CXFA_Node* pNode = m_pNode->JSNode()->GetProperty(0, XFA_Element::Message, true); if (!pNode) return; - CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pItemNode; + for (CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); + pItemNode; pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { if (pItemNode->GetElementType() != XFA_Element::Text) continue; @@ -88,6 +102,7 @@ void CXFA_ValidateData::SetMessageText(WideString& wsMessage, return; } } + CXFA_Node* pTextNode = pNode->CreateSamePacketNode(XFA_Element::Text); pNode->InsertChild(pTextNode, nullptr); pTextNode->JSNode()->SetCData(XFA_Attribute::Name, wsMessageType, false, @@ -95,19 +110,13 @@ void CXFA_ValidateData::SetMessageText(WideString& wsMessage, pTextNode->JSNode()->SetContent(wsMessage, wsMessage, false, false, true); } -void CXFA_ValidateData::GetScriptMessageText(WideString& wsMessage) { - GetMessageText(wsMessage, L"scriptTest"); -} - -void CXFA_ValidateData::SetScriptMessageText(WideString wsMessage) { - SetMessageText(wsMessage, L"scriptTest"); -} - -void CXFA_ValidateData::GetPicture(WideString& wsPicture) { - if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Picture, false)) - wsPicture = pNode->JSNode()->GetContent(false); +WideString CXFA_ValidateData::GetPicture() const { + CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Picture, false); + if (pNode) + return pNode->JSNode()->GetContent(false); + return L""; } -CXFA_ScriptData CXFA_ValidateData::GetScriptData() { +CXFA_ScriptData CXFA_ValidateData::GetScriptData() const { return CXFA_ScriptData(m_pNode->GetChild(0, XFA_Element::Script, false)); } diff --git a/xfa/fxfa/parser/cxfa_validatedata.h b/xfa/fxfa/parser/cxfa_validatedata.h index a431cbdf20..e18fcadeaf 100644 --- a/xfa/fxfa/parser/cxfa_validatedata.h +++ b/xfa/fxfa/parser/cxfa_validatedata.h @@ -18,22 +18,28 @@ class CXFA_ValidateData : public CXFA_DataData { public: explicit CXFA_ValidateData(CXFA_Node* pNode); - int32_t GetFormatTest(); - int32_t GetNullTest(); - bool SetNullTest(WideString wsValue); - int32_t GetScriptTest(); - void GetFormatMessageText(WideString& wsMessage); - void SetFormatMessageText(WideString wsMessage); - void GetNullMessageText(WideString& wsMessage); - void SetNullMessageText(WideString wsMessage); - void GetScriptMessageText(WideString& wsMessage); - void SetScriptMessageText(WideString wsMessage); - void GetPicture(WideString& wsPicture); - CXFA_ScriptData GetScriptData(); + XFA_ATTRIBUTEENUM GetFormatTest() const; + WideString GetFormatMessageText() const; + void SetFormatMessageText(const WideString& wsMessage); + + XFA_ATTRIBUTEENUM GetNullTest() const; + void SetNullTest(const WideString& wsValue); + + WideString GetNullMessageText() const; + void SetNullMessageText(const WideString& wsMessage); + + XFA_ATTRIBUTEENUM GetScriptTest() const; + WideString GetScriptMessageText() const; + void SetScriptMessageText(const WideString& wsMessage); + + WideString GetPicture() const; + + CXFA_ScriptData GetScriptData() const; private: - void GetMessageText(WideString& wsMessage, const WideString& wsMessageType); - void SetMessageText(WideString& wsMessage, const WideString& wsMessageType); + WideString GetMessageText(const WideString& wsMessageType) const; + void SetMessageText(const WideString& wsMessageType, + const WideString& wsMessage); }; #endif // XFA_FXFA_PARSER_CXFA_VALIDATEDATA_H_ |