dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
| 7 | #include "xfa/fxfa/parser/xfa_object.h" |
| 8 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 9 | #include <map> |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 10 | #include <memory> |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 11 | #include <utility> |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 12 | |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 13 | #include "core/fxcrt/fx_ext.h" |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 14 | #include "fxjs/cfxjse_value.h" |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 15 | #include "third_party/base/stl_util.h" |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 16 | #include "xfa/fde/xml/fde_xml_imp.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 17 | #include "xfa/fgas/crt/fgas_codepage.h" |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 18 | #include "xfa/fxfa/app/xfa_ffnotify.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 19 | #include "xfa/fxfa/cxfa_eventparam.h" |
dsinclair | 1628024 | 2016-07-21 12:03:47 -0700 | [diff] [blame] | 20 | #include "xfa/fxfa/parser/cxfa_document.h" |
dsinclair | 0b851ff | 2016-07-21 12:03:01 -0700 | [diff] [blame] | 21 | #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 22 | #include "xfa/fxfa/parser/cxfa_measurement.h" |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 23 | #include "xfa/fxfa/parser/cxfa_occur.h" |
dsinclair | 31f8740 | 2016-07-20 06:34:45 -0700 | [diff] [blame] | 24 | #include "xfa/fxfa/parser/cxfa_scriptcontext.h" |
dsinclair | 34f86b0 | 2016-07-11 08:42:33 -0700 | [diff] [blame] | 25 | #include "xfa/fxfa/parser/cxfa_simple_parser.h" |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 26 | #include "xfa/fxfa/parser/xfa_basic_data.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 27 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 28 | namespace { |
| 29 | |
| 30 | void XFA_DeleteWideString(void* pData) { |
| 31 | delete static_cast<CFX_WideString*>(pData); |
| 32 | } |
| 33 | |
| 34 | void XFA_CopyWideString(void*& pData) { |
| 35 | if (pData) { |
| 36 | CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData); |
| 37 | pData = pNewData; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString, |
| 42 | XFA_CopyWideString}; |
| 43 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 44 | void XFA_DataNodeDeleteBindItem(void* pData) { |
| 45 | delete static_cast<CXFA_NodeArray*>(pData); |
| 46 | } |
| 47 | |
| 48 | XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = { |
| 49 | XFA_DataNodeDeleteBindItem, nullptr}; |
| 50 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 51 | int32_t GetCount(CXFA_Node* pInstMgrNode) { |
| 52 | ASSERT(pInstMgrNode); |
| 53 | int32_t iCount = 0; |
| 54 | uint32_t dwNameHash = 0; |
| 55 | for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 56 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 57 | XFA_Element eCurType = pNode->GetElementType(); |
| 58 | if (eCurType == XFA_Element::InstanceManager) |
| 59 | break; |
| 60 | if ((eCurType != XFA_Element::Subform) && |
| 61 | (eCurType != XFA_Element::SubformSet)) { |
| 62 | continue; |
| 63 | } |
| 64 | if (iCount == 0) { |
| 65 | CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 66 | CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name); |
| 67 | if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || |
| 68 | wsInstName.Mid(1) != wsName) { |
| 69 | return iCount; |
| 70 | } |
| 71 | dwNameHash = pNode->GetNameHash(); |
| 72 | } |
| 73 | if (dwNameHash != pNode->GetNameHash()) |
| 74 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 75 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 76 | iCount++; |
| 77 | } |
| 78 | return iCount; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 79 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 80 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 81 | void SortNodeArrayByDocumentIdx(const CXFA_NodeSet& rgNodeSet, |
| 82 | CXFA_NodeArray& rgNodeArray, |
| 83 | CFX_ArrayTemplate<int32_t>& rgIdxArray) { |
| 84 | int32_t iCount = pdfium::CollectionSize<int32_t>(rgNodeSet); |
| 85 | rgNodeArray.SetSize(iCount); |
| 86 | rgIdxArray.SetSize(iCount); |
| 87 | if (iCount == 0) |
| 88 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 89 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 90 | int32_t iIndex = -1; |
| 91 | int32_t iTotalIndex = -1; |
| 92 | CXFA_Node* pCommonParent = |
| 93 | (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent); |
| 94 | for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 95 | pNode && iIndex < iCount; |
| 96 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 97 | iTotalIndex++; |
| 98 | if (pdfium::ContainsValue(rgNodeSet, pNode)) { |
| 99 | iIndex++; |
| 100 | rgNodeArray[iIndex] = pNode; |
| 101 | rgIdxArray[iIndex] = iTotalIndex; |
| 102 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 103 | } |
| 104 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 105 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 106 | using CXFA_NodeSetPair = std::pair<CXFA_NodeSet, CXFA_NodeSet>; |
| 107 | using CXFA_NodeSetPairMap = |
| 108 | std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>; |
| 109 | using CXFA_NodeSetPairMapMap = |
| 110 | std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>; |
| 111 | |
| 112 | CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode, |
| 113 | CXFA_NodeSetPairMapMap* pMap) { |
| 114 | CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 115 | uint32_t dwNameHash = pNode->GetNameHash(); |
| 116 | if (!pParentNode || !dwNameHash) |
| 117 | return nullptr; |
| 118 | |
| 119 | if (!(*pMap)[pParentNode]) |
| 120 | (*pMap)[pParentNode].reset(new CXFA_NodeSetPairMap); |
| 121 | |
| 122 | CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get(); |
| 123 | if (!(*pNodeSetPairMap)[dwNameHash]) |
| 124 | (*pNodeSetPairMap)[dwNameHash].reset(new CXFA_NodeSetPair); |
| 125 | |
| 126 | return (*pNodeSetPairMap)[dwNameHash].get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 127 | } |
| 128 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 129 | void ReorderDataNodes(const CXFA_NodeSet& sSet1, |
| 130 | const CXFA_NodeSet& sSet2, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 131 | bool bInsertBefore) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 132 | CXFA_NodeSetPairMapMap rgMap; |
| 133 | for (CXFA_Node* pNode : sSet1) { |
| 134 | CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap); |
| 135 | if (pNodeSetPair) |
| 136 | pNodeSetPair->first.insert(pNode); |
| 137 | } |
| 138 | for (CXFA_Node* pNode : sSet2) { |
| 139 | CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap); |
| 140 | if (pNodeSetPair) { |
| 141 | if (pdfium::ContainsValue(pNodeSetPair->first, pNode)) |
| 142 | pNodeSetPair->first.erase(pNode); |
| 143 | else |
| 144 | pNodeSetPair->second.insert(pNode); |
| 145 | } |
| 146 | } |
| 147 | for (const auto& iter1 : rgMap) { |
| 148 | CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get(); |
| 149 | if (!pNodeSetPairMap) |
| 150 | continue; |
| 151 | |
| 152 | for (const auto& iter2 : *pNodeSetPairMap) { |
| 153 | CXFA_NodeSetPair* pNodeSetPair = iter2.second.get(); |
| 154 | if (!pNodeSetPair) |
| 155 | continue; |
| 156 | if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) { |
| 157 | CXFA_NodeArray rgNodeArray1; |
| 158 | CXFA_NodeArray rgNodeArray2; |
| 159 | CFX_ArrayTemplate<int32_t> rgIdxArray1; |
| 160 | CFX_ArrayTemplate<int32_t> rgIdxArray2; |
| 161 | SortNodeArrayByDocumentIdx(pNodeSetPair->first, rgNodeArray1, |
| 162 | rgIdxArray1); |
| 163 | SortNodeArrayByDocumentIdx(pNodeSetPair->second, rgNodeArray2, |
| 164 | rgIdxArray2); |
| 165 | CXFA_Node* pParentNode = nullptr; |
| 166 | CXFA_Node* pBeforeNode = nullptr; |
| 167 | if (bInsertBefore) { |
| 168 | pBeforeNode = rgNodeArray2[0]; |
| 169 | pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 170 | } else { |
| 171 | CXFA_Node* pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1]; |
| 172 | pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 173 | pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 174 | } |
| 175 | for (int32_t iIdx = 0; iIdx < rgIdxArray1.GetSize(); iIdx++) { |
| 176 | CXFA_Node* pCurNode = rgNodeArray1[iIdx]; |
| 177 | pParentNode->RemoveChild(pCurNode); |
| 178 | pParentNode->InsertChild(pCurNode, pBeforeNode); |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | pNodeSetPairMap->clear(); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) { |
| 187 | ASSERT(pInstMgrNode); |
| 188 | int32_t iCount = 0; |
| 189 | uint32_t dwNameHash = 0; |
| 190 | for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 191 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 192 | XFA_Element eCurType = pNode->GetElementType(); |
| 193 | if (eCurType == XFA_Element::InstanceManager) |
| 194 | break; |
| 195 | if ((eCurType != XFA_Element::Subform) && |
| 196 | (eCurType != XFA_Element::SubformSet)) { |
| 197 | continue; |
| 198 | } |
| 199 | if (iCount == 0) { |
| 200 | CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 201 | CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name); |
| 202 | if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || |
| 203 | wsInstName.Mid(1) != wsName) { |
| 204 | return nullptr; |
| 205 | } |
| 206 | dwNameHash = pNode->GetNameHash(); |
| 207 | } |
| 208 | if (dwNameHash != pNode->GetNameHash()) |
| 209 | break; |
| 210 | |
| 211 | iCount++; |
| 212 | if (iCount > iIndex) |
| 213 | return pNode; |
| 214 | } |
| 215 | return nullptr; |
| 216 | } |
| 217 | |
| 218 | void InsertItem(CXFA_Node* pInstMgrNode, |
| 219 | CXFA_Node* pNewInstance, |
| 220 | int32_t iPos, |
| 221 | int32_t iCount = -1, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 222 | bool bMoveDataBindingNodes = true) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 223 | if (iCount < 0) |
| 224 | iCount = GetCount(pInstMgrNode); |
| 225 | if (iPos < 0) |
| 226 | iPos = iCount; |
| 227 | if (iPos == iCount) { |
| 228 | CXFA_Node* pNextSibling = |
| 229 | iCount > 0 |
| 230 | ? GetItem(pInstMgrNode, iCount - 1) |
| 231 | ->GetNodeItem(XFA_NODEITEM_NextSibling) |
| 232 | : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 233 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent) |
| 234 | ->InsertChild(pNewInstance, pNextSibling); |
| 235 | if (bMoveDataBindingNodes) { |
| 236 | CXFA_NodeSet sNew; |
| 237 | CXFA_NodeSet sAfter; |
| 238 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 239 | CXFA_TraverseStrategy_XFAContainerNode> |
| 240 | sIteratorNew(pNewInstance); |
| 241 | for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode; |
| 242 | pNode = sIteratorNew.MoveToNext()) { |
| 243 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 244 | if (!pDataNode) |
| 245 | continue; |
| 246 | |
| 247 | sNew.insert(pDataNode); |
| 248 | } |
| 249 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 250 | CXFA_TraverseStrategy_XFAContainerNode> |
| 251 | sIteratorAfter(pNextSibling); |
| 252 | for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode; |
| 253 | pNode = sIteratorAfter.MoveToNext()) { |
| 254 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 255 | if (!pDataNode) |
| 256 | continue; |
| 257 | |
| 258 | sAfter.insert(pDataNode); |
| 259 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 260 | ReorderDataNodes(sNew, sAfter, false); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 261 | } |
| 262 | } else { |
| 263 | CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos); |
| 264 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent) |
| 265 | ->InsertChild(pNewInstance, pBeforeInstance); |
| 266 | if (bMoveDataBindingNodes) { |
| 267 | CXFA_NodeSet sNew; |
| 268 | CXFA_NodeSet sBefore; |
| 269 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 270 | CXFA_TraverseStrategy_XFAContainerNode> |
| 271 | sIteratorNew(pNewInstance); |
| 272 | for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode; |
| 273 | pNode = sIteratorNew.MoveToNext()) { |
| 274 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 275 | if (!pDataNode) |
| 276 | continue; |
| 277 | |
| 278 | sNew.insert(pDataNode); |
| 279 | } |
| 280 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 281 | CXFA_TraverseStrategy_XFAContainerNode> |
| 282 | sIteratorBefore(pBeforeInstance); |
| 283 | for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode; |
| 284 | pNode = sIteratorBefore.MoveToNext()) { |
| 285 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 286 | if (!pDataNode) |
| 287 | continue; |
| 288 | |
| 289 | sBefore.insert(pDataNode); |
| 290 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 291 | ReorderDataNodes(sNew, sBefore, true); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | void RemoveItem(CXFA_Node* pInstMgrNode, |
| 297 | CXFA_Node* pRemoveInstance, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 298 | bool bRemoveDataBinding = true) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 299 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance); |
| 300 | if (!bRemoveDataBinding) |
| 301 | return; |
| 302 | |
| 303 | CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> |
| 304 | sIterator(pRemoveInstance); |
| 305 | for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode; |
| 306 | pFormNode = sIterator.MoveToNext()) { |
| 307 | CXFA_Node* pDataNode = pFormNode->GetBindData(); |
| 308 | if (!pDataNode) |
| 309 | continue; |
| 310 | |
| 311 | if (pDataNode->RemoveBindItem(pFormNode) == 0) { |
| 312 | if (CXFA_Node* pDataParent = |
| 313 | pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) { |
| 314 | pDataParent->RemoveChild(pDataNode); |
| 315 | } |
| 316 | } |
| 317 | pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
| 318 | } |
| 319 | } |
| 320 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 321 | CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 322 | CXFA_Document* pDocument = pInstMgrNode->GetDocument(); |
| 323 | CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode(); |
| 324 | CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 325 | CXFA_Node* pDataScope = nullptr; |
| 326 | for (CXFA_Node* pRootBoundNode = pFormParent; |
| 327 | pRootBoundNode && pRootBoundNode->IsContainerNode(); |
| 328 | pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) { |
| 329 | pDataScope = pRootBoundNode->GetBindData(); |
| 330 | if (pDataScope) |
| 331 | break; |
| 332 | } |
| 333 | if (!pDataScope) { |
| 334 | pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record)); |
| 335 | ASSERT(pDataScope); |
| 336 | } |
| 337 | CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 338 | pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 339 | if (pInstance) { |
| 340 | pDocument->DataMerge_UpdateBindingRelations(pInstance); |
| 341 | pFormParent->RemoveChild(pInstance); |
| 342 | } |
| 343 | return pInstance; |
| 344 | } |
| 345 | |
| 346 | struct XFA_ExecEventParaInfo { |
| 347 | public: |
| 348 | uint32_t m_uHash; |
| 349 | const FX_WCHAR* m_lpcEventName; |
| 350 | XFA_EVENTTYPE m_eventType; |
| 351 | uint32_t m_validFlags; |
| 352 | }; |
| 353 | static const XFA_ExecEventParaInfo gs_eventParaInfos[] = { |
| 354 | {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0}, |
| 355 | {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0}, |
| 356 | {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5}, |
| 357 | {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0}, |
| 358 | {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7}, |
| 359 | {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1}, |
| 360 | {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5}, |
| 361 | {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0}, |
| 362 | {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0}, |
| 363 | {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6}, |
| 364 | {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2}, |
| 365 | {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0}, |
| 366 | {0x7233018a, L"validate", XFA_EVENT_Validate, 1}, |
| 367 | {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3}, |
| 368 | {0x891f4606, L"change", XFA_EVENT_Change, 4}, |
| 369 | {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0}, |
| 370 | {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5}, |
| 371 | {0xcdce56b3, L"full", XFA_EVENT_Full, 4}, |
| 372 | {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5}, |
| 373 | {0xd95657a6, L"click", XFA_EVENT_Click, 4}, |
| 374 | {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1}, |
| 375 | {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7}, |
| 376 | {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2}, |
| 377 | {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0}, |
| 378 | {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6}, |
| 379 | }; |
| 380 | |
| 381 | const XFA_ExecEventParaInfo* GetEventParaInfoByName( |
| 382 | const CFX_WideStringC& wsEventName) { |
| 383 | uint32_t uHash = FX_HashCode_GetW(wsEventName, false); |
| 384 | int32_t iStart = 0; |
| 385 | int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1; |
| 386 | do { |
| 387 | int32_t iMid = (iStart + iEnd) / 2; |
| 388 | const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid]; |
| 389 | if (uHash == eventParaInfo->m_uHash) |
| 390 | return eventParaInfo; |
| 391 | if (uHash < eventParaInfo->m_uHash) |
| 392 | iEnd = iMid - 1; |
| 393 | else |
| 394 | iStart = iMid + 1; |
| 395 | } while (iStart <= iEnd); |
| 396 | return nullptr; |
| 397 | } |
| 398 | |
| 399 | void StrToRGB(const CFX_WideString& strRGB, |
| 400 | int32_t& r, |
| 401 | int32_t& g, |
| 402 | int32_t& b) { |
| 403 | r = 0; |
| 404 | g = 0; |
| 405 | b = 0; |
| 406 | |
| 407 | FX_WCHAR zero = '0'; |
| 408 | int32_t iIndex = 0; |
| 409 | int32_t iLen = strRGB.GetLength(); |
| 410 | for (int32_t i = 0; i < iLen; ++i) { |
| 411 | FX_WCHAR ch = strRGB.GetAt(i); |
| 412 | if (ch == L',') |
| 413 | ++iIndex; |
| 414 | if (iIndex > 2) |
| 415 | break; |
| 416 | |
| 417 | int32_t iValue = ch - zero; |
| 418 | if (iValue >= 0 && iValue <= 9) { |
| 419 | switch (iIndex) { |
| 420 | case 0: |
| 421 | r = r * 10 + iValue; |
| 422 | break; |
| 423 | case 1: |
| 424 | g = g * 10 + iValue; |
| 425 | break; |
| 426 | default: |
| 427 | b = b * 10 + iValue; |
| 428 | break; |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | enum XFA_KEYTYPE { |
| 435 | XFA_KEYTYPE_Custom, |
| 436 | XFA_KEYTYPE_Element, |
| 437 | }; |
| 438 | |
| 439 | void* GetMapKey_Custom(const CFX_WideStringC& wsKey) { |
| 440 | uint32_t dwKey = FX_HashCode_GetW(wsKey, false); |
| 441 | return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom); |
| 442 | } |
| 443 | |
| 444 | void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) { |
| 445 | return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) | |
| 446 | (eAttribute << 8) | XFA_KEYTYPE_Element); |
| 447 | } |
| 448 | |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 449 | const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement, |
| 450 | XFA_ATTRIBUTE eAttribute, |
| 451 | uint32_t dwPacket) { |
| 452 | int32_t iCount = 0; |
| 453 | const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount); |
| 454 | if (!pAttr || iCount < 1) |
| 455 | return nullptr; |
| 456 | |
| 457 | if (!std::binary_search(pAttr, pAttr + iCount, eAttribute)) |
| 458 | return nullptr; |
| 459 | |
| 460 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); |
| 461 | ASSERT(pInfo); |
| 462 | if (dwPacket == XFA_XDPPACKET_UNKNOWN) |
| 463 | return pInfo; |
| 464 | return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr; |
| 465 | } |
| 466 | |
| 467 | const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { |
| 468 | return g_XFAEnumData + eName; |
| 469 | } |
| 470 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 471 | } // namespace |
| 472 | |
| 473 | static void XFA_DefaultFreeData(void* pData) {} |
| 474 | |
| 475 | static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = { |
| 476 | XFA_DefaultFreeData, nullptr}; |
| 477 | |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 478 | XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {} |
| 479 | |
| 480 | XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {} |
| 481 | |
dsinclair | b977847 | 2016-06-23 13:34:10 -0700 | [diff] [blame] | 482 | CXFA_Node::CXFA_Node(CXFA_Document* pDoc, |
| 483 | uint16_t ePacket, |
| 484 | XFA_ObjectType oType, |
dsinclair | c1df5d4 | 2016-07-18 06:36:51 -0700 | [diff] [blame] | 485 | XFA_Element eType, |
| 486 | const CFX_WideStringC& elementName) |
| 487 | : CXFA_Object(pDoc, oType, eType, elementName), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 488 | m_pNext(nullptr), |
| 489 | m_pChild(nullptr), |
| 490 | m_pLastChild(nullptr), |
| 491 | m_pParent(nullptr), |
| 492 | m_pXMLNode(nullptr), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 493 | m_ePacket(ePacket), |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 494 | m_uNodeFlags(XFA_NodeFlag_None), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 495 | m_dwNameHash(0), |
| 496 | m_pAuxNode(nullptr), |
| 497 | m_pMapModuleData(nullptr) { |
| 498 | ASSERT(m_pDocument); |
| 499 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 500 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 501 | CXFA_Node::~CXFA_Node() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 502 | ASSERT(!m_pParent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 503 | RemoveMapModuleKey(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 504 | CXFA_Node* pNode = m_pChild; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 505 | while (pNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 506 | CXFA_Node* pNext = pNode->m_pNext; |
| 507 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 508 | delete pNode; |
| 509 | pNode = pNext; |
| 510 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 511 | if (m_pXMLNode && IsOwnXMLNode()) |
Tom Sepez | d3743ea | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 512 | m_pXMLNode->Release(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 513 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 514 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 515 | CXFA_Node* CXFA_Node::Clone(bool bRecursive) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 516 | CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 517 | if (!pClone) |
| 518 | return nullptr; |
| 519 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 520 | MergeAllData(pClone); |
| 521 | pClone->UpdateNameHash(); |
| 522 | if (IsNeedSavingXMLNode()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 523 | CFDE_XMLNode* pCloneXML = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 524 | if (IsAttributeInXML()) { |
| 525 | CFX_WideString wsName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 526 | GetAttribute(XFA_ATTRIBUTE_Name, wsName, false); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 527 | CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 528 | CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); |
| 529 | if (!wsValue.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 530 | pCloneXMLElement->SetTextData(CFX_WideString(wsValue)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 531 | } |
| 532 | pCloneXML = pCloneXMLElement; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 533 | pCloneXMLElement = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 534 | pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); |
| 535 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 536 | pCloneXML = m_pXMLNode->Clone(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 537 | } |
| 538 | pClone->SetXMLMappingNode(pCloneXML); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 539 | pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 540 | } |
| 541 | if (bRecursive) { |
| 542 | for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; |
| 543 | pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 544 | pClone->InsertChild(pChild->Clone(bRecursive)); |
| 545 | } |
| 546 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 547 | pClone->SetFlag(XFA_NodeFlag_Initialized, true); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 548 | pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 549 | return pClone; |
| 550 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 551 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 552 | CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const { |
| 553 | switch (eItem) { |
| 554 | case XFA_NODEITEM_NextSibling: |
| 555 | return m_pNext; |
| 556 | case XFA_NODEITEM_FirstChild: |
| 557 | return m_pChild; |
| 558 | case XFA_NODEITEM_Parent: |
| 559 | return m_pParent; |
| 560 | case XFA_NODEITEM_PrevSibling: |
| 561 | if (m_pParent) { |
| 562 | CXFA_Node* pSibling = m_pParent->m_pChild; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 563 | CXFA_Node* pPrev = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 564 | while (pSibling && pSibling != this) { |
| 565 | pPrev = pSibling; |
| 566 | pSibling = pSibling->m_pNext; |
| 567 | } |
| 568 | return pPrev; |
| 569 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 570 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 571 | default: |
| 572 | break; |
| 573 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 574 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 575 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 576 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 577 | CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem, |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 578 | XFA_ObjectType eType) const { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 579 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 580 | switch (eItem) { |
| 581 | case XFA_NODEITEM_NextSibling: |
| 582 | pNode = m_pNext; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 583 | while (pNode && pNode->GetObjectType() != eType) |
| 584 | pNode = pNode->m_pNext; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 585 | break; |
| 586 | case XFA_NODEITEM_FirstChild: |
| 587 | pNode = m_pChild; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 588 | while (pNode && pNode->GetObjectType() != eType) |
| 589 | pNode = pNode->m_pNext; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 590 | break; |
| 591 | case XFA_NODEITEM_Parent: |
| 592 | pNode = m_pParent; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 593 | while (pNode && pNode->GetObjectType() != eType) |
| 594 | pNode = pNode->m_pParent; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 595 | break; |
| 596 | case XFA_NODEITEM_PrevSibling: |
| 597 | if (m_pParent) { |
| 598 | CXFA_Node* pSibling = m_pParent->m_pChild; |
| 599 | while (pSibling && pSibling != this) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 600 | if (eType == pSibling->GetObjectType()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 601 | pNode = pSibling; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 602 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 603 | pSibling = pSibling->m_pNext; |
| 604 | } |
| 605 | } |
| 606 | break; |
| 607 | default: |
| 608 | break; |
| 609 | } |
| 610 | return pNode; |
| 611 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 612 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 613 | int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 614 | uint32_t dwTypeFilter, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 615 | XFA_Element eTypeFilter, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 616 | int32_t iLevel) { |
| 617 | if (--iLevel < 0) { |
| 618 | return nodes.GetSize(); |
| 619 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 620 | if (eTypeFilter != XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 621 | CXFA_Node* pChild = m_pChild; |
| 622 | while (pChild) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 623 | if (pChild->GetElementType() == eTypeFilter) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 624 | nodes.Add(pChild); |
| 625 | if (iLevel > 0) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 626 | GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | pChild = pChild->m_pNext; |
| 630 | } |
| 631 | } else if (dwTypeFilter == |
| 632 | (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) { |
| 633 | CXFA_Node* pChild = m_pChild; |
| 634 | while (pChild) { |
| 635 | nodes.Add(pChild); |
| 636 | if (iLevel > 0) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 637 | GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 638 | } |
| 639 | pChild = pChild->m_pNext; |
| 640 | } |
| 641 | } else if (dwTypeFilter != 0) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 642 | bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children); |
| 643 | bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties); |
| 644 | bool bFilterOneOfProperties = |
| 645 | !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 646 | CXFA_Node* pChild = m_pChild; |
| 647 | while (pChild) { |
| 648 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 649 | GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 650 | if (pProperty) { |
| 651 | if (bFilterProperties) { |
| 652 | nodes.Add(pChild); |
| 653 | } else if (bFilterOneOfProperties && |
| 654 | (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) { |
| 655 | nodes.Add(pChild); |
| 656 | } else if (bFilterChildren && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 657 | (pChild->GetElementType() == XFA_Element::Variables || |
| 658 | pChild->GetElementType() == XFA_Element::PageSet)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 659 | nodes.Add(pChild); |
| 660 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 661 | } else if (bFilterChildren) { |
| 662 | nodes.Add(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 663 | } |
| 664 | pChild = pChild->m_pNext; |
| 665 | } |
| 666 | if (bFilterOneOfProperties && nodes.GetSize() < 1) { |
| 667 | int32_t iProperties = 0; |
| 668 | const XFA_PROPERTY* pProperty = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 669 | XFA_GetElementProperties(GetElementType(), iProperties); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 670 | if (!pProperty || iProperties < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 671 | return 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 672 | for (int32_t i = 0; i < iProperties; i++) { |
| 673 | if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 674 | const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID()); |
| 675 | CXFA_Node* pNewNode = |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 676 | m_pDocument->CreateNode(pPacket, pProperty[i].eName); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 677 | if (!pNewNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 678 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 679 | InsertChild(pNewNode, nullptr); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 680 | pNewNode->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 681 | nodes.Add(pNewNode); |
| 682 | break; |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | } |
| 687 | return nodes.GetSize(); |
| 688 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 689 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 690 | CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 691 | uint32_t dwFlags) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 692 | CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 693 | pNode->SetFlag(dwFlags, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 694 | return pNode; |
| 695 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 696 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 697 | CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 698 | ASSERT(m_ePacket == XFA_XDPPACKET_Template); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 699 | CXFA_Node* pClone = |
| 700 | m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 701 | if (!pClone) |
| 702 | return nullptr; |
| 703 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 704 | pClone->SetTemplateNode(this); |
| 705 | pClone->UpdateNameHash(); |
| 706 | pClone->SetXMLMappingNode(GetXMLMappingNode()); |
| 707 | if (bRecursive) { |
| 708 | for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; |
| 709 | pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 710 | pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive)); |
| 711 | } |
| 712 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 713 | pClone->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 714 | return pClone; |
| 715 | } |
| 716 | |
| 717 | CXFA_Node* CXFA_Node::GetTemplateNode() const { |
| 718 | return m_pAuxNode; |
| 719 | } |
| 720 | |
| 721 | void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) { |
| 722 | m_pAuxNode = pTemplateNode; |
| 723 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 724 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 725 | CXFA_Node* CXFA_Node::GetBindData() { |
| 726 | ASSERT(GetPacketID() == XFA_XDPPACKET_Form); |
| 727 | return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 728 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 729 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 730 | int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 731 | if (BindsFormItems()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 732 | CXFA_NodeArray* pItems = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 733 | TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); |
| 734 | formItems.Copy(*pItems); |
| 735 | return formItems.GetSize(); |
| 736 | } |
| 737 | CXFA_Node* pFormNode = |
| 738 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 739 | if (pFormNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 740 | formItems.Add(pFormNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 741 | return formItems.GetSize(); |
| 742 | } |
| 743 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 744 | int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) { |
| 745 | ASSERT(pFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 746 | if (BindsFormItems()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 747 | CXFA_NodeArray* pItems = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 748 | TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); |
| 749 | ASSERT(pItems); |
| 750 | if (pItems->Find(pFormNode) < 0) { |
| 751 | pItems->Add(pFormNode); |
| 752 | } |
| 753 | return pItems->GetSize(); |
| 754 | } |
| 755 | CXFA_Node* pOldFormItem = |
| 756 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 757 | if (!pOldFormItem) { |
| 758 | SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode); |
| 759 | return 1; |
| 760 | } else if (pOldFormItem == pFormNode) { |
| 761 | return 1; |
| 762 | } |
| 763 | CXFA_NodeArray* pItems = new CXFA_NodeArray; |
| 764 | SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack); |
| 765 | pItems->Add(pOldFormItem); |
| 766 | pItems->Add(pFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 767 | m_uNodeFlags |= XFA_NodeFlag_BindFormItems; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 768 | return 2; |
| 769 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 770 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 771 | int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 772 | if (BindsFormItems()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 773 | CXFA_NodeArray* pItems = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 774 | TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); |
| 775 | ASSERT(pItems); |
| 776 | int32_t iIndex = pItems->Find(pFormNode); |
| 777 | int32_t iCount = pItems->GetSize(); |
| 778 | if (iIndex >= 0) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 779 | if (iIndex != iCount - 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 780 | pItems->SetAt(iIndex, pItems->GetAt(iCount - 1)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 781 | pItems->RemoveAt(iCount - 1); |
| 782 | if (iCount == 2) { |
| 783 | CXFA_Node* pLastFormNode = pItems->GetAt(0); |
| 784 | SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 785 | m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 786 | } |
| 787 | iCount--; |
| 788 | } |
| 789 | return iCount; |
| 790 | } |
| 791 | CXFA_Node* pOldFormItem = |
| 792 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 793 | if (pOldFormItem == pFormNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 794 | SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
| 795 | pOldFormItem = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 796 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 797 | return pOldFormItem ? 1 : 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 798 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 799 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 800 | bool CXFA_Node::HasBindItem() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 801 | return GetPacketID() == XFA_XDPPACKET_Datasets && |
| 802 | GetObject(XFA_ATTRIBUTE_BindingNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 803 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 804 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 805 | CXFA_WidgetData* CXFA_Node::GetWidgetData() { |
| 806 | return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData); |
| 807 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 808 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 809 | CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 810 | if (GetPacketID() != XFA_XDPPACKET_Form) |
| 811 | return nullptr; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 812 | XFA_Element eType = GetElementType(); |
| 813 | if (eType == XFA_Element::ExclGroup) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 814 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 815 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 816 | if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 817 | return nullptr; |
| 818 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 819 | if (eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 820 | CXFA_WidgetData* pFieldWidgetData = GetWidgetData(); |
| 821 | if (pFieldWidgetData && |
| 822 | pFieldWidgetData->GetChoiceListOpen() == |
| 823 | XFA_ATTRIBUTEENUM_MultiSelect) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 824 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 825 | } else { |
| 826 | CFX_WideString wsPicture; |
| 827 | if (pFieldWidgetData) { |
| 828 | pFieldWidgetData->GetPictureContent(wsPicture, |
| 829 | XFA_VALUEPICTURE_DataBind); |
| 830 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 831 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 832 | return pFieldWidgetData; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 833 | CXFA_Node* pDataNode = GetBindData(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 834 | if (!pDataNode) |
| 835 | return nullptr; |
| 836 | pFieldWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 837 | CXFA_NodeArray formNodes; |
| 838 | pDataNode->GetBindItems(formNodes); |
| 839 | for (int32_t i = 0; i < formNodes.GetSize(); i++) { |
| 840 | CXFA_Node* pFormNode = formNodes.GetAt(i); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 841 | if (!pFormNode || pFormNode->HasRemovedChildren()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 842 | continue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 843 | pFieldWidgetData = pFormNode->GetWidgetData(); |
| 844 | if (pFieldWidgetData) { |
| 845 | pFieldWidgetData->GetPictureContent(wsPicture, |
| 846 | XFA_VALUEPICTURE_DataBind); |
| 847 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 848 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 849 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 850 | pFieldWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 851 | } |
| 852 | return pFieldWidgetData; |
| 853 | } |
| 854 | } |
| 855 | CXFA_Node* pGrandNode = |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 856 | pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 857 | CXFA_Node* pValueNode = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 858 | (pParentNode && pParentNode->GetElementType() == XFA_Element::Value) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 859 | ? pParentNode |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 860 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 861 | if (!pValueNode) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 862 | pValueNode = |
| 863 | (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value) |
| 864 | ? pGrandNode |
| 865 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 866 | } |
| 867 | CXFA_Node* pParentOfValueNode = |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 868 | pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 869 | return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 870 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 871 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 872 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 873 | bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 874 | CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 875 | CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 876 | ASSERT(pTopSubform); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 877 | CXFA_Node* pLocaleNode = this; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 878 | bool bLocale = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 879 | do { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 880 | bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 881 | if (!bLocale) { |
| 882 | pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 883 | } |
| 884 | } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 885 | if (bLocale) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 886 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 887 | CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config)); |
| 888 | wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 889 | if (!wsLocaleName.IsEmpty()) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 890 | return true; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 891 | if (pTopSubform && |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 892 | pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) { |
| 893 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 894 | } |
| 895 | IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale(); |
| 896 | if (pLocale) { |
| 897 | wsLocaleName = pLocale->GetName(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 898 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 899 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 900 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 901 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 902 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 903 | XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 904 | CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 905 | XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout); |
| 906 | if (pKeep) { |
| 907 | XFA_ATTRIBUTEENUM eIntact; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 908 | if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 909 | if (eIntact == XFA_ATTRIBUTEENUM_None && |
| 910 | eLayoutType == XFA_ATTRIBUTEENUM_Row && |
| 911 | m_pDocument->GetCurVersionMode() < XFA_VERSION_208) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 912 | CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling, |
| 913 | XFA_ObjectType::ContainerNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 914 | if (pPreviewRow && |
| 915 | pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) == |
| 916 | XFA_ATTRIBUTEENUM_Row) { |
| 917 | XFA_ATTRIBUTEENUM eValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 918 | if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) && |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 919 | (eValue == XFA_ATTRIBUTEENUM_ContentArea || |
| 920 | eValue == XFA_ATTRIBUTEENUM_PageArea)) { |
| 921 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 922 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 923 | CXFA_Node* pNode = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 924 | pPreviewRow->GetFirstChildByClass(XFA_Element::Keep); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 925 | if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) && |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 926 | (eValue == XFA_ATTRIBUTEENUM_ContentArea || |
| 927 | eValue == XFA_ATTRIBUTEENUM_PageArea)) { |
| 928 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 929 | } |
| 930 | } |
| 931 | } |
| 932 | return eIntact; |
| 933 | } |
| 934 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 935 | switch (GetElementType()) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 936 | case XFA_Element::Subform: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 937 | switch (eLayoutType) { |
| 938 | case XFA_ATTRIBUTEENUM_Position: |
| 939 | case XFA_ATTRIBUTEENUM_Row: |
| 940 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 941 | case XFA_ATTRIBUTEENUM_Tb: |
| 942 | case XFA_ATTRIBUTEENUM_Table: |
| 943 | case XFA_ATTRIBUTEENUM_Lr_tb: |
| 944 | case XFA_ATTRIBUTEENUM_Rl_tb: |
| 945 | return XFA_ATTRIBUTEENUM_None; |
| 946 | default: |
| 947 | break; |
| 948 | } |
| 949 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 950 | case XFA_Element::Field: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 951 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 952 | if (!pParentNode || |
| 953 | pParentNode->GetElementType() == XFA_Element::PageArea) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 954 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 955 | if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) { |
| 956 | XFA_ATTRIBUTEENUM eParLayout = |
| 957 | pParentNode->GetEnum(XFA_ATTRIBUTE_Layout); |
| 958 | if (eParLayout == XFA_ATTRIBUTEENUM_Position || |
| 959 | eParLayout == XFA_ATTRIBUTEENUM_Row || |
| 960 | eParLayout == XFA_ATTRIBUTEENUM_Table) { |
| 961 | return XFA_ATTRIBUTEENUM_None; |
| 962 | } |
| 963 | XFA_VERSION version = m_pDocument->GetCurVersionMode(); |
| 964 | if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) { |
| 965 | CXFA_Measurement measureH; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 966 | if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 967 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 968 | } |
| 969 | return XFA_ATTRIBUTEENUM_None; |
| 970 | } |
| 971 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 972 | } |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 973 | case XFA_Element::Draw: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 974 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 975 | default: |
| 976 | break; |
| 977 | } |
| 978 | return XFA_ATTRIBUTEENUM_None; |
| 979 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 980 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 981 | CXFA_Node* CXFA_Node::GetDataDescriptionNode() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 982 | if (m_ePacket == XFA_XDPPACKET_Datasets) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 983 | return m_pAuxNode; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 984 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 985 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 986 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 987 | void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 988 | ASSERT(m_ePacket == XFA_XDPPACKET_Datasets); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 989 | m_pAuxNode = pDataDescriptionNode; |
| 990 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 991 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 992 | void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) { |
| 993 | int32_t iLength = pArguments->GetLength(); |
| 994 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 995 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 996 | return; |
| 997 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 998 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 999 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1000 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1001 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1002 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1003 | CXFA_Node* refNode = this; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1004 | if (refNode->GetElementType() == XFA_Element::Xfa) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1005 | refNode = ToNode(pScriptContext->GetThisObject()); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1006 | uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1007 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1008 | XFA_RESOLVENODE_Siblings; |
| 1009 | XFA_RESOLVENODE_RS resoveNodeRS; |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 1010 | int32_t iRet = pScriptContext->ResolveObjects( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1011 | refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1012 | if (iRet < 1) { |
| 1013 | pArguments->GetReturnValue()->SetNull(); |
| 1014 | return; |
| 1015 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1016 | if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { |
| 1017 | CXFA_Object* pNode = resoveNodeRS.nodes[0]; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1018 | pArguments->GetReturnValue()->Assign( |
| 1019 | pScriptContext->GetJSValueFromMap(pNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1020 | } else { |
| 1021 | const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = |
| 1022 | resoveNodeRS.pScriptAttribute; |
| 1023 | if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) { |
dsinclair | 86fad99 | 2016-05-31 11:34:04 -0700 | [diff] [blame] | 1024 | std::unique_ptr<CFXJSE_Value> pValue( |
| 1025 | new CFXJSE_Value(pScriptContext->GetRuntime())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1026 | (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1027 | pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1028 | pArguments->GetReturnValue()->Assign(pValue.get()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1029 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1030 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1031 | } |
| 1032 | } |
| 1033 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1034 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1035 | void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) { |
| 1036 | int32_t iLength = pArguments->GetLength(); |
| 1037 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1038 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNodes"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1039 | return; |
| 1040 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1041 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1042 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1043 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1044 | if (!pValue) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1045 | return; |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1046 | uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1047 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1048 | XFA_RESOLVENODE_Siblings; |
| 1049 | CXFA_Node* refNode = this; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1050 | if (refNode->GetElementType() == XFA_Element::Xfa) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1051 | refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject()); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1052 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1053 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1054 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1055 | void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1056 | CFX_WideString wsExpression, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1057 | uint32_t dwFlag, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1058 | CXFA_Node* refNode) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1059 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1060 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1061 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1062 | XFA_RESOLVENODE_RS resoveNodeRS; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1063 | if (!refNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1064 | refNode = this; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1065 | pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(), |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 1066 | resoveNodeRS, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1067 | CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument); |
| 1068 | if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { |
| 1069 | for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) { |
| 1070 | if (resoveNodeRS.nodes[i]->IsNode()) |
| 1071 | pNodeList->Append(resoveNodeRS.nodes[i]->AsNode()); |
| 1072 | } |
| 1073 | } else { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1074 | CXFA_ValueArray valueArray(pScriptContext->GetRuntime()); |
| 1075 | if (resoveNodeRS.GetAttributeResult(valueArray) > 0) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1076 | CXFA_ObjArray objectArray; |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1077 | valueArray.GetAttributeObject(objectArray); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1078 | for (int32_t i = 0; i < objectArray.GetSize(); i++) { |
| 1079 | if (objectArray[i]->IsNode()) |
| 1080 | pNodeList->Append(objectArray[i]->AsNode()); |
| 1081 | } |
| 1082 | } |
| 1083 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1084 | pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1085 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1086 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1087 | void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1088 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1089 | XFA_ATTRIBUTE eAttribute) { |
| 1090 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1091 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1092 | } else { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1093 | uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1094 | CFX_WideString wsName; |
| 1095 | GetAttribute(XFA_ATTRIBUTE_Name, wsName); |
| 1096 | CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]"); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1097 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1098 | } |
| 1099 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1100 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1101 | void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1102 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1103 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1104 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1105 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1106 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1107 | if (bSetting) { |
| 1108 | IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 1109 | ASSERT(pAppProvider); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1110 | CFX_WideString wsMessage; |
| 1111 | pAppProvider->LoadString(XFA_IDS_Unable_TO_SET, wsMessage); |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 1112 | FXJSE_ThrowMessage( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 1113 | FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1114 | } else { |
| 1115 | CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1116 | pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1117 | } |
| 1118 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1119 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1120 | void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1121 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1122 | XFA_ATTRIBUTE eAttribute) { |
| 1123 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1124 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1125 | } else { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1126 | uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; |
dsinclair | 017052a | 2016-06-28 07:43:51 -0700 | [diff] [blame] | 1127 | CFX_WideString wsExpression = |
| 1128 | FX_WSTRC(L"#") + GetClassName() + FX_WSTRC(L"[*]"); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1129 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1130 | } |
| 1131 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1132 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1133 | void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1134 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1135 | XFA_ATTRIBUTE eAttribute) { |
| 1136 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1137 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1138 | } else { |
| 1139 | CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); |
| 1140 | if (pParent) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1141 | pValue->Assign( |
| 1142 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1143 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1144 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1145 | } |
| 1146 | } |
| 1147 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1148 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1149 | void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1150 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1151 | XFA_ATTRIBUTE eAttribute) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1152 | if (bSetting) |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1153 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1154 | else |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1155 | pValue->SetInteger(GetNodeSameNameIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1156 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1157 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1158 | void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1159 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1160 | XFA_ATTRIBUTE eAttribute) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1161 | if (bSetting) |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1162 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1163 | else |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1164 | pValue->SetInteger(GetNodeSameClassIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1165 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1166 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1167 | void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1168 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1169 | XFA_ATTRIBUTE eAttribute) { |
| 1170 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1171 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1172 | } else { |
| 1173 | CFX_WideString wsSOMExpression; |
| 1174 | GetSOMExpression(wsSOMExpression); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1175 | pValue->SetString(FX_UTF8Encode(wsSOMExpression).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1176 | } |
| 1177 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1178 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1179 | void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) { |
| 1180 | int32_t iLength = pArguments->GetLength(); |
| 1181 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1182 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"applyXSL"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1183 | return; |
| 1184 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1185 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1186 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1187 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1188 | // For now, just put the variables here to avoid unused variable warning. |
| 1189 | (void)wsExpression; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1190 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1191 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1192 | void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) { |
| 1193 | int32_t iLength = pArguments->GetLength(); |
| 1194 | if (iLength < 1 || iLength > 3) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1195 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"assignNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1196 | return; |
| 1197 | } |
| 1198 | CFX_WideString wsExpression; |
| 1199 | CFX_WideString wsValue; |
| 1200 | int32_t iAction = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1201 | wsExpression = |
| 1202 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1203 | if (iLength >= 2) { |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1204 | wsValue = |
| 1205 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1206 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1207 | if (iLength >= 3) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1208 | iAction = pArguments->GetInt32(2); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1209 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1210 | // For now, just put the variables here to avoid unused variable warning. |
| 1211 | (void)wsExpression; |
| 1212 | (void)wsValue; |
| 1213 | (void)iAction; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1214 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1215 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1216 | void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) { |
| 1217 | int32_t iLength = pArguments->GetLength(); |
| 1218 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1219 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clone"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1220 | return; |
| 1221 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1222 | bool bClone = !!pArguments->GetInt32(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1223 | CXFA_Node* pCloneNode = Clone(bClone); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1224 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1225 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode)); |
| 1226 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1227 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1228 | void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) { |
| 1229 | int32_t iLength = pArguments->GetLength(); |
| 1230 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1231 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1232 | return; |
| 1233 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1234 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1235 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1236 | CFX_WideString wsValue; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1237 | GetAttribute(wsExpression.AsStringC(), wsValue); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1238 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1239 | if (pValue) |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1240 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1241 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1242 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1243 | void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) { |
| 1244 | int32_t iLength = pArguments->GetLength(); |
| 1245 | if (iLength < 1 || iLength > 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1246 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getElement"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1247 | return; |
| 1248 | } |
| 1249 | CFX_WideString wsExpression; |
| 1250 | int32_t iValue = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1251 | wsExpression = |
| 1252 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
| 1253 | if (iLength >= 2) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1254 | iValue = pArguments->GetInt32(1); |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1255 | CXFA_Node* pNode = |
| 1256 | GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC())); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1257 | pArguments->GetReturnValue()->Assign( |
| 1258 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1259 | } |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1260 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1261 | void CXFA_Node::Script_NodeClass_IsPropertySpecified( |
| 1262 | CFXJSE_Arguments* pArguments) { |
| 1263 | int32_t iLength = pArguments->GetLength(); |
| 1264 | if (iLength < 1 || iLength > 3) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1265 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isPropertySpecified"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1266 | return; |
| 1267 | } |
| 1268 | CFX_WideString wsExpression; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1269 | bool bParent = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1270 | int32_t iIndex = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1271 | wsExpression = |
| 1272 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1273 | if (iLength >= 2) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1274 | bParent = !!pArguments->GetInt32(1); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1275 | if (iLength >= 3) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1276 | iIndex = pArguments->GetInt32(2); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1277 | bool bHas = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1278 | const XFA_ATTRIBUTEINFO* pAttributeInfo = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1279 | XFA_GetAttributeByName(wsExpression.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1280 | CFX_WideString wsValue; |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1281 | if (pAttributeInfo) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1282 | bHas = HasAttribute(pAttributeInfo->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1283 | if (!bHas) { |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1284 | XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC()); |
| 1285 | bHas = !!GetProperty(iIndex, eType); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1286 | if (!bHas && bParent && m_pParent) { |
| 1287 | // Also check on the parent. |
| 1288 | bHas = m_pParent->HasAttribute(pAttributeInfo->eName); |
| 1289 | if (!bHas) |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1290 | bHas = !!m_pParent->GetProperty(iIndex, eType); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1291 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1292 | } |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1293 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
| 1294 | if (pValue) |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1295 | pValue->SetBoolean(bHas); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1296 | } |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1297 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1298 | void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { |
| 1299 | int32_t iLength = pArguments->GetLength(); |
| 1300 | if (iLength < 1 || iLength > 3) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1301 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1302 | return; |
| 1303 | } |
| 1304 | CFX_WideString wsExpression; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1305 | bool bIgnoreRoot = true; |
| 1306 | bool bOverwrite = 0; |
| 1307 | wsExpression = |
| 1308 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
| 1309 | if (wsExpression.IsEmpty()) |
Tom Sepez | d3743ea | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 1310 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1311 | if (iLength >= 2) |
| 1312 | bIgnoreRoot = !!pArguments->GetInt32(1); |
| 1313 | if (iLength >= 3) |
| 1314 | bOverwrite = !!pArguments->GetInt32(2); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1315 | std::unique_ptr<CXFA_SimpleParser> pParser( |
| 1316 | new CXFA_SimpleParser(m_pDocument, false)); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1317 | if (!pParser) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1318 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1319 | CFDE_XMLNode* pXMLNode = nullptr; |
| 1320 | int32_t iParserStatus = |
| 1321 | pParser->ParseXMLData(wsExpression, pXMLNode, nullptr); |
| 1322 | if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode) |
| 1323 | return; |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1324 | if (bIgnoreRoot && |
| 1325 | (pXMLNode->GetType() != FDE_XMLNODE_Element || |
| 1326 | XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1327 | bIgnoreRoot = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1328 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1329 | CXFA_Node* pFakeRoot = Clone(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1330 | CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType); |
| 1331 | if (!wsContentType.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 1332 | pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType, |
| 1333 | CFX_WideString(wsContentType)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1334 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1335 | CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1336 | if (!pFakeXMLRoot) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1337 | CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1338 | pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1339 | } |
dsinclair | 017052a | 2016-06-28 07:43:51 -0700 | [diff] [blame] | 1340 | if (!pFakeXMLRoot) |
| 1341 | pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName())); |
| 1342 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1343 | if (bIgnoreRoot) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1344 | CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1345 | while (pXMLChild) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1346 | CFDE_XMLNode* pXMLSibling = |
| 1347 | pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1348 | pXMLNode->RemoveChildNode(pXMLChild); |
| 1349 | pFakeXMLRoot->InsertChildNode(pXMLChild); |
| 1350 | pXMLChild = pXMLSibling; |
| 1351 | } |
| 1352 | } else { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1353 | CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1354 | if (pXMLParent) { |
| 1355 | pXMLParent->RemoveChildNode(pXMLNode); |
| 1356 | } |
| 1357 | pFakeXMLRoot->InsertChildNode(pXMLNode); |
| 1358 | } |
| 1359 | pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot); |
| 1360 | pFakeRoot = pParser->GetRootNode(); |
| 1361 | if (pFakeRoot) { |
| 1362 | if (bOverwrite) { |
| 1363 | CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1364 | CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1365 | int32_t index = 0; |
| 1366 | while (pNewChild) { |
| 1367 | CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1368 | pFakeRoot->RemoveChild(pNewChild); |
| 1369 | InsertChild(index++, pNewChild); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1370 | pNewChild->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1371 | pNewChild = pItem; |
| 1372 | } |
| 1373 | while (pChild) { |
| 1374 | CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1375 | RemoveChild(pChild); |
| 1376 | pFakeRoot->InsertChild(pChild); |
| 1377 | pChild = pItem; |
| 1378 | } |
| 1379 | if (GetPacketID() == XFA_XDPPACKET_Form && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1380 | GetElementType() == XFA_Element::ExData) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1381 | CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1382 | SetXMLMappingNode(pFakeXMLRoot); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1383 | SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1384 | if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1385 | pFakeXMLRoot = pTempXMLNode; |
| 1386 | } else { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1387 | pFakeXMLRoot = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1388 | } |
| 1389 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1390 | MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1391 | } else { |
| 1392 | CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1393 | while (pChild) { |
| 1394 | CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1395 | pFakeRoot->RemoveChild(pChild); |
| 1396 | InsertChild(pChild); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1397 | pChild->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1398 | pChild = pItem; |
| 1399 | } |
| 1400 | } |
| 1401 | if (pFakeXMLRoot) { |
| 1402 | pFakeRoot->SetXMLMappingNode(pFakeXMLRoot); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1403 | pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1404 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1405 | pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1406 | } else { |
Tom Sepez | d3743ea | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 1407 | if (pFakeXMLRoot) { |
| 1408 | pFakeXMLRoot->Release(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1409 | pFakeXMLRoot = nullptr; |
Tom Sepez | d3743ea | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 1410 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1411 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1412 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1413 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1414 | void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1415 | // TODO(weili): Check whether we need to implement this, pdfium:501. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { |
| 1419 | int32_t iLength = pArguments->GetLength(); |
| 1420 | if (iLength < 0 || iLength > 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1421 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1422 | return; |
| 1423 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1424 | bool bPrettyMode = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1425 | if (iLength == 1) { |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1426 | if (pArguments->GetUTF8String(0) != "pretty") { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1427 | ThrowException(XFA_IDS_ARGUMENT_MISMATCH); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1428 | return; |
| 1429 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1430 | bPrettyMode = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1431 | } |
| 1432 | CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1433 | if (GetPacketID() == XFA_XDPPACKET_Form || |
| 1434 | GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 1435 | CFDE_XMLNode* pElement = nullptr; |
| 1436 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 1437 | pElement = GetXMLMappingNode(); |
| 1438 | if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1439 | pArguments->GetReturnValue()->SetString(bsXMLHeader); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1440 | return; |
| 1441 | } |
| 1442 | XFA_DataExporter_DealWithDataGroupNode(this); |
| 1443 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1444 | std::unique_ptr<IFX_MemoryStream, ReleaseDeleter<IFX_MemoryStream>> |
tsepez | 345d489 | 2016-11-30 15:10:55 -0800 | [diff] [blame] | 1445 | pMemoryStream(IFX_MemoryStream::Create(true)); |
tsepez | 0527ec5 | 2016-12-02 10:53:30 -0800 | [diff] [blame] | 1446 | std::unique_ptr<IFGAS_Stream, ReleaseDeleter<IFGAS_Stream>> pStream( |
| 1447 | IFGAS_Stream::CreateStream( |
tsepez | ad2441e | 2016-10-24 10:19:11 -0700 | [diff] [blame] | 1448 | static_cast<IFX_SeekableWriteStream*>(pMemoryStream.get()), |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1449 | FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | |
| 1450 | FX_STREAMACCESS_Append)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1451 | if (!pStream) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1452 | pArguments->GetReturnValue()->SetString(bsXMLHeader); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1453 | return; |
| 1454 | } |
| 1455 | pStream->SetCodePage(FX_CODEPAGE_UTF8); |
dsinclair | 179bebb | 2016-04-05 11:02:18 -0700 | [diff] [blame] | 1456 | pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength()); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1457 | if (GetPacketID() == XFA_XDPPACKET_Form) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1458 | XFA_DataExporter_RegenerateFormFile(this, pStream.get(), nullptr, true); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1459 | else |
| 1460 | pElement->SaveXMLNode(pStream.get()); |
| 1461 | // TODO(weili): Check whether we need to save pretty print XML, pdfium:501. |
| 1462 | // For now, just put it here to avoid unused variable warning. |
| 1463 | (void)bPrettyMode; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1464 | pArguments->GetReturnValue()->SetString( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1465 | CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1466 | return; |
| 1467 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1468 | pArguments->GetReturnValue()->SetString(""); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) { |
| 1472 | int32_t iLength = pArguments->GetLength(); |
| 1473 | if (iLength != 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1474 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1475 | return; |
| 1476 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1477 | CFX_WideString wsAttributeValue = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1478 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1479 | CFX_WideString wsAttribute = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1480 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1481 | SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1482 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1483 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1484 | void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) { |
| 1485 | int32_t iLength = pArguments->GetLength(); |
| 1486 | if (iLength != 1 && iLength != 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1487 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setElement"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1488 | return; |
| 1489 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1490 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1491 | CFX_WideString wsName; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1492 | pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 1493 | if (iLength == 2) |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1494 | wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1495 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1496 | // For now, just put the variables here to avoid unused variable warning. |
| 1497 | (void)pNode; |
| 1498 | (void)wsName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1499 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1500 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1501 | void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1502 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1503 | XFA_ATTRIBUTE eAttribute) { |
| 1504 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1505 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1506 | } else { |
| 1507 | CFX_WideString wsNameSpace; |
| 1508 | TryNamespace(wsNameSpace); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1509 | pValue->SetString(FX_UTF8Encode(wsNameSpace).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1510 | } |
| 1511 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1512 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1513 | void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1514 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1515 | XFA_ATTRIBUTE eAttribute) { |
| 1516 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1517 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1518 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1519 | pValue->Assign( |
| 1520 | m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1521 | } |
| 1522 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1523 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1524 | void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1525 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1526 | XFA_ATTRIBUTE eAttribute) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1527 | if (bSetting) |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1528 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1529 | else |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1530 | pValue->SetBoolean(IsContainerNode()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1531 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1532 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1533 | void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1534 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1535 | XFA_ATTRIBUTE eAttribute) { |
| 1536 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1537 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1538 | } else { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1539 | if (GetElementType() == XFA_Element::Subform) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1540 | pValue->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1541 | return; |
| 1542 | } |
| 1543 | CFX_WideString strValue; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1544 | pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1545 | } |
| 1546 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1547 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1548 | void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1549 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1550 | XFA_ATTRIBUTE eAttribute) { |
| 1551 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1552 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1553 | } else { |
| 1554 | CXFA_NodeArray properts; |
| 1555 | int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty); |
| 1556 | if (iSize > 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1557 | pValue->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1558 | m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0])); |
| 1559 | } |
| 1560 | } |
| 1561 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1562 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1563 | void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {} |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1564 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1565 | void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) { |
| 1566 | CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1567 | pArguments->GetReturnValue()->SetObject( |
| 1568 | pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1569 | } |
| 1570 | void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) { |
| 1571 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1572 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1573 | void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) { |
| 1574 | Script_Template_CreateNode(pArguments); |
| 1575 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1576 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1577 | void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) { |
| 1578 | int32_t iLength = pArguments->GetLength(); |
| 1579 | if (iLength < 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1580 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isCompatibleNS"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1581 | return; |
| 1582 | } |
| 1583 | CFX_WideString wsNameSpace; |
| 1584 | if (iLength >= 1) { |
| 1585 | CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1586 | wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1587 | } |
| 1588 | CFX_WideString wsNodeNameSpace; |
| 1589 | TryNamespace(wsNodeNameSpace); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1590 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1591 | if (pValue) |
| 1592 | pValue->SetBoolean(wsNodeNameSpace == wsNameSpace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1593 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1594 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1595 | void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1596 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1597 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1598 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1599 | void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1600 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1601 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1602 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1603 | void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1604 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1605 | XFA_ATTRIBUTE eAttribute) { |
| 1606 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1607 | SetInteger(eAttribute, pValue->ToInteger(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1608 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1609 | pValue->SetInteger(GetInteger(eAttribute)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1610 | } |
| 1611 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1612 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1613 | void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1614 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1615 | XFA_ATTRIBUTE eAttribute) { |
| 1616 | if (!bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1617 | pValue->SetInteger(GetInteger(eAttribute)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1618 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1619 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1620 | } |
| 1621 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1622 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1623 | void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1624 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1625 | XFA_ATTRIBUTE eAttribute) { |
| 1626 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1627 | SetBoolean(eAttribute, pValue->ToBoolean(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1628 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1629 | pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1630 | } |
| 1631 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1632 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1633 | void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1634 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1635 | XFA_ATTRIBUTE eAttribute) { |
| 1636 | if (!bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1637 | pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1638 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1639 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1640 | } |
| 1641 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1642 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1643 | void CXFA_Node::Script_Attribute_SendAttributeChangeMessage( |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1644 | XFA_ATTRIBUTE eAttribute, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1645 | bool bScriptModify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1646 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1647 | if (!pLayoutPro) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1648 | return; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1649 | |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1650 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1651 | if (!pNotify) |
| 1652 | return; |
| 1653 | |
| 1654 | uint32_t dwPacket = GetPacketID(); |
| 1655 | if (!(dwPacket & XFA_XDPPACKET_Form)) { |
| 1656 | pNotify->OnValueChanged(this, eAttribute, this, this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1657 | return; |
| 1658 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1659 | |
| 1660 | bool bNeedFindContainer = false; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1661 | switch (GetElementType()) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1662 | case XFA_Element::Caption: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1663 | bNeedFindContainer = true; |
| 1664 | pNotify->OnValueChanged(this, eAttribute, this, |
| 1665 | GetNodeItem(XFA_NODEITEM_Parent)); |
| 1666 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1667 | case XFA_Element::Font: |
| 1668 | case XFA_Element::Para: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1669 | bNeedFindContainer = true; |
| 1670 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1671 | if (pParentNode->GetElementType() == XFA_Element::Caption) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1672 | pNotify->OnValueChanged(this, eAttribute, pParentNode, |
| 1673 | pParentNode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1674 | } else { |
| 1675 | pNotify->OnValueChanged(this, eAttribute, this, pParentNode); |
| 1676 | } |
| 1677 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1678 | case XFA_Element::Margin: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1679 | bNeedFindContainer = true; |
| 1680 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1681 | XFA_Element eParentType = pParentNode->GetElementType(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1682 | if (pParentNode->IsContainerNode()) { |
| 1683 | pNotify->OnValueChanged(this, eAttribute, this, pParentNode); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1684 | } else if (eParentType == XFA_Element::Caption) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1685 | pNotify->OnValueChanged(this, eAttribute, pParentNode, |
| 1686 | pParentNode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1687 | } else { |
| 1688 | CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1689 | if (pNode && pNode->GetElementType() == XFA_Element::Ui) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1690 | pNotify->OnValueChanged(this, eAttribute, pNode, |
| 1691 | pNode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1692 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1693 | } |
| 1694 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1695 | case XFA_Element::Comb: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1696 | CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1697 | XFA_Element eUIType = pEditNode->GetElementType(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1698 | if (pEditNode && (eUIType == XFA_Element::DateTimeEdit || |
| 1699 | eUIType == XFA_Element::NumericEdit || |
| 1700 | eUIType == XFA_Element::TextEdit)) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1701 | CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1702 | if (pUINode) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1703 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1704 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1705 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1706 | } |
| 1707 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1708 | case XFA_Element::Button: |
| 1709 | case XFA_Element::Barcode: |
| 1710 | case XFA_Element::ChoiceList: |
| 1711 | case XFA_Element::DateTimeEdit: |
| 1712 | case XFA_Element::NumericEdit: |
| 1713 | case XFA_Element::PasswordEdit: |
| 1714 | case XFA_Element::TextEdit: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1715 | CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1716 | if (pUINode) { |
| 1717 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1718 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1719 | } |
| 1720 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1721 | case XFA_Element::CheckButton: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1722 | bNeedFindContainer = true; |
| 1723 | CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1724 | if (pUINode) { |
| 1725 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1726 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1727 | } |
| 1728 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1729 | case XFA_Element::Keep: |
| 1730 | case XFA_Element::Bookend: |
| 1731 | case XFA_Element::Break: |
| 1732 | case XFA_Element::BreakAfter: |
| 1733 | case XFA_Element::BreakBefore: |
| 1734 | case XFA_Element::Overflow: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1735 | bNeedFindContainer = true; |
| 1736 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1737 | case XFA_Element::Area: |
| 1738 | case XFA_Element::Draw: |
| 1739 | case XFA_Element::ExclGroup: |
| 1740 | case XFA_Element::Field: |
| 1741 | case XFA_Element::Subform: |
| 1742 | case XFA_Element::SubformSet: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1743 | pLayoutPro->AddChangedContainer(this); |
| 1744 | pNotify->OnValueChanged(this, eAttribute, this, this); |
| 1745 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1746 | case XFA_Element::Sharptext: |
| 1747 | case XFA_Element::Sharpxml: |
| 1748 | case XFA_Element::SharpxHTML: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1749 | CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1750 | if (!pTextNode) { |
| 1751 | return; |
| 1752 | } |
| 1753 | CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1754 | if (!pValueNode) { |
| 1755 | return; |
| 1756 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1757 | XFA_Element eType = pValueNode->GetElementType(); |
| 1758 | if (eType == XFA_Element::Value) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1759 | bNeedFindContainer = true; |
| 1760 | CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1761 | if (pNode && pNode->IsContainerNode()) { |
| 1762 | if (bScriptModify) { |
| 1763 | pValueNode = pNode; |
| 1764 | } |
| 1765 | pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode); |
| 1766 | } else { |
| 1767 | pNotify->OnValueChanged(this, eAttribute, pNode, |
| 1768 | pNode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1769 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1770 | } else { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1771 | if (eType == XFA_Element::Items) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1772 | CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1773 | if (pNode && pNode->IsContainerNode()) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1774 | pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1775 | } |
| 1776 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1777 | } |
| 1778 | } break; |
| 1779 | default: |
| 1780 | break; |
| 1781 | } |
| 1782 | if (bNeedFindContainer) { |
| 1783 | CXFA_Node* pParent = this; |
| 1784 | while (pParent) { |
| 1785 | if (pParent->IsContainerNode()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1786 | break; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1787 | |
| 1788 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1789 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1790 | if (pParent) { |
| 1791 | pLayoutPro->AddChangedContainer(pParent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1792 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1793 | } |
| 1794 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1795 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1796 | void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1797 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1798 | XFA_ATTRIBUTE eAttribute) { |
| 1799 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1800 | CFX_WideString wsValue = pValue->ToWideString(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1801 | SetAttribute(eAttribute, wsValue.AsStringC(), true); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1802 | if (eAttribute == XFA_ATTRIBUTE_Use && |
| 1803 | GetElementType() == XFA_Element::Desc) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1804 | CXFA_Node* pTemplateNode = |
| 1805 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template)); |
| 1806 | CXFA_Node* pProtoRoot = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1807 | pTemplateNode->GetFirstChildByClass(XFA_Element::Subform) |
| 1808 | ->GetFirstChildByClass(XFA_Element::Proto); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1809 | |
| 1810 | CFX_WideString wsID; |
| 1811 | CFX_WideString wsSOM; |
| 1812 | if (!wsValue.IsEmpty()) { |
| 1813 | if (wsValue[0] == '#') { |
| 1814 | wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1815 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1816 | wsSOM = wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1817 | } |
| 1818 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1819 | CXFA_Node* pProtoNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1820 | if (!wsSOM.IsEmpty()) { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1821 | uint32_t dwFlag = XFA_RESOLVENODE_Children | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1822 | XFA_RESOLVENODE_Attributes | |
| 1823 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1824 | XFA_RESOLVENODE_Siblings; |
| 1825 | XFA_RESOLVENODE_RS resoveNodeRS; |
| 1826 | int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1827 | pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1828 | if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) { |
| 1829 | pProtoNode = resoveNodeRS.nodes[0]->AsNode(); |
| 1830 | } |
| 1831 | } else if (!wsID.IsEmpty()) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1832 | pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1833 | } |
| 1834 | if (pProtoNode) { |
| 1835 | CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1836 | while (pHeadChild) { |
| 1837 | CXFA_Node* pSibling = |
| 1838 | pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1839 | RemoveChild(pHeadChild); |
| 1840 | pHeadChild = pSibling; |
| 1841 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1842 | CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1843 | pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1844 | while (pHeadChild) { |
| 1845 | CXFA_Node* pSibling = |
| 1846 | pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1847 | pProtoForm->RemoveChild(pHeadChild); |
| 1848 | InsertChild(pHeadChild); |
| 1849 | pHeadChild = pSibling; |
| 1850 | } |
| 1851 | m_pDocument->RemovePurgeNode(pProtoForm); |
| 1852 | delete pProtoForm; |
| 1853 | } |
| 1854 | } |
| 1855 | } else { |
| 1856 | CFX_WideString wsValue; |
| 1857 | GetAttribute(eAttribute, wsValue); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1858 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 1859 | FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1860 | } |
| 1861 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1862 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1863 | void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1864 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1865 | XFA_ATTRIBUTE eAttribute) { |
| 1866 | if (!bSetting) { |
| 1867 | CFX_WideString wsValue; |
| 1868 | GetAttribute(eAttribute, wsValue); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1869 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 1870 | FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1871 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1872 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1873 | } |
| 1874 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1875 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1876 | void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) { |
| 1877 | int32_t argc = pArguments->GetLength(); |
| 1878 | if ((argc == 0) || (argc == 1)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1879 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1880 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1881 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1882 | } |
| 1883 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1884 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1885 | void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) { |
| 1886 | int32_t argc = pArguments->GetLength(); |
| 1887 | if (argc == 0) { |
| 1888 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1889 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"restore"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1890 | } |
| 1891 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1892 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1893 | void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1894 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1895 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1896 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1897 | void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1898 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1899 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1900 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1901 | void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1902 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1903 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1904 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1905 | void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1906 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1907 | XFA_SOM_MESSAGETYPE iMessageType) { |
| 1908 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 1909 | if (!pWidgetData) { |
| 1910 | return; |
| 1911 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1912 | bool bNew = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1913 | CXFA_Validate validate = pWidgetData->GetValidate(); |
| 1914 | if (!validate) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1915 | validate = pWidgetData->GetValidate(true); |
| 1916 | bNew = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1917 | } |
| 1918 | if (bSetting) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1919 | switch (iMessageType) { |
| 1920 | case XFA_SOM_ValidationMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1921 | validate.SetScriptMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1922 | break; |
| 1923 | case XFA_SOM_FormatMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1924 | validate.SetFormatMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1925 | break; |
| 1926 | case XFA_SOM_MandatoryMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1927 | validate.SetNullMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1928 | break; |
| 1929 | default: |
| 1930 | break; |
| 1931 | } |
| 1932 | if (!bNew) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1933 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1934 | if (!pNotify) { |
| 1935 | return; |
| 1936 | } |
| 1937 | pNotify->AddCalcValidate(this); |
| 1938 | } |
| 1939 | } else { |
| 1940 | CFX_WideString wsMessage; |
| 1941 | switch (iMessageType) { |
| 1942 | case XFA_SOM_ValidationMessage: |
| 1943 | validate.GetScriptMessageText(wsMessage); |
| 1944 | break; |
| 1945 | case XFA_SOM_FormatMessage: |
| 1946 | validate.GetFormatMessageText(wsMessage); |
| 1947 | break; |
| 1948 | case XFA_SOM_MandatoryMessage: |
| 1949 | validate.GetNullMessageText(wsMessage); |
| 1950 | break; |
| 1951 | default: |
| 1952 | break; |
| 1953 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1954 | pValue->SetString(FX_UTF8Encode(wsMessage).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1955 | } |
| 1956 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1957 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1958 | void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1959 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1960 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1961 | Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1962 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1963 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1964 | void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1965 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1966 | XFA_ATTRIBUTE eAttribute) { |
| 1967 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1968 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1969 | } else { |
| 1970 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 1971 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1972 | pValue->SetInteger(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1973 | return; |
| 1974 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1975 | pValue->SetInteger(pWidgetData->CountChoiceListItems(true)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1976 | } |
| 1977 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1978 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1979 | void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1980 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1981 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1982 | XFA_Element eType = GetElementType(); |
| 1983 | if (eType == XFA_Element::Field) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1984 | Script_Field_DefaultValue(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1985 | return; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1986 | } |
| 1987 | if (eType == XFA_Element::Draw) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1988 | Script_Draw_DefaultValue(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1989 | return; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1990 | } |
| 1991 | if (eType == XFA_Element::Boolean) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1992 | Script_Boolean_Value(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1993 | return; |
| 1994 | } |
| 1995 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1996 | CFX_WideString wsNewValue; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 1997 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1998 | wsNewValue = pValue->ToWideString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1999 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2000 | CFX_WideString wsFormatValue(wsNewValue); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2001 | CXFA_WidgetData* pContainerWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2002 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 2003 | CXFA_NodeArray formNodes; |
| 2004 | GetBindItems(formNodes); |
| 2005 | CFX_WideString wsPicture; |
| 2006 | for (int32_t i = 0; i < formNodes.GetSize(); i++) { |
| 2007 | CXFA_Node* pFormNode = formNodes.GetAt(i); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 2008 | if (!pFormNode || pFormNode->HasRemovedChildren()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2009 | continue; |
| 2010 | } |
| 2011 | pContainerWidgetData = pFormNode->GetContainerWidgetData(); |
| 2012 | if (pContainerWidgetData) { |
| 2013 | pContainerWidgetData->GetPictureContent(wsPicture, |
| 2014 | XFA_VALUEPICTURE_DataBind); |
| 2015 | } |
| 2016 | if (!wsPicture.IsEmpty()) { |
| 2017 | break; |
| 2018 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2019 | pContainerWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2020 | } |
| 2021 | } else if (GetPacketID() == XFA_XDPPACKET_Form) { |
| 2022 | pContainerWidgetData = GetContainerWidgetData(); |
| 2023 | } |
| 2024 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2025 | pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2026 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2027 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2028 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2029 | CFX_WideString content = GetScriptContent(true); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2030 | if (content.IsEmpty() && eType != XFA_Element::Text && |
| 2031 | eType != XFA_Element::SubmitUrl) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2032 | pValue->SetNull(); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2033 | } else if (eType == XFA_Element::Integer) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2034 | pValue->SetInteger(FXSYS_wtoi(content.c_str())); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2035 | } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2036 | CFX_Decimal decimal(content.AsStringC()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2037 | pValue->SetFloat((FX_FLOAT)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2038 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2039 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2040 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2041 | } |
| 2042 | } |
| 2043 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2044 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2045 | void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2046 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2047 | XFA_ATTRIBUTE eAttribute) { |
| 2048 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2049 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2050 | return; |
| 2051 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2052 | CFX_WideString content = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2053 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2054 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2055 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2056 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2057 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2058 | } |
| 2059 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2060 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2061 | void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2062 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2063 | XFA_ATTRIBUTE eAttribute) { |
| 2064 | if (bSetting) { |
| 2065 | CFX_ByteString newValue; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2066 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2067 | newValue = pValue->ToString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2068 | |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 2069 | int32_t iValue = FXSYS_atoi(newValue.c_str()); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 2070 | CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2071 | CFX_WideString wsFormatValue(wsNewValue); |
| 2072 | CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData(); |
| 2073 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2074 | pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2075 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2076 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2077 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2078 | CFX_WideString wsValue = GetScriptContent(true); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2079 | pValue->SetBoolean(wsValue == FX_WSTRC(L"1")); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2080 | } |
| 2081 | } |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2082 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2083 | void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2084 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2085 | XFA_ATTRIBUTE eAttribute) { |
| 2086 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2087 | if (!pWidgetData) { |
| 2088 | return; |
| 2089 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2090 | CXFA_Border border = pWidgetData->GetBorder(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2091 | int32_t iSize = border.CountEdges(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2092 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2093 | int32_t r = 0; |
| 2094 | int32_t g = 0; |
| 2095 | int32_t b = 0; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2096 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2097 | FX_ARGB rgb = ArgbEncode(100, r, g, b); |
| 2098 | for (int32_t i = 0; i < iSize; ++i) { |
| 2099 | CXFA_Edge edge = border.GetEdge(i); |
| 2100 | edge.SetColor(rgb); |
| 2101 | } |
| 2102 | } else { |
| 2103 | CXFA_Edge edge = border.GetEdge(0); |
| 2104 | FX_ARGB color = edge.GetColor(); |
| 2105 | int32_t a, r, g, b; |
| 2106 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2107 | CFX_WideString strColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2108 | strColor.Format(L"%d,%d,%d", r, g, b); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2109 | pValue->SetString(FX_UTF8Encode(strColor).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2110 | } |
| 2111 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2112 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2113 | void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2114 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2115 | XFA_ATTRIBUTE eAttribute) { |
| 2116 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2117 | if (!pWidgetData) { |
| 2118 | return; |
| 2119 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2120 | CXFA_Border border = pWidgetData->GetBorder(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2121 | int32_t iSize = border.CountEdges(); |
| 2122 | CFX_WideString wsThickness; |
| 2123 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2124 | wsThickness = pValue->ToWideString(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2125 | for (int32_t i = 0; i < iSize; ++i) { |
| 2126 | CXFA_Edge edge = border.GetEdge(i); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2127 | CXFA_Measurement thickness(wsThickness.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2128 | edge.SetMSThickness(thickness); |
| 2129 | } |
| 2130 | } else { |
| 2131 | CXFA_Edge edge = border.GetEdge(0); |
| 2132 | CXFA_Measurement thickness = edge.GetMSThickness(); |
| 2133 | thickness.ToString(wsThickness); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2134 | pValue->SetString(FX_UTF8Encode(wsThickness).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2135 | } |
| 2136 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2137 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2138 | void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2139 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2140 | XFA_ATTRIBUTE eAttribute) { |
| 2141 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2142 | if (!pWidgetData) { |
| 2143 | return; |
| 2144 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2145 | CXFA_Border border = pWidgetData->GetBorder(true); |
| 2146 | CXFA_Fill borderfill = border.GetFill(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2147 | CXFA_Node* pNode = borderfill.GetNode(); |
| 2148 | if (!pNode) { |
| 2149 | return; |
| 2150 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2151 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2152 | int32_t r; |
| 2153 | int32_t g; |
| 2154 | int32_t b; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2155 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2156 | FX_ARGB color = ArgbEncode(0xff, r, g, b); |
| 2157 | borderfill.SetColor(color); |
| 2158 | } else { |
| 2159 | FX_ARGB color = borderfill.GetColor(); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2160 | int32_t a; |
| 2161 | int32_t r; |
| 2162 | int32_t g; |
| 2163 | int32_t b; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2164 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2165 | CFX_WideString wsColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2166 | wsColor.Format(L"%d,%d,%d", r, g, b); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2167 | pValue->SetString(FX_UTF8Encode(wsColor).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2168 | } |
| 2169 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2170 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2171 | void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2172 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2173 | XFA_ATTRIBUTE eAttribute) { |
| 2174 | if (!bSetting) { |
| 2175 | CXFA_Node* pDataNode = GetBindData(); |
| 2176 | if (pDataNode) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2177 | pValue->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2178 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode)); |
| 2179 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2180 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2181 | } |
| 2182 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2183 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2184 | } |
| 2185 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2186 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2187 | void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2188 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2189 | XFA_ATTRIBUTE eAttribute) { |
| 2190 | if (bSetting) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2191 | if (pValue && pValue->IsString()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2192 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 2193 | ASSERT(pWidgetData); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2194 | XFA_Element uiType = pWidgetData->GetUIType(); |
| 2195 | if (uiType == XFA_Element::Text) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2196 | CFX_WideString wsNewValue = pValue->ToWideString(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2197 | CFX_WideString wsFormatValue(wsNewValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2198 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2199 | } |
| 2200 | } |
| 2201 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2202 | CFX_WideString content = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2203 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2204 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2205 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2206 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2207 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2208 | } |
| 2209 | } |
| 2210 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2211 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2212 | void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2213 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2214 | XFA_ATTRIBUTE eAttribute) { |
| 2215 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2216 | if (!pWidgetData) { |
| 2217 | return; |
| 2218 | } |
| 2219 | if (bSetting) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2220 | if (pValue && pValue->IsNull()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2221 | pWidgetData->m_bPreNull = pWidgetData->m_bIsNull; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2222 | pWidgetData->m_bIsNull = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2223 | } else { |
| 2224 | pWidgetData->m_bPreNull = pWidgetData->m_bIsNull; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2225 | pWidgetData->m_bIsNull = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2226 | } |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2227 | CFX_WideString wsNewText; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2228 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2229 | wsNewText = pValue->ToWideString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2230 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2231 | CXFA_Node* pUIChild = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2232 | if (pUIChild->GetElementType() == XFA_Element::NumericEdit) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2233 | int32_t iLeadDigits = 0; |
| 2234 | int32_t iFracDigits = 0; |
| 2235 | pWidgetData->GetLeadDigits(iLeadDigits); |
| 2236 | pWidgetData->GetFracDigits(iFracDigits); |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 2237 | wsNewText = |
| 2238 | pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2239 | } |
| 2240 | CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData(); |
| 2241 | CFX_WideString wsFormatText(wsNewText); |
| 2242 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2243 | pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2244 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2245 | SetScriptContent(wsNewText, wsFormatText, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2246 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2247 | CFX_WideString content = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2248 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2249 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2250 | } else { |
| 2251 | CXFA_Node* pUIChild = pWidgetData->GetUIChild(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2252 | CXFA_Value defVal = pWidgetData->GetFormValue(); |
| 2253 | CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2254 | if (pNode && pNode->GetElementType() == XFA_Element::Decimal) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2255 | if (pUIChild->GetElementType() == XFA_Element::NumericEdit && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2256 | (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2257 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2258 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2259 | } else { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2260 | CFX_Decimal decimal(content.AsStringC()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2261 | pValue->SetFloat((FX_FLOAT)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2262 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2263 | } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2264 | pValue->SetInteger(FXSYS_wtoi(content.c_str())); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2265 | } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2266 | pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2267 | } else if (pNode && pNode->GetElementType() == XFA_Element::Float) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2268 | CFX_Decimal decimal(content.AsStringC()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2269 | pValue->SetFloat((FX_FLOAT)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2270 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2271 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2272 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2273 | } |
| 2274 | } |
| 2275 | } |
| 2276 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2277 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2278 | void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2279 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2280 | XFA_ATTRIBUTE eAttribute) { |
| 2281 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2282 | if (!pWidgetData) { |
| 2283 | return; |
| 2284 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2285 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2286 | pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2287 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2288 | CFX_WideString wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2289 | pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2290 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2291 | } |
| 2292 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2293 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2294 | void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2295 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2296 | XFA_ATTRIBUTE eAttribute) { |
| 2297 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2298 | if (!pWidgetData) { |
| 2299 | return; |
| 2300 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2301 | CXFA_Font font = pWidgetData->GetFont(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2302 | CXFA_Node* pNode = font.GetNode(); |
| 2303 | if (!pNode) { |
| 2304 | return; |
| 2305 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2306 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2307 | int32_t r; |
| 2308 | int32_t g; |
| 2309 | int32_t b; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2310 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2311 | FX_ARGB color = ArgbEncode(0xff, r, g, b); |
| 2312 | font.SetColor(color); |
| 2313 | } else { |
| 2314 | FX_ARGB color = font.GetColor(); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2315 | int32_t a; |
| 2316 | int32_t r; |
| 2317 | int32_t g; |
| 2318 | int32_t b; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2319 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2320 | CFX_WideString wsColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2321 | wsColor.Format(L"%d,%d,%d", r, g, b); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2322 | pValue->SetString(FX_UTF8Encode(wsColor).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2323 | } |
| 2324 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2325 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2326 | void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2327 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2328 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2329 | Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2330 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2331 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2332 | void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2333 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2334 | XFA_ATTRIBUTE eAttribute) { |
| 2335 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2336 | if (!pWidgetData) { |
| 2337 | return; |
| 2338 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2339 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2340 | pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2341 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2342 | CFX_WideString wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2343 | pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2344 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2345 | } |
| 2346 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2347 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2348 | void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2349 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2350 | XFA_ATTRIBUTE eAttribute) { |
| 2351 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2352 | if (!pWidgetData) { |
| 2353 | return; |
| 2354 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2355 | CXFA_Validate validate = pWidgetData->GetValidate(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2356 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2357 | validate.SetNullTest(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2358 | } else { |
| 2359 | int32_t iValue = validate.GetNullTest(); |
| 2360 | const XFA_ATTRIBUTEENUMINFO* pInfo = |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 2361 | GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2362 | CFX_WideString wsValue; |
| 2363 | if (pInfo) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2364 | wsValue = pInfo->pName; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2365 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2366 | } |
| 2367 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2368 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2369 | void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2370 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2371 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2372 | Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2373 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2374 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2375 | void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2376 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2377 | XFA_ATTRIBUTE eAttribute) { |
| 2378 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2379 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2380 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2381 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2382 | } |
| 2383 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2384 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2385 | void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2386 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2387 | XFA_ATTRIBUTE eAttribute) { |
| 2388 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2389 | if (!pWidgetData) { |
| 2390 | return; |
| 2391 | } |
| 2392 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2393 | int32_t iIndex = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2394 | if (iIndex == -1) { |
| 2395 | pWidgetData->ClearAllSelections(); |
| 2396 | return; |
| 2397 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2398 | pWidgetData->SetItemState(iIndex, true, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2399 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2400 | pValue->SetInteger(pWidgetData->GetSelectedItem()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2401 | } |
| 2402 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2403 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2404 | void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) { |
| 2405 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2406 | if (!pWidgetData) { |
| 2407 | return; |
| 2408 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2409 | pWidgetData->DeleteItem(-1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2410 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2411 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2412 | void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) { |
| 2413 | int32_t argc = pArguments->GetLength(); |
| 2414 | if (argc == 1) { |
| 2415 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2416 | int32_t iRet = execSingleEventByName( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2417 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2418 | XFA_Element::Field); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2419 | if (eventString == "validate") { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2420 | pArguments->GetReturnValue()->SetBoolean( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2421 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2422 | } |
| 2423 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2424 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2425 | } |
| 2426 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2427 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2428 | void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 2429 | int32_t argc = pArguments->GetLength(); |
| 2430 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2431 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2432 | if (!pNotify) { |
| 2433 | return; |
| 2434 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2435 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2436 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2437 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2438 | } |
| 2439 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2440 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2441 | void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) { |
| 2442 | int32_t iLength = pArguments->GetLength(); |
| 2443 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2444 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"deleteItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2445 | return; |
| 2446 | } |
| 2447 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2448 | if (!pWidgetData) { |
| 2449 | return; |
| 2450 | } |
| 2451 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2452 | bool bValue = pWidgetData->DeleteItem(iIndex, true, true); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2453 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2454 | if (pValue) |
| 2455 | pValue->SetBoolean(bValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2456 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2457 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2458 | void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) { |
| 2459 | int32_t iLength = pArguments->GetLength(); |
| 2460 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2461 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getSaveItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2462 | return; |
| 2463 | } |
| 2464 | int32_t iIndex = pArguments->GetInt32(0); |
| 2465 | if (iIndex < 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2466 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2467 | return; |
| 2468 | } |
| 2469 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2470 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2471 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2472 | return; |
| 2473 | } |
| 2474 | CFX_WideString wsValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2475 | bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2476 | if (bHasItem) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2477 | pArguments->GetReturnValue()->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2478 | FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2479 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2480 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2481 | } |
| 2482 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2483 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2484 | void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) { |
| 2485 | int32_t iLength = pArguments->GetLength(); |
| 2486 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2487 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"boundItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2488 | return; |
| 2489 | } |
| 2490 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2491 | if (!pWidgetData) { |
| 2492 | return; |
| 2493 | } |
| 2494 | CFX_ByteString bsValue = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2495 | CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2496 | CFX_WideString wsBoundValue; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2497 | pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2498 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2499 | if (pValue) |
| 2500 | pValue->SetString(FX_UTF8Encode(wsBoundValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2501 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2502 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2503 | void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) { |
| 2504 | int32_t iLength = pArguments->GetLength(); |
| 2505 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2506 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getItemState"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2507 | return; |
| 2508 | } |
| 2509 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2510 | if (!pWidgetData) { |
| 2511 | return; |
| 2512 | } |
| 2513 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2514 | bool bValue = pWidgetData->GetItemState(iIndex); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2515 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2516 | if (pValue) |
| 2517 | pValue->SetBoolean(bValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2518 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2519 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2520 | void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 2521 | int32_t argc = pArguments->GetLength(); |
| 2522 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2523 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2524 | if (!pNotify) { |
| 2525 | return; |
| 2526 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2527 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2528 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2529 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2530 | } |
| 2531 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2532 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2533 | void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2534 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2535 | void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) { |
| 2536 | int32_t iLength = pArguments->GetLength(); |
| 2537 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2538 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getDisplayItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2539 | return; |
| 2540 | } |
| 2541 | int32_t iIndex = pArguments->GetInt32(0); |
| 2542 | if (iIndex < 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2543 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2544 | return; |
| 2545 | } |
| 2546 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2547 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2548 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2549 | return; |
| 2550 | } |
| 2551 | CFX_WideString wsValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2552 | bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2553 | if (bHasItem) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2554 | pArguments->GetReturnValue()->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2555 | FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2556 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2557 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2558 | } |
| 2559 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2560 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2561 | void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) { |
| 2562 | int32_t iLength = pArguments->GetLength(); |
| 2563 | if (iLength != 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2564 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setItemState"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2565 | return; |
| 2566 | } |
| 2567 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2568 | if (!pWidgetData) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2569 | return; |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2570 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2571 | int32_t iIndex = pArguments->GetInt32(0); |
| 2572 | if (pArguments->GetInt32(1) != 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2573 | pWidgetData->SetItemState(iIndex, true, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2574 | } else { |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2575 | if (pWidgetData->GetItemState(iIndex)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2576 | pWidgetData->SetItemState(iIndex, false, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2577 | } |
| 2578 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2579 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2580 | void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) { |
| 2581 | int32_t iLength = pArguments->GetLength(); |
| 2582 | if (iLength < 1 || iLength > 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2583 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2584 | return; |
| 2585 | } |
| 2586 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2587 | if (!pWidgetData) { |
| 2588 | return; |
| 2589 | } |
| 2590 | CFX_WideString wsLabel; |
| 2591 | CFX_WideString wsValue; |
| 2592 | if (iLength >= 1) { |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 2593 | CFX_ByteString bsLabel = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2594 | wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2595 | } |
| 2596 | if (iLength >= 2) { |
| 2597 | CFX_ByteString bsValue = pArguments->GetUTF8String(1); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2598 | wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2599 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2600 | pWidgetData->InsertItem(wsLabel, wsValue, -1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2601 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2602 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2603 | void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 2604 | int32_t argc = pArguments->GetLength(); |
| 2605 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2606 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2607 | if (!pNotify) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2608 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2609 | } else { |
| 2610 | int32_t iRet = |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2611 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2612 | pArguments->GetReturnValue()->SetBoolean( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2613 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2614 | } |
| 2615 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2616 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2617 | } |
| 2618 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2619 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2620 | void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2621 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2622 | XFA_ATTRIBUTE eAttribute) { |
| 2623 | if (!bSetting) { |
| 2624 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2625 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2626 | } |
| 2627 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2628 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2629 | void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2630 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2631 | XFA_ATTRIBUTE eAttribute) { |
| 2632 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2633 | if (!pWidgetData) { |
| 2634 | return; |
| 2635 | } |
| 2636 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2637 | pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2638 | true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2639 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2640 | CFX_WideString wsValue = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2641 | XFA_VERSION curVersion = GetDocument()->GetCurVersionMode(); |
| 2642 | if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2643 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2644 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2645 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2646 | } |
| 2647 | } |
| 2648 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2649 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2650 | void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2651 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2652 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2653 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2654 | void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) { |
| 2655 | int32_t argc = pArguments->GetLength(); |
| 2656 | if (argc == 1) { |
| 2657 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2658 | execSingleEventByName( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2659 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2660 | XFA_Element::ExclGroup); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2661 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2662 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2663 | } |
| 2664 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2665 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2666 | void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) { |
| 2667 | int32_t argc = pArguments->GetLength(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2668 | if (argc < 0 || argc > 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2669 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"selectedMember"); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2670 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2671 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2672 | |
| 2673 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2674 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2675 | pArguments->GetReturnValue()->SetNull(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2676 | return; |
| 2677 | } |
| 2678 | |
| 2679 | CXFA_Node* pReturnNode = nullptr; |
| 2680 | if (argc == 0) { |
| 2681 | pReturnNode = pWidgetData->GetSelectedMember(); |
| 2682 | } else { |
| 2683 | CFX_ByteString szName; |
| 2684 | szName = pArguments->GetUTF8String(0); |
| 2685 | pReturnNode = pWidgetData->SetSelectedMember( |
| 2686 | CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true); |
| 2687 | } |
| 2688 | if (!pReturnNode) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2689 | pArguments->GetReturnValue()->SetNull(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2690 | return; |
| 2691 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2692 | pArguments->GetReturnValue()->Assign( |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2693 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2694 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2695 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2696 | void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 2697 | int32_t argc = pArguments->GetLength(); |
| 2698 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2699 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2700 | if (!pNotify) { |
| 2701 | return; |
| 2702 | } |
| 2703 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
| 2704 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2705 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2706 | } |
| 2707 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2708 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2709 | void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 2710 | int32_t argc = pArguments->GetLength(); |
| 2711 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2712 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2713 | if (!pNotify) { |
| 2714 | return; |
| 2715 | } |
| 2716 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 2717 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2718 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2719 | } |
| 2720 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2721 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2722 | void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 2723 | int32_t argc = pArguments->GetLength(); |
| 2724 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2725 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2726 | if (!pNotify) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2727 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2728 | } else { |
| 2729 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2730 | pArguments->GetReturnValue()->SetBoolean( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2731 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2732 | } |
| 2733 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2734 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2735 | } |
| 2736 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2737 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2738 | void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2739 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2740 | XFA_ATTRIBUTE eAttribute) { |
| 2741 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2742 | int32_t iTo = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2743 | int32_t iFrom = Subform_and_SubformSet_InstanceIndex(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2744 | CXFA_Node* pManagerNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2745 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2746 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2747 | if (pNode->GetElementType() == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2748 | pManagerNode = pNode; |
| 2749 | break; |
| 2750 | } |
| 2751 | } |
| 2752 | if (pManagerNode) { |
| 2753 | pManagerNode->InstanceManager_MoveInstance(iTo, iFrom); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2754 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2755 | if (!pNotify) { |
| 2756 | return; |
| 2757 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2758 | CXFA_Node* pToInstance = GetItem(pManagerNode, iTo); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2759 | if (pToInstance && |
| 2760 | pToInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2761 | pNotify->RunSubformIndexChange(pToInstance); |
| 2762 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2763 | CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2764 | if (pFromInstance && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2765 | pFromInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2766 | pNotify->RunSubformIndexChange(pFromInstance); |
| 2767 | } |
| 2768 | } |
| 2769 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2770 | pValue->SetInteger(Subform_and_SubformSet_InstanceIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2771 | } |
| 2772 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2773 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2774 | void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2775 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2776 | XFA_ATTRIBUTE eAttribute) { |
| 2777 | if (!bSetting) { |
| 2778 | CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2779 | CXFA_Node* pInstanceMgr = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2780 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2781 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2782 | if (pNode->GetElementType() == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2783 | CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 2784 | if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' && |
| 2785 | wsInstMgrName.Mid(1) == wsName) { |
| 2786 | pInstanceMgr = pNode; |
| 2787 | } |
| 2788 | break; |
| 2789 | } |
| 2790 | } |
| 2791 | if (pInstanceMgr) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2792 | pValue->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2793 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr)); |
| 2794 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2795 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2796 | } |
| 2797 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2798 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2799 | } |
| 2800 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2801 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2802 | void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2803 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2804 | XFA_ATTRIBUTE eAttribute) { |
| 2805 | if (bSetting) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2806 | SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2807 | } else { |
| 2808 | CFX_WideString wsLocaleName; |
| 2809 | GetLocaleName(wsLocaleName); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2810 | pValue->SetString( |
| 2811 | FX_UTF8Encode(wsLocaleName.c_str(), wsLocaleName.GetLength()) |
| 2812 | .AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2813 | } |
| 2814 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2815 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2816 | void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) { |
| 2817 | int32_t argc = pArguments->GetLength(); |
| 2818 | if (argc == 1) { |
| 2819 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2820 | execSingleEventByName( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2821 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2822 | XFA_Element::Subform); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2823 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2824 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2825 | } |
| 2826 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2827 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2828 | void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 2829 | int32_t argc = pArguments->GetLength(); |
| 2830 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2831 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2832 | if (!pNotify) { |
| 2833 | return; |
| 2834 | } |
| 2835 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
| 2836 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2837 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2838 | } |
| 2839 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2840 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2841 | void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 2842 | int32_t argc = pArguments->GetLength(); |
| 2843 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2844 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2845 | if (!pNotify) { |
| 2846 | return; |
| 2847 | } |
| 2848 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 2849 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2850 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2851 | } |
| 2852 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2853 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2854 | void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 2855 | int32_t argc = pArguments->GetLength(); |
| 2856 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2857 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2858 | if (!pNotify) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2859 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2860 | } else { |
| 2861 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2862 | pArguments->GetReturnValue()->SetBoolean( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2863 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2864 | } |
| 2865 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2866 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2867 | } |
| 2868 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2869 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2870 | void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) { |
| 2871 | int32_t argc = pArguments->GetLength(); |
| 2872 | if (argc == 0) { |
| 2873 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2874 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getInvalidObjects"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2875 | } |
| 2876 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2877 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2878 | int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() { |
| 2879 | int32_t index = 0; |
| 2880 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2881 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2882 | if ((pNode->GetElementType() == XFA_Element::Subform) || |
| 2883 | (pNode->GetElementType() == XFA_Element::SubformSet)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2884 | index++; |
| 2885 | } else { |
| 2886 | break; |
| 2887 | } |
| 2888 | } |
| 2889 | return index; |
| 2890 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2891 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2892 | void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) { |
| 2893 | int32_t argc = pArguments->GetLength(); |
| 2894 | if (argc == 1) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2895 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2896 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2897 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2898 | } |
| 2899 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2900 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2901 | void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) { |
| 2902 | int32_t argc = pArguments->GetLength(); |
| 2903 | if (argc == 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2904 | m_pDocument->DoDataRemerge(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2905 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2906 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2907 | } |
| 2908 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2909 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2910 | void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 2911 | int32_t argc = pArguments->GetLength(); |
| 2912 | if (argc == 0) { |
| 2913 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2914 | if (!pWidgetData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2915 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2916 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2917 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2918 | } |
| 2919 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2920 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2921 | } |
| 2922 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2923 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2924 | void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) { |
| 2925 | int32_t argc = pArguments->GetLength(); |
| 2926 | if ((argc > 0) && (argc < 4)) { |
| 2927 | CFX_WideString strTagName; |
| 2928 | CFX_WideString strName; |
| 2929 | CFX_WideString strNameSpace; |
| 2930 | CFX_ByteString bsTagName = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2931 | strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2932 | if (argc > 1) { |
| 2933 | CFX_ByteString bsName = pArguments->GetUTF8String(1); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2934 | strName = CFX_WideString::FromUTF8(bsName.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2935 | if (argc == 3) { |
| 2936 | CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2937 | strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2938 | } |
| 2939 | } |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 2940 | XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC()); |
| 2941 | CXFA_Node* pNewNode = CreateSamePacketNode(eType); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2942 | if (!pNewNode) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2943 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2944 | } else { |
| 2945 | if (!strName.IsEmpty()) { |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 2946 | if (GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name, |
| 2947 | XFA_XDPPACKET_UNKNOWN)) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 2948 | pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2949 | if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 2950 | pNewNode->CreateXMLMappingNode(); |
| 2951 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2952 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2953 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
| 2954 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2955 | ThrowException(XFA_IDS_NOT_HAVE_PROPERTY, strTagName.c_str(), |
| 2956 | L"name"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2957 | } |
| 2958 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2959 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2960 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
| 2961 | } |
| 2962 | } |
| 2963 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2964 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"createNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2965 | } |
| 2966 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2967 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2968 | void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) { |
| 2969 | if (pArguments->GetLength() == 1) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2970 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2971 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2972 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2973 | } |
| 2974 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2975 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2976 | void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 2977 | int32_t argc = pArguments->GetLength(); |
| 2978 | if (argc == 0) { |
| 2979 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2980 | if (!pWidgetData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2981 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2982 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2983 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2984 | } |
| 2985 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2986 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2987 | } |
| 2988 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2989 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2990 | void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 2991 | int32_t argc = pArguments->GetLength(); |
| 2992 | if (argc == 0) { |
| 2993 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2994 | if (!pWidgetData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2995 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2996 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2997 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2998 | } |
| 2999 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3000 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3001 | } |
| 3002 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3003 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3004 | void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) { |
| 3005 | int32_t argc = pArguments->GetLength(); |
| 3006 | if (argc == 0) { |
| 3007 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 3008 | if (!pWidgetData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3009 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3010 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3011 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3012 | } |
| 3013 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3014 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"evaluate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3015 | } |
| 3016 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3017 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3018 | void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3019 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3020 | XFA_ATTRIBUTE eAttribute) { |
| 3021 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3022 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3023 | return; |
| 3024 | } |
| 3025 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3026 | pValue->SetInteger(nodeOccur.GetMax()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3027 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3028 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3029 | void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3030 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3031 | XFA_ATTRIBUTE eAttribute) { |
| 3032 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3033 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3034 | return; |
| 3035 | } |
| 3036 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3037 | pValue->SetInteger(nodeOccur.GetMin()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3038 | } |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 3039 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3040 | void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3041 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3042 | XFA_ATTRIBUTE eAttribute) { |
| 3043 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3044 | int32_t iDesired = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3045 | InstanceManager_SetInstances(iDesired); |
| 3046 | } else { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3047 | pValue->SetInteger(GetCount(this)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3048 | } |
| 3049 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3050 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3051 | void CXFA_Node::Script_InstanceManager_MoveInstance( |
| 3052 | CFXJSE_Arguments* pArguments) { |
| 3053 | int32_t argc = pArguments->GetLength(); |
| 3054 | if (argc != 2) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3055 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3056 | return; |
| 3057 | } |
| 3058 | int32_t iFrom = pArguments->GetInt32(0); |
| 3059 | int32_t iTo = pArguments->GetInt32(1); |
| 3060 | InstanceManager_MoveInstance(iTo, iFrom); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3061 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3062 | if (!pNotify) { |
| 3063 | return; |
| 3064 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3065 | CXFA_Node* pToInstance = GetItem(this, iTo); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3066 | if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3067 | pNotify->RunSubformIndexChange(pToInstance); |
| 3068 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3069 | CXFA_Node* pFromInstance = GetItem(this, iFrom); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3070 | if (pFromInstance && |
| 3071 | pFromInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3072 | pNotify->RunSubformIndexChange(pFromInstance); |
| 3073 | } |
| 3074 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3075 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3076 | void CXFA_Node::Script_InstanceManager_RemoveInstance( |
| 3077 | CFXJSE_Arguments* pArguments) { |
| 3078 | int32_t argc = pArguments->GetLength(); |
| 3079 | if (argc != 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3080 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3081 | return; |
| 3082 | } |
| 3083 | int32_t iIndex = pArguments->GetInt32(0); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3084 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3085 | if (iIndex < 0 || iIndex >= iCount) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3086 | ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3087 | return; |
| 3088 | } |
| 3089 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3090 | int32_t iMin = nodeOccur.GetMin(); |
| 3091 | if (iCount - 1 < iMin) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3092 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3093 | return; |
| 3094 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3095 | CXFA_Node* pRemoveInstance = GetItem(this, iIndex); |
| 3096 | RemoveItem(this, pRemoveInstance); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3097 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3098 | if (pNotify) { |
| 3099 | for (int32_t i = iIndex; i < iCount - 1; i++) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3100 | CXFA_Node* pSubformInstance = GetItem(this, i); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3101 | if (pSubformInstance && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3102 | pSubformInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3103 | pNotify->RunSubformIndexChange(pSubformInstance); |
| 3104 | } |
| 3105 | } |
| 3106 | } |
| 3107 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3108 | if (!pLayoutPro) { |
| 3109 | return; |
| 3110 | } |
| 3111 | pLayoutPro->AddChangedContainer( |
| 3112 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3113 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3114 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3115 | void CXFA_Node::Script_InstanceManager_SetInstances( |
| 3116 | CFXJSE_Arguments* pArguments) { |
| 3117 | int32_t argc = pArguments->GetLength(); |
| 3118 | if (argc != 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3119 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3120 | return; |
| 3121 | } |
| 3122 | int32_t iDesired = pArguments->GetInt32(0); |
| 3123 | InstanceManager_SetInstances(iDesired); |
| 3124 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3125 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3126 | void CXFA_Node::Script_InstanceManager_AddInstance( |
| 3127 | CFXJSE_Arguments* pArguments) { |
| 3128 | int32_t argc = pArguments->GetLength(); |
| 3129 | if ((argc != 0) && (argc != 1)) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3130 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addInstance"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3131 | return; |
| 3132 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3133 | bool fFlags = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3134 | if (argc == 1) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3135 | fFlags = pArguments->GetInt32(0) == 0 ? false : true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3136 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3137 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3138 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3139 | int32_t iMax = nodeOccur.GetMax(); |
| 3140 | if (iMax >= 0 && iCount >= iMax) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3141 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3142 | return; |
| 3143 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3144 | CXFA_Node* pNewInstance = CreateInstance(this, fFlags); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3145 | InsertItem(this, pNewInstance, iCount, iCount, false); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3146 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3147 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance)); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3148 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3149 | if (!pNotify) { |
| 3150 | return; |
| 3151 | } |
| 3152 | pNotify->RunNodeInitialize(pNewInstance); |
| 3153 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3154 | if (!pLayoutPro) { |
| 3155 | return; |
| 3156 | } |
| 3157 | pLayoutPro->AddChangedContainer( |
| 3158 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3159 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3160 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3161 | void CXFA_Node::Script_InstanceManager_InsertInstance( |
| 3162 | CFXJSE_Arguments* pArguments) { |
| 3163 | int32_t argc = pArguments->GetLength(); |
| 3164 | if ((argc != 1) && (argc != 2)) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3165 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"insertInstance"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3166 | return; |
| 3167 | } |
| 3168 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3169 | bool bBind = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3170 | if (argc == 2) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3171 | bBind = pArguments->GetInt32(1) == 0 ? false : true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3172 | } |
| 3173 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3174 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3175 | if (iIndex < 0 || iIndex > iCount) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3176 | ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3177 | return; |
| 3178 | } |
| 3179 | int32_t iMax = nodeOccur.GetMax(); |
| 3180 | if (iMax >= 0 && iCount >= iMax) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3181 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3182 | return; |
| 3183 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3184 | CXFA_Node* pNewInstance = CreateInstance(this, bBind); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3185 | InsertItem(this, pNewInstance, iIndex, iCount, true); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3186 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3187 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance)); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3188 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3189 | if (!pNotify) { |
| 3190 | return; |
| 3191 | } |
| 3192 | pNotify->RunNodeInitialize(pNewInstance); |
| 3193 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3194 | if (!pLayoutPro) { |
| 3195 | return; |
| 3196 | } |
| 3197 | pLayoutPro->AddChangedContainer( |
| 3198 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3199 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3200 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3201 | int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) { |
| 3202 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3203 | int32_t iMax = nodeOccur.GetMax(); |
| 3204 | int32_t iMin = nodeOccur.GetMin(); |
| 3205 | if (iDesired < iMin) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3206 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3207 | return 1; |
| 3208 | } |
| 3209 | if ((iMax >= 0) && (iDesired > iMax)) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3210 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3211 | return 2; |
| 3212 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3213 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3214 | if (iDesired == iCount) { |
| 3215 | return 0; |
| 3216 | } |
| 3217 | if (iDesired < iCount) { |
| 3218 | CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3219 | CFX_WideString wsInstanceName = |
| 3220 | CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName |
| 3221 | : wsInstManagerName.Mid(1)); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 3222 | uint32_t dInstanceNameHash = |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 3223 | FX_HashCode_GetW(wsInstanceName.AsStringC(), false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3224 | CXFA_Node* pPrevSibling = |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3225 | (iDesired == 0) ? this : GetItem(this, iDesired - 1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3226 | while (iCount > iDesired) { |
| 3227 | CXFA_Node* pRemoveInstance = |
| 3228 | pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3229 | if (pRemoveInstance->GetElementType() != XFA_Element::Subform && |
| 3230 | pRemoveInstance->GetElementType() != XFA_Element::SubformSet) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3231 | continue; |
| 3232 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3233 | if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3234 | ASSERT(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3235 | break; |
| 3236 | } |
| 3237 | if (pRemoveInstance->GetNameHash() == dInstanceNameHash) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3238 | RemoveItem(this, pRemoveInstance); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3239 | iCount--; |
| 3240 | } |
| 3241 | } |
| 3242 | } else if (iDesired > iCount) { |
| 3243 | while (iCount < iDesired) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3244 | CXFA_Node* pNewInstance = CreateInstance(this, true); |
| 3245 | InsertItem(this, pNewInstance, iCount, iCount, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3246 | iCount++; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3247 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3248 | if (!pNotify) { |
| 3249 | return 0; |
| 3250 | } |
| 3251 | pNotify->RunNodeInitialize(pNewInstance); |
| 3252 | } |
| 3253 | } |
| 3254 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3255 | if (pLayoutPro) { |
| 3256 | pLayoutPro->AddChangedContainer( |
| 3257 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3258 | } |
| 3259 | return 0; |
| 3260 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3261 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3262 | int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3263 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3264 | if (iFrom > iCount || iTo > iCount - 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3265 | ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3266 | return 1; |
| 3267 | } |
| 3268 | if (iFrom < 0 || iTo < 0 || iFrom == iTo) { |
| 3269 | return 0; |
| 3270 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3271 | CXFA_Node* pMoveInstance = GetItem(this, iFrom); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3272 | RemoveItem(this, pMoveInstance, false); |
| 3273 | InsertItem(this, pMoveInstance, iTo, iCount - 1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3274 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3275 | if (pLayoutPro) { |
| 3276 | pLayoutPro->AddChangedContainer( |
| 3277 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3278 | } |
| 3279 | return 0; |
| 3280 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3281 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3282 | void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3283 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3284 | XFA_ATTRIBUTE eAttribute) { |
| 3285 | CXFA_Occur occur(this); |
| 3286 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3287 | int32_t iMax = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3288 | occur.SetMax(iMax); |
| 3289 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3290 | pValue->SetInteger(occur.GetMax()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3291 | } |
| 3292 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3293 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3294 | void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3295 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3296 | XFA_ATTRIBUTE eAttribute) { |
| 3297 | CXFA_Occur occur(this); |
| 3298 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3299 | int32_t iMin = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3300 | occur.SetMin(iMin); |
| 3301 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3302 | pValue->SetInteger(occur.GetMin()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3303 | } |
| 3304 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3305 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3306 | void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) { |
| 3307 | int32_t argc = pArguments->GetLength(); |
| 3308 | if ((argc == 0) || (argc == 1)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3309 | pArguments->GetReturnValue()->SetString(""); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3310 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3311 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"metadata"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3312 | } |
| 3313 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3314 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3315 | void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) { |
| 3316 | int32_t argc = pArguments->GetLength(); |
| 3317 | if (argc == 1) { |
| 3318 | CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 3319 | if (pDataNode) { |
| 3320 | CXFA_NodeArray formItems; |
| 3321 | CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); |
| 3322 | pFormNodes->SetArrayNodeList(formItems); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3323 | pArguments->GetReturnValue()->SetObject( |
| 3324 | pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3325 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3326 | ThrowException(XFA_IDS_ARGUMENT_MISMATCH); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3327 | } |
| 3328 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3329 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3330 | } |
| 3331 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3332 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3333 | void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) { |
| 3334 | int32_t argc = pArguments->GetLength(); |
| 3335 | if (argc == 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3336 | m_pDocument->DoDataRemerge(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3337 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3338 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3339 | } |
| 3340 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3341 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3342 | void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 3343 | int32_t argc = pArguments->GetLength(); |
| 3344 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3345 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3346 | if (!pNotify) { |
| 3347 | return; |
| 3348 | } |
| 3349 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
| 3350 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3351 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3352 | } |
| 3353 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3354 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3355 | void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) { |
| 3356 | CXFA_EventParam* pEventParam = |
| 3357 | m_pDocument->GetScriptContext()->GetEventParam(); |
| 3358 | if (pEventParam->m_eType == XFA_EVENT_Calculate || |
| 3359 | pEventParam->m_eType == XFA_EVENT_InitCalculate) { |
| 3360 | return; |
| 3361 | } |
| 3362 | int32_t argc = pArguments->GetLength(); |
| 3363 | if (argc == 1) { |
| 3364 | const bool bScriptFlags = pArguments->GetInt32(0) != 0; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3365 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3366 | if (!pNotify) { |
| 3367 | return; |
| 3368 | } |
| 3369 | if (bScriptFlags) { |
| 3370 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 3371 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3372 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3373 | } else { |
| 3374 | } |
| 3375 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3376 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3377 | } |
| 3378 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3379 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3380 | void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 3381 | int32_t argc = pArguments->GetLength(); |
| 3382 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3383 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3384 | if (!pNotify) { |
| 3385 | return; |
| 3386 | } |
| 3387 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 3388 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3389 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3390 | } |
| 3391 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3392 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3393 | void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 3394 | int32_t argc = pArguments->GetLength(); |
| 3395 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3396 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3397 | if (!pNotify) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3398 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3399 | } else { |
| 3400 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3401 | pArguments->GetReturnValue()->SetBoolean( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3402 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3403 | } |
| 3404 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3405 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3406 | } |
| 3407 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3408 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3409 | void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3410 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3411 | XFA_ATTRIBUTE eAttribute) { |
| 3412 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 3413 | SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3414 | } else { |
| 3415 | CFX_WideString wsChecksum; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3416 | GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3417 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3418 | FX_UTF8Encode(wsChecksum.c_str(), wsChecksum.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3419 | } |
| 3420 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3421 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3422 | void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) { |
| 3423 | int32_t argc = pArguments->GetLength(); |
| 3424 | if (argc == 1) { |
| 3425 | CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0); |
| 3426 | CFX_WideString wsAttributeValue; |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3427 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3428 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3429 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetString( |
| 3430 | CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(), |
| 3431 | wsAttributeValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3432 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3433 | pArguments->GetReturnValue()->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3434 | FX_UTF8Encode(wsAttributeValue.c_str(), wsAttributeValue.GetLength()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 3435 | .AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3436 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3437 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3438 | } |
| 3439 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3440 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3441 | void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) { |
| 3442 | int32_t argc = pArguments->GetLength(); |
| 3443 | if (argc == 2) { |
| 3444 | CFX_ByteString bsValue = pArguments->GetUTF8String(0); |
| 3445 | CFX_ByteString bsName = pArguments->GetUTF8String(1); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3446 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3447 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3448 | static_cast<CFDE_XMLElement*>(pXMLNode)->SetString( |
| 3449 | CFX_WideString::FromUTF8(bsName.AsStringC()), |
| 3450 | CFX_WideString::FromUTF8(bsValue.AsStringC())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3451 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3452 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3453 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3454 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3455 | } |
| 3456 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3457 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3458 | void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) { |
| 3459 | int32_t argc = pArguments->GetLength(); |
| 3460 | if (argc == 1) { |
| 3461 | CFX_ByteString bsName = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 3462 | CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC()); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3463 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3464 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3465 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3466 | if (pXMLElement->HasAttribute(wsName.c_str())) { |
| 3467 | pXMLElement->RemoveAttribute(wsName.c_str()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3468 | } |
| 3469 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3470 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3471 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3472 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"removeAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3473 | } |
| 3474 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3475 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3476 | void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3477 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3478 | XFA_ATTRIBUTE eAttribute) { |
| 3479 | if (bSetting) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3480 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3481 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3482 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 3483 | pXMLElement->SetTextData(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3484 | } |
| 3485 | } else { |
| 3486 | CFX_WideString wsTextData; |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3487 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3488 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3489 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3490 | pXMLElement->GetTextData(wsTextData); |
| 3491 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3492 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3493 | FX_UTF8Encode(wsTextData.c_str(), wsTextData.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3494 | } |
| 3495 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3496 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3497 | void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) { |
| 3498 | int32_t argc = pArguments->GetLength(); |
| 3499 | if (argc == 0) { |
| 3500 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3501 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"next"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3502 | } |
| 3503 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3504 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3505 | void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) { |
| 3506 | int32_t argc = pArguments->GetLength(); |
| 3507 | if (argc == 0) { |
| 3508 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3509 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancelBatch"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3510 | } |
| 3511 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3512 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3513 | void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) { |
| 3514 | int32_t argc = pArguments->GetLength(); |
| 3515 | if (argc == 0) { |
| 3516 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3517 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"first"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3518 | } |
| 3519 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3520 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3521 | void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) { |
| 3522 | int32_t argc = pArguments->GetLength(); |
| 3523 | if (argc == 0) { |
| 3524 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3525 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"updateBatch"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3526 | } |
| 3527 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3528 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3529 | void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) { |
| 3530 | int32_t argc = pArguments->GetLength(); |
| 3531 | if (argc == 0) { |
| 3532 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3533 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"previous"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3534 | } |
| 3535 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3536 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3537 | void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) { |
| 3538 | int32_t argc = pArguments->GetLength(); |
| 3539 | if (argc == 0) { |
| 3540 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3541 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isBOF"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3542 | } |
| 3543 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3544 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3545 | void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) { |
| 3546 | int32_t argc = pArguments->GetLength(); |
| 3547 | if (argc == 0) { |
| 3548 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3549 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isEOF"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3550 | } |
| 3551 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3552 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3553 | void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) { |
| 3554 | int32_t argc = pArguments->GetLength(); |
| 3555 | if (argc == 0) { |
| 3556 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3557 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancel"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3558 | } |
| 3559 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3560 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3561 | void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) { |
| 3562 | int32_t argc = pArguments->GetLength(); |
| 3563 | if (argc == 0) { |
| 3564 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3565 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"update"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3566 | } |
| 3567 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3568 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3569 | void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) { |
| 3570 | int32_t argc = pArguments->GetLength(); |
| 3571 | if (argc == 0) { |
| 3572 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3573 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"open"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3574 | } |
| 3575 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3576 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3577 | void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) { |
| 3578 | int32_t argc = pArguments->GetLength(); |
| 3579 | if (argc == 0) { |
| 3580 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3581 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"delete"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3582 | } |
| 3583 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3584 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3585 | void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) { |
| 3586 | int32_t argc = pArguments->GetLength(); |
| 3587 | if (argc == 0) { |
| 3588 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3589 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addNew"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3590 | } |
| 3591 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3592 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3593 | void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) { |
| 3594 | int32_t argc = pArguments->GetLength(); |
| 3595 | if (argc == 0) { |
| 3596 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3597 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"requery"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3598 | } |
| 3599 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3600 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3601 | void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) { |
| 3602 | int32_t argc = pArguments->GetLength(); |
| 3603 | if (argc == 0) { |
| 3604 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3605 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resync"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3606 | } |
| 3607 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3608 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3609 | void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) { |
| 3610 | int32_t argc = pArguments->GetLength(); |
| 3611 | if (argc == 0) { |
| 3612 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3613 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"close"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3614 | } |
| 3615 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3616 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3617 | void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) { |
| 3618 | int32_t argc = pArguments->GetLength(); |
| 3619 | if (argc == 0) { |
| 3620 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3621 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"last"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3622 | } |
| 3623 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3624 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3625 | void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) { |
| 3626 | int32_t argc = pArguments->GetLength(); |
| 3627 | if (argc == 0) { |
| 3628 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3629 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"hasDataChanged"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3630 | } |
| 3631 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3632 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3633 | void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3634 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3635 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3636 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3637 | void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3638 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3639 | XFA_ATTRIBUTE eAttribute) { |
| 3640 | if (!bSetting) { |
| 3641 | CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3642 | ASSERT(pThis); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3643 | pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3644 | } |
| 3645 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3646 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3647 | void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3648 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3649 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3650 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3651 | void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3652 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3653 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3654 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3655 | void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3656 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3657 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3658 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3659 | void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3660 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3661 | XFA_ATTRIBUTE eAttribute) { |
| 3662 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3663 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3664 | return; |
| 3665 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3666 | pValue->SetString(FX_UTF8Encode(FX_WSTRC(L"0")).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3667 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3668 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3669 | void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3670 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3671 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3672 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3673 | bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3674 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3675 | return HasMapModuleKey(pKey, bCanInherit); |
| 3676 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3677 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3678 | bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr, |
| 3679 | const CFX_WideStringC& wsValue, |
| 3680 | bool bNotify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3681 | const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3682 | if (!pAttr) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3683 | return false; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3684 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3685 | XFA_ATTRIBUTETYPE eType = pAttr->eType; |
| 3686 | if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
| 3687 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3688 | XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3689 | eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3690 | } |
| 3691 | switch (eType) { |
| 3692 | case XFA_ATTRIBUTETYPE_Enum: { |
| 3693 | const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue); |
| 3694 | return SetEnum(pAttr->eName, |
| 3695 | pEnum ? pEnum->eName |
| 3696 | : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue), |
| 3697 | bNotify); |
| 3698 | } break; |
| 3699 | case XFA_ATTRIBUTETYPE_Cdata: |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3700 | return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3701 | case XFA_ATTRIBUTETYPE_Boolean: |
| 3702 | return SetBoolean(pAttr->eName, wsValue != FX_WSTRC(L"0"), bNotify); |
| 3703 | case XFA_ATTRIBUTETYPE_Integer: |
dsinclair | e0347a6 | 2016-08-11 11:24:11 -0700 | [diff] [blame] | 3704 | return SetInteger(pAttr->eName, |
| 3705 | FXSYS_round(FXSYS_wcstof(wsValue.c_str(), |
| 3706 | wsValue.GetLength(), nullptr)), |
| 3707 | bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3708 | case XFA_ATTRIBUTETYPE_Measure: |
| 3709 | return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify); |
| 3710 | default: |
| 3711 | break; |
| 3712 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3713 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3714 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3715 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3716 | bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr, |
| 3717 | CFX_WideString& wsValue, |
| 3718 | bool bUseDefault) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3719 | const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3720 | if (!pAttr) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3721 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3722 | } |
| 3723 | XFA_ATTRIBUTETYPE eType = pAttr->eType; |
| 3724 | if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
| 3725 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3726 | XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3727 | eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3728 | } |
| 3729 | switch (eType) { |
| 3730 | case XFA_ATTRIBUTETYPE_Enum: { |
| 3731 | XFA_ATTRIBUTEENUM eValue; |
| 3732 | if (!TryEnum(pAttr->eName, eValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3733 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3734 | } |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 3735 | wsValue = GetAttributeEnumByID(eValue)->pName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3736 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3737 | } break; |
| 3738 | case XFA_ATTRIBUTETYPE_Cdata: { |
| 3739 | CFX_WideStringC wsValueC; |
| 3740 | if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3741 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3742 | } |
| 3743 | wsValue = wsValueC; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3744 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3745 | } break; |
| 3746 | case XFA_ATTRIBUTETYPE_Boolean: { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3747 | bool bValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3748 | if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3749 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3750 | } |
| 3751 | wsValue = bValue ? FX_WSTRC(L"1") : FX_WSTRC(L"0"); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3752 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3753 | } break; |
| 3754 | case XFA_ATTRIBUTETYPE_Integer: { |
| 3755 | int32_t iValue; |
| 3756 | if (!TryInteger(pAttr->eName, iValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3757 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3758 | } |
| 3759 | wsValue.Format(L"%d", iValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3760 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3761 | } break; |
| 3762 | case XFA_ATTRIBUTETYPE_Measure: { |
| 3763 | CXFA_Measurement mValue; |
| 3764 | if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3765 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3766 | } |
| 3767 | mValue.ToString(wsValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3768 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3769 | } break; |
| 3770 | default: |
| 3771 | break; |
| 3772 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3773 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3774 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3775 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3776 | bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr, |
| 3777 | const CFX_WideStringC& wsValue, |
| 3778 | bool bNotify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3779 | const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue); |
| 3780 | if (pAttributeInfo) { |
| 3781 | return SetAttribute(pAttributeInfo->eName, wsValue, bNotify); |
| 3782 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3783 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3784 | SetMapModuleString(pKey, wsValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3785 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3786 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3787 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3788 | bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr, |
| 3789 | CFX_WideString& wsValue, |
| 3790 | bool bUseDefault) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3791 | const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr); |
| 3792 | if (pAttributeInfo) { |
| 3793 | return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault); |
| 3794 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3795 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3796 | CFX_WideStringC wsValueC; |
| 3797 | if (GetMapModuleString(pKey, wsValueC)) { |
| 3798 | wsValue = wsValueC; |
| 3799 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3800 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3801 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3802 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3803 | bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3804 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3805 | RemoveMapModuleKey(pKey); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3806 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3807 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3808 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3809 | bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr, |
| 3810 | bool& bValue, |
| 3811 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3812 | void* pValue = nullptr; |
| 3813 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3814 | return false; |
tsepez | 478ed62 | 2016-10-27 14:32:33 -0700 | [diff] [blame] | 3815 | bValue = !!pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3816 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3817 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3818 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3819 | bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr, |
| 3820 | int32_t& iValue, |
| 3821 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3822 | void* pValue = nullptr; |
| 3823 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3824 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3825 | iValue = (int32_t)(uintptr_t)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3826 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3827 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3828 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3829 | bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr, |
| 3830 | XFA_ATTRIBUTEENUM& eValue, |
| 3831 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3832 | void* pValue = nullptr; |
| 3833 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3834 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3835 | eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3836 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3837 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3838 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3839 | bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr, |
| 3840 | CXFA_Measurement mValue, |
| 3841 | bool bNotify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3842 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3843 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3844 | SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3845 | OnChanged(eAttr, bNotify, false); |
| 3846 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3847 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3848 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3849 | bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr, |
| 3850 | CXFA_Measurement& mValue, |
| 3851 | bool bUseDefault) const { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3852 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3853 | void* pValue; |
| 3854 | int32_t iBytes; |
| 3855 | if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) { |
| 3856 | FXSYS_memcpy(&mValue, pValue, sizeof(mValue)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3857 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3858 | } |
| 3859 | if (bUseDefault && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3860 | XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3861 | XFA_ATTRIBUTETYPE_Measure, m_ePacket)) { |
| 3862 | FXSYS_memcpy(&mValue, pValue, sizeof(mValue)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3863 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3864 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3865 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3866 | } |
| 3867 | |
| 3868 | CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const { |
| 3869 | CXFA_Measurement mValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3870 | return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3871 | } |
| 3872 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3873 | bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr, |
| 3874 | const CFX_WideString& wsValue, |
| 3875 | bool bNotify, |
| 3876 | bool bScriptModify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3877 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3878 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3879 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3880 | CFX_WideString* pClone = new CFX_WideString(wsValue); |
| 3881 | SetUserData(pKey, pClone, &deleteWideStringCallBack); |
| 3882 | } else { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 3883 | SetMapModuleString(pKey, wsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3884 | if (eAttr == XFA_ATTRIBUTE_Name) |
| 3885 | UpdateNameHash(); |
| 3886 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3887 | OnChanged(eAttr, bNotify, bScriptModify); |
| 3888 | |
| 3889 | if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName || |
| 3890 | eAttr == XFA_ATTRIBUTE_BindingNode) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3891 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3892 | } |
| 3893 | |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3894 | if (eAttr == XFA_ATTRIBUTE_Name && |
| 3895 | (m_elementType == XFA_Element::DataValue || |
| 3896 | m_elementType == XFA_Element::DataGroup)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3897 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3898 | } |
| 3899 | |
| 3900 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3901 | FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType(); |
| 3902 | switch (eXMLType) { |
| 3903 | case FDE_XMLNODE_Element: |
| 3904 | if (IsAttributeInXML()) { |
| 3905 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3906 | ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)), |
| 3907 | wsValue); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3908 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3909 | bool bDeleteChildren = true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3910 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 3911 | for (CXFA_Node* pChildDataNode = |
| 3912 | GetNodeItem(XFA_NODEITEM_FirstChild); |
| 3913 | pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( |
| 3914 | XFA_NODEITEM_NextSibling)) { |
| 3915 | CXFA_NodeArray formNodes; |
| 3916 | if (pChildDataNode->GetBindItems(formNodes) > 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3917 | bDeleteChildren = false; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3918 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3919 | } |
| 3920 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3921 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3922 | if (bDeleteChildren) { |
| 3923 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren(); |
| 3924 | } |
| 3925 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue); |
| 3926 | } |
| 3927 | break; |
| 3928 | case FDE_XMLNODE_Text: |
| 3929 | static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue); |
| 3930 | break; |
| 3931 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3932 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3933 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3934 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3935 | } |
| 3936 | |
| 3937 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 3938 | if (pInfo) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3939 | ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3940 | CFX_WideString wsAttrName = pInfo->pName; |
| 3941 | if (pInfo->eName == XFA_ATTRIBUTE_ContentType) { |
| 3942 | wsAttrName = FX_WSTRC(L"xfa:") + wsAttrName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3943 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3944 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3945 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3946 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3947 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3948 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3949 | bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue, |
| 3950 | const CFX_WideString& wsXMLValue, |
| 3951 | bool bNotify, |
| 3952 | bool bScriptModify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3953 | void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3954 | OnChanging(XFA_ATTRIBUTE_Value, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3955 | CFX_WideString* pClone = new CFX_WideString(wsValue); |
| 3956 | SetUserData(pKey, pClone, &deleteWideStringCallBack); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3957 | OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3958 | if (IsNeedSavingXMLNode()) { |
| 3959 | FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType(); |
| 3960 | switch (eXMLType) { |
| 3961 | case FDE_XMLNODE_Element: |
| 3962 | if (IsAttributeInXML()) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3963 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3964 | ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)), |
| 3965 | wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3966 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3967 | bool bDeleteChildren = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3968 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 3969 | for (CXFA_Node* pChildDataNode = |
| 3970 | GetNodeItem(XFA_NODEITEM_FirstChild); |
| 3971 | pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( |
| 3972 | XFA_NODEITEM_NextSibling)) { |
| 3973 | CXFA_NodeArray formNodes; |
| 3974 | if (pChildDataNode->GetBindItems(formNodes) > 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3975 | bDeleteChildren = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3976 | break; |
| 3977 | } |
| 3978 | } |
| 3979 | } |
| 3980 | if (bDeleteChildren) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3981 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3982 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3983 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3984 | } |
| 3985 | break; |
| 3986 | case FDE_XMLNODE_Text: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3987 | static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3988 | break; |
| 3989 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3990 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3991 | } |
| 3992 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3993 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3994 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3995 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3996 | bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, |
| 3997 | CFX_WideString& wsValue, |
| 3998 | bool bUseDefault, |
| 3999 | bool bProto) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4000 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4001 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 4002 | CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); |
| 4003 | if (pStr) { |
| 4004 | wsValue = *pStr; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4005 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4006 | } |
| 4007 | } else { |
| 4008 | CFX_WideStringC wsValueC; |
| 4009 | if (GetMapModuleString(pKey, wsValueC)) { |
| 4010 | wsValue = wsValueC; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4011 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4012 | } |
| 4013 | } |
| 4014 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4015 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4016 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4017 | void* pValue = nullptr; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4018 | if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4019 | XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { |
| 4020 | wsValue = (const FX_WCHAR*)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4021 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4022 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4023 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4024 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4025 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4026 | bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, |
| 4027 | CFX_WideStringC& wsValue, |
| 4028 | bool bUseDefault, |
| 4029 | bool bProto) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4030 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4031 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 4032 | CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); |
| 4033 | if (pStr) { |
tsepez | 4d31d0c | 2016-04-19 14:11:59 -0700 | [diff] [blame] | 4034 | wsValue = pStr->AsStringC(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4035 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4036 | } |
| 4037 | } else { |
| 4038 | if (GetMapModuleString(pKey, wsValue)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4039 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4040 | } |
| 4041 | } |
| 4042 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4043 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4044 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4045 | void* pValue = nullptr; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4046 | if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4047 | XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { |
| 4048 | wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4049 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4050 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4051 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4052 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4053 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4054 | bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr, |
| 4055 | void* pData, |
| 4056 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4057 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4058 | return SetUserData(pKey, pData, pCallbackInfo); |
| 4059 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4060 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4061 | bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4062 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4063 | pData = GetUserData(pKey); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 4064 | return !!pData; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4065 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4066 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4067 | bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr, |
| 4068 | XFA_ATTRIBUTETYPE eType, |
| 4069 | void* pValue, |
| 4070 | bool bNotify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4071 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4072 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4073 | SetMapModuleValue(pKey, pValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4074 | OnChanged(eAttr, bNotify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4075 | if (IsNeedSavingXMLNode()) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4076 | ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4077 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 4078 | if (pInfo) { |
| 4079 | switch (eType) { |
| 4080 | case XFA_ATTRIBUTETYPE_Enum: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4081 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4082 | ->SetString( |
| 4083 | pInfo->pName, |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 4084 | GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4085 | ->pName); |
| 4086 | break; |
| 4087 | case XFA_ATTRIBUTETYPE_Boolean: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4088 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4089 | ->SetString(pInfo->pName, pValue ? L"1" : L"0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4090 | break; |
| 4091 | case XFA_ATTRIBUTETYPE_Integer: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4092 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4093 | ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue); |
| 4094 | break; |
| 4095 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4096 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4097 | } |
| 4098 | } |
| 4099 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4100 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4101 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4102 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4103 | bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr, |
| 4104 | XFA_ATTRIBUTETYPE eType, |
| 4105 | bool bUseDefault, |
| 4106 | void*& pValue) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4107 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4108 | if (GetMapModuleValue(pKey, pValue)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4109 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4110 | } |
| 4111 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4112 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4113 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4114 | return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4115 | m_ePacket); |
| 4116 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4117 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4118 | bool CXFA_Node::SetUserData(void* pKey, |
| 4119 | void* pData, |
| 4120 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4121 | SetMapModuleBuffer(pKey, &pData, sizeof(void*), |
| 4122 | pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4123 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4124 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4125 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4126 | bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4127 | int32_t iBytes = 0; |
| 4128 | if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4129 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4130 | } |
| 4131 | return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes); |
| 4132 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4133 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4134 | bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, |
| 4135 | const CFX_WideString& wsXMLValue, |
| 4136 | bool bNotify, |
| 4137 | bool bScriptModify, |
| 4138 | bool bSyncData) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4139 | CXFA_Node* pNode = nullptr; |
| 4140 | CXFA_Node* pBindNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4141 | switch (GetObjectType()) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4142 | case XFA_ObjectType::ContainerNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4143 | if (XFA_FieldIsMultiListBox(this)) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4144 | CXFA_Node* pValue = GetProperty(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4145 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4146 | ASSERT(pChildValue); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4147 | pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4148 | pChildValue->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4149 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4150 | CXFA_Node* pBind = GetBindData(); |
| 4151 | if (bSyncData && pBind) { |
| 4152 | CFX_WideStringArray wsSaveTextArray; |
| 4153 | int32_t iSize = 0; |
| 4154 | if (!wsContent.IsEmpty()) { |
| 4155 | int32_t iStart = 0; |
| 4156 | int32_t iLength = wsContent.GetLength(); |
| 4157 | int32_t iEnd = wsContent.Find(L'\n', iStart); |
| 4158 | iEnd = (iEnd == -1) ? iLength : iEnd; |
| 4159 | while (iEnd >= iStart) { |
| 4160 | wsSaveTextArray.Add(wsContent.Mid(iStart, iEnd - iStart)); |
| 4161 | iStart = iEnd + 1; |
| 4162 | if (iStart >= iLength) { |
| 4163 | break; |
| 4164 | } |
| 4165 | iEnd = wsContent.Find(L'\n', iStart); |
| 4166 | if (iEnd < 0) { |
| 4167 | wsSaveTextArray.Add(wsContent.Mid(iStart, iLength - iStart)); |
| 4168 | } |
| 4169 | } |
| 4170 | iSize = wsSaveTextArray.GetSize(); |
| 4171 | } |
| 4172 | if (iSize == 0) { |
| 4173 | while (CXFA_Node* pChildNode = |
| 4174 | pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) { |
| 4175 | pBind->RemoveChild(pChildNode); |
| 4176 | } |
| 4177 | } else { |
| 4178 | CXFA_NodeArray valueNodes; |
| 4179 | int32_t iDatas = pBind->GetNodeList( |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4180 | valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4181 | if (iDatas < iSize) { |
| 4182 | int32_t iAddNodes = iSize - iDatas; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4183 | CXFA_Node* pValueNodes = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4184 | while (iAddNodes-- > 0) { |
| 4185 | pValueNodes = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4186 | pBind->CreateSamePacketNode(XFA_Element::DataValue); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4187 | pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4188 | pValueNodes->CreateXMLMappingNode(); |
| 4189 | pBind->InsertChild(pValueNodes); |
| 4190 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4191 | pValueNodes = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4192 | } else if (iDatas > iSize) { |
| 4193 | int32_t iDelNodes = iDatas - iSize; |
| 4194 | while (iDelNodes-- > 0) { |
| 4195 | pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild)); |
| 4196 | } |
| 4197 | } |
| 4198 | int32_t i = 0; |
| 4199 | for (CXFA_Node* pValueNode = |
| 4200 | pBind->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4201 | pValueNode; pValueNode = pValueNode->GetNodeItem( |
| 4202 | XFA_NODEITEM_NextSibling)) { |
| 4203 | pValueNode->SetAttributeValue(wsSaveTextArray[i], |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4204 | wsSaveTextArray[i], false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4205 | i++; |
| 4206 | } |
| 4207 | } |
| 4208 | CXFA_NodeArray nodeArray; |
| 4209 | pBind->GetBindItems(nodeArray); |
| 4210 | for (int32_t i = 0; i < nodeArray.GetSize(); i++) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 4211 | if (nodeArray[i] != this) { |
| 4212 | nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4213 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4214 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4215 | } |
| 4216 | } |
| 4217 | break; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4218 | } else if (GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4219 | pNode = this; |
| 4220 | } else { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4221 | CXFA_Node* pValue = GetProperty(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4222 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4223 | ASSERT(pChildValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4224 | pChildValue->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4225 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4226 | } |
| 4227 | pBindNode = GetBindData(); |
| 4228 | if (pBindNode && bSyncData) { |
| 4229 | pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4230 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4231 | CXFA_NodeArray nodeArray; |
| 4232 | pBindNode->GetBindItems(nodeArray); |
| 4233 | for (int32_t i = 0; i < nodeArray.GetSize(); i++) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 4234 | if (nodeArray[i] != this) { |
| 4235 | nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4236 | false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4237 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4238 | } |
| 4239 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4240 | pBindNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4241 | break; |
| 4242 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4243 | case XFA_ObjectType::ContentNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4244 | CFX_WideString wsContentType; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4245 | if (GetElementType() == XFA_Element::ExData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4246 | GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false); |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4247 | if (wsContentType == FX_WSTRC(L"text/html")) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4248 | wsContentType = FX_WSTRC(L""); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 4249 | SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4250 | } |
| 4251 | } |
| 4252 | CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4253 | if (!pContentRawDataNode) { |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4254 | pContentRawDataNode = CreateSamePacketNode( |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4255 | (wsContentType == FX_WSTRC(L"text/xml")) ? XFA_Element::Sharpxml |
| 4256 | : XFA_Element::Sharptext); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4257 | InsertChild(pContentRawDataNode); |
| 4258 | } |
| 4259 | return pContentRawDataNode->SetScriptContent( |
| 4260 | wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData); |
| 4261 | } break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4262 | case XFA_ObjectType::NodeC: |
| 4263 | case XFA_ObjectType::TextNode: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4264 | pNode = this; |
| 4265 | break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4266 | case XFA_ObjectType::NodeV: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4267 | pNode = this; |
| 4268 | if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) { |
| 4269 | CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); |
| 4270 | if (pParent) { |
| 4271 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
| 4272 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4273 | if (pParent && pParent->GetElementType() == XFA_Element::Value) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4274 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
| 4275 | if (pParent && pParent->IsContainerNode()) { |
| 4276 | pBindNode = pParent->GetBindData(); |
| 4277 | if (pBindNode) { |
| 4278 | pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4279 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4280 | } |
| 4281 | } |
| 4282 | } |
| 4283 | } |
| 4284 | break; |
| 4285 | default: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4286 | if (GetElementType() == XFA_Element::DataValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4287 | pNode = this; |
| 4288 | pBindNode = this; |
| 4289 | } |
| 4290 | break; |
| 4291 | } |
| 4292 | if (pNode) { |
| 4293 | SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify); |
| 4294 | if (pBindNode && bSyncData) { |
| 4295 | CXFA_NodeArray nodeArray; |
| 4296 | pBindNode->GetBindItems(nodeArray); |
| 4297 | for (int32_t i = 0; i < nodeArray.GetSize(); i++) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 4298 | nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4299 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4300 | } |
| 4301 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4302 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4303 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4304 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4305 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4306 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4307 | bool CXFA_Node::SetContent(const CFX_WideString& wsContent, |
| 4308 | const CFX_WideString& wsXMLValue, |
| 4309 | bool bNotify, |
| 4310 | bool bScriptModify, |
| 4311 | bool bSyncData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4312 | return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify, |
| 4313 | bSyncData); |
| 4314 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4315 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4316 | CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4317 | CFX_WideString wsContent; |
| 4318 | return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString(); |
| 4319 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4320 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4321 | CFX_WideString CXFA_Node::GetContent() { |
| 4322 | return GetScriptContent(); |
| 4323 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4324 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4325 | bool CXFA_Node::TryContent(CFX_WideString& wsContent, |
| 4326 | bool bScriptModify, |
| 4327 | bool bProto) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4328 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4329 | switch (GetObjectType()) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4330 | case XFA_ObjectType::ContainerNode: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4331 | if (GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4332 | pNode = this; |
| 4333 | } else { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4334 | CXFA_Node* pValue = GetChild(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4335 | if (!pValue) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4336 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4337 | } |
| 4338 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4339 | if (pChildValue && XFA_FieldIsMultiListBox(this)) { |
| 4340 | pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, |
| 4341 | FX_WSTRC(L"text/xml")); |
| 4342 | } |
| 4343 | return pChildValue |
| 4344 | ? pChildValue->TryContent(wsContent, bScriptModify, bProto) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4345 | : false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4346 | } |
| 4347 | break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4348 | case XFA_ObjectType::ContentNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4349 | CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4350 | if (!pContentRawDataNode) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4351 | XFA_Element element = XFA_Element::Sharptext; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4352 | if (GetElementType() == XFA_Element::ExData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4353 | CFX_WideString wsContentType; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4354 | GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false); |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4355 | if (wsContentType == FX_WSTRC(L"text/html")) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4356 | element = XFA_Element::SharpxHTML; |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4357 | } else if (wsContentType == FX_WSTRC(L"text/xml")) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4358 | element = XFA_Element::Sharpxml; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4359 | } |
| 4360 | } |
| 4361 | pContentRawDataNode = CreateSamePacketNode(element); |
| 4362 | InsertChild(pContentRawDataNode); |
| 4363 | } |
| 4364 | return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto); |
| 4365 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4366 | case XFA_ObjectType::NodeC: |
| 4367 | case XFA_ObjectType::NodeV: |
| 4368 | case XFA_ObjectType::TextNode: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4369 | pNode = this; |
| 4370 | default: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4371 | if (GetElementType() == XFA_Element::DataValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4372 | pNode = this; |
| 4373 | } |
| 4374 | break; |
| 4375 | } |
| 4376 | if (pNode) { |
| 4377 | if (bScriptModify) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4378 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4379 | if (pScriptContext) { |
| 4380 | m_pDocument->GetScriptContext()->AddNodesOfRunScript(this); |
| 4381 | } |
| 4382 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4383 | return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4384 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4385 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4386 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4387 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4388 | CXFA_Node* CXFA_Node::GetModelNode() { |
| 4389 | switch (GetPacketID()) { |
| 4390 | case XFA_XDPPACKET_XDP: |
| 4391 | return m_pDocument->GetRoot(); |
| 4392 | case XFA_XDPPACKET_Config: |
| 4393 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config)); |
| 4394 | case XFA_XDPPACKET_Template: |
| 4395 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template)); |
| 4396 | case XFA_XDPPACKET_Form: |
| 4397 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)); |
| 4398 | case XFA_XDPPACKET_Datasets: |
| 4399 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets)); |
| 4400 | case XFA_XDPPACKET_LocaleSet: |
| 4401 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet)); |
| 4402 | case XFA_XDPPACKET_ConnectionSet: |
| 4403 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet)); |
| 4404 | case XFA_XDPPACKET_SourceSet: |
| 4405 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet)); |
| 4406 | case XFA_XDPPACKET_Xdc: |
| 4407 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc)); |
| 4408 | default: |
| 4409 | return this; |
| 4410 | } |
| 4411 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4412 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4413 | bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) { |
tsepez | 774bdde | 2016-04-14 09:49:44 -0700 | [diff] [blame] | 4414 | wsNamespace.clear(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4415 | if (IsModelNode() || GetElementType() == XFA_Element::Packet) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4416 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4417 | if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4418 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4419 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4420 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4421 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4422 | } else if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4423 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4424 | if (!pXMLNode) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4425 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4426 | } |
| 4427 | if (pXMLNode->GetType() != FDE_XMLNODE_Element) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4428 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4429 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4430 | if (GetElementType() == XFA_Element::DataValue && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4431 | GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) { |
| 4432 | return XFA_FDEExtension_ResolveNamespaceQualifier( |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4433 | static_cast<CFDE_XMLElement*>(pXMLNode), |
| 4434 | GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4435 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4436 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4437 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4438 | } else { |
| 4439 | CXFA_Node* pModelNode = GetModelNode(); |
| 4440 | return pModelNode->TryNamespace(wsNamespace); |
| 4441 | } |
| 4442 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4443 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4444 | CXFA_Node* CXFA_Node::GetProperty(int32_t index, |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4445 | XFA_Element eProperty, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4446 | bool bCreateProperty) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4447 | XFA_Element eType = GetElementType(); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4448 | uint32_t dwPacket = GetPacketID(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4449 | const XFA_PROPERTY* pProperty = |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4450 | XFA_GetPropertyOfElement(eType, eProperty, dwPacket); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4451 | if (!pProperty || index >= pProperty->uOccur) |
| 4452 | return nullptr; |
| 4453 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4454 | CXFA_Node* pNode = m_pChild; |
| 4455 | int32_t iCount = 0; |
| 4456 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4457 | if (pNode->GetElementType() == eProperty) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4458 | iCount++; |
| 4459 | if (iCount > index) { |
| 4460 | return pNode; |
| 4461 | } |
| 4462 | } |
| 4463 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4464 | if (!bCreateProperty) |
| 4465 | return nullptr; |
| 4466 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4467 | if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) { |
| 4468 | pNode = m_pChild; |
| 4469 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4470 | const XFA_PROPERTY* pExistProperty = |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4471 | XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4472 | if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) |
| 4473 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4474 | } |
| 4475 | } |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4476 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4477 | const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket); |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 4478 | CXFA_Node* pNewNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4479 | for (; iCount <= index; iCount++) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4480 | pNewNode = m_pDocument->CreateNode(pPacket, eProperty); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4481 | if (!pNewNode) |
| 4482 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4483 | InsertChild(pNewNode, nullptr); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4484 | pNewNode->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4485 | } |
| 4486 | return pNewNode; |
| 4487 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4488 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4489 | int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4490 | CXFA_Node* pNode = m_pChild; |
| 4491 | int32_t iCount = 0; |
| 4492 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4493 | if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4494 | if (bOnlyChild) { |
| 4495 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4496 | GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4497 | if (pProperty) { |
| 4498 | continue; |
| 4499 | } |
| 4500 | } |
| 4501 | iCount++; |
| 4502 | } |
| 4503 | } |
| 4504 | return iCount; |
| 4505 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4506 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4507 | CXFA_Node* CXFA_Node::GetChild(int32_t index, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4508 | XFA_Element eType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4509 | bool bOnlyChild) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4510 | ASSERT(index > -1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4511 | CXFA_Node* pNode = m_pChild; |
| 4512 | int32_t iCount = 0; |
| 4513 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4514 | if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4515 | if (bOnlyChild) { |
| 4516 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4517 | GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4518 | if (pProperty) { |
| 4519 | continue; |
| 4520 | } |
| 4521 | } |
| 4522 | iCount++; |
| 4523 | if (iCount > index) { |
| 4524 | return pNode; |
| 4525 | } |
| 4526 | } |
| 4527 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4528 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4529 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4530 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4531 | int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) { |
| 4532 | ASSERT(!pNode->m_pNext); |
| 4533 | pNode->m_pParent = this; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4534 | bool ret = m_pDocument->RemovePurgeNode(pNode); |
Wei Li | 5fe7ae7 | 2016-05-04 21:13:15 -0700 | [diff] [blame] | 4535 | ASSERT(ret); |
Wei Li | 439bb9e | 2016-05-05 00:35:26 -0700 | [diff] [blame] | 4536 | (void)ret; // Avoid unused variable warning. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4537 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4538 | if (!m_pChild || index == 0) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4539 | if (index > 0) { |
| 4540 | return -1; |
| 4541 | } |
| 4542 | pNode->m_pNext = m_pChild; |
| 4543 | m_pChild = pNode; |
| 4544 | index = 0; |
| 4545 | } else if (index < 0) { |
| 4546 | m_pLastChild->m_pNext = pNode; |
| 4547 | } else { |
| 4548 | CXFA_Node* pPrev = m_pChild; |
| 4549 | int32_t iCount = 0; |
| 4550 | while (++iCount != index && pPrev->m_pNext) { |
| 4551 | pPrev = pPrev->m_pNext; |
| 4552 | } |
| 4553 | if (index > 0 && index != iCount) { |
| 4554 | return -1; |
| 4555 | } |
| 4556 | pNode->m_pNext = pPrev->m_pNext; |
| 4557 | pPrev->m_pNext = pNode; |
| 4558 | index = iCount; |
| 4559 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4560 | if (!pNode->m_pNext) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4561 | m_pLastChild = pNode; |
| 4562 | } |
| 4563 | ASSERT(m_pLastChild); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4564 | ASSERT(!m_pLastChild->m_pNext); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4565 | pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4566 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4567 | if (pNotify) |
| 4568 | pNotify->OnChildAdded(this); |
| 4569 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4570 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4571 | ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4572 | m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4573 | pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4574 | } |
| 4575 | return index; |
| 4576 | } |
weili | 6e1ae86 | 2016-05-04 18:25:27 -0700 | [diff] [blame] | 4577 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4578 | bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4579 | if (!pNode || pNode->m_pParent || |
| 4580 | (pBeforeNode && pBeforeNode->m_pParent != this)) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4581 | ASSERT(false); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4582 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4583 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4584 | bool ret = m_pDocument->RemovePurgeNode(pNode); |
Wei Li | 5fe7ae7 | 2016-05-04 21:13:15 -0700 | [diff] [blame] | 4585 | ASSERT(ret); |
Wei Li | 439bb9e | 2016-05-05 00:35:26 -0700 | [diff] [blame] | 4586 | (void)ret; // Avoid unused variable warning. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4587 | |
| 4588 | int32_t nIndex = -1; |
| 4589 | pNode->m_pParent = this; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4590 | if (!m_pChild || pBeforeNode == m_pChild) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4591 | pNode->m_pNext = m_pChild; |
| 4592 | m_pChild = pNode; |
| 4593 | nIndex = 0; |
| 4594 | } else if (!pBeforeNode) { |
| 4595 | pNode->m_pNext = m_pLastChild->m_pNext; |
| 4596 | m_pLastChild->m_pNext = pNode; |
| 4597 | } else { |
| 4598 | nIndex = 1; |
| 4599 | CXFA_Node* pPrev = m_pChild; |
| 4600 | while (pPrev->m_pNext != pBeforeNode) { |
| 4601 | pPrev = pPrev->m_pNext; |
| 4602 | nIndex++; |
| 4603 | } |
| 4604 | pNode->m_pNext = pPrev->m_pNext; |
| 4605 | pPrev->m_pNext = pNode; |
| 4606 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4607 | if (!pNode->m_pNext) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4608 | m_pLastChild = pNode; |
| 4609 | } |
| 4610 | ASSERT(m_pLastChild); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4611 | ASSERT(!m_pLastChild->m_pNext); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4612 | pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4613 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4614 | if (pNotify) |
| 4615 | pNotify->OnChildAdded(this); |
| 4616 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4617 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4618 | ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4619 | m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4620 | pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4621 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4622 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4623 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4624 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4625 | CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() { |
| 4626 | if (!m_pParent) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4627 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4628 | } |
| 4629 | for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling; |
| 4630 | pSibling = pSibling->m_pNext) { |
| 4631 | if (pSibling->m_pNext == this) { |
| 4632 | return pSibling; |
| 4633 | } |
| 4634 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4635 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4636 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4637 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4638 | bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4639 | if (!pNode || pNode->m_pParent != this) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4640 | ASSERT(false); |
| 4641 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4642 | } |
| 4643 | if (m_pChild == pNode) { |
| 4644 | m_pChild = pNode->m_pNext; |
| 4645 | if (m_pLastChild == pNode) { |
| 4646 | m_pLastChild = pNode->m_pNext; |
| 4647 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4648 | pNode->m_pNext = nullptr; |
| 4649 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4650 | } else { |
| 4651 | CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling(); |
| 4652 | pPrev->m_pNext = pNode->m_pNext; |
| 4653 | if (m_pLastChild == pNode) { |
| 4654 | m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev; |
| 4655 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4656 | pNode->m_pNext = nullptr; |
| 4657 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4658 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4659 | ASSERT(!m_pLastChild || !m_pLastChild->m_pNext); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4660 | OnRemoved(bNotify); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4661 | pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4662 | m_pDocument->AddPurgeNode(pNode); |
| 4663 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
| 4664 | if (pNode->IsAttributeInXML()) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4665 | ASSERT(pNode->m_pXMLNode == m_pXMLNode && |
| 4666 | m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4667 | if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4668 | CFDE_XMLElement* pXMLElement = |
| 4669 | static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4670 | CFX_WideStringC wsAttributeName = |
| 4671 | pNode->GetCData(XFA_ATTRIBUTE_QualifiedName); |
tsepez | 660956f | 2016-04-06 06:27:29 -0700 | [diff] [blame] | 4672 | pXMLElement->RemoveAttribute(wsAttributeName.c_str()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4673 | } |
| 4674 | CFX_WideString wsName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4675 | pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4676 | CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4677 | CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); |
| 4678 | if (!wsValue.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4679 | pNewXMLElement->SetTextData(CFX_WideString(wsValue)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4680 | } |
| 4681 | pNode->m_pXMLNode = pNewXMLElement; |
| 4682 | pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); |
| 4683 | } else { |
| 4684 | m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode); |
| 4685 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4686 | pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4687 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4688 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4689 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4690 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4691 | CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4692 | return GetFirstChildByName(FX_HashCode_GetW(wsName, false)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4693 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4694 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4695 | CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4696 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; |
| 4697 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4698 | if (pNode->GetNameHash() == dwNameHash) { |
| 4699 | return pNode; |
| 4700 | } |
| 4701 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4702 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4703 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4704 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4705 | CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4706 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; |
| 4707 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4708 | if (pNode->GetElementType() == eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4709 | return pNode; |
| 4710 | } |
| 4711 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4712 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4713 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4714 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4715 | CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4716 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; |
| 4717 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4718 | if (pNode->GetNameHash() == dwNameHash) { |
| 4719 | return pNode; |
| 4720 | } |
| 4721 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4722 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4723 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4724 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4725 | CXFA_Node* CXFA_Node::GetNextSameNameSibling( |
| 4726 | const CFX_WideStringC& wsNodeName) const { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4727 | return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4728 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4729 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4730 | CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4731 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; |
| 4732 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4733 | if (pNode->GetElementType() == eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4734 | return pNode; |
| 4735 | } |
| 4736 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4737 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4738 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4739 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4740 | int32_t CXFA_Node::GetNodeSameNameIndex() const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4741 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4742 | if (!pScriptContext) { |
| 4743 | return -1; |
| 4744 | } |
| 4745 | return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this)); |
| 4746 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4747 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4748 | int32_t CXFA_Node::GetNodeSameClassIndex() const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4749 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4750 | if (!pScriptContext) { |
| 4751 | return -1; |
| 4752 | } |
| 4753 | return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this)); |
| 4754 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4755 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4756 | void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4757 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4758 | if (!pScriptContext) { |
| 4759 | return; |
| 4760 | } |
| 4761 | pScriptContext->GetSomExpression(this, wsSOMExpression); |
| 4762 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4763 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4764 | CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4765 | CXFA_Node* pInstanceMgr = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4766 | if (m_ePacket == XFA_XDPPACKET_Form) { |
| 4767 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4768 | if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4769 | return pInstanceMgr; |
| 4770 | } |
| 4771 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 4772 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4773 | XFA_Element eType = pNode->GetElementType(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4774 | if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4775 | pNode->m_dwNameHash != m_dwNameHash) { |
| 4776 | break; |
| 4777 | } |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4778 | if (eType == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4779 | CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 4780 | CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 4781 | if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' && |
| 4782 | wsInstName.Mid(1) == wsName) { |
| 4783 | pInstanceMgr = pNode; |
| 4784 | } |
| 4785 | break; |
| 4786 | } |
| 4787 | } |
| 4788 | } |
| 4789 | return pInstanceMgr; |
| 4790 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4791 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4792 | CXFA_Node* CXFA_Node::GetOccurNode() { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4793 | return GetFirstChildByClass(XFA_Element::Occur); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4794 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4795 | |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4796 | bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const { |
| 4797 | if (m_uNodeFlags & dwFlag) |
| 4798 | return true; |
| 4799 | if (dwFlag == XFA_NodeFlag_HasRemovedChildren) |
| 4800 | return m_pParent && m_pParent->HasFlag(dwFlag); |
| 4801 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4802 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4803 | |
| 4804 | void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4805 | if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4806 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4807 | if (pNotify) { |
| 4808 | pNotify->OnNodeReady(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4809 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4810 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4811 | m_uNodeFlags |= dwFlag; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4812 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4813 | |
| 4814 | void CXFA_Node::ClearFlag(uint32_t dwFlag) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4815 | m_uNodeFlags &= ~dwFlag; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4816 | } |
| 4817 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4818 | bool CXFA_Node::IsAttributeInXML() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4819 | return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData; |
| 4820 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4821 | |
| 4822 | void CXFA_Node::OnRemoved(bool bNotify) { |
| 4823 | if (!bNotify) |
| 4824 | return; |
| 4825 | |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4826 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4827 | if (pNotify) |
| 4828 | pNotify->OnChildRemoved(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4829 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4830 | |
| 4831 | void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4832 | if (bNotify && IsInitialized()) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4833 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4834 | if (pNotify) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4835 | pNotify->OnValueChanging(this, eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4836 | } |
| 4837 | } |
| 4838 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4839 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4840 | void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4841 | bool bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4842 | bool bScriptModify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4843 | if (bNotify && IsInitialized()) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4844 | Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4845 | } |
| 4846 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4847 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4848 | int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4849 | XFA_Element eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4850 | int32_t iRet = XFA_EVENTERROR_NotExist; |
| 4851 | const XFA_ExecEventParaInfo* eventParaInfo = |
| 4852 | GetEventParaInfoByName(wsEventName); |
| 4853 | if (eventParaInfo) { |
| 4854 | uint32_t validFlags = eventParaInfo->m_validFlags; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4855 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4856 | if (!pNotify) { |
| 4857 | return iRet; |
| 4858 | } |
| 4859 | if (validFlags == 1) { |
| 4860 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType); |
| 4861 | } else if (validFlags == 2) { |
| 4862 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4863 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4864 | } else if (validFlags == 3) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4865 | if (eType == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4866 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4867 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4868 | } |
| 4869 | } else if (validFlags == 4) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4870 | if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4871 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4872 | if (pParentNode && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4873 | pParentNode->GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4874 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4875 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4876 | } |
| 4877 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4878 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4879 | } |
| 4880 | } else if (validFlags == 5) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4881 | if (eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4882 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4883 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4884 | } |
| 4885 | } else if (validFlags == 6) { |
| 4886 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 4887 | if (pWidgetData) { |
| 4888 | CXFA_Node* pUINode = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4889 | if (pUINode->m_elementType == XFA_Element::Signature) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4890 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4891 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4892 | } |
| 4893 | } |
| 4894 | } else if (validFlags == 7) { |
| 4895 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 4896 | if (pWidgetData) { |
| 4897 | CXFA_Node* pUINode = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4898 | if ((pUINode->m_elementType == XFA_Element::ChoiceList) && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4899 | (!pWidgetData->IsListBox())) { |
| 4900 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4901 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4902 | } |
| 4903 | } |
| 4904 | } |
| 4905 | } |
| 4906 | return iRet; |
| 4907 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4908 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4909 | void CXFA_Node::UpdateNameHash() { |
| 4910 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4911 | XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name); |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4912 | CFX_WideStringC wsName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4913 | if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4914 | wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 4915 | m_dwNameHash = FX_HashCode_GetW(wsName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4916 | } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) { |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 4917 | wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName; |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4918 | m_dwNameHash = FX_HashCode_GetW(wsName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4919 | } |
| 4920 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4921 | |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4922 | CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4923 | if (!m_pXMLNode) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4924 | CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name)); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4925 | m_pXMLNode = new CFDE_XMLElement(wsTag); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4926 | SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4927 | } |
| 4928 | return m_pXMLNode; |
| 4929 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4930 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4931 | bool CXFA_Node::IsNeedSavingXMLNode() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4932 | return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets || |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4933 | GetElementType() == XFA_Element::Xfa); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4934 | } |
| 4935 | |
| 4936 | XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() { |
| 4937 | if (!m_pMapModuleData) |
| 4938 | m_pMapModuleData = new XFA_MAPMODULEDATA; |
| 4939 | return m_pMapModuleData; |
| 4940 | } |
| 4941 | |
| 4942 | XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const { |
| 4943 | return m_pMapModuleData; |
| 4944 | } |
| 4945 | |
| 4946 | void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) { |
| 4947 | XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); |
| 4948 | pModule->m_ValueMap.SetAt(pKey, pValue); |
| 4949 | } |
| 4950 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4951 | bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4952 | CXFA_Node* pNode = this; |
| 4953 | while (pNode) { |
| 4954 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
| 4955 | if (pModule && pModule->m_ValueMap.Lookup(pKey, pValue)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4956 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4957 | } |
| 4958 | pNode = pNode->GetPacketID() != XFA_XDPPACKET_Datasets |
| 4959 | ? pNode->GetTemplateNode() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4960 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4961 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4962 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4963 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4964 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4965 | void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) { |
tsepez | 660956f | 2016-04-06 06:27:29 -0700 | [diff] [blame] | 4966 | SetMapModuleBuffer(pKey, (void*)wsValue.c_str(), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4967 | wsValue.GetLength() * sizeof(FX_WCHAR)); |
| 4968 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4969 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4970 | bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4971 | void* pValue; |
| 4972 | int32_t iBytes; |
| 4973 | if (!GetMapModuleBuffer(pKey, pValue, iBytes)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4974 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4975 | } |
| 4976 | wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4977 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4978 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4979 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4980 | void CXFA_Node::SetMapModuleBuffer( |
| 4981 | void* pKey, |
| 4982 | void* pValue, |
| 4983 | int32_t iBytes, |
| 4984 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
| 4985 | XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); |
| 4986 | XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey]; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4987 | if (!pBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4988 | pBuffer = |
| 4989 | (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes); |
| 4990 | } else if (pBuffer->iBytes != iBytes) { |
| 4991 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 4992 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 4993 | } |
| 4994 | pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer, |
| 4995 | sizeof(XFA_MAPDATABLOCK) + iBytes); |
| 4996 | } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 4997 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 4998 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4999 | if (!pBuffer) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5000 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5001 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5002 | pBuffer->pCallbackInfo = pCallbackInfo; |
| 5003 | pBuffer->iBytes = iBytes; |
| 5004 | FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes); |
| 5005 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5006 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5007 | bool CXFA_Node::GetMapModuleBuffer(void* pKey, |
| 5008 | void*& pValue, |
| 5009 | int32_t& iBytes, |
| 5010 | bool bProtoAlso) const { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5011 | XFA_MAPDATABLOCK* pBuffer = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5012 | const CXFA_Node* pNode = this; |
| 5013 | while (pNode) { |
| 5014 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
| 5015 | if (pModule && pModule->m_BufferMap.Lookup(pKey, pBuffer)) { |
| 5016 | break; |
| 5017 | } |
| 5018 | pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets) |
| 5019 | ? pNode->GetTemplateNode() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5020 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5021 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5022 | if (!pBuffer) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5023 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5024 | } |
| 5025 | pValue = pBuffer->GetData(); |
| 5026 | iBytes = pBuffer->iBytes; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5027 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5028 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5029 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5030 | bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5031 | CXFA_Node* pNode = this; |
| 5032 | while (pNode) { |
| 5033 | void* pVal; |
| 5034 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
| 5035 | if (pModule && |
| 5036 | (pModule->m_ValueMap.Lookup(pKey, pVal) || |
| 5037 | pModule->m_BufferMap.Lookup(pKey, (XFA_MAPDATABLOCK*&)pVal))) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5038 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5039 | } |
| 5040 | pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets) |
| 5041 | ? pNode->GetTemplateNode() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5042 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5043 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5044 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5045 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5046 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5047 | void CXFA_Node::RemoveMapModuleKey(void* pKey) { |
| 5048 | XFA_MAPMODULEDATA* pModule = GetMapModuleData(); |
| 5049 | if (!pModule) |
| 5050 | return; |
| 5051 | |
| 5052 | if (pKey) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5053 | XFA_MAPDATABLOCK* pBuffer = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5054 | pModule->m_BufferMap.Lookup(pKey, pBuffer); |
| 5055 | if (pBuffer) { |
| 5056 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 5057 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5058 | } |
| 5059 | FX_Free(pBuffer); |
| 5060 | } |
| 5061 | pModule->m_BufferMap.RemoveKey(pKey); |
| 5062 | pModule->m_ValueMap.RemoveKey(pKey); |
| 5063 | } else { |
| 5064 | XFA_MAPDATABLOCK* pBuffer; |
| 5065 | FX_POSITION posBuffer = pModule->m_BufferMap.GetStartPosition(); |
| 5066 | while (posBuffer) { |
| 5067 | pModule->m_BufferMap.GetNextAssoc(posBuffer, pKey, pBuffer); |
| 5068 | if (pBuffer) { |
| 5069 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 5070 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5071 | } |
| 5072 | FX_Free(pBuffer); |
| 5073 | } |
| 5074 | } |
| 5075 | pModule->m_BufferMap.RemoveAll(); |
| 5076 | pModule->m_ValueMap.RemoveAll(); |
| 5077 | delete pModule; |
| 5078 | } |
| 5079 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5080 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5081 | void CXFA_Node::MergeAllData(void* pDstModule, bool bUseSrcAttr) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5082 | XFA_MAPMODULEDATA* pDstModuleData = |
| 5083 | static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData(); |
| 5084 | XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData(); |
| 5085 | if (!pSrcModuleData) { |
| 5086 | return; |
| 5087 | } |
| 5088 | FX_POSITION psValue = pSrcModuleData->m_ValueMap.GetStartPosition(); |
| 5089 | while (psValue) { |
| 5090 | void* pKey; |
| 5091 | void* pValue; |
| 5092 | pSrcModuleData->m_ValueMap.GetNextAssoc(psValue, pKey, pValue); |
| 5093 | if (bUseSrcAttr || !pDstModuleData->m_ValueMap.GetValueAt(pKey)) { |
| 5094 | pDstModuleData->m_ValueMap.SetAt(pKey, pValue); |
| 5095 | } |
| 5096 | } |
| 5097 | FX_POSITION psBuffer = pSrcModuleData->m_BufferMap.GetStartPosition(); |
| 5098 | while (psBuffer) { |
| 5099 | void* pKey; |
| 5100 | XFA_MAPDATABLOCK* pSrcBuffer; |
| 5101 | pSrcModuleData->m_BufferMap.GetNextAssoc(psBuffer, pKey, pSrcBuffer); |
| 5102 | XFA_MAPDATABLOCK*& pBuffer = pDstModuleData->m_BufferMap[pKey]; |
| 5103 | if (pBuffer && !bUseSrcAttr) { |
| 5104 | continue; |
| 5105 | } |
| 5106 | if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree && |
| 5107 | !pSrcBuffer->pCallbackInfo->pCopy) { |
| 5108 | if (pBuffer) { |
| 5109 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5110 | pDstModuleData->m_BufferMap.RemoveKey(pKey); |
| 5111 | } |
| 5112 | continue; |
| 5113 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5114 | if (!pBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5115 | pBuffer = (XFA_MAPDATABLOCK*)FX_Alloc( |
| 5116 | uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); |
| 5117 | } else if (pBuffer->iBytes != pSrcBuffer->iBytes) { |
| 5118 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 5119 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5120 | } |
| 5121 | pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc( |
| 5122 | uint8_t, pBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); |
| 5123 | } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 5124 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5125 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5126 | if (!pBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5127 | continue; |
| 5128 | } |
| 5129 | pBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo; |
| 5130 | pBuffer->iBytes = pSrcBuffer->iBytes; |
| 5131 | FXSYS_memcpy(pBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes); |
| 5132 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pCopy) { |
| 5133 | pBuffer->pCallbackInfo->pCopy(*(void**)pBuffer->GetData()); |
| 5134 | } |
| 5135 | } |
| 5136 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5137 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5138 | void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) { |
| 5139 | if (!pDstModule) { |
| 5140 | return; |
| 5141 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5142 | bool bNeedMove = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5143 | if (!pKey) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5144 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5145 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 5146 | if (pDstModule->GetElementType() != GetElementType()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5147 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5148 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5149 | XFA_MAPMODULEDATA* pSrcModuleData = nullptr; |
| 5150 | XFA_MAPMODULEDATA* pDstModuleData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5151 | if (bNeedMove) { |
| 5152 | pSrcModuleData = GetMapModuleData(); |
| 5153 | if (!pSrcModuleData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5154 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5155 | } |
| 5156 | pDstModuleData = pDstModule->CreateMapModuleData(); |
| 5157 | } |
| 5158 | if (bNeedMove) { |
| 5159 | void* pBufferBlockData = pSrcModuleData->m_BufferMap.GetValueAt(pKey); |
| 5160 | if (pBufferBlockData) { |
| 5161 | pSrcModuleData->m_BufferMap.RemoveKey(pKey); |
| 5162 | pDstModuleData->m_BufferMap.RemoveKey(pKey); |
| 5163 | pDstModuleData->m_BufferMap.SetAt(pKey, |
| 5164 | (XFA_MAPDATABLOCK*)pBufferBlockData); |
| 5165 | } |
| 5166 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 5167 | if (pDstModule->IsNodeV()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5168 | CFX_WideString wsValue = pDstModule->GetScriptContent(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5169 | CFX_WideString wsFormatValue(wsValue); |
| 5170 | CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData(); |
| 5171 | if (pWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 5172 | pWidgetData->GetFormatDataValue(wsValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5173 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5174 | pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5175 | } |
| 5176 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5177 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5178 | void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule, |
| 5179 | CXFA_Node* pDstModule, |
| 5180 | void* pKey, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5181 | bool bRecursive) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5182 | if (!pSrcModule || !pDstModule || !pKey) { |
| 5183 | return; |
| 5184 | } |
| 5185 | if (bRecursive) { |
| 5186 | CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 5187 | CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 5188 | for (; pSrcChild && pDstChild; |
| 5189 | pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling), |
| 5190 | pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5191 | MoveBufferMapData(pSrcChild, pDstChild, pKey, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5192 | } |
| 5193 | } |
| 5194 | pSrcModule->MoveBufferMapData(pDstModule, pKey); |
| 5195 | } |