From f1494f0f8a202b5a5437c987ba1509688071981c Mon Sep 17 00:00:00 2001 From: dsinclair Date: Thu, 7 Jul 2016 12:56:17 -0700 Subject: Cleanup xfa_document_datamerge files This CL moves the static methods into an anonymous namespace, removes default parameters and moves some other methods only used by this file into the anonymous namespace. Review-Url: https://codereview.chromium.org/2122373003 --- BUILD.gn | 4 +- xfa.gyp | 2 - .../parser/xfa_document_datadescription_imp.cpp | 121 --- xfa/fxfa/parser/xfa_document_datadescription_imp.h | 18 - xfa/fxfa/parser/xfa_document_datamerger_imp.cpp | 1115 +++++++++++--------- xfa/fxfa/parser/xfa_document_datamerger_imp.h | 11 +- xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp | 3 +- 7 files changed, 625 insertions(+), 649 deletions(-) delete mode 100644 xfa/fxfa/parser/xfa_document_datadescription_imp.cpp delete mode 100644 xfa/fxfa/parser/xfa_document_datadescription_imp.h diff --git a/BUILD.gn b/BUILD.gn index b0f89690a3..6fe33bb23c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1363,19 +1363,17 @@ if (pdf_enable_xfa) { "xfa/fxfa/parser/cxfa_widgetdata.cpp", "xfa/fxfa/parser/cxfa_widgetdata.h", "xfa/fxfa/parser/xfa_basic_data.cpp", + "xfa/fxfa/parser/xfa_basic_data.h", "xfa/fxfa/parser/xfa_basic_data_attributes.cpp", "xfa/fxfa/parser/xfa_basic_data_element_attributes.cpp", "xfa/fxfa/parser/xfa_basic_data_element_properties.cpp", "xfa/fxfa/parser/xfa_basic_data_element_script.cpp", "xfa/fxfa/parser/xfa_basic_data_enum.cpp", "xfa/fxfa/parser/xfa_basic_data_packets.cpp", - "xfa/fxfa/parser/xfa_basic_data.h", "xfa/fxfa/parser/xfa_basic_imp.cpp", "xfa/fxfa/parser/xfa_basic_imp.h", "xfa/fxfa/parser/xfa_doclayout.h", "xfa/fxfa/parser/xfa_document.h", - "xfa/fxfa/parser/xfa_document_datadescription_imp.cpp", - "xfa/fxfa/parser/xfa_document_datadescription_imp.h", "xfa/fxfa/parser/xfa_document_datamerger_imp.cpp", "xfa/fxfa/parser/xfa_document_datamerger_imp.h", "xfa/fxfa/parser/xfa_document_imp.cpp", diff --git a/xfa.gyp b/xfa.gyp index 4e6930c2b2..60e120a40a 100644 --- a/xfa.gyp +++ b/xfa.gyp @@ -524,8 +524,6 @@ "xfa/fxfa/parser/xfa_basic_imp.h", "xfa/fxfa/parser/xfa_doclayout.h", "xfa/fxfa/parser/xfa_document.h", - "xfa/fxfa/parser/xfa_document_datadescription_imp.cpp", - "xfa/fxfa/parser/xfa_document_datadescription_imp.h", "xfa/fxfa/parser/xfa_document_datamerger_imp.cpp", "xfa/fxfa/parser/xfa_document_datamerger_imp.h", "xfa/fxfa/parser/xfa_document_imp.cpp", diff --git a/xfa/fxfa/parser/xfa_document_datadescription_imp.cpp b/xfa/fxfa/parser/xfa_document_datadescription_imp.cpp deleted file mode 100644 index bcd6a874b3..0000000000 --- a/xfa/fxfa/parser/xfa_document_datadescription_imp.cpp +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/parser/xfa_doclayout.h" -#include "xfa/fxfa/parser/xfa_document.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_parser.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_utils.h" - -class CXFA_TraverseStrategy_DDGroup { - public: - static inline CXFA_Node* GetFirstChild(CXFA_Node* pDDGroupNode) { - return pDDGroupNode->GetFirstChildByName(XFA_HASHCODE_Group); - } - static inline CXFA_Node* GetNextSibling(CXFA_Node* pDDGroupNode) { - return pDDGroupNode->GetNextSameNameSibling(XFA_HASHCODE_Group); - } - static inline CXFA_Node* GetParent(CXFA_Node* pDDGroupNode) { - return pDDGroupNode->GetNodeItem(XFA_NODEITEM_Parent); - } -}; -void XFA_DataDescription_UpdateDataRelation(CXFA_Node* pDataNode, - CXFA_Node* pDataDescriptionNode) { - ASSERT(pDataDescriptionNode); - for (CXFA_Node* pDataChild = pDataNode->GetNodeItem(XFA_NODEITEM_FirstChild); - pDataChild; - pDataChild = pDataChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { - uint32_t dwNameHash = pDataChild->GetNameHash(); - if (!dwNameHash) - continue; - - CXFA_NodeIteratorTemplate - sIterator(pDataDescriptionNode); - for (CXFA_Node* pDDGroupNode = sIterator.GetCurrent(); pDDGroupNode; - pDDGroupNode = sIterator.MoveToNext()) { - if (pDDGroupNode != pDataDescriptionNode) { - if (pDDGroupNode->GetElementType() != XFA_Element::DataGroup) - continue; - - CFX_WideString wsNamespace; - if (!pDDGroupNode->TryNamespace(wsNamespace) || - wsNamespace != FX_WSTRC(L"http://ns.adobe.com/data-description/")) { - continue; - } - } - CXFA_Node* pDDNode = pDDGroupNode->GetFirstChildByName(dwNameHash); - if (!pDDNode) - continue; - if (pDDNode->GetElementType() != pDataChild->GetElementType()) - break; - - pDataChild->SetDataDescriptionNode(pDDNode); - XFA_DataDescription_UpdateDataRelation(pDataChild, pDDNode); - break; - } - } -} -CXFA_Node* XFA_DataDescription_MaybeCreateDataNode( - CXFA_Document* pDocument, - CXFA_Node* pDataParent, - XFA_Element eNodeType, - const CFX_WideString& wsName) { - if (!pDataParent) { - return nullptr; - } - CXFA_Node* pParentDDNode = pDataParent->GetDataDescriptionNode(); - if (!pParentDDNode) { - CXFA_Node* pDataNode = - pDocument->CreateNode(XFA_XDPPACKET_Datasets, eNodeType); - ASSERT(pDataNode); - pDataNode->SetCData(XFA_ATTRIBUTE_Name, wsName); - pDataNode->CreateXMLMappingNode(); - pDataParent->InsertChild(pDataNode); - pDataNode->SetFlag(XFA_NodeFlag_Initialized, false); - return pDataNode; - } else { - CXFA_NodeIteratorTemplate - sIterator(pParentDDNode); - for (CXFA_Node* pDDGroupNode = sIterator.GetCurrent(); pDDGroupNode; - pDDGroupNode = sIterator.MoveToNext()) { - if (pDDGroupNode != pParentDDNode) { - if (pDDGroupNode->GetElementType() != XFA_Element::DataGroup) { - continue; - } - CFX_WideString wsNamespace; - if (!pDDGroupNode->TryNamespace(wsNamespace) || - wsNamespace != FX_WSTRC(L"http://ns.adobe.com/data-description/")) { - continue; - } - } - CXFA_Node* pDDNode = - pDDGroupNode->GetFirstChildByName(wsName.AsStringC()); - if (!pDDNode) { - continue; - } - if (pDDNode->GetElementType() != eNodeType) { - break; - } - CXFA_Node* pDataNode = - pDocument->CreateNode(XFA_XDPPACKET_Datasets, eNodeType); - ASSERT(pDataNode); - pDataNode->SetCData(XFA_ATTRIBUTE_Name, wsName); - pDataNode->CreateXMLMappingNode(); - if (eNodeType == XFA_Element::DataValue && - pDDNode->GetEnum(XFA_ATTRIBUTE_Contains) == - XFA_ATTRIBUTEENUM_MetaData) { - pDataNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_MetaData); - } - pDataParent->InsertChild(pDataNode); - pDataNode->SetDataDescriptionNode(pDDNode); - pDataNode->SetFlag(XFA_NodeFlag_Initialized, false); - return pDataNode; - } - return nullptr; - } -} diff --git a/xfa/fxfa/parser/xfa_document_datadescription_imp.h b/xfa/fxfa/parser/xfa_document_datadescription_imp.h deleted file mode 100644 index f0c905c85d..0000000000 --- a/xfa/fxfa/parser/xfa_document_datadescription_imp.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_PARSER_XFA_DOCUMENT_DATADESCRIPTION_IMP_H_ -#define XFA_FXFA_PARSER_XFA_DOCUMENT_DATADESCRIPTION_IMP_H_ - -void XFA_DataDescription_UpdateDataRelation(CXFA_Node* pDataNode, - CXFA_Node* pDataDescriptionNode); -CXFA_Node* XFA_DataDescription_MaybeCreateDataNode( - CXFA_Document* pDocument, - CXFA_Node* pDataParent, - XFA_Element eNodeType, - const CFX_WideString& wsName); - -#endif // XFA_FXFA_PARSER_XFA_DOCUMENT_DATADESCRIPTION_IMP_H_ diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp index 94aa07406b..4374b7c43d 100644 --- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp @@ -12,7 +12,6 @@ #include "xfa/fxfa/parser/xfa_basic_imp.h" #include "xfa/fxfa/parser/xfa_doclayout.h" #include "xfa/fxfa/parser/xfa_document.h" -#include "xfa/fxfa/parser/xfa_document_datadescription_imp.h" #include "xfa/fxfa/parser/xfa_document_layout_imp.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" @@ -22,48 +21,62 @@ #include "xfa/fxfa/parser/xfa_script_imp.h" #include "xfa/fxfa/parser/xfa_utils.h" -static FX_BOOL XFA_GetOccurInfo(CXFA_Node* pOccurNode, - int32_t& iMin, - int32_t& iMax, - int32_t& iInit) { - if (!pOccurNode) { - return FALSE; +namespace { + +class CXFA_TraverseStrategy_DDGroup { + public: + static CXFA_Node* GetFirstChild(CXFA_Node* pDDGroupNode) { + return pDDGroupNode->GetFirstChildByName(XFA_HASHCODE_Group); } - CXFA_Occur occur(pOccurNode); - return occur.GetOccurInfo(iMin, iMax, iInit); -} -struct XFA_DataMerge_RecurseRecord { + static CXFA_Node* GetNextSibling(CXFA_Node* pDDGroupNode) { + return pDDGroupNode->GetNextSameNameSibling(XFA_HASHCODE_Group); + } + static CXFA_Node* GetParent(CXFA_Node* pDDGroupNode) { + return pDDGroupNode->GetNodeItem(XFA_NODEITEM_Parent); + } +}; + +struct RecurseRecord { CXFA_Node* pTemplateChild; CXFA_Node* pDataChild; }; -static CXFA_Node* XFA_DataMerge_FormValueNode_CreateChild( - CXFA_Node* pValueNode, - XFA_Element iType = XFA_Element::Unknown) { + +FX_BOOL GetOccurInfo(CXFA_Node* pOccurNode, + int32_t& iMin, + int32_t& iMax, + int32_t& iInit) { + if (!pOccurNode) + return FALSE; + + CXFA_Occur occur(pOccurNode); + return occur.GetOccurInfo(iMin, iMax, iInit); +} + +CXFA_Node* FormValueNode_CreateChild(CXFA_Node* pValueNode, XFA_Element iType) { CXFA_Node* pChildNode = pValueNode->GetNodeItem(XFA_NODEITEM_FirstChild); if (!pChildNode) { - if (iType == XFA_Element::Unknown) { + if (iType == XFA_Element::Unknown) return FALSE; - } pChildNode = pValueNode->GetProperty(0, iType); } return pChildNode; } -static void XFA_DataMerge_FormValueNode_MatchNoneCreateChild( - CXFA_Node* pFormNode) { + +void FormValueNode_MatchNoneCreateChild(CXFA_Node* pFormNode) { CXFA_WidgetData* pWidgetData = pFormNode->GetWidgetData(); ASSERT(pWidgetData); pWidgetData->GetUIType(); } -static FX_BOOL XFA_DataMerge_FormValueNode_SetChildContent( + +FX_BOOL FormValueNode_SetChildContent( CXFA_Node* pValueNode, const CFX_WideString& wsContent, XFA_Element iType = XFA_Element::Unknown) { - if (!pValueNode) { + if (!pValueNode) return FALSE; - } + ASSERT(pValueNode->GetPacketID() == XFA_XDPPACKET_Form); - CXFA_Node* pChildNode = - XFA_DataMerge_FormValueNode_CreateChild(pValueNode, iType); + CXFA_Node* pChildNode = FormValueNode_CreateChild(pValueNode, iType); if (!pChildNode) return FALSE; @@ -77,37 +90,39 @@ static FX_BOOL XFA_DataMerge_FormValueNode_SetChildContent( CFX_WideString wsContentType; pChildNode->GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE); - if (wsContentType == FX_WSTRC(L"text/html")) { + if (wsContentType == FX_WSTRC(L"text/html")) element = XFA_Element::SharpxHTML; - } else if (wsContentType == FX_WSTRC(L"text/xml")) { + else if (wsContentType == FX_WSTRC(L"text/xml")) element = XFA_Element::Sharpxml; - } } pContentRawDataNode = pChildNode->CreateSamePacketNode(element); pChildNode->InsertChild(pContentRawDataNode); } pContentRawDataNode->SetCData(XFA_ATTRIBUTE_Value, wsContent); - } break; + break; + } case XFA_ObjectType::NodeC: case XFA_ObjectType::TextNode: case XFA_ObjectType::NodeV: { pChildNode->SetCData(XFA_ATTRIBUTE_Value, wsContent); - } break; + break; + } default: ASSERT(FALSE); break; } return TRUE; } -static void XFA_DataMerge_CreateDataBinding(CXFA_Node* pFormNode, - CXFA_Node* pDataNode, - FX_BOOL bDataToForm = TRUE) { + +void CreateDataBinding(CXFA_Node* pFormNode, + CXFA_Node* pDataNode, + FX_BOOL bDataToForm) { pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, pDataNode); pDataNode->AddBindItem(pFormNode); XFA_Element eType = pFormNode->GetElementType(); - if (eType != XFA_Element::Field && eType != XFA_Element::ExclGroup) { + if (eType != XFA_Element::Field && eType != XFA_Element::ExclGroup) return; - } + CXFA_WidgetData* pWidgetData = pFormNode->GetWidgetData(); ASSERT(pWidgetData); XFA_Element eUIType = pWidgetData->GetUIType(); @@ -131,10 +146,11 @@ static void XFA_DataMerge_CreateDataBinding(CXFA_Node* pFormNode, pWidgetData->GetFormatDataValue(wsValue, wsFormatedValue); pDataNode->SetAttributeValue(wsValue, wsFormatedValue); pDataNode->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType); - if (!wsHref.IsEmpty()) { + if (!wsHref.IsEmpty()) pXMLDataElement->SetString(L"href", wsHref); - } - } break; + + break; + } case XFA_Element::ChoiceList: defValue.GetChildValueContent(wsValue); if (pWidgetData->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { @@ -163,9 +179,9 @@ static void XFA_DataMerge_CreateDataBinding(CXFA_Node* pFormNode, break; case XFA_Element::CheckButton: defValue.GetChildValueContent(wsValue); - if (wsValue.IsEmpty()) { + if (wsValue.IsEmpty()) break; - } + pWidgetData->GetFormatDataValue(wsValue, wsFormatedValue); pDataNode->SetAttributeValue(wsValue, wsFormatedValue); break; @@ -173,26 +189,26 @@ static void XFA_DataMerge_CreateDataBinding(CXFA_Node* pFormNode, CXFA_Node* pChecked = nullptr; CXFA_Node* pChild = pFormNode->GetNodeItem(XFA_NODEITEM_FirstChild); for (; pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pChild->GetElementType() != XFA_Element::Field) { + if (pChild->GetElementType() != XFA_Element::Field) continue; - } + CXFA_Node* pValue = pChild->GetChild(0, XFA_Element::Value); - if (!pValue) { + if (!pValue) continue; - } + CXFA_Value valueChild(pValue); valueChild.GetChildValueContent(wsValue); - if (wsValue.IsEmpty()) { + if (wsValue.IsEmpty()) continue; - } + CXFA_Node* pItems = pChild->GetChild(0, XFA_Element::Items); - if (!pItems) { + if (!pItems) continue; - } + CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); - if (!pText) { + if (!pText) continue; - } + CFX_WideString wsContent; if (pText->TryContent(wsContent) && (wsContent == wsValue)) { pChecked = pChild; @@ -202,161 +218,161 @@ static void XFA_DataMerge_CreateDataBinding(CXFA_Node* pFormNode, break; } } - if (!pChecked) { + if (!pChecked) break; - } + pChild = pFormNode->GetNodeItem(XFA_NODEITEM_FirstChild); for (; pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pChild == pChecked) { + if (pChild == pChecked) continue; - } - if (pChild->GetElementType() != XFA_Element::Field) { + if (pChild->GetElementType() != XFA_Element::Field) continue; - } + CXFA_Node* pValue = pChild->GetProperty(0, XFA_Element::Value); CXFA_Node* pItems = pChild->GetChild(0, XFA_Element::Items); CXFA_Node* pText = pItems ? pItems->GetNodeItem(XFA_NODEITEM_FirstChild) : nullptr; - if (pText) { + if (pText) pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); - } + CFX_WideString wsContent; - if (pText) { + if (pText) pText->TryContent(wsContent); - } - XFA_DataMerge_FormValueNode_SetChildContent(pValue, wsContent, - XFA_Element::Text); + + FormValueNode_SetChildContent(pValue, wsContent, XFA_Element::Text); } - } break; + break; + } case XFA_Element::NumericEdit: { defValue.GetChildValueContent(wsValue); - if (wsValue.IsEmpty()) { + if (wsValue.IsEmpty()) break; - } + CFX_WideString wsOutput; pWidgetData->NormalizeNumStr(wsValue, wsOutput); wsValue = wsOutput; pWidgetData->GetFormatDataValue(wsValue, wsFormatedValue); pDataNode->SetAttributeValue(wsValue, wsFormatedValue); CXFA_Node* pValue = pFormNode->GetProperty(0, XFA_Element::Value); - XFA_DataMerge_FormValueNode_SetChildContent(pValue, wsValue, - XFA_Element::Float); - } break; + FormValueNode_SetChildContent(pValue, wsValue, XFA_Element::Float); + break; + } default: defValue.GetChildValueContent(wsValue); - if (wsValue.IsEmpty()) { + if (wsValue.IsEmpty()) break; - } + pWidgetData->GetFormatDataValue(wsValue, wsFormatedValue); pDataNode->SetAttributeValue(wsValue, wsFormatedValue); break; } - } else { - CFX_WideString wsXMLValue; - pDataNode->TryContent(wsXMLValue); - CFX_WideString wsNormailizeValue; - pWidgetData->GetNormalizeDataValue(wsXMLValue, wsNormailizeValue); - pDataNode->SetAttributeValue(wsNormailizeValue, wsXMLValue); - switch (eUIType) { - case XFA_Element::ImageEdit: { - XFA_DataMerge_FormValueNode_SetChildContent( - defValue.GetNode(), wsNormailizeValue, XFA_Element::Image); - CXFA_Image image = defValue.GetImage(); - if (image) { - CFDE_XMLElement* pXMLDataElement = - static_cast(pDataNode->GetXMLMappingNode()); - ASSERT(pXMLDataElement); - CFX_WideString wsContentType; - CFX_WideString wsHref; - pXMLDataElement->GetString(L"xfa:contentType", wsContentType); - if (!wsContentType.IsEmpty()) { - pDataNode->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType); - image.SetContentType(wsContentType); - } - pXMLDataElement->GetString(L"href", wsHref); - if (!wsHref.IsEmpty()) { - image.SetHref(wsHref); - } + return; + } + + CFX_WideString wsXMLValue; + pDataNode->TryContent(wsXMLValue); + CFX_WideString wsNormalizeValue; + pWidgetData->GetNormalizeDataValue(wsXMLValue, wsNormalizeValue); + pDataNode->SetAttributeValue(wsNormalizeValue, wsXMLValue); + switch (eUIType) { + case XFA_Element::ImageEdit: { + FormValueNode_SetChildContent(defValue.GetNode(), wsNormalizeValue, + XFA_Element::Image); + CXFA_Image image = defValue.GetImage(); + if (image) { + CFDE_XMLElement* pXMLDataElement = + static_cast(pDataNode->GetXMLMappingNode()); + ASSERT(pXMLDataElement); + CFX_WideString wsContentType; + CFX_WideString wsHref; + pXMLDataElement->GetString(L"xfa:contentType", wsContentType); + if (!wsContentType.IsEmpty()) { + pDataNode->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType); + image.SetContentType(wsContentType); } - } break; - case XFA_Element::ChoiceList: - if (pWidgetData->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { - CXFA_NodeArray items; - pDataNode->GetNodeList(items); - int32_t iCounts = items.GetSize(); - if (iCounts > 0) { - wsNormailizeValue.clear(); - CFX_WideString wsItem; - for (int32_t i = 0; i < iCounts; i++) { - items[i]->TryContent(wsItem); - wsItem = (iCounts == 1) ? wsItem : wsItem + FX_WSTRC(L"\n"); - wsNormailizeValue += wsItem; - } - CXFA_ExData exData = defValue.GetExData(); - ASSERT(exData); - exData.SetContentType(iCounts == 1 ? L"text/plain" : L"text/xml"); + pXMLDataElement->GetString(L"href", wsHref); + if (!wsHref.IsEmpty()) + image.SetHref(wsHref); + } + break; + } + case XFA_Element::ChoiceList: + if (pWidgetData->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { + CXFA_NodeArray items; + pDataNode->GetNodeList(items); + int32_t iCounts = items.GetSize(); + if (iCounts > 0) { + wsNormalizeValue.clear(); + CFX_WideString wsItem; + for (int32_t i = 0; i < iCounts; i++) { + items[i]->TryContent(wsItem); + wsItem = (iCounts == 1) ? wsItem : wsItem + FX_WSTRC(L"\n"); + wsNormalizeValue += wsItem; } - XFA_DataMerge_FormValueNode_SetChildContent( - defValue.GetNode(), wsNormailizeValue, XFA_Element::ExData); - } else { - XFA_DataMerge_FormValueNode_SetChildContent( - defValue.GetNode(), wsNormailizeValue, XFA_Element::Text); - } - break; - case XFA_Element::CheckButton: - XFA_DataMerge_FormValueNode_SetChildContent( - defValue.GetNode(), wsNormailizeValue, XFA_Element::Text); - break; - case XFA_Element::ExclGroup: { - pWidgetData->SetSelectedMemberByValue(wsNormailizeValue.AsStringC(), - false, FALSE, FALSE); - } break; - case XFA_Element::DateTimeEdit: - XFA_DataMerge_FormValueNode_SetChildContent( - defValue.GetNode(), wsNormailizeValue, XFA_Element::DateTime); - break; - case XFA_Element::NumericEdit: { - CFX_WideString wsPicture; - pWidgetData->GetPictureContent(wsPicture, XFA_VALUEPICTURE_DataBind); - if (wsPicture.IsEmpty()) { - CFX_WideString wsOutput; - pWidgetData->NormalizeNumStr(wsNormailizeValue, wsOutput); - wsNormailizeValue = wsOutput; + CXFA_ExData exData = defValue.GetExData(); + ASSERT(exData); + exData.SetContentType(iCounts == 1 ? L"text/plain" : L"text/xml"); } - XFA_DataMerge_FormValueNode_SetChildContent( - defValue.GetNode(), wsNormailizeValue, XFA_Element::Float); - } break; - case XFA_Element::Barcode: - case XFA_Element::Button: - case XFA_Element::PasswordEdit: - case XFA_Element::Signature: - case XFA_Element::TextEdit: - default: - XFA_DataMerge_FormValueNode_SetChildContent( - defValue.GetNode(), wsNormailizeValue, XFA_Element::Text); - break; + FormValueNode_SetChildContent(defValue.GetNode(), wsNormalizeValue, + XFA_Element::ExData); + } else { + FormValueNode_SetChildContent(defValue.GetNode(), wsNormalizeValue, + XFA_Element::Text); + } + break; + case XFA_Element::CheckButton: + FormValueNode_SetChildContent(defValue.GetNode(), wsNormalizeValue, + XFA_Element::Text); + break; + case XFA_Element::ExclGroup: { + pWidgetData->SetSelectedMemberByValue(wsNormalizeValue.AsStringC(), false, + FALSE, FALSE); + break; + } + case XFA_Element::DateTimeEdit: + FormValueNode_SetChildContent(defValue.GetNode(), wsNormalizeValue, + XFA_Element::DateTime); + break; + case XFA_Element::NumericEdit: { + CFX_WideString wsPicture; + pWidgetData->GetPictureContent(wsPicture, XFA_VALUEPICTURE_DataBind); + if (wsPicture.IsEmpty()) { + CFX_WideString wsOutput; + pWidgetData->NormalizeNumStr(wsNormalizeValue, wsOutput); + wsNormalizeValue = wsOutput; + } + FormValueNode_SetChildContent(defValue.GetNode(), wsNormalizeValue, + XFA_Element::Float); + break; } + case XFA_Element::Barcode: + case XFA_Element::Button: + case XFA_Element::PasswordEdit: + case XFA_Element::Signature: + case XFA_Element::TextEdit: + default: + FormValueNode_SetChildContent(defValue.GetNode(), wsNormalizeValue, + XFA_Element::Text); + break; } } -static CXFA_Node* XFA_DataMerge_GetGlobalBinding(CXFA_Document* pDocument, - uint32_t dwNameHash) { + +CXFA_Node* GetGlobalBinding(CXFA_Document* pDocument, uint32_t dwNameHash) { CXFA_Node* pNode = nullptr; pDocument->m_rgGlobalBinding.Lookup(dwNameHash, pNode); return pNode; } -static void XFA_DataMerge_RegisterGlobalBinding(CXFA_Document* pDocument, - uint32_t dwNameHash, - CXFA_Node* pDataNode) { + +void RegisterGlobalBinding(CXFA_Document* pDocument, + uint32_t dwNameHash, + CXFA_Node* pDataNode) { pDocument->m_rgGlobalBinding.SetAt(dwNameHash, pDataNode); } -static void XFA_DataMerge_ClearGlobalBinding(CXFA_Document* pDocument) { - pDocument->m_rgGlobalBinding.RemoveAll(); -} -static CXFA_Node* XFA_DataMerge_ScopeMatchGlobalBinding( - CXFA_Node* pDataScope, - uint32_t dwNameHash, - XFA_Element eMatchDataNodeType, - FX_BOOL bUpLevel = TRUE) { + +CXFA_Node* ScopeMatchGlobalBinding(CXFA_Node* pDataScope, + uint32_t dwNameHash, + XFA_Element eMatchDataNodeType, + FX_BOOL bUpLevel) { for (CXFA_Node *pCurDataScope = pDataScope, *pLastDataScope = nullptr; pCurDataScope && pCurDataScope->GetPacketID() == XFA_XDPPACKET_Datasets; pLastDataScope = pCurDataScope, @@ -373,45 +389,44 @@ static CXFA_Node* XFA_DataMerge_ScopeMatchGlobalBinding( } return pDataChild; } + for (CXFA_Node* pDataChild = pCurDataScope->GetFirstChildByClass(XFA_Element::DataGroup); pDataChild; pDataChild = pDataChild->GetNextSameClassSibling( XFA_Element::DataGroup)) { - CXFA_Node* pDataNode = XFA_DataMerge_ScopeMatchGlobalBinding( - pDataChild, dwNameHash, eMatchDataNodeType, FALSE); - if (pDataNode) { + CXFA_Node* pDataNode = ScopeMatchGlobalBinding(pDataChild, dwNameHash, + eMatchDataNodeType, FALSE); + if (pDataNode) return pDataNode; - } } - if (!bUpLevel) { + if (!bUpLevel) break; - } } return nullptr; } -static CXFA_Node* XFA_DataMerge_FindGlobalDataNode(CXFA_Document* pDocument, - CFX_WideStringC wsName, - CXFA_Node* pDataScope, - XFA_Element eMatchNodeType) { + +CXFA_Node* FindGlobalDataNode(CXFA_Document* pDocument, + CFX_WideStringC wsName, + CXFA_Node* pDataScope, + XFA_Element eMatchNodeType) { if (wsName.IsEmpty()) return nullptr; uint32_t dwNameHash = FX_HashCode_GetW(wsName, false); - CXFA_Node* pBounded = XFA_DataMerge_GetGlobalBinding(pDocument, dwNameHash); + CXFA_Node* pBounded = GetGlobalBinding(pDocument, dwNameHash); if (!pBounded) { - pBounded = XFA_DataMerge_ScopeMatchGlobalBinding(pDataScope, dwNameHash, - eMatchNodeType); - if (pBounded) { - XFA_DataMerge_RegisterGlobalBinding(pDocument, dwNameHash, pBounded); - } + pBounded = + ScopeMatchGlobalBinding(pDataScope, dwNameHash, eMatchNodeType, TRUE); + if (pBounded) + RegisterGlobalBinding(pDocument, dwNameHash, pBounded); } return pBounded; } -static CXFA_Node* XFA_DataMerge_FindOnceDataNode(CXFA_Document* pDocument, - CFX_WideStringC wsName, - CXFA_Node* pDataScope, - XFA_Element eMatchNodeType) { +CXFA_Node* FindOnceDataNode(CXFA_Document* pDocument, + CFX_WideStringC wsName, + CXFA_Node* pDataScope, + XFA_Element eMatchNodeType) { if (wsName.IsEmpty()) return nullptr; @@ -435,17 +450,17 @@ static CXFA_Node* XFA_DataMerge_FindOnceDataNode(CXFA_Document* pDocument, return nullptr; } -static CXFA_Node* XFA_DataMerge_FindDataRefDataNode(CXFA_Document* pDocument, - CFX_WideStringC wsRef, - CXFA_Node* pDataScope, - XFA_Element eMatchNodeType, - CXFA_Node* pTemplateNode, - FX_BOOL bForceBind, - FX_BOOL bUpLevel = TRUE) { +CXFA_Node* FindDataRefDataNode(CXFA_Document* pDocument, + CFX_WideStringC wsRef, + CXFA_Node* pDataScope, + XFA_Element eMatchNodeType, + CXFA_Node* pTemplateNode, + FX_BOOL bForceBind, + FX_BOOL bUpLevel) { uint32_t dFlags = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_BindNew; - if (bUpLevel || wsRef != FX_WSTRC(L"name")) { + if (bUpLevel || wsRef != FX_WSTRC(L"name")) dFlags |= (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings); - } + XFA_RESOLVENODE_RS rs; pDocument->GetScriptContext()->ResolveObjects(pDataScope, wsRef, rs, dFlags, pTemplateNode); @@ -454,102 +469,33 @@ static CXFA_Node* XFA_DataMerge_FindDataRefDataNode(CXFA_Document* pDocument, rs.nodes.GetSize() > 1) { return pDocument->GetNotBindNode(rs.nodes); } + if (rs.dwFlags == XFA_RESOLVENODE_RSTYPE_CreateNodeOne) { CXFA_Object* pObject = (rs.nodes.GetSize() > 0) ? rs.nodes[0] : nullptr; CXFA_Node* pNode = ToNode(pObject); - if (!bForceBind && pNode && pNode->HasBindItem()) { - pNode = nullptr; - } - return pNode; + return (bForceBind || !pNode || !pNode->HasBindItem()) ? pNode : nullptr; } return nullptr; } -CXFA_Node* XFA_DataMerge_FindFormDOMInstance(CXFA_Document* pDocument, - XFA_Element eType, - uint32_t dwNameHash, - CXFA_Node* pFormParent) { - CXFA_Node* pFormChild = pFormParent->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pFormChild; - pFormChild = pFormChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pFormChild->GetElementType() == eType && - pFormChild->GetNameHash() == dwNameHash && pFormChild->IsUnusedNode()) { - return pFormChild; - } - } - return nullptr; -} -static FX_BOOL XFA_NeedGenerateForm(CXFA_Node* pTemplateChild, - FX_BOOL bUseInstanceManager = TRUE) { + +FX_BOOL NeedGenerateForm(CXFA_Node* pTemplateChild, + FX_BOOL bUseInstanceManager) { XFA_Element eType = pTemplateChild->GetElementType(); - if (eType == XFA_Element::Variables) { + if (eType == XFA_Element::Variables) return TRUE; - } - if (pTemplateChild->IsContainerNode()) { + if (pTemplateChild->IsContainerNode()) return FALSE; - } if (eType == XFA_Element::Proto || (bUseInstanceManager && eType == XFA_Element::Occur)) { return FALSE; } return TRUE; } -CXFA_Node* XFA_NodeMerge_CloneOrMergeContainer(CXFA_Document* pDocument, - CXFA_Node* pFormParent, - CXFA_Node* pTemplateNode, - FX_BOOL bRecursive, - CXFA_NodeArray* pSubformArray) { - CXFA_Node* pExistingNode = nullptr; - if (!pSubformArray) { - pExistingNode = XFA_DataMerge_FindFormDOMInstance( - pDocument, pTemplateNode->GetElementType(), - pTemplateNode->GetNameHash(), pFormParent); - } else if (pSubformArray->GetSize() > 0) { - pExistingNode = pSubformArray->GetAt(0); - pSubformArray->RemoveAt(0); - } - if (pExistingNode) { - if (pSubformArray) { - pFormParent->InsertChild(pExistingNode); - } else if (pExistingNode->IsContainerNode()) { - pFormParent->RemoveChild(pExistingNode); - pFormParent->InsertChild(pExistingNode); - } - pExistingNode->ClearFlag(XFA_NodeFlag_UnusedNode); - pExistingNode->SetTemplateNode(pTemplateNode); - if (bRecursive && pExistingNode->GetElementType() != XFA_Element::Items) { - for (CXFA_Node* pTemplateChild = - pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); - pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( - XFA_NODEITEM_NextSibling)) { - if (XFA_NeedGenerateForm(pTemplateChild)) { - XFA_NodeMerge_CloneOrMergeContainer(pDocument, pExistingNode, - pTemplateChild, bRecursive); - } - } - } - pExistingNode->SetFlag(XFA_NodeFlag_Initialized, true); - return pExistingNode; - } - CXFA_Node* pNewNode = pTemplateNode->CloneTemplateToForm(FALSE); - pFormParent->InsertChild(pNewNode, nullptr); - if (bRecursive) { - for (CXFA_Node* pTemplateChild = - pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); - pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( - XFA_NODEITEM_NextSibling)) { - if (XFA_NeedGenerateForm(pTemplateChild)) { - CXFA_Node* pNewChild = pTemplateChild->CloneTemplateToForm(TRUE); - pNewNode->InsertChild(pNewChild, nullptr); - } - } - } - return pNewNode; -} -static CXFA_Node* XFA_NodeMerge_CloneOrMergeInstanceManager( - CXFA_Document* pDocument, - CXFA_Node* pFormParent, - CXFA_Node* pTemplateNode, - CXFA_NodeArray& subforms) { + +CXFA_Node* CloneOrMergeInstanceManager(CXFA_Document* pDocument, + CXFA_Node* pFormParent, + CXFA_Node* pTemplateNode, + CXFA_NodeArray& subforms) { CFX_WideStringC wsSubformName = pTemplateNode->GetCData(XFA_ATTRIBUTE_Name); CFX_WideString wsInstMgrNodeName = FX_WSTRC(L"_") + wsSubformName; uint32_t dwInstNameHash = @@ -562,17 +508,17 @@ static CXFA_Node* XFA_NodeMerge_CloneOrMergeInstanceManager( pExistingNode->GetNodeItem(XFA_NODEITEM_NextSibling); pNode;) { XFA_Element eCurType = pNode->GetElementType(); - if (eCurType == XFA_Element::InstanceManager) { + if (eCurType == XFA_Element::InstanceManager) break; - } + if ((eCurType != XFA_Element::Subform) && (eCurType != XFA_Element::SubformSet)) { pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); continue; } - if (dwNameHash != pNode->GetNameHash()) { + if (dwNameHash != pNode->GetNameHash()) break; - } + CXFA_Node* pNextNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); pFormParent->RemoveChild(pNode); subforms.Add(pNode); @@ -584,6 +530,7 @@ static CXFA_Node* XFA_NodeMerge_CloneOrMergeInstanceManager( pExistingNode->SetTemplateNode(pTemplateNode); return pExistingNode; } + CXFA_Node* pNewNode = pDocument->GetParser()->GetFactory()->CreateNode( XFA_XDPPACKET_Form, XFA_Element::InstanceManager); ASSERT(pNewNode); @@ -594,7 +541,8 @@ static CXFA_Node* XFA_NodeMerge_CloneOrMergeInstanceManager( pNewNode->SetTemplateNode(pTemplateNode); return pNewNode; } -static CXFA_Node* XFA_DataMerge_FindMatchingDataNode( + +CXFA_Node* FindMatchingDataNode( CXFA_Document* pDocument, CXFA_Node* pTemplateNode, CXFA_Node* pDataScope, @@ -605,13 +553,14 @@ static CXFA_Node* XFA_DataMerge_FindMatchingDataNode( pIterator, FX_BOOL& bSelfMatch, XFA_ATTRIBUTEENUM& eBindMatch, - FX_BOOL bUpLevel = TRUE) { + FX_BOOL bUpLevel) { FX_BOOL bOwnIterator = FALSE; if (!pIterator) { bOwnIterator = TRUE; pIterator = new CXFA_NodeIteratorTemplate< CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode>(pTemplateNode); } + CXFA_Node* pResult = nullptr; for (CXFA_Node* pCurTemplateNode = pIterator->GetCurrent(); pCurTemplateNode;) { @@ -636,10 +585,11 @@ static CXFA_Node* XFA_DataMerge_FindMatchingDataNode( pCurTemplateNode->GetFirstChildByClass(XFA_Element::Occur); int32_t iMin, iMax, iInit; if (pTemplateNodeOccur && - XFA_GetOccurInfo(pTemplateNodeOccur, iMin, iMax, iInit) && iMax == 0) { + GetOccurInfo(pTemplateNodeOccur, iMin, iMax, iInit) && iMax == 0) { pCurTemplateNode = pIterator->MoveToNext(); continue; } + CXFA_Node* pTemplateNodeBind = pCurTemplateNode->GetFirstChildByClass(XFA_Element::Bind); XFA_ATTRIBUTEENUM eMatch = @@ -659,7 +609,7 @@ static CXFA_Node* XFA_DataMerge_FindMatchingDataNode( if (eMatchNodeType == XFA_Element::DataValue || (eMatchNodeType == XFA_Element::DataGroup && XFA_FieldIsMultiListBox(pTemplateNodeBind))) { - CXFA_Node* pGlobalBindNode = XFA_DataMerge_FindGlobalDataNode( + CXFA_Node* pGlobalBindNode = FindGlobalDataNode( pDocument, pCurTemplateNode->GetCData(XFA_ATTRIBUTE_Name), pDataScope, eMatchNodeType); if (!pGlobalBindNode) { @@ -671,7 +621,7 @@ static CXFA_Node* XFA_DataMerge_FindMatchingDataNode( } case XFA_ATTRIBUTEENUM_Once: { bAccessedDataDOM = TRUE; - CXFA_Node* pOnceBindNode = XFA_DataMerge_FindOnceDataNode( + CXFA_Node* pOnceBindNode = FindOnceDataNode( pDocument, pCurTemplateNode->GetCData(XFA_ATTRIBUTE_Name), pDataScope, eMatchNodeType); if (!pOnceBindNode) { @@ -679,10 +629,11 @@ static CXFA_Node* XFA_DataMerge_FindMatchingDataNode( continue; } pResult = pOnceBindNode; - } break; + break; + } case XFA_ATTRIBUTEENUM_DataRef: { bAccessedDataDOM = TRUE; - CXFA_Node* pDataRefBindNode = XFA_DataMerge_FindDataRefDataNode( + CXFA_Node* pDataRefBindNode = FindDataRefDataNode( pDocument, pTemplateNodeBind->GetCData(XFA_ATTRIBUTE_Ref), pDataScope, eMatchNodeType, pTemplateNode, bForceBind, bUpLevel); if (pDataRefBindNode && @@ -693,49 +644,47 @@ static CXFA_Node* XFA_DataMerge_FindMatchingDataNode( pCurTemplateNode = pIterator->SkipChildrenAndMoveToNext(); continue; } - } break; + break; + } default: break; } - if (pCurTemplateNode == pTemplateNode && pResult) { + if (pCurTemplateNode == pTemplateNode && pResult) bSelfMatch = TRUE; - } break; } - if (bOwnIterator) { + if (bOwnIterator) delete pIterator; - } return pResult; } -static void XFA_DataMerge_SortRecurseRecord( - CFX_ArrayTemplate& rgRecords, - CXFA_Node* pDataScope, - FX_BOOL bChoiceMode = FALSE) { + +void SortRecurseRecord(CFX_ArrayTemplate& rgRecords, + CXFA_Node* pDataScope, + FX_BOOL bChoiceMode) { int32_t iCount = rgRecords.GetSize(); - CFX_ArrayTemplate rgResultRecord; + CFX_ArrayTemplate rgResultRecord; for (CXFA_Node* pChildNode = pDataScope->GetNodeItem(XFA_NODEITEM_FirstChild); pChildNode; pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { for (int32_t i = 0; i < iCount; i++) { CXFA_Node* pNode = rgRecords[i].pDataChild; if (pChildNode == pNode) { - XFA_DataMerge_RecurseRecord sNewRecord = {rgRecords[i].pTemplateChild, - pNode}; + RecurseRecord sNewRecord = {rgRecords[i].pTemplateChild, pNode}; rgResultRecord.Add(sNewRecord); rgRecords.RemoveAt(i); iCount--; break; } } - if (bChoiceMode && rgResultRecord.GetSize() > 0) { + if (bChoiceMode && rgResultRecord.GetSize() > 0) break; - } } + if (rgResultRecord.GetSize() > 0) { if (!bChoiceMode) { for (int32_t i = 0; i < iCount; i++) { - XFA_DataMerge_RecurseRecord sNewRecord = {rgRecords[i].pTemplateChild, - rgRecords[i].pDataChild}; + RecurseRecord sNewRecord = {rgRecords[i].pTemplateChild, + rgRecords[i].pDataChild}; rgResultRecord.Add(sNewRecord); } } @@ -743,13 +692,13 @@ static void XFA_DataMerge_SortRecurseRecord( rgRecords.Copy(rgResultRecord); } } -static CXFA_Node* XFA_DataMerge_CopyContainer_SubformSet( - CXFA_Document* pDocument, - CXFA_Node* pTemplateNode, - CXFA_Node* pFormParentNode, - CXFA_Node* pDataScope, - FX_BOOL bOneInstance, - FX_BOOL bDataMerge) { + +CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, + CXFA_Node* pTemplateNode, + CXFA_Node* pFormParentNode, + CXFA_Node* pDataScope, + FX_BOOL bOneInstance, + FX_BOOL bDataMerge) { XFA_Element eType = pTemplateNode->GetElementType(); CXFA_Node* pOccurNode = nullptr; CXFA_Node* pFirstInstance = nullptr; @@ -760,41 +709,41 @@ static CXFA_Node* XFA_DataMerge_CopyContainer_SubformSet( CXFA_NodeArray* pSearchArray = nullptr; if (!bOneInstance && (eType == XFA_Element::SubformSet || eType == XFA_Element::Subform)) { - pInstMgrNode = - bUseInstanceManager - ? XFA_NodeMerge_CloneOrMergeInstanceManager( - pDocument, pFormParentNode, pTemplateNode, subformArray) - : nullptr; + pInstMgrNode = bUseInstanceManager ? CloneOrMergeInstanceManager( + pDocument, pFormParentNode, + pTemplateNode, subformArray) + : nullptr; if (CXFA_Node* pOccurTemplateNode = pTemplateNode->GetFirstChildByClass(XFA_Element::Occur)) { - pOccurNode = pInstMgrNode - ? XFA_NodeMerge_CloneOrMergeContainer( - pDocument, pInstMgrNode, pOccurTemplateNode, FALSE) - : pOccurTemplateNode; + pOccurNode = pInstMgrNode ? XFA_NodeMerge_CloneOrMergeContainer( + pDocument, pInstMgrNode, + pOccurTemplateNode, FALSE, nullptr) + : pOccurTemplateNode; } else if (pInstMgrNode) { pOccurNode = pInstMgrNode->GetFirstChildByClass(XFA_Element::Occur); - if (pOccurNode) { + if (pOccurNode) pOccurNode->ClearFlag(XFA_NodeFlag_UnusedNode); - } } if (pInstMgrNode) { pInstMgrNode->SetFlag(XFA_NodeFlag_Initialized, true); pSearchArray = &subformArray; if (pFormParentNode->GetElementType() == XFA_Element::PageArea) { bOneInstance = TRUE; - if (subformArray.GetSize() < 1) { + if (subformArray.GetSize() < 1) pSearchArray = nullptr; - } } else if ((pTemplateNode->GetNameHash() == 0) && (subformArray.GetSize() < 1)) { pSearchArray = nullptr; } } } - int32_t iMax = 1, iInit = 1, iMin = 1; - if (!bOneInstance) { - XFA_GetOccurInfo(pOccurNode, iMin, iMax, iInit); - } + + int32_t iMax = 1; + int32_t iInit = 1; + int32_t iMin = 1; + if (!bOneInstance) + GetOccurInfo(pOccurNode, iMin, iMax, iInit); + XFA_ATTRIBUTEENUM eRelation = eType == XFA_Element::SubformSet ? pTemplateNode->GetEnum(XFA_ATTRIBUTE_Relation) @@ -813,23 +762,24 @@ static CXFA_Node* XFA_DataMerge_CopyContainer_SubformSet( for (; iMax < 0 || iCurRepeatIndex < iMax; iCurRepeatIndex++) { FX_BOOL bSelfMatch = FALSE; XFA_ATTRIBUTEENUM eBindMatch = XFA_ATTRIBUTEENUM_None; - CXFA_Node* pDataNode = XFA_DataMerge_FindMatchingDataNode( + CXFA_Node* pDataNode = FindMatchingDataNode( pDocument, pTemplateNode, pDataScope, bAccessedDataDOM, FALSE, - &sNodeIterator, bSelfMatch, eBindMatch); - if (!pDataNode || sNodeIterator.GetCurrent() != pTemplateNode) { + &sNodeIterator, bSelfMatch, eBindMatch, TRUE); + if (!pDataNode || sNodeIterator.GetCurrent() != pTemplateNode) break; - } + eParentBindMatch = eBindMatch; CXFA_Node* pSubformNode = XFA_NodeMerge_CloneOrMergeContainer( pDocument, pFormParentNode, pTemplateNode, FALSE, pSearchArray); - if (!pFirstInstance) { + if (!pFirstInstance) pFirstInstance = pSubformNode; - } - XFA_DataMerge_CreateDataBinding(pSubformNode, pDataNode); + + CreateDataBinding(pSubformNode, pDataNode, TRUE); ASSERT(pSubformNode); subformMapArray.SetAt(pSubformNode, pDataNode); nodeArray.Add(pSubformNode); } + subformMapArray.GetStartPosition(); for (int32_t iIndex = 0; iIndex < nodeArray.GetSize(); iIndex++) { CXFA_Node* pSubform = nodeArray[iIndex]; @@ -839,9 +789,9 @@ static CXFA_Node* XFA_DataMerge_CopyContainer_SubformSet( pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( XFA_NODEITEM_NextSibling)) { - if (XFA_NeedGenerateForm(pTemplateChild, bUseInstanceManager)) { + if (NeedGenerateForm(pTemplateChild, bUseInstanceManager)) { XFA_NodeMerge_CloneOrMergeContainer(pDocument, pSubform, - pTemplateChild, TRUE); + pTemplateChild, TRUE, nullptr); } else if (pTemplateChild->IsContainerNode()) { pDocument->DataMerge_CopyContainer(pTemplateChild, pSubform, pDataNode, FALSE, TRUE, FALSE); @@ -850,65 +800,70 @@ static CXFA_Node* XFA_DataMerge_CopyContainer_SubformSet( } subformMapArray.RemoveAll(); } + for (; iMax < 0 || iCurRepeatIndex < iMax; iCurRepeatIndex++) { FX_BOOL bSelfMatch = FALSE; XFA_ATTRIBUTEENUM eBindMatch = XFA_ATTRIBUTEENUM_None; - if (!XFA_DataMerge_FindMatchingDataNode( - pDocument, pTemplateNode, pDataScope, bAccessedDataDOM, FALSE, - &sNodeIterator, bSelfMatch, eBindMatch)) { + if (!FindMatchingDataNode(pDocument, pTemplateNode, pDataScope, + bAccessedDataDOM, FALSE, &sNodeIterator, + bSelfMatch, eBindMatch, TRUE)) { break; } if (eBindMatch == XFA_ATTRIBUTEENUM_DataRef && eParentBindMatch == XFA_ATTRIBUTEENUM_DataRef) { break; } + if (eRelation == XFA_ATTRIBUTEENUM_Choice || eRelation == XFA_ATTRIBUTEENUM_Unordered) { CXFA_Node* pSubformSetNode = XFA_NodeMerge_CloneOrMergeContainer( pDocument, pFormParentNode, pTemplateNode, FALSE, pSearchArray); ASSERT(pSubformSetNode); - if (!pFirstInstance) { + if (!pFirstInstance) pFirstInstance = pSubformSetNode; - } - CFX_ArrayTemplate rgItemMatchList; + + CFX_ArrayTemplate rgItemMatchList; CFX_ArrayTemplate rgItemUnmatchList; for (CXFA_Node* pTemplateChild = pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( XFA_NODEITEM_NextSibling)) { - if (XFA_NeedGenerateForm(pTemplateChild, bUseInstanceManager)) { + if (NeedGenerateForm(pTemplateChild, bUseInstanceManager)) { XFA_NodeMerge_CloneOrMergeContainer(pDocument, pSubformSetNode, - pTemplateChild, TRUE); + pTemplateChild, TRUE, nullptr); } else if (pTemplateChild->IsContainerNode()) { bSelfMatch = FALSE; eBindMatch = XFA_ATTRIBUTEENUM_None; - CXFA_Node* pDataMatch; - if (eRelation != XFA_ATTRIBUTEENUM_Ordered && - (pDataMatch = XFA_DataMerge_FindMatchingDataNode( - pDocument, pTemplateChild, pDataScope, bAccessedDataDOM, - FALSE, nullptr, bSelfMatch, eBindMatch)) != nullptr) { - XFA_DataMerge_RecurseRecord sNewRecord = {pTemplateChild, - pDataMatch}; - if (bSelfMatch) { - rgItemMatchList.InsertAt(0, sNewRecord); + if (eRelation != XFA_ATTRIBUTEENUM_Ordered) { + CXFA_Node* pDataMatch = FindMatchingDataNode( + pDocument, pTemplateChild, pDataScope, bAccessedDataDOM, + FALSE, nullptr, bSelfMatch, eBindMatch, TRUE); + if (pDataMatch) { + RecurseRecord sNewRecord = {pTemplateChild, pDataMatch}; + if (bSelfMatch) + rgItemMatchList.InsertAt(0, sNewRecord); + else + rgItemMatchList.Add(sNewRecord); } else { - rgItemMatchList.Add(sNewRecord); + rgItemUnmatchList.Add(pTemplateChild); } } else { rgItemUnmatchList.Add(pTemplateChild); } } } + switch (eRelation) { case XFA_ATTRIBUTEENUM_Choice: { ASSERT(rgItemMatchList.GetSize()); - XFA_DataMerge_SortRecurseRecord(rgItemMatchList, pDataScope, TRUE); + SortRecurseRecord(rgItemMatchList, pDataScope, TRUE); pDocument->DataMerge_CopyContainer( rgItemMatchList[0].pTemplateChild, pSubformSetNode, pDataScope); - } break; + break; + } case XFA_ATTRIBUTEENUM_Unordered: { if (rgItemMatchList.GetSize()) { - XFA_DataMerge_SortRecurseRecord(rgItemMatchList, pDataScope); + SortRecurseRecord(rgItemMatchList, pDataScope, FALSE); for (int32_t i = 0, count = rgItemMatchList.GetSize(); i < count; i++) { pDocument->DataMerge_CopyContainer( @@ -921,7 +876,8 @@ static CXFA_Node* XFA_DataMerge_CopyContainer_SubformSet( pDocument->DataMerge_CopyContainer(rgItemUnmatchList[i], pSubformSetNode, pDataScope); } - } break; + break; + } default: break; } @@ -929,16 +885,16 @@ static CXFA_Node* XFA_DataMerge_CopyContainer_SubformSet( CXFA_Node* pSubformSetNode = XFA_NodeMerge_CloneOrMergeContainer( pDocument, pFormParentNode, pTemplateNode, FALSE, pSearchArray); ASSERT(pSubformSetNode); - if (!pFirstInstance) { + if (!pFirstInstance) pFirstInstance = pSubformSetNode; - } + for (CXFA_Node* pTemplateChild = pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( XFA_NODEITEM_NextSibling)) { - if (XFA_NeedGenerateForm(pTemplateChild, bUseInstanceManager)) { + if (NeedGenerateForm(pTemplateChild, bUseInstanceManager)) { XFA_NodeMerge_CloneOrMergeContainer(pDocument, pSubformSetNode, - pTemplateChild, TRUE); + pTemplateChild, TRUE, nullptr); } else if (pTemplateChild->IsContainerNode()) { pDocument->DataMerge_CopyContainer(pTemplateChild, pSubformSetNode, pDataScope); @@ -946,20 +902,20 @@ static CXFA_Node* XFA_DataMerge_CopyContainer_SubformSet( } } } + if (iCurRepeatIndex == 0 && bAccessedDataDOM == FALSE) { int32_t iLimit = iMax; if (pInstMgrNode && pTemplateNode->GetNameHash() == 0) { iLimit = subformArray.GetSize(); - if (iLimit < iMin) { + if (iLimit < iMin) iLimit = iInit; - } } + for (; (iLimit < 0 || iCurRepeatIndex < iLimit); iCurRepeatIndex++) { if (pInstMgrNode) { if (pSearchArray && pSearchArray->GetSize() < 1) { - if (pTemplateNode->GetNameHash() != 0) { + if (pTemplateNode->GetNameHash() != 0) break; - } pSearchArray = nullptr; } } else if (!XFA_DataMerge_FindFormDOMInstance( @@ -970,16 +926,16 @@ static CXFA_Node* XFA_DataMerge_CopyContainer_SubformSet( CXFA_Node* pSubformNode = XFA_NodeMerge_CloneOrMergeContainer( pDocument, pFormParentNode, pTemplateNode, FALSE, pSearchArray); ASSERT(pSubformNode); - if (!pFirstInstance) { + if (!pFirstInstance) pFirstInstance = pSubformNode; - } + for (CXFA_Node* pTemplateChild = pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( XFA_NODEITEM_NextSibling)) { - if (XFA_NeedGenerateForm(pTemplateChild, bUseInstanceManager)) { + if (NeedGenerateForm(pTemplateChild, bUseInstanceManager)) { XFA_NodeMerge_CloneOrMergeContainer(pDocument, pSubformNode, - pTemplateChild, TRUE); + pTemplateChild, TRUE, nullptr); } else if (pTemplateChild->IsContainerNode()) { pDocument->DataMerge_CopyContainer(pTemplateChild, pSubformNode, pDataScope); @@ -988,26 +944,27 @@ static CXFA_Node* XFA_DataMerge_CopyContainer_SubformSet( } } } + int32_t iMinimalLimit = iCurRepeatIndex == 0 ? iInit : iMin; for (; iCurRepeatIndex < iMinimalLimit; iCurRepeatIndex++) { CXFA_Node* pSubformSetNode = XFA_NodeMerge_CloneOrMergeContainer( pDocument, pFormParentNode, pTemplateNode, FALSE, pSearchArray); ASSERT(pSubformSetNode); - if (!pFirstInstance) { + if (!pFirstInstance) pFirstInstance = pSubformSetNode; - } + FX_BOOL bFound = FALSE; for (CXFA_Node* pTemplateChild = pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( XFA_NODEITEM_NextSibling)) { - if (XFA_NeedGenerateForm(pTemplateChild, bUseInstanceManager)) { + if (NeedGenerateForm(pTemplateChild, bUseInstanceManager)) { XFA_NodeMerge_CloneOrMergeContainer(pDocument, pSubformSetNode, - pTemplateChild, TRUE); + pTemplateChild, TRUE, nullptr); } else if (pTemplateChild->IsContainerNode()) { - if (bFound && eRelation == XFA_ATTRIBUTEENUM_Choice) { + if (bFound && eRelation == XFA_ATTRIBUTEENUM_Choice) continue; - } + pDocument->DataMerge_CopyContainer(pTemplateChild, pSubformSetNode, pDataScope, FALSE, bDataMerge); bFound = TRUE; @@ -1016,27 +973,28 @@ static CXFA_Node* XFA_DataMerge_CopyContainer_SubformSet( } return pFirstInstance; } -static CXFA_Node* XFA_DataMerge_CopyContainer_Field(CXFA_Document* pDocument, - CXFA_Node* pTemplateNode, - CXFA_Node* pFormNode, - CXFA_Node* pDataScope, - FX_BOOL bDataMerge, - FX_BOOL bUpLevel = TRUE) { + +CXFA_Node* CopyContainer_Field(CXFA_Document* pDocument, + CXFA_Node* pTemplateNode, + CXFA_Node* pFormNode, + CXFA_Node* pDataScope, + FX_BOOL bDataMerge, + FX_BOOL bUpLevel) { CXFA_Node* pFieldNode = XFA_NodeMerge_CloneOrMergeContainer( - pDocument, pFormNode, pTemplateNode, FALSE); + pDocument, pFormNode, pTemplateNode, FALSE, nullptr); ASSERT(pFieldNode); for (CXFA_Node* pTemplateChildNode = pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); pTemplateChildNode; pTemplateChildNode = pTemplateChildNode->GetNodeItem( XFA_NODEITEM_NextSibling)) { - if (XFA_NeedGenerateForm(pTemplateChildNode)) { + if (NeedGenerateForm(pTemplateChildNode, TRUE)) { XFA_NodeMerge_CloneOrMergeContainer(pDocument, pFieldNode, - pTemplateChildNode, TRUE); + pTemplateChildNode, TRUE, nullptr); } else if (pTemplateNode->GetElementType() == XFA_Element::ExclGroup && pTemplateChildNode->IsContainerNode()) { if (pTemplateChildNode->GetElementType() == XFA_Element::Field) { - XFA_DataMerge_CopyContainer_Field(pDocument, pTemplateChildNode, - pFieldNode, nullptr, FALSE); + CopyContainer_Field(pDocument, pTemplateChildNode, pFieldNode, nullptr, + FALSE, TRUE); } } } @@ -1044,52 +1002,77 @@ static CXFA_Node* XFA_DataMerge_CopyContainer_Field(CXFA_Document* pDocument, FX_BOOL bAccessedDataDOM = FALSE; FX_BOOL bSelfMatch = FALSE; XFA_ATTRIBUTEENUM eBindMatch; - CXFA_Node* pDataNode = XFA_DataMerge_FindMatchingDataNode( + CXFA_Node* pDataNode = FindMatchingDataNode( pDocument, pTemplateNode, pDataScope, bAccessedDataDOM, TRUE, nullptr, bSelfMatch, eBindMatch, bUpLevel); - if (pDataNode) { - XFA_DataMerge_CreateDataBinding(pFieldNode, pDataNode); - } + if (pDataNode) + CreateDataBinding(pFieldNode, pDataNode, TRUE); } else { - XFA_DataMerge_FormValueNode_MatchNoneCreateChild(pFieldNode); + FormValueNode_MatchNoneCreateChild(pFieldNode); } return pFieldNode; } -CXFA_Node* CXFA_Document::DataMerge_CopyContainer(CXFA_Node* pTemplateNode, - CXFA_Node* pFormNode, - CXFA_Node* pDataScope, - FX_BOOL bOneInstance, - FX_BOOL bDataMerge, - FX_BOOL bUpLevel) { - switch (pTemplateNode->GetElementType()) { - case XFA_Element::SubformSet: - case XFA_Element::Subform: - case XFA_Element::Area: - case XFA_Element::PageArea: - return XFA_DataMerge_CopyContainer_SubformSet( - this, pTemplateNode, pFormNode, pDataScope, bOneInstance, bDataMerge); - case XFA_Element::ExclGroup: - case XFA_Element::Field: - case XFA_Element::Draw: - case XFA_Element::ContentArea: - return XFA_DataMerge_CopyContainer_Field( - this, pTemplateNode, pFormNode, pDataScope, bDataMerge, bUpLevel); - case XFA_Element::PageSet: - break; - case XFA_Element::Variables: - break; - default: - ASSERT(FALSE); + +CXFA_Node* MaybeCreateDataNode(CXFA_Document* pDocument, + CXFA_Node* pDataParent, + XFA_Element eNodeType, + const CFX_WideString& wsName) { + if (!pDataParent) + return nullptr; + + CXFA_Node* pParentDDNode = pDataParent->GetDataDescriptionNode(); + if (!pParentDDNode) { + CXFA_Node* pDataNode = + pDocument->CreateNode(XFA_XDPPACKET_Datasets, eNodeType); + pDataNode->SetCData(XFA_ATTRIBUTE_Name, wsName); + pDataNode->CreateXMLMappingNode(); + pDataParent->InsertChild(pDataNode); + pDataNode->SetFlag(XFA_NodeFlag_Initialized, false); + return pDataNode; + } + + CXFA_NodeIteratorTemplate sIterator( + pParentDDNode); + for (CXFA_Node* pDDGroupNode = sIterator.GetCurrent(); pDDGroupNode; + pDDGroupNode = sIterator.MoveToNext()) { + if (pDDGroupNode != pParentDDNode) { + if (pDDGroupNode->GetElementType() != XFA_Element::DataGroup) + continue; + + CFX_WideString wsNamespace; + if (!pDDGroupNode->TryNamespace(wsNamespace) || + wsNamespace != FX_WSTRC(L"http://ns.adobe.com/data-description/")) { + continue; + } + } + CXFA_Node* pDDNode = pDDGroupNode->GetFirstChildByName(wsName.AsStringC()); + if (!pDDNode) + continue; + if (pDDNode->GetElementType() != eNodeType) break; + + CXFA_Node* pDataNode = + pDocument->CreateNode(XFA_XDPPACKET_Datasets, eNodeType); + pDataNode->SetCData(XFA_ATTRIBUTE_Name, wsName); + pDataNode->CreateXMLMappingNode(); + if (eNodeType == XFA_Element::DataValue && + pDDNode->GetEnum(XFA_ATTRIBUTE_Contains) == + XFA_ATTRIBUTEENUM_MetaData) { + pDataNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_MetaData); + } + pDataParent->InsertChild(pDataNode); + pDataNode->SetDataDescriptionNode(pDDNode); + pDataNode->SetFlag(XFA_NodeFlag_Initialized, false); + return pDataNode; } return nullptr; } -static void XFA_DataMerge_UpdateBindingRelations(CXFA_Document* pDocument, - CXFA_Node* pFormNode, - CXFA_Node* pDataScope, - FX_BOOL bDataRef, - FX_BOOL bParentDataRef) { +void UpdateBindingRelations(CXFA_Document* pDocument, + CXFA_Node* pFormNode, + CXFA_Node* pDataScope, + FX_BOOL bDataRef, + FX_BOOL bParentDataRef) { FX_BOOL bMatchRef = TRUE; XFA_Element eType = pFormNode->GetElementType(); CXFA_Node* pDataNode = pFormNode->GetBindData(); @@ -1104,9 +1087,8 @@ static void XFA_DataMerge_UpdateBindingRelations(CXFA_Document* pDocument, : XFA_ATTRIBUTEENUM_Once; switch (eMatch) { case XFA_ATTRIBUTEENUM_None: - if (!bDataRef || bParentDataRef) { - XFA_DataMerge_FormValueNode_MatchNoneCreateChild(pFormNode); - } + if (!bDataRef || bParentDataRef) + FormValueNode_MatchNoneCreateChild(pFormNode); break; case XFA_ATTRIBUTEENUM_Once: if (!bDataRef || bParentDataRef) { @@ -1118,16 +1100,15 @@ static void XFA_DataMerge_UpdateBindingRelations(CXFA_Document* pDocument, XFA_FieldIsMultiListBox(pFormNode)) ? XFA_Element::DataGroup : XFA_Element::DataValue; - pDataNode = XFA_DataDescription_MaybeCreateDataNode( + pDataNode = MaybeCreateDataNode( pDocument, pDataScope, eDataNodeType, CFX_WideString(pFormNode->GetCData(XFA_ATTRIBUTE_Name))); - if (pDataNode) { - XFA_DataMerge_CreateDataBinding(pFormNode, pDataNode, FALSE); - } - } - if (!pDataNode) { - XFA_DataMerge_FormValueNode_MatchNoneCreateChild(pFormNode); + if (pDataNode) + CreateDataBinding(pFormNode, pDataNode, FALSE); } + if (!pDataNode) + FormValueNode_MatchNoneCreateChild(pFormNode); + } else { CXFA_Node* pDataParent = pDataNode->GetNodeItem(XFA_NODEITEM_Parent); @@ -1143,7 +1124,7 @@ static void XFA_DataMerge_UpdateBindingRelations(CXFA_Document* pDocument, if (!bDataRef || bParentDataRef) { uint32_t dwNameHash = pFormNode->GetNameHash(); if (dwNameHash != 0 && !pDataNode) { - pDataNode = XFA_DataMerge_GetGlobalBinding(pDocument, dwNameHash); + pDataNode = GetGlobalBinding(pDocument, dwNameHash); if (!pDataNode) { XFA_Element eDataNodeType = (eType == XFA_Element::Subform || XFA_FieldIsMultiListBox(pFormNode)) @@ -1151,21 +1132,20 @@ static void XFA_DataMerge_UpdateBindingRelations(CXFA_Document* pDocument, : XFA_Element::DataValue; CXFA_Node* pRecordNode = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record)); - pDataNode = XFA_DataDescription_MaybeCreateDataNode( + pDataNode = MaybeCreateDataNode( pDocument, pRecordNode, eDataNodeType, CFX_WideString(pFormNode->GetCData(XFA_ATTRIBUTE_Name))); if (pDataNode) { - XFA_DataMerge_CreateDataBinding(pFormNode, pDataNode, FALSE); - XFA_DataMerge_RegisterGlobalBinding( - pDocument, pFormNode->GetNameHash(), pDataNode); + CreateDataBinding(pFormNode, pDataNode, FALSE); + RegisterGlobalBinding(pDocument, pFormNode->GetNameHash(), + pDataNode); } } else { - XFA_DataMerge_CreateDataBinding(pFormNode, pDataNode); + CreateDataBinding(pFormNode, pDataNode, TRUE); } } - if (!pDataNode) { - XFA_DataMerge_FormValueNode_MatchNoneCreateChild(pFormNode); - } + if (!pDataNode) + FormValueNode_MatchNoneCreateChild(pFormNode); } break; case XFA_ATTRIBUTEENUM_DataRef: { @@ -1183,18 +1163,19 @@ static void XFA_DataMerge_UpdateBindingRelations(CXFA_Document* pDocument, (rs.nodes.GetSize() > 0) ? rs.nodes[0] : nullptr; pDataNode = ToNode(pObject); if (pDataNode) { - XFA_DataMerge_CreateDataBinding( - pFormNode, pDataNode, - rs.dwFlags == XFA_RESOVENODE_RSTYPE_ExistNodes); + CreateDataBinding(pFormNode, pDataNode, + rs.dwFlags == XFA_RESOVENODE_RSTYPE_ExistNodes); } else { - XFA_DataMerge_FormValueNode_MatchNoneCreateChild(pFormNode); + FormValueNode_MatchNoneCreateChild(pFormNode); } } - } break; + break; + } default: break; } } + if (bMatchRef && (eType == XFA_Element::Subform || eType == XFA_Element::SubformSet || eType == XFA_Element::Area || eType == XFA_Element::PageArea || @@ -1208,36 +1189,173 @@ static void XFA_DataMerge_UpdateBindingRelations(CXFA_Document* pDocument, if (pFormChild->IsUnusedNode()) continue; - XFA_DataMerge_UpdateBindingRelations(pDocument, pFormChild, - pDataNode ? pDataNode : pDataScope, - bDataRef, bParentDataRef); + UpdateBindingRelations(pDocument, pFormChild, + pDataNode ? pDataNode : pDataScope, bDataRef, + bParentDataRef); } } } + +void UpdateDataRelation(CXFA_Node* pDataNode, CXFA_Node* pDataDescriptionNode) { + ASSERT(pDataDescriptionNode); + for (CXFA_Node* pDataChild = pDataNode->GetNodeItem(XFA_NODEITEM_FirstChild); + pDataChild; + pDataChild = pDataChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { + uint32_t dwNameHash = pDataChild->GetNameHash(); + if (!dwNameHash) + continue; + + CXFA_NodeIteratorTemplate + sIterator(pDataDescriptionNode); + for (CXFA_Node* pDDGroupNode = sIterator.GetCurrent(); pDDGroupNode; + pDDGroupNode = sIterator.MoveToNext()) { + if (pDDGroupNode != pDataDescriptionNode) { + if (pDDGroupNode->GetElementType() != XFA_Element::DataGroup) + continue; + + CFX_WideString wsNamespace; + if (!pDDGroupNode->TryNamespace(wsNamespace) || + wsNamespace != FX_WSTRC(L"http://ns.adobe.com/data-description/")) { + continue; + } + } + CXFA_Node* pDDNode = pDDGroupNode->GetFirstChildByName(dwNameHash); + if (!pDDNode) + continue; + if (pDDNode->GetElementType() != pDataChild->GetElementType()) + break; + + pDataChild->SetDataDescriptionNode(pDDNode); + UpdateDataRelation(pDataChild, pDDNode); + break; + } + } +} + +} // namespace + +CXFA_Node* XFA_DataMerge_FindFormDOMInstance(CXFA_Document* pDocument, + XFA_Element eType, + uint32_t dwNameHash, + CXFA_Node* pFormParent) { + CXFA_Node* pFormChild = pFormParent->GetNodeItem(XFA_NODEITEM_FirstChild); + for (; pFormChild; + pFormChild = pFormChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pFormChild->GetElementType() == eType && + pFormChild->GetNameHash() == dwNameHash && pFormChild->IsUnusedNode()) { + return pFormChild; + } + } + return nullptr; +} + +CXFA_Node* XFA_NodeMerge_CloneOrMergeContainer(CXFA_Document* pDocument, + CXFA_Node* pFormParent, + CXFA_Node* pTemplateNode, + FX_BOOL bRecursive, + CXFA_NodeArray* pSubformArray) { + CXFA_Node* pExistingNode = nullptr; + if (!pSubformArray) { + pExistingNode = XFA_DataMerge_FindFormDOMInstance( + pDocument, pTemplateNode->GetElementType(), + pTemplateNode->GetNameHash(), pFormParent); + } else if (pSubformArray->GetSize() > 0) { + pExistingNode = pSubformArray->GetAt(0); + pSubformArray->RemoveAt(0); + } + + if (pExistingNode) { + if (pSubformArray) { + pFormParent->InsertChild(pExistingNode); + } else if (pExistingNode->IsContainerNode()) { + pFormParent->RemoveChild(pExistingNode); + pFormParent->InsertChild(pExistingNode); + } + pExistingNode->ClearFlag(XFA_NodeFlag_UnusedNode); + pExistingNode->SetTemplateNode(pTemplateNode); + if (bRecursive && pExistingNode->GetElementType() != XFA_Element::Items) { + for (CXFA_Node* pTemplateChild = + pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); + pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( + XFA_NODEITEM_NextSibling)) { + if (NeedGenerateForm(pTemplateChild, TRUE)) { + XFA_NodeMerge_CloneOrMergeContainer( + pDocument, pExistingNode, pTemplateChild, bRecursive, nullptr); + } + } + } + pExistingNode->SetFlag(XFA_NodeFlag_Initialized, true); + return pExistingNode; + } + + CXFA_Node* pNewNode = pTemplateNode->CloneTemplateToForm(FALSE); + pFormParent->InsertChild(pNewNode, nullptr); + if (bRecursive) { + for (CXFA_Node* pTemplateChild = + pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); + pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( + XFA_NODEITEM_NextSibling)) { + if (NeedGenerateForm(pTemplateChild, TRUE)) { + CXFA_Node* pNewChild = pTemplateChild->CloneTemplateToForm(TRUE); + pNewNode->InsertChild(pNewChild, nullptr); + } + } + } + return pNewNode; +} + CXFA_Node* XFA_DataMerge_FindDataScope(CXFA_Node* pParentFormNode) { for (CXFA_Node* pRootBoundNode = pParentFormNode; pRootBoundNode && pRootBoundNode->IsContainerNode(); pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) { CXFA_Node* pDataScope = pRootBoundNode->GetBindData(); - if (pDataScope) { + if (pDataScope) return pDataScope; - } } return ToNode( pParentFormNode->GetDocument()->GetXFAObject(XFA_HASHCODE_Data)); } + +CXFA_Node* CXFA_Document::DataMerge_CopyContainer(CXFA_Node* pTemplateNode, + CXFA_Node* pFormNode, + CXFA_Node* pDataScope, + FX_BOOL bOneInstance, + FX_BOOL bDataMerge, + FX_BOOL bUpLevel) { + switch (pTemplateNode->GetElementType()) { + case XFA_Element::SubformSet: + case XFA_Element::Subform: + case XFA_Element::Area: + case XFA_Element::PageArea: + return CopyContainer_SubformSet(this, pTemplateNode, pFormNode, + pDataScope, bOneInstance, bDataMerge); + case XFA_Element::ExclGroup: + case XFA_Element::Field: + case XFA_Element::Draw: + case XFA_Element::ContentArea: + return CopyContainer_Field(this, pTemplateNode, pFormNode, pDataScope, + bDataMerge, bUpLevel); + case XFA_Element::PageSet: + case XFA_Element::Variables: + break; + default: + ASSERT(FALSE); + break; + } + return nullptr; +} + void CXFA_Document::DataMerge_UpdateBindingRelations( CXFA_Node* pFormUpdateRoot) { CXFA_Node* pDataScope = XFA_DataMerge_FindDataScope( pFormUpdateRoot->GetNodeItem(XFA_NODEITEM_Parent)); - if (!pDataScope) { + if (!pDataScope) return; - } - XFA_DataMerge_UpdateBindingRelations(this, pFormUpdateRoot, pDataScope, FALSE, - FALSE); - XFA_DataMerge_UpdateBindingRelations(this, pFormUpdateRoot, pDataScope, TRUE, - FALSE); + + UpdateBindingRelations(this, pFormUpdateRoot, pDataScope, FALSE, FALSE); + UpdateBindingRelations(this, pFormUpdateRoot, pDataScope, TRUE, FALSE); } + CXFA_Node* CXFA_Document::GetNotBindNode(CXFA_ObjArray& arrayNodes) { for (int32_t i = 0; i < arrayNodes.GetSize(); i++) { CXFA_Node* pNode = arrayNodes[i]->AsNode(); @@ -1246,6 +1364,7 @@ CXFA_Node* CXFA_Document::GetNotBindNode(CXFA_ObjArray& arrayNodes) { } return nullptr; } + void CXFA_Document::DoDataMerge() { CXFA_Node* pDatasetsRoot = ToNode(GetXFAObject(XFA_HASHCODE_Datasets)); if (!pDatasetsRoot) { @@ -1265,30 +1384,25 @@ void CXFA_Document::DoDataMerge() { pDatasetsRoot->GetNodeItem(XFA_NODEITEM_FirstChild); pChildNode; pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pChildNode->GetElementType() != XFA_Element::DataGroup) { + if (pChildNode->GetElementType() != XFA_Element::DataGroup) continue; - } + CFX_WideString wsNamespaceURI; if (!pDDRoot && pChildNode->GetNameHash() == XFA_HASHCODE_DataDescription) { - if (!pChildNode->TryNamespace(wsNamespaceURI)) { + if (!pChildNode->TryNamespace(wsNamespaceURI)) continue; - } - if (wsNamespaceURI == - FX_WSTRC(L"http://ns.adobe.com/data-description/")) { + if (wsNamespaceURI == FX_WSTRC(L"http://ns.adobe.com/data-description/")) pDDRoot = pChildNode; - } } else if (!pDataRoot && pChildNode->GetNameHash() == XFA_HASHCODE_Data) { - if (!pChildNode->TryNamespace(wsNamespaceURI)) { + if (!pChildNode->TryNamespace(wsNamespaceURI)) continue; - } - if (wsNamespaceURI == wsDatasetsURI) { + if (wsNamespaceURI == wsDatasetsURI) pDataRoot = pChildNode; - } } - if (pDataRoot && pDDRoot) { + if (pDataRoot && pDDRoot) break; - } } + if (!pDataRoot) { CFDE_XMLElement* pDataRootXMLNode = new CFDE_XMLElement(L"xfa:data"); pDataRoot = CreateNode(XFA_XDPPACKET_Datasets, XFA_Element::DataGroup); @@ -1296,14 +1410,15 @@ void CXFA_Document::DoDataMerge() { pDataRoot->SetXMLMappingNode(pDataRootXMLNode); pDatasetsRoot->InsertChild(pDataRoot); } + CXFA_Node* pDataTopLevel = pDataRoot->GetFirstChildByClass(XFA_Element::DataGroup); uint32_t dwNameHash = pDataTopLevel ? pDataTopLevel->GetNameHash() : 0; CXFA_Node* pTemplateRoot = m_pRootNode->GetFirstChildByClass(XFA_Element::Template); - if (!pTemplateRoot) { + if (!pTemplateRoot) return; - } + CXFA_Node* pTemplateChosen = dwNameHash != 0 ? pTemplateRoot->GetFirstChildByName(dwNameHash) : nullptr; @@ -1311,9 +1426,9 @@ void CXFA_Document::DoDataMerge() { pTemplateChosen->GetElementType() != XFA_Element::Subform) { pTemplateChosen = pTemplateRoot->GetFirstChildByClass(XFA_Element::Subform); } - if (!pTemplateChosen) { + if (!pTemplateChosen) return; - } + CXFA_Node* pFormRoot = m_pRootNode->GetFirstChildByClass(XFA_Element::Form); FX_BOOL bEmptyForm = FALSE; if (!pFormRoot) { @@ -1330,8 +1445,9 @@ void CXFA_Document::DoDataMerge() { pNode->SetFlag(XFA_NodeFlag_UnusedNode, true); } } + CXFA_Node* pSubformSetNode = XFA_NodeMerge_CloneOrMergeContainer( - this, pFormRoot, pTemplateChosen, FALSE); + this, pFormRoot, pTemplateChosen, FALSE, nullptr); ASSERT(pSubformSetNode); if (!pDataTopLevel) { CFX_WideStringC wsFormName = pSubformSetNode->GetCData(XFA_ATTRIBUTE_Name); @@ -1346,22 +1462,23 @@ void CXFA_Document::DoDataMerge() { CXFA_Node* pBeforeNode = pDataRoot->GetNodeItem(XFA_NODEITEM_FirstChild); pDataRoot->InsertChild(pDataTopLevel, pBeforeNode); } + ASSERT(pDataTopLevel); - XFA_DataMerge_CreateDataBinding(pSubformSetNode, pDataTopLevel); + CreateDataBinding(pSubformSetNode, pDataTopLevel, TRUE); for (CXFA_Node* pTemplateChild = pTemplateChosen->GetNodeItem(XFA_NODEITEM_FirstChild); pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (XFA_NeedGenerateForm(pTemplateChild)) { + if (NeedGenerateForm(pTemplateChild, TRUE)) { XFA_NodeMerge_CloneOrMergeContainer(this, pSubformSetNode, pTemplateChild, - TRUE); + TRUE, nullptr); } else if (pTemplateChild->IsContainerNode()) { DataMerge_CopyContainer(pTemplateChild, pSubformSetNode, pDataTopLevel); } } - if (pDDRoot) { - XFA_DataDescription_UpdateDataRelation(pDataRoot, pDDRoot); - } + if (pDDRoot) + UpdateDataRelation(pDataRoot, pDDRoot); + DataMerge_UpdateBindingRelations(pSubformSetNode); CXFA_Node* pPageSetNode = pSubformSetNode->GetFirstChildByClass(XFA_Element::PageSet); @@ -1372,41 +1489,43 @@ void CXFA_Document::DoDataMerge() { pSubformSetNode->RemoveChild(pPageSetNode); pPageSetNode = pNextPageSetNode; } - if (!bEmptyForm) { - CXFA_NodeIteratorTemplate - sIterator(pFormRoot); - CXFA_Node* pNode = sIterator.MoveToNext(); - while (pNode) { - if (pNode->IsUnusedNode()) { - if (pNode->IsContainerNode() || - pNode->GetElementType() == XFA_Element::InstanceManager) { - CXFA_Node* pNext = sIterator.SkipChildrenAndMoveToNext(); - pNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pNode); - pNode = pNext; - } else { - pNode->ClearFlag(XFA_NodeFlag_UnusedNode); - pNode->SetFlag(XFA_NodeFlag_Initialized, true); - pNode = sIterator.MoveToNext(); - } + + if (bEmptyForm) + return; + + CXFA_NodeIteratorTemplate sIterator( + pFormRoot); + CXFA_Node* pNode = sIterator.MoveToNext(); + while (pNode) { + if (pNode->IsUnusedNode()) { + if (pNode->IsContainerNode() || + pNode->GetElementType() == XFA_Element::InstanceManager) { + CXFA_Node* pNext = sIterator.SkipChildrenAndMoveToNext(); + pNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pNode); + pNode = pNext; } else { + pNode->ClearFlag(XFA_NodeFlag_UnusedNode); pNode->SetFlag(XFA_NodeFlag_Initialized, true); pNode = sIterator.MoveToNext(); } + } else { + pNode->SetFlag(XFA_NodeFlag_Initialized, true); + pNode = sIterator.MoveToNext(); } } } + void CXFA_Document::DoDataRemerge(FX_BOOL bDoDataMerge) { CXFA_Node* pFormRoot = ToNode(GetXFAObject(XFA_HASHCODE_Form)); if (pFormRoot) { - while (CXFA_Node* pNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) { + while (CXFA_Node* pNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) pFormRoot->RemoveChild(pNode); - } pFormRoot->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); } - XFA_DataMerge_ClearGlobalBinding(this); - if (bDoDataMerge) { + m_rgGlobalBinding.RemoveAll(); + if (bDoDataMerge) DoDataMerge(); - } + CXFA_LayoutProcessor* pLayoutProcessor = GetLayoutProcessor(); pLayoutProcessor->SetForceReLayout(TRUE); } diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.h b/xfa/fxfa/parser/xfa_document_datamerger_imp.h index a31bb3fd15..f97a7b43b9 100644 --- a/xfa/fxfa/parser/xfa_document_datamerger_imp.h +++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.h @@ -9,12 +9,11 @@ #include "xfa/fxfa/parser/xfa_object.h" -CXFA_Node* XFA_NodeMerge_CloneOrMergeContainer( - CXFA_Document* pDocument, - CXFA_Node* pFormParent, - CXFA_Node* pTemplateNode, - FX_BOOL bRecursive, - CXFA_NodeArray* pSubformArray = nullptr); +CXFA_Node* XFA_NodeMerge_CloneOrMergeContainer(CXFA_Document* pDocument, + CXFA_Node* pFormParent, + CXFA_Node* pTemplateNode, + FX_BOOL bRecursive, + CXFA_NodeArray* pSubformArray); CXFA_Node* XFA_DataMerge_FindDataScope(CXFA_Node* pParentFormNode); CXFA_Node* XFA_DataMerge_FindFormDOMInstance(CXFA_Document* pDocument, XFA_Element eType, diff --git a/xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp b/xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp index 2ade051a81..117e1cec8e 100644 --- a/xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp +++ b/xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp @@ -1698,7 +1698,8 @@ void CXFA_LayoutPageMgr::MergePageSetContents() { case XFA_Element::PageSet: { CXFA_Node* pParentNode = pContainerItem->m_pParent->m_pFormNode; pContainerItem->m_pFormNode = XFA_NodeMerge_CloneOrMergeContainer( - pDocument, pParentNode, pContainerItem->m_pFormNode, TRUE); + pDocument, pParentNode, pContainerItem->m_pFormNode, TRUE, + nullptr); } break; case XFA_Element::PageArea: { CXFA_ContainerLayoutItem* pFormLayout = pContainerItem; -- cgit v1.2.3