blob: f385b11b692a5de66da9180fdb03b3bad90db237 [file] [log] [blame]
dsinclair5b36f0a2016-07-19 10:56:23 -07001// Copyright 2016 PDFium Authors. All rights reserved.
Dan Sinclair1770c022016-03-14 14:14:16 -04002// 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
dsinclair5b36f0a2016-07-19 10:56:23 -07009#include <map>
tsepezaadedf92016-05-12 10:08:06 -070010#include <memory>
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050011#include <utility>
tsepez51709be2016-12-08 10:55:57 -080012#include <vector>
tsepezaadedf92016-05-12 10:08:06 -070013
dsinclaira52ab742016-09-29 13:59:29 -070014#include "core/fxcrt/fx_ext.h"
dsinclair43554682016-09-29 17:29:48 -070015#include "fxjs/cfxjse_value.h"
tsepeza9caab92016-12-14 05:57:10 -080016#include "third_party/base/ptr_util.h"
tsepezaadedf92016-05-12 10:08:06 -070017#include "third_party/base/stl_util.h"
dsinclairae95f762016-03-29 16:58:29 -070018#include "xfa/fde/xml/fde_xml_imp.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040019#include "xfa/fgas/crt/fgas_codepage.h"
dsinclairdf4bc592016-03-31 20:34:43 -070020#include "xfa/fxfa/app/xfa_ffnotify.h"
dsinclair5b493092016-09-29 20:20:24 -070021#include "xfa/fxfa/cxfa_eventparam.h"
dsinclair16280242016-07-21 12:03:47 -070022#include "xfa/fxfa/parser/cxfa_document.h"
dsinclair0b851ff2016-07-21 12:03:01 -070023#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
dsinclair9eb0db12016-07-21 12:01:39 -070024#include "xfa/fxfa/parser/cxfa_measurement.h"
dsinclair44d054c2016-04-06 10:23:46 -070025#include "xfa/fxfa/parser/cxfa_occur.h"
dsinclair31f87402016-07-20 06:34:45 -070026#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
dsinclair34f86b02016-07-11 08:42:33 -070027#include "xfa/fxfa/parser/cxfa_simple_parser.h"
dsinclair5b36f0a2016-07-19 10:56:23 -070028#include "xfa/fxfa/parser/xfa_basic_data.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040029
weili44f8faf2016-06-01 14:03:56 -070030namespace {
31
32void XFA_DeleteWideString(void* pData) {
33 delete static_cast<CFX_WideString*>(pData);
34}
35
36void XFA_CopyWideString(void*& pData) {
37 if (pData) {
38 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
39 pData = pNewData;
40 }
41}
42
43XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
44 XFA_CopyWideString};
45
weili44f8faf2016-06-01 14:03:56 -070046void XFA_DataNodeDeleteBindItem(void* pData) {
47 delete static_cast<CXFA_NodeArray*>(pData);
48}
49
50XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
51 XFA_DataNodeDeleteBindItem, nullptr};
52
dsinclair5b36f0a2016-07-19 10:56:23 -070053int32_t GetCount(CXFA_Node* pInstMgrNode) {
54 ASSERT(pInstMgrNode);
55 int32_t iCount = 0;
56 uint32_t dwNameHash = 0;
57 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
58 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
59 XFA_Element eCurType = pNode->GetElementType();
60 if (eCurType == XFA_Element::InstanceManager)
61 break;
62 if ((eCurType != XFA_Element::Subform) &&
63 (eCurType != XFA_Element::SubformSet)) {
64 continue;
65 }
66 if (iCount == 0) {
67 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
68 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
69 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
70 wsInstName.Mid(1) != wsName) {
71 return iCount;
72 }
73 dwNameHash = pNode->GetNameHash();
74 }
75 if (dwNameHash != pNode->GetNameHash())
76 break;
weili44f8faf2016-06-01 14:03:56 -070077
dsinclair5b36f0a2016-07-19 10:56:23 -070078 iCount++;
79 }
80 return iCount;
Dan Sinclair1770c022016-03-14 14:14:16 -040081}
weili44f8faf2016-06-01 14:03:56 -070082
dsinclair5b36f0a2016-07-19 10:56:23 -070083void SortNodeArrayByDocumentIdx(const CXFA_NodeSet& rgNodeSet,
84 CXFA_NodeArray& rgNodeArray,
85 CFX_ArrayTemplate<int32_t>& rgIdxArray) {
86 int32_t iCount = pdfium::CollectionSize<int32_t>(rgNodeSet);
87 rgNodeArray.SetSize(iCount);
88 rgIdxArray.SetSize(iCount);
89 if (iCount == 0)
90 return;
weili44f8faf2016-06-01 14:03:56 -070091
dsinclair5b36f0a2016-07-19 10:56:23 -070092 int32_t iIndex = -1;
93 int32_t iTotalIndex = -1;
94 CXFA_Node* pCommonParent =
95 (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent);
96 for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild);
97 pNode && iIndex < iCount;
98 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
99 iTotalIndex++;
100 if (pdfium::ContainsValue(rgNodeSet, pNode)) {
101 iIndex++;
102 rgNodeArray[iIndex] = pNode;
103 rgIdxArray[iIndex] = iTotalIndex;
104 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400105 }
106}
weili44f8faf2016-06-01 14:03:56 -0700107
dsinclair5b36f0a2016-07-19 10:56:23 -0700108using CXFA_NodeSetPair = std::pair<CXFA_NodeSet, CXFA_NodeSet>;
109using CXFA_NodeSetPairMap =
110 std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>;
111using CXFA_NodeSetPairMapMap =
112 std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>;
113
114CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode,
115 CXFA_NodeSetPairMapMap* pMap) {
116 CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
117 uint32_t dwNameHash = pNode->GetNameHash();
118 if (!pParentNode || !dwNameHash)
119 return nullptr;
120
121 if (!(*pMap)[pParentNode])
tsepeza9caab92016-12-14 05:57:10 -0800122 (*pMap)[pParentNode] = pdfium::MakeUnique<CXFA_NodeSetPairMap>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700123
124 CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get();
125 if (!(*pNodeSetPairMap)[dwNameHash])
tsepeza9caab92016-12-14 05:57:10 -0800126 (*pNodeSetPairMap)[dwNameHash] = pdfium::MakeUnique<CXFA_NodeSetPair>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700127
128 return (*pNodeSetPairMap)[dwNameHash].get();
Dan Sinclair1770c022016-03-14 14:14:16 -0400129}
130
dsinclair5b36f0a2016-07-19 10:56:23 -0700131void ReorderDataNodes(const CXFA_NodeSet& sSet1,
132 const CXFA_NodeSet& sSet2,
tsepezd19e9122016-11-02 15:43:18 -0700133 bool bInsertBefore) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700134 CXFA_NodeSetPairMapMap rgMap;
135 for (CXFA_Node* pNode : sSet1) {
136 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
137 if (pNodeSetPair)
138 pNodeSetPair->first.insert(pNode);
139 }
140 for (CXFA_Node* pNode : sSet2) {
141 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
142 if (pNodeSetPair) {
143 if (pdfium::ContainsValue(pNodeSetPair->first, pNode))
144 pNodeSetPair->first.erase(pNode);
145 else
146 pNodeSetPair->second.insert(pNode);
147 }
148 }
149 for (const auto& iter1 : rgMap) {
150 CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get();
151 if (!pNodeSetPairMap)
152 continue;
153
154 for (const auto& iter2 : *pNodeSetPairMap) {
155 CXFA_NodeSetPair* pNodeSetPair = iter2.second.get();
156 if (!pNodeSetPair)
157 continue;
158 if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) {
159 CXFA_NodeArray rgNodeArray1;
160 CXFA_NodeArray rgNodeArray2;
161 CFX_ArrayTemplate<int32_t> rgIdxArray1;
162 CFX_ArrayTemplate<int32_t> rgIdxArray2;
163 SortNodeArrayByDocumentIdx(pNodeSetPair->first, rgNodeArray1,
164 rgIdxArray1);
165 SortNodeArrayByDocumentIdx(pNodeSetPair->second, rgNodeArray2,
166 rgIdxArray2);
167 CXFA_Node* pParentNode = nullptr;
168 CXFA_Node* pBeforeNode = nullptr;
169 if (bInsertBefore) {
170 pBeforeNode = rgNodeArray2[0];
171 pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent);
172 } else {
173 CXFA_Node* pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1];
174 pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent);
175 pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling);
176 }
177 for (int32_t iIdx = 0; iIdx < rgIdxArray1.GetSize(); iIdx++) {
178 CXFA_Node* pCurNode = rgNodeArray1[iIdx];
179 pParentNode->RemoveChild(pCurNode);
180 pParentNode->InsertChild(pCurNode, pBeforeNode);
181 }
182 }
183 }
184 pNodeSetPairMap->clear();
185 }
186}
187
188CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
189 ASSERT(pInstMgrNode);
190 int32_t iCount = 0;
191 uint32_t dwNameHash = 0;
192 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
193 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
194 XFA_Element eCurType = pNode->GetElementType();
195 if (eCurType == XFA_Element::InstanceManager)
196 break;
197 if ((eCurType != XFA_Element::Subform) &&
198 (eCurType != XFA_Element::SubformSet)) {
199 continue;
200 }
201 if (iCount == 0) {
202 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
203 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
204 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
205 wsInstName.Mid(1) != wsName) {
206 return nullptr;
207 }
208 dwNameHash = pNode->GetNameHash();
209 }
210 if (dwNameHash != pNode->GetNameHash())
211 break;
212
213 iCount++;
214 if (iCount > iIndex)
215 return pNode;
216 }
217 return nullptr;
218}
219
220void InsertItem(CXFA_Node* pInstMgrNode,
221 CXFA_Node* pNewInstance,
222 int32_t iPos,
223 int32_t iCount = -1,
tsepezd19e9122016-11-02 15:43:18 -0700224 bool bMoveDataBindingNodes = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700225 if (iCount < 0)
226 iCount = GetCount(pInstMgrNode);
227 if (iPos < 0)
228 iPos = iCount;
229 if (iPos == iCount) {
230 CXFA_Node* pNextSibling =
231 iCount > 0
232 ? GetItem(pInstMgrNode, iCount - 1)
233 ->GetNodeItem(XFA_NODEITEM_NextSibling)
234 : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
235 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
236 ->InsertChild(pNewInstance, pNextSibling);
237 if (bMoveDataBindingNodes) {
238 CXFA_NodeSet sNew;
239 CXFA_NodeSet sAfter;
240 CXFA_NodeIteratorTemplate<CXFA_Node,
241 CXFA_TraverseStrategy_XFAContainerNode>
242 sIteratorNew(pNewInstance);
243 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
244 pNode = sIteratorNew.MoveToNext()) {
245 CXFA_Node* pDataNode = pNode->GetBindData();
246 if (!pDataNode)
247 continue;
248
249 sNew.insert(pDataNode);
250 }
251 CXFA_NodeIteratorTemplate<CXFA_Node,
252 CXFA_TraverseStrategy_XFAContainerNode>
253 sIteratorAfter(pNextSibling);
254 for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode;
255 pNode = sIteratorAfter.MoveToNext()) {
256 CXFA_Node* pDataNode = pNode->GetBindData();
257 if (!pDataNode)
258 continue;
259
260 sAfter.insert(pDataNode);
261 }
tsepezd19e9122016-11-02 15:43:18 -0700262 ReorderDataNodes(sNew, sAfter, false);
dsinclair5b36f0a2016-07-19 10:56:23 -0700263 }
264 } else {
265 CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos);
266 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
267 ->InsertChild(pNewInstance, pBeforeInstance);
268 if (bMoveDataBindingNodes) {
269 CXFA_NodeSet sNew;
270 CXFA_NodeSet sBefore;
271 CXFA_NodeIteratorTemplate<CXFA_Node,
272 CXFA_TraverseStrategy_XFAContainerNode>
273 sIteratorNew(pNewInstance);
274 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
275 pNode = sIteratorNew.MoveToNext()) {
276 CXFA_Node* pDataNode = pNode->GetBindData();
277 if (!pDataNode)
278 continue;
279
280 sNew.insert(pDataNode);
281 }
282 CXFA_NodeIteratorTemplate<CXFA_Node,
283 CXFA_TraverseStrategy_XFAContainerNode>
284 sIteratorBefore(pBeforeInstance);
285 for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode;
286 pNode = sIteratorBefore.MoveToNext()) {
287 CXFA_Node* pDataNode = pNode->GetBindData();
288 if (!pDataNode)
289 continue;
290
291 sBefore.insert(pDataNode);
292 }
tsepezd19e9122016-11-02 15:43:18 -0700293 ReorderDataNodes(sNew, sBefore, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700294 }
295 }
296}
297
298void RemoveItem(CXFA_Node* pInstMgrNode,
299 CXFA_Node* pRemoveInstance,
tsepezd19e9122016-11-02 15:43:18 -0700300 bool bRemoveDataBinding = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700301 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);
302 if (!bRemoveDataBinding)
303 return;
304
305 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode>
306 sIterator(pRemoveInstance);
307 for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode;
308 pFormNode = sIterator.MoveToNext()) {
309 CXFA_Node* pDataNode = pFormNode->GetBindData();
310 if (!pDataNode)
311 continue;
312
313 if (pDataNode->RemoveBindItem(pFormNode) == 0) {
314 if (CXFA_Node* pDataParent =
315 pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) {
316 pDataParent->RemoveChild(pDataNode);
317 }
318 }
319 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
320 }
321}
322
tsepezd19e9122016-11-02 15:43:18 -0700323CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700324 CXFA_Document* pDocument = pInstMgrNode->GetDocument();
325 CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();
326 CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);
327 CXFA_Node* pDataScope = nullptr;
328 for (CXFA_Node* pRootBoundNode = pFormParent;
329 pRootBoundNode && pRootBoundNode->IsContainerNode();
330 pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) {
331 pDataScope = pRootBoundNode->GetBindData();
332 if (pDataScope)
333 break;
334 }
335 if (!pDataScope) {
336 pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record));
337 ASSERT(pDataScope);
338 }
339 CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer(
tsepezd19e9122016-11-02 15:43:18 -0700340 pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700341 if (pInstance) {
342 pDocument->DataMerge_UpdateBindingRelations(pInstance);
343 pFormParent->RemoveChild(pInstance);
344 }
345 return pInstance;
346}
347
348struct XFA_ExecEventParaInfo {
349 public:
350 uint32_t m_uHash;
351 const FX_WCHAR* m_lpcEventName;
352 XFA_EVENTTYPE m_eventType;
353 uint32_t m_validFlags;
354};
355static const XFA_ExecEventParaInfo gs_eventParaInfos[] = {
356 {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0},
357 {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0},
358 {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5},
359 {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0},
360 {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7},
361 {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1},
362 {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5},
363 {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0},
364 {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0},
365 {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6},
366 {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2},
367 {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0},
368 {0x7233018a, L"validate", XFA_EVENT_Validate, 1},
369 {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3},
370 {0x891f4606, L"change", XFA_EVENT_Change, 4},
371 {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0},
372 {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5},
373 {0xcdce56b3, L"full", XFA_EVENT_Full, 4},
374 {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5},
375 {0xd95657a6, L"click", XFA_EVENT_Click, 4},
376 {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1},
377 {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7},
378 {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2},
379 {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0},
380 {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6},
381};
382
383const XFA_ExecEventParaInfo* GetEventParaInfoByName(
384 const CFX_WideStringC& wsEventName) {
385 uint32_t uHash = FX_HashCode_GetW(wsEventName, false);
386 int32_t iStart = 0;
387 int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
388 do {
389 int32_t iMid = (iStart + iEnd) / 2;
390 const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid];
391 if (uHash == eventParaInfo->m_uHash)
392 return eventParaInfo;
393 if (uHash < eventParaInfo->m_uHash)
394 iEnd = iMid - 1;
395 else
396 iStart = iMid + 1;
397 } while (iStart <= iEnd);
398 return nullptr;
399}
400
401void StrToRGB(const CFX_WideString& strRGB,
402 int32_t& r,
403 int32_t& g,
404 int32_t& b) {
405 r = 0;
406 g = 0;
407 b = 0;
408
409 FX_WCHAR zero = '0';
410 int32_t iIndex = 0;
411 int32_t iLen = strRGB.GetLength();
412 for (int32_t i = 0; i < iLen; ++i) {
413 FX_WCHAR ch = strRGB.GetAt(i);
414 if (ch == L',')
415 ++iIndex;
416 if (iIndex > 2)
417 break;
418
419 int32_t iValue = ch - zero;
420 if (iValue >= 0 && iValue <= 9) {
421 switch (iIndex) {
422 case 0:
423 r = r * 10 + iValue;
424 break;
425 case 1:
426 g = g * 10 + iValue;
427 break;
428 default:
429 b = b * 10 + iValue;
430 break;
431 }
432 }
433 }
434}
435
436enum XFA_KEYTYPE {
437 XFA_KEYTYPE_Custom,
438 XFA_KEYTYPE_Element,
439};
440
441void* GetMapKey_Custom(const CFX_WideStringC& wsKey) {
442 uint32_t dwKey = FX_HashCode_GetW(wsKey, false);
443 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom);
444}
445
446void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) {
447 return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) |
448 (eAttribute << 8) | XFA_KEYTYPE_Element);
449}
450
dsinclair9eb0db12016-07-21 12:01:39 -0700451const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement,
452 XFA_ATTRIBUTE eAttribute,
453 uint32_t dwPacket) {
454 int32_t iCount = 0;
455 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount);
456 if (!pAttr || iCount < 1)
457 return nullptr;
458
459 if (!std::binary_search(pAttr, pAttr + iCount, eAttribute))
460 return nullptr;
461
462 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute);
463 ASSERT(pInfo);
464 if (dwPacket == XFA_XDPPACKET_UNKNOWN)
465 return pInfo;
466 return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr;
467}
468
469const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) {
470 return g_XFAEnumData + eName;
471}
472
dsinclair5b36f0a2016-07-19 10:56:23 -0700473} // namespace
474
475static void XFA_DefaultFreeData(void* pData) {}
476
477static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {
478 XFA_DefaultFreeData, nullptr};
479
weili47bcd4c2016-06-16 08:00:06 -0700480XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {}
481
482XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {}
483
dsinclairb9778472016-06-23 13:34:10 -0700484CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
485 uint16_t ePacket,
486 XFA_ObjectType oType,
dsinclairc1df5d42016-07-18 06:36:51 -0700487 XFA_Element eType,
488 const CFX_WideStringC& elementName)
489 : CXFA_Object(pDoc, oType, eType, elementName),
Dan Sinclair1770c022016-03-14 14:14:16 -0400490 m_pNext(nullptr),
491 m_pChild(nullptr),
492 m_pLastChild(nullptr),
493 m_pParent(nullptr),
494 m_pXMLNode(nullptr),
Dan Sinclair1770c022016-03-14 14:14:16 -0400495 m_ePacket(ePacket),
dsinclairc5a8f212016-06-20 11:11:12 -0700496 m_uNodeFlags(XFA_NodeFlag_None),
Dan Sinclair1770c022016-03-14 14:14:16 -0400497 m_dwNameHash(0),
498 m_pAuxNode(nullptr),
499 m_pMapModuleData(nullptr) {
500 ASSERT(m_pDocument);
501}
weili44f8faf2016-06-01 14:03:56 -0700502
Dan Sinclair1770c022016-03-14 14:14:16 -0400503CXFA_Node::~CXFA_Node() {
weili44f8faf2016-06-01 14:03:56 -0700504 ASSERT(!m_pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400505 RemoveMapModuleKey();
weili44f8faf2016-06-01 14:03:56 -0700506 CXFA_Node* pNode = m_pChild;
Dan Sinclair1770c022016-03-14 14:14:16 -0400507 while (pNode) {
weili44f8faf2016-06-01 14:03:56 -0700508 CXFA_Node* pNext = pNode->m_pNext;
509 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400510 delete pNode;
511 pNode = pNext;
512 }
dsinclairc5a8f212016-06-20 11:11:12 -0700513 if (m_pXMLNode && IsOwnXMLNode())
Tom Sepezd3743ea2016-05-16 15:56:53 -0700514 m_pXMLNode->Release();
Dan Sinclair1770c022016-03-14 14:14:16 -0400515}
weili44f8faf2016-06-01 14:03:56 -0700516
tsepezd19e9122016-11-02 15:43:18 -0700517CXFA_Node* CXFA_Node::Clone(bool bRecursive) {
dsinclaira1b07722016-07-11 08:20:58 -0700518 CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700519 if (!pClone)
520 return nullptr;
521
Dan Sinclair1770c022016-03-14 14:14:16 -0400522 MergeAllData(pClone);
523 pClone->UpdateNameHash();
524 if (IsNeedSavingXMLNode()) {
weili44f8faf2016-06-01 14:03:56 -0700525 CFDE_XMLNode* pCloneXML = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400526 if (IsAttributeInXML()) {
527 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -0700528 GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -0700529 CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -0400530 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
531 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -0700532 pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -0400533 }
534 pCloneXML = pCloneXMLElement;
weili44f8faf2016-06-01 14:03:56 -0700535 pCloneXMLElement = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400536 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
537 } else {
tsepezd19e9122016-11-02 15:43:18 -0700538 pCloneXML = m_pXMLNode->Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400539 }
540 pClone->SetXMLMappingNode(pCloneXML);
dsinclairc5a8f212016-06-20 11:11:12 -0700541 pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400542 }
543 if (bRecursive) {
544 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
545 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
546 pClone->InsertChild(pChild->Clone(bRecursive));
547 }
548 }
dsinclairc5a8f212016-06-20 11:11:12 -0700549 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
weili44f8faf2016-06-01 14:03:56 -0700550 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400551 return pClone;
552}
weili44f8faf2016-06-01 14:03:56 -0700553
Dan Sinclair1770c022016-03-14 14:14:16 -0400554CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
555 switch (eItem) {
556 case XFA_NODEITEM_NextSibling:
557 return m_pNext;
558 case XFA_NODEITEM_FirstChild:
559 return m_pChild;
560 case XFA_NODEITEM_Parent:
561 return m_pParent;
562 case XFA_NODEITEM_PrevSibling:
563 if (m_pParent) {
564 CXFA_Node* pSibling = m_pParent->m_pChild;
weili44f8faf2016-06-01 14:03:56 -0700565 CXFA_Node* pPrev = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400566 while (pSibling && pSibling != this) {
567 pPrev = pSibling;
568 pSibling = pSibling->m_pNext;
569 }
570 return pPrev;
571 }
weili44f8faf2016-06-01 14:03:56 -0700572 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400573 default:
574 break;
575 }
weili44f8faf2016-06-01 14:03:56 -0700576 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400577}
weili44f8faf2016-06-01 14:03:56 -0700578
Dan Sinclair1770c022016-03-14 14:14:16 -0400579CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
dsinclairc5a8f212016-06-20 11:11:12 -0700580 XFA_ObjectType eType) const {
weili44f8faf2016-06-01 14:03:56 -0700581 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400582 switch (eItem) {
583 case XFA_NODEITEM_NextSibling:
584 pNode = m_pNext;
dsinclairc5a8f212016-06-20 11:11:12 -0700585 while (pNode && pNode->GetObjectType() != eType)
586 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400587 break;
588 case XFA_NODEITEM_FirstChild:
589 pNode = m_pChild;
dsinclairc5a8f212016-06-20 11:11:12 -0700590 while (pNode && pNode->GetObjectType() != eType)
591 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400592 break;
593 case XFA_NODEITEM_Parent:
594 pNode = m_pParent;
dsinclairc5a8f212016-06-20 11:11:12 -0700595 while (pNode && pNode->GetObjectType() != eType)
596 pNode = pNode->m_pParent;
Dan Sinclair1770c022016-03-14 14:14:16 -0400597 break;
598 case XFA_NODEITEM_PrevSibling:
599 if (m_pParent) {
600 CXFA_Node* pSibling = m_pParent->m_pChild;
601 while (pSibling && pSibling != this) {
dsinclairc5a8f212016-06-20 11:11:12 -0700602 if (eType == pSibling->GetObjectType())
Dan Sinclair1770c022016-03-14 14:14:16 -0400603 pNode = pSibling;
dsinclairc5a8f212016-06-20 11:11:12 -0700604
Dan Sinclair1770c022016-03-14 14:14:16 -0400605 pSibling = pSibling->m_pNext;
606 }
607 }
608 break;
609 default:
610 break;
611 }
612 return pNode;
613}
weili44f8faf2016-06-01 14:03:56 -0700614
Dan Sinclair1770c022016-03-14 14:14:16 -0400615int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes,
tsepez736f28a2016-03-25 14:19:51 -0700616 uint32_t dwTypeFilter,
dsinclair41cb62e2016-06-23 09:20:32 -0700617 XFA_Element eTypeFilter,
Dan Sinclair1770c022016-03-14 14:14:16 -0400618 int32_t iLevel) {
619 if (--iLevel < 0) {
620 return nodes.GetSize();
621 }
dsinclair41cb62e2016-06-23 09:20:32 -0700622 if (eTypeFilter != XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400623 CXFA_Node* pChild = m_pChild;
624 while (pChild) {
dsinclair41cb62e2016-06-23 09:20:32 -0700625 if (pChild->GetElementType() == eTypeFilter) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400626 nodes.Add(pChild);
627 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700628 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400629 }
630 }
631 pChild = pChild->m_pNext;
632 }
633 } else if (dwTypeFilter ==
634 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
635 CXFA_Node* pChild = m_pChild;
636 while (pChild) {
637 nodes.Add(pChild);
638 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700639 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400640 }
641 pChild = pChild->m_pNext;
642 }
643 } else if (dwTypeFilter != 0) {
weili44f8faf2016-06-01 14:03:56 -0700644 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
645 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
646 bool bFilterOneOfProperties =
647 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
Dan Sinclair1770c022016-03-14 14:14:16 -0400648 CXFA_Node* pChild = m_pChild;
649 while (pChild) {
650 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -0700651 GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -0400652 if (pProperty) {
653 if (bFilterProperties) {
654 nodes.Add(pChild);
655 } else if (bFilterOneOfProperties &&
656 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
657 nodes.Add(pChild);
658 } else if (bFilterChildren &&
dsinclair070fcdf2016-06-22 22:04:54 -0700659 (pChild->GetElementType() == XFA_Element::Variables ||
660 pChild->GetElementType() == XFA_Element::PageSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400661 nodes.Add(pChild);
662 }
weili44f8faf2016-06-01 14:03:56 -0700663 } else if (bFilterChildren) {
664 nodes.Add(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400665 }
666 pChild = pChild->m_pNext;
667 }
668 if (bFilterOneOfProperties && nodes.GetSize() < 1) {
669 int32_t iProperties = 0;
670 const XFA_PROPERTY* pProperty =
dsinclair070fcdf2016-06-22 22:04:54 -0700671 XFA_GetElementProperties(GetElementType(), iProperties);
weili44f8faf2016-06-01 14:03:56 -0700672 if (!pProperty || iProperties < 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400673 return 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400674 for (int32_t i = 0; i < iProperties; i++) {
675 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400676 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
677 CXFA_Node* pNewNode =
dsinclaira1b07722016-07-11 08:20:58 -0700678 m_pDocument->CreateNode(pPacket, pProperty[i].eName);
weili44f8faf2016-06-01 14:03:56 -0700679 if (!pNewNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400680 break;
weili44f8faf2016-06-01 14:03:56 -0700681 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -0700682 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400683 nodes.Add(pNewNode);
684 break;
685 }
686 }
687 }
688 }
689 return nodes.GetSize();
690}
weili44f8faf2016-06-01 14:03:56 -0700691
dsinclair41cb62e2016-06-23 09:20:32 -0700692CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
tsepez736f28a2016-03-25 14:19:51 -0700693 uint32_t dwFlags) {
dsinclaira1b07722016-07-11 08:20:58 -0700694 CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
thestigb1a59592016-04-14 18:29:56 -0700695 pNode->SetFlag(dwFlags, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400696 return pNode;
697}
weili44f8faf2016-06-01 14:03:56 -0700698
tsepezd19e9122016-11-02 15:43:18 -0700699CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) {
dsinclair43854a52016-04-27 12:26:00 -0700700 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
dsinclaira1b07722016-07-11 08:20:58 -0700701 CXFA_Node* pClone =
702 m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700703 if (!pClone)
704 return nullptr;
705
Dan Sinclair1770c022016-03-14 14:14:16 -0400706 pClone->SetTemplateNode(this);
707 pClone->UpdateNameHash();
708 pClone->SetXMLMappingNode(GetXMLMappingNode());
709 if (bRecursive) {
710 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
711 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
712 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
713 }
714 }
dsinclairc5a8f212016-06-20 11:11:12 -0700715 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400716 return pClone;
717}
718
719CXFA_Node* CXFA_Node::GetTemplateNode() const {
720 return m_pAuxNode;
721}
722
723void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
724 m_pAuxNode = pTemplateNode;
725}
weili44f8faf2016-06-01 14:03:56 -0700726
Dan Sinclair1770c022016-03-14 14:14:16 -0400727CXFA_Node* CXFA_Node::GetBindData() {
728 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
729 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
730}
weili44f8faf2016-06-01 14:03:56 -0700731
Dan Sinclair1770c022016-03-14 14:14:16 -0400732int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) {
dsinclairc5a8f212016-06-20 11:11:12 -0700733 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700734 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400735 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
736 formItems.Copy(*pItems);
737 return formItems.GetSize();
738 }
739 CXFA_Node* pFormNode =
740 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
weili44f8faf2016-06-01 14:03:56 -0700741 if (pFormNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400742 formItems.Add(pFormNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400743 return formItems.GetSize();
744}
745
Dan Sinclair1770c022016-03-14 14:14:16 -0400746int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
747 ASSERT(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700748 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700749 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400750 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
751 ASSERT(pItems);
752 if (pItems->Find(pFormNode) < 0) {
753 pItems->Add(pFormNode);
754 }
755 return pItems->GetSize();
756 }
757 CXFA_Node* pOldFormItem =
758 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
759 if (!pOldFormItem) {
760 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
761 return 1;
762 } else if (pOldFormItem == pFormNode) {
763 return 1;
764 }
765 CXFA_NodeArray* pItems = new CXFA_NodeArray;
766 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
767 pItems->Add(pOldFormItem);
768 pItems->Add(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700769 m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400770 return 2;
771}
weili44f8faf2016-06-01 14:03:56 -0700772
Dan Sinclair1770c022016-03-14 14:14:16 -0400773int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
dsinclairc5a8f212016-06-20 11:11:12 -0700774 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700775 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400776 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
777 ASSERT(pItems);
778 int32_t iIndex = pItems->Find(pFormNode);
779 int32_t iCount = pItems->GetSize();
780 if (iIndex >= 0) {
weili44f8faf2016-06-01 14:03:56 -0700781 if (iIndex != iCount - 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400782 pItems->SetAt(iIndex, pItems->GetAt(iCount - 1));
Dan Sinclair1770c022016-03-14 14:14:16 -0400783 pItems->RemoveAt(iCount - 1);
784 if (iCount == 2) {
785 CXFA_Node* pLastFormNode = pItems->GetAt(0);
786 SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700787 m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400788 }
789 iCount--;
790 }
791 return iCount;
792 }
793 CXFA_Node* pOldFormItem =
794 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
795 if (pOldFormItem == pFormNode) {
weili44f8faf2016-06-01 14:03:56 -0700796 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
797 pOldFormItem = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400798 }
weili44f8faf2016-06-01 14:03:56 -0700799 return pOldFormItem ? 1 : 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400800}
weili44f8faf2016-06-01 14:03:56 -0700801
tsepezd19e9122016-11-02 15:43:18 -0700802bool CXFA_Node::HasBindItem() {
weili44f8faf2016-06-01 14:03:56 -0700803 return GetPacketID() == XFA_XDPPACKET_Datasets &&
804 GetObject(XFA_ATTRIBUTE_BindingNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400805}
weili44f8faf2016-06-01 14:03:56 -0700806
Dan Sinclair1770c022016-03-14 14:14:16 -0400807CXFA_WidgetData* CXFA_Node::GetWidgetData() {
808 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
809}
weili44f8faf2016-06-01 14:03:56 -0700810
Dan Sinclair1770c022016-03-14 14:14:16 -0400811CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
weili44f8faf2016-06-01 14:03:56 -0700812 if (GetPacketID() != XFA_XDPPACKET_Form)
813 return nullptr;
dsinclair41cb62e2016-06-23 09:20:32 -0700814 XFA_Element eType = GetElementType();
815 if (eType == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700816 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400817 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700818 if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700819 return nullptr;
820
dsinclair41cb62e2016-06-23 09:20:32 -0700821 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400822 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
823 if (pFieldWidgetData &&
824 pFieldWidgetData->GetChoiceListOpen() ==
825 XFA_ATTRIBUTEENUM_MultiSelect) {
weili44f8faf2016-06-01 14:03:56 -0700826 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400827 } else {
828 CFX_WideString wsPicture;
829 if (pFieldWidgetData) {
830 pFieldWidgetData->GetPictureContent(wsPicture,
831 XFA_VALUEPICTURE_DataBind);
832 }
weili44f8faf2016-06-01 14:03:56 -0700833 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400834 return pFieldWidgetData;
Dan Sinclair1770c022016-03-14 14:14:16 -0400835 CXFA_Node* pDataNode = GetBindData();
weili44f8faf2016-06-01 14:03:56 -0700836 if (!pDataNode)
837 return nullptr;
838 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400839 CXFA_NodeArray formNodes;
840 pDataNode->GetBindItems(formNodes);
841 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
842 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -0700843 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -0400844 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400845 pFieldWidgetData = pFormNode->GetWidgetData();
846 if (pFieldWidgetData) {
847 pFieldWidgetData->GetPictureContent(wsPicture,
848 XFA_VALUEPICTURE_DataBind);
849 }
weili44f8faf2016-06-01 14:03:56 -0700850 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400851 break;
weili44f8faf2016-06-01 14:03:56 -0700852 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400853 }
854 return pFieldWidgetData;
855 }
856 }
857 CXFA_Node* pGrandNode =
weili44f8faf2016-06-01 14:03:56 -0700858 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400859 CXFA_Node* pValueNode =
dsinclair070fcdf2016-06-22 22:04:54 -0700860 (pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
Dan Sinclair1770c022016-03-14 14:14:16 -0400861 ? pParentNode
weili44f8faf2016-06-01 14:03:56 -0700862 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400863 if (!pValueNode) {
dsinclair070fcdf2016-06-22 22:04:54 -0700864 pValueNode =
865 (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
866 ? pGrandNode
867 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400868 }
869 CXFA_Node* pParentOfValueNode =
weili44f8faf2016-06-01 14:03:56 -0700870 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400871 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
weili44f8faf2016-06-01 14:03:56 -0700872 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400873}
weili44f8faf2016-06-01 14:03:56 -0700874
tsepezd19e9122016-11-02 15:43:18 -0700875bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400876 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
dsinclair56a8b192016-06-21 14:15:25 -0700877 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
dsinclair43854a52016-04-27 12:26:00 -0700878 ASSERT(pTopSubform);
Dan Sinclair1770c022016-03-14 14:14:16 -0400879 CXFA_Node* pLocaleNode = this;
tsepezd19e9122016-11-02 15:43:18 -0700880 bool bLocale = false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400881 do {
tsepezd19e9122016-11-02 15:43:18 -0700882 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400883 if (!bLocale) {
884 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
885 }
886 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
weili44f8faf2016-06-01 14:03:56 -0700887 if (bLocale)
tsepezd19e9122016-11-02 15:43:18 -0700888 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400889 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
890 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
weili44f8faf2016-06-01 14:03:56 -0700891 if (!wsLocaleName.IsEmpty())
tsepezd19e9122016-11-02 15:43:18 -0700892 return true;
weili44f8faf2016-06-01 14:03:56 -0700893 if (pTopSubform &&
tsepezd19e9122016-11-02 15:43:18 -0700894 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) {
895 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400896 }
897 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
898 if (pLocale) {
899 wsLocaleName = pLocale->GetName();
tsepezd19e9122016-11-02 15:43:18 -0700900 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400901 }
tsepezd19e9122016-11-02 15:43:18 -0700902 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400903}
weili44f8faf2016-06-01 14:03:56 -0700904
Dan Sinclair1770c022016-03-14 14:14:16 -0400905XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
dsinclair56a8b192016-06-21 14:15:25 -0700906 CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
Dan Sinclair1770c022016-03-14 14:14:16 -0400907 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
908 if (pKeep) {
909 XFA_ATTRIBUTEENUM eIntact;
tsepezd19e9122016-11-02 15:43:18 -0700910 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400911 if (eIntact == XFA_ATTRIBUTEENUM_None &&
912 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
913 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
dsinclairc5a8f212016-06-20 11:11:12 -0700914 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
915 XFA_ObjectType::ContainerNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400916 if (pPreviewRow &&
917 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
918 XFA_ATTRIBUTEENUM_Row) {
919 XFA_ATTRIBUTEENUM eValue;
tsepezd19e9122016-11-02 15:43:18 -0700920 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700921 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
922 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
923 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400924 }
weili44f8faf2016-06-01 14:03:56 -0700925 CXFA_Node* pNode =
dsinclair56a8b192016-06-21 14:15:25 -0700926 pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
tsepezd19e9122016-11-02 15:43:18 -0700927 if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700928 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
929 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
930 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400931 }
932 }
933 }
934 return eIntact;
935 }
936 }
dsinclair41cb62e2016-06-23 09:20:32 -0700937 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700938 case XFA_Element::Subform:
Dan Sinclair1770c022016-03-14 14:14:16 -0400939 switch (eLayoutType) {
940 case XFA_ATTRIBUTEENUM_Position:
941 case XFA_ATTRIBUTEENUM_Row:
942 return XFA_ATTRIBUTEENUM_ContentArea;
943 case XFA_ATTRIBUTEENUM_Tb:
944 case XFA_ATTRIBUTEENUM_Table:
945 case XFA_ATTRIBUTEENUM_Lr_tb:
946 case XFA_ATTRIBUTEENUM_Rl_tb:
947 return XFA_ATTRIBUTEENUM_None;
948 default:
949 break;
950 }
951 break;
dsinclair56a8b192016-06-21 14:15:25 -0700952 case XFA_Element::Field: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400953 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700954 if (!pParentNode ||
955 pParentNode->GetElementType() == XFA_Element::PageArea)
Dan Sinclair1770c022016-03-14 14:14:16 -0400956 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400957 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
958 XFA_ATTRIBUTEENUM eParLayout =
959 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
960 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
961 eParLayout == XFA_ATTRIBUTEENUM_Row ||
962 eParLayout == XFA_ATTRIBUTEENUM_Table) {
963 return XFA_ATTRIBUTEENUM_None;
964 }
965 XFA_VERSION version = m_pDocument->GetCurVersionMode();
966 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
967 CXFA_Measurement measureH;
tsepezd19e9122016-11-02 15:43:18 -0700968 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false))
Dan Sinclair1770c022016-03-14 14:14:16 -0400969 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400970 }
971 return XFA_ATTRIBUTEENUM_None;
972 }
973 return XFA_ATTRIBUTEENUM_ContentArea;
974 }
dsinclair56a8b192016-06-21 14:15:25 -0700975 case XFA_Element::Draw:
Dan Sinclair1770c022016-03-14 14:14:16 -0400976 return XFA_ATTRIBUTEENUM_ContentArea;
977 default:
978 break;
979 }
980 return XFA_ATTRIBUTEENUM_None;
981}
weili44f8faf2016-06-01 14:03:56 -0700982
Dan Sinclair1770c022016-03-14 14:14:16 -0400983CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
weili44f8faf2016-06-01 14:03:56 -0700984 if (m_ePacket == XFA_XDPPACKET_Datasets)
Dan Sinclair1770c022016-03-14 14:14:16 -0400985 return m_pAuxNode;
weili44f8faf2016-06-01 14:03:56 -0700986 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400987}
weili44f8faf2016-06-01 14:03:56 -0700988
Dan Sinclair1770c022016-03-14 14:14:16 -0400989void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
dsinclair43854a52016-04-27 12:26:00 -0700990 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
Dan Sinclair1770c022016-03-14 14:14:16 -0400991 m_pAuxNode = pDataDescriptionNode;
992}
weili44f8faf2016-06-01 14:03:56 -0700993
Dan Sinclair1770c022016-03-14 14:14:16 -0400994void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
995 int32_t iLength = pArguments->GetLength();
996 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -0700997 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNode");
Dan Sinclair1770c022016-03-14 14:14:16 -0400998 return;
999 }
tsepez6fe7d212016-04-06 10:51:14 -07001000 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001001 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclairdf4bc592016-03-31 20:34:43 -07001002 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001003 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001004 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001005 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001006 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001007 refNode = ToNode(pScriptContext->GetThisObject());
tsepez736f28a2016-03-25 14:19:51 -07001008 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001009 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1010 XFA_RESOLVENODE_Siblings;
1011 XFA_RESOLVENODE_RS resoveNodeRS;
tsepezfc58ad12016-04-05 12:22:15 -07001012 int32_t iRet = pScriptContext->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001013 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
dsinclairf27aeec2016-06-07 19:36:18 -07001014 if (iRet < 1) {
1015 pArguments->GetReturnValue()->SetNull();
1016 return;
1017 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001018 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1019 CXFA_Object* pNode = resoveNodeRS.nodes[0];
dsinclairf27aeec2016-06-07 19:36:18 -07001020 pArguments->GetReturnValue()->Assign(
1021 pScriptContext->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001022 } else {
1023 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
1024 resoveNodeRS.pScriptAttribute;
1025 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
dsinclair86fad992016-05-31 11:34:04 -07001026 std::unique_ptr<CFXJSE_Value> pValue(
1027 new CFXJSE_Value(pScriptContext->GetRuntime()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001028 (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))(
tsepezd19e9122016-11-02 15:43:18 -07001029 pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
dsinclairf27aeec2016-06-07 19:36:18 -07001030 pArguments->GetReturnValue()->Assign(pValue.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001031 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001032 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001033 }
1034 }
1035}
weili44f8faf2016-06-01 14:03:56 -07001036
Dan Sinclair1770c022016-03-14 14:14:16 -04001037void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
1038 int32_t iLength = pArguments->GetLength();
1039 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001040 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04001041 return;
1042 }
tsepez6fe7d212016-04-06 10:51:14 -07001043 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001044 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclair12a6b0c2016-05-26 11:14:08 -07001045 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001046 if (!pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04001047 return;
tsepez736f28a2016-03-25 14:19:51 -07001048 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001049 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1050 XFA_RESOLVENODE_Siblings;
1051 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001052 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001053 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
dsinclair12a6b0c2016-05-26 11:14:08 -07001054 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001055}
weili44f8faf2016-06-01 14:03:56 -07001056
dsinclair12a6b0c2016-05-26 11:14:08 -07001057void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001058 CFX_WideString wsExpression,
tsepez736f28a2016-03-25 14:19:51 -07001059 uint32_t dwFlag,
Dan Sinclair1770c022016-03-14 14:14:16 -04001060 CXFA_Node* refNode) {
dsinclairdf4bc592016-03-31 20:34:43 -07001061 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001062 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001063 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001064 XFA_RESOLVENODE_RS resoveNodeRS;
weili44f8faf2016-06-01 14:03:56 -07001065 if (!refNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04001066 refNode = this;
tsepez4c3debb2016-04-08 12:20:38 -07001067 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
tsepezfc58ad12016-04-05 12:22:15 -07001068 resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001069 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
1070 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1071 for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) {
1072 if (resoveNodeRS.nodes[i]->IsNode())
1073 pNodeList->Append(resoveNodeRS.nodes[i]->AsNode());
1074 }
1075 } else {
dsinclair12a6b0c2016-05-26 11:14:08 -07001076 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
1077 if (resoveNodeRS.GetAttributeResult(valueArray) > 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001078 CXFA_ObjArray objectArray;
dsinclair12a6b0c2016-05-26 11:14:08 -07001079 valueArray.GetAttributeObject(objectArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04001080 for (int32_t i = 0; i < objectArray.GetSize(); i++) {
1081 if (objectArray[i]->IsNode())
1082 pNodeList->Append(objectArray[i]->AsNode());
1083 }
1084 }
1085 }
dsinclairf27aeec2016-06-07 19:36:18 -07001086 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001087}
weili44f8faf2016-06-01 14:03:56 -07001088
dsinclair12a6b0c2016-05-26 11:14:08 -07001089void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001090 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001091 XFA_ATTRIBUTE eAttribute) {
1092 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001093 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001094 } else {
tsepez736f28a2016-03-25 14:19:51 -07001095 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
Dan Sinclair1770c022016-03-14 14:14:16 -04001096 CFX_WideString wsName;
1097 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
1098 CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]");
dsinclair12a6b0c2016-05-26 11:14:08 -07001099 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001100 }
1101}
weili44f8faf2016-06-01 14:03:56 -07001102
dsinclair12a6b0c2016-05-26 11:14:08 -07001103void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001104 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001105 XFA_ATTRIBUTE eAttribute) {
dsinclairdf4bc592016-03-31 20:34:43 -07001106 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001107 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001108 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001109 if (bSetting) {
1110 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider();
dsinclair43854a52016-04-27 12:26:00 -07001111 ASSERT(pAppProvider);
Dan Sinclair1770c022016-03-14 14:14:16 -04001112 CFX_WideString wsMessage;
1113 pAppProvider->LoadString(XFA_IDS_Unable_TO_SET, wsMessage);
tsepez28f97ff2016-04-04 16:41:35 -07001114 FXJSE_ThrowMessage(
tsepezbd9748d2016-04-13 21:40:19 -07001115 FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001116 } else {
1117 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
dsinclairf27aeec2016-06-07 19:36:18 -07001118 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001119 }
1120}
weili44f8faf2016-06-01 14:03:56 -07001121
dsinclair12a6b0c2016-05-26 11:14:08 -07001122void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001123 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001124 XFA_ATTRIBUTE eAttribute) {
1125 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001126 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001127 } else {
tsepez736f28a2016-03-25 14:19:51 -07001128 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
dsinclair017052a2016-06-28 07:43:51 -07001129 CFX_WideString wsExpression =
1130 FX_WSTRC(L"#") + GetClassName() + FX_WSTRC(L"[*]");
dsinclair12a6b0c2016-05-26 11:14:08 -07001131 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001132 }
1133}
weili44f8faf2016-06-01 14:03:56 -07001134
dsinclair12a6b0c2016-05-26 11:14:08 -07001135void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001136 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001137 XFA_ATTRIBUTE eAttribute) {
1138 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001139 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001140 } else {
1141 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
1142 if (pParent) {
dsinclairf27aeec2016-06-07 19:36:18 -07001143 pValue->Assign(
1144 m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001145 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001146 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001147 }
1148 }
1149}
weili44f8faf2016-06-01 14:03:56 -07001150
dsinclair12a6b0c2016-05-26 11:14:08 -07001151void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001152 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001153 XFA_ATTRIBUTE eAttribute) {
weili44f8faf2016-06-01 14:03:56 -07001154 if (bSetting)
dsinclair2235b7b2016-06-02 07:42:25 -07001155 ThrowException(XFA_IDS_INVAlID_PROP_SET);
weili44f8faf2016-06-01 14:03:56 -07001156 else
dsinclairf27aeec2016-06-07 19:36:18 -07001157 pValue->SetInteger(GetNodeSameNameIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001158}
weili44f8faf2016-06-01 14:03:56 -07001159
dsinclair12a6b0c2016-05-26 11:14:08 -07001160void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001161 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001162 XFA_ATTRIBUTE eAttribute) {
weili44f8faf2016-06-01 14:03:56 -07001163 if (bSetting)
dsinclair2235b7b2016-06-02 07:42:25 -07001164 ThrowException(XFA_IDS_INVAlID_PROP_SET);
weili44f8faf2016-06-01 14:03:56 -07001165 else
dsinclairf27aeec2016-06-07 19:36:18 -07001166 pValue->SetInteger(GetNodeSameClassIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001167}
weili44f8faf2016-06-01 14:03:56 -07001168
dsinclair12a6b0c2016-05-26 11:14:08 -07001169void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001170 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001171 XFA_ATTRIBUTE eAttribute) {
1172 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001173 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001174 } else {
1175 CFX_WideString wsSOMExpression;
1176 GetSOMExpression(wsSOMExpression);
dsinclairf27aeec2016-06-07 19:36:18 -07001177 pValue->SetString(FX_UTF8Encode(wsSOMExpression).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001178 }
1179}
weili44f8faf2016-06-01 14:03:56 -07001180
Dan Sinclair1770c022016-03-14 14:14:16 -04001181void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
1182 int32_t iLength = pArguments->GetLength();
1183 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001184 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"applyXSL");
Dan Sinclair1770c022016-03-14 14:14:16 -04001185 return;
1186 }
tsepez6fe7d212016-04-06 10:51:14 -07001187 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001188 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili60607c32016-05-26 11:53:12 -07001189 // TODO(weili): check whether we need to implement this, pdfium:501.
1190 // For now, just put the variables here to avoid unused variable warning.
1191 (void)wsExpression;
Dan Sinclair1770c022016-03-14 14:14:16 -04001192}
weili60607c32016-05-26 11:53:12 -07001193
Dan Sinclair1770c022016-03-14 14:14:16 -04001194void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
1195 int32_t iLength = pArguments->GetLength();
1196 if (iLength < 1 || iLength > 3) {
dsinclair2235b7b2016-06-02 07:42:25 -07001197 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"assignNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04001198 return;
1199 }
1200 CFX_WideString wsExpression;
1201 CFX_WideString wsValue;
1202 int32_t iAction = 0;
weili44f8faf2016-06-01 14:03:56 -07001203 wsExpression =
1204 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001205 if (iLength >= 2) {
weili60607c32016-05-26 11:53:12 -07001206 wsValue =
1207 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001208 }
weili60607c32016-05-26 11:53:12 -07001209 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001210 iAction = pArguments->GetInt32(2);
weili60607c32016-05-26 11:53:12 -07001211 // TODO(weili): check whether we need to implement this, pdfium:501.
1212 // For now, just put the variables here to avoid unused variable warning.
1213 (void)wsExpression;
1214 (void)wsValue;
1215 (void)iAction;
Dan Sinclair1770c022016-03-14 14:14:16 -04001216}
weili60607c32016-05-26 11:53:12 -07001217
Dan Sinclair1770c022016-03-14 14:14:16 -04001218void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
1219 int32_t iLength = pArguments->GetLength();
1220 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001221 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clone");
Dan Sinclair1770c022016-03-14 14:14:16 -04001222 return;
1223 }
weili44f8faf2016-06-01 14:03:56 -07001224 bool bClone = !!pArguments->GetInt32(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001225 CXFA_Node* pCloneNode = Clone(bClone);
dsinclairf27aeec2016-06-07 19:36:18 -07001226 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001227 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
1228}
weili44f8faf2016-06-01 14:03:56 -07001229
Dan Sinclair1770c022016-03-14 14:14:16 -04001230void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
1231 int32_t iLength = pArguments->GetLength();
1232 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001233 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001234 return;
1235 }
tsepez6fe7d212016-04-06 10:51:14 -07001236 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001237 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001238 CFX_WideString wsValue;
tsepez4c3debb2016-04-08 12:20:38 -07001239 GetAttribute(wsExpression.AsStringC(), wsValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07001240 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001241 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001242 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001243}
weili44f8faf2016-06-01 14:03:56 -07001244
Dan Sinclair1770c022016-03-14 14:14:16 -04001245void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
1246 int32_t iLength = pArguments->GetLength();
1247 if (iLength < 1 || iLength > 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07001248 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001249 return;
1250 }
1251 CFX_WideString wsExpression;
1252 int32_t iValue = 0;
weili44f8faf2016-06-01 14:03:56 -07001253 wsExpression =
1254 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1255 if (iLength >= 2)
Dan Sinclair1770c022016-03-14 14:14:16 -04001256 iValue = pArguments->GetInt32(1);
dsinclair6e124782016-06-23 12:14:55 -07001257 CXFA_Node* pNode =
1258 GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
dsinclairf27aeec2016-06-07 19:36:18 -07001259 pArguments->GetReturnValue()->Assign(
1260 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001261}
weili65be4b12016-05-25 15:47:43 -07001262
Dan Sinclair1770c022016-03-14 14:14:16 -04001263void CXFA_Node::Script_NodeClass_IsPropertySpecified(
1264 CFXJSE_Arguments* pArguments) {
1265 int32_t iLength = pArguments->GetLength();
1266 if (iLength < 1 || iLength > 3) {
dsinclair2235b7b2016-06-02 07:42:25 -07001267 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isPropertySpecified");
Dan Sinclair1770c022016-03-14 14:14:16 -04001268 return;
1269 }
1270 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001271 bool bParent = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001272 int32_t iIndex = 0;
weili44f8faf2016-06-01 14:03:56 -07001273 wsExpression =
1274 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili65be4b12016-05-25 15:47:43 -07001275 if (iLength >= 2)
weili44f8faf2016-06-01 14:03:56 -07001276 bParent = !!pArguments->GetInt32(1);
weili65be4b12016-05-25 15:47:43 -07001277 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001278 iIndex = pArguments->GetInt32(2);
tsepezd19e9122016-11-02 15:43:18 -07001279 bool bHas = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001280 const XFA_ATTRIBUTEINFO* pAttributeInfo =
tsepez4c3debb2016-04-08 12:20:38 -07001281 XFA_GetAttributeByName(wsExpression.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001282 CFX_WideString wsValue;
weili65be4b12016-05-25 15:47:43 -07001283 if (pAttributeInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04001284 bHas = HasAttribute(pAttributeInfo->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04001285 if (!bHas) {
dsinclair6e124782016-06-23 12:14:55 -07001286 XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
1287 bHas = !!GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001288 if (!bHas && bParent && m_pParent) {
1289 // Also check on the parent.
1290 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
1291 if (!bHas)
dsinclair6e124782016-06-23 12:14:55 -07001292 bHas = !!m_pParent->GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001293 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001294 }
dsinclair12a6b0c2016-05-26 11:14:08 -07001295 CFXJSE_Value* pValue = pArguments->GetReturnValue();
1296 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001297 pValue->SetBoolean(bHas);
Dan Sinclair1770c022016-03-14 14:14:16 -04001298}
weili65be4b12016-05-25 15:47:43 -07001299
Dan Sinclair1770c022016-03-14 14:14:16 -04001300void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
1301 int32_t iLength = pArguments->GetLength();
1302 if (iLength < 1 || iLength > 3) {
dsinclair2235b7b2016-06-02 07:42:25 -07001303 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001304 return;
1305 }
1306 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001307 bool bIgnoreRoot = true;
1308 bool bOverwrite = 0;
1309 wsExpression =
1310 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1311 if (wsExpression.IsEmpty())
Tom Sepezd3743ea2016-05-16 15:56:53 -07001312 return;
weili44f8faf2016-06-01 14:03:56 -07001313 if (iLength >= 2)
1314 bIgnoreRoot = !!pArguments->GetInt32(1);
1315 if (iLength >= 3)
1316 bOverwrite = !!pArguments->GetInt32(2);
dsinclaira1b07722016-07-11 08:20:58 -07001317 std::unique_ptr<CXFA_SimpleParser> pParser(
1318 new CXFA_SimpleParser(m_pDocument, false));
weili44f8faf2016-06-01 14:03:56 -07001319 if (!pParser)
Dan Sinclair1770c022016-03-14 14:14:16 -04001320 return;
weili44f8faf2016-06-01 14:03:56 -07001321 CFDE_XMLNode* pXMLNode = nullptr;
1322 int32_t iParserStatus =
1323 pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
1324 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
1325 return;
dsinclairae95f762016-03-29 16:58:29 -07001326 if (bIgnoreRoot &&
1327 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
1328 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
weili44f8faf2016-06-01 14:03:56 -07001329 bIgnoreRoot = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001330 }
tsepezd19e9122016-11-02 15:43:18 -07001331 CXFA_Node* pFakeRoot = Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001332 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
1333 if (!wsContentType.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07001334 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
1335 CFX_WideString(wsContentType));
Dan Sinclair1770c022016-03-14 14:14:16 -04001336 }
dsinclairae95f762016-03-29 16:58:29 -07001337 CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001338 if (!pFakeXMLRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001339 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
tsepezd19e9122016-11-02 15:43:18 -07001340 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001341 }
dsinclair017052a2016-06-28 07:43:51 -07001342 if (!pFakeXMLRoot)
1343 pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName()));
1344
Dan Sinclair1770c022016-03-14 14:14:16 -04001345 if (bIgnoreRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001346 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001347 while (pXMLChild) {
dsinclairae95f762016-03-29 16:58:29 -07001348 CFDE_XMLNode* pXMLSibling =
1349 pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001350 pXMLNode->RemoveChildNode(pXMLChild);
1351 pFakeXMLRoot->InsertChildNode(pXMLChild);
1352 pXMLChild = pXMLSibling;
1353 }
1354 } else {
dsinclairae95f762016-03-29 16:58:29 -07001355 CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001356 if (pXMLParent) {
1357 pXMLParent->RemoveChildNode(pXMLNode);
1358 }
1359 pFakeXMLRoot->InsertChildNode(pXMLNode);
1360 }
1361 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot);
1362 pFakeRoot = pParser->GetRootNode();
1363 if (pFakeRoot) {
1364 if (bOverwrite) {
1365 CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1366 CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1367 int32_t index = 0;
1368 while (pNewChild) {
1369 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1370 pFakeRoot->RemoveChild(pNewChild);
1371 InsertChild(index++, pNewChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001372 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001373 pNewChild = pItem;
1374 }
1375 while (pChild) {
1376 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1377 RemoveChild(pChild);
1378 pFakeRoot->InsertChild(pChild);
1379 pChild = pItem;
1380 }
1381 if (GetPacketID() == XFA_XDPPACKET_Form &&
dsinclair070fcdf2016-06-22 22:04:54 -07001382 GetElementType() == XFA_Element::ExData) {
dsinclairae95f762016-03-29 16:58:29 -07001383 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001384 SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001385 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
weili44f8faf2016-06-01 14:03:56 -07001386 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001387 pFakeXMLRoot = pTempXMLNode;
1388 } else {
weili44f8faf2016-06-01 14:03:56 -07001389 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001390 }
1391 }
tsepezd19e9122016-11-02 15:43:18 -07001392 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001393 } else {
1394 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1395 while (pChild) {
1396 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1397 pFakeRoot->RemoveChild(pChild);
1398 InsertChild(pChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001399 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001400 pChild = pItem;
1401 }
1402 }
1403 if (pFakeXMLRoot) {
1404 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001405 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001406 }
dsinclairc5a8f212016-06-20 11:11:12 -07001407 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001408 } else {
Tom Sepezd3743ea2016-05-16 15:56:53 -07001409 if (pFakeXMLRoot) {
1410 pFakeXMLRoot->Release();
weili44f8faf2016-06-01 14:03:56 -07001411 pFakeXMLRoot = nullptr;
Tom Sepezd3743ea2016-05-16 15:56:53 -07001412 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001413 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001414}
weili44f8faf2016-06-01 14:03:56 -07001415
Dan Sinclair1770c022016-03-14 14:14:16 -04001416void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
weili44f8faf2016-06-01 14:03:56 -07001417 // TODO(weili): Check whether we need to implement this, pdfium:501.
Dan Sinclair1770c022016-03-14 14:14:16 -04001418}
1419
1420void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1421 int32_t iLength = pArguments->GetLength();
1422 if (iLength < 0 || iLength > 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001423 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001424 return;
1425 }
weili44f8faf2016-06-01 14:03:56 -07001426 bool bPrettyMode = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001427 if (iLength == 1) {
weili65be4b12016-05-25 15:47:43 -07001428 if (pArguments->GetUTF8String(0) != "pretty") {
dsinclair2235b7b2016-06-02 07:42:25 -07001429 ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
Dan Sinclair1770c022016-03-14 14:14:16 -04001430 return;
1431 }
weili44f8faf2016-06-01 14:03:56 -07001432 bPrettyMode = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001433 }
1434 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
weili65be4b12016-05-25 15:47:43 -07001435 if (GetPacketID() == XFA_XDPPACKET_Form ||
1436 GetPacketID() == XFA_XDPPACKET_Datasets) {
1437 CFDE_XMLNode* pElement = nullptr;
1438 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1439 pElement = GetXMLMappingNode();
1440 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
dsinclairf27aeec2016-06-07 19:36:18 -07001441 pArguments->GetReturnValue()->SetString(bsXMLHeader);
weili65be4b12016-05-25 15:47:43 -07001442 return;
1443 }
1444 XFA_DataExporter_DealWithDataGroupNode(this);
1445 }
tsepez833619b2016-12-07 09:21:17 -08001446 CFX_RetainPtr<IFX_MemoryStream> pMemoryStream =
1447 IFX_MemoryStream::Create(true);
1448
1449 // Note: ambiguious below without static_cast.
tsepez7cda31a2016-12-07 12:10:20 -08001450 CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream(
1451 CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream),
1452 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
tsepez833619b2016-12-07 09:21:17 -08001453
Dan Sinclair1770c022016-03-14 14:14:16 -04001454 if (!pStream) {
dsinclairf27aeec2016-06-07 19:36:18 -07001455 pArguments->GetReturnValue()->SetString(bsXMLHeader);
Dan Sinclair1770c022016-03-14 14:14:16 -04001456 return;
1457 }
1458 pStream->SetCodePage(FX_CODEPAGE_UTF8);
dsinclair179bebb2016-04-05 11:02:18 -07001459 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
weili65be4b12016-05-25 15:47:43 -07001460 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepez7cda31a2016-12-07 12:10:20 -08001461 XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001462 else
tsepez7cda31a2016-12-07 12:10:20 -08001463 pElement->SaveXMLNode(pStream);
weili65be4b12016-05-25 15:47:43 -07001464 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1465 // For now, just put it here to avoid unused variable warning.
1466 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001467 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001468 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001469 return;
1470 }
dsinclairf27aeec2016-06-07 19:36:18 -07001471 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001472}
1473
1474void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1475 int32_t iLength = pArguments->GetLength();
1476 if (iLength != 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07001477 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001478 return;
1479 }
tsepez6fe7d212016-04-06 10:51:14 -07001480 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001481 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001482 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001483 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001484 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001485}
weili60607c32016-05-26 11:53:12 -07001486
Dan Sinclair1770c022016-03-14 14:14:16 -04001487void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1488 int32_t iLength = pArguments->GetLength();
1489 if (iLength != 1 && iLength != 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07001490 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001491 return;
1492 }
weili60607c32016-05-26 11:53:12 -07001493 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001494 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001495 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1496 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001497 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001498 // TODO(weili): check whether we need to implement this, pdfium:501.
1499 // For now, just put the variables here to avoid unused variable warning.
1500 (void)pNode;
1501 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001502}
weili60607c32016-05-26 11:53:12 -07001503
dsinclair12a6b0c2016-05-26 11:14:08 -07001504void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001505 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001506 XFA_ATTRIBUTE eAttribute) {
1507 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001508 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001509 } else {
1510 CFX_WideString wsNameSpace;
1511 TryNamespace(wsNameSpace);
dsinclairf27aeec2016-06-07 19:36:18 -07001512 pValue->SetString(FX_UTF8Encode(wsNameSpace).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001513 }
1514}
weili44f8faf2016-06-01 14:03:56 -07001515
dsinclair12a6b0c2016-05-26 11:14:08 -07001516void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001517 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001518 XFA_ATTRIBUTE eAttribute) {
1519 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001520 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001521 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001522 pValue->Assign(
1523 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001524 }
1525}
weili44f8faf2016-06-01 14:03:56 -07001526
dsinclair12a6b0c2016-05-26 11:14:08 -07001527void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001528 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001529 XFA_ATTRIBUTE eAttribute) {
weili44f8faf2016-06-01 14:03:56 -07001530 if (bSetting)
dsinclair2235b7b2016-06-02 07:42:25 -07001531 ThrowException(XFA_IDS_INVAlID_PROP_SET);
weili44f8faf2016-06-01 14:03:56 -07001532 else
dsinclairf27aeec2016-06-07 19:36:18 -07001533 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001534}
weili44f8faf2016-06-01 14:03:56 -07001535
dsinclair12a6b0c2016-05-26 11:14:08 -07001536void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001537 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001538 XFA_ATTRIBUTE eAttribute) {
1539 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001540 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001541 } else {
dsinclair070fcdf2016-06-22 22:04:54 -07001542 if (GetElementType() == XFA_Element::Subform) {
tsepezd19e9122016-11-02 15:43:18 -07001543 pValue->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001544 return;
1545 }
1546 CFX_WideString strValue;
dsinclairf27aeec2016-06-07 19:36:18 -07001547 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001548 }
1549}
weili44f8faf2016-06-01 14:03:56 -07001550
dsinclair12a6b0c2016-05-26 11:14:08 -07001551void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001552 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001553 XFA_ATTRIBUTE eAttribute) {
1554 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001555 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001556 } else {
1557 CXFA_NodeArray properts;
1558 int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty);
1559 if (iSize > 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07001560 pValue->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001561 m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0]));
1562 }
1563 }
1564}
weili44f8faf2016-06-01 14:03:56 -07001565
Dan Sinclair1770c022016-03-14 14:14:16 -04001566void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001567
Dan Sinclair1770c022016-03-14 14:14:16 -04001568void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1569 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001570 pArguments->GetReturnValue()->SetObject(
1571 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001572}
1573void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1574}
dsinclair5b36f0a2016-07-19 10:56:23 -07001575
Dan Sinclair1770c022016-03-14 14:14:16 -04001576void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1577 Script_Template_CreateNode(pArguments);
1578}
dsinclair5b36f0a2016-07-19 10:56:23 -07001579
Dan Sinclair1770c022016-03-14 14:14:16 -04001580void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1581 int32_t iLength = pArguments->GetLength();
1582 if (iLength < 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001583 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001584 return;
1585 }
1586 CFX_WideString wsNameSpace;
1587 if (iLength >= 1) {
1588 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001589 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001590 }
1591 CFX_WideString wsNodeNameSpace;
1592 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001593 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001594 if (pValue)
1595 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001596}
dsinclair5b36f0a2016-07-19 10:56:23 -07001597
dsinclair12a6b0c2016-05-26 11:14:08 -07001598void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001599 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001600 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001601
dsinclair12a6b0c2016-05-26 11:14:08 -07001602void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001603 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001604 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001605
dsinclair12a6b0c2016-05-26 11:14:08 -07001606void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001607 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001608 XFA_ATTRIBUTE eAttribute) {
1609 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001610 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001611 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001612 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001613 }
1614}
dsinclair5b36f0a2016-07-19 10:56:23 -07001615
dsinclair12a6b0c2016-05-26 11:14:08 -07001616void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001617 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001618 XFA_ATTRIBUTE eAttribute) {
1619 if (!bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001620 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001621 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001622 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001623 }
1624}
dsinclair5b36f0a2016-07-19 10:56:23 -07001625
dsinclair12a6b0c2016-05-26 11:14:08 -07001626void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001627 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001628 XFA_ATTRIBUTE eAttribute) {
1629 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001630 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001631 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001632 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001633 }
1634}
dsinclair5b36f0a2016-07-19 10:56:23 -07001635
dsinclair12a6b0c2016-05-26 11:14:08 -07001636void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001637 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001638 XFA_ATTRIBUTE eAttribute) {
1639 if (!bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001640 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001641 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001642 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001643 }
1644}
thestigb1a59592016-04-14 18:29:56 -07001645
Dan Sinclair1770c022016-03-14 14:14:16 -04001646void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001647 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001648 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001649 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001650 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001651 return;
thestigb1a59592016-04-14 18:29:56 -07001652
dsinclaira1b07722016-07-11 08:20:58 -07001653 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001654 if (!pNotify)
1655 return;
1656
1657 uint32_t dwPacket = GetPacketID();
1658 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1659 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001660 return;
1661 }
thestigb1a59592016-04-14 18:29:56 -07001662
1663 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001664 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001665 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001666 bNeedFindContainer = true;
1667 pNotify->OnValueChanged(this, eAttribute, this,
1668 GetNodeItem(XFA_NODEITEM_Parent));
1669 break;
dsinclair56a8b192016-06-21 14:15:25 -07001670 case XFA_Element::Font:
1671 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001672 bNeedFindContainer = true;
1673 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001674 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001675 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1676 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1677 } else {
1678 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1679 }
1680 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001681 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001682 bNeedFindContainer = true;
1683 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001684 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001685 if (pParentNode->IsContainerNode()) {
1686 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001687 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001688 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1689 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1690 } else {
1691 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001692 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001693 pNotify->OnValueChanged(this, eAttribute, pNode,
1694 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001695 }
thestigb1a59592016-04-14 18:29:56 -07001696 }
1697 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001698 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001699 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001700 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001701 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1702 eUIType == XFA_Element::NumericEdit ||
1703 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001704 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001705 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001706 pNotify->OnValueChanged(this, eAttribute, pUINode,
1707 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001708 }
thestigb1a59592016-04-14 18:29:56 -07001709 }
1710 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001711 case XFA_Element::Button:
1712 case XFA_Element::Barcode:
1713 case XFA_Element::ChoiceList:
1714 case XFA_Element::DateTimeEdit:
1715 case XFA_Element::NumericEdit:
1716 case XFA_Element::PasswordEdit:
1717 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001718 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1719 if (pUINode) {
1720 pNotify->OnValueChanged(this, eAttribute, pUINode,
1721 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1722 }
1723 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001724 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001725 bNeedFindContainer = true;
1726 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1727 if (pUINode) {
1728 pNotify->OnValueChanged(this, eAttribute, pUINode,
1729 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1730 }
1731 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001732 case XFA_Element::Keep:
1733 case XFA_Element::Bookend:
1734 case XFA_Element::Break:
1735 case XFA_Element::BreakAfter:
1736 case XFA_Element::BreakBefore:
1737 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001738 bNeedFindContainer = true;
1739 break;
dsinclair56a8b192016-06-21 14:15:25 -07001740 case XFA_Element::Area:
1741 case XFA_Element::Draw:
1742 case XFA_Element::ExclGroup:
1743 case XFA_Element::Field:
1744 case XFA_Element::Subform:
1745 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001746 pLayoutPro->AddChangedContainer(this);
1747 pNotify->OnValueChanged(this, eAttribute, this, this);
1748 break;
dsinclair56a8b192016-06-21 14:15:25 -07001749 case XFA_Element::Sharptext:
1750 case XFA_Element::Sharpxml:
1751 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001752 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1753 if (!pTextNode) {
1754 return;
1755 }
1756 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1757 if (!pValueNode) {
1758 return;
1759 }
dsinclair41cb62e2016-06-23 09:20:32 -07001760 XFA_Element eType = pValueNode->GetElementType();
1761 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001762 bNeedFindContainer = true;
1763 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1764 if (pNode && pNode->IsContainerNode()) {
1765 if (bScriptModify) {
1766 pValueNode = pNode;
1767 }
1768 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1769 } else {
1770 pNotify->OnValueChanged(this, eAttribute, pNode,
1771 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001772 }
thestigb1a59592016-04-14 18:29:56 -07001773 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001774 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001775 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1776 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001777 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001778 }
1779 }
thestigb1a59592016-04-14 18:29:56 -07001780 }
1781 } break;
1782 default:
1783 break;
1784 }
1785 if (bNeedFindContainer) {
1786 CXFA_Node* pParent = this;
1787 while (pParent) {
1788 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001789 break;
thestigb1a59592016-04-14 18:29:56 -07001790
1791 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001792 }
thestigb1a59592016-04-14 18:29:56 -07001793 if (pParent) {
1794 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001795 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001796 }
1797}
thestigb1a59592016-04-14 18:29:56 -07001798
dsinclair12a6b0c2016-05-26 11:14:08 -07001799void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001800 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001801 XFA_ATTRIBUTE eAttribute) {
1802 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001803 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001804 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001805 if (eAttribute == XFA_ATTRIBUTE_Use &&
1806 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001807 CXFA_Node* pTemplateNode =
1808 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1809 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001810 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1811 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001812
1813 CFX_WideString wsID;
1814 CFX_WideString wsSOM;
1815 if (!wsValue.IsEmpty()) {
1816 if (wsValue[0] == '#') {
1817 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001818 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001819 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001820 }
1821 }
weili44f8faf2016-06-01 14:03:56 -07001822 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001823 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001824 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001825 XFA_RESOLVENODE_Attributes |
1826 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1827 XFA_RESOLVENODE_Siblings;
1828 XFA_RESOLVENODE_RS resoveNodeRS;
1829 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001830 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001831 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) {
1832 pProtoNode = resoveNodeRS.nodes[0]->AsNode();
1833 }
1834 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001835 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001836 }
1837 if (pProtoNode) {
1838 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1839 while (pHeadChild) {
1840 CXFA_Node* pSibling =
1841 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1842 RemoveChild(pHeadChild);
1843 pHeadChild = pSibling;
1844 }
tsepezd19e9122016-11-02 15:43:18 -07001845 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001846 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1847 while (pHeadChild) {
1848 CXFA_Node* pSibling =
1849 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1850 pProtoForm->RemoveChild(pHeadChild);
1851 InsertChild(pHeadChild);
1852 pHeadChild = pSibling;
1853 }
1854 m_pDocument->RemovePurgeNode(pProtoForm);
1855 delete pProtoForm;
1856 }
1857 }
1858 } else {
1859 CFX_WideString wsValue;
1860 GetAttribute(eAttribute, wsValue);
dsinclairf27aeec2016-06-07 19:36:18 -07001861 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07001862 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001863 }
1864}
dsinclair5b36f0a2016-07-19 10:56:23 -07001865
dsinclair12a6b0c2016-05-26 11:14:08 -07001866void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001867 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001868 XFA_ATTRIBUTE eAttribute) {
1869 if (!bSetting) {
1870 CFX_WideString wsValue;
1871 GetAttribute(eAttribute, wsValue);
dsinclairf27aeec2016-06-07 19:36:18 -07001872 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07001873 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001874 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001875 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001876 }
1877}
dsinclair5b36f0a2016-07-19 10:56:23 -07001878
Dan Sinclair1770c022016-03-14 14:14:16 -04001879void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1880 int32_t argc = pArguments->GetLength();
1881 if ((argc == 0) || (argc == 1)) {
tsepezd19e9122016-11-02 15:43:18 -07001882 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001883 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001884 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001885 }
1886}
dsinclair5b36f0a2016-07-19 10:56:23 -07001887
Dan Sinclair1770c022016-03-14 14:14:16 -04001888void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
1889 int32_t argc = pArguments->GetLength();
1890 if (argc == 0) {
1891 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001892 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001893 }
1894}
dsinclair5b36f0a2016-07-19 10:56:23 -07001895
dsinclair12a6b0c2016-05-26 11:14:08 -07001896void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001897 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001898 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001899
dsinclair12a6b0c2016-05-26 11:14:08 -07001900void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001901 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001902 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001903
dsinclair12a6b0c2016-05-26 11:14:08 -07001904void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001905 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001906 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001907
dsinclair12a6b0c2016-05-26 11:14:08 -07001908void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001909 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001910 XFA_SOM_MESSAGETYPE iMessageType) {
1911 CXFA_WidgetData* pWidgetData = GetWidgetData();
1912 if (!pWidgetData) {
1913 return;
1914 }
tsepezd19e9122016-11-02 15:43:18 -07001915 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001916 CXFA_Validate validate = pWidgetData->GetValidate();
1917 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001918 validate = pWidgetData->GetValidate(true);
1919 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001920 }
1921 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001922 switch (iMessageType) {
1923 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001924 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001925 break;
1926 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001927 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001928 break;
1929 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001930 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001931 break;
1932 default:
1933 break;
1934 }
1935 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001936 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001937 if (!pNotify) {
1938 return;
1939 }
1940 pNotify->AddCalcValidate(this);
1941 }
1942 } else {
1943 CFX_WideString wsMessage;
1944 switch (iMessageType) {
1945 case XFA_SOM_ValidationMessage:
1946 validate.GetScriptMessageText(wsMessage);
1947 break;
1948 case XFA_SOM_FormatMessage:
1949 validate.GetFormatMessageText(wsMessage);
1950 break;
1951 case XFA_SOM_MandatoryMessage:
1952 validate.GetNullMessageText(wsMessage);
1953 break;
1954 default:
1955 break;
1956 }
dsinclairf27aeec2016-06-07 19:36:18 -07001957 pValue->SetString(FX_UTF8Encode(wsMessage).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001958 }
1959}
dsinclair5b36f0a2016-07-19 10:56:23 -07001960
dsinclair12a6b0c2016-05-26 11:14:08 -07001961void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001962 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001963 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001964 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001965}
dsinclair5b36f0a2016-07-19 10:56:23 -07001966
dsinclair12a6b0c2016-05-26 11:14:08 -07001967void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001968 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001969 XFA_ATTRIBUTE eAttribute) {
1970 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001971 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001972 } else {
1973 CXFA_WidgetData* pWidgetData = GetWidgetData();
1974 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07001975 pValue->SetInteger(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001976 return;
1977 }
tsepezd19e9122016-11-02 15:43:18 -07001978 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001979 }
1980}
dsinclair5b36f0a2016-07-19 10:56:23 -07001981
dsinclair12a6b0c2016-05-26 11:14:08 -07001982void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001983 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001984 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001985 XFA_Element eType = GetElementType();
1986 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001987 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001988 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001989 }
1990 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001991 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001992 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001993 }
1994 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001995 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001996 return;
1997 }
1998 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001999 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07002000 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002001 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002002
Dan Sinclair1770c022016-03-14 14:14:16 -04002003 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07002004 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002005 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
2006 CXFA_NodeArray formNodes;
2007 GetBindItems(formNodes);
2008 CFX_WideString wsPicture;
2009 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
2010 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -07002011 if (!pFormNode || pFormNode->HasRemovedChildren()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002012 continue;
2013 }
2014 pContainerWidgetData = pFormNode->GetContainerWidgetData();
2015 if (pContainerWidgetData) {
2016 pContainerWidgetData->GetPictureContent(wsPicture,
2017 XFA_VALUEPICTURE_DataBind);
2018 }
2019 if (!wsPicture.IsEmpty()) {
2020 break;
2021 }
weili44f8faf2016-06-01 14:03:56 -07002022 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002023 }
2024 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
2025 pContainerWidgetData = GetContainerWidgetData();
2026 }
2027 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002028 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002029 }
tsepezd19e9122016-11-02 15:43:18 -07002030 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002031 } else {
tsepezd19e9122016-11-02 15:43:18 -07002032 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07002033 if (content.IsEmpty() && eType != XFA_Element::Text &&
2034 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07002035 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07002036 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002037 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07002038 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07002039 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002040 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002041 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002042 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002043 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002044 }
2045 }
2046}
dsinclair5b36f0a2016-07-19 10:56:23 -07002047
dsinclair12a6b0c2016-05-26 11:14:08 -07002048void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002049 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002050 XFA_ATTRIBUTE eAttribute) {
2051 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07002052 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002053 return;
2054 }
tsepezd19e9122016-11-02 15:43:18 -07002055 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002056 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002057 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002058 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002059 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002060 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002061 }
2062}
dsinclair5b36f0a2016-07-19 10:56:23 -07002063
dsinclair12a6b0c2016-05-26 11:14:08 -07002064void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002065 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002066 XFA_ATTRIBUTE eAttribute) {
2067 if (bSetting) {
2068 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002069 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002070 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002071
tsepezb4c9f3f2016-04-13 15:41:21 -07002072 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002073 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002074 CFX_WideString wsFormatValue(wsNewValue);
2075 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2076 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002077 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002078 }
tsepezd19e9122016-11-02 15:43:18 -07002079 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002080 } else {
tsepezd19e9122016-11-02 15:43:18 -07002081 CFX_WideString wsValue = GetScriptContent(true);
dsinclairf27aeec2016-06-07 19:36:18 -07002082 pValue->SetBoolean(wsValue == FX_WSTRC(L"1"));
Dan Sinclair1770c022016-03-14 14:14:16 -04002083 }
2084}
dsinclair2f5582f2016-06-09 11:48:23 -07002085
dsinclair12a6b0c2016-05-26 11:14:08 -07002086void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002087 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002088 XFA_ATTRIBUTE eAttribute) {
2089 CXFA_WidgetData* pWidgetData = GetWidgetData();
2090 if (!pWidgetData) {
2091 return;
2092 }
tsepezd19e9122016-11-02 15:43:18 -07002093 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002094 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002095 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002096 int32_t r = 0;
2097 int32_t g = 0;
2098 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002099 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002100 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2101 for (int32_t i = 0; i < iSize; ++i) {
2102 CXFA_Edge edge = border.GetEdge(i);
2103 edge.SetColor(rgb);
2104 }
2105 } else {
2106 CXFA_Edge edge = border.GetEdge(0);
2107 FX_ARGB color = edge.GetColor();
2108 int32_t a, r, g, b;
2109 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002110 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002111 strColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002112 pValue->SetString(FX_UTF8Encode(strColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002113 }
2114}
dsinclair5b36f0a2016-07-19 10:56:23 -07002115
dsinclair12a6b0c2016-05-26 11:14:08 -07002116void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002117 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002118 XFA_ATTRIBUTE eAttribute) {
2119 CXFA_WidgetData* pWidgetData = GetWidgetData();
2120 if (!pWidgetData) {
2121 return;
2122 }
tsepezd19e9122016-11-02 15:43:18 -07002123 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002124 int32_t iSize = border.CountEdges();
2125 CFX_WideString wsThickness;
2126 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002127 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002128 for (int32_t i = 0; i < iSize; ++i) {
2129 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002130 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002131 edge.SetMSThickness(thickness);
2132 }
2133 } else {
2134 CXFA_Edge edge = border.GetEdge(0);
2135 CXFA_Measurement thickness = edge.GetMSThickness();
2136 thickness.ToString(wsThickness);
dsinclairf27aeec2016-06-07 19:36:18 -07002137 pValue->SetString(FX_UTF8Encode(wsThickness).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002138 }
2139}
dsinclair5b36f0a2016-07-19 10:56:23 -07002140
dsinclair12a6b0c2016-05-26 11:14:08 -07002141void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002142 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002143 XFA_ATTRIBUTE eAttribute) {
2144 CXFA_WidgetData* pWidgetData = GetWidgetData();
2145 if (!pWidgetData) {
2146 return;
2147 }
tsepezd19e9122016-11-02 15:43:18 -07002148 CXFA_Border border = pWidgetData->GetBorder(true);
2149 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002150 CXFA_Node* pNode = borderfill.GetNode();
2151 if (!pNode) {
2152 return;
2153 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002154 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002155 int32_t r;
2156 int32_t g;
2157 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002158 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002159 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2160 borderfill.SetColor(color);
2161 } else {
2162 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002163 int32_t a;
2164 int32_t r;
2165 int32_t g;
2166 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002167 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002168 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002169 wsColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002170 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002171 }
2172}
dsinclair5b36f0a2016-07-19 10:56:23 -07002173
dsinclair12a6b0c2016-05-26 11:14:08 -07002174void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002175 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002176 XFA_ATTRIBUTE eAttribute) {
2177 if (!bSetting) {
2178 CXFA_Node* pDataNode = GetBindData();
2179 if (pDataNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002180 pValue->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002181 m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
2182 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002183 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002184 }
2185 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002186 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002187 }
2188}
dsinclair5b36f0a2016-07-19 10:56:23 -07002189
dsinclair12a6b0c2016-05-26 11:14:08 -07002190void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002191 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002192 XFA_ATTRIBUTE eAttribute) {
2193 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002194 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002195 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002196 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002197 XFA_Element uiType = pWidgetData->GetUIType();
2198 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002199 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002200 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002201 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002202 }
2203 }
2204 } else {
tsepezd19e9122016-11-02 15:43:18 -07002205 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002206 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002207 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002208 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002209 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002210 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002211 }
2212 }
2213}
dsinclair5b36f0a2016-07-19 10:56:23 -07002214
dsinclair12a6b0c2016-05-26 11:14:08 -07002215void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002216 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002217 XFA_ATTRIBUTE eAttribute) {
2218 CXFA_WidgetData* pWidgetData = GetWidgetData();
2219 if (!pWidgetData) {
2220 return;
2221 }
2222 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002223 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002224 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002225 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002226 } else {
2227 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002228 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002229 }
dsinclair2f5582f2016-06-09 11:48:23 -07002230 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002231 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002232 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002233
Dan Sinclair1770c022016-03-14 14:14:16 -04002234 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002235 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002236 int32_t iLeadDigits = 0;
2237 int32_t iFracDigits = 0;
2238 pWidgetData->GetLeadDigits(iLeadDigits);
2239 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002240 wsNewText =
2241 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002242 }
2243 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2244 CFX_WideString wsFormatText(wsNewText);
2245 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002246 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002247 }
tsepezd19e9122016-11-02 15:43:18 -07002248 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002249 } else {
tsepezd19e9122016-11-02 15:43:18 -07002250 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002251 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002252 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002253 } else {
2254 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002255 CXFA_Value defVal = pWidgetData->GetFormValue();
2256 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002257 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002258 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002259 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002260 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002261 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002262 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002263 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002264 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002265 }
dsinclair070fcdf2016-06-22 22:04:54 -07002266 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002267 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002268 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002269 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002270 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002271 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002272 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002273 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002274 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002275 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002276 }
2277 }
2278 }
2279}
dsinclair5b36f0a2016-07-19 10:56:23 -07002280
dsinclair12a6b0c2016-05-26 11:14:08 -07002281void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002282 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002283 XFA_ATTRIBUTE eAttribute) {
2284 CXFA_WidgetData* pWidgetData = GetWidgetData();
2285 if (!pWidgetData) {
2286 return;
2287 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002288 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002289 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002290 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002291 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002292 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
dsinclairf27aeec2016-06-07 19:36:18 -07002293 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002294 }
2295}
dsinclair5b36f0a2016-07-19 10:56:23 -07002296
dsinclair12a6b0c2016-05-26 11:14:08 -07002297void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002298 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002299 XFA_ATTRIBUTE eAttribute) {
2300 CXFA_WidgetData* pWidgetData = GetWidgetData();
2301 if (!pWidgetData) {
2302 return;
2303 }
tsepezd19e9122016-11-02 15:43:18 -07002304 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002305 CXFA_Node* pNode = font.GetNode();
2306 if (!pNode) {
2307 return;
2308 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002309 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002310 int32_t r;
2311 int32_t g;
2312 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002313 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002314 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2315 font.SetColor(color);
2316 } else {
2317 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002318 int32_t a;
2319 int32_t r;
2320 int32_t g;
2321 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002322 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002323 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002324 wsColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002325 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002326 }
2327}
dsinclair5b36f0a2016-07-19 10:56:23 -07002328
dsinclair12a6b0c2016-05-26 11:14:08 -07002329void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002330 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002331 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002332 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002333}
dsinclair5b36f0a2016-07-19 10:56:23 -07002334
dsinclair12a6b0c2016-05-26 11:14:08 -07002335void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002336 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002337 XFA_ATTRIBUTE eAttribute) {
2338 CXFA_WidgetData* pWidgetData = GetWidgetData();
2339 if (!pWidgetData) {
2340 return;
2341 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002342 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002343 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002344 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002345 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002346 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
dsinclairf27aeec2016-06-07 19:36:18 -07002347 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002348 }
2349}
dsinclair5b36f0a2016-07-19 10:56:23 -07002350
dsinclair12a6b0c2016-05-26 11:14:08 -07002351void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002352 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002353 XFA_ATTRIBUTE eAttribute) {
2354 CXFA_WidgetData* pWidgetData = GetWidgetData();
2355 if (!pWidgetData) {
2356 return;
2357 }
tsepezd19e9122016-11-02 15:43:18 -07002358 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002359 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002360 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002361 } else {
2362 int32_t iValue = validate.GetNullTest();
2363 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002364 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002365 CFX_WideString wsValue;
2366 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002367 wsValue = pInfo->pName;
dsinclairf27aeec2016-06-07 19:36:18 -07002368 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002369 }
2370}
dsinclair5b36f0a2016-07-19 10:56:23 -07002371
dsinclair12a6b0c2016-05-26 11:14:08 -07002372void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002373 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002374 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002375 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002376}
dsinclair5b36f0a2016-07-19 10:56:23 -07002377
dsinclair12a6b0c2016-05-26 11:14:08 -07002378void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002379 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002380 XFA_ATTRIBUTE eAttribute) {
2381 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07002382 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002383 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002384 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002385 }
2386}
dsinclair5b36f0a2016-07-19 10:56:23 -07002387
dsinclair12a6b0c2016-05-26 11:14:08 -07002388void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002389 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002390 XFA_ATTRIBUTE eAttribute) {
2391 CXFA_WidgetData* pWidgetData = GetWidgetData();
2392 if (!pWidgetData) {
2393 return;
2394 }
2395 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002396 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002397 if (iIndex == -1) {
2398 pWidgetData->ClearAllSelections();
2399 return;
2400 }
tsepezd19e9122016-11-02 15:43:18 -07002401 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002402 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002403 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002404 }
2405}
dsinclair5b36f0a2016-07-19 10:56:23 -07002406
Dan Sinclair1770c022016-03-14 14:14:16 -04002407void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2408 CXFA_WidgetData* pWidgetData = GetWidgetData();
2409 if (!pWidgetData) {
2410 return;
2411 }
tsepezd19e9122016-11-02 15:43:18 -07002412 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002413}
dsinclair5b36f0a2016-07-19 10:56:23 -07002414
Dan Sinclair1770c022016-03-14 14:14:16 -04002415void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
2416 int32_t argc = pArguments->GetLength();
2417 if (argc == 1) {
2418 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2419 int32_t iRet = execSingleEventByName(
tsepez4c3debb2016-04-08 12:20:38 -07002420 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
dsinclair56a8b192016-06-21 14:15:25 -07002421 XFA_Element::Field);
Dan Sinclair1770c022016-03-14 14:14:16 -04002422 if (eventString == "validate") {
dsinclairf27aeec2016-06-07 19:36:18 -07002423 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07002424 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002425 }
2426 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002427 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
Dan Sinclair1770c022016-03-14 14:14:16 -04002428 }
2429}
dsinclair5b36f0a2016-07-19 10:56:23 -07002430
Dan Sinclair1770c022016-03-14 14:14:16 -04002431void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
2432 int32_t argc = pArguments->GetLength();
2433 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002434 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002435 if (!pNotify) {
2436 return;
2437 }
tsepezd19e9122016-11-02 15:43:18 -07002438 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002439 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002440 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002441 }
2442}
dsinclair5b36f0a2016-07-19 10:56:23 -07002443
Dan Sinclair1770c022016-03-14 14:14:16 -04002444void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2445 int32_t iLength = pArguments->GetLength();
2446 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002447 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002448 return;
2449 }
2450 CXFA_WidgetData* pWidgetData = GetWidgetData();
2451 if (!pWidgetData) {
2452 return;
2453 }
2454 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002455 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002456 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002457 if (pValue)
2458 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002459}
dsinclair5b36f0a2016-07-19 10:56:23 -07002460
Dan Sinclair1770c022016-03-14 14:14:16 -04002461void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2462 int32_t iLength = pArguments->GetLength();
2463 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002464 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002465 return;
2466 }
2467 int32_t iIndex = pArguments->GetInt32(0);
2468 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002469 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002470 return;
2471 }
2472 CXFA_WidgetData* pWidgetData = GetWidgetData();
2473 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002474 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002475 return;
2476 }
2477 CFX_WideString wsValue;
tsepezd19e9122016-11-02 15:43:18 -07002478 bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002479 if (bHasItem) {
dsinclairf27aeec2016-06-07 19:36:18 -07002480 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002481 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002482 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002483 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002484 }
2485}
dsinclair5b36f0a2016-07-19 10:56:23 -07002486
Dan Sinclair1770c022016-03-14 14:14:16 -04002487void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2488 int32_t iLength = pArguments->GetLength();
2489 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002490 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002491 return;
2492 }
2493 CXFA_WidgetData* pWidgetData = GetWidgetData();
2494 if (!pWidgetData) {
2495 return;
2496 }
2497 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002498 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002499 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002500 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002501 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002502 if (pValue)
2503 pValue->SetString(FX_UTF8Encode(wsBoundValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002504}
dsinclair5b36f0a2016-07-19 10:56:23 -07002505
Dan Sinclair1770c022016-03-14 14:14:16 -04002506void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2507 int32_t iLength = pArguments->GetLength();
2508 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002509 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002510 return;
2511 }
2512 CXFA_WidgetData* pWidgetData = GetWidgetData();
2513 if (!pWidgetData) {
2514 return;
2515 }
2516 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002517 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002518 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002519 if (pValue)
2520 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002521}
dsinclair5b36f0a2016-07-19 10:56:23 -07002522
Dan Sinclair1770c022016-03-14 14:14:16 -04002523void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
2524 int32_t argc = pArguments->GetLength();
2525 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002526 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002527 if (!pNotify) {
2528 return;
2529 }
tsepezd19e9122016-11-02 15:43:18 -07002530 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002531 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002532 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002533 }
2534}
dsinclair5b36f0a2016-07-19 10:56:23 -07002535
Dan Sinclair1770c022016-03-14 14:14:16 -04002536void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002537
Dan Sinclair1770c022016-03-14 14:14:16 -04002538void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2539 int32_t iLength = pArguments->GetLength();
2540 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002541 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002542 return;
2543 }
2544 int32_t iIndex = pArguments->GetInt32(0);
2545 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002546 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002547 return;
2548 }
2549 CXFA_WidgetData* pWidgetData = GetWidgetData();
2550 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002551 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002552 return;
2553 }
2554 CFX_WideString wsValue;
tsepezd19e9122016-11-02 15:43:18 -07002555 bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002556 if (bHasItem) {
dsinclairf27aeec2016-06-07 19:36:18 -07002557 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002558 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002559 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002560 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002561 }
2562}
dsinclair5b36f0a2016-07-19 10:56:23 -07002563
Dan Sinclair1770c022016-03-14 14:14:16 -04002564void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2565 int32_t iLength = pArguments->GetLength();
2566 if (iLength != 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07002567 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002568 return;
2569 }
2570 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002571 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002572 return;
thestig800222e2016-05-26 22:00:29 -07002573
Dan Sinclair1770c022016-03-14 14:14:16 -04002574 int32_t iIndex = pArguments->GetInt32(0);
2575 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002576 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002577 } else {
thestig800222e2016-05-26 22:00:29 -07002578 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002579 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002580 }
2581}
dsinclair5b36f0a2016-07-19 10:56:23 -07002582
Dan Sinclair1770c022016-03-14 14:14:16 -04002583void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2584 int32_t iLength = pArguments->GetLength();
2585 if (iLength < 1 || iLength > 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07002586 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002587 return;
2588 }
2589 CXFA_WidgetData* pWidgetData = GetWidgetData();
2590 if (!pWidgetData) {
2591 return;
2592 }
2593 CFX_WideString wsLabel;
2594 CFX_WideString wsValue;
2595 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002596 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002597 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002598 }
2599 if (iLength >= 2) {
2600 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002601 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002602 }
tsepezd19e9122016-11-02 15:43:18 -07002603 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002604}
dsinclair5b36f0a2016-07-19 10:56:23 -07002605
Dan Sinclair1770c022016-03-14 14:14:16 -04002606void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
2607 int32_t argc = pArguments->GetLength();
2608 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002609 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002610 if (!pNotify) {
tsepezd19e9122016-11-02 15:43:18 -07002611 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002612 } else {
2613 int32_t iRet =
tsepezd19e9122016-11-02 15:43:18 -07002614 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
dsinclairf27aeec2016-06-07 19:36:18 -07002615 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07002616 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002617 }
2618 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002619 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002620 }
2621}
dsinclair5b36f0a2016-07-19 10:56:23 -07002622
dsinclair12a6b0c2016-05-26 11:14:08 -07002623void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002624 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002625 XFA_ATTRIBUTE eAttribute) {
2626 if (!bSetting) {
2627 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002628 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002629 }
2630}
dsinclair5b36f0a2016-07-19 10:56:23 -07002631
dsinclair12a6b0c2016-05-26 11:14:08 -07002632void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002633 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002634 XFA_ATTRIBUTE eAttribute) {
2635 CXFA_WidgetData* pWidgetData = GetWidgetData();
2636 if (!pWidgetData) {
2637 return;
2638 }
2639 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002640 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002641 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002642 } else {
tsepezd19e9122016-11-02 15:43:18 -07002643 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002644 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2645 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002646 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002647 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002648 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002649 }
2650 }
2651}
dsinclair5b36f0a2016-07-19 10:56:23 -07002652
dsinclair12a6b0c2016-05-26 11:14:08 -07002653void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002654 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002655 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002656
Dan Sinclair1770c022016-03-14 14:14:16 -04002657void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
2658 int32_t argc = pArguments->GetLength();
2659 if (argc == 1) {
2660 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2661 execSingleEventByName(
tsepez4c3debb2016-04-08 12:20:38 -07002662 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
dsinclair56a8b192016-06-21 14:15:25 -07002663 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002664 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002665 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
Dan Sinclair1770c022016-03-14 14:14:16 -04002666 }
2667}
thestig800222e2016-05-26 22:00:29 -07002668
Dan Sinclair1770c022016-03-14 14:14:16 -04002669void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2670 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002671 if (argc < 0 || argc > 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002672 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002673 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002674 }
thestig800222e2016-05-26 22:00:29 -07002675
2676 CXFA_WidgetData* pWidgetData = GetWidgetData();
2677 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002678 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002679 return;
2680 }
2681
2682 CXFA_Node* pReturnNode = nullptr;
2683 if (argc == 0) {
2684 pReturnNode = pWidgetData->GetSelectedMember();
2685 } else {
2686 CFX_ByteString szName;
2687 szName = pArguments->GetUTF8String(0);
2688 pReturnNode = pWidgetData->SetSelectedMember(
2689 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2690 }
2691 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002692 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002693 return;
2694 }
dsinclairf27aeec2016-06-07 19:36:18 -07002695 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002696 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002697}
thestig800222e2016-05-26 22:00:29 -07002698
Dan Sinclair1770c022016-03-14 14:14:16 -04002699void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
2700 int32_t argc = pArguments->GetLength();
2701 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002702 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002703 if (!pNotify) {
2704 return;
2705 }
2706 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
2707 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002708 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002709 }
2710}
dsinclair5b36f0a2016-07-19 10:56:23 -07002711
Dan Sinclair1770c022016-03-14 14:14:16 -04002712void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
2713 int32_t argc = pArguments->GetLength();
2714 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002715 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002716 if (!pNotify) {
2717 return;
2718 }
2719 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
2720 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002721 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002722 }
2723}
dsinclair5b36f0a2016-07-19 10:56:23 -07002724
Dan Sinclair1770c022016-03-14 14:14:16 -04002725void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
2726 int32_t argc = pArguments->GetLength();
2727 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002728 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002729 if (!pNotify) {
tsepezd19e9122016-11-02 15:43:18 -07002730 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002731 } else {
2732 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
dsinclairf27aeec2016-06-07 19:36:18 -07002733 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07002734 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002735 }
2736 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002737 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002738 }
2739}
dsinclair5b36f0a2016-07-19 10:56:23 -07002740
dsinclair12a6b0c2016-05-26 11:14:08 -07002741void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002742 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002743 XFA_ATTRIBUTE eAttribute) {
2744 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002745 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002746 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002747 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002748 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2749 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002750 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002751 pManagerNode = pNode;
2752 break;
2753 }
2754 }
2755 if (pManagerNode) {
2756 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002757 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002758 if (!pNotify) {
2759 return;
2760 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002761 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002762 if (pToInstance &&
2763 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002764 pNotify->RunSubformIndexChange(pToInstance);
2765 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002766 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002767 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002768 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002769 pNotify->RunSubformIndexChange(pFromInstance);
2770 }
2771 }
2772 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002773 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002774 }
2775}
dsinclair5b36f0a2016-07-19 10:56:23 -07002776
dsinclair12a6b0c2016-05-26 11:14:08 -07002777void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002778 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002779 XFA_ATTRIBUTE eAttribute) {
2780 if (!bSetting) {
2781 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
weili44f8faf2016-06-01 14:03:56 -07002782 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002783 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2784 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002785 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002786 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2787 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2788 wsInstMgrName.Mid(1) == wsName) {
2789 pInstanceMgr = pNode;
2790 }
2791 break;
2792 }
2793 }
2794 if (pInstanceMgr) {
dsinclairf27aeec2016-06-07 19:36:18 -07002795 pValue->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002796 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
2797 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002798 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002799 }
2800 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002801 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002802 }
2803}
dsinclair5b36f0a2016-07-19 10:56:23 -07002804
dsinclair12a6b0c2016-05-26 11:14:08 -07002805void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002806 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002807 XFA_ATTRIBUTE eAttribute) {
2808 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002809 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002810 } else {
2811 CFX_WideString wsLocaleName;
2812 GetLocaleName(wsLocaleName);
dsinclairf27aeec2016-06-07 19:36:18 -07002813 pValue->SetString(
2814 FX_UTF8Encode(wsLocaleName.c_str(), wsLocaleName.GetLength())
2815 .AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002816 }
2817}
dsinclair5b36f0a2016-07-19 10:56:23 -07002818
Dan Sinclair1770c022016-03-14 14:14:16 -04002819void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
2820 int32_t argc = pArguments->GetLength();
2821 if (argc == 1) {
2822 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2823 execSingleEventByName(
tsepez4c3debb2016-04-08 12:20:38 -07002824 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
dsinclair56a8b192016-06-21 14:15:25 -07002825 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002826 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002827 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
Dan Sinclair1770c022016-03-14 14:14:16 -04002828 }
2829}
dsinclair5b36f0a2016-07-19 10:56:23 -07002830
Dan Sinclair1770c022016-03-14 14:14:16 -04002831void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
2832 int32_t argc = pArguments->GetLength();
2833 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002834 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002835 if (!pNotify) {
2836 return;
2837 }
2838 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
2839 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002840 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002841 }
2842}
dsinclair5b36f0a2016-07-19 10:56:23 -07002843
Dan Sinclair1770c022016-03-14 14:14:16 -04002844void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
2845 int32_t argc = pArguments->GetLength();
2846 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002847 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002848 if (!pNotify) {
2849 return;
2850 }
2851 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
2852 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002853 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002854 }
2855}
dsinclair5b36f0a2016-07-19 10:56:23 -07002856
Dan Sinclair1770c022016-03-14 14:14:16 -04002857void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
2858 int32_t argc = pArguments->GetLength();
2859 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002860 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002861 if (!pNotify) {
tsepezd19e9122016-11-02 15:43:18 -07002862 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002863 } else {
2864 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
dsinclairf27aeec2016-06-07 19:36:18 -07002865 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07002866 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002867 }
2868 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002869 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002870 }
2871}
dsinclair5b36f0a2016-07-19 10:56:23 -07002872
Dan Sinclair1770c022016-03-14 14:14:16 -04002873void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
2874 int32_t argc = pArguments->GetLength();
2875 if (argc == 0) {
2876 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002877 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002878 }
2879}
dsinclair5b36f0a2016-07-19 10:56:23 -07002880
Dan Sinclair1770c022016-03-14 14:14:16 -04002881int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2882 int32_t index = 0;
2883 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2884 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002885 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2886 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002887 index++;
2888 } else {
2889 break;
2890 }
2891 }
2892 return index;
2893}
dsinclair5b36f0a2016-07-19 10:56:23 -07002894
Dan Sinclair1770c022016-03-14 14:14:16 -04002895void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
2896 int32_t argc = pArguments->GetLength();
2897 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07002898 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002899 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002900 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04002901 }
2902}
dsinclair5b36f0a2016-07-19 10:56:23 -07002903
Dan Sinclair1770c022016-03-14 14:14:16 -04002904void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
2905 int32_t argc = pArguments->GetLength();
2906 if (argc == 0) {
tsepezd19e9122016-11-02 15:43:18 -07002907 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002908 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002909 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge");
Dan Sinclair1770c022016-03-14 14:14:16 -04002910 }
2911}
dsinclair5b36f0a2016-07-19 10:56:23 -07002912
Dan Sinclair1770c022016-03-14 14:14:16 -04002913void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
2914 int32_t argc = pArguments->GetLength();
2915 if (argc == 0) {
2916 CXFA_WidgetData* pWidgetData = GetWidgetData();
2917 if (!pWidgetData) {
tsepezd19e9122016-11-02 15:43:18 -07002918 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002919 } else {
tsepezd19e9122016-11-02 15:43:18 -07002920 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002921 }
2922 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002923 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002924 }
2925}
dsinclair5b36f0a2016-07-19 10:56:23 -07002926
Dan Sinclair1770c022016-03-14 14:14:16 -04002927void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2928 int32_t argc = pArguments->GetLength();
2929 if ((argc > 0) && (argc < 4)) {
2930 CFX_WideString strTagName;
2931 CFX_WideString strName;
2932 CFX_WideString strNameSpace;
2933 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002934 strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002935 if (argc > 1) {
2936 CFX_ByteString bsName = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002937 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002938 if (argc == 3) {
2939 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
tsepez4c3debb2016-04-08 12:20:38 -07002940 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002941 }
2942 }
dsinclair6e124782016-06-23 12:14:55 -07002943 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2944 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
Dan Sinclair1770c022016-03-14 14:14:16 -04002945 if (!pNewNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002946 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002947 } else {
2948 if (!strName.IsEmpty()) {
dsinclair9eb0db12016-07-21 12:01:39 -07002949 if (GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2950 XFA_XDPPACKET_UNKNOWN)) {
thestigb1a59592016-04-14 18:29:56 -07002951 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002952 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) {
2953 pNewNode->CreateXMLMappingNode();
2954 }
dsinclairf27aeec2016-06-07 19:36:18 -07002955 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002956 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2957 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002958 ThrowException(XFA_IDS_NOT_HAVE_PROPERTY, strTagName.c_str(),
2959 L"name");
Dan Sinclair1770c022016-03-14 14:14:16 -04002960 }
2961 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002962 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002963 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2964 }
2965 }
2966 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002967 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"createNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04002968 }
2969}
dsinclair5b36f0a2016-07-19 10:56:23 -07002970
Dan Sinclair1770c022016-03-14 14:14:16 -04002971void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
2972 if (pArguments->GetLength() == 1) {
tsepezd19e9122016-11-02 15:43:18 -07002973 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002974 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002975 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002976 }
2977}
dsinclair5b36f0a2016-07-19 10:56:23 -07002978
Dan Sinclair1770c022016-03-14 14:14:16 -04002979void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
2980 int32_t argc = pArguments->GetLength();
2981 if (argc == 0) {
2982 CXFA_WidgetData* pWidgetData = GetWidgetData();
2983 if (!pWidgetData) {
tsepezd19e9122016-11-02 15:43:18 -07002984 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002985 } else {
tsepezd19e9122016-11-02 15:43:18 -07002986 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002987 }
2988 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002989 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002990 }
2991}
dsinclair5b36f0a2016-07-19 10:56:23 -07002992
Dan Sinclair1770c022016-03-14 14:14:16 -04002993void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
2994 int32_t argc = pArguments->GetLength();
2995 if (argc == 0) {
2996 CXFA_WidgetData* pWidgetData = GetWidgetData();
2997 if (!pWidgetData) {
tsepezd19e9122016-11-02 15:43:18 -07002998 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002999 } else {
tsepezd19e9122016-11-02 15:43:18 -07003000 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003001 }
3002 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003003 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003004 }
3005}
dsinclair5b36f0a2016-07-19 10:56:23 -07003006
Dan Sinclair1770c022016-03-14 14:14:16 -04003007void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
3008 int32_t argc = pArguments->GetLength();
3009 if (argc == 0) {
3010 CXFA_WidgetData* pWidgetData = GetWidgetData();
3011 if (!pWidgetData) {
tsepezd19e9122016-11-02 15:43:18 -07003012 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003013 } else {
tsepezd19e9122016-11-02 15:43:18 -07003014 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003015 }
3016 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003017 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"evaluate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003018 }
3019}
dsinclair5b36f0a2016-07-19 10:56:23 -07003020
dsinclair12a6b0c2016-05-26 11:14:08 -07003021void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003022 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003023 XFA_ATTRIBUTE eAttribute) {
3024 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07003025 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04003026 return;
3027 }
3028 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003029 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003030}
dsinclair5b36f0a2016-07-19 10:56:23 -07003031
dsinclair12a6b0c2016-05-26 11:14:08 -07003032void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003033 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003034 XFA_ATTRIBUTE eAttribute) {
3035 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07003036 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04003037 return;
3038 }
3039 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003040 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003041}
tsepezaadedf92016-05-12 10:08:06 -07003042
dsinclair12a6b0c2016-05-26 11:14:08 -07003043void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003044 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003045 XFA_ATTRIBUTE eAttribute) {
3046 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003047 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003048 InstanceManager_SetInstances(iDesired);
3049 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07003050 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04003051 }
3052}
dsinclair5b36f0a2016-07-19 10:56:23 -07003053
Dan Sinclair1770c022016-03-14 14:14:16 -04003054void CXFA_Node::Script_InstanceManager_MoveInstance(
3055 CFXJSE_Arguments* pArguments) {
3056 int32_t argc = pArguments->GetLength();
3057 if (argc != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003058 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003059 return;
3060 }
3061 int32_t iFrom = pArguments->GetInt32(0);
3062 int32_t iTo = pArguments->GetInt32(1);
3063 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003064 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003065 if (!pNotify) {
3066 return;
3067 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003068 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003069 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003070 pNotify->RunSubformIndexChange(pToInstance);
3071 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003072 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003073 if (pFromInstance &&
3074 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003075 pNotify->RunSubformIndexChange(pFromInstance);
3076 }
3077}
dsinclair5b36f0a2016-07-19 10:56:23 -07003078
Dan Sinclair1770c022016-03-14 14:14:16 -04003079void CXFA_Node::Script_InstanceManager_RemoveInstance(
3080 CFXJSE_Arguments* pArguments) {
3081 int32_t argc = pArguments->GetLength();
3082 if (argc != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003083 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003084 return;
3085 }
3086 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003087 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003088 if (iIndex < 0 || iIndex >= iCount) {
dsinclair2235b7b2016-06-02 07:42:25 -07003089 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
Dan Sinclair1770c022016-03-14 14:14:16 -04003090 return;
3091 }
3092 CXFA_Occur nodeOccur(GetOccurNode());
3093 int32_t iMin = nodeOccur.GetMin();
3094 if (iCount - 1 < iMin) {
dsinclair2235b7b2016-06-02 07:42:25 -07003095 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003096 return;
3097 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003098 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3099 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003100 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003101 if (pNotify) {
3102 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003103 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003104 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003105 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003106 pNotify->RunSubformIndexChange(pSubformInstance);
3107 }
3108 }
3109 }
3110 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3111 if (!pLayoutPro) {
3112 return;
3113 }
3114 pLayoutPro->AddChangedContainer(
3115 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3116}
dsinclair5b36f0a2016-07-19 10:56:23 -07003117
Dan Sinclair1770c022016-03-14 14:14:16 -04003118void CXFA_Node::Script_InstanceManager_SetInstances(
3119 CFXJSE_Arguments* pArguments) {
3120 int32_t argc = pArguments->GetLength();
3121 if (argc != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003122 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003123 return;
3124 }
3125 int32_t iDesired = pArguments->GetInt32(0);
3126 InstanceManager_SetInstances(iDesired);
3127}
dsinclair5b36f0a2016-07-19 10:56:23 -07003128
Dan Sinclair1770c022016-03-14 14:14:16 -04003129void CXFA_Node::Script_InstanceManager_AddInstance(
3130 CFXJSE_Arguments* pArguments) {
3131 int32_t argc = pArguments->GetLength();
3132 if ((argc != 0) && (argc != 1)) {
dsinclair2235b7b2016-06-02 07:42:25 -07003133 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003134 return;
3135 }
tsepezd19e9122016-11-02 15:43:18 -07003136 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003137 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003138 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003139 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003140 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003141 CXFA_Occur nodeOccur(GetOccurNode());
3142 int32_t iMax = nodeOccur.GetMax();
3143 if (iMax >= 0 && iCount >= iMax) {
dsinclair2235b7b2016-06-02 07:42:25 -07003144 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003145 return;
3146 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003147 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003148 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003149 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003150 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003151 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003152 if (!pNotify) {
3153 return;
3154 }
3155 pNotify->RunNodeInitialize(pNewInstance);
3156 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3157 if (!pLayoutPro) {
3158 return;
3159 }
3160 pLayoutPro->AddChangedContainer(
3161 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3162}
dsinclair5b36f0a2016-07-19 10:56:23 -07003163
Dan Sinclair1770c022016-03-14 14:14:16 -04003164void CXFA_Node::Script_InstanceManager_InsertInstance(
3165 CFXJSE_Arguments* pArguments) {
3166 int32_t argc = pArguments->GetLength();
3167 if ((argc != 1) && (argc != 2)) {
dsinclair2235b7b2016-06-02 07:42:25 -07003168 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003169 return;
3170 }
3171 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003172 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003173 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003174 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003175 }
3176 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003177 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003178 if (iIndex < 0 || iIndex > iCount) {
dsinclair2235b7b2016-06-02 07:42:25 -07003179 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
Dan Sinclair1770c022016-03-14 14:14:16 -04003180 return;
3181 }
3182 int32_t iMax = nodeOccur.GetMax();
3183 if (iMax >= 0 && iCount >= iMax) {
dsinclair2235b7b2016-06-02 07:42:25 -07003184 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003185 return;
3186 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003187 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003188 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003189 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003190 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003191 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003192 if (!pNotify) {
3193 return;
3194 }
3195 pNotify->RunNodeInitialize(pNewInstance);
3196 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3197 if (!pLayoutPro) {
3198 return;
3199 }
3200 pLayoutPro->AddChangedContainer(
3201 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3202}
dsinclair5b36f0a2016-07-19 10:56:23 -07003203
Dan Sinclair1770c022016-03-14 14:14:16 -04003204int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3205 CXFA_Occur nodeOccur(GetOccurNode());
3206 int32_t iMax = nodeOccur.GetMax();
3207 int32_t iMin = nodeOccur.GetMin();
3208 if (iDesired < iMin) {
dsinclair2235b7b2016-06-02 07:42:25 -07003209 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003210 return 1;
3211 }
3212 if ((iMax >= 0) && (iDesired > iMax)) {
dsinclair2235b7b2016-06-02 07:42:25 -07003213 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003214 return 2;
3215 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003216 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003217 if (iDesired == iCount) {
3218 return 0;
3219 }
3220 if (iDesired < iCount) {
3221 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003222 CFX_WideString wsInstanceName =
3223 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3224 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003225 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003226 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003227 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003228 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003229 while (iCount > iDesired) {
3230 CXFA_Node* pRemoveInstance =
3231 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003232 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3233 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003234 continue;
3235 }
dsinclair070fcdf2016-06-22 22:04:54 -07003236 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003237 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003238 break;
3239 }
3240 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003241 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003242 iCount--;
3243 }
3244 }
3245 } else if (iDesired > iCount) {
3246 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003247 CXFA_Node* pNewInstance = CreateInstance(this, true);
3248 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003249 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003250 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003251 if (!pNotify) {
3252 return 0;
3253 }
3254 pNotify->RunNodeInitialize(pNewInstance);
3255 }
3256 }
3257 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3258 if (pLayoutPro) {
3259 pLayoutPro->AddChangedContainer(
3260 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3261 }
3262 return 0;
3263}
dsinclair5b36f0a2016-07-19 10:56:23 -07003264
Dan Sinclair1770c022016-03-14 14:14:16 -04003265int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003266 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003267 if (iFrom > iCount || iTo > iCount - 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07003268 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
Dan Sinclair1770c022016-03-14 14:14:16 -04003269 return 1;
3270 }
3271 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3272 return 0;
3273 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003274 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003275 RemoveItem(this, pMoveInstance, false);
3276 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003277 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3278 if (pLayoutPro) {
3279 pLayoutPro->AddChangedContainer(
3280 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3281 }
3282 return 0;
3283}
dsinclair5b36f0a2016-07-19 10:56:23 -07003284
dsinclair12a6b0c2016-05-26 11:14:08 -07003285void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003286 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003287 XFA_ATTRIBUTE eAttribute) {
3288 CXFA_Occur occur(this);
3289 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003290 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003291 occur.SetMax(iMax);
3292 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003293 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003294 }
3295}
dsinclair5b36f0a2016-07-19 10:56:23 -07003296
dsinclair12a6b0c2016-05-26 11:14:08 -07003297void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003298 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003299 XFA_ATTRIBUTE eAttribute) {
3300 CXFA_Occur occur(this);
3301 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003302 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003303 occur.SetMin(iMin);
3304 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003305 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003306 }
3307}
dsinclair5b36f0a2016-07-19 10:56:23 -07003308
Dan Sinclair1770c022016-03-14 14:14:16 -04003309void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3310 int32_t argc = pArguments->GetLength();
3311 if ((argc == 0) || (argc == 1)) {
dsinclairf27aeec2016-06-07 19:36:18 -07003312 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003313 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003314 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"metadata");
Dan Sinclair1770c022016-03-14 14:14:16 -04003315 }
3316}
dsinclair5b36f0a2016-07-19 10:56:23 -07003317
Dan Sinclair1770c022016-03-14 14:14:16 -04003318void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
3319 int32_t argc = pArguments->GetLength();
3320 if (argc == 1) {
3321 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3322 if (pDataNode) {
3323 CXFA_NodeArray formItems;
3324 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3325 pFormNodes->SetArrayNodeList(formItems);
dsinclairf27aeec2016-06-07 19:36:18 -07003326 pArguments->GetReturnValue()->SetObject(
3327 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003328 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003329 ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
Dan Sinclair1770c022016-03-14 14:14:16 -04003330 }
3331 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003332 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04003333 }
3334}
dsinclair5b36f0a2016-07-19 10:56:23 -07003335
Dan Sinclair1770c022016-03-14 14:14:16 -04003336void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
3337 int32_t argc = pArguments->GetLength();
3338 if (argc == 0) {
tsepezd19e9122016-11-02 15:43:18 -07003339 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003340 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003341 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge");
Dan Sinclair1770c022016-03-14 14:14:16 -04003342 }
3343}
dsinclair5b36f0a2016-07-19 10:56:23 -07003344
Dan Sinclair1770c022016-03-14 14:14:16 -04003345void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
3346 int32_t argc = pArguments->GetLength();
3347 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07003348 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003349 if (!pNotify) {
3350 return;
3351 }
3352 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
3353 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003354 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04003355 }
3356}
dsinclair5b36f0a2016-07-19 10:56:23 -07003357
Dan Sinclair1770c022016-03-14 14:14:16 -04003358void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3359 CXFA_EventParam* pEventParam =
3360 m_pDocument->GetScriptContext()->GetEventParam();
3361 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3362 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3363 return;
3364 }
3365 int32_t argc = pArguments->GetLength();
3366 if (argc == 1) {
3367 const bool bScriptFlags = pArguments->GetInt32(0) != 0;
dsinclaira1b07722016-07-11 08:20:58 -07003368 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003369 if (!pNotify) {
3370 return;
3371 }
3372 if (bScriptFlags) {
3373 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3374 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
tsepezd19e9122016-11-02 15:43:18 -07003375 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003376 } else {
3377 }
3378 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003379 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003380 }
3381}
dsinclair5b36f0a2016-07-19 10:56:23 -07003382
Dan Sinclair1770c022016-03-14 14:14:16 -04003383void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
3384 int32_t argc = pArguments->GetLength();
3385 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07003386 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003387 if (!pNotify) {
3388 return;
3389 }
3390 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3391 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003392 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003393 }
3394}
dsinclair5b36f0a2016-07-19 10:56:23 -07003395
Dan Sinclair1770c022016-03-14 14:14:16 -04003396void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
3397 int32_t argc = pArguments->GetLength();
3398 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07003399 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003400 if (!pNotify) {
tsepezd19e9122016-11-02 15:43:18 -07003401 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003402 } else {
3403 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
dsinclairf27aeec2016-06-07 19:36:18 -07003404 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07003405 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003406 }
3407 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003408 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003409 }
3410}
dsinclair5b36f0a2016-07-19 10:56:23 -07003411
dsinclair12a6b0c2016-05-26 11:14:08 -07003412void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003413 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003414 XFA_ATTRIBUTE eAttribute) {
3415 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003416 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003417 } else {
3418 CFX_WideString wsChecksum;
tsepezd19e9122016-11-02 15:43:18 -07003419 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003420 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003421 FX_UTF8Encode(wsChecksum.c_str(), wsChecksum.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003422 }
3423}
dsinclair5b36f0a2016-07-19 10:56:23 -07003424
Dan Sinclair1770c022016-03-14 14:14:16 -04003425void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
3426 int32_t argc = pArguments->GetLength();
3427 if (argc == 1) {
3428 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3429 CFX_WideString wsAttributeValue;
dsinclairae95f762016-03-29 16:58:29 -07003430 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003431 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
tsepezbd9748d2016-04-13 21:40:19 -07003432 static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3433 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(),
3434 wsAttributeValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003435 }
dsinclairf27aeec2016-06-07 19:36:18 -07003436 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003437 FX_UTF8Encode(wsAttributeValue.c_str(), wsAttributeValue.GetLength())
tsepez4c3debb2016-04-08 12:20:38 -07003438 .AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003439 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003440 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04003441 }
3442}
dsinclair5b36f0a2016-07-19 10:56:23 -07003443
Dan Sinclair1770c022016-03-14 14:14:16 -04003444void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
3445 int32_t argc = pArguments->GetLength();
3446 if (argc == 2) {
3447 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3448 CFX_ByteString bsName = pArguments->GetUTF8String(1);
dsinclairae95f762016-03-29 16:58:29 -07003449 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003450 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003451 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(
3452 CFX_WideString::FromUTF8(bsName.AsStringC()),
3453 CFX_WideString::FromUTF8(bsValue.AsStringC()));
Dan Sinclair1770c022016-03-14 14:14:16 -04003454 }
dsinclairf27aeec2016-06-07 19:36:18 -07003455 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003456 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003457 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04003458 }
3459}
dsinclair5b36f0a2016-07-19 10:56:23 -07003460
Dan Sinclair1770c022016-03-14 14:14:16 -04003461void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
3462 int32_t argc = pArguments->GetLength();
3463 if (argc == 1) {
3464 CFX_ByteString bsName = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07003465 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
dsinclairae95f762016-03-29 16:58:29 -07003466 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003467 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003468 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
tsepezbd9748d2016-04-13 21:40:19 -07003469 if (pXMLElement->HasAttribute(wsName.c_str())) {
3470 pXMLElement->RemoveAttribute(wsName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04003471 }
3472 }
dsinclairf27aeec2016-06-07 19:36:18 -07003473 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003474 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003475 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"removeAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04003476 }
3477}
dsinclair5b36f0a2016-07-19 10:56:23 -07003478
dsinclair12a6b0c2016-05-26 11:14:08 -07003479void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003480 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003481 XFA_ATTRIBUTE eAttribute) {
3482 if (bSetting) {
dsinclairae95f762016-03-29 16:58:29 -07003483 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003484 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003485 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003486 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003487 }
3488 } else {
3489 CFX_WideString wsTextData;
dsinclairae95f762016-03-29 16:58:29 -07003490 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003491 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003492 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04003493 pXMLElement->GetTextData(wsTextData);
3494 }
dsinclairf27aeec2016-06-07 19:36:18 -07003495 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003496 FX_UTF8Encode(wsTextData.c_str(), wsTextData.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003497 }
3498}
dsinclair5b36f0a2016-07-19 10:56:23 -07003499
Dan Sinclair1770c022016-03-14 14:14:16 -04003500void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
3501 int32_t argc = pArguments->GetLength();
3502 if (argc == 0) {
3503 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003504 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003505 }
3506}
dsinclair5b36f0a2016-07-19 10:56:23 -07003507
Dan Sinclair1770c022016-03-14 14:14:16 -04003508void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
3509 int32_t argc = pArguments->GetLength();
3510 if (argc == 0) {
3511 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003512 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003513 }
3514}
dsinclair5b36f0a2016-07-19 10:56:23 -07003515
Dan Sinclair1770c022016-03-14 14:14:16 -04003516void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
3517 int32_t argc = pArguments->GetLength();
3518 if (argc == 0) {
3519 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003520 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003521 }
3522}
dsinclair5b36f0a2016-07-19 10:56:23 -07003523
Dan Sinclair1770c022016-03-14 14:14:16 -04003524void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
3525 int32_t argc = pArguments->GetLength();
3526 if (argc == 0) {
3527 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003528 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003529 }
3530}
dsinclair5b36f0a2016-07-19 10:56:23 -07003531
Dan Sinclair1770c022016-03-14 14:14:16 -04003532void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
3533 int32_t argc = pArguments->GetLength();
3534 if (argc == 0) {
3535 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003536 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003537 }
3538}
dsinclair5b36f0a2016-07-19 10:56:23 -07003539
Dan Sinclair1770c022016-03-14 14:14:16 -04003540void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
3541 int32_t argc = pArguments->GetLength();
3542 if (argc == 0) {
3543 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003544 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003545 }
3546}
dsinclair5b36f0a2016-07-19 10:56:23 -07003547
Dan Sinclair1770c022016-03-14 14:14:16 -04003548void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
3549 int32_t argc = pArguments->GetLength();
3550 if (argc == 0) {
3551 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003552 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003553 }
3554}
dsinclair5b36f0a2016-07-19 10:56:23 -07003555
Dan Sinclair1770c022016-03-14 14:14:16 -04003556void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
3557 int32_t argc = pArguments->GetLength();
3558 if (argc == 0) {
3559 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003560 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003561 }
3562}
dsinclair5b36f0a2016-07-19 10:56:23 -07003563
Dan Sinclair1770c022016-03-14 14:14:16 -04003564void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
3565 int32_t argc = pArguments->GetLength();
3566 if (argc == 0) {
3567 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003568 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003569 }
3570}
dsinclair5b36f0a2016-07-19 10:56:23 -07003571
Dan Sinclair1770c022016-03-14 14:14:16 -04003572void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
3573 int32_t argc = pArguments->GetLength();
3574 if (argc == 0) {
3575 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003576 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003577 }
3578}
dsinclair5b36f0a2016-07-19 10:56:23 -07003579
Dan Sinclair1770c022016-03-14 14:14:16 -04003580void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
3581 int32_t argc = pArguments->GetLength();
3582 if (argc == 0) {
3583 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003584 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003585 }
3586}
dsinclair5b36f0a2016-07-19 10:56:23 -07003587
Dan Sinclair1770c022016-03-14 14:14:16 -04003588void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
3589 int32_t argc = pArguments->GetLength();
3590 if (argc == 0) {
3591 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003592 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003593 }
3594}
dsinclair5b36f0a2016-07-19 10:56:23 -07003595
Dan Sinclair1770c022016-03-14 14:14:16 -04003596void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
3597 int32_t argc = pArguments->GetLength();
3598 if (argc == 0) {
3599 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003600 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003601 }
3602}
dsinclair5b36f0a2016-07-19 10:56:23 -07003603
Dan Sinclair1770c022016-03-14 14:14:16 -04003604void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
3605 int32_t argc = pArguments->GetLength();
3606 if (argc == 0) {
3607 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003608 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003609 }
3610}
dsinclair5b36f0a2016-07-19 10:56:23 -07003611
Dan Sinclair1770c022016-03-14 14:14:16 -04003612void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
3613 int32_t argc = pArguments->GetLength();
3614 if (argc == 0) {
3615 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003616 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003617 }
3618}
dsinclair5b36f0a2016-07-19 10:56:23 -07003619
Dan Sinclair1770c022016-03-14 14:14:16 -04003620void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
3621 int32_t argc = pArguments->GetLength();
3622 if (argc == 0) {
3623 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003624 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003625 }
3626}
dsinclair5b36f0a2016-07-19 10:56:23 -07003627
Dan Sinclair1770c022016-03-14 14:14:16 -04003628void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
3629 int32_t argc = pArguments->GetLength();
3630 if (argc == 0) {
3631 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003632 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003633 }
3634}
dsinclair5b36f0a2016-07-19 10:56:23 -07003635
dsinclair12a6b0c2016-05-26 11:14:08 -07003636void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003637 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003638 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003639
dsinclair12a6b0c2016-05-26 11:14:08 -07003640void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003641 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003642 XFA_ATTRIBUTE eAttribute) {
3643 if (!bSetting) {
3644 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003645 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003646 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003647 }
3648}
dsinclair5b36f0a2016-07-19 10:56:23 -07003649
dsinclair12a6b0c2016-05-26 11:14:08 -07003650void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003651 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003652 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003653
dsinclair12a6b0c2016-05-26 11:14:08 -07003654void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003655 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003656 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003657
dsinclair12a6b0c2016-05-26 11:14:08 -07003658void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003659 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003660 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003661
dsinclair12a6b0c2016-05-26 11:14:08 -07003662void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003663 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003664 XFA_ATTRIBUTE eAttribute) {
3665 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07003666 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04003667 return;
3668 }
dsinclairf27aeec2016-06-07 19:36:18 -07003669 pValue->SetString(FX_UTF8Encode(FX_WSTRC(L"0")).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003670}
dsinclair5b36f0a2016-07-19 10:56:23 -07003671
dsinclair12a6b0c2016-05-26 11:14:08 -07003672void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003673 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003674 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003675
tsepezd19e9122016-11-02 15:43:18 -07003676bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003677 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003678 return HasMapModuleKey(pKey, bCanInherit);
3679}
dsinclair5b36f0a2016-07-19 10:56:23 -07003680
tsepezd19e9122016-11-02 15:43:18 -07003681bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3682 const CFX_WideStringC& wsValue,
3683 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003684 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003685 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003686 return false;
weili44f8faf2016-06-01 14:03:56 -07003687
Dan Sinclair1770c022016-03-14 14:14:16 -04003688 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3689 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3690 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003691 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003692 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3693 }
3694 switch (eType) {
3695 case XFA_ATTRIBUTETYPE_Enum: {
3696 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3697 return SetEnum(pAttr->eName,
3698 pEnum ? pEnum->eName
3699 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3700 bNotify);
3701 } break;
3702 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003703 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003704 case XFA_ATTRIBUTETYPE_Boolean:
3705 return SetBoolean(pAttr->eName, wsValue != FX_WSTRC(L"0"), bNotify);
3706 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003707 return SetInteger(pAttr->eName,
3708 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3709 wsValue.GetLength(), nullptr)),
3710 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003711 case XFA_ATTRIBUTETYPE_Measure:
3712 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3713 default:
3714 break;
3715 }
tsepezd19e9122016-11-02 15:43:18 -07003716 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003717}
dsinclair5b36f0a2016-07-19 10:56:23 -07003718
tsepezd19e9122016-11-02 15:43:18 -07003719bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3720 CFX_WideString& wsValue,
3721 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003722 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003723 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003724 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003725 }
3726 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3727 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3728 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003729 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003730 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3731 }
3732 switch (eType) {
3733 case XFA_ATTRIBUTETYPE_Enum: {
3734 XFA_ATTRIBUTEENUM eValue;
3735 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003736 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003737 }
dsinclair9eb0db12016-07-21 12:01:39 -07003738 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003739 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003740 } break;
3741 case XFA_ATTRIBUTETYPE_Cdata: {
3742 CFX_WideStringC wsValueC;
3743 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003744 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003745 }
3746 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003747 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003748 } break;
3749 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003750 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003751 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003752 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003753 }
3754 wsValue = bValue ? FX_WSTRC(L"1") : FX_WSTRC(L"0");
tsepezd19e9122016-11-02 15:43:18 -07003755 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003756 } break;
3757 case XFA_ATTRIBUTETYPE_Integer: {
3758 int32_t iValue;
3759 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003760 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003761 }
3762 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003763 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003764 } break;
3765 case XFA_ATTRIBUTETYPE_Measure: {
3766 CXFA_Measurement mValue;
3767 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003768 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003769 }
3770 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003771 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003772 } break;
3773 default:
3774 break;
3775 }
tsepezd19e9122016-11-02 15:43:18 -07003776 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003777}
dsinclair5b36f0a2016-07-19 10:56:23 -07003778
tsepezd19e9122016-11-02 15:43:18 -07003779bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3780 const CFX_WideStringC& wsValue,
3781 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003782 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3783 if (pAttributeInfo) {
3784 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3785 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003786 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003787 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003788 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003789}
dsinclair5b36f0a2016-07-19 10:56:23 -07003790
tsepezd19e9122016-11-02 15:43:18 -07003791bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3792 CFX_WideString& wsValue,
3793 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003794 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3795 if (pAttributeInfo) {
3796 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3797 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003798 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003799 CFX_WideStringC wsValueC;
3800 if (GetMapModuleString(pKey, wsValueC)) {
3801 wsValue = wsValueC;
3802 }
tsepezd19e9122016-11-02 15:43:18 -07003803 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003804}
dsinclair5b36f0a2016-07-19 10:56:23 -07003805
tsepezd19e9122016-11-02 15:43:18 -07003806bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003807 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003808 RemoveMapModuleKey(pKey);
tsepezd19e9122016-11-02 15:43:18 -07003809 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003810}
dsinclair5b36f0a2016-07-19 10:56:23 -07003811
tsepezd19e9122016-11-02 15:43:18 -07003812bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3813 bool& bValue,
3814 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003815 void* pValue = nullptr;
3816 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003817 return false;
tsepez478ed622016-10-27 14:32:33 -07003818 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003819 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003820}
dsinclair5b36f0a2016-07-19 10:56:23 -07003821
tsepezd19e9122016-11-02 15:43:18 -07003822bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3823 int32_t& iValue,
3824 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003825 void* pValue = nullptr;
3826 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003827 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003828 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003829 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003830}
dsinclair5b36f0a2016-07-19 10:56:23 -07003831
tsepezd19e9122016-11-02 15:43:18 -07003832bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3833 XFA_ATTRIBUTEENUM& eValue,
3834 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003835 void* pValue = nullptr;
3836 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003837 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003838 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003839 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003840}
thestigb1a59592016-04-14 18:29:56 -07003841
tsepezd19e9122016-11-02 15:43:18 -07003842bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3843 CXFA_Measurement mValue,
3844 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003845 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003846 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003847 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003848 OnChanged(eAttr, bNotify, false);
3849 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003850}
thestigb1a59592016-04-14 18:29:56 -07003851
tsepezd19e9122016-11-02 15:43:18 -07003852bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3853 CXFA_Measurement& mValue,
3854 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003855 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003856 void* pValue;
3857 int32_t iBytes;
3858 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
3859 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003860 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003861 }
3862 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003863 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003864 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
3865 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003866 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003867 }
tsepezd19e9122016-11-02 15:43:18 -07003868 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003869}
3870
3871CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3872 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003873 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003874}
3875
tsepezd19e9122016-11-02 15:43:18 -07003876bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3877 const CFX_WideString& wsValue,
3878 bool bNotify,
3879 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003880 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003881 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003882 if (eAttr == XFA_ATTRIBUTE_Value) {
3883 CFX_WideString* pClone = new CFX_WideString(wsValue);
3884 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3885 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003886 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003887 if (eAttr == XFA_ATTRIBUTE_Name)
3888 UpdateNameHash();
3889 }
thestigb1a59592016-04-14 18:29:56 -07003890 OnChanged(eAttr, bNotify, bScriptModify);
3891
3892 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3893 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003894 return true;
thestigb1a59592016-04-14 18:29:56 -07003895 }
3896
dsinclair070fcdf2016-06-22 22:04:54 -07003897 if (eAttr == XFA_ATTRIBUTE_Name &&
3898 (m_elementType == XFA_Element::DataValue ||
3899 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003900 return true;
thestigb1a59592016-04-14 18:29:56 -07003901 }
3902
3903 if (eAttr == XFA_ATTRIBUTE_Value) {
3904 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3905 switch (eXMLType) {
3906 case FDE_XMLNODE_Element:
3907 if (IsAttributeInXML()) {
3908 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003909 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3910 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003911 } else {
tsepezd19e9122016-11-02 15:43:18 -07003912 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003913 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3914 for (CXFA_Node* pChildDataNode =
3915 GetNodeItem(XFA_NODEITEM_FirstChild);
3916 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3917 XFA_NODEITEM_NextSibling)) {
3918 CXFA_NodeArray formNodes;
3919 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003920 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003921 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003922 }
3923 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003924 }
thestigb1a59592016-04-14 18:29:56 -07003925 if (bDeleteChildren) {
3926 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3927 }
3928 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3929 }
3930 break;
3931 case FDE_XMLNODE_Text:
3932 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3933 break;
3934 default:
dsinclair43854a52016-04-27 12:26:00 -07003935 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003936 }
tsepezd19e9122016-11-02 15:43:18 -07003937 return true;
thestigb1a59592016-04-14 18:29:56 -07003938 }
3939
3940 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3941 if (pInfo) {
dsinclair43854a52016-04-27 12:26:00 -07003942 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003943 CFX_WideString wsAttrName = pInfo->pName;
3944 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
3945 wsAttrName = FX_WSTRC(L"xfa:") + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003946 }
thestigb1a59592016-04-14 18:29:56 -07003947 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003948 }
tsepezd19e9122016-11-02 15:43:18 -07003949 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003950}
thestigb1a59592016-04-14 18:29:56 -07003951
tsepezd19e9122016-11-02 15:43:18 -07003952bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3953 const CFX_WideString& wsXMLValue,
3954 bool bNotify,
3955 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003956 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003957 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003958 CFX_WideString* pClone = new CFX_WideString(wsValue);
3959 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003960 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003961 if (IsNeedSavingXMLNode()) {
3962 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3963 switch (eXMLType) {
3964 case FDE_XMLNODE_Element:
3965 if (IsAttributeInXML()) {
dsinclairae95f762016-03-29 16:58:29 -07003966 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003967 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3968 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003969 } else {
tsepezd19e9122016-11-02 15:43:18 -07003970 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003971 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3972 for (CXFA_Node* pChildDataNode =
3973 GetNodeItem(XFA_NODEITEM_FirstChild);
3974 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3975 XFA_NODEITEM_NextSibling)) {
3976 CXFA_NodeArray formNodes;
3977 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003978 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003979 break;
3980 }
3981 }
3982 }
3983 if (bDeleteChildren) {
dsinclairae95f762016-03-29 16:58:29 -07003984 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003985 }
dsinclairae95f762016-03-29 16:58:29 -07003986 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003987 }
3988 break;
3989 case FDE_XMLNODE_Text:
dsinclairae95f762016-03-29 16:58:29 -07003990 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003991 break;
3992 default:
dsinclair43854a52016-04-27 12:26:00 -07003993 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003994 }
3995 }
tsepezd19e9122016-11-02 15:43:18 -07003996 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003997}
dsinclair5b36f0a2016-07-19 10:56:23 -07003998
tsepezd19e9122016-11-02 15:43:18 -07003999bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
4000 CFX_WideString& wsValue,
4001 bool bUseDefault,
4002 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004003 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004004 if (eAttr == XFA_ATTRIBUTE_Value) {
4005 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
4006 if (pStr) {
4007 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07004008 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004009 }
4010 } else {
4011 CFX_WideStringC wsValueC;
4012 if (GetMapModuleString(pKey, wsValueC)) {
4013 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07004014 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004015 }
4016 }
4017 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004018 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004019 }
weili44f8faf2016-06-01 14:03:56 -07004020 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07004021 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04004022 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
4023 wsValue = (const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07004024 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004025 }
tsepezd19e9122016-11-02 15:43:18 -07004026 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004027}
dsinclair5b36f0a2016-07-19 10:56:23 -07004028
tsepezd19e9122016-11-02 15:43:18 -07004029bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
4030 CFX_WideStringC& wsValue,
4031 bool bUseDefault,
4032 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004033 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004034 if (eAttr == XFA_ATTRIBUTE_Value) {
4035 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
4036 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07004037 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07004038 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004039 }
4040 } else {
4041 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004042 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004043 }
4044 }
4045 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004046 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004047 }
weili44f8faf2016-06-01 14:03:56 -07004048 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07004049 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04004050 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
4051 wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07004052 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004053 }
tsepezd19e9122016-11-02 15:43:18 -07004054 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004055}
dsinclair5b36f0a2016-07-19 10:56:23 -07004056
tsepezd19e9122016-11-02 15:43:18 -07004057bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
4058 void* pData,
4059 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004060 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004061 return SetUserData(pKey, pData, pCallbackInfo);
4062}
dsinclair5b36f0a2016-07-19 10:56:23 -07004063
tsepezd19e9122016-11-02 15:43:18 -07004064bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004065 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004066 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07004067 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04004068}
dsinclair5b36f0a2016-07-19 10:56:23 -07004069
tsepezd19e9122016-11-02 15:43:18 -07004070bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
4071 XFA_ATTRIBUTETYPE eType,
4072 void* pValue,
4073 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004074 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07004075 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004076 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07004077 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004078 if (IsNeedSavingXMLNode()) {
dsinclair43854a52016-04-27 12:26:00 -07004079 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004080 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
4081 if (pInfo) {
4082 switch (eType) {
4083 case XFA_ATTRIBUTETYPE_Enum:
dsinclairae95f762016-03-29 16:58:29 -07004084 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004085 ->SetString(
4086 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07004087 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04004088 ->pName);
4089 break;
4090 case XFA_ATTRIBUTETYPE_Boolean:
dsinclairae95f762016-03-29 16:58:29 -07004091 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07004092 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04004093 break;
4094 case XFA_ATTRIBUTETYPE_Integer:
dsinclairae95f762016-03-29 16:58:29 -07004095 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004096 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue);
4097 break;
4098 default:
dsinclair43854a52016-04-27 12:26:00 -07004099 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04004100 }
4101 }
4102 }
tsepezd19e9122016-11-02 15:43:18 -07004103 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004104}
dsinclair5b36f0a2016-07-19 10:56:23 -07004105
tsepezd19e9122016-11-02 15:43:18 -07004106bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
4107 XFA_ATTRIBUTETYPE eType,
4108 bool bUseDefault,
4109 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004110 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004111 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004112 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004113 }
4114 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004115 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004116 }
dsinclair070fcdf2016-06-22 22:04:54 -07004117 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004118 m_ePacket);
4119}
dsinclair5b36f0a2016-07-19 10:56:23 -07004120
tsepezd19e9122016-11-02 15:43:18 -07004121bool CXFA_Node::SetUserData(void* pKey,
4122 void* pData,
4123 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004124 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4125 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004126 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004127}
dsinclair5b36f0a2016-07-19 10:56:23 -07004128
tsepezd19e9122016-11-02 15:43:18 -07004129bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004130 int32_t iBytes = 0;
4131 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004132 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004133 }
4134 return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes);
4135}
dsinclair5b36f0a2016-07-19 10:56:23 -07004136
tsepezd19e9122016-11-02 15:43:18 -07004137bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4138 const CFX_WideString& wsXMLValue,
4139 bool bNotify,
4140 bool bScriptModify,
4141 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004142 CXFA_Node* pNode = nullptr;
4143 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004144 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004145 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004146 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004147 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004148 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004149 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004150 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004151 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004152 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004153 CXFA_Node* pBind = GetBindData();
4154 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004155 std::vector<CFX_WideString> wsSaveTextArray;
Dan Sinclair1770c022016-03-14 14:14:16 -04004156 int32_t iSize = 0;
4157 if (!wsContent.IsEmpty()) {
4158 int32_t iStart = 0;
4159 int32_t iLength = wsContent.GetLength();
4160 int32_t iEnd = wsContent.Find(L'\n', iStart);
4161 iEnd = (iEnd == -1) ? iLength : iEnd;
4162 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004163 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004164 iStart = iEnd + 1;
4165 if (iStart >= iLength) {
4166 break;
4167 }
4168 iEnd = wsContent.Find(L'\n', iStart);
4169 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004170 wsSaveTextArray.push_back(
4171 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004172 }
4173 }
tsepez51709be2016-12-08 10:55:57 -08004174 iSize = pdfium::CollectionSize<int32_t>(wsSaveTextArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04004175 }
4176 if (iSize == 0) {
4177 while (CXFA_Node* pChildNode =
4178 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4179 pBind->RemoveChild(pChildNode);
4180 }
4181 } else {
4182 CXFA_NodeArray valueNodes;
4183 int32_t iDatas = pBind->GetNodeList(
dsinclair56a8b192016-06-21 14:15:25 -07004184 valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004185 if (iDatas < iSize) {
4186 int32_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004187 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004188 while (iAddNodes-- > 0) {
4189 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004190 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004191 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004192 pValueNodes->CreateXMLMappingNode();
4193 pBind->InsertChild(pValueNodes);
4194 }
weili44f8faf2016-06-01 14:03:56 -07004195 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004196 } else if (iDatas > iSize) {
4197 int32_t iDelNodes = iDatas - iSize;
4198 while (iDelNodes-- > 0) {
4199 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4200 }
4201 }
4202 int32_t i = 0;
4203 for (CXFA_Node* pValueNode =
4204 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4205 pValueNode; pValueNode = pValueNode->GetNodeItem(
4206 XFA_NODEITEM_NextSibling)) {
4207 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004208 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004209 i++;
4210 }
4211 }
4212 CXFA_NodeArray nodeArray;
4213 pBind->GetBindItems(nodeArray);
4214 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004215 if (nodeArray[i] != this) {
4216 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004217 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004218 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004219 }
4220 }
4221 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004222 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004223 pNode = this;
4224 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004225 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004226 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004227 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004228 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004229 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004230 }
4231 pBindNode = GetBindData();
4232 if (pBindNode && bSyncData) {
4233 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004234 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004235 CXFA_NodeArray nodeArray;
4236 pBindNode->GetBindItems(nodeArray);
4237 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004238 if (nodeArray[i] != this) {
4239 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true,
tsepezd19e9122016-11-02 15:43:18 -07004240 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004241 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004242 }
4243 }
weili44f8faf2016-06-01 14:03:56 -07004244 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004245 break;
4246 }
dsinclairc5a8f212016-06-20 11:11:12 -07004247 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004248 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004249 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004250 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
tsepez9f2970c2016-04-01 10:23:04 -07004251 if (wsContentType == FX_WSTRC(L"text/html")) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004252 wsContentType = FX_WSTRC(L"");
tsepez4c3debb2016-04-08 12:20:38 -07004253 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004254 }
4255 }
4256 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4257 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004258 pContentRawDataNode = CreateSamePacketNode(
dsinclair56a8b192016-06-21 14:15:25 -07004259 (wsContentType == FX_WSTRC(L"text/xml")) ? XFA_Element::Sharpxml
4260 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004261 InsertChild(pContentRawDataNode);
4262 }
4263 return pContentRawDataNode->SetScriptContent(
4264 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4265 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004266 case XFA_ObjectType::NodeC:
4267 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004268 pNode = this;
4269 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004270 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004271 pNode = this;
4272 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4273 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4274 if (pParent) {
4275 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4276 }
dsinclair070fcdf2016-06-22 22:04:54 -07004277 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004278 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4279 if (pParent && pParent->IsContainerNode()) {
4280 pBindNode = pParent->GetBindData();
4281 if (pBindNode) {
4282 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004283 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004284 }
4285 }
4286 }
4287 }
4288 break;
4289 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004290 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004291 pNode = this;
4292 pBindNode = this;
4293 }
4294 break;
4295 }
4296 if (pNode) {
4297 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4298 if (pBindNode && bSyncData) {
4299 CXFA_NodeArray nodeArray;
4300 pBindNode->GetBindItems(nodeArray);
4301 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004302 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004303 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004304 }
4305 }
tsepezd19e9122016-11-02 15:43:18 -07004306 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004307 }
tsepezd19e9122016-11-02 15:43:18 -07004308 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004309}
dsinclair5b36f0a2016-07-19 10:56:23 -07004310
tsepezd19e9122016-11-02 15:43:18 -07004311bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4312 const CFX_WideString& wsXMLValue,
4313 bool bNotify,
4314 bool bScriptModify,
4315 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004316 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4317 bSyncData);
4318}
dsinclair5b36f0a2016-07-19 10:56:23 -07004319
tsepezd19e9122016-11-02 15:43:18 -07004320CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004321 CFX_WideString wsContent;
4322 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4323}
dsinclair5b36f0a2016-07-19 10:56:23 -07004324
Dan Sinclair1770c022016-03-14 14:14:16 -04004325CFX_WideString CXFA_Node::GetContent() {
4326 return GetScriptContent();
4327}
dsinclair5b36f0a2016-07-19 10:56:23 -07004328
tsepezd19e9122016-11-02 15:43:18 -07004329bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4330 bool bScriptModify,
4331 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004332 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004333 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004334 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004335 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004336 pNode = this;
4337 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004338 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004339 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004340 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004341 }
4342 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4343 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
4344 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType,
4345 FX_WSTRC(L"text/xml"));
4346 }
4347 return pChildValue
4348 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004349 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004350 }
4351 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004352 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004353 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4354 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004355 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004356 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004357 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004358 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
tsepez9f2970c2016-04-01 10:23:04 -07004359 if (wsContentType == FX_WSTRC(L"text/html")) {
dsinclair56a8b192016-06-21 14:15:25 -07004360 element = XFA_Element::SharpxHTML;
tsepez9f2970c2016-04-01 10:23:04 -07004361 } else if (wsContentType == FX_WSTRC(L"text/xml")) {
dsinclair56a8b192016-06-21 14:15:25 -07004362 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004363 }
4364 }
4365 pContentRawDataNode = CreateSamePacketNode(element);
4366 InsertChild(pContentRawDataNode);
4367 }
4368 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4369 }
dsinclairc5a8f212016-06-20 11:11:12 -07004370 case XFA_ObjectType::NodeC:
4371 case XFA_ObjectType::NodeV:
4372 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004373 pNode = this;
4374 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004375 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004376 pNode = this;
4377 }
4378 break;
4379 }
4380 if (pNode) {
4381 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004382 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004383 if (pScriptContext) {
4384 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4385 }
4386 }
tsepezd19e9122016-11-02 15:43:18 -07004387 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004388 }
tsepezd19e9122016-11-02 15:43:18 -07004389 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004390}
dsinclair5b36f0a2016-07-19 10:56:23 -07004391
Dan Sinclair1770c022016-03-14 14:14:16 -04004392CXFA_Node* CXFA_Node::GetModelNode() {
4393 switch (GetPacketID()) {
4394 case XFA_XDPPACKET_XDP:
4395 return m_pDocument->GetRoot();
4396 case XFA_XDPPACKET_Config:
4397 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4398 case XFA_XDPPACKET_Template:
4399 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4400 case XFA_XDPPACKET_Form:
4401 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4402 case XFA_XDPPACKET_Datasets:
4403 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4404 case XFA_XDPPACKET_LocaleSet:
4405 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4406 case XFA_XDPPACKET_ConnectionSet:
4407 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4408 case XFA_XDPPACKET_SourceSet:
4409 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4410 case XFA_XDPPACKET_Xdc:
4411 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4412 default:
4413 return this;
4414 }
4415}
dsinclair5b36f0a2016-07-19 10:56:23 -07004416
tsepezd19e9122016-11-02 15:43:18 -07004417bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004418 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004419 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
dsinclairae95f762016-03-29 16:58:29 -07004420 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004421 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004422 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004423 }
dsinclairae95f762016-03-29 16:58:29 -07004424 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004425 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004426 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
dsinclairae95f762016-03-29 16:58:29 -07004427 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004428 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004429 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004430 }
4431 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004432 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004433 }
dsinclair070fcdf2016-06-22 22:04:54 -07004434 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004435 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4436 return XFA_FDEExtension_ResolveNamespaceQualifier(
dsinclairae95f762016-03-29 16:58:29 -07004437 static_cast<CFDE_XMLElement*>(pXMLNode),
4438 GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004439 }
dsinclairae95f762016-03-29 16:58:29 -07004440 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004441 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004442 } else {
4443 CXFA_Node* pModelNode = GetModelNode();
4444 return pModelNode->TryNamespace(wsNamespace);
4445 }
4446}
dsinclair5b36f0a2016-07-19 10:56:23 -07004447
Dan Sinclair1770c022016-03-14 14:14:16 -04004448CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004449 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004450 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004451 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004452 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004453 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004454 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004455 if (!pProperty || index >= pProperty->uOccur)
4456 return nullptr;
4457
Dan Sinclair1770c022016-03-14 14:14:16 -04004458 CXFA_Node* pNode = m_pChild;
4459 int32_t iCount = 0;
4460 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004461 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004462 iCount++;
4463 if (iCount > index) {
4464 return pNode;
4465 }
4466 }
4467 }
weili44f8faf2016-06-01 14:03:56 -07004468 if (!bCreateProperty)
4469 return nullptr;
4470
Dan Sinclair1770c022016-03-14 14:14:16 -04004471 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4472 pNode = m_pChild;
4473 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4474 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004475 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004476 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4477 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004478 }
4479 }
dsinclaira1b07722016-07-11 08:20:58 -07004480
Dan Sinclair1770c022016-03-14 14:14:16 -04004481 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004482 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004483 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004484 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004485 if (!pNewNode)
4486 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004487 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004488 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004489 }
4490 return pNewNode;
4491}
dsinclair5b36f0a2016-07-19 10:56:23 -07004492
tsepezd19e9122016-11-02 15:43:18 -07004493int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004494 CXFA_Node* pNode = m_pChild;
4495 int32_t iCount = 0;
4496 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004497 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004498 if (bOnlyChild) {
4499 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004500 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004501 if (pProperty) {
4502 continue;
4503 }
4504 }
4505 iCount++;
4506 }
4507 }
4508 return iCount;
4509}
dsinclair5b36f0a2016-07-19 10:56:23 -07004510
Dan Sinclair1770c022016-03-14 14:14:16 -04004511CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004512 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004513 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004514 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004515 CXFA_Node* pNode = m_pChild;
4516 int32_t iCount = 0;
4517 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004518 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004519 if (bOnlyChild) {
4520 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004521 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004522 if (pProperty) {
4523 continue;
4524 }
4525 }
4526 iCount++;
4527 if (iCount > index) {
4528 return pNode;
4529 }
4530 }
4531 }
weili44f8faf2016-06-01 14:03:56 -07004532 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004533}
dsinclair5b36f0a2016-07-19 10:56:23 -07004534
Dan Sinclair1770c022016-03-14 14:14:16 -04004535int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4536 ASSERT(!pNode->m_pNext);
4537 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004538 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004539 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004540 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004541
weili44f8faf2016-06-01 14:03:56 -07004542 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004543 if (index > 0) {
4544 return -1;
4545 }
4546 pNode->m_pNext = m_pChild;
4547 m_pChild = pNode;
4548 index = 0;
4549 } else if (index < 0) {
4550 m_pLastChild->m_pNext = pNode;
4551 } else {
4552 CXFA_Node* pPrev = m_pChild;
4553 int32_t iCount = 0;
4554 while (++iCount != index && pPrev->m_pNext) {
4555 pPrev = pPrev->m_pNext;
4556 }
4557 if (index > 0 && index != iCount) {
4558 return -1;
4559 }
4560 pNode->m_pNext = pPrev->m_pNext;
4561 pPrev->m_pNext = pNode;
4562 index = iCount;
4563 }
weili44f8faf2016-06-01 14:03:56 -07004564 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004565 m_pLastChild = pNode;
4566 }
4567 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004568 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004569 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004570 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004571 if (pNotify)
4572 pNotify->OnChildAdded(this);
4573
Dan Sinclair1770c022016-03-14 14:14:16 -04004574 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004575 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004576 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004577 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004578 }
4579 return index;
4580}
weili6e1ae862016-05-04 18:25:27 -07004581
tsepezd19e9122016-11-02 15:43:18 -07004582bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004583 if (!pNode || pNode->m_pParent ||
4584 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004585 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004586 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004587 }
tsepezd19e9122016-11-02 15:43:18 -07004588 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004589 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004590 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004591
4592 int32_t nIndex = -1;
4593 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004594 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004595 pNode->m_pNext = m_pChild;
4596 m_pChild = pNode;
4597 nIndex = 0;
4598 } else if (!pBeforeNode) {
4599 pNode->m_pNext = m_pLastChild->m_pNext;
4600 m_pLastChild->m_pNext = pNode;
4601 } else {
4602 nIndex = 1;
4603 CXFA_Node* pPrev = m_pChild;
4604 while (pPrev->m_pNext != pBeforeNode) {
4605 pPrev = pPrev->m_pNext;
4606 nIndex++;
4607 }
4608 pNode->m_pNext = pPrev->m_pNext;
4609 pPrev->m_pNext = pNode;
4610 }
weili44f8faf2016-06-01 14:03:56 -07004611 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004612 m_pLastChild = pNode;
4613 }
4614 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004615 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004616 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004617 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004618 if (pNotify)
4619 pNotify->OnChildAdded(this);
4620
Dan Sinclair1770c022016-03-14 14:14:16 -04004621 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004622 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004623 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004624 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004625 }
tsepezd19e9122016-11-02 15:43:18 -07004626 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004627}
dsinclair5b36f0a2016-07-19 10:56:23 -07004628
Dan Sinclair1770c022016-03-14 14:14:16 -04004629CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4630 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004631 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004632 }
4633 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4634 pSibling = pSibling->m_pNext) {
4635 if (pSibling->m_pNext == this) {
4636 return pSibling;
4637 }
4638 }
weili44f8faf2016-06-01 14:03:56 -07004639 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004640}
dsinclair5b36f0a2016-07-19 10:56:23 -07004641
tsepezd19e9122016-11-02 15:43:18 -07004642bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004643 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004644 ASSERT(false);
4645 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004646 }
4647 if (m_pChild == pNode) {
4648 m_pChild = pNode->m_pNext;
4649 if (m_pLastChild == pNode) {
4650 m_pLastChild = pNode->m_pNext;
4651 }
weili44f8faf2016-06-01 14:03:56 -07004652 pNode->m_pNext = nullptr;
4653 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004654 } else {
4655 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4656 pPrev->m_pNext = pNode->m_pNext;
4657 if (m_pLastChild == pNode) {
4658 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4659 }
weili44f8faf2016-06-01 14:03:56 -07004660 pNode->m_pNext = nullptr;
4661 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004662 }
weili44f8faf2016-06-01 14:03:56 -07004663 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004664 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004665 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004666 m_pDocument->AddPurgeNode(pNode);
4667 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4668 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004669 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4670 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004671 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07004672 CFDE_XMLElement* pXMLElement =
4673 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004674 CFX_WideStringC wsAttributeName =
4675 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004676 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004677 }
4678 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004679 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -07004680 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004681 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4682 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004683 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004684 }
4685 pNode->m_pXMLNode = pNewXMLElement;
4686 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4687 } else {
4688 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4689 }
dsinclairc5a8f212016-06-20 11:11:12 -07004690 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004691 }
tsepezd19e9122016-11-02 15:43:18 -07004692 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004693}
dsinclair5b36f0a2016-07-19 10:56:23 -07004694
Dan Sinclair1770c022016-03-14 14:14:16 -04004695CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004696 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004697}
dsinclair5b36f0a2016-07-19 10:56:23 -07004698
tsepez736f28a2016-03-25 14:19:51 -07004699CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004700 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4701 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4702 if (pNode->GetNameHash() == dwNameHash) {
4703 return pNode;
4704 }
4705 }
weili44f8faf2016-06-01 14:03:56 -07004706 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004707}
dsinclair5b36f0a2016-07-19 10:56:23 -07004708
dsinclair41cb62e2016-06-23 09:20:32 -07004709CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004710 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4711 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004712 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004713 return pNode;
4714 }
4715 }
weili44f8faf2016-06-01 14:03:56 -07004716 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004717}
dsinclair5b36f0a2016-07-19 10:56:23 -07004718
tsepez736f28a2016-03-25 14:19:51 -07004719CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004720 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4721 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4722 if (pNode->GetNameHash() == dwNameHash) {
4723 return pNode;
4724 }
4725 }
weili44f8faf2016-06-01 14:03:56 -07004726 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004727}
dsinclair5b36f0a2016-07-19 10:56:23 -07004728
Dan Sinclair1770c022016-03-14 14:14:16 -04004729CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4730 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004731 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004732}
dsinclair5b36f0a2016-07-19 10:56:23 -07004733
dsinclair41cb62e2016-06-23 09:20:32 -07004734CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004735 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4736 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004737 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004738 return pNode;
4739 }
4740 }
weili44f8faf2016-06-01 14:03:56 -07004741 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004742}
dsinclair5b36f0a2016-07-19 10:56:23 -07004743
Dan Sinclair1770c022016-03-14 14:14:16 -04004744int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004745 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004746 if (!pScriptContext) {
4747 return -1;
4748 }
4749 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4750}
dsinclair5b36f0a2016-07-19 10:56:23 -07004751
Dan Sinclair1770c022016-03-14 14:14:16 -04004752int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004753 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004754 if (!pScriptContext) {
4755 return -1;
4756 }
4757 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4758}
dsinclair5b36f0a2016-07-19 10:56:23 -07004759
Dan Sinclair1770c022016-03-14 14:14:16 -04004760void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004761 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004762 if (!pScriptContext) {
4763 return;
4764 }
4765 pScriptContext->GetSomExpression(this, wsSOMExpression);
4766}
dsinclair5b36f0a2016-07-19 10:56:23 -07004767
Dan Sinclair1770c022016-03-14 14:14:16 -04004768CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004769 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004770 if (m_ePacket == XFA_XDPPACKET_Form) {
4771 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004772 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004773 return pInstanceMgr;
4774 }
4775 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4776 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004777 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004778 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004779 pNode->m_dwNameHash != m_dwNameHash) {
4780 break;
4781 }
dsinclair56a8b192016-06-21 14:15:25 -07004782 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004783 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4784 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4785 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4786 wsInstName.Mid(1) == wsName) {
4787 pInstanceMgr = pNode;
4788 }
4789 break;
4790 }
4791 }
4792 }
4793 return pInstanceMgr;
4794}
dsinclair5b36f0a2016-07-19 10:56:23 -07004795
Dan Sinclair1770c022016-03-14 14:14:16 -04004796CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004797 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004798}
dsinclair5b36f0a2016-07-19 10:56:23 -07004799
dsinclairc5a8f212016-06-20 11:11:12 -07004800bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4801 if (m_uNodeFlags & dwFlag)
4802 return true;
4803 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4804 return m_pParent && m_pParent->HasFlag(dwFlag);
4805 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004806}
thestigb1a59592016-04-14 18:29:56 -07004807
4808void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004809 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004810 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004811 if (pNotify) {
4812 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004813 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004814 }
dsinclairc5a8f212016-06-20 11:11:12 -07004815 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004816}
thestigb1a59592016-04-14 18:29:56 -07004817
4818void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004819 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004820}
4821
tsepezd19e9122016-11-02 15:43:18 -07004822bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004823 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4824}
thestigb1a59592016-04-14 18:29:56 -07004825
4826void CXFA_Node::OnRemoved(bool bNotify) {
4827 if (!bNotify)
4828 return;
4829
dsinclaira1b07722016-07-11 08:20:58 -07004830 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004831 if (pNotify)
4832 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004833}
thestigb1a59592016-04-14 18:29:56 -07004834
4835void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004836 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004837 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004838 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004839 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004840 }
4841 }
4842}
thestigb1a59592016-04-14 18:29:56 -07004843
Dan Sinclair1770c022016-03-14 14:14:16 -04004844void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004845 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004846 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004847 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004848 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004849 }
4850}
thestigb1a59592016-04-14 18:29:56 -07004851
Dan Sinclair1770c022016-03-14 14:14:16 -04004852int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004853 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004854 int32_t iRet = XFA_EVENTERROR_NotExist;
4855 const XFA_ExecEventParaInfo* eventParaInfo =
4856 GetEventParaInfoByName(wsEventName);
4857 if (eventParaInfo) {
4858 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004859 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004860 if (!pNotify) {
4861 return iRet;
4862 }
4863 if (validFlags == 1) {
4864 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4865 } else if (validFlags == 2) {
4866 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004867 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004868 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004869 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004870 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004871 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004872 }
4873 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004874 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004875 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004876 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004877 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004878 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004879 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004880 }
4881 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004882 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004883 }
4884 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004885 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004886 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004887 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004888 }
4889 } else if (validFlags == 6) {
4890 CXFA_WidgetData* pWidgetData = GetWidgetData();
4891 if (pWidgetData) {
4892 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004893 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004894 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004895 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004896 }
4897 }
4898 } else if (validFlags == 7) {
4899 CXFA_WidgetData* pWidgetData = GetWidgetData();
4900 if (pWidgetData) {
4901 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004902 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004903 (!pWidgetData->IsListBox())) {
4904 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004905 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004906 }
4907 }
4908 }
4909 }
4910 return iRet;
4911}
dsinclair5b36f0a2016-07-19 10:56:23 -07004912
Dan Sinclair1770c022016-03-14 14:14:16 -04004913void CXFA_Node::UpdateNameHash() {
4914 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004915 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004916 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004917 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004918 wsName = GetCData(XFA_ATTRIBUTE_Name);
4919 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004920 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004921 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004922 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004923 }
4924}
dsinclair5b36f0a2016-07-19 10:56:23 -07004925
dsinclairae95f762016-03-29 16:58:29 -07004926CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004927 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004928 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
dsinclairae95f762016-03-29 16:58:29 -07004929 m_pXMLNode = new CFDE_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004930 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004931 }
4932 return m_pXMLNode;
4933}
dsinclair5b36f0a2016-07-19 10:56:23 -07004934
tsepezd19e9122016-11-02 15:43:18 -07004935bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004936 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004937 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004938}
4939
4940XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4941 if (!m_pMapModuleData)
4942 m_pMapModuleData = new XFA_MAPMODULEDATA;
4943 return m_pMapModuleData;
4944}
4945
4946XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4947 return m_pMapModuleData;
4948}
4949
4950void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4951 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4952 pModule->m_ValueMap.SetAt(pKey, pValue);
4953}
4954
tsepezd19e9122016-11-02 15:43:18 -07004955bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004956 CXFA_Node* pNode = this;
4957 while (pNode) {
4958 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
4959 if (pModule && pModule->m_ValueMap.Lookup(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004960 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004961 }
4962 pNode = pNode->GetPacketID() != XFA_XDPPACKET_Datasets
4963 ? pNode->GetTemplateNode()
weili44f8faf2016-06-01 14:03:56 -07004964 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004965 }
tsepezd19e9122016-11-02 15:43:18 -07004966 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004967}
dsinclair5b36f0a2016-07-19 10:56:23 -07004968
Dan Sinclair1770c022016-03-14 14:14:16 -04004969void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004970 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair1770c022016-03-14 14:14:16 -04004971 wsValue.GetLength() * sizeof(FX_WCHAR));
4972}
dsinclair5b36f0a2016-07-19 10:56:23 -07004973
tsepezd19e9122016-11-02 15:43:18 -07004974bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004975 void* pValue;
4976 int32_t iBytes;
4977 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004978 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004979 }
4980 wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR));
tsepezd19e9122016-11-02 15:43:18 -07004981 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004982}
dsinclair5b36f0a2016-07-19 10:56:23 -07004983
Dan Sinclair1770c022016-03-14 14:14:16 -04004984void CXFA_Node::SetMapModuleBuffer(
4985 void* pKey,
4986 void* pValue,
4987 int32_t iBytes,
4988 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4989 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4990 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004991 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004992 pBuffer =
4993 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4994 } else if (pBuffer->iBytes != iBytes) {
4995 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4996 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4997 }
4998 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4999 sizeof(XFA_MAPDATABLOCK) + iBytes);
5000 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5001 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5002 }
weili44f8faf2016-06-01 14:03:56 -07005003 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04005004 return;
weili44f8faf2016-06-01 14:03:56 -07005005
Dan Sinclair1770c022016-03-14 14:14:16 -04005006 pBuffer->pCallbackInfo = pCallbackInfo;
5007 pBuffer->iBytes = iBytes;
5008 FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes);
5009}
dsinclair5b36f0a2016-07-19 10:56:23 -07005010
tsepezd19e9122016-11-02 15:43:18 -07005011bool CXFA_Node::GetMapModuleBuffer(void* pKey,
5012 void*& pValue,
5013 int32_t& iBytes,
5014 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07005015 XFA_MAPDATABLOCK* pBuffer = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005016 const CXFA_Node* pNode = this;
5017 while (pNode) {
5018 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
5019 if (pModule && pModule->m_BufferMap.Lookup(pKey, pBuffer)) {
5020 break;
5021 }
5022 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets)
5023 ? pNode->GetTemplateNode()
weili44f8faf2016-06-01 14:03:56 -07005024 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005025 }
weili44f8faf2016-06-01 14:03:56 -07005026 if (!pBuffer) {
tsepezd19e9122016-11-02 15:43:18 -07005027 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005028 }
5029 pValue = pBuffer->GetData();
5030 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07005031 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005032}
dsinclair5b36f0a2016-07-19 10:56:23 -07005033
tsepezd19e9122016-11-02 15:43:18 -07005034bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005035 CXFA_Node* pNode = this;
5036 while (pNode) {
5037 void* pVal;
5038 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
5039 if (pModule &&
5040 (pModule->m_ValueMap.Lookup(pKey, pVal) ||
5041 pModule->m_BufferMap.Lookup(pKey, (XFA_MAPDATABLOCK*&)pVal))) {
tsepezd19e9122016-11-02 15:43:18 -07005042 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005043 }
5044 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets)
5045 ? pNode->GetTemplateNode()
weili44f8faf2016-06-01 14:03:56 -07005046 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005047 }
tsepezd19e9122016-11-02 15:43:18 -07005048 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005049}
dsinclair5b36f0a2016-07-19 10:56:23 -07005050
Dan Sinclair1770c022016-03-14 14:14:16 -04005051void CXFA_Node::RemoveMapModuleKey(void* pKey) {
5052 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
5053 if (!pModule)
5054 return;
5055
5056 if (pKey) {
weili44f8faf2016-06-01 14:03:56 -07005057 XFA_MAPDATABLOCK* pBuffer = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005058 pModule->m_BufferMap.Lookup(pKey, pBuffer);
5059 if (pBuffer) {
5060 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5061 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5062 }
5063 FX_Free(pBuffer);
5064 }
5065 pModule->m_BufferMap.RemoveKey(pKey);
5066 pModule->m_ValueMap.RemoveKey(pKey);
5067 } else {
5068 XFA_MAPDATABLOCK* pBuffer;
5069 FX_POSITION posBuffer = pModule->m_BufferMap.GetStartPosition();
5070 while (posBuffer) {
5071 pModule->m_BufferMap.GetNextAssoc(posBuffer, pKey, pBuffer);
5072 if (pBuffer) {
5073 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5074 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5075 }
5076 FX_Free(pBuffer);
5077 }
5078 }
5079 pModule->m_BufferMap.RemoveAll();
5080 pModule->m_ValueMap.RemoveAll();
5081 delete pModule;
5082 }
5083}
dsinclair5b36f0a2016-07-19 10:56:23 -07005084
tsepezd19e9122016-11-02 15:43:18 -07005085void CXFA_Node::MergeAllData(void* pDstModule, bool bUseSrcAttr) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005086 XFA_MAPMODULEDATA* pDstModuleData =
5087 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
5088 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
5089 if (!pSrcModuleData) {
5090 return;
5091 }
5092 FX_POSITION psValue = pSrcModuleData->m_ValueMap.GetStartPosition();
5093 while (psValue) {
5094 void* pKey;
5095 void* pValue;
5096 pSrcModuleData->m_ValueMap.GetNextAssoc(psValue, pKey, pValue);
5097 if (bUseSrcAttr || !pDstModuleData->m_ValueMap.GetValueAt(pKey)) {
5098 pDstModuleData->m_ValueMap.SetAt(pKey, pValue);
5099 }
5100 }
5101 FX_POSITION psBuffer = pSrcModuleData->m_BufferMap.GetStartPosition();
5102 while (psBuffer) {
5103 void* pKey;
5104 XFA_MAPDATABLOCK* pSrcBuffer;
5105 pSrcModuleData->m_BufferMap.GetNextAssoc(psBuffer, pKey, pSrcBuffer);
5106 XFA_MAPDATABLOCK*& pBuffer = pDstModuleData->m_BufferMap[pKey];
5107 if (pBuffer && !bUseSrcAttr) {
5108 continue;
5109 }
5110 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
5111 !pSrcBuffer->pCallbackInfo->pCopy) {
5112 if (pBuffer) {
5113 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5114 pDstModuleData->m_BufferMap.RemoveKey(pKey);
5115 }
5116 continue;
5117 }
weili44f8faf2016-06-01 14:03:56 -07005118 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005119 pBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
5120 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5121 } else if (pBuffer->iBytes != pSrcBuffer->iBytes) {
5122 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5123 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5124 }
5125 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
5126 uint8_t, pBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5127 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5128 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5129 }
weili44f8faf2016-06-01 14:03:56 -07005130 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005131 continue;
5132 }
5133 pBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5134 pBuffer->iBytes = pSrcBuffer->iBytes;
5135 FXSYS_memcpy(pBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes);
5136 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pCopy) {
5137 pBuffer->pCallbackInfo->pCopy(*(void**)pBuffer->GetData());
5138 }
5139 }
5140}
dsinclair5b36f0a2016-07-19 10:56:23 -07005141
Dan Sinclair1770c022016-03-14 14:14:16 -04005142void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5143 if (!pDstModule) {
5144 return;
5145 }
tsepezd19e9122016-11-02 15:43:18 -07005146 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005147 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005148 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005149 }
dsinclair070fcdf2016-06-22 22:04:54 -07005150 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005151 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005152 }
weili44f8faf2016-06-01 14:03:56 -07005153 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5154 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005155 if (bNeedMove) {
5156 pSrcModuleData = GetMapModuleData();
5157 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005158 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005159 }
5160 pDstModuleData = pDstModule->CreateMapModuleData();
5161 }
5162 if (bNeedMove) {
5163 void* pBufferBlockData = pSrcModuleData->m_BufferMap.GetValueAt(pKey);
5164 if (pBufferBlockData) {
5165 pSrcModuleData->m_BufferMap.RemoveKey(pKey);
5166 pDstModuleData->m_BufferMap.RemoveKey(pKey);
5167 pDstModuleData->m_BufferMap.SetAt(pKey,
5168 (XFA_MAPDATABLOCK*)pBufferBlockData);
5169 }
5170 }
dsinclairc5a8f212016-06-20 11:11:12 -07005171 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005172 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005173 CFX_WideString wsFormatValue(wsValue);
5174 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5175 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005176 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005177 }
tsepezd19e9122016-11-02 15:43:18 -07005178 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005179 }
5180}
dsinclair5b36f0a2016-07-19 10:56:23 -07005181
Dan Sinclair1770c022016-03-14 14:14:16 -04005182void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5183 CXFA_Node* pDstModule,
5184 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005185 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005186 if (!pSrcModule || !pDstModule || !pKey) {
5187 return;
5188 }
5189 if (bRecursive) {
5190 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5191 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5192 for (; pSrcChild && pDstChild;
5193 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5194 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005195 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005196 }
5197 }
5198 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5199}