blob: 1721cb79825c4b859a85159f4c95c3b05087830b [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"
tsepezaadedf92016-05-12 10:08:06 -070016#include "third_party/base/stl_util.h"
dsinclairae95f762016-03-29 16:58:29 -070017#include "xfa/fde/xml/fde_xml_imp.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040018#include "xfa/fgas/crt/fgas_codepage.h"
dsinclairdf4bc592016-03-31 20:34:43 -070019#include "xfa/fxfa/app/xfa_ffnotify.h"
dsinclair5b493092016-09-29 20:20:24 -070020#include "xfa/fxfa/cxfa_eventparam.h"
dsinclair16280242016-07-21 12:03:47 -070021#include "xfa/fxfa/parser/cxfa_document.h"
dsinclair0b851ff2016-07-21 12:03:01 -070022#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
dsinclair9eb0db12016-07-21 12:01:39 -070023#include "xfa/fxfa/parser/cxfa_measurement.h"
dsinclair44d054c2016-04-06 10:23:46 -070024#include "xfa/fxfa/parser/cxfa_occur.h"
dsinclair31f87402016-07-20 06:34:45 -070025#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
dsinclair34f86b02016-07-11 08:42:33 -070026#include "xfa/fxfa/parser/cxfa_simple_parser.h"
dsinclair5b36f0a2016-07-19 10:56:23 -070027#include "xfa/fxfa/parser/xfa_basic_data.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040028
weili44f8faf2016-06-01 14:03:56 -070029namespace {
30
31void XFA_DeleteWideString(void* pData) {
32 delete static_cast<CFX_WideString*>(pData);
33}
34
35void XFA_CopyWideString(void*& pData) {
36 if (pData) {
37 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
38 pData = pNewData;
39 }
40}
41
42XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
43 XFA_CopyWideString};
44
weili44f8faf2016-06-01 14:03:56 -070045void XFA_DataNodeDeleteBindItem(void* pData) {
46 delete static_cast<CXFA_NodeArray*>(pData);
47}
48
49XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
50 XFA_DataNodeDeleteBindItem, nullptr};
51
dsinclair5b36f0a2016-07-19 10:56:23 -070052int32_t GetCount(CXFA_Node* pInstMgrNode) {
53 ASSERT(pInstMgrNode);
54 int32_t iCount = 0;
55 uint32_t dwNameHash = 0;
56 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
57 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
58 XFA_Element eCurType = pNode->GetElementType();
59 if (eCurType == XFA_Element::InstanceManager)
60 break;
61 if ((eCurType != XFA_Element::Subform) &&
62 (eCurType != XFA_Element::SubformSet)) {
63 continue;
64 }
65 if (iCount == 0) {
66 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
67 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
68 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
69 wsInstName.Mid(1) != wsName) {
70 return iCount;
71 }
72 dwNameHash = pNode->GetNameHash();
73 }
74 if (dwNameHash != pNode->GetNameHash())
75 break;
weili44f8faf2016-06-01 14:03:56 -070076
dsinclair5b36f0a2016-07-19 10:56:23 -070077 iCount++;
78 }
79 return iCount;
Dan Sinclair1770c022016-03-14 14:14:16 -040080}
weili44f8faf2016-06-01 14:03:56 -070081
dsinclair5b36f0a2016-07-19 10:56:23 -070082void SortNodeArrayByDocumentIdx(const CXFA_NodeSet& rgNodeSet,
83 CXFA_NodeArray& rgNodeArray,
84 CFX_ArrayTemplate<int32_t>& rgIdxArray) {
85 int32_t iCount = pdfium::CollectionSize<int32_t>(rgNodeSet);
86 rgNodeArray.SetSize(iCount);
87 rgIdxArray.SetSize(iCount);
88 if (iCount == 0)
89 return;
weili44f8faf2016-06-01 14:03:56 -070090
dsinclair5b36f0a2016-07-19 10:56:23 -070091 int32_t iIndex = -1;
92 int32_t iTotalIndex = -1;
93 CXFA_Node* pCommonParent =
94 (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent);
95 for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild);
96 pNode && iIndex < iCount;
97 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
98 iTotalIndex++;
99 if (pdfium::ContainsValue(rgNodeSet, pNode)) {
100 iIndex++;
101 rgNodeArray[iIndex] = pNode;
102 rgIdxArray[iIndex] = iTotalIndex;
103 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400104 }
105}
weili44f8faf2016-06-01 14:03:56 -0700106
dsinclair5b36f0a2016-07-19 10:56:23 -0700107using CXFA_NodeSetPair = std::pair<CXFA_NodeSet, CXFA_NodeSet>;
108using CXFA_NodeSetPairMap =
109 std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>;
110using CXFA_NodeSetPairMapMap =
111 std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>;
112
113CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode,
114 CXFA_NodeSetPairMapMap* pMap) {
115 CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
116 uint32_t dwNameHash = pNode->GetNameHash();
117 if (!pParentNode || !dwNameHash)
118 return nullptr;
119
120 if (!(*pMap)[pParentNode])
121 (*pMap)[pParentNode].reset(new CXFA_NodeSetPairMap);
122
123 CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get();
124 if (!(*pNodeSetPairMap)[dwNameHash])
125 (*pNodeSetPairMap)[dwNameHash].reset(new CXFA_NodeSetPair);
126
127 return (*pNodeSetPairMap)[dwNameHash].get();
Dan Sinclair1770c022016-03-14 14:14:16 -0400128}
129
dsinclair5b36f0a2016-07-19 10:56:23 -0700130void ReorderDataNodes(const CXFA_NodeSet& sSet1,
131 const CXFA_NodeSet& sSet2,
tsepezd19e9122016-11-02 15:43:18 -0700132 bool bInsertBefore) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700133 CXFA_NodeSetPairMapMap rgMap;
134 for (CXFA_Node* pNode : sSet1) {
135 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
136 if (pNodeSetPair)
137 pNodeSetPair->first.insert(pNode);
138 }
139 for (CXFA_Node* pNode : sSet2) {
140 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
141 if (pNodeSetPair) {
142 if (pdfium::ContainsValue(pNodeSetPair->first, pNode))
143 pNodeSetPair->first.erase(pNode);
144 else
145 pNodeSetPair->second.insert(pNode);
146 }
147 }
148 for (const auto& iter1 : rgMap) {
149 CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get();
150 if (!pNodeSetPairMap)
151 continue;
152
153 for (const auto& iter2 : *pNodeSetPairMap) {
154 CXFA_NodeSetPair* pNodeSetPair = iter2.second.get();
155 if (!pNodeSetPair)
156 continue;
157 if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) {
158 CXFA_NodeArray rgNodeArray1;
159 CXFA_NodeArray rgNodeArray2;
160 CFX_ArrayTemplate<int32_t> rgIdxArray1;
161 CFX_ArrayTemplate<int32_t> rgIdxArray2;
162 SortNodeArrayByDocumentIdx(pNodeSetPair->first, rgNodeArray1,
163 rgIdxArray1);
164 SortNodeArrayByDocumentIdx(pNodeSetPair->second, rgNodeArray2,
165 rgIdxArray2);
166 CXFA_Node* pParentNode = nullptr;
167 CXFA_Node* pBeforeNode = nullptr;
168 if (bInsertBefore) {
169 pBeforeNode = rgNodeArray2[0];
170 pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent);
171 } else {
172 CXFA_Node* pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1];
173 pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent);
174 pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling);
175 }
176 for (int32_t iIdx = 0; iIdx < rgIdxArray1.GetSize(); iIdx++) {
177 CXFA_Node* pCurNode = rgNodeArray1[iIdx];
178 pParentNode->RemoveChild(pCurNode);
179 pParentNode->InsertChild(pCurNode, pBeforeNode);
180 }
181 }
182 }
183 pNodeSetPairMap->clear();
184 }
185}
186
187CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
188 ASSERT(pInstMgrNode);
189 int32_t iCount = 0;
190 uint32_t dwNameHash = 0;
191 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
192 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
193 XFA_Element eCurType = pNode->GetElementType();
194 if (eCurType == XFA_Element::InstanceManager)
195 break;
196 if ((eCurType != XFA_Element::Subform) &&
197 (eCurType != XFA_Element::SubformSet)) {
198 continue;
199 }
200 if (iCount == 0) {
201 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
202 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
203 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
204 wsInstName.Mid(1) != wsName) {
205 return nullptr;
206 }
207 dwNameHash = pNode->GetNameHash();
208 }
209 if (dwNameHash != pNode->GetNameHash())
210 break;
211
212 iCount++;
213 if (iCount > iIndex)
214 return pNode;
215 }
216 return nullptr;
217}
218
219void InsertItem(CXFA_Node* pInstMgrNode,
220 CXFA_Node* pNewInstance,
221 int32_t iPos,
222 int32_t iCount = -1,
tsepezd19e9122016-11-02 15:43:18 -0700223 bool bMoveDataBindingNodes = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700224 if (iCount < 0)
225 iCount = GetCount(pInstMgrNode);
226 if (iPos < 0)
227 iPos = iCount;
228 if (iPos == iCount) {
229 CXFA_Node* pNextSibling =
230 iCount > 0
231 ? GetItem(pInstMgrNode, iCount - 1)
232 ->GetNodeItem(XFA_NODEITEM_NextSibling)
233 : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
234 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
235 ->InsertChild(pNewInstance, pNextSibling);
236 if (bMoveDataBindingNodes) {
237 CXFA_NodeSet sNew;
238 CXFA_NodeSet sAfter;
239 CXFA_NodeIteratorTemplate<CXFA_Node,
240 CXFA_TraverseStrategy_XFAContainerNode>
241 sIteratorNew(pNewInstance);
242 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
243 pNode = sIteratorNew.MoveToNext()) {
244 CXFA_Node* pDataNode = pNode->GetBindData();
245 if (!pDataNode)
246 continue;
247
248 sNew.insert(pDataNode);
249 }
250 CXFA_NodeIteratorTemplate<CXFA_Node,
251 CXFA_TraverseStrategy_XFAContainerNode>
252 sIteratorAfter(pNextSibling);
253 for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode;
254 pNode = sIteratorAfter.MoveToNext()) {
255 CXFA_Node* pDataNode = pNode->GetBindData();
256 if (!pDataNode)
257 continue;
258
259 sAfter.insert(pDataNode);
260 }
tsepezd19e9122016-11-02 15:43:18 -0700261 ReorderDataNodes(sNew, sAfter, false);
dsinclair5b36f0a2016-07-19 10:56:23 -0700262 }
263 } else {
264 CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos);
265 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
266 ->InsertChild(pNewInstance, pBeforeInstance);
267 if (bMoveDataBindingNodes) {
268 CXFA_NodeSet sNew;
269 CXFA_NodeSet sBefore;
270 CXFA_NodeIteratorTemplate<CXFA_Node,
271 CXFA_TraverseStrategy_XFAContainerNode>
272 sIteratorNew(pNewInstance);
273 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
274 pNode = sIteratorNew.MoveToNext()) {
275 CXFA_Node* pDataNode = pNode->GetBindData();
276 if (!pDataNode)
277 continue;
278
279 sNew.insert(pDataNode);
280 }
281 CXFA_NodeIteratorTemplate<CXFA_Node,
282 CXFA_TraverseStrategy_XFAContainerNode>
283 sIteratorBefore(pBeforeInstance);
284 for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode;
285 pNode = sIteratorBefore.MoveToNext()) {
286 CXFA_Node* pDataNode = pNode->GetBindData();
287 if (!pDataNode)
288 continue;
289
290 sBefore.insert(pDataNode);
291 }
tsepezd19e9122016-11-02 15:43:18 -0700292 ReorderDataNodes(sNew, sBefore, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700293 }
294 }
295}
296
297void RemoveItem(CXFA_Node* pInstMgrNode,
298 CXFA_Node* pRemoveInstance,
tsepezd19e9122016-11-02 15:43:18 -0700299 bool bRemoveDataBinding = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700300 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);
301 if (!bRemoveDataBinding)
302 return;
303
304 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode>
305 sIterator(pRemoveInstance);
306 for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode;
307 pFormNode = sIterator.MoveToNext()) {
308 CXFA_Node* pDataNode = pFormNode->GetBindData();
309 if (!pDataNode)
310 continue;
311
312 if (pDataNode->RemoveBindItem(pFormNode) == 0) {
313 if (CXFA_Node* pDataParent =
314 pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) {
315 pDataParent->RemoveChild(pDataNode);
316 }
317 }
318 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
319 }
320}
321
tsepezd19e9122016-11-02 15:43:18 -0700322CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700323 CXFA_Document* pDocument = pInstMgrNode->GetDocument();
324 CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();
325 CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);
326 CXFA_Node* pDataScope = nullptr;
327 for (CXFA_Node* pRootBoundNode = pFormParent;
328 pRootBoundNode && pRootBoundNode->IsContainerNode();
329 pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) {
330 pDataScope = pRootBoundNode->GetBindData();
331 if (pDataScope)
332 break;
333 }
334 if (!pDataScope) {
335 pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record));
336 ASSERT(pDataScope);
337 }
338 CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer(
tsepezd19e9122016-11-02 15:43:18 -0700339 pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700340 if (pInstance) {
341 pDocument->DataMerge_UpdateBindingRelations(pInstance);
342 pFormParent->RemoveChild(pInstance);
343 }
344 return pInstance;
345}
346
347struct XFA_ExecEventParaInfo {
348 public:
349 uint32_t m_uHash;
350 const FX_WCHAR* m_lpcEventName;
351 XFA_EVENTTYPE m_eventType;
352 uint32_t m_validFlags;
353};
354static const XFA_ExecEventParaInfo gs_eventParaInfos[] = {
355 {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0},
356 {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0},
357 {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5},
358 {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0},
359 {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7},
360 {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1},
361 {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5},
362 {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0},
363 {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0},
364 {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6},
365 {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2},
366 {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0},
367 {0x7233018a, L"validate", XFA_EVENT_Validate, 1},
368 {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3},
369 {0x891f4606, L"change", XFA_EVENT_Change, 4},
370 {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0},
371 {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5},
372 {0xcdce56b3, L"full", XFA_EVENT_Full, 4},
373 {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5},
374 {0xd95657a6, L"click", XFA_EVENT_Click, 4},
375 {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1},
376 {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7},
377 {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2},
378 {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0},
379 {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6},
380};
381
382const XFA_ExecEventParaInfo* GetEventParaInfoByName(
383 const CFX_WideStringC& wsEventName) {
384 uint32_t uHash = FX_HashCode_GetW(wsEventName, false);
385 int32_t iStart = 0;
386 int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
387 do {
388 int32_t iMid = (iStart + iEnd) / 2;
389 const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid];
390 if (uHash == eventParaInfo->m_uHash)
391 return eventParaInfo;
392 if (uHash < eventParaInfo->m_uHash)
393 iEnd = iMid - 1;
394 else
395 iStart = iMid + 1;
396 } while (iStart <= iEnd);
397 return nullptr;
398}
399
400void StrToRGB(const CFX_WideString& strRGB,
401 int32_t& r,
402 int32_t& g,
403 int32_t& b) {
404 r = 0;
405 g = 0;
406 b = 0;
407
408 FX_WCHAR zero = '0';
409 int32_t iIndex = 0;
410 int32_t iLen = strRGB.GetLength();
411 for (int32_t i = 0; i < iLen; ++i) {
412 FX_WCHAR ch = strRGB.GetAt(i);
413 if (ch == L',')
414 ++iIndex;
415 if (iIndex > 2)
416 break;
417
418 int32_t iValue = ch - zero;
419 if (iValue >= 0 && iValue <= 9) {
420 switch (iIndex) {
421 case 0:
422 r = r * 10 + iValue;
423 break;
424 case 1:
425 g = g * 10 + iValue;
426 break;
427 default:
428 b = b * 10 + iValue;
429 break;
430 }
431 }
432 }
433}
434
435enum XFA_KEYTYPE {
436 XFA_KEYTYPE_Custom,
437 XFA_KEYTYPE_Element,
438};
439
440void* GetMapKey_Custom(const CFX_WideStringC& wsKey) {
441 uint32_t dwKey = FX_HashCode_GetW(wsKey, false);
442 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom);
443}
444
445void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) {
446 return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) |
447 (eAttribute << 8) | XFA_KEYTYPE_Element);
448}
449
dsinclair9eb0db12016-07-21 12:01:39 -0700450const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement,
451 XFA_ATTRIBUTE eAttribute,
452 uint32_t dwPacket) {
453 int32_t iCount = 0;
454 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount);
455 if (!pAttr || iCount < 1)
456 return nullptr;
457
458 if (!std::binary_search(pAttr, pAttr + iCount, eAttribute))
459 return nullptr;
460
461 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute);
462 ASSERT(pInfo);
463 if (dwPacket == XFA_XDPPACKET_UNKNOWN)
464 return pInfo;
465 return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr;
466}
467
468const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) {
469 return g_XFAEnumData + eName;
470}
471
dsinclair5b36f0a2016-07-19 10:56:23 -0700472} // namespace
473
474static void XFA_DefaultFreeData(void* pData) {}
475
476static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {
477 XFA_DefaultFreeData, nullptr};
478
weili47bcd4c2016-06-16 08:00:06 -0700479XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {}
480
481XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {}
482
dsinclairb9778472016-06-23 13:34:10 -0700483CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
484 uint16_t ePacket,
485 XFA_ObjectType oType,
dsinclairc1df5d42016-07-18 06:36:51 -0700486 XFA_Element eType,
487 const CFX_WideStringC& elementName)
488 : CXFA_Object(pDoc, oType, eType, elementName),
Dan Sinclair1770c022016-03-14 14:14:16 -0400489 m_pNext(nullptr),
490 m_pChild(nullptr),
491 m_pLastChild(nullptr),
492 m_pParent(nullptr),
493 m_pXMLNode(nullptr),
Dan Sinclair1770c022016-03-14 14:14:16 -0400494 m_ePacket(ePacket),
dsinclairc5a8f212016-06-20 11:11:12 -0700495 m_uNodeFlags(XFA_NodeFlag_None),
Dan Sinclair1770c022016-03-14 14:14:16 -0400496 m_dwNameHash(0),
497 m_pAuxNode(nullptr),
498 m_pMapModuleData(nullptr) {
499 ASSERT(m_pDocument);
500}
weili44f8faf2016-06-01 14:03:56 -0700501
Dan Sinclair1770c022016-03-14 14:14:16 -0400502CXFA_Node::~CXFA_Node() {
weili44f8faf2016-06-01 14:03:56 -0700503 ASSERT(!m_pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400504 RemoveMapModuleKey();
weili44f8faf2016-06-01 14:03:56 -0700505 CXFA_Node* pNode = m_pChild;
Dan Sinclair1770c022016-03-14 14:14:16 -0400506 while (pNode) {
weili44f8faf2016-06-01 14:03:56 -0700507 CXFA_Node* pNext = pNode->m_pNext;
508 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400509 delete pNode;
510 pNode = pNext;
511 }
dsinclairc5a8f212016-06-20 11:11:12 -0700512 if (m_pXMLNode && IsOwnXMLNode())
Tom Sepezd3743ea2016-05-16 15:56:53 -0700513 m_pXMLNode->Release();
Dan Sinclair1770c022016-03-14 14:14:16 -0400514}
weili44f8faf2016-06-01 14:03:56 -0700515
tsepezd19e9122016-11-02 15:43:18 -0700516CXFA_Node* CXFA_Node::Clone(bool bRecursive) {
dsinclaira1b07722016-07-11 08:20:58 -0700517 CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700518 if (!pClone)
519 return nullptr;
520
Dan Sinclair1770c022016-03-14 14:14:16 -0400521 MergeAllData(pClone);
522 pClone->UpdateNameHash();
523 if (IsNeedSavingXMLNode()) {
weili44f8faf2016-06-01 14:03:56 -0700524 CFDE_XMLNode* pCloneXML = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400525 if (IsAttributeInXML()) {
526 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -0700527 GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -0700528 CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -0400529 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
530 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -0700531 pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -0400532 }
533 pCloneXML = pCloneXMLElement;
weili44f8faf2016-06-01 14:03:56 -0700534 pCloneXMLElement = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400535 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
536 } else {
tsepezd19e9122016-11-02 15:43:18 -0700537 pCloneXML = m_pXMLNode->Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400538 }
539 pClone->SetXMLMappingNode(pCloneXML);
dsinclairc5a8f212016-06-20 11:11:12 -0700540 pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400541 }
542 if (bRecursive) {
543 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
544 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
545 pClone->InsertChild(pChild->Clone(bRecursive));
546 }
547 }
dsinclairc5a8f212016-06-20 11:11:12 -0700548 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
weili44f8faf2016-06-01 14:03:56 -0700549 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400550 return pClone;
551}
weili44f8faf2016-06-01 14:03:56 -0700552
Dan Sinclair1770c022016-03-14 14:14:16 -0400553CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
554 switch (eItem) {
555 case XFA_NODEITEM_NextSibling:
556 return m_pNext;
557 case XFA_NODEITEM_FirstChild:
558 return m_pChild;
559 case XFA_NODEITEM_Parent:
560 return m_pParent;
561 case XFA_NODEITEM_PrevSibling:
562 if (m_pParent) {
563 CXFA_Node* pSibling = m_pParent->m_pChild;
weili44f8faf2016-06-01 14:03:56 -0700564 CXFA_Node* pPrev = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400565 while (pSibling && pSibling != this) {
566 pPrev = pSibling;
567 pSibling = pSibling->m_pNext;
568 }
569 return pPrev;
570 }
weili44f8faf2016-06-01 14:03:56 -0700571 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400572 default:
573 break;
574 }
weili44f8faf2016-06-01 14:03:56 -0700575 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400576}
weili44f8faf2016-06-01 14:03:56 -0700577
Dan Sinclair1770c022016-03-14 14:14:16 -0400578CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
dsinclairc5a8f212016-06-20 11:11:12 -0700579 XFA_ObjectType eType) const {
weili44f8faf2016-06-01 14:03:56 -0700580 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400581 switch (eItem) {
582 case XFA_NODEITEM_NextSibling:
583 pNode = m_pNext;
dsinclairc5a8f212016-06-20 11:11:12 -0700584 while (pNode && pNode->GetObjectType() != eType)
585 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400586 break;
587 case XFA_NODEITEM_FirstChild:
588 pNode = m_pChild;
dsinclairc5a8f212016-06-20 11:11:12 -0700589 while (pNode && pNode->GetObjectType() != eType)
590 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400591 break;
592 case XFA_NODEITEM_Parent:
593 pNode = m_pParent;
dsinclairc5a8f212016-06-20 11:11:12 -0700594 while (pNode && pNode->GetObjectType() != eType)
595 pNode = pNode->m_pParent;
Dan Sinclair1770c022016-03-14 14:14:16 -0400596 break;
597 case XFA_NODEITEM_PrevSibling:
598 if (m_pParent) {
599 CXFA_Node* pSibling = m_pParent->m_pChild;
600 while (pSibling && pSibling != this) {
dsinclairc5a8f212016-06-20 11:11:12 -0700601 if (eType == pSibling->GetObjectType())
Dan Sinclair1770c022016-03-14 14:14:16 -0400602 pNode = pSibling;
dsinclairc5a8f212016-06-20 11:11:12 -0700603
Dan Sinclair1770c022016-03-14 14:14:16 -0400604 pSibling = pSibling->m_pNext;
605 }
606 }
607 break;
608 default:
609 break;
610 }
611 return pNode;
612}
weili44f8faf2016-06-01 14:03:56 -0700613
Dan Sinclair1770c022016-03-14 14:14:16 -0400614int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes,
tsepez736f28a2016-03-25 14:19:51 -0700615 uint32_t dwTypeFilter,
dsinclair41cb62e2016-06-23 09:20:32 -0700616 XFA_Element eTypeFilter,
Dan Sinclair1770c022016-03-14 14:14:16 -0400617 int32_t iLevel) {
618 if (--iLevel < 0) {
619 return nodes.GetSize();
620 }
dsinclair41cb62e2016-06-23 09:20:32 -0700621 if (eTypeFilter != XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400622 CXFA_Node* pChild = m_pChild;
623 while (pChild) {
dsinclair41cb62e2016-06-23 09:20:32 -0700624 if (pChild->GetElementType() == eTypeFilter) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400625 nodes.Add(pChild);
626 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700627 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400628 }
629 }
630 pChild = pChild->m_pNext;
631 }
632 } else if (dwTypeFilter ==
633 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
634 CXFA_Node* pChild = m_pChild;
635 while (pChild) {
636 nodes.Add(pChild);
637 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700638 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400639 }
640 pChild = pChild->m_pNext;
641 }
642 } else if (dwTypeFilter != 0) {
weili44f8faf2016-06-01 14:03:56 -0700643 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
644 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
645 bool bFilterOneOfProperties =
646 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
Dan Sinclair1770c022016-03-14 14:14:16 -0400647 CXFA_Node* pChild = m_pChild;
648 while (pChild) {
649 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -0700650 GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -0400651 if (pProperty) {
652 if (bFilterProperties) {
653 nodes.Add(pChild);
654 } else if (bFilterOneOfProperties &&
655 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
656 nodes.Add(pChild);
657 } else if (bFilterChildren &&
dsinclair070fcdf2016-06-22 22:04:54 -0700658 (pChild->GetElementType() == XFA_Element::Variables ||
659 pChild->GetElementType() == XFA_Element::PageSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400660 nodes.Add(pChild);
661 }
weili44f8faf2016-06-01 14:03:56 -0700662 } else if (bFilterChildren) {
663 nodes.Add(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400664 }
665 pChild = pChild->m_pNext;
666 }
667 if (bFilterOneOfProperties && nodes.GetSize() < 1) {
668 int32_t iProperties = 0;
669 const XFA_PROPERTY* pProperty =
dsinclair070fcdf2016-06-22 22:04:54 -0700670 XFA_GetElementProperties(GetElementType(), iProperties);
weili44f8faf2016-06-01 14:03:56 -0700671 if (!pProperty || iProperties < 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400672 return 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400673 for (int32_t i = 0; i < iProperties; i++) {
674 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400675 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
676 CXFA_Node* pNewNode =
dsinclaira1b07722016-07-11 08:20:58 -0700677 m_pDocument->CreateNode(pPacket, pProperty[i].eName);
weili44f8faf2016-06-01 14:03:56 -0700678 if (!pNewNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400679 break;
weili44f8faf2016-06-01 14:03:56 -0700680 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -0700681 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400682 nodes.Add(pNewNode);
683 break;
684 }
685 }
686 }
687 }
688 return nodes.GetSize();
689}
weili44f8faf2016-06-01 14:03:56 -0700690
dsinclair41cb62e2016-06-23 09:20:32 -0700691CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
tsepez736f28a2016-03-25 14:19:51 -0700692 uint32_t dwFlags) {
dsinclaira1b07722016-07-11 08:20:58 -0700693 CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
thestigb1a59592016-04-14 18:29:56 -0700694 pNode->SetFlag(dwFlags, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400695 return pNode;
696}
weili44f8faf2016-06-01 14:03:56 -0700697
tsepezd19e9122016-11-02 15:43:18 -0700698CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) {
dsinclair43854a52016-04-27 12:26:00 -0700699 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
dsinclaira1b07722016-07-11 08:20:58 -0700700 CXFA_Node* pClone =
701 m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700702 if (!pClone)
703 return nullptr;
704
Dan Sinclair1770c022016-03-14 14:14:16 -0400705 pClone->SetTemplateNode(this);
706 pClone->UpdateNameHash();
707 pClone->SetXMLMappingNode(GetXMLMappingNode());
708 if (bRecursive) {
709 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
710 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
711 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
712 }
713 }
dsinclairc5a8f212016-06-20 11:11:12 -0700714 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400715 return pClone;
716}
717
718CXFA_Node* CXFA_Node::GetTemplateNode() const {
719 return m_pAuxNode;
720}
721
722void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
723 m_pAuxNode = pTemplateNode;
724}
weili44f8faf2016-06-01 14:03:56 -0700725
Dan Sinclair1770c022016-03-14 14:14:16 -0400726CXFA_Node* CXFA_Node::GetBindData() {
727 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
728 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
729}
weili44f8faf2016-06-01 14:03:56 -0700730
Dan Sinclair1770c022016-03-14 14:14:16 -0400731int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) {
dsinclairc5a8f212016-06-20 11:11:12 -0700732 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700733 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400734 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
735 formItems.Copy(*pItems);
736 return formItems.GetSize();
737 }
738 CXFA_Node* pFormNode =
739 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
weili44f8faf2016-06-01 14:03:56 -0700740 if (pFormNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400741 formItems.Add(pFormNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400742 return formItems.GetSize();
743}
744
Dan Sinclair1770c022016-03-14 14:14:16 -0400745int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
746 ASSERT(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700747 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700748 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400749 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
750 ASSERT(pItems);
751 if (pItems->Find(pFormNode) < 0) {
752 pItems->Add(pFormNode);
753 }
754 return pItems->GetSize();
755 }
756 CXFA_Node* pOldFormItem =
757 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
758 if (!pOldFormItem) {
759 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
760 return 1;
761 } else if (pOldFormItem == pFormNode) {
762 return 1;
763 }
764 CXFA_NodeArray* pItems = new CXFA_NodeArray;
765 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
766 pItems->Add(pOldFormItem);
767 pItems->Add(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700768 m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400769 return 2;
770}
weili44f8faf2016-06-01 14:03:56 -0700771
Dan Sinclair1770c022016-03-14 14:14:16 -0400772int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
dsinclairc5a8f212016-06-20 11:11:12 -0700773 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700774 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400775 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
776 ASSERT(pItems);
777 int32_t iIndex = pItems->Find(pFormNode);
778 int32_t iCount = pItems->GetSize();
779 if (iIndex >= 0) {
weili44f8faf2016-06-01 14:03:56 -0700780 if (iIndex != iCount - 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400781 pItems->SetAt(iIndex, pItems->GetAt(iCount - 1));
Dan Sinclair1770c022016-03-14 14:14:16 -0400782 pItems->RemoveAt(iCount - 1);
783 if (iCount == 2) {
784 CXFA_Node* pLastFormNode = pItems->GetAt(0);
785 SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700786 m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400787 }
788 iCount--;
789 }
790 return iCount;
791 }
792 CXFA_Node* pOldFormItem =
793 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
794 if (pOldFormItem == pFormNode) {
weili44f8faf2016-06-01 14:03:56 -0700795 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
796 pOldFormItem = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400797 }
weili44f8faf2016-06-01 14:03:56 -0700798 return pOldFormItem ? 1 : 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400799}
weili44f8faf2016-06-01 14:03:56 -0700800
tsepezd19e9122016-11-02 15:43:18 -0700801bool CXFA_Node::HasBindItem() {
weili44f8faf2016-06-01 14:03:56 -0700802 return GetPacketID() == XFA_XDPPACKET_Datasets &&
803 GetObject(XFA_ATTRIBUTE_BindingNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400804}
weili44f8faf2016-06-01 14:03:56 -0700805
Dan Sinclair1770c022016-03-14 14:14:16 -0400806CXFA_WidgetData* CXFA_Node::GetWidgetData() {
807 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
808}
weili44f8faf2016-06-01 14:03:56 -0700809
Dan Sinclair1770c022016-03-14 14:14:16 -0400810CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
weili44f8faf2016-06-01 14:03:56 -0700811 if (GetPacketID() != XFA_XDPPACKET_Form)
812 return nullptr;
dsinclair41cb62e2016-06-23 09:20:32 -0700813 XFA_Element eType = GetElementType();
814 if (eType == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700815 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400816 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700817 if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700818 return nullptr;
819
dsinclair41cb62e2016-06-23 09:20:32 -0700820 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400821 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
822 if (pFieldWidgetData &&
823 pFieldWidgetData->GetChoiceListOpen() ==
824 XFA_ATTRIBUTEENUM_MultiSelect) {
weili44f8faf2016-06-01 14:03:56 -0700825 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400826 } else {
827 CFX_WideString wsPicture;
828 if (pFieldWidgetData) {
829 pFieldWidgetData->GetPictureContent(wsPicture,
830 XFA_VALUEPICTURE_DataBind);
831 }
weili44f8faf2016-06-01 14:03:56 -0700832 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400833 return pFieldWidgetData;
Dan Sinclair1770c022016-03-14 14:14:16 -0400834 CXFA_Node* pDataNode = GetBindData();
weili44f8faf2016-06-01 14:03:56 -0700835 if (!pDataNode)
836 return nullptr;
837 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400838 CXFA_NodeArray formNodes;
839 pDataNode->GetBindItems(formNodes);
840 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
841 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -0700842 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -0400843 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400844 pFieldWidgetData = pFormNode->GetWidgetData();
845 if (pFieldWidgetData) {
846 pFieldWidgetData->GetPictureContent(wsPicture,
847 XFA_VALUEPICTURE_DataBind);
848 }
weili44f8faf2016-06-01 14:03:56 -0700849 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400850 break;
weili44f8faf2016-06-01 14:03:56 -0700851 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400852 }
853 return pFieldWidgetData;
854 }
855 }
856 CXFA_Node* pGrandNode =
weili44f8faf2016-06-01 14:03:56 -0700857 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400858 CXFA_Node* pValueNode =
dsinclair070fcdf2016-06-22 22:04:54 -0700859 (pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
Dan Sinclair1770c022016-03-14 14:14:16 -0400860 ? pParentNode
weili44f8faf2016-06-01 14:03:56 -0700861 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400862 if (!pValueNode) {
dsinclair070fcdf2016-06-22 22:04:54 -0700863 pValueNode =
864 (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
865 ? pGrandNode
866 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400867 }
868 CXFA_Node* pParentOfValueNode =
weili44f8faf2016-06-01 14:03:56 -0700869 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400870 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
weili44f8faf2016-06-01 14:03:56 -0700871 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400872}
weili44f8faf2016-06-01 14:03:56 -0700873
tsepezd19e9122016-11-02 15:43:18 -0700874bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400875 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
dsinclair56a8b192016-06-21 14:15:25 -0700876 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
dsinclair43854a52016-04-27 12:26:00 -0700877 ASSERT(pTopSubform);
Dan Sinclair1770c022016-03-14 14:14:16 -0400878 CXFA_Node* pLocaleNode = this;
tsepezd19e9122016-11-02 15:43:18 -0700879 bool bLocale = false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400880 do {
tsepezd19e9122016-11-02 15:43:18 -0700881 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400882 if (!bLocale) {
883 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
884 }
885 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
weili44f8faf2016-06-01 14:03:56 -0700886 if (bLocale)
tsepezd19e9122016-11-02 15:43:18 -0700887 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400888 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
889 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
weili44f8faf2016-06-01 14:03:56 -0700890 if (!wsLocaleName.IsEmpty())
tsepezd19e9122016-11-02 15:43:18 -0700891 return true;
weili44f8faf2016-06-01 14:03:56 -0700892 if (pTopSubform &&
tsepezd19e9122016-11-02 15:43:18 -0700893 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) {
894 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400895 }
896 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
897 if (pLocale) {
898 wsLocaleName = pLocale->GetName();
tsepezd19e9122016-11-02 15:43:18 -0700899 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400900 }
tsepezd19e9122016-11-02 15:43:18 -0700901 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400902}
weili44f8faf2016-06-01 14:03:56 -0700903
Dan Sinclair1770c022016-03-14 14:14:16 -0400904XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
dsinclair56a8b192016-06-21 14:15:25 -0700905 CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
Dan Sinclair1770c022016-03-14 14:14:16 -0400906 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
907 if (pKeep) {
908 XFA_ATTRIBUTEENUM eIntact;
tsepezd19e9122016-11-02 15:43:18 -0700909 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400910 if (eIntact == XFA_ATTRIBUTEENUM_None &&
911 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
912 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
dsinclairc5a8f212016-06-20 11:11:12 -0700913 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
914 XFA_ObjectType::ContainerNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400915 if (pPreviewRow &&
916 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
917 XFA_ATTRIBUTEENUM_Row) {
918 XFA_ATTRIBUTEENUM eValue;
tsepezd19e9122016-11-02 15:43:18 -0700919 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700920 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
921 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
922 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400923 }
weili44f8faf2016-06-01 14:03:56 -0700924 CXFA_Node* pNode =
dsinclair56a8b192016-06-21 14:15:25 -0700925 pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
tsepezd19e9122016-11-02 15:43:18 -0700926 if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700927 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
928 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
929 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400930 }
931 }
932 }
933 return eIntact;
934 }
935 }
dsinclair41cb62e2016-06-23 09:20:32 -0700936 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700937 case XFA_Element::Subform:
Dan Sinclair1770c022016-03-14 14:14:16 -0400938 switch (eLayoutType) {
939 case XFA_ATTRIBUTEENUM_Position:
940 case XFA_ATTRIBUTEENUM_Row:
941 return XFA_ATTRIBUTEENUM_ContentArea;
942 case XFA_ATTRIBUTEENUM_Tb:
943 case XFA_ATTRIBUTEENUM_Table:
944 case XFA_ATTRIBUTEENUM_Lr_tb:
945 case XFA_ATTRIBUTEENUM_Rl_tb:
946 return XFA_ATTRIBUTEENUM_None;
947 default:
948 break;
949 }
950 break;
dsinclair56a8b192016-06-21 14:15:25 -0700951 case XFA_Element::Field: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400952 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700953 if (!pParentNode ||
954 pParentNode->GetElementType() == XFA_Element::PageArea)
Dan Sinclair1770c022016-03-14 14:14:16 -0400955 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400956 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
957 XFA_ATTRIBUTEENUM eParLayout =
958 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
959 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
960 eParLayout == XFA_ATTRIBUTEENUM_Row ||
961 eParLayout == XFA_ATTRIBUTEENUM_Table) {
962 return XFA_ATTRIBUTEENUM_None;
963 }
964 XFA_VERSION version = m_pDocument->GetCurVersionMode();
965 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
966 CXFA_Measurement measureH;
tsepezd19e9122016-11-02 15:43:18 -0700967 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false))
Dan Sinclair1770c022016-03-14 14:14:16 -0400968 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400969 }
970 return XFA_ATTRIBUTEENUM_None;
971 }
972 return XFA_ATTRIBUTEENUM_ContentArea;
973 }
dsinclair56a8b192016-06-21 14:15:25 -0700974 case XFA_Element::Draw:
Dan Sinclair1770c022016-03-14 14:14:16 -0400975 return XFA_ATTRIBUTEENUM_ContentArea;
976 default:
977 break;
978 }
979 return XFA_ATTRIBUTEENUM_None;
980}
weili44f8faf2016-06-01 14:03:56 -0700981
Dan Sinclair1770c022016-03-14 14:14:16 -0400982CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
weili44f8faf2016-06-01 14:03:56 -0700983 if (m_ePacket == XFA_XDPPACKET_Datasets)
Dan Sinclair1770c022016-03-14 14:14:16 -0400984 return m_pAuxNode;
weili44f8faf2016-06-01 14:03:56 -0700985 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400986}
weili44f8faf2016-06-01 14:03:56 -0700987
Dan Sinclair1770c022016-03-14 14:14:16 -0400988void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
dsinclair43854a52016-04-27 12:26:00 -0700989 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
Dan Sinclair1770c022016-03-14 14:14:16 -0400990 m_pAuxNode = pDataDescriptionNode;
991}
weili44f8faf2016-06-01 14:03:56 -0700992
Dan Sinclair1770c022016-03-14 14:14:16 -0400993void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
994 int32_t iLength = pArguments->GetLength();
995 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -0700996 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNode");
Dan Sinclair1770c022016-03-14 14:14:16 -0400997 return;
998 }
tsepez6fe7d212016-04-06 10:51:14 -0700999 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001000 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclairdf4bc592016-03-31 20:34:43 -07001001 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001002 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001003 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001004 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001005 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001006 refNode = ToNode(pScriptContext->GetThisObject());
tsepez736f28a2016-03-25 14:19:51 -07001007 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001008 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1009 XFA_RESOLVENODE_Siblings;
1010 XFA_RESOLVENODE_RS resoveNodeRS;
tsepezfc58ad12016-04-05 12:22:15 -07001011 int32_t iRet = pScriptContext->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001012 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
dsinclairf27aeec2016-06-07 19:36:18 -07001013 if (iRet < 1) {
1014 pArguments->GetReturnValue()->SetNull();
1015 return;
1016 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001017 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1018 CXFA_Object* pNode = resoveNodeRS.nodes[0];
dsinclairf27aeec2016-06-07 19:36:18 -07001019 pArguments->GetReturnValue()->Assign(
1020 pScriptContext->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001021 } else {
1022 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
1023 resoveNodeRS.pScriptAttribute;
1024 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
dsinclair86fad992016-05-31 11:34:04 -07001025 std::unique_ptr<CFXJSE_Value> pValue(
1026 new CFXJSE_Value(pScriptContext->GetRuntime()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001027 (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))(
tsepezd19e9122016-11-02 15:43:18 -07001028 pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
dsinclairf27aeec2016-06-07 19:36:18 -07001029 pArguments->GetReturnValue()->Assign(pValue.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001030 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001031 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001032 }
1033 }
1034}
weili44f8faf2016-06-01 14:03:56 -07001035
Dan Sinclair1770c022016-03-14 14:14:16 -04001036void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
1037 int32_t iLength = pArguments->GetLength();
1038 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001039 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04001040 return;
1041 }
tsepez6fe7d212016-04-06 10:51:14 -07001042 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001043 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclair12a6b0c2016-05-26 11:14:08 -07001044 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001045 if (!pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04001046 return;
tsepez736f28a2016-03-25 14:19:51 -07001047 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001048 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1049 XFA_RESOLVENODE_Siblings;
1050 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001051 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001052 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
dsinclair12a6b0c2016-05-26 11:14:08 -07001053 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001054}
weili44f8faf2016-06-01 14:03:56 -07001055
dsinclair12a6b0c2016-05-26 11:14:08 -07001056void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001057 CFX_WideString wsExpression,
tsepez736f28a2016-03-25 14:19:51 -07001058 uint32_t dwFlag,
Dan Sinclair1770c022016-03-14 14:14:16 -04001059 CXFA_Node* refNode) {
dsinclairdf4bc592016-03-31 20:34:43 -07001060 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001061 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001062 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001063 XFA_RESOLVENODE_RS resoveNodeRS;
weili44f8faf2016-06-01 14:03:56 -07001064 if (!refNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04001065 refNode = this;
tsepez4c3debb2016-04-08 12:20:38 -07001066 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
tsepezfc58ad12016-04-05 12:22:15 -07001067 resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001068 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
1069 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1070 for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) {
1071 if (resoveNodeRS.nodes[i]->IsNode())
1072 pNodeList->Append(resoveNodeRS.nodes[i]->AsNode());
1073 }
1074 } else {
dsinclair12a6b0c2016-05-26 11:14:08 -07001075 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
1076 if (resoveNodeRS.GetAttributeResult(valueArray) > 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001077 CXFA_ObjArray objectArray;
dsinclair12a6b0c2016-05-26 11:14:08 -07001078 valueArray.GetAttributeObject(objectArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04001079 for (int32_t i = 0; i < objectArray.GetSize(); i++) {
1080 if (objectArray[i]->IsNode())
1081 pNodeList->Append(objectArray[i]->AsNode());
1082 }
1083 }
1084 }
dsinclairf27aeec2016-06-07 19:36:18 -07001085 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001086}
weili44f8faf2016-06-01 14:03:56 -07001087
dsinclair12a6b0c2016-05-26 11:14:08 -07001088void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001089 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001090 XFA_ATTRIBUTE eAttribute) {
1091 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001092 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001093 } else {
tsepez736f28a2016-03-25 14:19:51 -07001094 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
Dan Sinclair1770c022016-03-14 14:14:16 -04001095 CFX_WideString wsName;
1096 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
1097 CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]");
dsinclair12a6b0c2016-05-26 11:14:08 -07001098 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001099 }
1100}
weili44f8faf2016-06-01 14:03:56 -07001101
dsinclair12a6b0c2016-05-26 11:14:08 -07001102void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001103 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001104 XFA_ATTRIBUTE eAttribute) {
dsinclairdf4bc592016-03-31 20:34:43 -07001105 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001106 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001107 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001108 if (bSetting) {
1109 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider();
dsinclair43854a52016-04-27 12:26:00 -07001110 ASSERT(pAppProvider);
Dan Sinclair1770c022016-03-14 14:14:16 -04001111 CFX_WideString wsMessage;
1112 pAppProvider->LoadString(XFA_IDS_Unable_TO_SET, wsMessage);
tsepez28f97ff2016-04-04 16:41:35 -07001113 FXJSE_ThrowMessage(
tsepezbd9748d2016-04-13 21:40:19 -07001114 FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001115 } else {
1116 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
dsinclairf27aeec2016-06-07 19:36:18 -07001117 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001118 }
1119}
weili44f8faf2016-06-01 14:03:56 -07001120
dsinclair12a6b0c2016-05-26 11:14:08 -07001121void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001122 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001123 XFA_ATTRIBUTE eAttribute) {
1124 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001125 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001126 } else {
tsepez736f28a2016-03-25 14:19:51 -07001127 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
dsinclair017052a2016-06-28 07:43:51 -07001128 CFX_WideString wsExpression =
1129 FX_WSTRC(L"#") + GetClassName() + FX_WSTRC(L"[*]");
dsinclair12a6b0c2016-05-26 11:14:08 -07001130 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001131 }
1132}
weili44f8faf2016-06-01 14:03:56 -07001133
dsinclair12a6b0c2016-05-26 11:14:08 -07001134void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001135 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001136 XFA_ATTRIBUTE eAttribute) {
1137 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001138 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001139 } else {
1140 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
1141 if (pParent) {
dsinclairf27aeec2016-06-07 19:36:18 -07001142 pValue->Assign(
1143 m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001144 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001145 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001146 }
1147 }
1148}
weili44f8faf2016-06-01 14:03:56 -07001149
dsinclair12a6b0c2016-05-26 11:14:08 -07001150void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001151 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001152 XFA_ATTRIBUTE eAttribute) {
weili44f8faf2016-06-01 14:03:56 -07001153 if (bSetting)
dsinclair2235b7b2016-06-02 07:42:25 -07001154 ThrowException(XFA_IDS_INVAlID_PROP_SET);
weili44f8faf2016-06-01 14:03:56 -07001155 else
dsinclairf27aeec2016-06-07 19:36:18 -07001156 pValue->SetInteger(GetNodeSameNameIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001157}
weili44f8faf2016-06-01 14:03:56 -07001158
dsinclair12a6b0c2016-05-26 11:14:08 -07001159void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001160 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001161 XFA_ATTRIBUTE eAttribute) {
weili44f8faf2016-06-01 14:03:56 -07001162 if (bSetting)
dsinclair2235b7b2016-06-02 07:42:25 -07001163 ThrowException(XFA_IDS_INVAlID_PROP_SET);
weili44f8faf2016-06-01 14:03:56 -07001164 else
dsinclairf27aeec2016-06-07 19:36:18 -07001165 pValue->SetInteger(GetNodeSameClassIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001166}
weili44f8faf2016-06-01 14:03:56 -07001167
dsinclair12a6b0c2016-05-26 11:14:08 -07001168void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001169 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001170 XFA_ATTRIBUTE eAttribute) {
1171 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001172 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001173 } else {
1174 CFX_WideString wsSOMExpression;
1175 GetSOMExpression(wsSOMExpression);
dsinclairf27aeec2016-06-07 19:36:18 -07001176 pValue->SetString(FX_UTF8Encode(wsSOMExpression).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001177 }
1178}
weili44f8faf2016-06-01 14:03:56 -07001179
Dan Sinclair1770c022016-03-14 14:14:16 -04001180void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
1181 int32_t iLength = pArguments->GetLength();
1182 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001183 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"applyXSL");
Dan Sinclair1770c022016-03-14 14:14:16 -04001184 return;
1185 }
tsepez6fe7d212016-04-06 10:51:14 -07001186 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001187 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili60607c32016-05-26 11:53:12 -07001188 // TODO(weili): check whether we need to implement this, pdfium:501.
1189 // For now, just put the variables here to avoid unused variable warning.
1190 (void)wsExpression;
Dan Sinclair1770c022016-03-14 14:14:16 -04001191}
weili60607c32016-05-26 11:53:12 -07001192
Dan Sinclair1770c022016-03-14 14:14:16 -04001193void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
1194 int32_t iLength = pArguments->GetLength();
1195 if (iLength < 1 || iLength > 3) {
dsinclair2235b7b2016-06-02 07:42:25 -07001196 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"assignNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04001197 return;
1198 }
1199 CFX_WideString wsExpression;
1200 CFX_WideString wsValue;
1201 int32_t iAction = 0;
weili44f8faf2016-06-01 14:03:56 -07001202 wsExpression =
1203 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001204 if (iLength >= 2) {
weili60607c32016-05-26 11:53:12 -07001205 wsValue =
1206 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001207 }
weili60607c32016-05-26 11:53:12 -07001208 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001209 iAction = pArguments->GetInt32(2);
weili60607c32016-05-26 11:53:12 -07001210 // TODO(weili): check whether we need to implement this, pdfium:501.
1211 // For now, just put the variables here to avoid unused variable warning.
1212 (void)wsExpression;
1213 (void)wsValue;
1214 (void)iAction;
Dan Sinclair1770c022016-03-14 14:14:16 -04001215}
weili60607c32016-05-26 11:53:12 -07001216
Dan Sinclair1770c022016-03-14 14:14:16 -04001217void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
1218 int32_t iLength = pArguments->GetLength();
1219 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001220 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clone");
Dan Sinclair1770c022016-03-14 14:14:16 -04001221 return;
1222 }
weili44f8faf2016-06-01 14:03:56 -07001223 bool bClone = !!pArguments->GetInt32(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001224 CXFA_Node* pCloneNode = Clone(bClone);
dsinclairf27aeec2016-06-07 19:36:18 -07001225 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001226 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
1227}
weili44f8faf2016-06-01 14:03:56 -07001228
Dan Sinclair1770c022016-03-14 14:14:16 -04001229void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
1230 int32_t iLength = pArguments->GetLength();
1231 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001232 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001233 return;
1234 }
tsepez6fe7d212016-04-06 10:51:14 -07001235 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001236 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001237 CFX_WideString wsValue;
tsepez4c3debb2016-04-08 12:20:38 -07001238 GetAttribute(wsExpression.AsStringC(), wsValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07001239 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001240 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001241 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001242}
weili44f8faf2016-06-01 14:03:56 -07001243
Dan Sinclair1770c022016-03-14 14:14:16 -04001244void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
1245 int32_t iLength = pArguments->GetLength();
1246 if (iLength < 1 || iLength > 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07001247 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001248 return;
1249 }
1250 CFX_WideString wsExpression;
1251 int32_t iValue = 0;
weili44f8faf2016-06-01 14:03:56 -07001252 wsExpression =
1253 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1254 if (iLength >= 2)
Dan Sinclair1770c022016-03-14 14:14:16 -04001255 iValue = pArguments->GetInt32(1);
dsinclair6e124782016-06-23 12:14:55 -07001256 CXFA_Node* pNode =
1257 GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
dsinclairf27aeec2016-06-07 19:36:18 -07001258 pArguments->GetReturnValue()->Assign(
1259 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001260}
weili65be4b12016-05-25 15:47:43 -07001261
Dan Sinclair1770c022016-03-14 14:14:16 -04001262void CXFA_Node::Script_NodeClass_IsPropertySpecified(
1263 CFXJSE_Arguments* pArguments) {
1264 int32_t iLength = pArguments->GetLength();
1265 if (iLength < 1 || iLength > 3) {
dsinclair2235b7b2016-06-02 07:42:25 -07001266 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isPropertySpecified");
Dan Sinclair1770c022016-03-14 14:14:16 -04001267 return;
1268 }
1269 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001270 bool bParent = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001271 int32_t iIndex = 0;
weili44f8faf2016-06-01 14:03:56 -07001272 wsExpression =
1273 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili65be4b12016-05-25 15:47:43 -07001274 if (iLength >= 2)
weili44f8faf2016-06-01 14:03:56 -07001275 bParent = !!pArguments->GetInt32(1);
weili65be4b12016-05-25 15:47:43 -07001276 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001277 iIndex = pArguments->GetInt32(2);
tsepezd19e9122016-11-02 15:43:18 -07001278 bool bHas = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001279 const XFA_ATTRIBUTEINFO* pAttributeInfo =
tsepez4c3debb2016-04-08 12:20:38 -07001280 XFA_GetAttributeByName(wsExpression.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001281 CFX_WideString wsValue;
weili65be4b12016-05-25 15:47:43 -07001282 if (pAttributeInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04001283 bHas = HasAttribute(pAttributeInfo->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04001284 if (!bHas) {
dsinclair6e124782016-06-23 12:14:55 -07001285 XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
1286 bHas = !!GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001287 if (!bHas && bParent && m_pParent) {
1288 // Also check on the parent.
1289 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
1290 if (!bHas)
dsinclair6e124782016-06-23 12:14:55 -07001291 bHas = !!m_pParent->GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001292 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001293 }
dsinclair12a6b0c2016-05-26 11:14:08 -07001294 CFXJSE_Value* pValue = pArguments->GetReturnValue();
1295 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001296 pValue->SetBoolean(bHas);
Dan Sinclair1770c022016-03-14 14:14:16 -04001297}
weili65be4b12016-05-25 15:47:43 -07001298
Dan Sinclair1770c022016-03-14 14:14:16 -04001299void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
1300 int32_t iLength = pArguments->GetLength();
1301 if (iLength < 1 || iLength > 3) {
dsinclair2235b7b2016-06-02 07:42:25 -07001302 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001303 return;
1304 }
1305 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001306 bool bIgnoreRoot = true;
1307 bool bOverwrite = 0;
1308 wsExpression =
1309 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1310 if (wsExpression.IsEmpty())
Tom Sepezd3743ea2016-05-16 15:56:53 -07001311 return;
weili44f8faf2016-06-01 14:03:56 -07001312 if (iLength >= 2)
1313 bIgnoreRoot = !!pArguments->GetInt32(1);
1314 if (iLength >= 3)
1315 bOverwrite = !!pArguments->GetInt32(2);
dsinclaira1b07722016-07-11 08:20:58 -07001316 std::unique_ptr<CXFA_SimpleParser> pParser(
1317 new CXFA_SimpleParser(m_pDocument, false));
weili44f8faf2016-06-01 14:03:56 -07001318 if (!pParser)
Dan Sinclair1770c022016-03-14 14:14:16 -04001319 return;
weili44f8faf2016-06-01 14:03:56 -07001320 CFDE_XMLNode* pXMLNode = nullptr;
1321 int32_t iParserStatus =
1322 pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
1323 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
1324 return;
dsinclairae95f762016-03-29 16:58:29 -07001325 if (bIgnoreRoot &&
1326 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
1327 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
weili44f8faf2016-06-01 14:03:56 -07001328 bIgnoreRoot = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001329 }
tsepezd19e9122016-11-02 15:43:18 -07001330 CXFA_Node* pFakeRoot = Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001331 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
1332 if (!wsContentType.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07001333 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
1334 CFX_WideString(wsContentType));
Dan Sinclair1770c022016-03-14 14:14:16 -04001335 }
dsinclairae95f762016-03-29 16:58:29 -07001336 CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001337 if (!pFakeXMLRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001338 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
tsepezd19e9122016-11-02 15:43:18 -07001339 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001340 }
dsinclair017052a2016-06-28 07:43:51 -07001341 if (!pFakeXMLRoot)
1342 pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName()));
1343
Dan Sinclair1770c022016-03-14 14:14:16 -04001344 if (bIgnoreRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001345 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001346 while (pXMLChild) {
dsinclairae95f762016-03-29 16:58:29 -07001347 CFDE_XMLNode* pXMLSibling =
1348 pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001349 pXMLNode->RemoveChildNode(pXMLChild);
1350 pFakeXMLRoot->InsertChildNode(pXMLChild);
1351 pXMLChild = pXMLSibling;
1352 }
1353 } else {
dsinclairae95f762016-03-29 16:58:29 -07001354 CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001355 if (pXMLParent) {
1356 pXMLParent->RemoveChildNode(pXMLNode);
1357 }
1358 pFakeXMLRoot->InsertChildNode(pXMLNode);
1359 }
1360 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot);
1361 pFakeRoot = pParser->GetRootNode();
1362 if (pFakeRoot) {
1363 if (bOverwrite) {
1364 CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1365 CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1366 int32_t index = 0;
1367 while (pNewChild) {
1368 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1369 pFakeRoot->RemoveChild(pNewChild);
1370 InsertChild(index++, pNewChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001371 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001372 pNewChild = pItem;
1373 }
1374 while (pChild) {
1375 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1376 RemoveChild(pChild);
1377 pFakeRoot->InsertChild(pChild);
1378 pChild = pItem;
1379 }
1380 if (GetPacketID() == XFA_XDPPACKET_Form &&
dsinclair070fcdf2016-06-22 22:04:54 -07001381 GetElementType() == XFA_Element::ExData) {
dsinclairae95f762016-03-29 16:58:29 -07001382 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001383 SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001384 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
weili44f8faf2016-06-01 14:03:56 -07001385 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001386 pFakeXMLRoot = pTempXMLNode;
1387 } else {
weili44f8faf2016-06-01 14:03:56 -07001388 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001389 }
1390 }
tsepezd19e9122016-11-02 15:43:18 -07001391 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001392 } else {
1393 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1394 while (pChild) {
1395 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1396 pFakeRoot->RemoveChild(pChild);
1397 InsertChild(pChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001398 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001399 pChild = pItem;
1400 }
1401 }
1402 if (pFakeXMLRoot) {
1403 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001404 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001405 }
dsinclairc5a8f212016-06-20 11:11:12 -07001406 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001407 } else {
Tom Sepezd3743ea2016-05-16 15:56:53 -07001408 if (pFakeXMLRoot) {
1409 pFakeXMLRoot->Release();
weili44f8faf2016-06-01 14:03:56 -07001410 pFakeXMLRoot = nullptr;
Tom Sepezd3743ea2016-05-16 15:56:53 -07001411 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001412 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001413}
weili44f8faf2016-06-01 14:03:56 -07001414
Dan Sinclair1770c022016-03-14 14:14:16 -04001415void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
weili44f8faf2016-06-01 14:03:56 -07001416 // TODO(weili): Check whether we need to implement this, pdfium:501.
Dan Sinclair1770c022016-03-14 14:14:16 -04001417}
1418
1419void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1420 int32_t iLength = pArguments->GetLength();
1421 if (iLength < 0 || iLength > 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001422 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001423 return;
1424 }
weili44f8faf2016-06-01 14:03:56 -07001425 bool bPrettyMode = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001426 if (iLength == 1) {
weili65be4b12016-05-25 15:47:43 -07001427 if (pArguments->GetUTF8String(0) != "pretty") {
dsinclair2235b7b2016-06-02 07:42:25 -07001428 ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
Dan Sinclair1770c022016-03-14 14:14:16 -04001429 return;
1430 }
weili44f8faf2016-06-01 14:03:56 -07001431 bPrettyMode = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001432 }
1433 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
weili65be4b12016-05-25 15:47:43 -07001434 if (GetPacketID() == XFA_XDPPACKET_Form ||
1435 GetPacketID() == XFA_XDPPACKET_Datasets) {
1436 CFDE_XMLNode* pElement = nullptr;
1437 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1438 pElement = GetXMLMappingNode();
1439 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
dsinclairf27aeec2016-06-07 19:36:18 -07001440 pArguments->GetReturnValue()->SetString(bsXMLHeader);
weili65be4b12016-05-25 15:47:43 -07001441 return;
1442 }
1443 XFA_DataExporter_DealWithDataGroupNode(this);
1444 }
tsepez833619b2016-12-07 09:21:17 -08001445 CFX_RetainPtr<IFX_MemoryStream> pMemoryStream =
1446 IFX_MemoryStream::Create(true);
1447
1448 // Note: ambiguious below without static_cast.
tsepez7cda31a2016-12-07 12:10:20 -08001449 CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream(
1450 CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream),
1451 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
tsepez833619b2016-12-07 09:21:17 -08001452
Dan Sinclair1770c022016-03-14 14:14:16 -04001453 if (!pStream) {
dsinclairf27aeec2016-06-07 19:36:18 -07001454 pArguments->GetReturnValue()->SetString(bsXMLHeader);
Dan Sinclair1770c022016-03-14 14:14:16 -04001455 return;
1456 }
1457 pStream->SetCodePage(FX_CODEPAGE_UTF8);
dsinclair179bebb2016-04-05 11:02:18 -07001458 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
weili65be4b12016-05-25 15:47:43 -07001459 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepez7cda31a2016-12-07 12:10:20 -08001460 XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001461 else
tsepez7cda31a2016-12-07 12:10:20 -08001462 pElement->SaveXMLNode(pStream);
weili65be4b12016-05-25 15:47:43 -07001463 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1464 // For now, just put it here to avoid unused variable warning.
1465 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001466 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001467 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001468 return;
1469 }
dsinclairf27aeec2016-06-07 19:36:18 -07001470 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001471}
1472
1473void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1474 int32_t iLength = pArguments->GetLength();
1475 if (iLength != 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07001476 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001477 return;
1478 }
tsepez6fe7d212016-04-06 10:51:14 -07001479 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001480 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001481 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001482 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001483 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001484}
weili60607c32016-05-26 11:53:12 -07001485
Dan Sinclair1770c022016-03-14 14:14:16 -04001486void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1487 int32_t iLength = pArguments->GetLength();
1488 if (iLength != 1 && iLength != 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07001489 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001490 return;
1491 }
weili60607c32016-05-26 11:53:12 -07001492 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001493 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001494 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1495 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001496 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001497 // TODO(weili): check whether we need to implement this, pdfium:501.
1498 // For now, just put the variables here to avoid unused variable warning.
1499 (void)pNode;
1500 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001501}
weili60607c32016-05-26 11:53:12 -07001502
dsinclair12a6b0c2016-05-26 11:14:08 -07001503void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001504 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001505 XFA_ATTRIBUTE eAttribute) {
1506 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001507 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001508 } else {
1509 CFX_WideString wsNameSpace;
1510 TryNamespace(wsNameSpace);
dsinclairf27aeec2016-06-07 19:36:18 -07001511 pValue->SetString(FX_UTF8Encode(wsNameSpace).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001512 }
1513}
weili44f8faf2016-06-01 14:03:56 -07001514
dsinclair12a6b0c2016-05-26 11:14:08 -07001515void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001516 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001517 XFA_ATTRIBUTE eAttribute) {
1518 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001519 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001520 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001521 pValue->Assign(
1522 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001523 }
1524}
weili44f8faf2016-06-01 14:03:56 -07001525
dsinclair12a6b0c2016-05-26 11:14:08 -07001526void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001527 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001528 XFA_ATTRIBUTE eAttribute) {
weili44f8faf2016-06-01 14:03:56 -07001529 if (bSetting)
dsinclair2235b7b2016-06-02 07:42:25 -07001530 ThrowException(XFA_IDS_INVAlID_PROP_SET);
weili44f8faf2016-06-01 14:03:56 -07001531 else
dsinclairf27aeec2016-06-07 19:36:18 -07001532 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001533}
weili44f8faf2016-06-01 14:03:56 -07001534
dsinclair12a6b0c2016-05-26 11:14:08 -07001535void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001536 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001537 XFA_ATTRIBUTE eAttribute) {
1538 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001539 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001540 } else {
dsinclair070fcdf2016-06-22 22:04:54 -07001541 if (GetElementType() == XFA_Element::Subform) {
tsepezd19e9122016-11-02 15:43:18 -07001542 pValue->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001543 return;
1544 }
1545 CFX_WideString strValue;
dsinclairf27aeec2016-06-07 19:36:18 -07001546 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001547 }
1548}
weili44f8faf2016-06-01 14:03:56 -07001549
dsinclair12a6b0c2016-05-26 11:14:08 -07001550void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001551 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001552 XFA_ATTRIBUTE eAttribute) {
1553 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001554 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001555 } else {
1556 CXFA_NodeArray properts;
1557 int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty);
1558 if (iSize > 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07001559 pValue->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001560 m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0]));
1561 }
1562 }
1563}
weili44f8faf2016-06-01 14:03:56 -07001564
Dan Sinclair1770c022016-03-14 14:14:16 -04001565void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001566
Dan Sinclair1770c022016-03-14 14:14:16 -04001567void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1568 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001569 pArguments->GetReturnValue()->SetObject(
1570 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001571}
1572void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1573}
dsinclair5b36f0a2016-07-19 10:56:23 -07001574
Dan Sinclair1770c022016-03-14 14:14:16 -04001575void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1576 Script_Template_CreateNode(pArguments);
1577}
dsinclair5b36f0a2016-07-19 10:56:23 -07001578
Dan Sinclair1770c022016-03-14 14:14:16 -04001579void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1580 int32_t iLength = pArguments->GetLength();
1581 if (iLength < 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001582 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001583 return;
1584 }
1585 CFX_WideString wsNameSpace;
1586 if (iLength >= 1) {
1587 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001588 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001589 }
1590 CFX_WideString wsNodeNameSpace;
1591 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001592 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001593 if (pValue)
1594 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001595}
dsinclair5b36f0a2016-07-19 10:56:23 -07001596
dsinclair12a6b0c2016-05-26 11:14:08 -07001597void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001598 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001599 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001600
dsinclair12a6b0c2016-05-26 11:14:08 -07001601void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001602 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001603 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001604
dsinclair12a6b0c2016-05-26 11:14:08 -07001605void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001606 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001607 XFA_ATTRIBUTE eAttribute) {
1608 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001609 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001610 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001611 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001612 }
1613}
dsinclair5b36f0a2016-07-19 10:56:23 -07001614
dsinclair12a6b0c2016-05-26 11:14:08 -07001615void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001616 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001617 XFA_ATTRIBUTE eAttribute) {
1618 if (!bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001619 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001620 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001621 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001622 }
1623}
dsinclair5b36f0a2016-07-19 10:56:23 -07001624
dsinclair12a6b0c2016-05-26 11:14:08 -07001625void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001626 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001627 XFA_ATTRIBUTE eAttribute) {
1628 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001629 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001630 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001631 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001632 }
1633}
dsinclair5b36f0a2016-07-19 10:56:23 -07001634
dsinclair12a6b0c2016-05-26 11:14:08 -07001635void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001636 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001637 XFA_ATTRIBUTE eAttribute) {
1638 if (!bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001639 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001640 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001641 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001642 }
1643}
thestigb1a59592016-04-14 18:29:56 -07001644
Dan Sinclair1770c022016-03-14 14:14:16 -04001645void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001646 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001647 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001648 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001649 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001650 return;
thestigb1a59592016-04-14 18:29:56 -07001651
dsinclaira1b07722016-07-11 08:20:58 -07001652 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001653 if (!pNotify)
1654 return;
1655
1656 uint32_t dwPacket = GetPacketID();
1657 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1658 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001659 return;
1660 }
thestigb1a59592016-04-14 18:29:56 -07001661
1662 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001663 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001664 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001665 bNeedFindContainer = true;
1666 pNotify->OnValueChanged(this, eAttribute, this,
1667 GetNodeItem(XFA_NODEITEM_Parent));
1668 break;
dsinclair56a8b192016-06-21 14:15:25 -07001669 case XFA_Element::Font:
1670 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001671 bNeedFindContainer = true;
1672 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001673 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001674 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1675 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1676 } else {
1677 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1678 }
1679 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001680 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001681 bNeedFindContainer = true;
1682 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001683 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001684 if (pParentNode->IsContainerNode()) {
1685 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001686 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001687 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1688 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1689 } else {
1690 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001691 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001692 pNotify->OnValueChanged(this, eAttribute, pNode,
1693 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001694 }
thestigb1a59592016-04-14 18:29:56 -07001695 }
1696 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001697 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001698 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001699 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001700 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1701 eUIType == XFA_Element::NumericEdit ||
1702 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001703 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001704 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001705 pNotify->OnValueChanged(this, eAttribute, pUINode,
1706 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001707 }
thestigb1a59592016-04-14 18:29:56 -07001708 }
1709 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001710 case XFA_Element::Button:
1711 case XFA_Element::Barcode:
1712 case XFA_Element::ChoiceList:
1713 case XFA_Element::DateTimeEdit:
1714 case XFA_Element::NumericEdit:
1715 case XFA_Element::PasswordEdit:
1716 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001717 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1718 if (pUINode) {
1719 pNotify->OnValueChanged(this, eAttribute, pUINode,
1720 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1721 }
1722 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001723 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001724 bNeedFindContainer = true;
1725 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1726 if (pUINode) {
1727 pNotify->OnValueChanged(this, eAttribute, pUINode,
1728 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1729 }
1730 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001731 case XFA_Element::Keep:
1732 case XFA_Element::Bookend:
1733 case XFA_Element::Break:
1734 case XFA_Element::BreakAfter:
1735 case XFA_Element::BreakBefore:
1736 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001737 bNeedFindContainer = true;
1738 break;
dsinclair56a8b192016-06-21 14:15:25 -07001739 case XFA_Element::Area:
1740 case XFA_Element::Draw:
1741 case XFA_Element::ExclGroup:
1742 case XFA_Element::Field:
1743 case XFA_Element::Subform:
1744 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001745 pLayoutPro->AddChangedContainer(this);
1746 pNotify->OnValueChanged(this, eAttribute, this, this);
1747 break;
dsinclair56a8b192016-06-21 14:15:25 -07001748 case XFA_Element::Sharptext:
1749 case XFA_Element::Sharpxml:
1750 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001751 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1752 if (!pTextNode) {
1753 return;
1754 }
1755 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1756 if (!pValueNode) {
1757 return;
1758 }
dsinclair41cb62e2016-06-23 09:20:32 -07001759 XFA_Element eType = pValueNode->GetElementType();
1760 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001761 bNeedFindContainer = true;
1762 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1763 if (pNode && pNode->IsContainerNode()) {
1764 if (bScriptModify) {
1765 pValueNode = pNode;
1766 }
1767 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1768 } else {
1769 pNotify->OnValueChanged(this, eAttribute, pNode,
1770 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001771 }
thestigb1a59592016-04-14 18:29:56 -07001772 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001773 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001774 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1775 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001776 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001777 }
1778 }
thestigb1a59592016-04-14 18:29:56 -07001779 }
1780 } break;
1781 default:
1782 break;
1783 }
1784 if (bNeedFindContainer) {
1785 CXFA_Node* pParent = this;
1786 while (pParent) {
1787 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001788 break;
thestigb1a59592016-04-14 18:29:56 -07001789
1790 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001791 }
thestigb1a59592016-04-14 18:29:56 -07001792 if (pParent) {
1793 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001794 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001795 }
1796}
thestigb1a59592016-04-14 18:29:56 -07001797
dsinclair12a6b0c2016-05-26 11:14:08 -07001798void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001799 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001800 XFA_ATTRIBUTE eAttribute) {
1801 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001802 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001803 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001804 if (eAttribute == XFA_ATTRIBUTE_Use &&
1805 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001806 CXFA_Node* pTemplateNode =
1807 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1808 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001809 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1810 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001811
1812 CFX_WideString wsID;
1813 CFX_WideString wsSOM;
1814 if (!wsValue.IsEmpty()) {
1815 if (wsValue[0] == '#') {
1816 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001817 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001818 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001819 }
1820 }
weili44f8faf2016-06-01 14:03:56 -07001821 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001822 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001823 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001824 XFA_RESOLVENODE_Attributes |
1825 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1826 XFA_RESOLVENODE_Siblings;
1827 XFA_RESOLVENODE_RS resoveNodeRS;
1828 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001829 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001830 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) {
1831 pProtoNode = resoveNodeRS.nodes[0]->AsNode();
1832 }
1833 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001834 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001835 }
1836 if (pProtoNode) {
1837 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1838 while (pHeadChild) {
1839 CXFA_Node* pSibling =
1840 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1841 RemoveChild(pHeadChild);
1842 pHeadChild = pSibling;
1843 }
tsepezd19e9122016-11-02 15:43:18 -07001844 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001845 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1846 while (pHeadChild) {
1847 CXFA_Node* pSibling =
1848 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1849 pProtoForm->RemoveChild(pHeadChild);
1850 InsertChild(pHeadChild);
1851 pHeadChild = pSibling;
1852 }
1853 m_pDocument->RemovePurgeNode(pProtoForm);
1854 delete pProtoForm;
1855 }
1856 }
1857 } else {
1858 CFX_WideString wsValue;
1859 GetAttribute(eAttribute, wsValue);
dsinclairf27aeec2016-06-07 19:36:18 -07001860 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07001861 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001862 }
1863}
dsinclair5b36f0a2016-07-19 10:56:23 -07001864
dsinclair12a6b0c2016-05-26 11:14:08 -07001865void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001866 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001867 XFA_ATTRIBUTE eAttribute) {
1868 if (!bSetting) {
1869 CFX_WideString wsValue;
1870 GetAttribute(eAttribute, wsValue);
dsinclairf27aeec2016-06-07 19:36:18 -07001871 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07001872 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001873 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001874 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001875 }
1876}
dsinclair5b36f0a2016-07-19 10:56:23 -07001877
Dan Sinclair1770c022016-03-14 14:14:16 -04001878void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1879 int32_t argc = pArguments->GetLength();
1880 if ((argc == 0) || (argc == 1)) {
tsepezd19e9122016-11-02 15:43:18 -07001881 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001882 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001883 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001884 }
1885}
dsinclair5b36f0a2016-07-19 10:56:23 -07001886
Dan Sinclair1770c022016-03-14 14:14:16 -04001887void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
1888 int32_t argc = pArguments->GetLength();
1889 if (argc == 0) {
1890 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001891 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001892 }
1893}
dsinclair5b36f0a2016-07-19 10:56:23 -07001894
dsinclair12a6b0c2016-05-26 11:14:08 -07001895void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001896 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001897 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001898
dsinclair12a6b0c2016-05-26 11:14:08 -07001899void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001900 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001901 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001902
dsinclair12a6b0c2016-05-26 11:14:08 -07001903void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001904 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001905 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001906
dsinclair12a6b0c2016-05-26 11:14:08 -07001907void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001908 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001909 XFA_SOM_MESSAGETYPE iMessageType) {
1910 CXFA_WidgetData* pWidgetData = GetWidgetData();
1911 if (!pWidgetData) {
1912 return;
1913 }
tsepezd19e9122016-11-02 15:43:18 -07001914 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001915 CXFA_Validate validate = pWidgetData->GetValidate();
1916 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001917 validate = pWidgetData->GetValidate(true);
1918 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001919 }
1920 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001921 switch (iMessageType) {
1922 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001923 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001924 break;
1925 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001926 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001927 break;
1928 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001929 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001930 break;
1931 default:
1932 break;
1933 }
1934 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001935 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001936 if (!pNotify) {
1937 return;
1938 }
1939 pNotify->AddCalcValidate(this);
1940 }
1941 } else {
1942 CFX_WideString wsMessage;
1943 switch (iMessageType) {
1944 case XFA_SOM_ValidationMessage:
1945 validate.GetScriptMessageText(wsMessage);
1946 break;
1947 case XFA_SOM_FormatMessage:
1948 validate.GetFormatMessageText(wsMessage);
1949 break;
1950 case XFA_SOM_MandatoryMessage:
1951 validate.GetNullMessageText(wsMessage);
1952 break;
1953 default:
1954 break;
1955 }
dsinclairf27aeec2016-06-07 19:36:18 -07001956 pValue->SetString(FX_UTF8Encode(wsMessage).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001957 }
1958}
dsinclair5b36f0a2016-07-19 10:56:23 -07001959
dsinclair12a6b0c2016-05-26 11:14:08 -07001960void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001961 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001962 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001963 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001964}
dsinclair5b36f0a2016-07-19 10:56:23 -07001965
dsinclair12a6b0c2016-05-26 11:14:08 -07001966void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001967 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001968 XFA_ATTRIBUTE eAttribute) {
1969 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001970 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001971 } else {
1972 CXFA_WidgetData* pWidgetData = GetWidgetData();
1973 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07001974 pValue->SetInteger(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001975 return;
1976 }
tsepezd19e9122016-11-02 15:43:18 -07001977 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001978 }
1979}
dsinclair5b36f0a2016-07-19 10:56:23 -07001980
dsinclair12a6b0c2016-05-26 11:14:08 -07001981void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001982 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001983 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001984 XFA_Element eType = GetElementType();
1985 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001986 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001987 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001988 }
1989 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001990 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001991 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001992 }
1993 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001994 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001995 return;
1996 }
1997 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001998 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07001999 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002000 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002001
Dan Sinclair1770c022016-03-14 14:14:16 -04002002 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07002003 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002004 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
2005 CXFA_NodeArray formNodes;
2006 GetBindItems(formNodes);
2007 CFX_WideString wsPicture;
2008 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
2009 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -07002010 if (!pFormNode || pFormNode->HasRemovedChildren()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002011 continue;
2012 }
2013 pContainerWidgetData = pFormNode->GetContainerWidgetData();
2014 if (pContainerWidgetData) {
2015 pContainerWidgetData->GetPictureContent(wsPicture,
2016 XFA_VALUEPICTURE_DataBind);
2017 }
2018 if (!wsPicture.IsEmpty()) {
2019 break;
2020 }
weili44f8faf2016-06-01 14:03:56 -07002021 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002022 }
2023 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
2024 pContainerWidgetData = GetContainerWidgetData();
2025 }
2026 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002027 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002028 }
tsepezd19e9122016-11-02 15:43:18 -07002029 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002030 } else {
tsepezd19e9122016-11-02 15:43:18 -07002031 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07002032 if (content.IsEmpty() && eType != XFA_Element::Text &&
2033 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07002034 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07002035 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002036 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07002037 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07002038 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002039 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002040 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002041 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002042 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002043 }
2044 }
2045}
dsinclair5b36f0a2016-07-19 10:56:23 -07002046
dsinclair12a6b0c2016-05-26 11:14:08 -07002047void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002048 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002049 XFA_ATTRIBUTE eAttribute) {
2050 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07002051 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002052 return;
2053 }
tsepezd19e9122016-11-02 15:43:18 -07002054 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002055 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002056 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002057 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002058 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002059 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002060 }
2061}
dsinclair5b36f0a2016-07-19 10:56:23 -07002062
dsinclair12a6b0c2016-05-26 11:14:08 -07002063void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002064 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002065 XFA_ATTRIBUTE eAttribute) {
2066 if (bSetting) {
2067 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002068 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002069 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002070
tsepezb4c9f3f2016-04-13 15:41:21 -07002071 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002072 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002073 CFX_WideString wsFormatValue(wsNewValue);
2074 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2075 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002076 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002077 }
tsepezd19e9122016-11-02 15:43:18 -07002078 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002079 } else {
tsepezd19e9122016-11-02 15:43:18 -07002080 CFX_WideString wsValue = GetScriptContent(true);
dsinclairf27aeec2016-06-07 19:36:18 -07002081 pValue->SetBoolean(wsValue == FX_WSTRC(L"1"));
Dan Sinclair1770c022016-03-14 14:14:16 -04002082 }
2083}
dsinclair2f5582f2016-06-09 11:48:23 -07002084
dsinclair12a6b0c2016-05-26 11:14:08 -07002085void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002086 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002087 XFA_ATTRIBUTE eAttribute) {
2088 CXFA_WidgetData* pWidgetData = GetWidgetData();
2089 if (!pWidgetData) {
2090 return;
2091 }
tsepezd19e9122016-11-02 15:43:18 -07002092 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002093 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002094 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002095 int32_t r = 0;
2096 int32_t g = 0;
2097 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002098 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002099 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2100 for (int32_t i = 0; i < iSize; ++i) {
2101 CXFA_Edge edge = border.GetEdge(i);
2102 edge.SetColor(rgb);
2103 }
2104 } else {
2105 CXFA_Edge edge = border.GetEdge(0);
2106 FX_ARGB color = edge.GetColor();
2107 int32_t a, r, g, b;
2108 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002109 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002110 strColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002111 pValue->SetString(FX_UTF8Encode(strColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002112 }
2113}
dsinclair5b36f0a2016-07-19 10:56:23 -07002114
dsinclair12a6b0c2016-05-26 11:14:08 -07002115void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002116 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002117 XFA_ATTRIBUTE eAttribute) {
2118 CXFA_WidgetData* pWidgetData = GetWidgetData();
2119 if (!pWidgetData) {
2120 return;
2121 }
tsepezd19e9122016-11-02 15:43:18 -07002122 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002123 int32_t iSize = border.CountEdges();
2124 CFX_WideString wsThickness;
2125 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002126 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002127 for (int32_t i = 0; i < iSize; ++i) {
2128 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002129 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002130 edge.SetMSThickness(thickness);
2131 }
2132 } else {
2133 CXFA_Edge edge = border.GetEdge(0);
2134 CXFA_Measurement thickness = edge.GetMSThickness();
2135 thickness.ToString(wsThickness);
dsinclairf27aeec2016-06-07 19:36:18 -07002136 pValue->SetString(FX_UTF8Encode(wsThickness).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002137 }
2138}
dsinclair5b36f0a2016-07-19 10:56:23 -07002139
dsinclair12a6b0c2016-05-26 11:14:08 -07002140void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002141 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002142 XFA_ATTRIBUTE eAttribute) {
2143 CXFA_WidgetData* pWidgetData = GetWidgetData();
2144 if (!pWidgetData) {
2145 return;
2146 }
tsepezd19e9122016-11-02 15:43:18 -07002147 CXFA_Border border = pWidgetData->GetBorder(true);
2148 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002149 CXFA_Node* pNode = borderfill.GetNode();
2150 if (!pNode) {
2151 return;
2152 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002153 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002154 int32_t r;
2155 int32_t g;
2156 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002157 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002158 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2159 borderfill.SetColor(color);
2160 } else {
2161 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002162 int32_t a;
2163 int32_t r;
2164 int32_t g;
2165 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002166 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002167 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002168 wsColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002169 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002170 }
2171}
dsinclair5b36f0a2016-07-19 10:56:23 -07002172
dsinclair12a6b0c2016-05-26 11:14:08 -07002173void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002174 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002175 XFA_ATTRIBUTE eAttribute) {
2176 if (!bSetting) {
2177 CXFA_Node* pDataNode = GetBindData();
2178 if (pDataNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002179 pValue->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002180 m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
2181 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002182 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002183 }
2184 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002185 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002186 }
2187}
dsinclair5b36f0a2016-07-19 10:56:23 -07002188
dsinclair12a6b0c2016-05-26 11:14:08 -07002189void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002190 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002191 XFA_ATTRIBUTE eAttribute) {
2192 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002193 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002194 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002195 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002196 XFA_Element uiType = pWidgetData->GetUIType();
2197 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002198 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002199 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002200 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002201 }
2202 }
2203 } else {
tsepezd19e9122016-11-02 15:43:18 -07002204 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002205 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002206 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002207 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002208 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002209 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002210 }
2211 }
2212}
dsinclair5b36f0a2016-07-19 10:56:23 -07002213
dsinclair12a6b0c2016-05-26 11:14:08 -07002214void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002215 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002216 XFA_ATTRIBUTE eAttribute) {
2217 CXFA_WidgetData* pWidgetData = GetWidgetData();
2218 if (!pWidgetData) {
2219 return;
2220 }
2221 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002222 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002223 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002224 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002225 } else {
2226 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002227 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002228 }
dsinclair2f5582f2016-06-09 11:48:23 -07002229 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002230 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002231 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002232
Dan Sinclair1770c022016-03-14 14:14:16 -04002233 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002234 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002235 int32_t iLeadDigits = 0;
2236 int32_t iFracDigits = 0;
2237 pWidgetData->GetLeadDigits(iLeadDigits);
2238 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002239 wsNewText =
2240 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002241 }
2242 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2243 CFX_WideString wsFormatText(wsNewText);
2244 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002245 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002246 }
tsepezd19e9122016-11-02 15:43:18 -07002247 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002248 } else {
tsepezd19e9122016-11-02 15:43:18 -07002249 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002250 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002251 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002252 } else {
2253 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002254 CXFA_Value defVal = pWidgetData->GetFormValue();
2255 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002256 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002257 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002258 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002259 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002260 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002261 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002262 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002263 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002264 }
dsinclair070fcdf2016-06-22 22:04:54 -07002265 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002266 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002267 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002268 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002269 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002270 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002271 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002272 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002273 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002274 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002275 }
2276 }
2277 }
2278}
dsinclair5b36f0a2016-07-19 10:56:23 -07002279
dsinclair12a6b0c2016-05-26 11:14:08 -07002280void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002281 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002282 XFA_ATTRIBUTE eAttribute) {
2283 CXFA_WidgetData* pWidgetData = GetWidgetData();
2284 if (!pWidgetData) {
2285 return;
2286 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002287 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002288 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002289 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002290 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002291 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
dsinclairf27aeec2016-06-07 19:36:18 -07002292 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002293 }
2294}
dsinclair5b36f0a2016-07-19 10:56:23 -07002295
dsinclair12a6b0c2016-05-26 11:14:08 -07002296void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002297 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002298 XFA_ATTRIBUTE eAttribute) {
2299 CXFA_WidgetData* pWidgetData = GetWidgetData();
2300 if (!pWidgetData) {
2301 return;
2302 }
tsepezd19e9122016-11-02 15:43:18 -07002303 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002304 CXFA_Node* pNode = font.GetNode();
2305 if (!pNode) {
2306 return;
2307 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002308 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002309 int32_t r;
2310 int32_t g;
2311 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002312 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002313 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2314 font.SetColor(color);
2315 } else {
2316 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002317 int32_t a;
2318 int32_t r;
2319 int32_t g;
2320 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002321 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002322 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002323 wsColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002324 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002325 }
2326}
dsinclair5b36f0a2016-07-19 10:56:23 -07002327
dsinclair12a6b0c2016-05-26 11:14:08 -07002328void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002329 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002330 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002331 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002332}
dsinclair5b36f0a2016-07-19 10:56:23 -07002333
dsinclair12a6b0c2016-05-26 11:14:08 -07002334void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002335 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002336 XFA_ATTRIBUTE eAttribute) {
2337 CXFA_WidgetData* pWidgetData = GetWidgetData();
2338 if (!pWidgetData) {
2339 return;
2340 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002341 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002342 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002343 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002344 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002345 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
dsinclairf27aeec2016-06-07 19:36:18 -07002346 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002347 }
2348}
dsinclair5b36f0a2016-07-19 10:56:23 -07002349
dsinclair12a6b0c2016-05-26 11:14:08 -07002350void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002351 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002352 XFA_ATTRIBUTE eAttribute) {
2353 CXFA_WidgetData* pWidgetData = GetWidgetData();
2354 if (!pWidgetData) {
2355 return;
2356 }
tsepezd19e9122016-11-02 15:43:18 -07002357 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002358 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002359 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002360 } else {
2361 int32_t iValue = validate.GetNullTest();
2362 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002363 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002364 CFX_WideString wsValue;
2365 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002366 wsValue = pInfo->pName;
dsinclairf27aeec2016-06-07 19:36:18 -07002367 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002368 }
2369}
dsinclair5b36f0a2016-07-19 10:56:23 -07002370
dsinclair12a6b0c2016-05-26 11:14:08 -07002371void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002372 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002373 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002374 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002375}
dsinclair5b36f0a2016-07-19 10:56:23 -07002376
dsinclair12a6b0c2016-05-26 11:14:08 -07002377void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002378 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002379 XFA_ATTRIBUTE eAttribute) {
2380 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07002381 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002382 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002383 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002384 }
2385}
dsinclair5b36f0a2016-07-19 10:56:23 -07002386
dsinclair12a6b0c2016-05-26 11:14:08 -07002387void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002388 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002389 XFA_ATTRIBUTE eAttribute) {
2390 CXFA_WidgetData* pWidgetData = GetWidgetData();
2391 if (!pWidgetData) {
2392 return;
2393 }
2394 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002395 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002396 if (iIndex == -1) {
2397 pWidgetData->ClearAllSelections();
2398 return;
2399 }
tsepezd19e9122016-11-02 15:43:18 -07002400 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002401 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002402 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002403 }
2404}
dsinclair5b36f0a2016-07-19 10:56:23 -07002405
Dan Sinclair1770c022016-03-14 14:14:16 -04002406void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2407 CXFA_WidgetData* pWidgetData = GetWidgetData();
2408 if (!pWidgetData) {
2409 return;
2410 }
tsepezd19e9122016-11-02 15:43:18 -07002411 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002412}
dsinclair5b36f0a2016-07-19 10:56:23 -07002413
Dan Sinclair1770c022016-03-14 14:14:16 -04002414void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
2415 int32_t argc = pArguments->GetLength();
2416 if (argc == 1) {
2417 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2418 int32_t iRet = execSingleEventByName(
tsepez4c3debb2016-04-08 12:20:38 -07002419 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
dsinclair56a8b192016-06-21 14:15:25 -07002420 XFA_Element::Field);
Dan Sinclair1770c022016-03-14 14:14:16 -04002421 if (eventString == "validate") {
dsinclairf27aeec2016-06-07 19:36:18 -07002422 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07002423 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002424 }
2425 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002426 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
Dan Sinclair1770c022016-03-14 14:14:16 -04002427 }
2428}
dsinclair5b36f0a2016-07-19 10:56:23 -07002429
Dan Sinclair1770c022016-03-14 14:14:16 -04002430void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
2431 int32_t argc = pArguments->GetLength();
2432 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002433 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002434 if (!pNotify) {
2435 return;
2436 }
tsepezd19e9122016-11-02 15:43:18 -07002437 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002438 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002439 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002440 }
2441}
dsinclair5b36f0a2016-07-19 10:56:23 -07002442
Dan Sinclair1770c022016-03-14 14:14:16 -04002443void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2444 int32_t iLength = pArguments->GetLength();
2445 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002446 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002447 return;
2448 }
2449 CXFA_WidgetData* pWidgetData = GetWidgetData();
2450 if (!pWidgetData) {
2451 return;
2452 }
2453 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002454 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002455 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002456 if (pValue)
2457 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002458}
dsinclair5b36f0a2016-07-19 10:56:23 -07002459
Dan Sinclair1770c022016-03-14 14:14:16 -04002460void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2461 int32_t iLength = pArguments->GetLength();
2462 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002463 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002464 return;
2465 }
2466 int32_t iIndex = pArguments->GetInt32(0);
2467 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002468 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002469 return;
2470 }
2471 CXFA_WidgetData* pWidgetData = GetWidgetData();
2472 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002473 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002474 return;
2475 }
2476 CFX_WideString wsValue;
tsepezd19e9122016-11-02 15:43:18 -07002477 bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002478 if (bHasItem) {
dsinclairf27aeec2016-06-07 19:36:18 -07002479 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002480 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002481 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002482 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002483 }
2484}
dsinclair5b36f0a2016-07-19 10:56:23 -07002485
Dan Sinclair1770c022016-03-14 14:14:16 -04002486void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2487 int32_t iLength = pArguments->GetLength();
2488 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002489 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002490 return;
2491 }
2492 CXFA_WidgetData* pWidgetData = GetWidgetData();
2493 if (!pWidgetData) {
2494 return;
2495 }
2496 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002497 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002498 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002499 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002500 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002501 if (pValue)
2502 pValue->SetString(FX_UTF8Encode(wsBoundValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002503}
dsinclair5b36f0a2016-07-19 10:56:23 -07002504
Dan Sinclair1770c022016-03-14 14:14:16 -04002505void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2506 int32_t iLength = pArguments->GetLength();
2507 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002508 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002509 return;
2510 }
2511 CXFA_WidgetData* pWidgetData = GetWidgetData();
2512 if (!pWidgetData) {
2513 return;
2514 }
2515 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002516 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002517 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002518 if (pValue)
2519 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002520}
dsinclair5b36f0a2016-07-19 10:56:23 -07002521
Dan Sinclair1770c022016-03-14 14:14:16 -04002522void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
2523 int32_t argc = pArguments->GetLength();
2524 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002525 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002526 if (!pNotify) {
2527 return;
2528 }
tsepezd19e9122016-11-02 15:43:18 -07002529 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002530 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002531 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002532 }
2533}
dsinclair5b36f0a2016-07-19 10:56:23 -07002534
Dan Sinclair1770c022016-03-14 14:14:16 -04002535void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002536
Dan Sinclair1770c022016-03-14 14:14:16 -04002537void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2538 int32_t iLength = pArguments->GetLength();
2539 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002540 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002541 return;
2542 }
2543 int32_t iIndex = pArguments->GetInt32(0);
2544 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002545 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002546 return;
2547 }
2548 CXFA_WidgetData* pWidgetData = GetWidgetData();
2549 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002550 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002551 return;
2552 }
2553 CFX_WideString wsValue;
tsepezd19e9122016-11-02 15:43:18 -07002554 bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002555 if (bHasItem) {
dsinclairf27aeec2016-06-07 19:36:18 -07002556 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002557 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002558 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002559 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002560 }
2561}
dsinclair5b36f0a2016-07-19 10:56:23 -07002562
Dan Sinclair1770c022016-03-14 14:14:16 -04002563void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2564 int32_t iLength = pArguments->GetLength();
2565 if (iLength != 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07002566 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002567 return;
2568 }
2569 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002570 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002571 return;
thestig800222e2016-05-26 22:00:29 -07002572
Dan Sinclair1770c022016-03-14 14:14:16 -04002573 int32_t iIndex = pArguments->GetInt32(0);
2574 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002575 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002576 } else {
thestig800222e2016-05-26 22:00:29 -07002577 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002578 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002579 }
2580}
dsinclair5b36f0a2016-07-19 10:56:23 -07002581
Dan Sinclair1770c022016-03-14 14:14:16 -04002582void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2583 int32_t iLength = pArguments->GetLength();
2584 if (iLength < 1 || iLength > 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07002585 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002586 return;
2587 }
2588 CXFA_WidgetData* pWidgetData = GetWidgetData();
2589 if (!pWidgetData) {
2590 return;
2591 }
2592 CFX_WideString wsLabel;
2593 CFX_WideString wsValue;
2594 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002595 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002596 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002597 }
2598 if (iLength >= 2) {
2599 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002600 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002601 }
tsepezd19e9122016-11-02 15:43:18 -07002602 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002603}
dsinclair5b36f0a2016-07-19 10:56:23 -07002604
Dan Sinclair1770c022016-03-14 14:14:16 -04002605void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
2606 int32_t argc = pArguments->GetLength();
2607 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002608 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002609 if (!pNotify) {
tsepezd19e9122016-11-02 15:43:18 -07002610 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002611 } else {
2612 int32_t iRet =
tsepezd19e9122016-11-02 15:43:18 -07002613 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
dsinclairf27aeec2016-06-07 19:36:18 -07002614 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07002615 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002616 }
2617 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002618 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002619 }
2620}
dsinclair5b36f0a2016-07-19 10:56:23 -07002621
dsinclair12a6b0c2016-05-26 11:14:08 -07002622void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002623 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002624 XFA_ATTRIBUTE eAttribute) {
2625 if (!bSetting) {
2626 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002627 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002628 }
2629}
dsinclair5b36f0a2016-07-19 10:56:23 -07002630
dsinclair12a6b0c2016-05-26 11:14:08 -07002631void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002632 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002633 XFA_ATTRIBUTE eAttribute) {
2634 CXFA_WidgetData* pWidgetData = GetWidgetData();
2635 if (!pWidgetData) {
2636 return;
2637 }
2638 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002639 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002640 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002641 } else {
tsepezd19e9122016-11-02 15:43:18 -07002642 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002643 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2644 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002645 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002646 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002647 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002648 }
2649 }
2650}
dsinclair5b36f0a2016-07-19 10:56:23 -07002651
dsinclair12a6b0c2016-05-26 11:14:08 -07002652void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002653 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002654 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002655
Dan Sinclair1770c022016-03-14 14:14:16 -04002656void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
2657 int32_t argc = pArguments->GetLength();
2658 if (argc == 1) {
2659 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2660 execSingleEventByName(
tsepez4c3debb2016-04-08 12:20:38 -07002661 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
dsinclair56a8b192016-06-21 14:15:25 -07002662 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002663 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002664 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
Dan Sinclair1770c022016-03-14 14:14:16 -04002665 }
2666}
thestig800222e2016-05-26 22:00:29 -07002667
Dan Sinclair1770c022016-03-14 14:14:16 -04002668void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2669 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002670 if (argc < 0 || argc > 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002671 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002672 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002673 }
thestig800222e2016-05-26 22:00:29 -07002674
2675 CXFA_WidgetData* pWidgetData = GetWidgetData();
2676 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002677 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002678 return;
2679 }
2680
2681 CXFA_Node* pReturnNode = nullptr;
2682 if (argc == 0) {
2683 pReturnNode = pWidgetData->GetSelectedMember();
2684 } else {
2685 CFX_ByteString szName;
2686 szName = pArguments->GetUTF8String(0);
2687 pReturnNode = pWidgetData->SetSelectedMember(
2688 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2689 }
2690 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002691 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002692 return;
2693 }
dsinclairf27aeec2016-06-07 19:36:18 -07002694 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002695 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002696}
thestig800222e2016-05-26 22:00:29 -07002697
Dan Sinclair1770c022016-03-14 14:14:16 -04002698void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
2699 int32_t argc = pArguments->GetLength();
2700 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002701 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002702 if (!pNotify) {
2703 return;
2704 }
2705 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
2706 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002707 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002708 }
2709}
dsinclair5b36f0a2016-07-19 10:56:23 -07002710
Dan Sinclair1770c022016-03-14 14:14:16 -04002711void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
2712 int32_t argc = pArguments->GetLength();
2713 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002714 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002715 if (!pNotify) {
2716 return;
2717 }
2718 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
2719 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002720 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002721 }
2722}
dsinclair5b36f0a2016-07-19 10:56:23 -07002723
Dan Sinclair1770c022016-03-14 14:14:16 -04002724void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
2725 int32_t argc = pArguments->GetLength();
2726 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002727 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002728 if (!pNotify) {
tsepezd19e9122016-11-02 15:43:18 -07002729 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002730 } else {
2731 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
dsinclairf27aeec2016-06-07 19:36:18 -07002732 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07002733 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002734 }
2735 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002736 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002737 }
2738}
dsinclair5b36f0a2016-07-19 10:56:23 -07002739
dsinclair12a6b0c2016-05-26 11:14:08 -07002740void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002741 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002742 XFA_ATTRIBUTE eAttribute) {
2743 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002744 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002745 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002746 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002747 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2748 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002749 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002750 pManagerNode = pNode;
2751 break;
2752 }
2753 }
2754 if (pManagerNode) {
2755 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002756 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002757 if (!pNotify) {
2758 return;
2759 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002760 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002761 if (pToInstance &&
2762 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002763 pNotify->RunSubformIndexChange(pToInstance);
2764 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002765 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002766 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002767 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002768 pNotify->RunSubformIndexChange(pFromInstance);
2769 }
2770 }
2771 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002772 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002773 }
2774}
dsinclair5b36f0a2016-07-19 10:56:23 -07002775
dsinclair12a6b0c2016-05-26 11:14:08 -07002776void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002777 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002778 XFA_ATTRIBUTE eAttribute) {
2779 if (!bSetting) {
2780 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
weili44f8faf2016-06-01 14:03:56 -07002781 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002782 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2783 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002784 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002785 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2786 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2787 wsInstMgrName.Mid(1) == wsName) {
2788 pInstanceMgr = pNode;
2789 }
2790 break;
2791 }
2792 }
2793 if (pInstanceMgr) {
dsinclairf27aeec2016-06-07 19:36:18 -07002794 pValue->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002795 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
2796 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002797 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002798 }
2799 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002800 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002801 }
2802}
dsinclair5b36f0a2016-07-19 10:56:23 -07002803
dsinclair12a6b0c2016-05-26 11:14:08 -07002804void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002805 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002806 XFA_ATTRIBUTE eAttribute) {
2807 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002808 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002809 } else {
2810 CFX_WideString wsLocaleName;
2811 GetLocaleName(wsLocaleName);
dsinclairf27aeec2016-06-07 19:36:18 -07002812 pValue->SetString(
2813 FX_UTF8Encode(wsLocaleName.c_str(), wsLocaleName.GetLength())
2814 .AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002815 }
2816}
dsinclair5b36f0a2016-07-19 10:56:23 -07002817
Dan Sinclair1770c022016-03-14 14:14:16 -04002818void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
2819 int32_t argc = pArguments->GetLength();
2820 if (argc == 1) {
2821 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2822 execSingleEventByName(
tsepez4c3debb2016-04-08 12:20:38 -07002823 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
dsinclair56a8b192016-06-21 14:15:25 -07002824 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002825 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002826 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
Dan Sinclair1770c022016-03-14 14:14:16 -04002827 }
2828}
dsinclair5b36f0a2016-07-19 10:56:23 -07002829
Dan Sinclair1770c022016-03-14 14:14:16 -04002830void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
2831 int32_t argc = pArguments->GetLength();
2832 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002833 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002834 if (!pNotify) {
2835 return;
2836 }
2837 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
2838 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002839 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002840 }
2841}
dsinclair5b36f0a2016-07-19 10:56:23 -07002842
Dan Sinclair1770c022016-03-14 14:14:16 -04002843void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
2844 int32_t argc = pArguments->GetLength();
2845 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002846 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002847 if (!pNotify) {
2848 return;
2849 }
2850 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
2851 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002852 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002853 }
2854}
dsinclair5b36f0a2016-07-19 10:56:23 -07002855
Dan Sinclair1770c022016-03-14 14:14:16 -04002856void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
2857 int32_t argc = pArguments->GetLength();
2858 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002859 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002860 if (!pNotify) {
tsepezd19e9122016-11-02 15:43:18 -07002861 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002862 } else {
2863 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
dsinclairf27aeec2016-06-07 19:36:18 -07002864 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07002865 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002866 }
2867 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002868 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002869 }
2870}
dsinclair5b36f0a2016-07-19 10:56:23 -07002871
Dan Sinclair1770c022016-03-14 14:14:16 -04002872void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
2873 int32_t argc = pArguments->GetLength();
2874 if (argc == 0) {
2875 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002876 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002877 }
2878}
dsinclair5b36f0a2016-07-19 10:56:23 -07002879
Dan Sinclair1770c022016-03-14 14:14:16 -04002880int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2881 int32_t index = 0;
2882 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2883 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002884 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2885 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002886 index++;
2887 } else {
2888 break;
2889 }
2890 }
2891 return index;
2892}
dsinclair5b36f0a2016-07-19 10:56:23 -07002893
Dan Sinclair1770c022016-03-14 14:14:16 -04002894void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
2895 int32_t argc = pArguments->GetLength();
2896 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07002897 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002898 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002899 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04002900 }
2901}
dsinclair5b36f0a2016-07-19 10:56:23 -07002902
Dan Sinclair1770c022016-03-14 14:14:16 -04002903void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
2904 int32_t argc = pArguments->GetLength();
2905 if (argc == 0) {
tsepezd19e9122016-11-02 15:43:18 -07002906 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002907 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002908 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge");
Dan Sinclair1770c022016-03-14 14:14:16 -04002909 }
2910}
dsinclair5b36f0a2016-07-19 10:56:23 -07002911
Dan Sinclair1770c022016-03-14 14:14:16 -04002912void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
2913 int32_t argc = pArguments->GetLength();
2914 if (argc == 0) {
2915 CXFA_WidgetData* pWidgetData = GetWidgetData();
2916 if (!pWidgetData) {
tsepezd19e9122016-11-02 15:43:18 -07002917 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002918 } else {
tsepezd19e9122016-11-02 15:43:18 -07002919 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002920 }
2921 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002922 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002923 }
2924}
dsinclair5b36f0a2016-07-19 10:56:23 -07002925
Dan Sinclair1770c022016-03-14 14:14:16 -04002926void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2927 int32_t argc = pArguments->GetLength();
2928 if ((argc > 0) && (argc < 4)) {
2929 CFX_WideString strTagName;
2930 CFX_WideString strName;
2931 CFX_WideString strNameSpace;
2932 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002933 strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002934 if (argc > 1) {
2935 CFX_ByteString bsName = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002936 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002937 if (argc == 3) {
2938 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
tsepez4c3debb2016-04-08 12:20:38 -07002939 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002940 }
2941 }
dsinclair6e124782016-06-23 12:14:55 -07002942 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2943 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
Dan Sinclair1770c022016-03-14 14:14:16 -04002944 if (!pNewNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002945 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002946 } else {
2947 if (!strName.IsEmpty()) {
dsinclair9eb0db12016-07-21 12:01:39 -07002948 if (GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2949 XFA_XDPPACKET_UNKNOWN)) {
thestigb1a59592016-04-14 18:29:56 -07002950 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002951 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) {
2952 pNewNode->CreateXMLMappingNode();
2953 }
dsinclairf27aeec2016-06-07 19:36:18 -07002954 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002955 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2956 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002957 ThrowException(XFA_IDS_NOT_HAVE_PROPERTY, strTagName.c_str(),
2958 L"name");
Dan Sinclair1770c022016-03-14 14:14:16 -04002959 }
2960 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002961 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002962 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2963 }
2964 }
2965 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002966 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"createNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04002967 }
2968}
dsinclair5b36f0a2016-07-19 10:56:23 -07002969
Dan Sinclair1770c022016-03-14 14:14:16 -04002970void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
2971 if (pArguments->GetLength() == 1) {
tsepezd19e9122016-11-02 15:43:18 -07002972 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002973 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002974 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002975 }
2976}
dsinclair5b36f0a2016-07-19 10:56:23 -07002977
Dan Sinclair1770c022016-03-14 14:14:16 -04002978void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
2979 int32_t argc = pArguments->GetLength();
2980 if (argc == 0) {
2981 CXFA_WidgetData* pWidgetData = GetWidgetData();
2982 if (!pWidgetData) {
tsepezd19e9122016-11-02 15:43:18 -07002983 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002984 } else {
tsepezd19e9122016-11-02 15:43:18 -07002985 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002986 }
2987 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002988 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002989 }
2990}
dsinclair5b36f0a2016-07-19 10:56:23 -07002991
Dan Sinclair1770c022016-03-14 14:14:16 -04002992void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
2993 int32_t argc = pArguments->GetLength();
2994 if (argc == 0) {
2995 CXFA_WidgetData* pWidgetData = GetWidgetData();
2996 if (!pWidgetData) {
tsepezd19e9122016-11-02 15:43:18 -07002997 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002998 } else {
tsepezd19e9122016-11-02 15:43:18 -07002999 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003000 }
3001 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003002 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003003 }
3004}
dsinclair5b36f0a2016-07-19 10:56:23 -07003005
Dan Sinclair1770c022016-03-14 14:14:16 -04003006void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
3007 int32_t argc = pArguments->GetLength();
3008 if (argc == 0) {
3009 CXFA_WidgetData* pWidgetData = GetWidgetData();
3010 if (!pWidgetData) {
tsepezd19e9122016-11-02 15:43:18 -07003011 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003012 } else {
tsepezd19e9122016-11-02 15:43:18 -07003013 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003014 }
3015 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003016 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"evaluate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003017 }
3018}
dsinclair5b36f0a2016-07-19 10:56:23 -07003019
dsinclair12a6b0c2016-05-26 11:14:08 -07003020void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003021 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003022 XFA_ATTRIBUTE eAttribute) {
3023 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07003024 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04003025 return;
3026 }
3027 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003028 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003029}
dsinclair5b36f0a2016-07-19 10:56:23 -07003030
dsinclair12a6b0c2016-05-26 11:14:08 -07003031void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003032 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003033 XFA_ATTRIBUTE eAttribute) {
3034 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07003035 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04003036 return;
3037 }
3038 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003039 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003040}
tsepezaadedf92016-05-12 10:08:06 -07003041
dsinclair12a6b0c2016-05-26 11:14:08 -07003042void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003043 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003044 XFA_ATTRIBUTE eAttribute) {
3045 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003046 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003047 InstanceManager_SetInstances(iDesired);
3048 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07003049 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04003050 }
3051}
dsinclair5b36f0a2016-07-19 10:56:23 -07003052
Dan Sinclair1770c022016-03-14 14:14:16 -04003053void CXFA_Node::Script_InstanceManager_MoveInstance(
3054 CFXJSE_Arguments* pArguments) {
3055 int32_t argc = pArguments->GetLength();
3056 if (argc != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003057 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003058 return;
3059 }
3060 int32_t iFrom = pArguments->GetInt32(0);
3061 int32_t iTo = pArguments->GetInt32(1);
3062 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003063 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003064 if (!pNotify) {
3065 return;
3066 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003067 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003068 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003069 pNotify->RunSubformIndexChange(pToInstance);
3070 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003071 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003072 if (pFromInstance &&
3073 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003074 pNotify->RunSubformIndexChange(pFromInstance);
3075 }
3076}
dsinclair5b36f0a2016-07-19 10:56:23 -07003077
Dan Sinclair1770c022016-03-14 14:14:16 -04003078void CXFA_Node::Script_InstanceManager_RemoveInstance(
3079 CFXJSE_Arguments* pArguments) {
3080 int32_t argc = pArguments->GetLength();
3081 if (argc != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003082 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003083 return;
3084 }
3085 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003086 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003087 if (iIndex < 0 || iIndex >= iCount) {
dsinclair2235b7b2016-06-02 07:42:25 -07003088 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
Dan Sinclair1770c022016-03-14 14:14:16 -04003089 return;
3090 }
3091 CXFA_Occur nodeOccur(GetOccurNode());
3092 int32_t iMin = nodeOccur.GetMin();
3093 if (iCount - 1 < iMin) {
dsinclair2235b7b2016-06-02 07:42:25 -07003094 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003095 return;
3096 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003097 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3098 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003099 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003100 if (pNotify) {
3101 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003102 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003103 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003104 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003105 pNotify->RunSubformIndexChange(pSubformInstance);
3106 }
3107 }
3108 }
3109 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3110 if (!pLayoutPro) {
3111 return;
3112 }
3113 pLayoutPro->AddChangedContainer(
3114 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3115}
dsinclair5b36f0a2016-07-19 10:56:23 -07003116
Dan Sinclair1770c022016-03-14 14:14:16 -04003117void CXFA_Node::Script_InstanceManager_SetInstances(
3118 CFXJSE_Arguments* pArguments) {
3119 int32_t argc = pArguments->GetLength();
3120 if (argc != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003121 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003122 return;
3123 }
3124 int32_t iDesired = pArguments->GetInt32(0);
3125 InstanceManager_SetInstances(iDesired);
3126}
dsinclair5b36f0a2016-07-19 10:56:23 -07003127
Dan Sinclair1770c022016-03-14 14:14:16 -04003128void CXFA_Node::Script_InstanceManager_AddInstance(
3129 CFXJSE_Arguments* pArguments) {
3130 int32_t argc = pArguments->GetLength();
3131 if ((argc != 0) && (argc != 1)) {
dsinclair2235b7b2016-06-02 07:42:25 -07003132 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003133 return;
3134 }
tsepezd19e9122016-11-02 15:43:18 -07003135 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003136 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003137 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003138 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003139 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003140 CXFA_Occur nodeOccur(GetOccurNode());
3141 int32_t iMax = nodeOccur.GetMax();
3142 if (iMax >= 0 && iCount >= iMax) {
dsinclair2235b7b2016-06-02 07:42:25 -07003143 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003144 return;
3145 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003146 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003147 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003148 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003149 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003150 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003151 if (!pNotify) {
3152 return;
3153 }
3154 pNotify->RunNodeInitialize(pNewInstance);
3155 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3156 if (!pLayoutPro) {
3157 return;
3158 }
3159 pLayoutPro->AddChangedContainer(
3160 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3161}
dsinclair5b36f0a2016-07-19 10:56:23 -07003162
Dan Sinclair1770c022016-03-14 14:14:16 -04003163void CXFA_Node::Script_InstanceManager_InsertInstance(
3164 CFXJSE_Arguments* pArguments) {
3165 int32_t argc = pArguments->GetLength();
3166 if ((argc != 1) && (argc != 2)) {
dsinclair2235b7b2016-06-02 07:42:25 -07003167 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003168 return;
3169 }
3170 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003171 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003172 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003173 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003174 }
3175 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003176 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003177 if (iIndex < 0 || iIndex > iCount) {
dsinclair2235b7b2016-06-02 07:42:25 -07003178 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
Dan Sinclair1770c022016-03-14 14:14:16 -04003179 return;
3180 }
3181 int32_t iMax = nodeOccur.GetMax();
3182 if (iMax >= 0 && iCount >= iMax) {
dsinclair2235b7b2016-06-02 07:42:25 -07003183 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003184 return;
3185 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003186 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003187 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003188 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003189 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003190 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003191 if (!pNotify) {
3192 return;
3193 }
3194 pNotify->RunNodeInitialize(pNewInstance);
3195 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3196 if (!pLayoutPro) {
3197 return;
3198 }
3199 pLayoutPro->AddChangedContainer(
3200 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3201}
dsinclair5b36f0a2016-07-19 10:56:23 -07003202
Dan Sinclair1770c022016-03-14 14:14:16 -04003203int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3204 CXFA_Occur nodeOccur(GetOccurNode());
3205 int32_t iMax = nodeOccur.GetMax();
3206 int32_t iMin = nodeOccur.GetMin();
3207 if (iDesired < iMin) {
dsinclair2235b7b2016-06-02 07:42:25 -07003208 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003209 return 1;
3210 }
3211 if ((iMax >= 0) && (iDesired > iMax)) {
dsinclair2235b7b2016-06-02 07:42:25 -07003212 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003213 return 2;
3214 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003215 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003216 if (iDesired == iCount) {
3217 return 0;
3218 }
3219 if (iDesired < iCount) {
3220 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003221 CFX_WideString wsInstanceName =
3222 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3223 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003224 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003225 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003226 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003227 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003228 while (iCount > iDesired) {
3229 CXFA_Node* pRemoveInstance =
3230 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003231 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3232 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003233 continue;
3234 }
dsinclair070fcdf2016-06-22 22:04:54 -07003235 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003236 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003237 break;
3238 }
3239 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003240 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003241 iCount--;
3242 }
3243 }
3244 } else if (iDesired > iCount) {
3245 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003246 CXFA_Node* pNewInstance = CreateInstance(this, true);
3247 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003248 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003249 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003250 if (!pNotify) {
3251 return 0;
3252 }
3253 pNotify->RunNodeInitialize(pNewInstance);
3254 }
3255 }
3256 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3257 if (pLayoutPro) {
3258 pLayoutPro->AddChangedContainer(
3259 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3260 }
3261 return 0;
3262}
dsinclair5b36f0a2016-07-19 10:56:23 -07003263
Dan Sinclair1770c022016-03-14 14:14:16 -04003264int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003265 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003266 if (iFrom > iCount || iTo > iCount - 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07003267 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
Dan Sinclair1770c022016-03-14 14:14:16 -04003268 return 1;
3269 }
3270 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3271 return 0;
3272 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003273 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003274 RemoveItem(this, pMoveInstance, false);
3275 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003276 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3277 if (pLayoutPro) {
3278 pLayoutPro->AddChangedContainer(
3279 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3280 }
3281 return 0;
3282}
dsinclair5b36f0a2016-07-19 10:56:23 -07003283
dsinclair12a6b0c2016-05-26 11:14:08 -07003284void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003285 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003286 XFA_ATTRIBUTE eAttribute) {
3287 CXFA_Occur occur(this);
3288 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003289 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003290 occur.SetMax(iMax);
3291 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003292 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003293 }
3294}
dsinclair5b36f0a2016-07-19 10:56:23 -07003295
dsinclair12a6b0c2016-05-26 11:14:08 -07003296void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003297 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003298 XFA_ATTRIBUTE eAttribute) {
3299 CXFA_Occur occur(this);
3300 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003301 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003302 occur.SetMin(iMin);
3303 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003304 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003305 }
3306}
dsinclair5b36f0a2016-07-19 10:56:23 -07003307
Dan Sinclair1770c022016-03-14 14:14:16 -04003308void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3309 int32_t argc = pArguments->GetLength();
3310 if ((argc == 0) || (argc == 1)) {
dsinclairf27aeec2016-06-07 19:36:18 -07003311 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003312 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003313 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"metadata");
Dan Sinclair1770c022016-03-14 14:14:16 -04003314 }
3315}
dsinclair5b36f0a2016-07-19 10:56:23 -07003316
Dan Sinclair1770c022016-03-14 14:14:16 -04003317void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
3318 int32_t argc = pArguments->GetLength();
3319 if (argc == 1) {
3320 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3321 if (pDataNode) {
3322 CXFA_NodeArray formItems;
3323 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3324 pFormNodes->SetArrayNodeList(formItems);
dsinclairf27aeec2016-06-07 19:36:18 -07003325 pArguments->GetReturnValue()->SetObject(
3326 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003327 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003328 ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
Dan Sinclair1770c022016-03-14 14:14:16 -04003329 }
3330 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003331 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04003332 }
3333}
dsinclair5b36f0a2016-07-19 10:56:23 -07003334
Dan Sinclair1770c022016-03-14 14:14:16 -04003335void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
3336 int32_t argc = pArguments->GetLength();
3337 if (argc == 0) {
tsepezd19e9122016-11-02 15:43:18 -07003338 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003339 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003340 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge");
Dan Sinclair1770c022016-03-14 14:14:16 -04003341 }
3342}
dsinclair5b36f0a2016-07-19 10:56:23 -07003343
Dan Sinclair1770c022016-03-14 14:14:16 -04003344void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
3345 int32_t argc = pArguments->GetLength();
3346 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07003347 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003348 if (!pNotify) {
3349 return;
3350 }
3351 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
3352 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003353 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04003354 }
3355}
dsinclair5b36f0a2016-07-19 10:56:23 -07003356
Dan Sinclair1770c022016-03-14 14:14:16 -04003357void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3358 CXFA_EventParam* pEventParam =
3359 m_pDocument->GetScriptContext()->GetEventParam();
3360 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3361 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3362 return;
3363 }
3364 int32_t argc = pArguments->GetLength();
3365 if (argc == 1) {
3366 const bool bScriptFlags = pArguments->GetInt32(0) != 0;
dsinclaira1b07722016-07-11 08:20:58 -07003367 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003368 if (!pNotify) {
3369 return;
3370 }
3371 if (bScriptFlags) {
3372 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3373 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
tsepezd19e9122016-11-02 15:43:18 -07003374 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003375 } else {
3376 }
3377 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003378 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003379 }
3380}
dsinclair5b36f0a2016-07-19 10:56:23 -07003381
Dan Sinclair1770c022016-03-14 14:14:16 -04003382void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
3383 int32_t argc = pArguments->GetLength();
3384 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07003385 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003386 if (!pNotify) {
3387 return;
3388 }
3389 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3390 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003391 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003392 }
3393}
dsinclair5b36f0a2016-07-19 10:56:23 -07003394
Dan Sinclair1770c022016-03-14 14:14:16 -04003395void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
3396 int32_t argc = pArguments->GetLength();
3397 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07003398 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003399 if (!pNotify) {
tsepezd19e9122016-11-02 15:43:18 -07003400 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003401 } else {
3402 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
dsinclairf27aeec2016-06-07 19:36:18 -07003403 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07003404 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003405 }
3406 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003407 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003408 }
3409}
dsinclair5b36f0a2016-07-19 10:56:23 -07003410
dsinclair12a6b0c2016-05-26 11:14:08 -07003411void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003412 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003413 XFA_ATTRIBUTE eAttribute) {
3414 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003415 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003416 } else {
3417 CFX_WideString wsChecksum;
tsepezd19e9122016-11-02 15:43:18 -07003418 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003419 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003420 FX_UTF8Encode(wsChecksum.c_str(), wsChecksum.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003421 }
3422}
dsinclair5b36f0a2016-07-19 10:56:23 -07003423
Dan Sinclair1770c022016-03-14 14:14:16 -04003424void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
3425 int32_t argc = pArguments->GetLength();
3426 if (argc == 1) {
3427 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3428 CFX_WideString wsAttributeValue;
dsinclairae95f762016-03-29 16:58:29 -07003429 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003430 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
tsepezbd9748d2016-04-13 21:40:19 -07003431 static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3432 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(),
3433 wsAttributeValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003434 }
dsinclairf27aeec2016-06-07 19:36:18 -07003435 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003436 FX_UTF8Encode(wsAttributeValue.c_str(), wsAttributeValue.GetLength())
tsepez4c3debb2016-04-08 12:20:38 -07003437 .AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003438 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003439 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04003440 }
3441}
dsinclair5b36f0a2016-07-19 10:56:23 -07003442
Dan Sinclair1770c022016-03-14 14:14:16 -04003443void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
3444 int32_t argc = pArguments->GetLength();
3445 if (argc == 2) {
3446 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3447 CFX_ByteString bsName = pArguments->GetUTF8String(1);
dsinclairae95f762016-03-29 16:58:29 -07003448 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003449 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003450 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(
3451 CFX_WideString::FromUTF8(bsName.AsStringC()),
3452 CFX_WideString::FromUTF8(bsValue.AsStringC()));
Dan Sinclair1770c022016-03-14 14:14:16 -04003453 }
dsinclairf27aeec2016-06-07 19:36:18 -07003454 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003455 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003456 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04003457 }
3458}
dsinclair5b36f0a2016-07-19 10:56:23 -07003459
Dan Sinclair1770c022016-03-14 14:14:16 -04003460void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
3461 int32_t argc = pArguments->GetLength();
3462 if (argc == 1) {
3463 CFX_ByteString bsName = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07003464 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
dsinclairae95f762016-03-29 16:58:29 -07003465 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003466 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003467 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
tsepezbd9748d2016-04-13 21:40:19 -07003468 if (pXMLElement->HasAttribute(wsName.c_str())) {
3469 pXMLElement->RemoveAttribute(wsName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04003470 }
3471 }
dsinclairf27aeec2016-06-07 19:36:18 -07003472 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003473 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003474 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"removeAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04003475 }
3476}
dsinclair5b36f0a2016-07-19 10:56:23 -07003477
dsinclair12a6b0c2016-05-26 11:14:08 -07003478void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003479 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003480 XFA_ATTRIBUTE eAttribute) {
3481 if (bSetting) {
dsinclairae95f762016-03-29 16:58:29 -07003482 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003483 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003484 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003485 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003486 }
3487 } else {
3488 CFX_WideString wsTextData;
dsinclairae95f762016-03-29 16:58:29 -07003489 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003490 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003491 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04003492 pXMLElement->GetTextData(wsTextData);
3493 }
dsinclairf27aeec2016-06-07 19:36:18 -07003494 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003495 FX_UTF8Encode(wsTextData.c_str(), wsTextData.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003496 }
3497}
dsinclair5b36f0a2016-07-19 10:56:23 -07003498
Dan Sinclair1770c022016-03-14 14:14:16 -04003499void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
3500 int32_t argc = pArguments->GetLength();
3501 if (argc == 0) {
3502 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003503 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003504 }
3505}
dsinclair5b36f0a2016-07-19 10:56:23 -07003506
Dan Sinclair1770c022016-03-14 14:14:16 -04003507void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
3508 int32_t argc = pArguments->GetLength();
3509 if (argc == 0) {
3510 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003511 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003512 }
3513}
dsinclair5b36f0a2016-07-19 10:56:23 -07003514
Dan Sinclair1770c022016-03-14 14:14:16 -04003515void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
3516 int32_t argc = pArguments->GetLength();
3517 if (argc == 0) {
3518 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003519 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003520 }
3521}
dsinclair5b36f0a2016-07-19 10:56:23 -07003522
Dan Sinclair1770c022016-03-14 14:14:16 -04003523void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
3524 int32_t argc = pArguments->GetLength();
3525 if (argc == 0) {
3526 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003527 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003528 }
3529}
dsinclair5b36f0a2016-07-19 10:56:23 -07003530
Dan Sinclair1770c022016-03-14 14:14:16 -04003531void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
3532 int32_t argc = pArguments->GetLength();
3533 if (argc == 0) {
3534 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003535 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003536 }
3537}
dsinclair5b36f0a2016-07-19 10:56:23 -07003538
Dan Sinclair1770c022016-03-14 14:14:16 -04003539void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
3540 int32_t argc = pArguments->GetLength();
3541 if (argc == 0) {
3542 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003543 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003544 }
3545}
dsinclair5b36f0a2016-07-19 10:56:23 -07003546
Dan Sinclair1770c022016-03-14 14:14:16 -04003547void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
3548 int32_t argc = pArguments->GetLength();
3549 if (argc == 0) {
3550 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003551 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003552 }
3553}
dsinclair5b36f0a2016-07-19 10:56:23 -07003554
Dan Sinclair1770c022016-03-14 14:14:16 -04003555void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
3556 int32_t argc = pArguments->GetLength();
3557 if (argc == 0) {
3558 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003559 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003560 }
3561}
dsinclair5b36f0a2016-07-19 10:56:23 -07003562
Dan Sinclair1770c022016-03-14 14:14:16 -04003563void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
3564 int32_t argc = pArguments->GetLength();
3565 if (argc == 0) {
3566 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003567 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003568 }
3569}
dsinclair5b36f0a2016-07-19 10:56:23 -07003570
Dan Sinclair1770c022016-03-14 14:14:16 -04003571void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
3572 int32_t argc = pArguments->GetLength();
3573 if (argc == 0) {
3574 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003575 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003576 }
3577}
dsinclair5b36f0a2016-07-19 10:56:23 -07003578
Dan Sinclair1770c022016-03-14 14:14:16 -04003579void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
3580 int32_t argc = pArguments->GetLength();
3581 if (argc == 0) {
3582 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003583 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003584 }
3585}
dsinclair5b36f0a2016-07-19 10:56:23 -07003586
Dan Sinclair1770c022016-03-14 14:14:16 -04003587void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
3588 int32_t argc = pArguments->GetLength();
3589 if (argc == 0) {
3590 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003591 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003592 }
3593}
dsinclair5b36f0a2016-07-19 10:56:23 -07003594
Dan Sinclair1770c022016-03-14 14:14:16 -04003595void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
3596 int32_t argc = pArguments->GetLength();
3597 if (argc == 0) {
3598 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003599 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003600 }
3601}
dsinclair5b36f0a2016-07-19 10:56:23 -07003602
Dan Sinclair1770c022016-03-14 14:14:16 -04003603void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
3604 int32_t argc = pArguments->GetLength();
3605 if (argc == 0) {
3606 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003607 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003608 }
3609}
dsinclair5b36f0a2016-07-19 10:56:23 -07003610
Dan Sinclair1770c022016-03-14 14:14:16 -04003611void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
3612 int32_t argc = pArguments->GetLength();
3613 if (argc == 0) {
3614 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003615 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003616 }
3617}
dsinclair5b36f0a2016-07-19 10:56:23 -07003618
Dan Sinclair1770c022016-03-14 14:14:16 -04003619void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
3620 int32_t argc = pArguments->GetLength();
3621 if (argc == 0) {
3622 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003623 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003624 }
3625}
dsinclair5b36f0a2016-07-19 10:56:23 -07003626
Dan Sinclair1770c022016-03-14 14:14:16 -04003627void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
3628 int32_t argc = pArguments->GetLength();
3629 if (argc == 0) {
3630 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003631 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003632 }
3633}
dsinclair5b36f0a2016-07-19 10:56:23 -07003634
dsinclair12a6b0c2016-05-26 11:14:08 -07003635void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003636 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003637 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003638
dsinclair12a6b0c2016-05-26 11:14:08 -07003639void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003640 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003641 XFA_ATTRIBUTE eAttribute) {
3642 if (!bSetting) {
3643 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003644 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003645 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003646 }
3647}
dsinclair5b36f0a2016-07-19 10:56:23 -07003648
dsinclair12a6b0c2016-05-26 11:14:08 -07003649void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003650 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003651 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003652
dsinclair12a6b0c2016-05-26 11:14:08 -07003653void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003654 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003655 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003656
dsinclair12a6b0c2016-05-26 11:14:08 -07003657void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003658 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003659 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003660
dsinclair12a6b0c2016-05-26 11:14:08 -07003661void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003662 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003663 XFA_ATTRIBUTE eAttribute) {
3664 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07003665 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04003666 return;
3667 }
dsinclairf27aeec2016-06-07 19:36:18 -07003668 pValue->SetString(FX_UTF8Encode(FX_WSTRC(L"0")).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003669}
dsinclair5b36f0a2016-07-19 10:56:23 -07003670
dsinclair12a6b0c2016-05-26 11:14:08 -07003671void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003672 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003673 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003674
tsepezd19e9122016-11-02 15:43:18 -07003675bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003676 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003677 return HasMapModuleKey(pKey, bCanInherit);
3678}
dsinclair5b36f0a2016-07-19 10:56:23 -07003679
tsepezd19e9122016-11-02 15:43:18 -07003680bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3681 const CFX_WideStringC& wsValue,
3682 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003683 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003684 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003685 return false;
weili44f8faf2016-06-01 14:03:56 -07003686
Dan Sinclair1770c022016-03-14 14:14:16 -04003687 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3688 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3689 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003690 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003691 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3692 }
3693 switch (eType) {
3694 case XFA_ATTRIBUTETYPE_Enum: {
3695 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3696 return SetEnum(pAttr->eName,
3697 pEnum ? pEnum->eName
3698 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3699 bNotify);
3700 } break;
3701 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003702 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003703 case XFA_ATTRIBUTETYPE_Boolean:
3704 return SetBoolean(pAttr->eName, wsValue != FX_WSTRC(L"0"), bNotify);
3705 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003706 return SetInteger(pAttr->eName,
3707 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3708 wsValue.GetLength(), nullptr)),
3709 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003710 case XFA_ATTRIBUTETYPE_Measure:
3711 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3712 default:
3713 break;
3714 }
tsepezd19e9122016-11-02 15:43:18 -07003715 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003716}
dsinclair5b36f0a2016-07-19 10:56:23 -07003717
tsepezd19e9122016-11-02 15:43:18 -07003718bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3719 CFX_WideString& wsValue,
3720 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003721 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003722 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003723 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003724 }
3725 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3726 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3727 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003728 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003729 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3730 }
3731 switch (eType) {
3732 case XFA_ATTRIBUTETYPE_Enum: {
3733 XFA_ATTRIBUTEENUM eValue;
3734 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003735 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003736 }
dsinclair9eb0db12016-07-21 12:01:39 -07003737 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003738 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003739 } break;
3740 case XFA_ATTRIBUTETYPE_Cdata: {
3741 CFX_WideStringC wsValueC;
3742 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003743 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003744 }
3745 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003746 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003747 } break;
3748 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003749 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003750 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003751 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003752 }
3753 wsValue = bValue ? FX_WSTRC(L"1") : FX_WSTRC(L"0");
tsepezd19e9122016-11-02 15:43:18 -07003754 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003755 } break;
3756 case XFA_ATTRIBUTETYPE_Integer: {
3757 int32_t iValue;
3758 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003759 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003760 }
3761 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003762 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003763 } break;
3764 case XFA_ATTRIBUTETYPE_Measure: {
3765 CXFA_Measurement mValue;
3766 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003767 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003768 }
3769 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003770 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003771 } break;
3772 default:
3773 break;
3774 }
tsepezd19e9122016-11-02 15:43:18 -07003775 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003776}
dsinclair5b36f0a2016-07-19 10:56:23 -07003777
tsepezd19e9122016-11-02 15:43:18 -07003778bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3779 const CFX_WideStringC& wsValue,
3780 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003781 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3782 if (pAttributeInfo) {
3783 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3784 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003785 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003786 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003787 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003788}
dsinclair5b36f0a2016-07-19 10:56:23 -07003789
tsepezd19e9122016-11-02 15:43:18 -07003790bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3791 CFX_WideString& wsValue,
3792 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003793 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3794 if (pAttributeInfo) {
3795 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3796 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003797 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003798 CFX_WideStringC wsValueC;
3799 if (GetMapModuleString(pKey, wsValueC)) {
3800 wsValue = wsValueC;
3801 }
tsepezd19e9122016-11-02 15:43:18 -07003802 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003803}
dsinclair5b36f0a2016-07-19 10:56:23 -07003804
tsepezd19e9122016-11-02 15:43:18 -07003805bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003806 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003807 RemoveMapModuleKey(pKey);
tsepezd19e9122016-11-02 15:43:18 -07003808 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003809}
dsinclair5b36f0a2016-07-19 10:56:23 -07003810
tsepezd19e9122016-11-02 15:43:18 -07003811bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3812 bool& bValue,
3813 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003814 void* pValue = nullptr;
3815 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003816 return false;
tsepez478ed622016-10-27 14:32:33 -07003817 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003818 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003819}
dsinclair5b36f0a2016-07-19 10:56:23 -07003820
tsepezd19e9122016-11-02 15:43:18 -07003821bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3822 int32_t& iValue,
3823 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003824 void* pValue = nullptr;
3825 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003826 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003827 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003828 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003829}
dsinclair5b36f0a2016-07-19 10:56:23 -07003830
tsepezd19e9122016-11-02 15:43:18 -07003831bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3832 XFA_ATTRIBUTEENUM& eValue,
3833 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003834 void* pValue = nullptr;
3835 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003836 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003837 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003838 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003839}
thestigb1a59592016-04-14 18:29:56 -07003840
tsepezd19e9122016-11-02 15:43:18 -07003841bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3842 CXFA_Measurement mValue,
3843 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003844 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003845 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003846 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003847 OnChanged(eAttr, bNotify, false);
3848 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003849}
thestigb1a59592016-04-14 18:29:56 -07003850
tsepezd19e9122016-11-02 15:43:18 -07003851bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3852 CXFA_Measurement& mValue,
3853 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003854 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003855 void* pValue;
3856 int32_t iBytes;
3857 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
3858 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003859 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003860 }
3861 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003862 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003863 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
3864 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003865 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003866 }
tsepezd19e9122016-11-02 15:43:18 -07003867 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003868}
3869
3870CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3871 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003872 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003873}
3874
tsepezd19e9122016-11-02 15:43:18 -07003875bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3876 const CFX_WideString& wsValue,
3877 bool bNotify,
3878 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003879 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003880 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003881 if (eAttr == XFA_ATTRIBUTE_Value) {
3882 CFX_WideString* pClone = new CFX_WideString(wsValue);
3883 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3884 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003885 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003886 if (eAttr == XFA_ATTRIBUTE_Name)
3887 UpdateNameHash();
3888 }
thestigb1a59592016-04-14 18:29:56 -07003889 OnChanged(eAttr, bNotify, bScriptModify);
3890
3891 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3892 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003893 return true;
thestigb1a59592016-04-14 18:29:56 -07003894 }
3895
dsinclair070fcdf2016-06-22 22:04:54 -07003896 if (eAttr == XFA_ATTRIBUTE_Name &&
3897 (m_elementType == XFA_Element::DataValue ||
3898 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003899 return true;
thestigb1a59592016-04-14 18:29:56 -07003900 }
3901
3902 if (eAttr == XFA_ATTRIBUTE_Value) {
3903 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3904 switch (eXMLType) {
3905 case FDE_XMLNODE_Element:
3906 if (IsAttributeInXML()) {
3907 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003908 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3909 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003910 } else {
tsepezd19e9122016-11-02 15:43:18 -07003911 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003912 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3913 for (CXFA_Node* pChildDataNode =
3914 GetNodeItem(XFA_NODEITEM_FirstChild);
3915 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3916 XFA_NODEITEM_NextSibling)) {
3917 CXFA_NodeArray formNodes;
3918 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003919 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003920 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003921 }
3922 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003923 }
thestigb1a59592016-04-14 18:29:56 -07003924 if (bDeleteChildren) {
3925 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3926 }
3927 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3928 }
3929 break;
3930 case FDE_XMLNODE_Text:
3931 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3932 break;
3933 default:
dsinclair43854a52016-04-27 12:26:00 -07003934 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003935 }
tsepezd19e9122016-11-02 15:43:18 -07003936 return true;
thestigb1a59592016-04-14 18:29:56 -07003937 }
3938
3939 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3940 if (pInfo) {
dsinclair43854a52016-04-27 12:26:00 -07003941 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003942 CFX_WideString wsAttrName = pInfo->pName;
3943 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
3944 wsAttrName = FX_WSTRC(L"xfa:") + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003945 }
thestigb1a59592016-04-14 18:29:56 -07003946 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003947 }
tsepezd19e9122016-11-02 15:43:18 -07003948 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003949}
thestigb1a59592016-04-14 18:29:56 -07003950
tsepezd19e9122016-11-02 15:43:18 -07003951bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3952 const CFX_WideString& wsXMLValue,
3953 bool bNotify,
3954 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003955 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003956 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003957 CFX_WideString* pClone = new CFX_WideString(wsValue);
3958 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003959 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003960 if (IsNeedSavingXMLNode()) {
3961 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3962 switch (eXMLType) {
3963 case FDE_XMLNODE_Element:
3964 if (IsAttributeInXML()) {
dsinclairae95f762016-03-29 16:58:29 -07003965 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003966 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3967 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003968 } else {
tsepezd19e9122016-11-02 15:43:18 -07003969 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003970 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3971 for (CXFA_Node* pChildDataNode =
3972 GetNodeItem(XFA_NODEITEM_FirstChild);
3973 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3974 XFA_NODEITEM_NextSibling)) {
3975 CXFA_NodeArray formNodes;
3976 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003977 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003978 break;
3979 }
3980 }
3981 }
3982 if (bDeleteChildren) {
dsinclairae95f762016-03-29 16:58:29 -07003983 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003984 }
dsinclairae95f762016-03-29 16:58:29 -07003985 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003986 }
3987 break;
3988 case FDE_XMLNODE_Text:
dsinclairae95f762016-03-29 16:58:29 -07003989 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003990 break;
3991 default:
dsinclair43854a52016-04-27 12:26:00 -07003992 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003993 }
3994 }
tsepezd19e9122016-11-02 15:43:18 -07003995 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003996}
dsinclair5b36f0a2016-07-19 10:56:23 -07003997
tsepezd19e9122016-11-02 15:43:18 -07003998bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3999 CFX_WideString& wsValue,
4000 bool bUseDefault,
4001 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004002 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004003 if (eAttr == XFA_ATTRIBUTE_Value) {
4004 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
4005 if (pStr) {
4006 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07004007 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004008 }
4009 } else {
4010 CFX_WideStringC wsValueC;
4011 if (GetMapModuleString(pKey, wsValueC)) {
4012 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07004013 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004014 }
4015 }
4016 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004017 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004018 }
weili44f8faf2016-06-01 14:03:56 -07004019 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07004020 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04004021 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
4022 wsValue = (const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07004023 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004024 }
tsepezd19e9122016-11-02 15:43:18 -07004025 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004026}
dsinclair5b36f0a2016-07-19 10:56:23 -07004027
tsepezd19e9122016-11-02 15:43:18 -07004028bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
4029 CFX_WideStringC& wsValue,
4030 bool bUseDefault,
4031 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004032 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004033 if (eAttr == XFA_ATTRIBUTE_Value) {
4034 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
4035 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07004036 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07004037 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004038 }
4039 } else {
4040 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004041 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004042 }
4043 }
4044 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004045 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004046 }
weili44f8faf2016-06-01 14:03:56 -07004047 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07004048 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04004049 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
4050 wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07004051 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004052 }
tsepezd19e9122016-11-02 15:43:18 -07004053 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004054}
dsinclair5b36f0a2016-07-19 10:56:23 -07004055
tsepezd19e9122016-11-02 15:43:18 -07004056bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
4057 void* pData,
4058 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004059 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004060 return SetUserData(pKey, pData, pCallbackInfo);
4061}
dsinclair5b36f0a2016-07-19 10:56:23 -07004062
tsepezd19e9122016-11-02 15:43:18 -07004063bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004064 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004065 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07004066 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04004067}
dsinclair5b36f0a2016-07-19 10:56:23 -07004068
tsepezd19e9122016-11-02 15:43:18 -07004069bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
4070 XFA_ATTRIBUTETYPE eType,
4071 void* pValue,
4072 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004073 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07004074 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004075 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07004076 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004077 if (IsNeedSavingXMLNode()) {
dsinclair43854a52016-04-27 12:26:00 -07004078 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004079 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
4080 if (pInfo) {
4081 switch (eType) {
4082 case XFA_ATTRIBUTETYPE_Enum:
dsinclairae95f762016-03-29 16:58:29 -07004083 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004084 ->SetString(
4085 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07004086 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04004087 ->pName);
4088 break;
4089 case XFA_ATTRIBUTETYPE_Boolean:
dsinclairae95f762016-03-29 16:58:29 -07004090 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07004091 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04004092 break;
4093 case XFA_ATTRIBUTETYPE_Integer:
dsinclairae95f762016-03-29 16:58:29 -07004094 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004095 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue);
4096 break;
4097 default:
dsinclair43854a52016-04-27 12:26:00 -07004098 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04004099 }
4100 }
4101 }
tsepezd19e9122016-11-02 15:43:18 -07004102 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004103}
dsinclair5b36f0a2016-07-19 10:56:23 -07004104
tsepezd19e9122016-11-02 15:43:18 -07004105bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
4106 XFA_ATTRIBUTETYPE eType,
4107 bool bUseDefault,
4108 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004109 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004110 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004111 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004112 }
4113 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004114 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004115 }
dsinclair070fcdf2016-06-22 22:04:54 -07004116 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004117 m_ePacket);
4118}
dsinclair5b36f0a2016-07-19 10:56:23 -07004119
tsepezd19e9122016-11-02 15:43:18 -07004120bool CXFA_Node::SetUserData(void* pKey,
4121 void* pData,
4122 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004123 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4124 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004125 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004126}
dsinclair5b36f0a2016-07-19 10:56:23 -07004127
tsepezd19e9122016-11-02 15:43:18 -07004128bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004129 int32_t iBytes = 0;
4130 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004131 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004132 }
4133 return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes);
4134}
dsinclair5b36f0a2016-07-19 10:56:23 -07004135
tsepezd19e9122016-11-02 15:43:18 -07004136bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4137 const CFX_WideString& wsXMLValue,
4138 bool bNotify,
4139 bool bScriptModify,
4140 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004141 CXFA_Node* pNode = nullptr;
4142 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004143 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004144 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004145 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004146 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004147 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004148 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004149 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004150 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004151 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004152 CXFA_Node* pBind = GetBindData();
4153 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004154 std::vector<CFX_WideString> wsSaveTextArray;
Dan Sinclair1770c022016-03-14 14:14:16 -04004155 int32_t iSize = 0;
4156 if (!wsContent.IsEmpty()) {
4157 int32_t iStart = 0;
4158 int32_t iLength = wsContent.GetLength();
4159 int32_t iEnd = wsContent.Find(L'\n', iStart);
4160 iEnd = (iEnd == -1) ? iLength : iEnd;
4161 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004162 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004163 iStart = iEnd + 1;
4164 if (iStart >= iLength) {
4165 break;
4166 }
4167 iEnd = wsContent.Find(L'\n', iStart);
4168 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004169 wsSaveTextArray.push_back(
4170 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004171 }
4172 }
tsepez51709be2016-12-08 10:55:57 -08004173 iSize = pdfium::CollectionSize<int32_t>(wsSaveTextArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04004174 }
4175 if (iSize == 0) {
4176 while (CXFA_Node* pChildNode =
4177 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4178 pBind->RemoveChild(pChildNode);
4179 }
4180 } else {
4181 CXFA_NodeArray valueNodes;
4182 int32_t iDatas = pBind->GetNodeList(
dsinclair56a8b192016-06-21 14:15:25 -07004183 valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004184 if (iDatas < iSize) {
4185 int32_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004186 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004187 while (iAddNodes-- > 0) {
4188 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004189 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004190 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004191 pValueNodes->CreateXMLMappingNode();
4192 pBind->InsertChild(pValueNodes);
4193 }
weili44f8faf2016-06-01 14:03:56 -07004194 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004195 } else if (iDatas > iSize) {
4196 int32_t iDelNodes = iDatas - iSize;
4197 while (iDelNodes-- > 0) {
4198 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4199 }
4200 }
4201 int32_t i = 0;
4202 for (CXFA_Node* pValueNode =
4203 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4204 pValueNode; pValueNode = pValueNode->GetNodeItem(
4205 XFA_NODEITEM_NextSibling)) {
4206 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004207 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004208 i++;
4209 }
4210 }
4211 CXFA_NodeArray nodeArray;
4212 pBind->GetBindItems(nodeArray);
4213 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004214 if (nodeArray[i] != this) {
4215 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004216 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004217 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004218 }
4219 }
4220 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004221 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004222 pNode = this;
4223 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004224 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004225 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004226 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004227 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004228 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004229 }
4230 pBindNode = GetBindData();
4231 if (pBindNode && bSyncData) {
4232 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004233 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004234 CXFA_NodeArray nodeArray;
4235 pBindNode->GetBindItems(nodeArray);
4236 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004237 if (nodeArray[i] != this) {
4238 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true,
tsepezd19e9122016-11-02 15:43:18 -07004239 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004240 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004241 }
4242 }
weili44f8faf2016-06-01 14:03:56 -07004243 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004244 break;
4245 }
dsinclairc5a8f212016-06-20 11:11:12 -07004246 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004247 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004248 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004249 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
tsepez9f2970c2016-04-01 10:23:04 -07004250 if (wsContentType == FX_WSTRC(L"text/html")) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004251 wsContentType = FX_WSTRC(L"");
tsepez4c3debb2016-04-08 12:20:38 -07004252 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004253 }
4254 }
4255 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4256 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004257 pContentRawDataNode = CreateSamePacketNode(
dsinclair56a8b192016-06-21 14:15:25 -07004258 (wsContentType == FX_WSTRC(L"text/xml")) ? XFA_Element::Sharpxml
4259 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004260 InsertChild(pContentRawDataNode);
4261 }
4262 return pContentRawDataNode->SetScriptContent(
4263 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4264 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004265 case XFA_ObjectType::NodeC:
4266 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004267 pNode = this;
4268 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004269 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004270 pNode = this;
4271 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4272 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4273 if (pParent) {
4274 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4275 }
dsinclair070fcdf2016-06-22 22:04:54 -07004276 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004277 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4278 if (pParent && pParent->IsContainerNode()) {
4279 pBindNode = pParent->GetBindData();
4280 if (pBindNode) {
4281 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004282 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004283 }
4284 }
4285 }
4286 }
4287 break;
4288 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004289 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004290 pNode = this;
4291 pBindNode = this;
4292 }
4293 break;
4294 }
4295 if (pNode) {
4296 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4297 if (pBindNode && bSyncData) {
4298 CXFA_NodeArray nodeArray;
4299 pBindNode->GetBindItems(nodeArray);
4300 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004301 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004302 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004303 }
4304 }
tsepezd19e9122016-11-02 15:43:18 -07004305 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004306 }
tsepezd19e9122016-11-02 15:43:18 -07004307 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004308}
dsinclair5b36f0a2016-07-19 10:56:23 -07004309
tsepezd19e9122016-11-02 15:43:18 -07004310bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4311 const CFX_WideString& wsXMLValue,
4312 bool bNotify,
4313 bool bScriptModify,
4314 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004315 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4316 bSyncData);
4317}
dsinclair5b36f0a2016-07-19 10:56:23 -07004318
tsepezd19e9122016-11-02 15:43:18 -07004319CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004320 CFX_WideString wsContent;
4321 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4322}
dsinclair5b36f0a2016-07-19 10:56:23 -07004323
Dan Sinclair1770c022016-03-14 14:14:16 -04004324CFX_WideString CXFA_Node::GetContent() {
4325 return GetScriptContent();
4326}
dsinclair5b36f0a2016-07-19 10:56:23 -07004327
tsepezd19e9122016-11-02 15:43:18 -07004328bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4329 bool bScriptModify,
4330 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004331 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004332 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004333 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004334 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004335 pNode = this;
4336 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004337 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004338 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004339 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004340 }
4341 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4342 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
4343 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType,
4344 FX_WSTRC(L"text/xml"));
4345 }
4346 return pChildValue
4347 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004348 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004349 }
4350 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004351 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004352 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4353 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004354 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004355 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004356 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004357 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
tsepez9f2970c2016-04-01 10:23:04 -07004358 if (wsContentType == FX_WSTRC(L"text/html")) {
dsinclair56a8b192016-06-21 14:15:25 -07004359 element = XFA_Element::SharpxHTML;
tsepez9f2970c2016-04-01 10:23:04 -07004360 } else if (wsContentType == FX_WSTRC(L"text/xml")) {
dsinclair56a8b192016-06-21 14:15:25 -07004361 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004362 }
4363 }
4364 pContentRawDataNode = CreateSamePacketNode(element);
4365 InsertChild(pContentRawDataNode);
4366 }
4367 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4368 }
dsinclairc5a8f212016-06-20 11:11:12 -07004369 case XFA_ObjectType::NodeC:
4370 case XFA_ObjectType::NodeV:
4371 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004372 pNode = this;
4373 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004374 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004375 pNode = this;
4376 }
4377 break;
4378 }
4379 if (pNode) {
4380 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004381 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004382 if (pScriptContext) {
4383 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4384 }
4385 }
tsepezd19e9122016-11-02 15:43:18 -07004386 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004387 }
tsepezd19e9122016-11-02 15:43:18 -07004388 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004389}
dsinclair5b36f0a2016-07-19 10:56:23 -07004390
Dan Sinclair1770c022016-03-14 14:14:16 -04004391CXFA_Node* CXFA_Node::GetModelNode() {
4392 switch (GetPacketID()) {
4393 case XFA_XDPPACKET_XDP:
4394 return m_pDocument->GetRoot();
4395 case XFA_XDPPACKET_Config:
4396 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4397 case XFA_XDPPACKET_Template:
4398 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4399 case XFA_XDPPACKET_Form:
4400 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4401 case XFA_XDPPACKET_Datasets:
4402 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4403 case XFA_XDPPACKET_LocaleSet:
4404 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4405 case XFA_XDPPACKET_ConnectionSet:
4406 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4407 case XFA_XDPPACKET_SourceSet:
4408 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4409 case XFA_XDPPACKET_Xdc:
4410 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4411 default:
4412 return this;
4413 }
4414}
dsinclair5b36f0a2016-07-19 10:56:23 -07004415
tsepezd19e9122016-11-02 15:43:18 -07004416bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004417 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004418 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
dsinclairae95f762016-03-29 16:58:29 -07004419 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004420 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004421 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004422 }
dsinclairae95f762016-03-29 16:58:29 -07004423 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004424 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004425 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
dsinclairae95f762016-03-29 16:58:29 -07004426 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004427 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004428 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004429 }
4430 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004431 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004432 }
dsinclair070fcdf2016-06-22 22:04:54 -07004433 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004434 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4435 return XFA_FDEExtension_ResolveNamespaceQualifier(
dsinclairae95f762016-03-29 16:58:29 -07004436 static_cast<CFDE_XMLElement*>(pXMLNode),
4437 GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004438 }
dsinclairae95f762016-03-29 16:58:29 -07004439 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004440 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004441 } else {
4442 CXFA_Node* pModelNode = GetModelNode();
4443 return pModelNode->TryNamespace(wsNamespace);
4444 }
4445}
dsinclair5b36f0a2016-07-19 10:56:23 -07004446
Dan Sinclair1770c022016-03-14 14:14:16 -04004447CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004448 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004449 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004450 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004451 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004452 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004453 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004454 if (!pProperty || index >= pProperty->uOccur)
4455 return nullptr;
4456
Dan Sinclair1770c022016-03-14 14:14:16 -04004457 CXFA_Node* pNode = m_pChild;
4458 int32_t iCount = 0;
4459 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004460 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004461 iCount++;
4462 if (iCount > index) {
4463 return pNode;
4464 }
4465 }
4466 }
weili44f8faf2016-06-01 14:03:56 -07004467 if (!bCreateProperty)
4468 return nullptr;
4469
Dan Sinclair1770c022016-03-14 14:14:16 -04004470 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4471 pNode = m_pChild;
4472 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4473 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004474 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004475 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4476 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004477 }
4478 }
dsinclaira1b07722016-07-11 08:20:58 -07004479
Dan Sinclair1770c022016-03-14 14:14:16 -04004480 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004481 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004482 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004483 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004484 if (!pNewNode)
4485 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004486 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004487 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004488 }
4489 return pNewNode;
4490}
dsinclair5b36f0a2016-07-19 10:56:23 -07004491
tsepezd19e9122016-11-02 15:43:18 -07004492int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004493 CXFA_Node* pNode = m_pChild;
4494 int32_t iCount = 0;
4495 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004496 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004497 if (bOnlyChild) {
4498 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004499 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004500 if (pProperty) {
4501 continue;
4502 }
4503 }
4504 iCount++;
4505 }
4506 }
4507 return iCount;
4508}
dsinclair5b36f0a2016-07-19 10:56:23 -07004509
Dan Sinclair1770c022016-03-14 14:14:16 -04004510CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004511 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004512 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004513 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004514 CXFA_Node* pNode = m_pChild;
4515 int32_t iCount = 0;
4516 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004517 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004518 if (bOnlyChild) {
4519 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004520 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004521 if (pProperty) {
4522 continue;
4523 }
4524 }
4525 iCount++;
4526 if (iCount > index) {
4527 return pNode;
4528 }
4529 }
4530 }
weili44f8faf2016-06-01 14:03:56 -07004531 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004532}
dsinclair5b36f0a2016-07-19 10:56:23 -07004533
Dan Sinclair1770c022016-03-14 14:14:16 -04004534int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4535 ASSERT(!pNode->m_pNext);
4536 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004537 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004538 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004539 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004540
weili44f8faf2016-06-01 14:03:56 -07004541 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004542 if (index > 0) {
4543 return -1;
4544 }
4545 pNode->m_pNext = m_pChild;
4546 m_pChild = pNode;
4547 index = 0;
4548 } else if (index < 0) {
4549 m_pLastChild->m_pNext = pNode;
4550 } else {
4551 CXFA_Node* pPrev = m_pChild;
4552 int32_t iCount = 0;
4553 while (++iCount != index && pPrev->m_pNext) {
4554 pPrev = pPrev->m_pNext;
4555 }
4556 if (index > 0 && index != iCount) {
4557 return -1;
4558 }
4559 pNode->m_pNext = pPrev->m_pNext;
4560 pPrev->m_pNext = pNode;
4561 index = iCount;
4562 }
weili44f8faf2016-06-01 14:03:56 -07004563 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004564 m_pLastChild = pNode;
4565 }
4566 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004567 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004568 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004569 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004570 if (pNotify)
4571 pNotify->OnChildAdded(this);
4572
Dan Sinclair1770c022016-03-14 14:14:16 -04004573 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004574 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004575 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004576 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004577 }
4578 return index;
4579}
weili6e1ae862016-05-04 18:25:27 -07004580
tsepezd19e9122016-11-02 15:43:18 -07004581bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004582 if (!pNode || pNode->m_pParent ||
4583 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004584 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004585 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004586 }
tsepezd19e9122016-11-02 15:43:18 -07004587 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004588 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004589 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004590
4591 int32_t nIndex = -1;
4592 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004593 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004594 pNode->m_pNext = m_pChild;
4595 m_pChild = pNode;
4596 nIndex = 0;
4597 } else if (!pBeforeNode) {
4598 pNode->m_pNext = m_pLastChild->m_pNext;
4599 m_pLastChild->m_pNext = pNode;
4600 } else {
4601 nIndex = 1;
4602 CXFA_Node* pPrev = m_pChild;
4603 while (pPrev->m_pNext != pBeforeNode) {
4604 pPrev = pPrev->m_pNext;
4605 nIndex++;
4606 }
4607 pNode->m_pNext = pPrev->m_pNext;
4608 pPrev->m_pNext = pNode;
4609 }
weili44f8faf2016-06-01 14:03:56 -07004610 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004611 m_pLastChild = pNode;
4612 }
4613 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004614 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004615 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004616 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004617 if (pNotify)
4618 pNotify->OnChildAdded(this);
4619
Dan Sinclair1770c022016-03-14 14:14:16 -04004620 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004621 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004622 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004623 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004624 }
tsepezd19e9122016-11-02 15:43:18 -07004625 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004626}
dsinclair5b36f0a2016-07-19 10:56:23 -07004627
Dan Sinclair1770c022016-03-14 14:14:16 -04004628CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4629 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004630 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004631 }
4632 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4633 pSibling = pSibling->m_pNext) {
4634 if (pSibling->m_pNext == this) {
4635 return pSibling;
4636 }
4637 }
weili44f8faf2016-06-01 14:03:56 -07004638 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004639}
dsinclair5b36f0a2016-07-19 10:56:23 -07004640
tsepezd19e9122016-11-02 15:43:18 -07004641bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004642 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004643 ASSERT(false);
4644 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004645 }
4646 if (m_pChild == pNode) {
4647 m_pChild = pNode->m_pNext;
4648 if (m_pLastChild == pNode) {
4649 m_pLastChild = pNode->m_pNext;
4650 }
weili44f8faf2016-06-01 14:03:56 -07004651 pNode->m_pNext = nullptr;
4652 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004653 } else {
4654 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4655 pPrev->m_pNext = pNode->m_pNext;
4656 if (m_pLastChild == pNode) {
4657 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4658 }
weili44f8faf2016-06-01 14:03:56 -07004659 pNode->m_pNext = nullptr;
4660 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004661 }
weili44f8faf2016-06-01 14:03:56 -07004662 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004663 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004664 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004665 m_pDocument->AddPurgeNode(pNode);
4666 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4667 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004668 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4669 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004670 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07004671 CFDE_XMLElement* pXMLElement =
4672 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004673 CFX_WideStringC wsAttributeName =
4674 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004675 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004676 }
4677 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004678 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -07004679 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004680 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4681 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004682 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004683 }
4684 pNode->m_pXMLNode = pNewXMLElement;
4685 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4686 } else {
4687 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4688 }
dsinclairc5a8f212016-06-20 11:11:12 -07004689 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004690 }
tsepezd19e9122016-11-02 15:43:18 -07004691 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004692}
dsinclair5b36f0a2016-07-19 10:56:23 -07004693
Dan Sinclair1770c022016-03-14 14:14:16 -04004694CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004695 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004696}
dsinclair5b36f0a2016-07-19 10:56:23 -07004697
tsepez736f28a2016-03-25 14:19:51 -07004698CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004699 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4700 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4701 if (pNode->GetNameHash() == dwNameHash) {
4702 return pNode;
4703 }
4704 }
weili44f8faf2016-06-01 14:03:56 -07004705 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004706}
dsinclair5b36f0a2016-07-19 10:56:23 -07004707
dsinclair41cb62e2016-06-23 09:20:32 -07004708CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004709 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4710 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004711 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004712 return pNode;
4713 }
4714 }
weili44f8faf2016-06-01 14:03:56 -07004715 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004716}
dsinclair5b36f0a2016-07-19 10:56:23 -07004717
tsepez736f28a2016-03-25 14:19:51 -07004718CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004719 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4720 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4721 if (pNode->GetNameHash() == dwNameHash) {
4722 return pNode;
4723 }
4724 }
weili44f8faf2016-06-01 14:03:56 -07004725 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004726}
dsinclair5b36f0a2016-07-19 10:56:23 -07004727
Dan Sinclair1770c022016-03-14 14:14:16 -04004728CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4729 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004730 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004731}
dsinclair5b36f0a2016-07-19 10:56:23 -07004732
dsinclair41cb62e2016-06-23 09:20:32 -07004733CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004734 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4735 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004736 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004737 return pNode;
4738 }
4739 }
weili44f8faf2016-06-01 14:03:56 -07004740 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004741}
dsinclair5b36f0a2016-07-19 10:56:23 -07004742
Dan Sinclair1770c022016-03-14 14:14:16 -04004743int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004744 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004745 if (!pScriptContext) {
4746 return -1;
4747 }
4748 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4749}
dsinclair5b36f0a2016-07-19 10:56:23 -07004750
Dan Sinclair1770c022016-03-14 14:14:16 -04004751int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004752 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004753 if (!pScriptContext) {
4754 return -1;
4755 }
4756 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4757}
dsinclair5b36f0a2016-07-19 10:56:23 -07004758
Dan Sinclair1770c022016-03-14 14:14:16 -04004759void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004760 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004761 if (!pScriptContext) {
4762 return;
4763 }
4764 pScriptContext->GetSomExpression(this, wsSOMExpression);
4765}
dsinclair5b36f0a2016-07-19 10:56:23 -07004766
Dan Sinclair1770c022016-03-14 14:14:16 -04004767CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004768 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004769 if (m_ePacket == XFA_XDPPACKET_Form) {
4770 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004771 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004772 return pInstanceMgr;
4773 }
4774 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4775 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004776 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004777 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004778 pNode->m_dwNameHash != m_dwNameHash) {
4779 break;
4780 }
dsinclair56a8b192016-06-21 14:15:25 -07004781 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004782 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4783 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4784 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4785 wsInstName.Mid(1) == wsName) {
4786 pInstanceMgr = pNode;
4787 }
4788 break;
4789 }
4790 }
4791 }
4792 return pInstanceMgr;
4793}
dsinclair5b36f0a2016-07-19 10:56:23 -07004794
Dan Sinclair1770c022016-03-14 14:14:16 -04004795CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004796 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004797}
dsinclair5b36f0a2016-07-19 10:56:23 -07004798
dsinclairc5a8f212016-06-20 11:11:12 -07004799bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4800 if (m_uNodeFlags & dwFlag)
4801 return true;
4802 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4803 return m_pParent && m_pParent->HasFlag(dwFlag);
4804 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004805}
thestigb1a59592016-04-14 18:29:56 -07004806
4807void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004808 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004809 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004810 if (pNotify) {
4811 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004812 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004813 }
dsinclairc5a8f212016-06-20 11:11:12 -07004814 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004815}
thestigb1a59592016-04-14 18:29:56 -07004816
4817void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004818 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004819}
4820
tsepezd19e9122016-11-02 15:43:18 -07004821bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004822 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4823}
thestigb1a59592016-04-14 18:29:56 -07004824
4825void CXFA_Node::OnRemoved(bool bNotify) {
4826 if (!bNotify)
4827 return;
4828
dsinclaira1b07722016-07-11 08:20:58 -07004829 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004830 if (pNotify)
4831 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004832}
thestigb1a59592016-04-14 18:29:56 -07004833
4834void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004835 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004836 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004837 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004838 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004839 }
4840 }
4841}
thestigb1a59592016-04-14 18:29:56 -07004842
Dan Sinclair1770c022016-03-14 14:14:16 -04004843void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004844 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004845 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004846 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004847 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004848 }
4849}
thestigb1a59592016-04-14 18:29:56 -07004850
Dan Sinclair1770c022016-03-14 14:14:16 -04004851int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004852 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004853 int32_t iRet = XFA_EVENTERROR_NotExist;
4854 const XFA_ExecEventParaInfo* eventParaInfo =
4855 GetEventParaInfoByName(wsEventName);
4856 if (eventParaInfo) {
4857 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004858 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004859 if (!pNotify) {
4860 return iRet;
4861 }
4862 if (validFlags == 1) {
4863 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4864 } else if (validFlags == 2) {
4865 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004866 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004867 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004868 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004869 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004870 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004871 }
4872 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004873 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004874 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004875 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004876 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004877 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004878 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004879 }
4880 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004881 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004882 }
4883 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004884 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004885 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004886 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004887 }
4888 } else if (validFlags == 6) {
4889 CXFA_WidgetData* pWidgetData = GetWidgetData();
4890 if (pWidgetData) {
4891 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004892 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004893 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004894 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004895 }
4896 }
4897 } else if (validFlags == 7) {
4898 CXFA_WidgetData* pWidgetData = GetWidgetData();
4899 if (pWidgetData) {
4900 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004901 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004902 (!pWidgetData->IsListBox())) {
4903 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004904 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004905 }
4906 }
4907 }
4908 }
4909 return iRet;
4910}
dsinclair5b36f0a2016-07-19 10:56:23 -07004911
Dan Sinclair1770c022016-03-14 14:14:16 -04004912void CXFA_Node::UpdateNameHash() {
4913 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004914 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004915 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004916 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004917 wsName = GetCData(XFA_ATTRIBUTE_Name);
4918 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004919 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004920 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004921 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004922 }
4923}
dsinclair5b36f0a2016-07-19 10:56:23 -07004924
dsinclairae95f762016-03-29 16:58:29 -07004925CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004926 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004927 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
dsinclairae95f762016-03-29 16:58:29 -07004928 m_pXMLNode = new CFDE_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004929 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004930 }
4931 return m_pXMLNode;
4932}
dsinclair5b36f0a2016-07-19 10:56:23 -07004933
tsepezd19e9122016-11-02 15:43:18 -07004934bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004935 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004936 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004937}
4938
4939XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4940 if (!m_pMapModuleData)
4941 m_pMapModuleData = new XFA_MAPMODULEDATA;
4942 return m_pMapModuleData;
4943}
4944
4945XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4946 return m_pMapModuleData;
4947}
4948
4949void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4950 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4951 pModule->m_ValueMap.SetAt(pKey, pValue);
4952}
4953
tsepezd19e9122016-11-02 15:43:18 -07004954bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004955 CXFA_Node* pNode = this;
4956 while (pNode) {
4957 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
4958 if (pModule && pModule->m_ValueMap.Lookup(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004959 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004960 }
4961 pNode = pNode->GetPacketID() != XFA_XDPPACKET_Datasets
4962 ? pNode->GetTemplateNode()
weili44f8faf2016-06-01 14:03:56 -07004963 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004964 }
tsepezd19e9122016-11-02 15:43:18 -07004965 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004966}
dsinclair5b36f0a2016-07-19 10:56:23 -07004967
Dan Sinclair1770c022016-03-14 14:14:16 -04004968void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004969 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair1770c022016-03-14 14:14:16 -04004970 wsValue.GetLength() * sizeof(FX_WCHAR));
4971}
dsinclair5b36f0a2016-07-19 10:56:23 -07004972
tsepezd19e9122016-11-02 15:43:18 -07004973bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004974 void* pValue;
4975 int32_t iBytes;
4976 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004977 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004978 }
4979 wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR));
tsepezd19e9122016-11-02 15:43:18 -07004980 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004981}
dsinclair5b36f0a2016-07-19 10:56:23 -07004982
Dan Sinclair1770c022016-03-14 14:14:16 -04004983void CXFA_Node::SetMapModuleBuffer(
4984 void* pKey,
4985 void* pValue,
4986 int32_t iBytes,
4987 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4988 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4989 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004990 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004991 pBuffer =
4992 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4993 } else if (pBuffer->iBytes != iBytes) {
4994 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4995 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4996 }
4997 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4998 sizeof(XFA_MAPDATABLOCK) + iBytes);
4999 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5000 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5001 }
weili44f8faf2016-06-01 14:03:56 -07005002 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04005003 return;
weili44f8faf2016-06-01 14:03:56 -07005004
Dan Sinclair1770c022016-03-14 14:14:16 -04005005 pBuffer->pCallbackInfo = pCallbackInfo;
5006 pBuffer->iBytes = iBytes;
5007 FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes);
5008}
dsinclair5b36f0a2016-07-19 10:56:23 -07005009
tsepezd19e9122016-11-02 15:43:18 -07005010bool CXFA_Node::GetMapModuleBuffer(void* pKey,
5011 void*& pValue,
5012 int32_t& iBytes,
5013 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07005014 XFA_MAPDATABLOCK* pBuffer = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005015 const CXFA_Node* pNode = this;
5016 while (pNode) {
5017 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
5018 if (pModule && pModule->m_BufferMap.Lookup(pKey, pBuffer)) {
5019 break;
5020 }
5021 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets)
5022 ? pNode->GetTemplateNode()
weili44f8faf2016-06-01 14:03:56 -07005023 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005024 }
weili44f8faf2016-06-01 14:03:56 -07005025 if (!pBuffer) {
tsepezd19e9122016-11-02 15:43:18 -07005026 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005027 }
5028 pValue = pBuffer->GetData();
5029 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07005030 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005031}
dsinclair5b36f0a2016-07-19 10:56:23 -07005032
tsepezd19e9122016-11-02 15:43:18 -07005033bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005034 CXFA_Node* pNode = this;
5035 while (pNode) {
5036 void* pVal;
5037 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
5038 if (pModule &&
5039 (pModule->m_ValueMap.Lookup(pKey, pVal) ||
5040 pModule->m_BufferMap.Lookup(pKey, (XFA_MAPDATABLOCK*&)pVal))) {
tsepezd19e9122016-11-02 15:43:18 -07005041 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005042 }
5043 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets)
5044 ? pNode->GetTemplateNode()
weili44f8faf2016-06-01 14:03:56 -07005045 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005046 }
tsepezd19e9122016-11-02 15:43:18 -07005047 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005048}
dsinclair5b36f0a2016-07-19 10:56:23 -07005049
Dan Sinclair1770c022016-03-14 14:14:16 -04005050void CXFA_Node::RemoveMapModuleKey(void* pKey) {
5051 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
5052 if (!pModule)
5053 return;
5054
5055 if (pKey) {
weili44f8faf2016-06-01 14:03:56 -07005056 XFA_MAPDATABLOCK* pBuffer = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005057 pModule->m_BufferMap.Lookup(pKey, pBuffer);
5058 if (pBuffer) {
5059 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5060 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5061 }
5062 FX_Free(pBuffer);
5063 }
5064 pModule->m_BufferMap.RemoveKey(pKey);
5065 pModule->m_ValueMap.RemoveKey(pKey);
5066 } else {
5067 XFA_MAPDATABLOCK* pBuffer;
5068 FX_POSITION posBuffer = pModule->m_BufferMap.GetStartPosition();
5069 while (posBuffer) {
5070 pModule->m_BufferMap.GetNextAssoc(posBuffer, pKey, pBuffer);
5071 if (pBuffer) {
5072 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5073 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5074 }
5075 FX_Free(pBuffer);
5076 }
5077 }
5078 pModule->m_BufferMap.RemoveAll();
5079 pModule->m_ValueMap.RemoveAll();
5080 delete pModule;
5081 }
5082}
dsinclair5b36f0a2016-07-19 10:56:23 -07005083
tsepezd19e9122016-11-02 15:43:18 -07005084void CXFA_Node::MergeAllData(void* pDstModule, bool bUseSrcAttr) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005085 XFA_MAPMODULEDATA* pDstModuleData =
5086 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
5087 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
5088 if (!pSrcModuleData) {
5089 return;
5090 }
5091 FX_POSITION psValue = pSrcModuleData->m_ValueMap.GetStartPosition();
5092 while (psValue) {
5093 void* pKey;
5094 void* pValue;
5095 pSrcModuleData->m_ValueMap.GetNextAssoc(psValue, pKey, pValue);
5096 if (bUseSrcAttr || !pDstModuleData->m_ValueMap.GetValueAt(pKey)) {
5097 pDstModuleData->m_ValueMap.SetAt(pKey, pValue);
5098 }
5099 }
5100 FX_POSITION psBuffer = pSrcModuleData->m_BufferMap.GetStartPosition();
5101 while (psBuffer) {
5102 void* pKey;
5103 XFA_MAPDATABLOCK* pSrcBuffer;
5104 pSrcModuleData->m_BufferMap.GetNextAssoc(psBuffer, pKey, pSrcBuffer);
5105 XFA_MAPDATABLOCK*& pBuffer = pDstModuleData->m_BufferMap[pKey];
5106 if (pBuffer && !bUseSrcAttr) {
5107 continue;
5108 }
5109 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
5110 !pSrcBuffer->pCallbackInfo->pCopy) {
5111 if (pBuffer) {
5112 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5113 pDstModuleData->m_BufferMap.RemoveKey(pKey);
5114 }
5115 continue;
5116 }
weili44f8faf2016-06-01 14:03:56 -07005117 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005118 pBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
5119 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5120 } else if (pBuffer->iBytes != pSrcBuffer->iBytes) {
5121 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5122 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5123 }
5124 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
5125 uint8_t, pBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5126 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5127 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5128 }
weili44f8faf2016-06-01 14:03:56 -07005129 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005130 continue;
5131 }
5132 pBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5133 pBuffer->iBytes = pSrcBuffer->iBytes;
5134 FXSYS_memcpy(pBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes);
5135 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pCopy) {
5136 pBuffer->pCallbackInfo->pCopy(*(void**)pBuffer->GetData());
5137 }
5138 }
5139}
dsinclair5b36f0a2016-07-19 10:56:23 -07005140
Dan Sinclair1770c022016-03-14 14:14:16 -04005141void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5142 if (!pDstModule) {
5143 return;
5144 }
tsepezd19e9122016-11-02 15:43:18 -07005145 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005146 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005147 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005148 }
dsinclair070fcdf2016-06-22 22:04:54 -07005149 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005150 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005151 }
weili44f8faf2016-06-01 14:03:56 -07005152 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5153 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005154 if (bNeedMove) {
5155 pSrcModuleData = GetMapModuleData();
5156 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005157 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005158 }
5159 pDstModuleData = pDstModule->CreateMapModuleData();
5160 }
5161 if (bNeedMove) {
5162 void* pBufferBlockData = pSrcModuleData->m_BufferMap.GetValueAt(pKey);
5163 if (pBufferBlockData) {
5164 pSrcModuleData->m_BufferMap.RemoveKey(pKey);
5165 pDstModuleData->m_BufferMap.RemoveKey(pKey);
5166 pDstModuleData->m_BufferMap.SetAt(pKey,
5167 (XFA_MAPDATABLOCK*)pBufferBlockData);
5168 }
5169 }
dsinclairc5a8f212016-06-20 11:11:12 -07005170 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005171 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005172 CFX_WideString wsFormatValue(wsValue);
5173 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5174 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005175 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005176 }
tsepezd19e9122016-11-02 15:43:18 -07005177 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005178 }
5179}
dsinclair5b36f0a2016-07-19 10:56:23 -07005180
Dan Sinclair1770c022016-03-14 14:14:16 -04005181void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5182 CXFA_Node* pDstModule,
5183 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005184 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005185 if (!pSrcModule || !pDstModule || !pKey) {
5186 return;
5187 }
5188 if (bRecursive) {
5189 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5190 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5191 for (; pSrcChild && pDstChild;
5192 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5193 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005194 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005195 }
5196 }
5197 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5198}