void CScript_LayoutPseudoModel::GetObjArray(CXFA_LayoutProcessor* pDocLayout, int32_t iPageNo, const CFX_WideString& wsType, FX_BOOL bOnPageArea, CXFA_NodeArray& retArray) { CXFA_ContainerLayoutItem* pLayoutPage = pDocLayout->GetPage(iPageNo); if (!pLayoutPage) { return; } if (wsType == FX_WSTRC(L"pageArea")) { if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { retArray.Add(pMasterPage); } return; } if (wsType == FX_WSTRC(L"contentArea")) { for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; pItem = pItem->m_pNextSibling) { if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { retArray.Add(pItem->m_pFormNode); } } return; } std::set<CXFA_Node*> formItems; if (wsType.IsEmpty()) { if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { retArray.Add(pMasterPage); } for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; pItem = pItem->m_pNextSibling) { if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { retArray.Add(pItem->m_pFormNode); if (!bOnPageArea) { CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, CXFA_TraverseStrategy_ContentLayoutItem> iterator(static_cast<CXFA_ContentLayoutItem*>(pItem->m_pFirstChild)); for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) { if (!pItemChild->IsContentLayoutItem()) { continue; } XFA_Element eType = pItemChild->m_pFormNode->GetElementType(); if (eType != XFA_Element::Field && eType != XFA_Element::Draw && eType != XFA_Element::Subform && eType != XFA_Element::Area) { continue; } if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) continue; formItems.insert(pItemChild->m_pFormNode); retArray.Add(pItemChild->m_pFormNode); } } } else { if (bOnPageArea) { CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, CXFA_TraverseStrategy_ContentLayoutItem> iterator(static_cast<CXFA_ContentLayoutItem*>(pItem)); for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) { if (!pItemChild->IsContentLayoutItem()) { continue; } XFA_Element eType = pItemChild->m_pFormNode->GetElementType(); if (eType != XFA_Element::Field && eType != XFA_Element::Draw && eType != XFA_Element::Subform && eType != XFA_Element::Area) { continue; } if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) continue; formItems.insert(pItemChild->m_pFormNode); retArray.Add(pItemChild->m_pFormNode); } } } } return; } XFA_Element eType = XFA_Element::Unknown; if (wsType == FX_WSTRC(L"field")) { eType = XFA_Element::Field; } else if (wsType == FX_WSTRC(L"draw")) { eType = XFA_Element::Draw; } else if (wsType == FX_WSTRC(L"subform")) { eType = XFA_Element::Subform; } else if (wsType == FX_WSTRC(L"area")) { eType = XFA_Element::Area; } if (eType != XFA_Element::Unknown) { for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; pItem = pItem->m_pNextSibling) { if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { if (!bOnPageArea) { CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, CXFA_TraverseStrategy_ContentLayoutItem> iterator(static_cast<CXFA_ContentLayoutItem*>(pItem->m_pFirstChild)); for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) { if (!pItemChild->IsContentLayoutItem()) continue; if (pItemChild->m_pFormNode->GetElementType() != eType) continue; if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) continue; formItems.insert(pItemChild->m_pFormNode); retArray.Add(pItemChild->m_pFormNode); } } } else { if (bOnPageArea) { CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, CXFA_TraverseStrategy_ContentLayoutItem> iterator(static_cast<CXFA_ContentLayoutItem*>(pItem)); for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) { if (!pItemChild->IsContentLayoutItem()) continue; if (pItemChild->m_pFormNode->GetElementType() != eType) continue; if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) continue; formItems.insert(pItemChild->m_pFormNode); retArray.Add(pItemChild->m_pFormNode); } } } } return; } }
int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_Normal( CXFA_ResolveNodesData& rnd) { if (rnd.m_nLevel > 32) { return 0; } if (!rnd.m_CurNode->IsNode()) { return 0; } CXFA_Node* curNode = ToNode(rnd.m_CurNode); CXFA_ObjArray& nodes = rnd.m_Nodes; int32_t nNum = nodes.GetSize(); FX_DWORD dwStyles = rnd.m_dwStyles; CFX_WideString& wsName = rnd.m_wsName; uint32_t uNameHash = rnd.m_uHashName; CFX_WideString& wsCondition = rnd.m_wsCondition; CXFA_ResolveNodesData rndFind; rndFind.m_wsName = rnd.m_wsName; rndFind.m_wsCondition = rnd.m_wsCondition; rndFind.m_pSC = rnd.m_pSC; rndFind.m_nLevel = rnd.m_nLevel + 1; rndFind.m_uHashName = uNameHash; CXFA_NodeArray children; CXFA_NodeArray properties; CXFA_Node* pVariablesNode = NULL; CXFA_Node* pPageSetNode = NULL; CXFA_Node* pChild = curNode->GetNodeItem(XFA_NODEITEM_FirstChild); while (pChild) { if (pChild->GetClassID() == XFA_ELEMENT_Variables) { pVariablesNode = pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); continue; } else if (pChild->GetClassID() == XFA_ELEMENT_PageSet) { pPageSetNode = pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); continue; } else { XFA_LPCPROPERTY pPropert = XFA_GetPropertyOfElement( curNode->GetClassID(), pChild->GetClassID(), XFA_XDPPACKET_UNKNOWN); if (pPropert) { properties.Add(pChild); } else { children.Add(pChild); } } pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); } if ((dwStyles & XFA_RESOLVENODE_Properties) && pVariablesNode) { uint32_t uPropHash = pVariablesNode->GetClassHashCode(); if (uPropHash == uNameHash) { nodes.Add(pVariablesNode); } else { rndFind.m_CurNode = pVariablesNode; XFA_ResolveNodes_SetStylesForChild(dwStyles, rndFind); CFX_WideString wsSaveCondition = rndFind.m_wsCondition; rndFind.m_wsCondition.Empty(); XFA_ResolveNodes_Normal(rndFind); rndFind.m_wsCondition = wsSaveCondition; if (rndFind.m_Nodes.GetSize() > 0) { nodes.Append(rndFind.m_Nodes); rndFind.m_Nodes.RemoveAll(); } } if (nodes.GetSize() > nNum) { XFA_ResolveNode_FilterCondition(rnd, wsCondition); if (nodes.GetSize() > 0) { return 1; } return 0; } } if (dwStyles & XFA_RESOLVENODE_Children) { FX_BOOL bSetFlag = FALSE; if (pPageSetNode && (dwStyles & XFA_RESOLVENODE_Properties)) { children.Add(pPageSetNode); } for (int32_t i = 0; i < children.GetSize(); i++) { CXFA_Node* child = children[i]; if (dwStyles & XFA_RESOLVENODE_TagName) { if (child->GetClassHashCode() == uNameHash) { nodes.Add(child); } } else if (child->GetNameHash() == uNameHash) { nodes.Add(child); } if (m_pNodeHelper->XFA_NodeIsTransparent(child) && child->GetClassID() != XFA_ELEMENT_PageSet) { if (!bSetFlag) { XFA_ResolveNodes_SetStylesForChild(dwStyles, rndFind); bSetFlag = TRUE; } rndFind.m_CurNode = child; CFX_WideString wsSaveCondition = rndFind.m_wsCondition; rndFind.m_wsCondition.Empty(); XFA_ResolveNodes_Normal(rndFind); rndFind.m_wsCondition = wsSaveCondition; if (rndFind.m_Nodes.GetSize() > 0) { nodes.Append(rndFind.m_Nodes); rndFind.m_Nodes.RemoveAll(); } } } if (nodes.GetSize() > nNum) { if (!(dwStyles & XFA_RESOLVENODE_ALL)) { CXFA_NodeArray upArrayNodes; if (m_pNodeHelper->XFA_NodeIsTransparent(ToNode(curNode))) { m_pNodeHelper->XFA_CountSiblings( ToNode(nodes[0]), XFA_LOGIC_Transparent, &upArrayNodes, !!(dwStyles & XFA_RESOLVENODE_TagName)); } if (upArrayNodes.GetSize() > nodes.GetSize()) { upArrayNodes[0] = ToNode(nodes[0]); nodes.RemoveAll(); nodes.Append((CXFA_ObjArray&)upArrayNodes); upArrayNodes.RemoveAll(); } } XFA_ResolveNode_FilterCondition(rnd, wsCondition); if (nodes.GetSize() > 0) { return 1; } return 0; } } if (dwStyles & XFA_RESOLVENODE_Attributes) { if (XFA_ResolveNodes_ForAttributeRs(curNode, rnd, wsName)) { return 1; } } if (dwStyles & XFA_RESOLVENODE_Properties) { for (int32_t i = 0; i < properties.GetSize(); i++) { CXFA_Node* childProperty = properties[i]; if (childProperty->IsUnnamed()) { uint32_t uPropHash = childProperty->GetClassHashCode(); if (uPropHash == uNameHash) { nodes.Add(childProperty); } } else if (childProperty->GetNameHash() == uNameHash && childProperty->GetClassID() != XFA_ELEMENT_Extras && childProperty->GetClassID() != XFA_ELEMENT_Items) { nodes.Add(childProperty); } } if (nodes.GetSize() > nNum) { XFA_ResolveNode_FilterCondition(rnd, wsCondition); if (nodes.GetSize() > 0) { return 1; } return 0; } CXFA_Node* pProp = NULL; if (XFA_ELEMENT_Subform == curNode->GetClassID() && XFA_HASHCODE_Occur == uNameHash) { CXFA_Node* pInstanceManager = curNode->AsNode()->GetInstanceMgrOfSubform(); if (pInstanceManager) { pProp = pInstanceManager->GetProperty(0, XFA_ELEMENT_Occur, TRUE); } } else { XFA_LPCELEMENTINFO pElement = XFA_GetElementByName(wsName); if (pElement) { pProp = curNode->AsNode()->GetProperty( 0, pElement->eName, pElement->eName != XFA_ELEMENT_PageSet); } } if (pProp) { nodes.Add(pProp); return nodes.GetSize(); } } CXFA_Node* parentNode = m_pNodeHelper->XFA_ResolveNodes_GetParent( curNode->AsNode(), XFA_LOGIC_NoTransparent); uint32_t uCurClassHash = curNode->GetClassHashCode(); if (!parentNode) { if (uCurClassHash == uNameHash) { nodes.Add(curNode->AsNode()); XFA_ResolveNode_FilterCondition(rnd, wsCondition); if (nodes.GetSize() > 0) { return 1; } } return 0; } if (dwStyles & XFA_RESOLVENODE_Siblings) { CXFA_Node* child = parentNode->GetNodeItem(XFA_NODEITEM_FirstChild); FX_DWORD dwSubStyles = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties; if (dwStyles & XFA_RESOLVENODE_TagName) { dwSubStyles |= XFA_RESOLVENODE_TagName; } if (dwStyles & XFA_RESOLVENODE_ALL) { dwSubStyles |= XFA_RESOLVENODE_ALL; } rndFind.m_dwStyles = dwSubStyles; while (child) { if (child == curNode) { if (dwStyles & XFA_RESOLVENODE_TagName) { if (uCurClassHash == uNameHash) { nodes.Add(curNode); } } else { if (child->GetNameHash() == uNameHash) { nodes.Add(curNode); if (rnd.m_nLevel == 0 && wsCondition.GetLength() == 0) { nodes.RemoveAll(); nodes.Add(curNode); return 1; } } } child = child->GetNodeItem(XFA_NODEITEM_NextSibling); continue; } if (dwStyles & XFA_RESOLVENODE_TagName) { if (child->GetClassHashCode() == uNameHash) { nodes.Add(child); } } else if (child->GetNameHash() == uNameHash) { nodes.Add(child); } XFA_LPCPROPERTY pPropert = XFA_GetPropertyOfElement( parentNode->GetClassID(), child->GetClassID(), XFA_XDPPACKET_UNKNOWN); FX_BOOL bInnerSearch = FALSE; if (pPropert) { if ((child->GetClassID() == XFA_ELEMENT_Variables || child->GetClassID() == XFA_ELEMENT_PageSet)) { bInnerSearch = TRUE; } } else { if (m_pNodeHelper->XFA_NodeIsTransparent(child)) { bInnerSearch = TRUE; } } if (bInnerSearch) { rndFind.m_CurNode = child; CFX_WideString wsOriginCondition = rndFind.m_wsCondition; rndFind.m_wsCondition.Empty(); FX_DWORD dwOriginStyle = rndFind.m_dwStyles; rndFind.m_dwStyles = dwOriginStyle | XFA_RESOLVENODE_ALL; XFA_ResolveNodes_Normal(rndFind); rndFind.m_dwStyles = dwOriginStyle; rndFind.m_wsCondition = wsOriginCondition; if (rndFind.m_Nodes.GetSize() > 0) { nodes.Append(rndFind.m_Nodes); rndFind.m_Nodes.RemoveAll(); } } child = child->GetNodeItem(XFA_NODEITEM_NextSibling); } if (nodes.GetSize() > nNum) { if (m_pNodeHelper->XFA_NodeIsTransparent(parentNode)) { CXFA_NodeArray upArrayNodes; m_pNodeHelper->XFA_CountSiblings( ToNode(nodes[0]), XFA_LOGIC_Transparent, &upArrayNodes, !!(dwStyles & XFA_RESOLVENODE_TagName)); if (upArrayNodes.GetSize() > nodes.GetSize()) { upArrayNodes[0] = ToNode(nodes[0]); nodes.RemoveAll(); nodes.Append((CXFA_ObjArray&)upArrayNodes); upArrayNodes.RemoveAll(); } } XFA_ResolveNode_FilterCondition(rnd, wsCondition); if (nodes.GetSize() > 0) { return 1; } return 0; } } if (dwStyles & XFA_RESOLVENODE_Parent) { FX_DWORD dwSubStyles = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Properties; if (dwStyles & XFA_RESOLVENODE_TagName) { dwSubStyles |= XFA_RESOLVENODE_TagName; } if (dwStyles & XFA_RESOLVENODE_ALL) { dwSubStyles |= XFA_RESOLVENODE_ALL; } rndFind.m_dwStyles = dwSubStyles; rndFind.m_CurNode = parentNode; CXFA_NodeArray& array = rnd.m_pSC->GetUpObjectArray(); array.Add(parentNode); XFA_ResolveNodes_Normal(rndFind); if (rndFind.m_Nodes.GetSize() > 0) { nodes.Append(rndFind.m_Nodes); rndFind.m_Nodes.RemoveAll(); } if (nodes.GetSize() > nNum) { return 1; } } return 0; }
void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_GetObjArray( IXFA_DocLayout* pDocLayout, int32_t iPageNo, const CFX_WideString& wsType, FX_BOOL bOnPageArea, CXFA_NodeArray& retArray) { CXFA_ContainerLayoutItem* pLayoutPage = (CXFA_ContainerLayoutItem*)pDocLayout->GetPage(iPageNo); if (!pLayoutPage) { return; } if (wsType == FX_WSTRC(L"pageArea")) { if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { retArray.Add(pMasterPage); } return; } if (wsType == FX_WSTRC(L"contentArea")) { for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; pItem = pItem->m_pNextSibling) { if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) { retArray.Add(pItem->m_pFormNode); } } return; } CFX_MapPtrToPtr formItems; formItems.InitHashTable(256, TRUE); if (wsType.IsEmpty()) { if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { retArray.Add(pMasterPage); } for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; pItem = pItem->m_pNextSibling) { if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) { retArray.Add(pItem->m_pFormNode); if (!bOnPageArea) { CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, CXFA_TraverseStrategy_ContentLayoutItem> iterator((CXFA_ContentLayoutItem*)pItem->m_pFirstChild); for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) { if (!pItemChild->IsContentLayoutItem()) { continue; } XFA_ELEMENT eElementType = pItemChild->m_pFormNode->GetClassID(); if (eElementType != XFA_ELEMENT_Field && eElementType != XFA_ELEMENT_Draw && eElementType != XFA_ELEMENT_Subform && eElementType != XFA_ELEMENT_Area) { continue; } if (formItems.GetValueAt(pItemChild->m_pFormNode)) { continue; } formItems.SetAt(pItemChild->m_pFormNode, this); retArray.Add(pItemChild->m_pFormNode); } } } else { if (bOnPageArea) { CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, CXFA_TraverseStrategy_ContentLayoutItem> iterator((CXFA_ContentLayoutItem*)pItem); for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) { if (!pItemChild->IsContentLayoutItem()) { continue; } XFA_ELEMENT eElementType = pItemChild->m_pFormNode->GetClassID(); if (eElementType != XFA_ELEMENT_Field && eElementType != XFA_ELEMENT_Draw && eElementType != XFA_ELEMENT_Subform && eElementType != XFA_ELEMENT_Area) { continue; } if (formItems.GetValueAt(pItemChild->m_pFormNode)) { continue; } formItems.SetAt(pItemChild->m_pFormNode, this); retArray.Add(pItemChild->m_pFormNode); } } } } return; } XFA_ELEMENT eType = XFA_ELEMENT_UNKNOWN; if (wsType == FX_WSTRC(L"field")) { eType = XFA_ELEMENT_Field; } else if (wsType == FX_WSTRC(L"draw")) { eType = XFA_ELEMENT_Draw; } else if (wsType == FX_WSTRC(L"subform")) { eType = XFA_ELEMENT_Subform; } else if (wsType == FX_WSTRC(L"area")) { eType = XFA_ELEMENT_Area; } if (eType != XFA_ELEMENT_UNKNOWN) { for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; pItem = pItem->m_pNextSibling) { if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) { if (!bOnPageArea) { CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, CXFA_TraverseStrategy_ContentLayoutItem> iterator((CXFA_ContentLayoutItem*)pItem->m_pFirstChild); for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) { if (!pItemChild->IsContentLayoutItem()) { continue; } if (pItemChild->m_pFormNode->GetClassID() != eType) { continue; } if (formItems.GetValueAt(pItemChild->m_pFormNode)) { continue; } formItems.SetAt(pItemChild->m_pFormNode, this); retArray.Add(pItemChild->m_pFormNode); } } } else { if (bOnPageArea) { CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, CXFA_TraverseStrategy_ContentLayoutItem> iterator((CXFA_ContentLayoutItem*)pItem); for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) { if (!pItemChild->IsContentLayoutItem()) { continue; } if (pItemChild->m_pFormNode->GetClassID() != eType) { continue; } if (formItems.GetValueAt(pItemChild->m_pFormNode)) { continue; } formItems.SetAt(pItemChild->m_pFormNode, this); retArray.Add(pItemChild->m_pFormNode); } } } } return; } }