blob: 1e508969d1a66c0b9640c055fbad7e46b678dcf4 [file] [log] [blame]
dsinclair5b36f0a2016-07-19 10:56:23 -07001// Copyright 2016 PDFium Authors. All rights reserved.
Dan Sinclair1770c022016-03-14 14:14:16 -04002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "xfa/fxfa/parser/xfa_object.h"
8
dsinclair5b36f0a2016-07-19 10:56:23 -07009#include <map>
tsepezaadedf92016-05-12 10:08:06 -070010#include <memory>
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050011#include <utility>
tsepez51709be2016-12-08 10:55:57 -080012#include <vector>
tsepezaadedf92016-05-12 10:08:06 -070013
dsinclaira52ab742016-09-29 13:59:29 -070014#include "core/fxcrt/fx_ext.h"
dsinclair43554682016-09-29 17:29:48 -070015#include "fxjs/cfxjse_value.h"
tsepeza9caab92016-12-14 05:57:10 -080016#include "third_party/base/ptr_util.h"
tsepezaadedf92016-05-12 10:08:06 -070017#include "third_party/base/stl_util.h"
dsinclairae95f762016-03-29 16:58:29 -070018#include "xfa/fde/xml/fde_xml_imp.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040019#include "xfa/fgas/crt/fgas_codepage.h"
dsinclairdf4bc592016-03-31 20:34:43 -070020#include "xfa/fxfa/app/xfa_ffnotify.h"
dsinclair5b493092016-09-29 20:20:24 -070021#include "xfa/fxfa/cxfa_eventparam.h"
dsinclair16280242016-07-21 12:03:47 -070022#include "xfa/fxfa/parser/cxfa_document.h"
dsinclair0b851ff2016-07-21 12:03:01 -070023#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
dsinclair9eb0db12016-07-21 12:01:39 -070024#include "xfa/fxfa/parser/cxfa_measurement.h"
dsinclair44d054c2016-04-06 10:23:46 -070025#include "xfa/fxfa/parser/cxfa_occur.h"
dsinclair31f87402016-07-20 06:34:45 -070026#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
dsinclair34f86b02016-07-11 08:42:33 -070027#include "xfa/fxfa/parser/cxfa_simple_parser.h"
dsinclair5b36f0a2016-07-19 10:56:23 -070028#include "xfa/fxfa/parser/xfa_basic_data.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040029
weili44f8faf2016-06-01 14:03:56 -070030namespace {
31
32void XFA_DeleteWideString(void* pData) {
33 delete static_cast<CFX_WideString*>(pData);
34}
35
36void XFA_CopyWideString(void*& pData) {
37 if (pData) {
38 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
39 pData = pNewData;
40 }
41}
42
43XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
44 XFA_CopyWideString};
45
weili44f8faf2016-06-01 14:03:56 -070046void XFA_DataNodeDeleteBindItem(void* pData) {
47 delete static_cast<CXFA_NodeArray*>(pData);
48}
49
50XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
51 XFA_DataNodeDeleteBindItem, nullptr};
52
dsinclair5b36f0a2016-07-19 10:56:23 -070053int32_t GetCount(CXFA_Node* pInstMgrNode) {
54 ASSERT(pInstMgrNode);
55 int32_t iCount = 0;
56 uint32_t dwNameHash = 0;
57 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
58 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
59 XFA_Element eCurType = pNode->GetElementType();
60 if (eCurType == XFA_Element::InstanceManager)
61 break;
62 if ((eCurType != XFA_Element::Subform) &&
63 (eCurType != XFA_Element::SubformSet)) {
64 continue;
65 }
66 if (iCount == 0) {
67 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
68 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
69 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
70 wsInstName.Mid(1) != wsName) {
71 return iCount;
72 }
73 dwNameHash = pNode->GetNameHash();
74 }
75 if (dwNameHash != pNode->GetNameHash())
76 break;
weili44f8faf2016-06-01 14:03:56 -070077
dsinclair5b36f0a2016-07-19 10:56:23 -070078 iCount++;
79 }
80 return iCount;
Dan Sinclair1770c022016-03-14 14:14:16 -040081}
weili44f8faf2016-06-01 14:03:56 -070082
dsinclair5b36f0a2016-07-19 10:56:23 -070083void SortNodeArrayByDocumentIdx(const CXFA_NodeSet& rgNodeSet,
84 CXFA_NodeArray& rgNodeArray,
85 CFX_ArrayTemplate<int32_t>& rgIdxArray) {
86 int32_t iCount = pdfium::CollectionSize<int32_t>(rgNodeSet);
87 rgNodeArray.SetSize(iCount);
88 rgIdxArray.SetSize(iCount);
89 if (iCount == 0)
90 return;
weili44f8faf2016-06-01 14:03:56 -070091
dsinclair5b36f0a2016-07-19 10:56:23 -070092 int32_t iIndex = -1;
93 int32_t iTotalIndex = -1;
94 CXFA_Node* pCommonParent =
95 (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent);
96 for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild);
97 pNode && iIndex < iCount;
98 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
99 iTotalIndex++;
100 if (pdfium::ContainsValue(rgNodeSet, pNode)) {
101 iIndex++;
102 rgNodeArray[iIndex] = pNode;
103 rgIdxArray[iIndex] = iTotalIndex;
104 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400105 }
106}
weili44f8faf2016-06-01 14:03:56 -0700107
dsinclair5b36f0a2016-07-19 10:56:23 -0700108using CXFA_NodeSetPair = std::pair<CXFA_NodeSet, CXFA_NodeSet>;
109using CXFA_NodeSetPairMap =
110 std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>;
111using CXFA_NodeSetPairMapMap =
112 std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>;
113
114CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode,
115 CXFA_NodeSetPairMapMap* pMap) {
116 CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
117 uint32_t dwNameHash = pNode->GetNameHash();
118 if (!pParentNode || !dwNameHash)
119 return nullptr;
120
121 if (!(*pMap)[pParentNode])
tsepeza9caab92016-12-14 05:57:10 -0800122 (*pMap)[pParentNode] = pdfium::MakeUnique<CXFA_NodeSetPairMap>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700123
124 CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get();
125 if (!(*pNodeSetPairMap)[dwNameHash])
tsepeza9caab92016-12-14 05:57:10 -0800126 (*pNodeSetPairMap)[dwNameHash] = pdfium::MakeUnique<CXFA_NodeSetPair>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700127
128 return (*pNodeSetPairMap)[dwNameHash].get();
Dan Sinclair1770c022016-03-14 14:14:16 -0400129}
130
dsinclair5b36f0a2016-07-19 10:56:23 -0700131void ReorderDataNodes(const CXFA_NodeSet& sSet1,
132 const CXFA_NodeSet& sSet2,
tsepezd19e9122016-11-02 15:43:18 -0700133 bool bInsertBefore) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700134 CXFA_NodeSetPairMapMap rgMap;
135 for (CXFA_Node* pNode : sSet1) {
136 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
137 if (pNodeSetPair)
138 pNodeSetPair->first.insert(pNode);
139 }
140 for (CXFA_Node* pNode : sSet2) {
141 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
142 if (pNodeSetPair) {
143 if (pdfium::ContainsValue(pNodeSetPair->first, pNode))
144 pNodeSetPair->first.erase(pNode);
145 else
146 pNodeSetPair->second.insert(pNode);
147 }
148 }
149 for (const auto& iter1 : rgMap) {
150 CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get();
151 if (!pNodeSetPairMap)
152 continue;
153
154 for (const auto& iter2 : *pNodeSetPairMap) {
155 CXFA_NodeSetPair* pNodeSetPair = iter2.second.get();
156 if (!pNodeSetPair)
157 continue;
158 if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) {
159 CXFA_NodeArray rgNodeArray1;
160 CXFA_NodeArray rgNodeArray2;
161 CFX_ArrayTemplate<int32_t> rgIdxArray1;
162 CFX_ArrayTemplate<int32_t> rgIdxArray2;
163 SortNodeArrayByDocumentIdx(pNodeSetPair->first, rgNodeArray1,
164 rgIdxArray1);
165 SortNodeArrayByDocumentIdx(pNodeSetPair->second, rgNodeArray2,
166 rgIdxArray2);
167 CXFA_Node* pParentNode = nullptr;
168 CXFA_Node* pBeforeNode = nullptr;
169 if (bInsertBefore) {
170 pBeforeNode = rgNodeArray2[0];
171 pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent);
172 } else {
173 CXFA_Node* pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1];
174 pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent);
175 pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling);
176 }
177 for (int32_t iIdx = 0; iIdx < rgIdxArray1.GetSize(); iIdx++) {
178 CXFA_Node* pCurNode = rgNodeArray1[iIdx];
179 pParentNode->RemoveChild(pCurNode);
180 pParentNode->InsertChild(pCurNode, pBeforeNode);
181 }
182 }
183 }
184 pNodeSetPairMap->clear();
185 }
186}
187
188CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
189 ASSERT(pInstMgrNode);
190 int32_t iCount = 0;
191 uint32_t dwNameHash = 0;
192 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
193 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
194 XFA_Element eCurType = pNode->GetElementType();
195 if (eCurType == XFA_Element::InstanceManager)
196 break;
197 if ((eCurType != XFA_Element::Subform) &&
198 (eCurType != XFA_Element::SubformSet)) {
199 continue;
200 }
201 if (iCount == 0) {
202 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
203 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
204 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
205 wsInstName.Mid(1) != wsName) {
206 return nullptr;
207 }
208 dwNameHash = pNode->GetNameHash();
209 }
210 if (dwNameHash != pNode->GetNameHash())
211 break;
212
213 iCount++;
214 if (iCount > iIndex)
215 return pNode;
216 }
217 return nullptr;
218}
219
220void InsertItem(CXFA_Node* pInstMgrNode,
221 CXFA_Node* pNewInstance,
222 int32_t iPos,
223 int32_t iCount = -1,
tsepezd19e9122016-11-02 15:43:18 -0700224 bool bMoveDataBindingNodes = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700225 if (iCount < 0)
226 iCount = GetCount(pInstMgrNode);
227 if (iPos < 0)
228 iPos = iCount;
229 if (iPos == iCount) {
230 CXFA_Node* pNextSibling =
231 iCount > 0
232 ? GetItem(pInstMgrNode, iCount - 1)
233 ->GetNodeItem(XFA_NODEITEM_NextSibling)
234 : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
235 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
236 ->InsertChild(pNewInstance, pNextSibling);
237 if (bMoveDataBindingNodes) {
238 CXFA_NodeSet sNew;
239 CXFA_NodeSet sAfter;
240 CXFA_NodeIteratorTemplate<CXFA_Node,
241 CXFA_TraverseStrategy_XFAContainerNode>
242 sIteratorNew(pNewInstance);
243 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
244 pNode = sIteratorNew.MoveToNext()) {
245 CXFA_Node* pDataNode = pNode->GetBindData();
246 if (!pDataNode)
247 continue;
248
249 sNew.insert(pDataNode);
250 }
251 CXFA_NodeIteratorTemplate<CXFA_Node,
252 CXFA_TraverseStrategy_XFAContainerNode>
253 sIteratorAfter(pNextSibling);
254 for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode;
255 pNode = sIteratorAfter.MoveToNext()) {
256 CXFA_Node* pDataNode = pNode->GetBindData();
257 if (!pDataNode)
258 continue;
259
260 sAfter.insert(pDataNode);
261 }
tsepezd19e9122016-11-02 15:43:18 -0700262 ReorderDataNodes(sNew, sAfter, false);
dsinclair5b36f0a2016-07-19 10:56:23 -0700263 }
264 } else {
265 CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos);
266 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
267 ->InsertChild(pNewInstance, pBeforeInstance);
268 if (bMoveDataBindingNodes) {
269 CXFA_NodeSet sNew;
270 CXFA_NodeSet sBefore;
271 CXFA_NodeIteratorTemplate<CXFA_Node,
272 CXFA_TraverseStrategy_XFAContainerNode>
273 sIteratorNew(pNewInstance);
274 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
275 pNode = sIteratorNew.MoveToNext()) {
276 CXFA_Node* pDataNode = pNode->GetBindData();
277 if (!pDataNode)
278 continue;
279
280 sNew.insert(pDataNode);
281 }
282 CXFA_NodeIteratorTemplate<CXFA_Node,
283 CXFA_TraverseStrategy_XFAContainerNode>
284 sIteratorBefore(pBeforeInstance);
285 for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode;
286 pNode = sIteratorBefore.MoveToNext()) {
287 CXFA_Node* pDataNode = pNode->GetBindData();
288 if (!pDataNode)
289 continue;
290
291 sBefore.insert(pDataNode);
292 }
tsepezd19e9122016-11-02 15:43:18 -0700293 ReorderDataNodes(sNew, sBefore, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700294 }
295 }
296}
297
298void RemoveItem(CXFA_Node* pInstMgrNode,
299 CXFA_Node* pRemoveInstance,
tsepezd19e9122016-11-02 15:43:18 -0700300 bool bRemoveDataBinding = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700301 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);
302 if (!bRemoveDataBinding)
303 return;
304
305 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode>
306 sIterator(pRemoveInstance);
307 for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode;
308 pFormNode = sIterator.MoveToNext()) {
309 CXFA_Node* pDataNode = pFormNode->GetBindData();
310 if (!pDataNode)
311 continue;
312
313 if (pDataNode->RemoveBindItem(pFormNode) == 0) {
314 if (CXFA_Node* pDataParent =
315 pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) {
316 pDataParent->RemoveChild(pDataNode);
317 }
318 }
319 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
320 }
321}
322
tsepezd19e9122016-11-02 15:43:18 -0700323CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700324 CXFA_Document* pDocument = pInstMgrNode->GetDocument();
325 CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();
326 CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);
327 CXFA_Node* pDataScope = nullptr;
328 for (CXFA_Node* pRootBoundNode = pFormParent;
329 pRootBoundNode && pRootBoundNode->IsContainerNode();
330 pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) {
331 pDataScope = pRootBoundNode->GetBindData();
332 if (pDataScope)
333 break;
334 }
335 if (!pDataScope) {
336 pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record));
337 ASSERT(pDataScope);
338 }
339 CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer(
tsepezd19e9122016-11-02 15:43:18 -0700340 pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700341 if (pInstance) {
342 pDocument->DataMerge_UpdateBindingRelations(pInstance);
343 pFormParent->RemoveChild(pInstance);
344 }
345 return pInstance;
346}
347
348struct XFA_ExecEventParaInfo {
349 public:
350 uint32_t m_uHash;
351 const FX_WCHAR* m_lpcEventName;
352 XFA_EVENTTYPE m_eventType;
353 uint32_t m_validFlags;
354};
355static const XFA_ExecEventParaInfo gs_eventParaInfos[] = {
356 {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0},
357 {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0},
358 {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5},
359 {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0},
360 {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7},
361 {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1},
362 {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5},
363 {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0},
364 {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0},
365 {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6},
366 {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2},
367 {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0},
368 {0x7233018a, L"validate", XFA_EVENT_Validate, 1},
369 {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3},
370 {0x891f4606, L"change", XFA_EVENT_Change, 4},
371 {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0},
372 {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5},
373 {0xcdce56b3, L"full", XFA_EVENT_Full, 4},
374 {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5},
375 {0xd95657a6, L"click", XFA_EVENT_Click, 4},
376 {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1},
377 {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7},
378 {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2},
379 {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0},
380 {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6},
381};
382
383const XFA_ExecEventParaInfo* GetEventParaInfoByName(
384 const CFX_WideStringC& wsEventName) {
385 uint32_t uHash = FX_HashCode_GetW(wsEventName, false);
386 int32_t iStart = 0;
387 int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
388 do {
389 int32_t iMid = (iStart + iEnd) / 2;
390 const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid];
391 if (uHash == eventParaInfo->m_uHash)
392 return eventParaInfo;
393 if (uHash < eventParaInfo->m_uHash)
394 iEnd = iMid - 1;
395 else
396 iStart = iMid + 1;
397 } while (iStart <= iEnd);
398 return nullptr;
399}
400
401void StrToRGB(const CFX_WideString& strRGB,
402 int32_t& r,
403 int32_t& g,
404 int32_t& b) {
405 r = 0;
406 g = 0;
407 b = 0;
408
409 FX_WCHAR zero = '0';
410 int32_t iIndex = 0;
411 int32_t iLen = strRGB.GetLength();
412 for (int32_t i = 0; i < iLen; ++i) {
413 FX_WCHAR ch = strRGB.GetAt(i);
414 if (ch == L',')
415 ++iIndex;
416 if (iIndex > 2)
417 break;
418
419 int32_t iValue = ch - zero;
420 if (iValue >= 0 && iValue <= 9) {
421 switch (iIndex) {
422 case 0:
423 r = r * 10 + iValue;
424 break;
425 case 1:
426 g = g * 10 + iValue;
427 break;
428 default:
429 b = b * 10 + iValue;
430 break;
431 }
432 }
433 }
434}
435
436enum XFA_KEYTYPE {
437 XFA_KEYTYPE_Custom,
438 XFA_KEYTYPE_Element,
439};
440
441void* GetMapKey_Custom(const CFX_WideStringC& wsKey) {
442 uint32_t dwKey = FX_HashCode_GetW(wsKey, false);
443 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom);
444}
445
446void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) {
447 return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) |
448 (eAttribute << 8) | XFA_KEYTYPE_Element);
449}
450
dsinclair9eb0db12016-07-21 12:01:39 -0700451const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement,
452 XFA_ATTRIBUTE eAttribute,
453 uint32_t dwPacket) {
454 int32_t iCount = 0;
455 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount);
456 if (!pAttr || iCount < 1)
457 return nullptr;
458
459 if (!std::binary_search(pAttr, pAttr + iCount, eAttribute))
460 return nullptr;
461
462 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute);
463 ASSERT(pInfo);
464 if (dwPacket == XFA_XDPPACKET_UNKNOWN)
465 return pInfo;
466 return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr;
467}
468
469const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) {
470 return g_XFAEnumData + eName;
471}
472
dsinclair5b36f0a2016-07-19 10:56:23 -0700473} // namespace
474
475static void XFA_DefaultFreeData(void* pData) {}
476
477static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {
478 XFA_DefaultFreeData, nullptr};
479
weili47bcd4c2016-06-16 08:00:06 -0700480XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {}
481
482XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {}
483
dsinclairb9778472016-06-23 13:34:10 -0700484CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
485 uint16_t ePacket,
486 XFA_ObjectType oType,
dsinclairc1df5d42016-07-18 06:36:51 -0700487 XFA_Element eType,
488 const CFX_WideStringC& elementName)
489 : CXFA_Object(pDoc, oType, eType, elementName),
Dan Sinclair1770c022016-03-14 14:14:16 -0400490 m_pNext(nullptr),
491 m_pChild(nullptr),
492 m_pLastChild(nullptr),
493 m_pParent(nullptr),
494 m_pXMLNode(nullptr),
Dan Sinclair1770c022016-03-14 14:14:16 -0400495 m_ePacket(ePacket),
dsinclairc5a8f212016-06-20 11:11:12 -0700496 m_uNodeFlags(XFA_NodeFlag_None),
Dan Sinclair1770c022016-03-14 14:14:16 -0400497 m_dwNameHash(0),
498 m_pAuxNode(nullptr),
499 m_pMapModuleData(nullptr) {
500 ASSERT(m_pDocument);
501}
weili44f8faf2016-06-01 14:03:56 -0700502
Dan Sinclair1770c022016-03-14 14:14:16 -0400503CXFA_Node::~CXFA_Node() {
weili44f8faf2016-06-01 14:03:56 -0700504 ASSERT(!m_pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400505 RemoveMapModuleKey();
weili44f8faf2016-06-01 14:03:56 -0700506 CXFA_Node* pNode = m_pChild;
Dan Sinclair1770c022016-03-14 14:14:16 -0400507 while (pNode) {
weili44f8faf2016-06-01 14:03:56 -0700508 CXFA_Node* pNext = pNode->m_pNext;
509 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400510 delete pNode;
511 pNode = pNext;
512 }
dsinclairc5a8f212016-06-20 11:11:12 -0700513 if (m_pXMLNode && IsOwnXMLNode())
tsepezc757d9a2017-01-23 11:01:42 -0800514 delete m_pXMLNode;
Dan Sinclair1770c022016-03-14 14:14:16 -0400515}
weili44f8faf2016-06-01 14:03:56 -0700516
tsepezd19e9122016-11-02 15:43:18 -0700517CXFA_Node* CXFA_Node::Clone(bool bRecursive) {
dsinclaira1b07722016-07-11 08:20:58 -0700518 CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700519 if (!pClone)
520 return nullptr;
521
Dan Sinclair1770c022016-03-14 14:14:16 -0400522 MergeAllData(pClone);
523 pClone->UpdateNameHash();
524 if (IsNeedSavingXMLNode()) {
weili44f8faf2016-06-01 14:03:56 -0700525 CFDE_XMLNode* pCloneXML = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400526 if (IsAttributeInXML()) {
527 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -0700528 GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -0700529 CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -0400530 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
531 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -0700532 pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -0400533 }
534 pCloneXML = pCloneXMLElement;
weili44f8faf2016-06-01 14:03:56 -0700535 pCloneXMLElement = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400536 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
537 } else {
tsepezd19e9122016-11-02 15:43:18 -0700538 pCloneXML = m_pXMLNode->Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400539 }
540 pClone->SetXMLMappingNode(pCloneXML);
dsinclairc5a8f212016-06-20 11:11:12 -0700541 pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400542 }
543 if (bRecursive) {
544 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
545 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
546 pClone->InsertChild(pChild->Clone(bRecursive));
547 }
548 }
dsinclairc5a8f212016-06-20 11:11:12 -0700549 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
weili44f8faf2016-06-01 14:03:56 -0700550 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400551 return pClone;
552}
weili44f8faf2016-06-01 14:03:56 -0700553
Dan Sinclair1770c022016-03-14 14:14:16 -0400554CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
555 switch (eItem) {
556 case XFA_NODEITEM_NextSibling:
557 return m_pNext;
558 case XFA_NODEITEM_FirstChild:
559 return m_pChild;
560 case XFA_NODEITEM_Parent:
561 return m_pParent;
562 case XFA_NODEITEM_PrevSibling:
563 if (m_pParent) {
564 CXFA_Node* pSibling = m_pParent->m_pChild;
weili44f8faf2016-06-01 14:03:56 -0700565 CXFA_Node* pPrev = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400566 while (pSibling && pSibling != this) {
567 pPrev = pSibling;
568 pSibling = pSibling->m_pNext;
569 }
570 return pPrev;
571 }
weili44f8faf2016-06-01 14:03:56 -0700572 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400573 default:
574 break;
575 }
weili44f8faf2016-06-01 14:03:56 -0700576 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400577}
weili44f8faf2016-06-01 14:03:56 -0700578
Dan Sinclair1770c022016-03-14 14:14:16 -0400579CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
dsinclairc5a8f212016-06-20 11:11:12 -0700580 XFA_ObjectType eType) const {
weili44f8faf2016-06-01 14:03:56 -0700581 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400582 switch (eItem) {
583 case XFA_NODEITEM_NextSibling:
584 pNode = m_pNext;
dsinclairc5a8f212016-06-20 11:11:12 -0700585 while (pNode && pNode->GetObjectType() != eType)
586 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400587 break;
588 case XFA_NODEITEM_FirstChild:
589 pNode = m_pChild;
dsinclairc5a8f212016-06-20 11:11:12 -0700590 while (pNode && pNode->GetObjectType() != eType)
591 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400592 break;
593 case XFA_NODEITEM_Parent:
594 pNode = m_pParent;
dsinclairc5a8f212016-06-20 11:11:12 -0700595 while (pNode && pNode->GetObjectType() != eType)
596 pNode = pNode->m_pParent;
Dan Sinclair1770c022016-03-14 14:14:16 -0400597 break;
598 case XFA_NODEITEM_PrevSibling:
599 if (m_pParent) {
600 CXFA_Node* pSibling = m_pParent->m_pChild;
601 while (pSibling && pSibling != this) {
dsinclairc5a8f212016-06-20 11:11:12 -0700602 if (eType == pSibling->GetObjectType())
Dan Sinclair1770c022016-03-14 14:14:16 -0400603 pNode = pSibling;
dsinclairc5a8f212016-06-20 11:11:12 -0700604
Dan Sinclair1770c022016-03-14 14:14:16 -0400605 pSibling = pSibling->m_pNext;
606 }
607 }
608 break;
609 default:
610 break;
611 }
612 return pNode;
613}
weili44f8faf2016-06-01 14:03:56 -0700614
Dan Sinclair1770c022016-03-14 14:14:16 -0400615int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes,
tsepez736f28a2016-03-25 14:19:51 -0700616 uint32_t dwTypeFilter,
dsinclair41cb62e2016-06-23 09:20:32 -0700617 XFA_Element eTypeFilter,
Dan Sinclair1770c022016-03-14 14:14:16 -0400618 int32_t iLevel) {
619 if (--iLevel < 0) {
620 return nodes.GetSize();
621 }
dsinclair41cb62e2016-06-23 09:20:32 -0700622 if (eTypeFilter != XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400623 CXFA_Node* pChild = m_pChild;
624 while (pChild) {
dsinclair41cb62e2016-06-23 09:20:32 -0700625 if (pChild->GetElementType() == eTypeFilter) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400626 nodes.Add(pChild);
627 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700628 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400629 }
630 }
631 pChild = pChild->m_pNext;
632 }
633 } else if (dwTypeFilter ==
634 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
635 CXFA_Node* pChild = m_pChild;
636 while (pChild) {
637 nodes.Add(pChild);
638 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700639 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400640 }
641 pChild = pChild->m_pNext;
642 }
643 } else if (dwTypeFilter != 0) {
weili44f8faf2016-06-01 14:03:56 -0700644 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
645 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
646 bool bFilterOneOfProperties =
647 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
Dan Sinclair1770c022016-03-14 14:14:16 -0400648 CXFA_Node* pChild = m_pChild;
649 while (pChild) {
650 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -0700651 GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -0400652 if (pProperty) {
653 if (bFilterProperties) {
654 nodes.Add(pChild);
655 } else if (bFilterOneOfProperties &&
656 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
657 nodes.Add(pChild);
658 } else if (bFilterChildren &&
dsinclair070fcdf2016-06-22 22:04:54 -0700659 (pChild->GetElementType() == XFA_Element::Variables ||
660 pChild->GetElementType() == XFA_Element::PageSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400661 nodes.Add(pChild);
662 }
weili44f8faf2016-06-01 14:03:56 -0700663 } else if (bFilterChildren) {
664 nodes.Add(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400665 }
666 pChild = pChild->m_pNext;
667 }
668 if (bFilterOneOfProperties && nodes.GetSize() < 1) {
669 int32_t iProperties = 0;
670 const XFA_PROPERTY* pProperty =
dsinclair070fcdf2016-06-22 22:04:54 -0700671 XFA_GetElementProperties(GetElementType(), iProperties);
weili44f8faf2016-06-01 14:03:56 -0700672 if (!pProperty || iProperties < 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400673 return 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400674 for (int32_t i = 0; i < iProperties; i++) {
675 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400676 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
677 CXFA_Node* pNewNode =
dsinclaira1b07722016-07-11 08:20:58 -0700678 m_pDocument->CreateNode(pPacket, pProperty[i].eName);
weili44f8faf2016-06-01 14:03:56 -0700679 if (!pNewNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400680 break;
weili44f8faf2016-06-01 14:03:56 -0700681 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -0700682 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400683 nodes.Add(pNewNode);
684 break;
685 }
686 }
687 }
688 }
689 return nodes.GetSize();
690}
weili44f8faf2016-06-01 14:03:56 -0700691
dsinclair41cb62e2016-06-23 09:20:32 -0700692CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
tsepez736f28a2016-03-25 14:19:51 -0700693 uint32_t dwFlags) {
dsinclaira1b07722016-07-11 08:20:58 -0700694 CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
thestigb1a59592016-04-14 18:29:56 -0700695 pNode->SetFlag(dwFlags, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400696 return pNode;
697}
weili44f8faf2016-06-01 14:03:56 -0700698
tsepezd19e9122016-11-02 15:43:18 -0700699CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) {
dsinclair43854a52016-04-27 12:26:00 -0700700 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
dsinclaira1b07722016-07-11 08:20:58 -0700701 CXFA_Node* pClone =
702 m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700703 if (!pClone)
704 return nullptr;
705
Dan Sinclair1770c022016-03-14 14:14:16 -0400706 pClone->SetTemplateNode(this);
707 pClone->UpdateNameHash();
708 pClone->SetXMLMappingNode(GetXMLMappingNode());
709 if (bRecursive) {
710 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
711 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
712 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
713 }
714 }
dsinclairc5a8f212016-06-20 11:11:12 -0700715 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400716 return pClone;
717}
718
719CXFA_Node* CXFA_Node::GetTemplateNode() const {
720 return m_pAuxNode;
721}
722
723void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
724 m_pAuxNode = pTemplateNode;
725}
weili44f8faf2016-06-01 14:03:56 -0700726
Dan Sinclair1770c022016-03-14 14:14:16 -0400727CXFA_Node* CXFA_Node::GetBindData() {
728 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
729 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
730}
weili44f8faf2016-06-01 14:03:56 -0700731
Dan Sinclair1770c022016-03-14 14:14:16 -0400732int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) {
dsinclairc5a8f212016-06-20 11:11:12 -0700733 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700734 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400735 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
736 formItems.Copy(*pItems);
737 return formItems.GetSize();
738 }
739 CXFA_Node* pFormNode =
740 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
weili44f8faf2016-06-01 14:03:56 -0700741 if (pFormNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400742 formItems.Add(pFormNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400743 return formItems.GetSize();
744}
745
Dan Sinclair1770c022016-03-14 14:14:16 -0400746int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
747 ASSERT(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700748 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700749 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400750 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
751 ASSERT(pItems);
752 if (pItems->Find(pFormNode) < 0) {
753 pItems->Add(pFormNode);
754 }
755 return pItems->GetSize();
756 }
757 CXFA_Node* pOldFormItem =
758 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
759 if (!pOldFormItem) {
760 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
761 return 1;
762 } else if (pOldFormItem == pFormNode) {
763 return 1;
764 }
765 CXFA_NodeArray* pItems = new CXFA_NodeArray;
766 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
767 pItems->Add(pOldFormItem);
768 pItems->Add(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700769 m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400770 return 2;
771}
weili44f8faf2016-06-01 14:03:56 -0700772
Dan Sinclair1770c022016-03-14 14:14:16 -0400773int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
dsinclairc5a8f212016-06-20 11:11:12 -0700774 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700775 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400776 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
777 ASSERT(pItems);
778 int32_t iIndex = pItems->Find(pFormNode);
779 int32_t iCount = pItems->GetSize();
780 if (iIndex >= 0) {
weili44f8faf2016-06-01 14:03:56 -0700781 if (iIndex != iCount - 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400782 pItems->SetAt(iIndex, pItems->GetAt(iCount - 1));
Dan Sinclair1770c022016-03-14 14:14:16 -0400783 pItems->RemoveAt(iCount - 1);
784 if (iCount == 2) {
785 CXFA_Node* pLastFormNode = pItems->GetAt(0);
786 SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700787 m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400788 }
789 iCount--;
790 }
791 return iCount;
792 }
793 CXFA_Node* pOldFormItem =
794 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
795 if (pOldFormItem == pFormNode) {
weili44f8faf2016-06-01 14:03:56 -0700796 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
797 pOldFormItem = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400798 }
weili44f8faf2016-06-01 14:03:56 -0700799 return pOldFormItem ? 1 : 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400800}
weili44f8faf2016-06-01 14:03:56 -0700801
tsepezd19e9122016-11-02 15:43:18 -0700802bool CXFA_Node::HasBindItem() {
weili44f8faf2016-06-01 14:03:56 -0700803 return GetPacketID() == XFA_XDPPACKET_Datasets &&
804 GetObject(XFA_ATTRIBUTE_BindingNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400805}
weili44f8faf2016-06-01 14:03:56 -0700806
Dan Sinclair1770c022016-03-14 14:14:16 -0400807CXFA_WidgetData* CXFA_Node::GetWidgetData() {
808 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
809}
weili44f8faf2016-06-01 14:03:56 -0700810
Dan Sinclair1770c022016-03-14 14:14:16 -0400811CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
weili44f8faf2016-06-01 14:03:56 -0700812 if (GetPacketID() != XFA_XDPPACKET_Form)
813 return nullptr;
dsinclair41cb62e2016-06-23 09:20:32 -0700814 XFA_Element eType = GetElementType();
815 if (eType == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700816 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400817 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700818 if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700819 return nullptr;
820
dsinclair41cb62e2016-06-23 09:20:32 -0700821 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400822 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
823 if (pFieldWidgetData &&
824 pFieldWidgetData->GetChoiceListOpen() ==
825 XFA_ATTRIBUTEENUM_MultiSelect) {
weili44f8faf2016-06-01 14:03:56 -0700826 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400827 } else {
828 CFX_WideString wsPicture;
829 if (pFieldWidgetData) {
830 pFieldWidgetData->GetPictureContent(wsPicture,
831 XFA_VALUEPICTURE_DataBind);
832 }
weili44f8faf2016-06-01 14:03:56 -0700833 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400834 return pFieldWidgetData;
Dan Sinclair1770c022016-03-14 14:14:16 -0400835 CXFA_Node* pDataNode = GetBindData();
weili44f8faf2016-06-01 14:03:56 -0700836 if (!pDataNode)
837 return nullptr;
838 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400839 CXFA_NodeArray formNodes;
840 pDataNode->GetBindItems(formNodes);
841 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
842 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -0700843 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -0400844 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400845 pFieldWidgetData = pFormNode->GetWidgetData();
846 if (pFieldWidgetData) {
847 pFieldWidgetData->GetPictureContent(wsPicture,
848 XFA_VALUEPICTURE_DataBind);
849 }
weili44f8faf2016-06-01 14:03:56 -0700850 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400851 break;
weili44f8faf2016-06-01 14:03:56 -0700852 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400853 }
854 return pFieldWidgetData;
855 }
856 }
857 CXFA_Node* pGrandNode =
weili44f8faf2016-06-01 14:03:56 -0700858 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400859 CXFA_Node* pValueNode =
dsinclair070fcdf2016-06-22 22:04:54 -0700860 (pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
Dan Sinclair1770c022016-03-14 14:14:16 -0400861 ? pParentNode
weili44f8faf2016-06-01 14:03:56 -0700862 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400863 if (!pValueNode) {
dsinclair070fcdf2016-06-22 22:04:54 -0700864 pValueNode =
865 (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
866 ? pGrandNode
867 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400868 }
869 CXFA_Node* pParentOfValueNode =
weili44f8faf2016-06-01 14:03:56 -0700870 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400871 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
weili44f8faf2016-06-01 14:03:56 -0700872 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400873}
weili44f8faf2016-06-01 14:03:56 -0700874
tsepezd19e9122016-11-02 15:43:18 -0700875bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400876 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
dsinclair56a8b192016-06-21 14:15:25 -0700877 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
dsinclair43854a52016-04-27 12:26:00 -0700878 ASSERT(pTopSubform);
Dan Sinclair1770c022016-03-14 14:14:16 -0400879 CXFA_Node* pLocaleNode = this;
tsepezd19e9122016-11-02 15:43:18 -0700880 bool bLocale = false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400881 do {
tsepezd19e9122016-11-02 15:43:18 -0700882 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400883 if (!bLocale) {
884 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
885 }
886 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
weili44f8faf2016-06-01 14:03:56 -0700887 if (bLocale)
tsepezd19e9122016-11-02 15:43:18 -0700888 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400889 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
890 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
weili44f8faf2016-06-01 14:03:56 -0700891 if (!wsLocaleName.IsEmpty())
tsepezd19e9122016-11-02 15:43:18 -0700892 return true;
weili44f8faf2016-06-01 14:03:56 -0700893 if (pTopSubform &&
tsepezd19e9122016-11-02 15:43:18 -0700894 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) {
895 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400896 }
897 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
898 if (pLocale) {
899 wsLocaleName = pLocale->GetName();
tsepezd19e9122016-11-02 15:43:18 -0700900 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400901 }
tsepezd19e9122016-11-02 15:43:18 -0700902 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400903}
weili44f8faf2016-06-01 14:03:56 -0700904
Dan Sinclair1770c022016-03-14 14:14:16 -0400905XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
dsinclair56a8b192016-06-21 14:15:25 -0700906 CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
Dan Sinclair1770c022016-03-14 14:14:16 -0400907 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
908 if (pKeep) {
909 XFA_ATTRIBUTEENUM eIntact;
tsepezd19e9122016-11-02 15:43:18 -0700910 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400911 if (eIntact == XFA_ATTRIBUTEENUM_None &&
912 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
913 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
dsinclairc5a8f212016-06-20 11:11:12 -0700914 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
915 XFA_ObjectType::ContainerNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400916 if (pPreviewRow &&
917 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
918 XFA_ATTRIBUTEENUM_Row) {
919 XFA_ATTRIBUTEENUM eValue;
tsepezd19e9122016-11-02 15:43:18 -0700920 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700921 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
922 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
923 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400924 }
weili44f8faf2016-06-01 14:03:56 -0700925 CXFA_Node* pNode =
dsinclair56a8b192016-06-21 14:15:25 -0700926 pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
tsepezd19e9122016-11-02 15:43:18 -0700927 if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700928 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
929 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
930 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400931 }
932 }
933 }
934 return eIntact;
935 }
936 }
dsinclair41cb62e2016-06-23 09:20:32 -0700937 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700938 case XFA_Element::Subform:
Dan Sinclair1770c022016-03-14 14:14:16 -0400939 switch (eLayoutType) {
940 case XFA_ATTRIBUTEENUM_Position:
941 case XFA_ATTRIBUTEENUM_Row:
942 return XFA_ATTRIBUTEENUM_ContentArea;
943 case XFA_ATTRIBUTEENUM_Tb:
944 case XFA_ATTRIBUTEENUM_Table:
945 case XFA_ATTRIBUTEENUM_Lr_tb:
946 case XFA_ATTRIBUTEENUM_Rl_tb:
947 return XFA_ATTRIBUTEENUM_None;
948 default:
949 break;
950 }
951 break;
dsinclair56a8b192016-06-21 14:15:25 -0700952 case XFA_Element::Field: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400953 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700954 if (!pParentNode ||
955 pParentNode->GetElementType() == XFA_Element::PageArea)
Dan Sinclair1770c022016-03-14 14:14:16 -0400956 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400957 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
958 XFA_ATTRIBUTEENUM eParLayout =
959 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
960 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
961 eParLayout == XFA_ATTRIBUTEENUM_Row ||
962 eParLayout == XFA_ATTRIBUTEENUM_Table) {
963 return XFA_ATTRIBUTEENUM_None;
964 }
965 XFA_VERSION version = m_pDocument->GetCurVersionMode();
966 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
967 CXFA_Measurement measureH;
tsepezd19e9122016-11-02 15:43:18 -0700968 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false))
Dan Sinclair1770c022016-03-14 14:14:16 -0400969 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400970 }
971 return XFA_ATTRIBUTEENUM_None;
972 }
973 return XFA_ATTRIBUTEENUM_ContentArea;
974 }
dsinclair56a8b192016-06-21 14:15:25 -0700975 case XFA_Element::Draw:
Dan Sinclair1770c022016-03-14 14:14:16 -0400976 return XFA_ATTRIBUTEENUM_ContentArea;
977 default:
978 break;
979 }
980 return XFA_ATTRIBUTEENUM_None;
981}
weili44f8faf2016-06-01 14:03:56 -0700982
Dan Sinclair1770c022016-03-14 14:14:16 -0400983CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
weili44f8faf2016-06-01 14:03:56 -0700984 if (m_ePacket == XFA_XDPPACKET_Datasets)
Dan Sinclair1770c022016-03-14 14:14:16 -0400985 return m_pAuxNode;
weili44f8faf2016-06-01 14:03:56 -0700986 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400987}
weili44f8faf2016-06-01 14:03:56 -0700988
Dan Sinclair1770c022016-03-14 14:14:16 -0400989void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
dsinclair43854a52016-04-27 12:26:00 -0700990 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
Dan Sinclair1770c022016-03-14 14:14:16 -0400991 m_pAuxNode = pDataDescriptionNode;
992}
weili44f8faf2016-06-01 14:03:56 -0700993
Dan Sinclair1770c022016-03-14 14:14:16 -0400994void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
995 int32_t iLength = pArguments->GetLength();
996 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -0500997 ThrowParamCountMismatchException(L"resolveNode");
Dan Sinclair1770c022016-03-14 14:14:16 -0400998 return;
999 }
tsepez6fe7d212016-04-06 10:51:14 -07001000 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001001 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclairdf4bc592016-03-31 20:34:43 -07001002 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001003 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001004 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001005 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001006 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001007 refNode = ToNode(pScriptContext->GetThisObject());
tsepez736f28a2016-03-25 14:19:51 -07001008 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001009 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1010 XFA_RESOLVENODE_Siblings;
1011 XFA_RESOLVENODE_RS resoveNodeRS;
tsepezfc58ad12016-04-05 12:22:15 -07001012 int32_t iRet = pScriptContext->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001013 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
dsinclairf27aeec2016-06-07 19:36:18 -07001014 if (iRet < 1) {
1015 pArguments->GetReturnValue()->SetNull();
1016 return;
1017 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001018 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1019 CXFA_Object* pNode = resoveNodeRS.nodes[0];
dsinclairf27aeec2016-06-07 19:36:18 -07001020 pArguments->GetReturnValue()->Assign(
1021 pScriptContext->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001022 } else {
1023 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
1024 resoveNodeRS.pScriptAttribute;
1025 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
dsinclair86fad992016-05-31 11:34:04 -07001026 std::unique_ptr<CFXJSE_Value> pValue(
1027 new CFXJSE_Value(pScriptContext->GetRuntime()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001028 (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))(
tsepezd19e9122016-11-02 15:43:18 -07001029 pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
dsinclairf27aeec2016-06-07 19:36:18 -07001030 pArguments->GetReturnValue()->Assign(pValue.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001031 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001032 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001033 }
1034 }
1035}
weili44f8faf2016-06-01 14:03:56 -07001036
Dan Sinclair1770c022016-03-14 14:14:16 -04001037void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
1038 int32_t iLength = pArguments->GetLength();
1039 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001040 ThrowParamCountMismatchException(L"resolveNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04001041 return;
1042 }
tsepez6fe7d212016-04-06 10:51:14 -07001043 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001044 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclair12a6b0c2016-05-26 11:14:08 -07001045 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001046 if (!pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04001047 return;
tsepez736f28a2016-03-25 14:19:51 -07001048 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001049 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1050 XFA_RESOLVENODE_Siblings;
1051 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001052 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001053 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
dsinclair12a6b0c2016-05-26 11:14:08 -07001054 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001055}
weili44f8faf2016-06-01 14:03:56 -07001056
dsinclair12a6b0c2016-05-26 11:14:08 -07001057void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001058 CFX_WideString wsExpression,
tsepez736f28a2016-03-25 14:19:51 -07001059 uint32_t dwFlag,
Dan Sinclair1770c022016-03-14 14:14:16 -04001060 CXFA_Node* refNode) {
dsinclairdf4bc592016-03-31 20:34:43 -07001061 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001062 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001063 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001064 XFA_RESOLVENODE_RS resoveNodeRS;
weili44f8faf2016-06-01 14:03:56 -07001065 if (!refNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04001066 refNode = this;
tsepez4c3debb2016-04-08 12:20:38 -07001067 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
tsepezfc58ad12016-04-05 12:22:15 -07001068 resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001069 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
1070 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1071 for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) {
1072 if (resoveNodeRS.nodes[i]->IsNode())
1073 pNodeList->Append(resoveNodeRS.nodes[i]->AsNode());
1074 }
1075 } else {
dsinclair12a6b0c2016-05-26 11:14:08 -07001076 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
1077 if (resoveNodeRS.GetAttributeResult(valueArray) > 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001078 CXFA_ObjArray objectArray;
dsinclair12a6b0c2016-05-26 11:14:08 -07001079 valueArray.GetAttributeObject(objectArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04001080 for (int32_t i = 0; i < objectArray.GetSize(); i++) {
1081 if (objectArray[i]->IsNode())
1082 pNodeList->Append(objectArray[i]->AsNode());
1083 }
1084 }
1085 }
dsinclairf27aeec2016-06-07 19:36:18 -07001086 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001087}
weili44f8faf2016-06-01 14:03:56 -07001088
dsinclair12a6b0c2016-05-26 11:14:08 -07001089void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001090 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001091 XFA_ATTRIBUTE eAttribute) {
1092 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001093 ThrowInvalidPropertyException();
1094 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001095 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001096
1097 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
1098 CFX_WideString wsName;
1099 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
dan sinclair65c7c232017-02-02 14:05:30 -08001100 CFX_WideString wsExpression = wsName + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001101 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001102}
weili44f8faf2016-06-01 14:03:56 -07001103
dsinclair12a6b0c2016-05-26 11:14:08 -07001104void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001105 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001106 XFA_ATTRIBUTE eAttribute) {
dsinclairdf4bc592016-03-31 20:34:43 -07001107 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001108 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001109 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001110 if (bSetting) {
Dan Sinclairc8fd3312017-01-02 17:17:02 -05001111 CFX_WideString wsMessage = L"Unable to set ";
Tom Sepezf0b65542017-02-13 10:26:01 -08001112 FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001113 } else {
1114 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
dsinclairf27aeec2016-06-07 19:36:18 -07001115 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001116 }
1117}
weili44f8faf2016-06-01 14:03:56 -07001118
dsinclair12a6b0c2016-05-26 11:14:08 -07001119void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001120 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001121 XFA_ATTRIBUTE eAttribute) {
1122 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001123 ThrowInvalidPropertyException();
1124 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001125 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001126 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
dan sinclair65c7c232017-02-02 14:05:30 -08001127 CFX_WideString wsExpression = L"#" + GetClassName() + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001128 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001129}
weili44f8faf2016-06-01 14:03:56 -07001130
dsinclair12a6b0c2016-05-26 11:14:08 -07001131void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001132 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001133 XFA_ATTRIBUTE eAttribute) {
1134 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001135 ThrowInvalidPropertyException();
1136 return;
1137 }
1138 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
1139 if (pParent) {
1140 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001141 } else {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001142 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001143 }
1144}
weili44f8faf2016-06-01 14:03:56 -07001145
dsinclair12a6b0c2016-05-26 11:14:08 -07001146void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001147 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001148 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001149 if (bSetting) {
1150 ThrowInvalidPropertyException();
1151 return;
1152 }
1153 pValue->SetInteger(GetNodeSameNameIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001154}
weili44f8faf2016-06-01 14:03:56 -07001155
dsinclair12a6b0c2016-05-26 11:14:08 -07001156void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001157 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001158 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001159 if (bSetting) {
1160 ThrowInvalidPropertyException();
1161 return;
1162 }
1163 pValue->SetInteger(GetNodeSameClassIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001164}
weili44f8faf2016-06-01 14:03:56 -07001165
dsinclair12a6b0c2016-05-26 11:14:08 -07001166void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001167 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001168 XFA_ATTRIBUTE eAttribute) {
1169 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001170 ThrowInvalidPropertyException();
1171 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001172 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001173 CFX_WideString wsSOMExpression;
1174 GetSOMExpression(wsSOMExpression);
Tom Sepezf0b65542017-02-13 10:26:01 -08001175 pValue->SetString(wsSOMExpression.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001176}
weili44f8faf2016-06-01 14:03:56 -07001177
Dan Sinclair1770c022016-03-14 14:14:16 -04001178void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
1179 int32_t iLength = pArguments->GetLength();
1180 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001181 ThrowParamCountMismatchException(L"applyXSL");
Dan Sinclair1770c022016-03-14 14:14:16 -04001182 return;
1183 }
tsepez6fe7d212016-04-06 10:51:14 -07001184 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001185 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili60607c32016-05-26 11:53:12 -07001186 // TODO(weili): check whether we need to implement this, pdfium:501.
1187 // For now, just put the variables here to avoid unused variable warning.
1188 (void)wsExpression;
Dan Sinclair1770c022016-03-14 14:14:16 -04001189}
weili60607c32016-05-26 11:53:12 -07001190
Dan Sinclair1770c022016-03-14 14:14:16 -04001191void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
1192 int32_t iLength = pArguments->GetLength();
1193 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001194 ThrowParamCountMismatchException(L"assignNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04001195 return;
1196 }
1197 CFX_WideString wsExpression;
1198 CFX_WideString wsValue;
1199 int32_t iAction = 0;
weili44f8faf2016-06-01 14:03:56 -07001200 wsExpression =
1201 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001202 if (iLength >= 2) {
weili60607c32016-05-26 11:53:12 -07001203 wsValue =
1204 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001205 }
weili60607c32016-05-26 11:53:12 -07001206 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001207 iAction = pArguments->GetInt32(2);
weili60607c32016-05-26 11:53:12 -07001208 // TODO(weili): check whether we need to implement this, pdfium:501.
1209 // For now, just put the variables here to avoid unused variable warning.
1210 (void)wsExpression;
1211 (void)wsValue;
1212 (void)iAction;
Dan Sinclair1770c022016-03-14 14:14:16 -04001213}
weili60607c32016-05-26 11:53:12 -07001214
Dan Sinclair1770c022016-03-14 14:14:16 -04001215void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
1216 int32_t iLength = pArguments->GetLength();
1217 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001218 ThrowParamCountMismatchException(L"clone");
Dan Sinclair1770c022016-03-14 14:14:16 -04001219 return;
1220 }
weili44f8faf2016-06-01 14:03:56 -07001221 bool bClone = !!pArguments->GetInt32(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001222 CXFA_Node* pCloneNode = Clone(bClone);
dsinclairf27aeec2016-06-07 19:36:18 -07001223 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001224 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
1225}
weili44f8faf2016-06-01 14:03:56 -07001226
Dan Sinclair1770c022016-03-14 14:14:16 -04001227void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
1228 int32_t iLength = pArguments->GetLength();
1229 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001230 ThrowParamCountMismatchException(L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001231 return;
1232 }
tsepez6fe7d212016-04-06 10:51:14 -07001233 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001234 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001235 CFX_WideString wsValue;
tsepez4c3debb2016-04-08 12:20:38 -07001236 GetAttribute(wsExpression.AsStringC(), wsValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07001237 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001238 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08001239 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001240}
weili44f8faf2016-06-01 14:03:56 -07001241
Dan Sinclair1770c022016-03-14 14:14:16 -04001242void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
1243 int32_t iLength = pArguments->GetLength();
1244 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001245 ThrowParamCountMismatchException(L"getElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001246 return;
1247 }
1248 CFX_WideString wsExpression;
1249 int32_t iValue = 0;
weili44f8faf2016-06-01 14:03:56 -07001250 wsExpression =
1251 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1252 if (iLength >= 2)
Dan Sinclair1770c022016-03-14 14:14:16 -04001253 iValue = pArguments->GetInt32(1);
dsinclair6e124782016-06-23 12:14:55 -07001254 CXFA_Node* pNode =
1255 GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
dsinclairf27aeec2016-06-07 19:36:18 -07001256 pArguments->GetReturnValue()->Assign(
1257 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001258}
weili65be4b12016-05-25 15:47:43 -07001259
Dan Sinclair1770c022016-03-14 14:14:16 -04001260void CXFA_Node::Script_NodeClass_IsPropertySpecified(
1261 CFXJSE_Arguments* pArguments) {
1262 int32_t iLength = pArguments->GetLength();
1263 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001264 ThrowParamCountMismatchException(L"isPropertySpecified");
Dan Sinclair1770c022016-03-14 14:14:16 -04001265 return;
1266 }
1267 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001268 bool bParent = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001269 int32_t iIndex = 0;
weili44f8faf2016-06-01 14:03:56 -07001270 wsExpression =
1271 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili65be4b12016-05-25 15:47:43 -07001272 if (iLength >= 2)
weili44f8faf2016-06-01 14:03:56 -07001273 bParent = !!pArguments->GetInt32(1);
weili65be4b12016-05-25 15:47:43 -07001274 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001275 iIndex = pArguments->GetInt32(2);
tsepezd19e9122016-11-02 15:43:18 -07001276 bool bHas = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001277 const XFA_ATTRIBUTEINFO* pAttributeInfo =
tsepez4c3debb2016-04-08 12:20:38 -07001278 XFA_GetAttributeByName(wsExpression.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001279 CFX_WideString wsValue;
weili65be4b12016-05-25 15:47:43 -07001280 if (pAttributeInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04001281 bHas = HasAttribute(pAttributeInfo->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04001282 if (!bHas) {
dsinclair6e124782016-06-23 12:14:55 -07001283 XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
1284 bHas = !!GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001285 if (!bHas && bParent && m_pParent) {
1286 // Also check on the parent.
1287 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
1288 if (!bHas)
dsinclair6e124782016-06-23 12:14:55 -07001289 bHas = !!m_pParent->GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001290 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001291 }
dsinclair12a6b0c2016-05-26 11:14:08 -07001292 CFXJSE_Value* pValue = pArguments->GetReturnValue();
1293 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001294 pValue->SetBoolean(bHas);
Dan Sinclair1770c022016-03-14 14:14:16 -04001295}
weili65be4b12016-05-25 15:47:43 -07001296
Dan Sinclair1770c022016-03-14 14:14:16 -04001297void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
1298 int32_t iLength = pArguments->GetLength();
1299 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001300 ThrowParamCountMismatchException(L"loadXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001301 return;
1302 }
1303 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001304 bool bIgnoreRoot = true;
1305 bool bOverwrite = 0;
1306 wsExpression =
1307 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1308 if (wsExpression.IsEmpty())
Tom Sepezd3743ea2016-05-16 15:56:53 -07001309 return;
weili44f8faf2016-06-01 14:03:56 -07001310 if (iLength >= 2)
1311 bIgnoreRoot = !!pArguments->GetInt32(1);
1312 if (iLength >= 3)
1313 bOverwrite = !!pArguments->GetInt32(2);
dsinclaira1b07722016-07-11 08:20:58 -07001314 std::unique_ptr<CXFA_SimpleParser> pParser(
1315 new CXFA_SimpleParser(m_pDocument, false));
weili44f8faf2016-06-01 14:03:56 -07001316 if (!pParser)
Dan Sinclair1770c022016-03-14 14:14:16 -04001317 return;
weili44f8faf2016-06-01 14:03:56 -07001318 CFDE_XMLNode* pXMLNode = nullptr;
1319 int32_t iParserStatus =
1320 pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
1321 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
1322 return;
dsinclairae95f762016-03-29 16:58:29 -07001323 if (bIgnoreRoot &&
1324 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
1325 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
weili44f8faf2016-06-01 14:03:56 -07001326 bIgnoreRoot = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001327 }
tsepezd19e9122016-11-02 15:43:18 -07001328 CXFA_Node* pFakeRoot = Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001329 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
1330 if (!wsContentType.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07001331 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
1332 CFX_WideString(wsContentType));
Dan Sinclair1770c022016-03-14 14:14:16 -04001333 }
dsinclairae95f762016-03-29 16:58:29 -07001334 CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001335 if (!pFakeXMLRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001336 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
tsepezd19e9122016-11-02 15:43:18 -07001337 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001338 }
dsinclair017052a2016-06-28 07:43:51 -07001339 if (!pFakeXMLRoot)
1340 pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName()));
1341
Dan Sinclair1770c022016-03-14 14:14:16 -04001342 if (bIgnoreRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001343 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001344 while (pXMLChild) {
dsinclairae95f762016-03-29 16:58:29 -07001345 CFDE_XMLNode* pXMLSibling =
1346 pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001347 pXMLNode->RemoveChildNode(pXMLChild);
1348 pFakeXMLRoot->InsertChildNode(pXMLChild);
1349 pXMLChild = pXMLSibling;
1350 }
1351 } else {
dsinclairae95f762016-03-29 16:58:29 -07001352 CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001353 if (pXMLParent) {
1354 pXMLParent->RemoveChildNode(pXMLNode);
1355 }
1356 pFakeXMLRoot->InsertChildNode(pXMLNode);
1357 }
1358 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot);
1359 pFakeRoot = pParser->GetRootNode();
1360 if (pFakeRoot) {
1361 if (bOverwrite) {
1362 CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1363 CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1364 int32_t index = 0;
1365 while (pNewChild) {
1366 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1367 pFakeRoot->RemoveChild(pNewChild);
1368 InsertChild(index++, pNewChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001369 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001370 pNewChild = pItem;
1371 }
1372 while (pChild) {
1373 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1374 RemoveChild(pChild);
1375 pFakeRoot->InsertChild(pChild);
1376 pChild = pItem;
1377 }
1378 if (GetPacketID() == XFA_XDPPACKET_Form &&
dsinclair070fcdf2016-06-22 22:04:54 -07001379 GetElementType() == XFA_Element::ExData) {
dsinclairae95f762016-03-29 16:58:29 -07001380 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001381 SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001382 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
weili44f8faf2016-06-01 14:03:56 -07001383 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001384 pFakeXMLRoot = pTempXMLNode;
1385 } else {
weili44f8faf2016-06-01 14:03:56 -07001386 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001387 }
1388 }
tsepezd19e9122016-11-02 15:43:18 -07001389 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001390 } else {
1391 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1392 while (pChild) {
1393 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1394 pFakeRoot->RemoveChild(pChild);
1395 InsertChild(pChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001396 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001397 pChild = pItem;
1398 }
1399 }
1400 if (pFakeXMLRoot) {
1401 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001402 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001403 }
dsinclairc5a8f212016-06-20 11:11:12 -07001404 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001405 } else {
tsepezc757d9a2017-01-23 11:01:42 -08001406 delete pFakeXMLRoot;
1407 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001408 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001409}
weili44f8faf2016-06-01 14:03:56 -07001410
Dan Sinclair1770c022016-03-14 14:14:16 -04001411void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
weili44f8faf2016-06-01 14:03:56 -07001412 // TODO(weili): Check whether we need to implement this, pdfium:501.
Dan Sinclair1770c022016-03-14 14:14:16 -04001413}
1414
1415void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1416 int32_t iLength = pArguments->GetLength();
1417 if (iLength < 0 || iLength > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001418 ThrowParamCountMismatchException(L"saveXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001419 return;
1420 }
weili44f8faf2016-06-01 14:03:56 -07001421 bool bPrettyMode = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001422 if (iLength == 1) {
weili65be4b12016-05-25 15:47:43 -07001423 if (pArguments->GetUTF8String(0) != "pretty") {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001424 ThrowArgumentMismatchException();
Dan Sinclair1770c022016-03-14 14:14:16 -04001425 return;
1426 }
weili44f8faf2016-06-01 14:03:56 -07001427 bPrettyMode = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001428 }
1429 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
weili65be4b12016-05-25 15:47:43 -07001430 if (GetPacketID() == XFA_XDPPACKET_Form ||
1431 GetPacketID() == XFA_XDPPACKET_Datasets) {
1432 CFDE_XMLNode* pElement = nullptr;
1433 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1434 pElement = GetXMLMappingNode();
1435 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
dsinclairf27aeec2016-06-07 19:36:18 -07001436 pArguments->GetReturnValue()->SetString(bsXMLHeader);
weili65be4b12016-05-25 15:47:43 -07001437 return;
1438 }
1439 XFA_DataExporter_DealWithDataGroupNode(this);
1440 }
tsepez833619b2016-12-07 09:21:17 -08001441 CFX_RetainPtr<IFX_MemoryStream> pMemoryStream =
1442 IFX_MemoryStream::Create(true);
1443
1444 // Note: ambiguious below without static_cast.
tsepez7cda31a2016-12-07 12:10:20 -08001445 CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream(
1446 CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream),
1447 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
tsepez833619b2016-12-07 09:21:17 -08001448
Dan Sinclair1770c022016-03-14 14:14:16 -04001449 if (!pStream) {
dsinclairf27aeec2016-06-07 19:36:18 -07001450 pArguments->GetReturnValue()->SetString(bsXMLHeader);
Dan Sinclair1770c022016-03-14 14:14:16 -04001451 return;
1452 }
1453 pStream->SetCodePage(FX_CODEPAGE_UTF8);
dsinclair179bebb2016-04-05 11:02:18 -07001454 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
weili65be4b12016-05-25 15:47:43 -07001455 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepez7cda31a2016-12-07 12:10:20 -08001456 XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001457 else
tsepez7cda31a2016-12-07 12:10:20 -08001458 pElement->SaveXMLNode(pStream);
weili65be4b12016-05-25 15:47:43 -07001459 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1460 // For now, just put it here to avoid unused variable warning.
1461 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001462 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001463 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001464 return;
1465 }
dsinclairf27aeec2016-06-07 19:36:18 -07001466 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001467}
1468
1469void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1470 int32_t iLength = pArguments->GetLength();
1471 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001472 ThrowParamCountMismatchException(L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001473 return;
1474 }
tsepez6fe7d212016-04-06 10:51:14 -07001475 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001476 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001477 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001478 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001479 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001480}
weili60607c32016-05-26 11:53:12 -07001481
Dan Sinclair1770c022016-03-14 14:14:16 -04001482void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1483 int32_t iLength = pArguments->GetLength();
1484 if (iLength != 1 && iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001485 ThrowParamCountMismatchException(L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001486 return;
1487 }
weili60607c32016-05-26 11:53:12 -07001488 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001489 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001490 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1491 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001492 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001493 // TODO(weili): check whether we need to implement this, pdfium:501.
1494 // For now, just put the variables here to avoid unused variable warning.
1495 (void)pNode;
1496 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001497}
weili60607c32016-05-26 11:53:12 -07001498
dsinclair12a6b0c2016-05-26 11:14:08 -07001499void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001500 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001501 XFA_ATTRIBUTE eAttribute) {
1502 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001503 ThrowInvalidPropertyException();
1504 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001505 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001506
1507 CFX_WideString wsNameSpace;
1508 TryNamespace(wsNameSpace);
Tom Sepezf0b65542017-02-13 10:26:01 -08001509 pValue->SetString(wsNameSpace.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001510}
weili44f8faf2016-06-01 14:03:56 -07001511
dsinclair12a6b0c2016-05-26 11:14:08 -07001512void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001513 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001514 XFA_ATTRIBUTE eAttribute) {
1515 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001516 ThrowInvalidPropertyException();
1517 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001518 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001519 pValue->Assign(
1520 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001521}
weili44f8faf2016-06-01 14:03:56 -07001522
dsinclair12a6b0c2016-05-26 11:14:08 -07001523void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001524 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001525 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001526 if (bSetting) {
1527 ThrowInvalidPropertyException();
1528 return;
1529 }
1530 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001531}
weili44f8faf2016-06-01 14:03:56 -07001532
dsinclair12a6b0c2016-05-26 11:14:08 -07001533void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001534 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001535 XFA_ATTRIBUTE eAttribute) {
1536 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001537 ThrowInvalidPropertyException();
1538 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001539 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001540 if (GetElementType() == XFA_Element::Subform) {
1541 pValue->SetBoolean(false);
1542 return;
1543 }
1544 CFX_WideString strValue;
1545 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001546}
weili44f8faf2016-06-01 14:03:56 -07001547
dsinclair12a6b0c2016-05-26 11:14:08 -07001548void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001549 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001550 XFA_ATTRIBUTE eAttribute) {
1551 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001552 ThrowInvalidPropertyException();
1553 return;
1554 }
1555
1556 CXFA_NodeArray properts;
1557 int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty);
1558 if (iSize > 0) {
1559 pValue->Assign(
1560 m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0]));
Dan Sinclair1770c022016-03-14 14:14:16 -04001561 }
1562}
weili44f8faf2016-06-01 14:03:56 -07001563
Dan Sinclair1770c022016-03-14 14:14:16 -04001564void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001565
Dan Sinclair1770c022016-03-14 14:14:16 -04001566void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1567 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001568 pArguments->GetReturnValue()->SetObject(
1569 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001570}
1571void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1572}
dsinclair5b36f0a2016-07-19 10:56:23 -07001573
Dan Sinclair1770c022016-03-14 14:14:16 -04001574void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1575 Script_Template_CreateNode(pArguments);
1576}
dsinclair5b36f0a2016-07-19 10:56:23 -07001577
Dan Sinclair1770c022016-03-14 14:14:16 -04001578void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1579 int32_t iLength = pArguments->GetLength();
1580 if (iLength < 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001581 ThrowParamCountMismatchException(L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001582 return;
1583 }
1584 CFX_WideString wsNameSpace;
1585 if (iLength >= 1) {
1586 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001587 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001588 }
1589 CFX_WideString wsNodeNameSpace;
1590 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001591 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001592 if (pValue)
1593 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001594}
dsinclair5b36f0a2016-07-19 10:56:23 -07001595
dsinclair12a6b0c2016-05-26 11:14:08 -07001596void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001597 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001598 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001599
dsinclair12a6b0c2016-05-26 11:14:08 -07001600void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001601 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001602 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001603
dsinclair12a6b0c2016-05-26 11:14:08 -07001604void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001605 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001606 XFA_ATTRIBUTE eAttribute) {
1607 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001608 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001609 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001610 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001611 }
1612}
dsinclair5b36f0a2016-07-19 10:56:23 -07001613
dsinclair12a6b0c2016-05-26 11:14:08 -07001614void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001615 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001616 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001617 if (bSetting) {
1618 ThrowInvalidPropertyException();
1619 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001620 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001621 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001622}
dsinclair5b36f0a2016-07-19 10:56:23 -07001623
dsinclair12a6b0c2016-05-26 11:14:08 -07001624void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001625 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001626 XFA_ATTRIBUTE eAttribute) {
1627 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001628 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001629 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001630 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001631 }
1632}
dsinclair5b36f0a2016-07-19 10:56:23 -07001633
dsinclair12a6b0c2016-05-26 11:14:08 -07001634void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001635 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001636 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001637 if (bSetting) {
1638 ThrowInvalidPropertyException();
1639 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001640 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001641 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001642}
thestigb1a59592016-04-14 18:29:56 -07001643
Dan Sinclair1770c022016-03-14 14:14:16 -04001644void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001645 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001646 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001647 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001648 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001649 return;
thestigb1a59592016-04-14 18:29:56 -07001650
dsinclaira1b07722016-07-11 08:20:58 -07001651 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001652 if (!pNotify)
1653 return;
1654
1655 uint32_t dwPacket = GetPacketID();
1656 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1657 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001658 return;
1659 }
thestigb1a59592016-04-14 18:29:56 -07001660
1661 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001662 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001663 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001664 bNeedFindContainer = true;
1665 pNotify->OnValueChanged(this, eAttribute, this,
1666 GetNodeItem(XFA_NODEITEM_Parent));
1667 break;
dsinclair56a8b192016-06-21 14:15:25 -07001668 case XFA_Element::Font:
1669 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001670 bNeedFindContainer = true;
1671 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001672 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001673 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1674 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1675 } else {
1676 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1677 }
1678 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001679 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001680 bNeedFindContainer = true;
1681 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001682 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001683 if (pParentNode->IsContainerNode()) {
1684 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001685 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001686 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1687 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1688 } else {
1689 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001690 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001691 pNotify->OnValueChanged(this, eAttribute, pNode,
1692 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001693 }
thestigb1a59592016-04-14 18:29:56 -07001694 }
1695 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001696 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001697 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001698 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001699 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1700 eUIType == XFA_Element::NumericEdit ||
1701 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001702 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001703 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001704 pNotify->OnValueChanged(this, eAttribute, pUINode,
1705 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001706 }
thestigb1a59592016-04-14 18:29:56 -07001707 }
1708 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001709 case XFA_Element::Button:
1710 case XFA_Element::Barcode:
1711 case XFA_Element::ChoiceList:
1712 case XFA_Element::DateTimeEdit:
1713 case XFA_Element::NumericEdit:
1714 case XFA_Element::PasswordEdit:
1715 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001716 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1717 if (pUINode) {
1718 pNotify->OnValueChanged(this, eAttribute, pUINode,
1719 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1720 }
1721 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001722 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001723 bNeedFindContainer = true;
1724 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1725 if (pUINode) {
1726 pNotify->OnValueChanged(this, eAttribute, pUINode,
1727 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1728 }
1729 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001730 case XFA_Element::Keep:
1731 case XFA_Element::Bookend:
1732 case XFA_Element::Break:
1733 case XFA_Element::BreakAfter:
1734 case XFA_Element::BreakBefore:
1735 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001736 bNeedFindContainer = true;
1737 break;
dsinclair56a8b192016-06-21 14:15:25 -07001738 case XFA_Element::Area:
1739 case XFA_Element::Draw:
1740 case XFA_Element::ExclGroup:
1741 case XFA_Element::Field:
1742 case XFA_Element::Subform:
1743 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001744 pLayoutPro->AddChangedContainer(this);
1745 pNotify->OnValueChanged(this, eAttribute, this, this);
1746 break;
dsinclair56a8b192016-06-21 14:15:25 -07001747 case XFA_Element::Sharptext:
1748 case XFA_Element::Sharpxml:
1749 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001750 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1751 if (!pTextNode) {
1752 return;
1753 }
1754 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1755 if (!pValueNode) {
1756 return;
1757 }
dsinclair41cb62e2016-06-23 09:20:32 -07001758 XFA_Element eType = pValueNode->GetElementType();
1759 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001760 bNeedFindContainer = true;
1761 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1762 if (pNode && pNode->IsContainerNode()) {
1763 if (bScriptModify) {
1764 pValueNode = pNode;
1765 }
1766 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1767 } else {
1768 pNotify->OnValueChanged(this, eAttribute, pNode,
1769 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001770 }
thestigb1a59592016-04-14 18:29:56 -07001771 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001772 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001773 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1774 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001775 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001776 }
1777 }
thestigb1a59592016-04-14 18:29:56 -07001778 }
1779 } break;
1780 default:
1781 break;
1782 }
1783 if (bNeedFindContainer) {
1784 CXFA_Node* pParent = this;
1785 while (pParent) {
1786 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001787 break;
thestigb1a59592016-04-14 18:29:56 -07001788
1789 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001790 }
thestigb1a59592016-04-14 18:29:56 -07001791 if (pParent) {
1792 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001793 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001794 }
1795}
thestigb1a59592016-04-14 18:29:56 -07001796
dsinclair12a6b0c2016-05-26 11:14:08 -07001797void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001798 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001799 XFA_ATTRIBUTE eAttribute) {
1800 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001801 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001802 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001803 if (eAttribute == XFA_ATTRIBUTE_Use &&
1804 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001805 CXFA_Node* pTemplateNode =
1806 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1807 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001808 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1809 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001810
1811 CFX_WideString wsID;
1812 CFX_WideString wsSOM;
1813 if (!wsValue.IsEmpty()) {
1814 if (wsValue[0] == '#') {
1815 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001816 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001817 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001818 }
1819 }
weili44f8faf2016-06-01 14:03:56 -07001820 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001821 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001822 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001823 XFA_RESOLVENODE_Attributes |
1824 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1825 XFA_RESOLVENODE_Siblings;
1826 XFA_RESOLVENODE_RS resoveNodeRS;
1827 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001828 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001829 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) {
1830 pProtoNode = resoveNodeRS.nodes[0]->AsNode();
1831 }
1832 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001833 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001834 }
1835 if (pProtoNode) {
1836 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1837 while (pHeadChild) {
1838 CXFA_Node* pSibling =
1839 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1840 RemoveChild(pHeadChild);
1841 pHeadChild = pSibling;
1842 }
tsepezd19e9122016-11-02 15:43:18 -07001843 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001844 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1845 while (pHeadChild) {
1846 CXFA_Node* pSibling =
1847 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1848 pProtoForm->RemoveChild(pHeadChild);
1849 InsertChild(pHeadChild);
1850 pHeadChild = pSibling;
1851 }
1852 m_pDocument->RemovePurgeNode(pProtoForm);
1853 delete pProtoForm;
1854 }
1855 }
1856 } else {
1857 CFX_WideString wsValue;
1858 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001859 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001860 }
1861}
dsinclair5b36f0a2016-07-19 10:56:23 -07001862
dsinclair12a6b0c2016-05-26 11:14:08 -07001863void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001864 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001865 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001866 if (bSetting) {
1867 ThrowInvalidPropertyException();
1868 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001869 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001870
1871 CFX_WideString wsValue;
1872 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001873 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001874}
dsinclair5b36f0a2016-07-19 10:56:23 -07001875
Dan Sinclair1770c022016-03-14 14:14:16 -04001876void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1877 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001878 if (argc != 0 && argc != 1) {
1879 ThrowParamCountMismatchException(L"execute");
1880 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001881 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001882 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001883}
dsinclair5b36f0a2016-07-19 10:56:23 -07001884
Dan Sinclair1770c022016-03-14 14:14:16 -04001885void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001886 if (pArguments->GetLength() != 0)
1887 ThrowParamCountMismatchException(L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001888}
dsinclair5b36f0a2016-07-19 10:56:23 -07001889
dsinclair12a6b0c2016-05-26 11:14:08 -07001890void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001891 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001892 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001893
dsinclair12a6b0c2016-05-26 11:14:08 -07001894void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001895 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001896 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001897
dsinclair12a6b0c2016-05-26 11:14:08 -07001898void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001899 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001900 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001901
dsinclair12a6b0c2016-05-26 11:14:08 -07001902void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001903 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001904 XFA_SOM_MESSAGETYPE iMessageType) {
1905 CXFA_WidgetData* pWidgetData = GetWidgetData();
1906 if (!pWidgetData) {
1907 return;
1908 }
tsepezd19e9122016-11-02 15:43:18 -07001909 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001910 CXFA_Validate validate = pWidgetData->GetValidate();
1911 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001912 validate = pWidgetData->GetValidate(true);
1913 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001914 }
1915 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001916 switch (iMessageType) {
1917 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001918 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001919 break;
1920 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001921 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001922 break;
1923 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001924 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001925 break;
1926 default:
1927 break;
1928 }
1929 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001930 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001931 if (!pNotify) {
1932 return;
1933 }
1934 pNotify->AddCalcValidate(this);
1935 }
1936 } else {
1937 CFX_WideString wsMessage;
1938 switch (iMessageType) {
1939 case XFA_SOM_ValidationMessage:
1940 validate.GetScriptMessageText(wsMessage);
1941 break;
1942 case XFA_SOM_FormatMessage:
1943 validate.GetFormatMessageText(wsMessage);
1944 break;
1945 case XFA_SOM_MandatoryMessage:
1946 validate.GetNullMessageText(wsMessage);
1947 break;
1948 default:
1949 break;
1950 }
Tom Sepezf0b65542017-02-13 10:26:01 -08001951 pValue->SetString(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001952 }
1953}
dsinclair5b36f0a2016-07-19 10:56:23 -07001954
dsinclair12a6b0c2016-05-26 11:14:08 -07001955void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001956 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001957 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001958 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001959}
dsinclair5b36f0a2016-07-19 10:56:23 -07001960
dsinclair12a6b0c2016-05-26 11:14:08 -07001961void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001962 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001963 XFA_ATTRIBUTE eAttribute) {
1964 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001965 ThrowInvalidPropertyException();
1966 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001967 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001968
1969 CXFA_WidgetData* pWidgetData = GetWidgetData();
1970 if (!pWidgetData) {
1971 pValue->SetInteger(0);
1972 return;
1973 }
1974 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001975}
dsinclair5b36f0a2016-07-19 10:56:23 -07001976
dsinclair12a6b0c2016-05-26 11:14:08 -07001977void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001978 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001979 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001980 XFA_Element eType = GetElementType();
1981 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001982 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001983 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001984 }
1985 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001986 Script_Draw_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::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001990 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001991 return;
1992 }
1993 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001994 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07001995 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07001996 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07001997
Dan Sinclair1770c022016-03-14 14:14:16 -04001998 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07001999 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002000 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
2001 CXFA_NodeArray formNodes;
2002 GetBindItems(formNodes);
2003 CFX_WideString wsPicture;
2004 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
2005 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -07002006 if (!pFormNode || pFormNode->HasRemovedChildren()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002007 continue;
2008 }
2009 pContainerWidgetData = pFormNode->GetContainerWidgetData();
2010 if (pContainerWidgetData) {
2011 pContainerWidgetData->GetPictureContent(wsPicture,
2012 XFA_VALUEPICTURE_DataBind);
2013 }
2014 if (!wsPicture.IsEmpty()) {
2015 break;
2016 }
weili44f8faf2016-06-01 14:03:56 -07002017 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002018 }
2019 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
2020 pContainerWidgetData = GetContainerWidgetData();
2021 }
2022 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002023 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002024 }
tsepezd19e9122016-11-02 15:43:18 -07002025 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002026 } else {
tsepezd19e9122016-11-02 15:43:18 -07002027 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07002028 if (content.IsEmpty() && eType != XFA_Element::Text &&
2029 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07002030 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07002031 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002032 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07002033 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07002034 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002035 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002036 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002037 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002038 }
2039 }
2040}
dsinclair5b36f0a2016-07-19 10:56:23 -07002041
dsinclair12a6b0c2016-05-26 11:14:08 -07002042void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002043 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002044 XFA_ATTRIBUTE eAttribute) {
2045 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002046 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002047 return;
2048 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002049
tsepezd19e9122016-11-02 15:43:18 -07002050 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002051 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002052 pValue->SetNull();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002053 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002054 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002055 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002056}
dsinclair5b36f0a2016-07-19 10:56:23 -07002057
dsinclair12a6b0c2016-05-26 11:14:08 -07002058void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002059 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002060 XFA_ATTRIBUTE eAttribute) {
2061 if (bSetting) {
2062 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002063 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002064 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002065
tsepezb4c9f3f2016-04-13 15:41:21 -07002066 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002067 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002068 CFX_WideString wsFormatValue(wsNewValue);
2069 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2070 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002071 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002072 }
tsepezd19e9122016-11-02 15:43:18 -07002073 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002074 } else {
tsepezd19e9122016-11-02 15:43:18 -07002075 CFX_WideString wsValue = GetScriptContent(true);
dan sinclair65c7c232017-02-02 14:05:30 -08002076 pValue->SetBoolean(wsValue == L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002077 }
2078}
dsinclair2f5582f2016-06-09 11:48:23 -07002079
dsinclair12a6b0c2016-05-26 11:14:08 -07002080void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002081 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002082 XFA_ATTRIBUTE eAttribute) {
2083 CXFA_WidgetData* pWidgetData = GetWidgetData();
2084 if (!pWidgetData) {
2085 return;
2086 }
tsepezd19e9122016-11-02 15:43:18 -07002087 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002088 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002089 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002090 int32_t r = 0;
2091 int32_t g = 0;
2092 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002093 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002094 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2095 for (int32_t i = 0; i < iSize; ++i) {
2096 CXFA_Edge edge = border.GetEdge(i);
2097 edge.SetColor(rgb);
2098 }
2099 } else {
2100 CXFA_Edge edge = border.GetEdge(0);
2101 FX_ARGB color = edge.GetColor();
2102 int32_t a, r, g, b;
2103 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002104 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002105 strColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002106 pValue->SetString(strColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002107 }
2108}
dsinclair5b36f0a2016-07-19 10:56:23 -07002109
dsinclair12a6b0c2016-05-26 11:14:08 -07002110void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002111 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002112 XFA_ATTRIBUTE eAttribute) {
2113 CXFA_WidgetData* pWidgetData = GetWidgetData();
2114 if (!pWidgetData) {
2115 return;
2116 }
tsepezd19e9122016-11-02 15:43:18 -07002117 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002118 int32_t iSize = border.CountEdges();
2119 CFX_WideString wsThickness;
2120 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002121 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002122 for (int32_t i = 0; i < iSize; ++i) {
2123 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002124 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002125 edge.SetMSThickness(thickness);
2126 }
2127 } else {
2128 CXFA_Edge edge = border.GetEdge(0);
2129 CXFA_Measurement thickness = edge.GetMSThickness();
2130 thickness.ToString(wsThickness);
Tom Sepezf0b65542017-02-13 10:26:01 -08002131 pValue->SetString(wsThickness.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002132 }
2133}
dsinclair5b36f0a2016-07-19 10:56:23 -07002134
dsinclair12a6b0c2016-05-26 11:14:08 -07002135void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002136 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002137 XFA_ATTRIBUTE eAttribute) {
2138 CXFA_WidgetData* pWidgetData = GetWidgetData();
2139 if (!pWidgetData) {
2140 return;
2141 }
tsepezd19e9122016-11-02 15:43:18 -07002142 CXFA_Border border = pWidgetData->GetBorder(true);
2143 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002144 CXFA_Node* pNode = borderfill.GetNode();
2145 if (!pNode) {
2146 return;
2147 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002148 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002149 int32_t r;
2150 int32_t g;
2151 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002152 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002153 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2154 borderfill.SetColor(color);
2155 } else {
2156 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002157 int32_t a;
2158 int32_t r;
2159 int32_t g;
2160 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002161 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002162 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002163 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002164 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002165 }
2166}
dsinclair5b36f0a2016-07-19 10:56:23 -07002167
dsinclair12a6b0c2016-05-26 11:14:08 -07002168void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002169 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002170 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002171 if (bSetting) {
2172 ThrowInvalidPropertyException();
2173 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002174 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002175
2176 CXFA_Node* pDataNode = GetBindData();
2177 if (!pDataNode) {
2178 pValue->SetNull();
2179 return;
2180 }
2181
2182 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002183}
dsinclair5b36f0a2016-07-19 10:56:23 -07002184
dsinclair12a6b0c2016-05-26 11:14:08 -07002185void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002186 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002187 XFA_ATTRIBUTE eAttribute) {
2188 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002189 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002190 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002191 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002192 XFA_Element uiType = pWidgetData->GetUIType();
2193 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002194 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002195 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002196 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002197 }
2198 }
2199 } else {
tsepezd19e9122016-11-02 15:43:18 -07002200 CFX_WideString content = GetScriptContent(true);
Tom Sepezf0b65542017-02-13 10:26:01 -08002201 if (content.IsEmpty())
dsinclairf27aeec2016-06-07 19:36:18 -07002202 pValue->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002203 else
2204 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002205 }
2206}
dsinclair5b36f0a2016-07-19 10:56:23 -07002207
dsinclair12a6b0c2016-05-26 11:14:08 -07002208void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002209 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002210 XFA_ATTRIBUTE eAttribute) {
2211 CXFA_WidgetData* pWidgetData = GetWidgetData();
2212 if (!pWidgetData) {
2213 return;
2214 }
2215 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002216 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002217 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002218 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002219 } else {
2220 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002221 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002222 }
dsinclair2f5582f2016-06-09 11:48:23 -07002223 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002224 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002225 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002226
Dan Sinclair1770c022016-03-14 14:14:16 -04002227 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002228 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002229 int32_t iLeadDigits = 0;
2230 int32_t iFracDigits = 0;
2231 pWidgetData->GetLeadDigits(iLeadDigits);
2232 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002233 wsNewText =
2234 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002235 }
2236 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2237 CFX_WideString wsFormatText(wsNewText);
2238 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002239 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002240 }
tsepezd19e9122016-11-02 15:43:18 -07002241 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002242 } else {
tsepezd19e9122016-11-02 15:43:18 -07002243 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002244 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002245 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002246 } else {
2247 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002248 CXFA_Value defVal = pWidgetData->GetFormValue();
2249 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002250 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002251 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002252 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
Tom Sepezf0b65542017-02-13 10:26:01 -08002253 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002254 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002255 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002256 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002257 }
dsinclair070fcdf2016-06-22 22:04:54 -07002258 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002259 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002260 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002261 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002262 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002263 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002264 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002265 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002266 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002267 }
2268 }
2269 }
2270}
dsinclair5b36f0a2016-07-19 10:56:23 -07002271
dsinclair12a6b0c2016-05-26 11:14:08 -07002272void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002273 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002274 XFA_ATTRIBUTE eAttribute) {
2275 CXFA_WidgetData* pWidgetData = GetWidgetData();
2276 if (!pWidgetData) {
2277 return;
2278 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002279 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002280 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002281 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002282 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002283 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
Tom Sepezf0b65542017-02-13 10:26:01 -08002284 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002285 }
2286}
dsinclair5b36f0a2016-07-19 10:56:23 -07002287
dsinclair12a6b0c2016-05-26 11:14:08 -07002288void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002289 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002290 XFA_ATTRIBUTE eAttribute) {
2291 CXFA_WidgetData* pWidgetData = GetWidgetData();
2292 if (!pWidgetData) {
2293 return;
2294 }
tsepezd19e9122016-11-02 15:43:18 -07002295 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002296 CXFA_Node* pNode = font.GetNode();
2297 if (!pNode) {
2298 return;
2299 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002300 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002301 int32_t r;
2302 int32_t g;
2303 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002304 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002305 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2306 font.SetColor(color);
2307 } else {
2308 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002309 int32_t a;
2310 int32_t r;
2311 int32_t g;
2312 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002313 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002314 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002315 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002316 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002317 }
2318}
dsinclair5b36f0a2016-07-19 10:56:23 -07002319
dsinclair12a6b0c2016-05-26 11:14:08 -07002320void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002321 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002322 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002323 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002324}
dsinclair5b36f0a2016-07-19 10:56:23 -07002325
dsinclair12a6b0c2016-05-26 11:14:08 -07002326void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002327 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002328 XFA_ATTRIBUTE eAttribute) {
2329 CXFA_WidgetData* pWidgetData = GetWidgetData();
2330 if (!pWidgetData) {
2331 return;
2332 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002333 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002334 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002335 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002336 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002337 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
Tom Sepezf0b65542017-02-13 10:26:01 -08002338 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002339 }
2340}
dsinclair5b36f0a2016-07-19 10:56:23 -07002341
dsinclair12a6b0c2016-05-26 11:14:08 -07002342void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002343 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002344 XFA_ATTRIBUTE eAttribute) {
2345 CXFA_WidgetData* pWidgetData = GetWidgetData();
2346 if (!pWidgetData) {
2347 return;
2348 }
tsepezd19e9122016-11-02 15:43:18 -07002349 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002350 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002351 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002352 } else {
2353 int32_t iValue = validate.GetNullTest();
2354 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002355 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002356 CFX_WideString wsValue;
2357 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002358 wsValue = pInfo->pName;
Tom Sepezf0b65542017-02-13 10:26:01 -08002359 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002360 }
2361}
dsinclair5b36f0a2016-07-19 10:56:23 -07002362
dsinclair12a6b0c2016-05-26 11:14:08 -07002363void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002364 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002365 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002366 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002367}
dsinclair5b36f0a2016-07-19 10:56:23 -07002368
dsinclair12a6b0c2016-05-26 11:14:08 -07002369void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002370 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002371 XFA_ATTRIBUTE eAttribute) {
2372 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002373 ThrowInvalidPropertyException();
2374 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002375 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002376 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002377}
dsinclair5b36f0a2016-07-19 10:56:23 -07002378
dsinclair12a6b0c2016-05-26 11:14:08 -07002379void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002380 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002381 XFA_ATTRIBUTE eAttribute) {
2382 CXFA_WidgetData* pWidgetData = GetWidgetData();
2383 if (!pWidgetData) {
2384 return;
2385 }
2386 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002387 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002388 if (iIndex == -1) {
2389 pWidgetData->ClearAllSelections();
2390 return;
2391 }
tsepezd19e9122016-11-02 15:43:18 -07002392 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002393 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002394 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002395 }
2396}
dsinclair5b36f0a2016-07-19 10:56:23 -07002397
Dan Sinclair1770c022016-03-14 14:14:16 -04002398void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2399 CXFA_WidgetData* pWidgetData = GetWidgetData();
2400 if (!pWidgetData) {
2401 return;
2402 }
tsepezd19e9122016-11-02 15:43:18 -07002403 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002404}
dsinclair5b36f0a2016-07-19 10:56:23 -07002405
Dan Sinclair1770c022016-03-14 14:14:16 -04002406void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002407 if (pArguments->GetLength() != 1) {
2408 ThrowParamCountMismatchException(L"execEvent");
2409 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002410 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002411
2412 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2413 int32_t iRet = execSingleEventByName(
2414 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2415 XFA_Element::Field);
2416 if (eventString != "validate")
2417 return;
2418
2419 pArguments->GetReturnValue()->SetBoolean(
2420 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002421}
dsinclair5b36f0a2016-07-19 10:56:23 -07002422
Dan Sinclair1770c022016-03-14 14:14:16 -04002423void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002424 if (pArguments->GetLength() != 0) {
2425 ThrowParamCountMismatchException(L"execInitialize");
2426 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002427 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002428
2429 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2430 if (!pNotify)
2431 return;
2432
2433 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002434}
dsinclair5b36f0a2016-07-19 10:56:23 -07002435
Dan Sinclair1770c022016-03-14 14:14:16 -04002436void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2437 int32_t iLength = pArguments->GetLength();
2438 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002439 ThrowParamCountMismatchException(L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002440 return;
2441 }
2442 CXFA_WidgetData* pWidgetData = GetWidgetData();
2443 if (!pWidgetData) {
2444 return;
2445 }
2446 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002447 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002448 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002449 if (pValue)
2450 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002451}
dsinclair5b36f0a2016-07-19 10:56:23 -07002452
Dan Sinclair1770c022016-03-14 14:14:16 -04002453void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2454 int32_t iLength = pArguments->GetLength();
2455 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002456 ThrowParamCountMismatchException(L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002457 return;
2458 }
2459 int32_t iIndex = pArguments->GetInt32(0);
2460 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002461 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002462 return;
2463 }
2464 CXFA_WidgetData* pWidgetData = GetWidgetData();
2465 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002466 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002467 return;
2468 }
2469 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002470 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002471 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002472 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002473 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002474 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002475}
dsinclair5b36f0a2016-07-19 10:56:23 -07002476
Dan Sinclair1770c022016-03-14 14:14:16 -04002477void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2478 int32_t iLength = pArguments->GetLength();
2479 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002480 ThrowParamCountMismatchException(L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002481 return;
2482 }
2483 CXFA_WidgetData* pWidgetData = GetWidgetData();
2484 if (!pWidgetData) {
2485 return;
2486 }
2487 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002488 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002489 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002490 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002491 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002492 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08002493 pValue->SetString(wsBoundValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002494}
dsinclair5b36f0a2016-07-19 10:56:23 -07002495
Dan Sinclair1770c022016-03-14 14:14:16 -04002496void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2497 int32_t iLength = pArguments->GetLength();
2498 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002499 ThrowParamCountMismatchException(L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002500 return;
2501 }
2502 CXFA_WidgetData* pWidgetData = GetWidgetData();
2503 if (!pWidgetData) {
2504 return;
2505 }
2506 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002507 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002508 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002509 if (pValue)
2510 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002511}
dsinclair5b36f0a2016-07-19 10:56:23 -07002512
Dan Sinclair1770c022016-03-14 14:14:16 -04002513void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002514 if (pArguments->GetLength() != 0) {
2515 ThrowParamCountMismatchException(L"execCalculate");
2516 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002517 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002518
2519 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2520 if (!pNotify)
2521 return;
2522
2523 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002524}
dsinclair5b36f0a2016-07-19 10:56:23 -07002525
Dan Sinclair1770c022016-03-14 14:14:16 -04002526void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002527
Dan Sinclair1770c022016-03-14 14:14:16 -04002528void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2529 int32_t iLength = pArguments->GetLength();
2530 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002531 ThrowParamCountMismatchException(L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002532 return;
2533 }
2534 int32_t iIndex = pArguments->GetInt32(0);
2535 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002536 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002537 return;
2538 }
2539 CXFA_WidgetData* pWidgetData = GetWidgetData();
2540 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002541 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002542 return;
2543 }
2544 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002545 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002546 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002547 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002548 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002549 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002550}
dsinclair5b36f0a2016-07-19 10:56:23 -07002551
Dan Sinclair1770c022016-03-14 14:14:16 -04002552void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2553 int32_t iLength = pArguments->GetLength();
2554 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002555 ThrowParamCountMismatchException(L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002556 return;
2557 }
2558 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002559 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002560 return;
thestig800222e2016-05-26 22:00:29 -07002561
Dan Sinclair1770c022016-03-14 14:14:16 -04002562 int32_t iIndex = pArguments->GetInt32(0);
2563 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002564 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002565 } else {
thestig800222e2016-05-26 22:00:29 -07002566 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002567 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002568 }
2569}
dsinclair5b36f0a2016-07-19 10:56:23 -07002570
Dan Sinclair1770c022016-03-14 14:14:16 -04002571void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2572 int32_t iLength = pArguments->GetLength();
2573 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002574 ThrowParamCountMismatchException(L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002575 return;
2576 }
2577 CXFA_WidgetData* pWidgetData = GetWidgetData();
2578 if (!pWidgetData) {
2579 return;
2580 }
2581 CFX_WideString wsLabel;
2582 CFX_WideString wsValue;
2583 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002584 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002585 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002586 }
2587 if (iLength >= 2) {
2588 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002589 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002590 }
tsepezd19e9122016-11-02 15:43:18 -07002591 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002592}
dsinclair5b36f0a2016-07-19 10:56:23 -07002593
Dan Sinclair1770c022016-03-14 14:14:16 -04002594void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002595 if (pArguments->GetLength() != 0) {
2596 ThrowParamCountMismatchException(L"execValidate");
2597 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002598 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002599
2600 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2601 if (!pNotify) {
2602 pArguments->GetReturnValue()->SetBoolean(false);
2603 return;
2604 }
2605
2606 int32_t iRet =
2607 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
2608 pArguments->GetReturnValue()->SetBoolean(
2609 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002610}
dsinclair5b36f0a2016-07-19 10:56:23 -07002611
dsinclair12a6b0c2016-05-26 11:14:08 -07002612void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002613 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002614 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002615 if (bSetting)
2616 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002617}
dsinclair5b36f0a2016-07-19 10:56:23 -07002618
dsinclair12a6b0c2016-05-26 11:14:08 -07002619void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002620 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002621 XFA_ATTRIBUTE eAttribute) {
2622 CXFA_WidgetData* pWidgetData = GetWidgetData();
2623 if (!pWidgetData) {
2624 return;
2625 }
2626 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002627 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002628 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002629 } else {
tsepezd19e9122016-11-02 15:43:18 -07002630 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002631 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2632 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002633 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002634 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002635 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002636 }
2637 }
2638}
dsinclair5b36f0a2016-07-19 10:56:23 -07002639
dsinclair12a6b0c2016-05-26 11:14:08 -07002640void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002641 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002642 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002643
Dan Sinclair1770c022016-03-14 14:14:16 -04002644void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002645 if (pArguments->GetLength() != 1) {
2646 ThrowParamCountMismatchException(L"execEvent");
2647 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002648 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002649
2650 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2651 execSingleEventByName(
2652 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2653 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002654}
thestig800222e2016-05-26 22:00:29 -07002655
Dan Sinclair1770c022016-03-14 14:14:16 -04002656void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2657 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002658 if (argc < 0 || argc > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002659 ThrowParamCountMismatchException(L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002660 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002661 }
thestig800222e2016-05-26 22:00:29 -07002662
2663 CXFA_WidgetData* pWidgetData = GetWidgetData();
2664 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002665 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002666 return;
2667 }
2668
2669 CXFA_Node* pReturnNode = nullptr;
2670 if (argc == 0) {
2671 pReturnNode = pWidgetData->GetSelectedMember();
2672 } else {
2673 CFX_ByteString szName;
2674 szName = pArguments->GetUTF8String(0);
2675 pReturnNode = pWidgetData->SetSelectedMember(
2676 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2677 }
2678 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002679 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002680 return;
2681 }
dsinclairf27aeec2016-06-07 19:36:18 -07002682 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002683 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002684}
thestig800222e2016-05-26 22:00:29 -07002685
Dan Sinclair1770c022016-03-14 14:14:16 -04002686void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002687 if (pArguments->GetLength() != 0) {
2688 ThrowParamCountMismatchException(L"execInitialize");
2689 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002690 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002691
2692 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2693 if (!pNotify)
2694 return;
2695
2696 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002697}
dsinclair5b36f0a2016-07-19 10:56:23 -07002698
Dan Sinclair1770c022016-03-14 14:14:16 -04002699void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002700 if (pArguments->GetLength() != 0) {
2701 ThrowParamCountMismatchException(L"execCalculate");
2702 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002703 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002704
2705 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2706 if (!pNotify)
2707 return;
2708
2709 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002710}
dsinclair5b36f0a2016-07-19 10:56:23 -07002711
Dan Sinclair1770c022016-03-14 14:14:16 -04002712void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002713 if (pArguments->GetLength() != 0) {
2714 ThrowParamCountMismatchException(L"execValidate");
2715 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002716 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002717
2718 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2719 if (!pNotify) {
2720 pArguments->GetReturnValue()->SetBoolean(false);
2721 return;
2722 }
2723
2724 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2725 pArguments->GetReturnValue()->SetBoolean(
2726 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002727}
dsinclair5b36f0a2016-07-19 10:56:23 -07002728
dsinclair12a6b0c2016-05-26 11:14:08 -07002729void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002730 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002731 XFA_ATTRIBUTE eAttribute) {
2732 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002733 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002734 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002735 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002736 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2737 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002738 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002739 pManagerNode = pNode;
2740 break;
2741 }
2742 }
2743 if (pManagerNode) {
2744 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002745 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002746 if (!pNotify) {
2747 return;
2748 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002749 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002750 if (pToInstance &&
2751 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002752 pNotify->RunSubformIndexChange(pToInstance);
2753 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002754 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002755 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002756 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002757 pNotify->RunSubformIndexChange(pFromInstance);
2758 }
2759 }
2760 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002761 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002762 }
2763}
dsinclair5b36f0a2016-07-19 10:56:23 -07002764
dsinclair12a6b0c2016-05-26 11:14:08 -07002765void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002766 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002767 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002768 if (bSetting) {
2769 ThrowInvalidPropertyException();
2770 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002771 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002772
2773 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2774 CXFA_Node* pInstanceMgr = nullptr;
2775 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2776 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2777 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2778 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2779 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2780 wsInstMgrName.Mid(1) == wsName) {
2781 pInstanceMgr = pNode;
2782 }
2783 break;
2784 }
2785 }
2786 if (!pInstanceMgr) {
2787 pValue->SetNull();
2788 return;
2789 }
2790
2791 pValue->Assign(
2792 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
Dan Sinclair1770c022016-03-14 14:14:16 -04002793}
dsinclair5b36f0a2016-07-19 10:56:23 -07002794
dsinclair12a6b0c2016-05-26 11:14:08 -07002795void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002796 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002797 XFA_ATTRIBUTE eAttribute) {
2798 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002799 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002800 } else {
2801 CFX_WideString wsLocaleName;
2802 GetLocaleName(wsLocaleName);
Tom Sepezf0b65542017-02-13 10:26:01 -08002803 pValue->SetString(wsLocaleName.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002804 }
2805}
dsinclair5b36f0a2016-07-19 10:56:23 -07002806
Dan Sinclair1770c022016-03-14 14:14:16 -04002807void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002808 if (pArguments->GetLength() != 1) {
2809 ThrowParamCountMismatchException(L"execEvent");
2810 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002811 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002812
2813 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2814 execSingleEventByName(
2815 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2816 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002817}
dsinclair5b36f0a2016-07-19 10:56:23 -07002818
Dan Sinclair1770c022016-03-14 14:14:16 -04002819void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002820 if (pArguments->GetLength() != 0) {
2821 ThrowParamCountMismatchException(L"execInitialize");
2822 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002823 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002824
2825 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2826 if (!pNotify)
2827 return;
2828
2829 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002830}
dsinclair5b36f0a2016-07-19 10:56:23 -07002831
Dan Sinclair1770c022016-03-14 14:14:16 -04002832void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002833 if (pArguments->GetLength() != 0) {
2834 ThrowParamCountMismatchException(L"execCalculate");
2835 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002836 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002837
2838 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2839 if (!pNotify)
2840 return;
2841
2842 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002843}
dsinclair5b36f0a2016-07-19 10:56:23 -07002844
Dan Sinclair1770c022016-03-14 14:14:16 -04002845void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002846 if (pArguments->GetLength() != 0) {
2847 ThrowParamCountMismatchException(L"execValidate");
2848 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002849 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002850
2851 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2852 if (!pNotify) {
2853 pArguments->GetReturnValue()->SetBoolean(false);
2854 return;
2855 }
2856
2857 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2858 pArguments->GetReturnValue()->SetBoolean(
2859 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002860}
dsinclair5b36f0a2016-07-19 10:56:23 -07002861
Dan Sinclair1770c022016-03-14 14:14:16 -04002862void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002863 if (pArguments->GetLength() != 0)
2864 ThrowParamCountMismatchException(L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002865}
dsinclair5b36f0a2016-07-19 10:56:23 -07002866
Dan Sinclair1770c022016-03-14 14:14:16 -04002867int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2868 int32_t index = 0;
2869 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2870 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002871 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2872 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002873 index++;
2874 } else {
2875 break;
2876 }
2877 }
2878 return index;
2879}
dsinclair5b36f0a2016-07-19 10:56:23 -07002880
Dan Sinclair1770c022016-03-14 14:14:16 -04002881void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002882 if (pArguments->GetLength() != 1) {
2883 ThrowParamCountMismatchException(L"formNodes");
2884 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002885 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002886 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002887}
dsinclair5b36f0a2016-07-19 10:56:23 -07002888
Dan Sinclair1770c022016-03-14 14:14:16 -04002889void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002890 if (pArguments->GetLength() != 0) {
2891 ThrowParamCountMismatchException(L"remerge");
2892 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002893 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002894 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002895}
dsinclair5b36f0a2016-07-19 10:56:23 -07002896
Dan Sinclair1770c022016-03-14 14:14:16 -04002897void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002898 if (pArguments->GetLength() != 0) {
2899 ThrowParamCountMismatchException(L"execInitialize");
2900 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002901 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002902
2903 CXFA_WidgetData* pWidgetData = GetWidgetData();
2904 if (!pWidgetData) {
2905 pArguments->GetReturnValue()->SetBoolean(false);
2906 return;
2907 }
2908 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002909}
dsinclair5b36f0a2016-07-19 10:56:23 -07002910
Dan Sinclair1770c022016-03-14 14:14:16 -04002911void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2912 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002913 if (argc <= 0 || argc >= 4) {
2914 ThrowParamCountMismatchException(L"createNode");
2915 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002916 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002917
2918 CFX_WideString strName;
2919 CFX_WideString strNameSpace;
2920 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
2921 CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
2922 if (argc > 1) {
2923 CFX_ByteString bsName = pArguments->GetUTF8String(1);
2924 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
2925 if (argc == 3) {
2926 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
2927 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
2928 }
2929 }
2930
2931 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2932 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
2933 if (!pNewNode) {
2934 pArguments->GetReturnValue()->SetNull();
2935 return;
2936 }
2937
2938 if (strName.IsEmpty()) {
2939 pArguments->GetReturnValue()->Assign(
2940 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2941 return;
2942 }
2943
2944 if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2945 XFA_XDPPACKET_UNKNOWN)) {
2946 ThrowMissingPropertyException(strTagName, L"name");
2947 return;
2948 }
2949
2950 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
2951 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets)
2952 pNewNode->CreateXMLMappingNode();
2953
2954 pArguments->GetReturnValue()->Assign(
2955 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002956}
dsinclair5b36f0a2016-07-19 10:56:23 -07002957
Dan Sinclair1770c022016-03-14 14:14:16 -04002958void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002959 if (pArguments->GetLength() != 1) {
2960 ThrowParamCountMismatchException(L"recalculate");
2961 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002962 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002963 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002964}
dsinclair5b36f0a2016-07-19 10:56:23 -07002965
Dan Sinclair1770c022016-03-14 14:14:16 -04002966void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002967 if (pArguments->GetLength() != 0) {
2968 ThrowParamCountMismatchException(L"execCalculate");
2969 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002970 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002971
2972 CXFA_WidgetData* pWidgetData = GetWidgetData();
2973 if (!pWidgetData) {
2974 pArguments->GetReturnValue()->SetBoolean(false);
2975 return;
2976 }
2977 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002978}
dsinclair5b36f0a2016-07-19 10:56:23 -07002979
Dan Sinclair1770c022016-03-14 14:14:16 -04002980void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002981 if (pArguments->GetLength() != 0) {
2982 ThrowParamCountMismatchException(L"execValidate");
2983 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002984 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002985 CXFA_WidgetData* pWidgetData = GetWidgetData();
2986 if (!pWidgetData) {
2987 pArguments->GetReturnValue()->SetBoolean(false);
2988 return;
2989 }
2990 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002991}
dsinclair5b36f0a2016-07-19 10:56:23 -07002992
Dan Sinclair1770c022016-03-14 14:14:16 -04002993void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002994 if (pArguments->GetLength() != 0) {
2995 ThrowParamCountMismatchException(L"evaluate");
2996 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002997 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002998
2999 CXFA_WidgetData* pWidgetData = GetWidgetData();
3000 if (!pWidgetData) {
3001 pArguments->GetReturnValue()->SetBoolean(false);
3002 return;
3003 }
3004 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003005}
dsinclair5b36f0a2016-07-19 10:56:23 -07003006
dsinclair12a6b0c2016-05-26 11:14:08 -07003007void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003008 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003009 XFA_ATTRIBUTE eAttribute) {
3010 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003011 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003012 return;
3013 }
3014 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003015 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003016}
dsinclair5b36f0a2016-07-19 10:56:23 -07003017
dsinclair12a6b0c2016-05-26 11:14:08 -07003018void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003019 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003020 XFA_ATTRIBUTE eAttribute) {
3021 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003022 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003023 return;
3024 }
3025 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003026 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003027}
tsepezaadedf92016-05-12 10:08:06 -07003028
dsinclair12a6b0c2016-05-26 11:14:08 -07003029void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003030 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003031 XFA_ATTRIBUTE eAttribute) {
3032 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003033 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003034 InstanceManager_SetInstances(iDesired);
3035 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07003036 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04003037 }
3038}
dsinclair5b36f0a2016-07-19 10:56:23 -07003039
Dan Sinclair1770c022016-03-14 14:14:16 -04003040void CXFA_Node::Script_InstanceManager_MoveInstance(
3041 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003042 if (pArguments->GetLength() != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003043 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003044 return;
3045 }
3046 int32_t iFrom = pArguments->GetInt32(0);
3047 int32_t iTo = pArguments->GetInt32(1);
3048 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003049 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003050 if (!pNotify) {
3051 return;
3052 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003053 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003054 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003055 pNotify->RunSubformIndexChange(pToInstance);
3056 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003057 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003058 if (pFromInstance &&
3059 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003060 pNotify->RunSubformIndexChange(pFromInstance);
3061 }
3062}
dsinclair5b36f0a2016-07-19 10:56:23 -07003063
Dan Sinclair1770c022016-03-14 14:14:16 -04003064void CXFA_Node::Script_InstanceManager_RemoveInstance(
3065 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003066 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003067 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003068 return;
3069 }
3070 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003071 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003072 if (iIndex < 0 || iIndex >= iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003073 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003074 return;
3075 }
3076 CXFA_Occur nodeOccur(GetOccurNode());
3077 int32_t iMin = nodeOccur.GetMin();
3078 if (iCount - 1 < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003079 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003080 return;
3081 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003082 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3083 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003084 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003085 if (pNotify) {
3086 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003087 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003088 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003089 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003090 pNotify->RunSubformIndexChange(pSubformInstance);
3091 }
3092 }
3093 }
3094 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3095 if (!pLayoutPro) {
3096 return;
3097 }
3098 pLayoutPro->AddChangedContainer(
3099 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3100}
dsinclair5b36f0a2016-07-19 10:56:23 -07003101
Dan Sinclair1770c022016-03-14 14:14:16 -04003102void CXFA_Node::Script_InstanceManager_SetInstances(
3103 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003104 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003105 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003106 return;
3107 }
3108 int32_t iDesired = pArguments->GetInt32(0);
3109 InstanceManager_SetInstances(iDesired);
3110}
dsinclair5b36f0a2016-07-19 10:56:23 -07003111
Dan Sinclair1770c022016-03-14 14:14:16 -04003112void CXFA_Node::Script_InstanceManager_AddInstance(
3113 CFXJSE_Arguments* pArguments) {
3114 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003115 if (argc != 0 && argc != 1) {
3116 ThrowParamCountMismatchException(L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003117 return;
3118 }
tsepezd19e9122016-11-02 15:43:18 -07003119 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003120 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003121 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003122 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003123 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003124 CXFA_Occur nodeOccur(GetOccurNode());
3125 int32_t iMax = nodeOccur.GetMax();
3126 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003127 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003128 return;
3129 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003130 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003131 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003132 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003133 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003134 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003135 if (!pNotify) {
3136 return;
3137 }
3138 pNotify->RunNodeInitialize(pNewInstance);
3139 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3140 if (!pLayoutPro) {
3141 return;
3142 }
3143 pLayoutPro->AddChangedContainer(
3144 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3145}
dsinclair5b36f0a2016-07-19 10:56:23 -07003146
Dan Sinclair1770c022016-03-14 14:14:16 -04003147void CXFA_Node::Script_InstanceManager_InsertInstance(
3148 CFXJSE_Arguments* pArguments) {
3149 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003150 if (argc != 1 && argc != 2) {
3151 ThrowParamCountMismatchException(L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003152 return;
3153 }
3154 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003155 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003156 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003157 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003158 }
3159 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003160 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003161 if (iIndex < 0 || iIndex > iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003162 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003163 return;
3164 }
3165 int32_t iMax = nodeOccur.GetMax();
3166 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003167 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003168 return;
3169 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003170 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003171 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003172 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003173 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003174 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003175 if (!pNotify) {
3176 return;
3177 }
3178 pNotify->RunNodeInitialize(pNewInstance);
3179 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3180 if (!pLayoutPro) {
3181 return;
3182 }
3183 pLayoutPro->AddChangedContainer(
3184 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3185}
dsinclair5b36f0a2016-07-19 10:56:23 -07003186
Dan Sinclair1770c022016-03-14 14:14:16 -04003187int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3188 CXFA_Occur nodeOccur(GetOccurNode());
3189 int32_t iMax = nodeOccur.GetMax();
3190 int32_t iMin = nodeOccur.GetMin();
3191 if (iDesired < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003192 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003193 return 1;
3194 }
3195 if ((iMax >= 0) && (iDesired > iMax)) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003196 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003197 return 2;
3198 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003199 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003200 if (iDesired == iCount) {
3201 return 0;
3202 }
3203 if (iDesired < iCount) {
3204 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003205 CFX_WideString wsInstanceName =
3206 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3207 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003208 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003209 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003210 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003211 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003212 while (iCount > iDesired) {
3213 CXFA_Node* pRemoveInstance =
3214 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003215 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3216 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003217 continue;
3218 }
dsinclair070fcdf2016-06-22 22:04:54 -07003219 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003220 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003221 break;
3222 }
3223 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003224 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003225 iCount--;
3226 }
3227 }
3228 } else if (iDesired > iCount) {
3229 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003230 CXFA_Node* pNewInstance = CreateInstance(this, true);
3231 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003232 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003233 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003234 if (!pNotify) {
3235 return 0;
3236 }
3237 pNotify->RunNodeInitialize(pNewInstance);
3238 }
3239 }
3240 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3241 if (pLayoutPro) {
3242 pLayoutPro->AddChangedContainer(
3243 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3244 }
3245 return 0;
3246}
dsinclair5b36f0a2016-07-19 10:56:23 -07003247
Dan Sinclair1770c022016-03-14 14:14:16 -04003248int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003249 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003250 if (iFrom > iCount || iTo > iCount - 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003251 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003252 return 1;
3253 }
3254 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3255 return 0;
3256 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003257 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003258 RemoveItem(this, pMoveInstance, false);
3259 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003260 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3261 if (pLayoutPro) {
3262 pLayoutPro->AddChangedContainer(
3263 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3264 }
3265 return 0;
3266}
dsinclair5b36f0a2016-07-19 10:56:23 -07003267
dsinclair12a6b0c2016-05-26 11:14:08 -07003268void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003269 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003270 XFA_ATTRIBUTE eAttribute) {
3271 CXFA_Occur occur(this);
3272 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003273 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003274 occur.SetMax(iMax);
3275 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003276 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003277 }
3278}
dsinclair5b36f0a2016-07-19 10:56:23 -07003279
dsinclair12a6b0c2016-05-26 11:14:08 -07003280void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003281 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003282 XFA_ATTRIBUTE eAttribute) {
3283 CXFA_Occur occur(this);
3284 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003285 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003286 occur.SetMin(iMin);
3287 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003288 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003289 }
3290}
dsinclair5b36f0a2016-07-19 10:56:23 -07003291
Dan Sinclair1770c022016-03-14 14:14:16 -04003292void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3293 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003294 if (argc != 0 && argc != 1) {
3295 ThrowParamCountMismatchException(L"metadata");
3296 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003297 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003298 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003299}
dsinclair5b36f0a2016-07-19 10:56:23 -07003300
Dan Sinclair1770c022016-03-14 14:14:16 -04003301void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003302 if (pArguments->GetLength() != 1) {
3303 ThrowParamCountMismatchException(L"formNodes");
3304 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003305 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003306
3307 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3308 if (!pDataNode) {
3309 ThrowArgumentMismatchException();
3310 return;
3311 }
3312
3313 CXFA_NodeArray formItems;
3314 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3315 pFormNodes->SetArrayNodeList(formItems);
3316 pArguments->GetReturnValue()->SetObject(
3317 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003318}
dsinclair5b36f0a2016-07-19 10:56:23 -07003319
Dan Sinclair1770c022016-03-14 14:14:16 -04003320void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003321 if (pArguments->GetLength() != 0) {
3322 ThrowParamCountMismatchException(L"remerge");
3323 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003324 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003325
3326 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003327}
dsinclair5b36f0a2016-07-19 10:56:23 -07003328
Dan Sinclair1770c022016-03-14 14:14:16 -04003329void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003330 if (pArguments->GetLength() != 0) {
3331 ThrowParamCountMismatchException(L"execInitialize");
3332 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003333 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003334
3335 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3336 if (!pNotify)
3337 return;
3338
3339 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04003340}
dsinclair5b36f0a2016-07-19 10:56:23 -07003341
Dan Sinclair1770c022016-03-14 14:14:16 -04003342void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3343 CXFA_EventParam* pEventParam =
3344 m_pDocument->GetScriptContext()->GetEventParam();
3345 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3346 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3347 return;
3348 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003349 if (pArguments->GetLength() != 1) {
3350 ThrowParamCountMismatchException(L"recalculate");
3351 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003352 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003353
3354 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3355 if (!pNotify)
3356 return;
3357 if (pArguments->GetInt32(0) != 0)
3358 return;
3359
3360 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3361 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3362 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003363}
dsinclair5b36f0a2016-07-19 10:56:23 -07003364
Dan Sinclair1770c022016-03-14 14:14:16 -04003365void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003366 if (pArguments->GetLength() != 0) {
3367 ThrowParamCountMismatchException(L"execCalculate");
3368 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003369 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003370
3371 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3372 if (!pNotify)
3373 return;
3374
3375 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04003376}
dsinclair5b36f0a2016-07-19 10:56:23 -07003377
Dan Sinclair1770c022016-03-14 14:14:16 -04003378void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003379 if (pArguments->GetLength() != 0) {
3380 ThrowParamCountMismatchException(L"execValidate");
3381 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003382 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003383
3384 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3385 if (!pNotify) {
3386 pArguments->GetReturnValue()->SetBoolean(false);
3387 return;
3388 }
3389
3390 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3391 pArguments->GetReturnValue()->SetBoolean(
3392 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003393}
dsinclair5b36f0a2016-07-19 10:56:23 -07003394
dsinclair12a6b0c2016-05-26 11:14:08 -07003395void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003396 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003397 XFA_ATTRIBUTE eAttribute) {
3398 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003399 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003400 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003401 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003402 CFX_WideString wsChecksum;
3403 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
Tom Sepezf0b65542017-02-13 10:26:01 -08003404 pValue->SetString(wsChecksum.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003405}
dsinclair5b36f0a2016-07-19 10:56:23 -07003406
Dan Sinclair1770c022016-03-14 14:14:16 -04003407void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003408 if (pArguments->GetLength() != 1) {
3409 ThrowParamCountMismatchException(L"getAttribute");
3410 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003411 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003412 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3413 CFX_WideString wsAttributeValue;
3414 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3415 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3416 static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3417 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(),
3418 wsAttributeValue);
3419 }
3420 pArguments->GetReturnValue()->SetString(
Tom Sepezf0b65542017-02-13 10:26:01 -08003421 wsAttributeValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003422}
dsinclair5b36f0a2016-07-19 10:56:23 -07003423
Dan Sinclair1770c022016-03-14 14:14:16 -04003424void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003425 if (pArguments->GetLength() != 2) {
3426 ThrowParamCountMismatchException(L"setAttribute");
3427 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003428 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003429 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3430 CFX_ByteString bsName = pArguments->GetUTF8String(1);
3431 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3432 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3433 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(
3434 CFX_WideString::FromUTF8(bsName.AsStringC()),
3435 CFX_WideString::FromUTF8(bsValue.AsStringC()));
3436 }
3437 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003438}
dsinclair5b36f0a2016-07-19 10:56:23 -07003439
Dan Sinclair1770c022016-03-14 14:14:16 -04003440void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003441 if (pArguments->GetLength() != 1) {
3442 ThrowParamCountMismatchException(L"removeAttribute");
3443 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003444 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003445
3446 CFX_ByteString bsName = pArguments->GetUTF8String(0);
3447 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
3448 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3449 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3450 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
3451 if (pXMLElement->HasAttribute(wsName.c_str())) {
3452 pXMLElement->RemoveAttribute(wsName.c_str());
3453 }
3454 }
3455 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003456}
dsinclair5b36f0a2016-07-19 10:56:23 -07003457
dsinclair12a6b0c2016-05-26 11:14:08 -07003458void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003459 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003460 XFA_ATTRIBUTE eAttribute) {
3461 if (bSetting) {
dsinclairae95f762016-03-29 16:58:29 -07003462 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003463 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003464 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003465 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003466 }
3467 } else {
3468 CFX_WideString wsTextData;
dsinclairae95f762016-03-29 16:58:29 -07003469 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003470 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003471 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04003472 pXMLElement->GetTextData(wsTextData);
3473 }
Tom Sepezf0b65542017-02-13 10:26:01 -08003474 pValue->SetString(wsTextData.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003475 }
3476}
dsinclair5b36f0a2016-07-19 10:56:23 -07003477
Dan Sinclair1770c022016-03-14 14:14:16 -04003478void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003479 if (pArguments->GetLength() != 0)
3480 ThrowParamCountMismatchException(L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003481}
dsinclair5b36f0a2016-07-19 10:56:23 -07003482
Dan Sinclair1770c022016-03-14 14:14:16 -04003483void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003484 if (pArguments->GetLength() != 0)
3485 ThrowParamCountMismatchException(L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003486}
dsinclair5b36f0a2016-07-19 10:56:23 -07003487
Dan Sinclair1770c022016-03-14 14:14:16 -04003488void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003489 if (pArguments->GetLength() != 0)
3490 ThrowParamCountMismatchException(L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003491}
dsinclair5b36f0a2016-07-19 10:56:23 -07003492
Dan Sinclair1770c022016-03-14 14:14:16 -04003493void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003494 if (pArguments->GetLength() != 0)
3495 ThrowParamCountMismatchException(L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003496}
dsinclair5b36f0a2016-07-19 10:56:23 -07003497
Dan Sinclair1770c022016-03-14 14:14:16 -04003498void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003499 if (pArguments->GetLength() != 0)
3500 ThrowParamCountMismatchException(L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003501}
dsinclair5b36f0a2016-07-19 10:56:23 -07003502
Dan Sinclair1770c022016-03-14 14:14:16 -04003503void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003504 if (pArguments->GetLength() != 0)
3505 ThrowParamCountMismatchException(L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003506}
dsinclair5b36f0a2016-07-19 10:56:23 -07003507
Dan Sinclair1770c022016-03-14 14:14:16 -04003508void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003509 if (pArguments->GetLength() != 0)
3510 ThrowParamCountMismatchException(L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003511}
dsinclair5b36f0a2016-07-19 10:56:23 -07003512
Dan Sinclair1770c022016-03-14 14:14:16 -04003513void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003514 if (pArguments->GetLength() != 0)
3515 ThrowParamCountMismatchException(L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003516}
dsinclair5b36f0a2016-07-19 10:56:23 -07003517
Dan Sinclair1770c022016-03-14 14:14:16 -04003518void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003519 if (pArguments->GetLength() != 0)
3520 ThrowParamCountMismatchException(L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003521}
dsinclair5b36f0a2016-07-19 10:56:23 -07003522
Dan Sinclair1770c022016-03-14 14:14:16 -04003523void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003524 if (pArguments->GetLength() != 0)
3525 ThrowParamCountMismatchException(L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003526}
dsinclair5b36f0a2016-07-19 10:56:23 -07003527
Dan Sinclair1770c022016-03-14 14:14:16 -04003528void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003529 if (pArguments->GetLength() != 0)
3530 ThrowParamCountMismatchException(L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003531}
dsinclair5b36f0a2016-07-19 10:56:23 -07003532
Dan Sinclair1770c022016-03-14 14:14:16 -04003533void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003534 if (pArguments->GetLength() != 0)
3535 ThrowParamCountMismatchException(L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003536}
dsinclair5b36f0a2016-07-19 10:56:23 -07003537
Dan Sinclair1770c022016-03-14 14:14:16 -04003538void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003539 if (pArguments->GetLength() != 0)
3540 ThrowParamCountMismatchException(L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003541}
dsinclair5b36f0a2016-07-19 10:56:23 -07003542
Dan Sinclair1770c022016-03-14 14:14:16 -04003543void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003544 if (pArguments->GetLength() != 0)
3545 ThrowParamCountMismatchException(L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003546}
dsinclair5b36f0a2016-07-19 10:56:23 -07003547
Dan Sinclair1770c022016-03-14 14:14:16 -04003548void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003549 if (pArguments->GetLength() != 0)
3550 ThrowParamCountMismatchException(L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003551}
dsinclair5b36f0a2016-07-19 10:56:23 -07003552
Dan Sinclair1770c022016-03-14 14:14:16 -04003553void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003554 if (pArguments->GetLength() != 0)
3555 ThrowParamCountMismatchException(L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003556}
dsinclair5b36f0a2016-07-19 10:56:23 -07003557
Dan Sinclair1770c022016-03-14 14:14:16 -04003558void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003559 if (pArguments->GetLength() != 0)
3560 ThrowParamCountMismatchException(L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003561}
dsinclair5b36f0a2016-07-19 10:56:23 -07003562
dsinclair12a6b0c2016-05-26 11:14:08 -07003563void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003564 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003565 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003566
dsinclair12a6b0c2016-05-26 11:14:08 -07003567void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003568 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003569 XFA_ATTRIBUTE eAttribute) {
3570 if (!bSetting) {
3571 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003572 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003573 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003574 }
3575}
dsinclair5b36f0a2016-07-19 10:56:23 -07003576
dsinclair12a6b0c2016-05-26 11:14:08 -07003577void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003578 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003579 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003580
dsinclair12a6b0c2016-05-26 11:14:08 -07003581void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003582 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003583 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003584
dsinclair12a6b0c2016-05-26 11:14:08 -07003585void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003586 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003587 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003588
dsinclair12a6b0c2016-05-26 11:14:08 -07003589void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003590 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003591 XFA_ATTRIBUTE eAttribute) {
3592 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003593 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003594 return;
3595 }
dan sinclair65c7c232017-02-02 14:05:30 -08003596 pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003597}
dsinclair5b36f0a2016-07-19 10:56:23 -07003598
dsinclair12a6b0c2016-05-26 11:14:08 -07003599void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003600 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003601 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003602
tsepezd19e9122016-11-02 15:43:18 -07003603bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003604 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003605 return HasMapModuleKey(pKey, bCanInherit);
3606}
dsinclair5b36f0a2016-07-19 10:56:23 -07003607
tsepezd19e9122016-11-02 15:43:18 -07003608bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3609 const CFX_WideStringC& wsValue,
3610 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003611 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003612 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003613 return false;
weili44f8faf2016-06-01 14:03:56 -07003614
Dan Sinclair1770c022016-03-14 14:14:16 -04003615 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3616 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3617 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003618 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003619 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3620 }
3621 switch (eType) {
3622 case XFA_ATTRIBUTETYPE_Enum: {
3623 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3624 return SetEnum(pAttr->eName,
3625 pEnum ? pEnum->eName
3626 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3627 bNotify);
3628 } break;
3629 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003630 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003631 case XFA_ATTRIBUTETYPE_Boolean:
dan sinclair65c7c232017-02-02 14:05:30 -08003632 return SetBoolean(pAttr->eName, wsValue != L"0", bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003633 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003634 return SetInteger(pAttr->eName,
3635 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3636 wsValue.GetLength(), nullptr)),
3637 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003638 case XFA_ATTRIBUTETYPE_Measure:
3639 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3640 default:
3641 break;
3642 }
tsepezd19e9122016-11-02 15:43:18 -07003643 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003644}
dsinclair5b36f0a2016-07-19 10:56:23 -07003645
tsepezd19e9122016-11-02 15:43:18 -07003646bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3647 CFX_WideString& wsValue,
3648 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003649 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003650 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003651 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003652 }
3653 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3654 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3655 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003656 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003657 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3658 }
3659 switch (eType) {
3660 case XFA_ATTRIBUTETYPE_Enum: {
3661 XFA_ATTRIBUTEENUM eValue;
3662 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003663 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003664 }
dsinclair9eb0db12016-07-21 12:01:39 -07003665 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003666 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003667 } break;
3668 case XFA_ATTRIBUTETYPE_Cdata: {
3669 CFX_WideStringC wsValueC;
3670 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003671 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003672 }
3673 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003674 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003675 } break;
3676 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003677 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003678 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003679 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003680 }
dan sinclair65c7c232017-02-02 14:05:30 -08003681 wsValue = bValue ? L"1" : L"0";
tsepezd19e9122016-11-02 15:43:18 -07003682 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003683 } break;
3684 case XFA_ATTRIBUTETYPE_Integer: {
3685 int32_t iValue;
3686 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003687 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003688 }
3689 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003690 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003691 } break;
3692 case XFA_ATTRIBUTETYPE_Measure: {
3693 CXFA_Measurement mValue;
3694 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003695 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003696 }
3697 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003698 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003699 } break;
3700 default:
3701 break;
3702 }
tsepezd19e9122016-11-02 15:43:18 -07003703 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003704}
dsinclair5b36f0a2016-07-19 10:56:23 -07003705
tsepezd19e9122016-11-02 15:43:18 -07003706bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3707 const CFX_WideStringC& wsValue,
3708 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003709 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3710 if (pAttributeInfo) {
3711 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3712 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003713 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003714 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003715 return true;
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(const CFX_WideStringC& wsAttr,
3719 CFX_WideString& wsValue,
3720 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003721 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3722 if (pAttributeInfo) {
3723 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3724 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003725 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003726 CFX_WideStringC wsValueC;
3727 if (GetMapModuleString(pKey, wsValueC)) {
3728 wsValue = wsValueC;
3729 }
tsepezd19e9122016-11-02 15:43:18 -07003730 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003731}
dsinclair5b36f0a2016-07-19 10:56:23 -07003732
tsepezd19e9122016-11-02 15:43:18 -07003733bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003734 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003735 RemoveMapModuleKey(pKey);
tsepezd19e9122016-11-02 15:43:18 -07003736 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003737}
dsinclair5b36f0a2016-07-19 10:56:23 -07003738
tsepezd19e9122016-11-02 15:43:18 -07003739bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3740 bool& bValue,
3741 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003742 void* pValue = nullptr;
3743 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003744 return false;
tsepez478ed622016-10-27 14:32:33 -07003745 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003746 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003747}
dsinclair5b36f0a2016-07-19 10:56:23 -07003748
tsepezd19e9122016-11-02 15:43:18 -07003749bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3750 int32_t& iValue,
3751 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003752 void* pValue = nullptr;
3753 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003754 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003755 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003756 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003757}
dsinclair5b36f0a2016-07-19 10:56:23 -07003758
tsepezd19e9122016-11-02 15:43:18 -07003759bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3760 XFA_ATTRIBUTEENUM& eValue,
3761 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003762 void* pValue = nullptr;
3763 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003764 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003765 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003766 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003767}
thestigb1a59592016-04-14 18:29:56 -07003768
tsepezd19e9122016-11-02 15:43:18 -07003769bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3770 CXFA_Measurement mValue,
3771 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003772 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003773 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003774 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003775 OnChanged(eAttr, bNotify, false);
3776 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003777}
thestigb1a59592016-04-14 18:29:56 -07003778
tsepezd19e9122016-11-02 15:43:18 -07003779bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3780 CXFA_Measurement& mValue,
3781 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003782 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003783 void* pValue;
3784 int32_t iBytes;
3785 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
3786 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003787 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003788 }
3789 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003790 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003791 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
3792 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003793 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003794 }
tsepezd19e9122016-11-02 15:43:18 -07003795 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003796}
3797
3798CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3799 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003800 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003801}
3802
tsepezd19e9122016-11-02 15:43:18 -07003803bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3804 const CFX_WideString& wsValue,
3805 bool bNotify,
3806 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003807 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003808 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003809 if (eAttr == XFA_ATTRIBUTE_Value) {
3810 CFX_WideString* pClone = new CFX_WideString(wsValue);
3811 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3812 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003813 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003814 if (eAttr == XFA_ATTRIBUTE_Name)
3815 UpdateNameHash();
3816 }
thestigb1a59592016-04-14 18:29:56 -07003817 OnChanged(eAttr, bNotify, bScriptModify);
3818
3819 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3820 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003821 return true;
thestigb1a59592016-04-14 18:29:56 -07003822 }
3823
dsinclair070fcdf2016-06-22 22:04:54 -07003824 if (eAttr == XFA_ATTRIBUTE_Name &&
3825 (m_elementType == XFA_Element::DataValue ||
3826 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003827 return true;
thestigb1a59592016-04-14 18:29:56 -07003828 }
3829
3830 if (eAttr == XFA_ATTRIBUTE_Value) {
3831 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3832 switch (eXMLType) {
3833 case FDE_XMLNODE_Element:
3834 if (IsAttributeInXML()) {
3835 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003836 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3837 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003838 } else {
tsepezd19e9122016-11-02 15:43:18 -07003839 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003840 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3841 for (CXFA_Node* pChildDataNode =
3842 GetNodeItem(XFA_NODEITEM_FirstChild);
3843 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3844 XFA_NODEITEM_NextSibling)) {
3845 CXFA_NodeArray formNodes;
3846 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003847 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003848 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003849 }
3850 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003851 }
thestigb1a59592016-04-14 18:29:56 -07003852 if (bDeleteChildren) {
3853 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3854 }
3855 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3856 }
3857 break;
3858 case FDE_XMLNODE_Text:
3859 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3860 break;
3861 default:
dsinclair43854a52016-04-27 12:26:00 -07003862 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003863 }
tsepezd19e9122016-11-02 15:43:18 -07003864 return true;
thestigb1a59592016-04-14 18:29:56 -07003865 }
3866
3867 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3868 if (pInfo) {
dsinclair43854a52016-04-27 12:26:00 -07003869 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003870 CFX_WideString wsAttrName = pInfo->pName;
3871 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
dan sinclair65c7c232017-02-02 14:05:30 -08003872 wsAttrName = L"xfa:" + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003873 }
thestigb1a59592016-04-14 18:29:56 -07003874 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003875 }
tsepezd19e9122016-11-02 15:43:18 -07003876 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003877}
thestigb1a59592016-04-14 18:29:56 -07003878
tsepezd19e9122016-11-02 15:43:18 -07003879bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3880 const CFX_WideString& wsXMLValue,
3881 bool bNotify,
3882 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003883 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003884 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003885 CFX_WideString* pClone = new CFX_WideString(wsValue);
3886 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003887 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003888 if (IsNeedSavingXMLNode()) {
3889 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3890 switch (eXMLType) {
3891 case FDE_XMLNODE_Element:
3892 if (IsAttributeInXML()) {
dsinclairae95f762016-03-29 16:58:29 -07003893 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003894 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3895 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003896 } else {
tsepezd19e9122016-11-02 15:43:18 -07003897 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003898 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3899 for (CXFA_Node* pChildDataNode =
3900 GetNodeItem(XFA_NODEITEM_FirstChild);
3901 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3902 XFA_NODEITEM_NextSibling)) {
3903 CXFA_NodeArray formNodes;
3904 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003905 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003906 break;
3907 }
3908 }
3909 }
3910 if (bDeleteChildren) {
dsinclairae95f762016-03-29 16:58:29 -07003911 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003912 }
dsinclairae95f762016-03-29 16:58:29 -07003913 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003914 }
3915 break;
3916 case FDE_XMLNODE_Text:
dsinclairae95f762016-03-29 16:58:29 -07003917 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003918 break;
3919 default:
dsinclair43854a52016-04-27 12:26:00 -07003920 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003921 }
3922 }
tsepezd19e9122016-11-02 15:43:18 -07003923 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003924}
dsinclair5b36f0a2016-07-19 10:56:23 -07003925
tsepezd19e9122016-11-02 15:43:18 -07003926bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3927 CFX_WideString& wsValue,
3928 bool bUseDefault,
3929 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003930 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003931 if (eAttr == XFA_ATTRIBUTE_Value) {
3932 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3933 if (pStr) {
3934 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07003935 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003936 }
3937 } else {
3938 CFX_WideStringC wsValueC;
3939 if (GetMapModuleString(pKey, wsValueC)) {
3940 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003941 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003942 }
3943 }
3944 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003945 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003946 }
weili44f8faf2016-06-01 14:03:56 -07003947 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003948 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003949 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
3950 wsValue = (const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003951 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003952 }
tsepezd19e9122016-11-02 15:43:18 -07003953 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003954}
dsinclair5b36f0a2016-07-19 10:56:23 -07003955
tsepezd19e9122016-11-02 15:43:18 -07003956bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3957 CFX_WideStringC& wsValue,
3958 bool bUseDefault,
3959 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003960 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003961 if (eAttr == XFA_ATTRIBUTE_Value) {
3962 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3963 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07003964 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07003965 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003966 }
3967 } else {
3968 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003969 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003970 }
3971 }
3972 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003973 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003974 }
weili44f8faf2016-06-01 14:03:56 -07003975 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003976 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003977 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
3978 wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003979 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003980 }
tsepezd19e9122016-11-02 15:43:18 -07003981 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003982}
dsinclair5b36f0a2016-07-19 10:56:23 -07003983
tsepezd19e9122016-11-02 15:43:18 -07003984bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
3985 void* pData,
3986 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003987 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003988 return SetUserData(pKey, pData, pCallbackInfo);
3989}
dsinclair5b36f0a2016-07-19 10:56:23 -07003990
tsepezd19e9122016-11-02 15:43:18 -07003991bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003992 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003993 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07003994 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04003995}
dsinclair5b36f0a2016-07-19 10:56:23 -07003996
tsepezd19e9122016-11-02 15:43:18 -07003997bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
3998 XFA_ATTRIBUTETYPE eType,
3999 void* pValue,
4000 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004001 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07004002 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004003 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07004004 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004005 if (IsNeedSavingXMLNode()) {
dsinclair43854a52016-04-27 12:26:00 -07004006 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004007 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
4008 if (pInfo) {
4009 switch (eType) {
4010 case XFA_ATTRIBUTETYPE_Enum:
dsinclairae95f762016-03-29 16:58:29 -07004011 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004012 ->SetString(
4013 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07004014 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04004015 ->pName);
4016 break;
4017 case XFA_ATTRIBUTETYPE_Boolean:
dsinclairae95f762016-03-29 16:58:29 -07004018 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07004019 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04004020 break;
4021 case XFA_ATTRIBUTETYPE_Integer:
dsinclairae95f762016-03-29 16:58:29 -07004022 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004023 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue);
4024 break;
4025 default:
dsinclair43854a52016-04-27 12:26:00 -07004026 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04004027 }
4028 }
4029 }
tsepezd19e9122016-11-02 15:43:18 -07004030 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004031}
dsinclair5b36f0a2016-07-19 10:56:23 -07004032
tsepezd19e9122016-11-02 15:43:18 -07004033bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
4034 XFA_ATTRIBUTETYPE eType,
4035 bool bUseDefault,
4036 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004037 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004038 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004039 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004040 }
4041 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004042 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004043 }
dsinclair070fcdf2016-06-22 22:04:54 -07004044 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004045 m_ePacket);
4046}
dsinclair5b36f0a2016-07-19 10:56:23 -07004047
tsepezd19e9122016-11-02 15:43:18 -07004048bool CXFA_Node::SetUserData(void* pKey,
4049 void* pData,
4050 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004051 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4052 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004053 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004054}
dsinclair5b36f0a2016-07-19 10:56:23 -07004055
tsepezd19e9122016-11-02 15:43:18 -07004056bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004057 int32_t iBytes = 0;
4058 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004059 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004060 }
4061 return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes);
4062}
dsinclair5b36f0a2016-07-19 10:56:23 -07004063
tsepezd19e9122016-11-02 15:43:18 -07004064bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4065 const CFX_WideString& wsXMLValue,
4066 bool bNotify,
4067 bool bScriptModify,
4068 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004069 CXFA_Node* pNode = nullptr;
4070 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004071 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004072 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004073 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004074 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004075 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004076 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004077 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004078 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004079 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004080 CXFA_Node* pBind = GetBindData();
4081 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004082 std::vector<CFX_WideString> wsSaveTextArray;
Dan Sinclair1770c022016-03-14 14:14:16 -04004083 int32_t iSize = 0;
4084 if (!wsContent.IsEmpty()) {
4085 int32_t iStart = 0;
4086 int32_t iLength = wsContent.GetLength();
4087 int32_t iEnd = wsContent.Find(L'\n', iStart);
4088 iEnd = (iEnd == -1) ? iLength : iEnd;
4089 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004090 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004091 iStart = iEnd + 1;
4092 if (iStart >= iLength) {
4093 break;
4094 }
4095 iEnd = wsContent.Find(L'\n', iStart);
4096 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004097 wsSaveTextArray.push_back(
4098 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004099 }
4100 }
tsepez51709be2016-12-08 10:55:57 -08004101 iSize = pdfium::CollectionSize<int32_t>(wsSaveTextArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04004102 }
4103 if (iSize == 0) {
4104 while (CXFA_Node* pChildNode =
4105 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4106 pBind->RemoveChild(pChildNode);
4107 }
4108 } else {
4109 CXFA_NodeArray valueNodes;
4110 int32_t iDatas = pBind->GetNodeList(
dsinclair56a8b192016-06-21 14:15:25 -07004111 valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004112 if (iDatas < iSize) {
4113 int32_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004114 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004115 while (iAddNodes-- > 0) {
4116 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004117 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004118 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004119 pValueNodes->CreateXMLMappingNode();
4120 pBind->InsertChild(pValueNodes);
4121 }
weili44f8faf2016-06-01 14:03:56 -07004122 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004123 } else if (iDatas > iSize) {
4124 int32_t iDelNodes = iDatas - iSize;
4125 while (iDelNodes-- > 0) {
4126 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4127 }
4128 }
4129 int32_t i = 0;
4130 for (CXFA_Node* pValueNode =
4131 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4132 pValueNode; pValueNode = pValueNode->GetNodeItem(
4133 XFA_NODEITEM_NextSibling)) {
4134 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004135 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004136 i++;
4137 }
4138 }
4139 CXFA_NodeArray nodeArray;
4140 pBind->GetBindItems(nodeArray);
4141 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004142 if (nodeArray[i] != this) {
4143 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004144 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004145 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004146 }
4147 }
4148 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004149 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004150 pNode = this;
4151 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004152 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004153 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004154 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004155 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004156 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004157 }
4158 pBindNode = GetBindData();
4159 if (pBindNode && bSyncData) {
4160 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004161 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004162 CXFA_NodeArray nodeArray;
4163 pBindNode->GetBindItems(nodeArray);
4164 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004165 if (nodeArray[i] != this) {
4166 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true,
tsepezd19e9122016-11-02 15:43:18 -07004167 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004168 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004169 }
4170 }
weili44f8faf2016-06-01 14:03:56 -07004171 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004172 break;
4173 }
dsinclairc5a8f212016-06-20 11:11:12 -07004174 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004175 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004176 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004177 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004178 if (wsContentType == L"text/html") {
4179 wsContentType = L"";
tsepez4c3debb2016-04-08 12:20:38 -07004180 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004181 }
4182 }
4183 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4184 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004185 pContentRawDataNode = CreateSamePacketNode(
dan sinclair65c7c232017-02-02 14:05:30 -08004186 (wsContentType == L"text/xml") ? XFA_Element::Sharpxml
4187 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004188 InsertChild(pContentRawDataNode);
4189 }
4190 return pContentRawDataNode->SetScriptContent(
4191 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4192 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004193 case XFA_ObjectType::NodeC:
4194 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004195 pNode = this;
4196 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004197 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004198 pNode = this;
4199 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4200 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4201 if (pParent) {
4202 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4203 }
dsinclair070fcdf2016-06-22 22:04:54 -07004204 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004205 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4206 if (pParent && pParent->IsContainerNode()) {
4207 pBindNode = pParent->GetBindData();
4208 if (pBindNode) {
4209 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004210 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004211 }
4212 }
4213 }
4214 }
4215 break;
4216 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004217 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004218 pNode = this;
4219 pBindNode = this;
4220 }
4221 break;
4222 }
4223 if (pNode) {
4224 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4225 if (pBindNode && bSyncData) {
4226 CXFA_NodeArray nodeArray;
4227 pBindNode->GetBindItems(nodeArray);
4228 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004229 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004230 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004231 }
4232 }
tsepezd19e9122016-11-02 15:43:18 -07004233 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004234 }
tsepezd19e9122016-11-02 15:43:18 -07004235 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004236}
dsinclair5b36f0a2016-07-19 10:56:23 -07004237
tsepezd19e9122016-11-02 15:43:18 -07004238bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4239 const CFX_WideString& wsXMLValue,
4240 bool bNotify,
4241 bool bScriptModify,
4242 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004243 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4244 bSyncData);
4245}
dsinclair5b36f0a2016-07-19 10:56:23 -07004246
tsepezd19e9122016-11-02 15:43:18 -07004247CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004248 CFX_WideString wsContent;
4249 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4250}
dsinclair5b36f0a2016-07-19 10:56:23 -07004251
Dan Sinclair1770c022016-03-14 14:14:16 -04004252CFX_WideString CXFA_Node::GetContent() {
4253 return GetScriptContent();
4254}
dsinclair5b36f0a2016-07-19 10:56:23 -07004255
tsepezd19e9122016-11-02 15:43:18 -07004256bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4257 bool bScriptModify,
4258 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004259 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004260 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004261 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004262 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004263 pNode = this;
4264 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004265 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004266 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004267 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004268 }
4269 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4270 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
dan sinclair65c7c232017-02-02 14:05:30 -08004271 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004272 }
4273 return pChildValue
4274 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004275 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004276 }
4277 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004278 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004279 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4280 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004281 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004282 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004283 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004284 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004285 if (wsContentType == L"text/html") {
dsinclair56a8b192016-06-21 14:15:25 -07004286 element = XFA_Element::SharpxHTML;
dan sinclair65c7c232017-02-02 14:05:30 -08004287 } else if (wsContentType == L"text/xml") {
dsinclair56a8b192016-06-21 14:15:25 -07004288 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004289 }
4290 }
4291 pContentRawDataNode = CreateSamePacketNode(element);
4292 InsertChild(pContentRawDataNode);
4293 }
4294 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4295 }
dsinclairc5a8f212016-06-20 11:11:12 -07004296 case XFA_ObjectType::NodeC:
4297 case XFA_ObjectType::NodeV:
4298 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004299 pNode = this;
4300 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004301 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004302 pNode = this;
4303 }
4304 break;
4305 }
4306 if (pNode) {
4307 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004308 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004309 if (pScriptContext) {
4310 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4311 }
4312 }
tsepezd19e9122016-11-02 15:43:18 -07004313 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004314 }
tsepezd19e9122016-11-02 15:43:18 -07004315 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004316}
dsinclair5b36f0a2016-07-19 10:56:23 -07004317
Dan Sinclair1770c022016-03-14 14:14:16 -04004318CXFA_Node* CXFA_Node::GetModelNode() {
4319 switch (GetPacketID()) {
4320 case XFA_XDPPACKET_XDP:
4321 return m_pDocument->GetRoot();
4322 case XFA_XDPPACKET_Config:
4323 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4324 case XFA_XDPPACKET_Template:
4325 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4326 case XFA_XDPPACKET_Form:
4327 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4328 case XFA_XDPPACKET_Datasets:
4329 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4330 case XFA_XDPPACKET_LocaleSet:
4331 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4332 case XFA_XDPPACKET_ConnectionSet:
4333 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4334 case XFA_XDPPACKET_SourceSet:
4335 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4336 case XFA_XDPPACKET_Xdc:
4337 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4338 default:
4339 return this;
4340 }
4341}
dsinclair5b36f0a2016-07-19 10:56:23 -07004342
tsepezd19e9122016-11-02 15:43:18 -07004343bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004344 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004345 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
dsinclairae95f762016-03-29 16:58:29 -07004346 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004347 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004348 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004349 }
dsinclairae95f762016-03-29 16:58:29 -07004350 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004351 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004352 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
dsinclairae95f762016-03-29 16:58:29 -07004353 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004354 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004355 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004356 }
4357 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004358 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004359 }
dsinclair070fcdf2016-06-22 22:04:54 -07004360 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004361 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4362 return XFA_FDEExtension_ResolveNamespaceQualifier(
dsinclairae95f762016-03-29 16:58:29 -07004363 static_cast<CFDE_XMLElement*>(pXMLNode),
4364 GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004365 }
dsinclairae95f762016-03-29 16:58:29 -07004366 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004367 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004368 } else {
4369 CXFA_Node* pModelNode = GetModelNode();
4370 return pModelNode->TryNamespace(wsNamespace);
4371 }
4372}
dsinclair5b36f0a2016-07-19 10:56:23 -07004373
Dan Sinclair1770c022016-03-14 14:14:16 -04004374CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004375 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004376 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004377 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004378 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004379 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004380 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004381 if (!pProperty || index >= pProperty->uOccur)
4382 return nullptr;
4383
Dan Sinclair1770c022016-03-14 14:14:16 -04004384 CXFA_Node* pNode = m_pChild;
4385 int32_t iCount = 0;
4386 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004387 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004388 iCount++;
4389 if (iCount > index) {
4390 return pNode;
4391 }
4392 }
4393 }
weili44f8faf2016-06-01 14:03:56 -07004394 if (!bCreateProperty)
4395 return nullptr;
4396
Dan Sinclair1770c022016-03-14 14:14:16 -04004397 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4398 pNode = m_pChild;
4399 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4400 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004401 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004402 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4403 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004404 }
4405 }
dsinclaira1b07722016-07-11 08:20:58 -07004406
Dan Sinclair1770c022016-03-14 14:14:16 -04004407 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004408 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004409 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004410 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004411 if (!pNewNode)
4412 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004413 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004414 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004415 }
4416 return pNewNode;
4417}
dsinclair5b36f0a2016-07-19 10:56:23 -07004418
tsepezd19e9122016-11-02 15:43:18 -07004419int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004420 CXFA_Node* pNode = m_pChild;
4421 int32_t iCount = 0;
4422 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004423 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004424 if (bOnlyChild) {
4425 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004426 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004427 if (pProperty) {
4428 continue;
4429 }
4430 }
4431 iCount++;
4432 }
4433 }
4434 return iCount;
4435}
dsinclair5b36f0a2016-07-19 10:56:23 -07004436
Dan Sinclair1770c022016-03-14 14:14:16 -04004437CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004438 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004439 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004440 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004441 CXFA_Node* pNode = m_pChild;
4442 int32_t iCount = 0;
4443 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004444 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004445 if (bOnlyChild) {
4446 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004447 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004448 if (pProperty) {
4449 continue;
4450 }
4451 }
4452 iCount++;
4453 if (iCount > index) {
4454 return pNode;
4455 }
4456 }
4457 }
weili44f8faf2016-06-01 14:03:56 -07004458 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004459}
dsinclair5b36f0a2016-07-19 10:56:23 -07004460
Dan Sinclair1770c022016-03-14 14:14:16 -04004461int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4462 ASSERT(!pNode->m_pNext);
4463 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004464 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004465 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004466 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004467
weili44f8faf2016-06-01 14:03:56 -07004468 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004469 if (index > 0) {
4470 return -1;
4471 }
4472 pNode->m_pNext = m_pChild;
4473 m_pChild = pNode;
4474 index = 0;
4475 } else if (index < 0) {
4476 m_pLastChild->m_pNext = pNode;
4477 } else {
4478 CXFA_Node* pPrev = m_pChild;
4479 int32_t iCount = 0;
4480 while (++iCount != index && pPrev->m_pNext) {
4481 pPrev = pPrev->m_pNext;
4482 }
4483 if (index > 0 && index != iCount) {
4484 return -1;
4485 }
4486 pNode->m_pNext = pPrev->m_pNext;
4487 pPrev->m_pNext = pNode;
4488 index = iCount;
4489 }
weili44f8faf2016-06-01 14:03:56 -07004490 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004491 m_pLastChild = pNode;
4492 }
4493 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004494 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004495 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004496 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004497 if (pNotify)
4498 pNotify->OnChildAdded(this);
4499
Dan Sinclair1770c022016-03-14 14:14:16 -04004500 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004501 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004502 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004503 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004504 }
4505 return index;
4506}
weili6e1ae862016-05-04 18:25:27 -07004507
tsepezd19e9122016-11-02 15:43:18 -07004508bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004509 if (!pNode || pNode->m_pParent ||
4510 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004511 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004512 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004513 }
tsepezd19e9122016-11-02 15:43:18 -07004514 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004515 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004516 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004517
4518 int32_t nIndex = -1;
4519 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004520 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004521 pNode->m_pNext = m_pChild;
4522 m_pChild = pNode;
4523 nIndex = 0;
4524 } else if (!pBeforeNode) {
4525 pNode->m_pNext = m_pLastChild->m_pNext;
4526 m_pLastChild->m_pNext = pNode;
4527 } else {
4528 nIndex = 1;
4529 CXFA_Node* pPrev = m_pChild;
4530 while (pPrev->m_pNext != pBeforeNode) {
4531 pPrev = pPrev->m_pNext;
4532 nIndex++;
4533 }
4534 pNode->m_pNext = pPrev->m_pNext;
4535 pPrev->m_pNext = pNode;
4536 }
weili44f8faf2016-06-01 14:03:56 -07004537 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004538 m_pLastChild = pNode;
4539 }
4540 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004541 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004542 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004543 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004544 if (pNotify)
4545 pNotify->OnChildAdded(this);
4546
Dan Sinclair1770c022016-03-14 14:14:16 -04004547 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004548 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004549 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004550 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004551 }
tsepezd19e9122016-11-02 15:43:18 -07004552 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004553}
dsinclair5b36f0a2016-07-19 10:56:23 -07004554
Dan Sinclair1770c022016-03-14 14:14:16 -04004555CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4556 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004557 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004558 }
4559 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4560 pSibling = pSibling->m_pNext) {
4561 if (pSibling->m_pNext == this) {
4562 return pSibling;
4563 }
4564 }
weili44f8faf2016-06-01 14:03:56 -07004565 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004566}
dsinclair5b36f0a2016-07-19 10:56:23 -07004567
tsepezd19e9122016-11-02 15:43:18 -07004568bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004569 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004570 ASSERT(false);
4571 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004572 }
4573 if (m_pChild == pNode) {
4574 m_pChild = pNode->m_pNext;
4575 if (m_pLastChild == pNode) {
4576 m_pLastChild = pNode->m_pNext;
4577 }
weili44f8faf2016-06-01 14:03:56 -07004578 pNode->m_pNext = nullptr;
4579 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004580 } else {
4581 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4582 pPrev->m_pNext = pNode->m_pNext;
4583 if (m_pLastChild == pNode) {
4584 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4585 }
weili44f8faf2016-06-01 14:03:56 -07004586 pNode->m_pNext = nullptr;
4587 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004588 }
weili44f8faf2016-06-01 14:03:56 -07004589 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004590 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004591 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004592 m_pDocument->AddPurgeNode(pNode);
4593 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4594 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004595 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4596 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004597 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07004598 CFDE_XMLElement* pXMLElement =
4599 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004600 CFX_WideStringC wsAttributeName =
4601 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004602 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004603 }
4604 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004605 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -07004606 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004607 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4608 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004609 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004610 }
4611 pNode->m_pXMLNode = pNewXMLElement;
4612 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4613 } else {
4614 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4615 }
dsinclairc5a8f212016-06-20 11:11:12 -07004616 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004617 }
tsepezd19e9122016-11-02 15:43:18 -07004618 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004619}
dsinclair5b36f0a2016-07-19 10:56:23 -07004620
Dan Sinclair1770c022016-03-14 14:14:16 -04004621CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004622 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004623}
dsinclair5b36f0a2016-07-19 10:56:23 -07004624
tsepez736f28a2016-03-25 14:19:51 -07004625CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004626 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4627 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4628 if (pNode->GetNameHash() == dwNameHash) {
4629 return pNode;
4630 }
4631 }
weili44f8faf2016-06-01 14:03:56 -07004632 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004633}
dsinclair5b36f0a2016-07-19 10:56:23 -07004634
dsinclair41cb62e2016-06-23 09:20:32 -07004635CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004636 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4637 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004638 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004639 return pNode;
4640 }
4641 }
weili44f8faf2016-06-01 14:03:56 -07004642 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004643}
dsinclair5b36f0a2016-07-19 10:56:23 -07004644
tsepez736f28a2016-03-25 14:19:51 -07004645CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004646 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4647 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4648 if (pNode->GetNameHash() == dwNameHash) {
4649 return pNode;
4650 }
4651 }
weili44f8faf2016-06-01 14:03:56 -07004652 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004653}
dsinclair5b36f0a2016-07-19 10:56:23 -07004654
Dan Sinclair1770c022016-03-14 14:14:16 -04004655CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4656 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004657 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004658}
dsinclair5b36f0a2016-07-19 10:56:23 -07004659
dsinclair41cb62e2016-06-23 09:20:32 -07004660CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004661 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4662 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004663 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004664 return pNode;
4665 }
4666 }
weili44f8faf2016-06-01 14:03:56 -07004667 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004668}
dsinclair5b36f0a2016-07-19 10:56:23 -07004669
Dan Sinclair1770c022016-03-14 14:14:16 -04004670int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004671 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004672 if (!pScriptContext) {
4673 return -1;
4674 }
4675 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4676}
dsinclair5b36f0a2016-07-19 10:56:23 -07004677
Dan Sinclair1770c022016-03-14 14:14:16 -04004678int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004679 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004680 if (!pScriptContext) {
4681 return -1;
4682 }
4683 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4684}
dsinclair5b36f0a2016-07-19 10:56:23 -07004685
Dan Sinclair1770c022016-03-14 14:14:16 -04004686void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004687 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004688 if (!pScriptContext) {
4689 return;
4690 }
4691 pScriptContext->GetSomExpression(this, wsSOMExpression);
4692}
dsinclair5b36f0a2016-07-19 10:56:23 -07004693
Dan Sinclair1770c022016-03-14 14:14:16 -04004694CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004695 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004696 if (m_ePacket == XFA_XDPPACKET_Form) {
4697 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004698 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004699 return pInstanceMgr;
4700 }
4701 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4702 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004703 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004704 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004705 pNode->m_dwNameHash != m_dwNameHash) {
4706 break;
4707 }
dsinclair56a8b192016-06-21 14:15:25 -07004708 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004709 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4710 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4711 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4712 wsInstName.Mid(1) == wsName) {
4713 pInstanceMgr = pNode;
4714 }
4715 break;
4716 }
4717 }
4718 }
4719 return pInstanceMgr;
4720}
dsinclair5b36f0a2016-07-19 10:56:23 -07004721
Dan Sinclair1770c022016-03-14 14:14:16 -04004722CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004723 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004724}
dsinclair5b36f0a2016-07-19 10:56:23 -07004725
dsinclairc5a8f212016-06-20 11:11:12 -07004726bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4727 if (m_uNodeFlags & dwFlag)
4728 return true;
4729 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4730 return m_pParent && m_pParent->HasFlag(dwFlag);
4731 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004732}
thestigb1a59592016-04-14 18:29:56 -07004733
4734void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004735 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004736 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004737 if (pNotify) {
4738 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004739 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004740 }
dsinclairc5a8f212016-06-20 11:11:12 -07004741 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004742}
thestigb1a59592016-04-14 18:29:56 -07004743
4744void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004745 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004746}
4747
tsepezd19e9122016-11-02 15:43:18 -07004748bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004749 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4750}
thestigb1a59592016-04-14 18:29:56 -07004751
4752void CXFA_Node::OnRemoved(bool bNotify) {
4753 if (!bNotify)
4754 return;
4755
dsinclaira1b07722016-07-11 08:20:58 -07004756 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004757 if (pNotify)
4758 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004759}
thestigb1a59592016-04-14 18:29:56 -07004760
4761void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004762 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004763 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004764 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004765 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004766 }
4767 }
4768}
thestigb1a59592016-04-14 18:29:56 -07004769
Dan Sinclair1770c022016-03-14 14:14:16 -04004770void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004771 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004772 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004773 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004774 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004775 }
4776}
thestigb1a59592016-04-14 18:29:56 -07004777
Dan Sinclair1770c022016-03-14 14:14:16 -04004778int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004779 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004780 int32_t iRet = XFA_EVENTERROR_NotExist;
4781 const XFA_ExecEventParaInfo* eventParaInfo =
4782 GetEventParaInfoByName(wsEventName);
4783 if (eventParaInfo) {
4784 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004785 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004786 if (!pNotify) {
4787 return iRet;
4788 }
4789 if (validFlags == 1) {
4790 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4791 } else if (validFlags == 2) {
4792 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004793 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004794 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004795 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004796 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004797 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004798 }
4799 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004800 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004801 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004802 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004803 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004804 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004805 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004806 }
4807 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004808 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004809 }
4810 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004811 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004812 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004813 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004814 }
4815 } else if (validFlags == 6) {
4816 CXFA_WidgetData* pWidgetData = GetWidgetData();
4817 if (pWidgetData) {
4818 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004819 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004820 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004821 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004822 }
4823 }
4824 } else if (validFlags == 7) {
4825 CXFA_WidgetData* pWidgetData = GetWidgetData();
4826 if (pWidgetData) {
4827 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004828 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004829 (!pWidgetData->IsListBox())) {
4830 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004831 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004832 }
4833 }
4834 }
4835 }
4836 return iRet;
4837}
dsinclair5b36f0a2016-07-19 10:56:23 -07004838
Dan Sinclair1770c022016-03-14 14:14:16 -04004839void CXFA_Node::UpdateNameHash() {
4840 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004841 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004842 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004843 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004844 wsName = GetCData(XFA_ATTRIBUTE_Name);
4845 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004846 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004847 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004848 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004849 }
4850}
dsinclair5b36f0a2016-07-19 10:56:23 -07004851
dsinclairae95f762016-03-29 16:58:29 -07004852CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004853 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004854 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
dsinclairae95f762016-03-29 16:58:29 -07004855 m_pXMLNode = new CFDE_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004856 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004857 }
4858 return m_pXMLNode;
4859}
dsinclair5b36f0a2016-07-19 10:56:23 -07004860
tsepezd19e9122016-11-02 15:43:18 -07004861bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004862 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004863 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004864}
4865
4866XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4867 if (!m_pMapModuleData)
4868 m_pMapModuleData = new XFA_MAPMODULEDATA;
4869 return m_pMapModuleData;
4870}
4871
4872XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4873 return m_pMapModuleData;
4874}
4875
4876void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4877 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004878 pModule->m_ValueMap[pKey] = pValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04004879}
4880
tsepezd19e9122016-11-02 15:43:18 -07004881bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
tsepez6bb3b892017-01-05 12:18:41 -08004882 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004883 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004884 if (pModule) {
4885 auto it = pModule->m_ValueMap.find(pKey);
4886 if (it != pModule->m_ValueMap.end()) {
4887 pValue = it->second;
4888 return true;
4889 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004890 }
tsepez6bb3b892017-01-05 12:18:41 -08004891 if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4892 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004893 }
tsepezd19e9122016-11-02 15:43:18 -07004894 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004895}
dsinclair5b36f0a2016-07-19 10:56:23 -07004896
Dan Sinclair1770c022016-03-14 14:14:16 -04004897void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004898 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair1770c022016-03-14 14:14:16 -04004899 wsValue.GetLength() * sizeof(FX_WCHAR));
4900}
dsinclair5b36f0a2016-07-19 10:56:23 -07004901
tsepezd19e9122016-11-02 15:43:18 -07004902bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004903 void* pValue;
4904 int32_t iBytes;
4905 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004906 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004907 }
4908 wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR));
tsepezd19e9122016-11-02 15:43:18 -07004909 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004910}
dsinclair5b36f0a2016-07-19 10:56:23 -07004911
Dan Sinclair1770c022016-03-14 14:14:16 -04004912void CXFA_Node::SetMapModuleBuffer(
4913 void* pKey,
4914 void* pValue,
4915 int32_t iBytes,
4916 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4917 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4918 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004919 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004920 pBuffer =
4921 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4922 } else if (pBuffer->iBytes != iBytes) {
4923 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4924 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4925 }
4926 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4927 sizeof(XFA_MAPDATABLOCK) + iBytes);
4928 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4929 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4930 }
weili44f8faf2016-06-01 14:03:56 -07004931 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04004932 return;
weili44f8faf2016-06-01 14:03:56 -07004933
Dan Sinclair1770c022016-03-14 14:14:16 -04004934 pBuffer->pCallbackInfo = pCallbackInfo;
4935 pBuffer->iBytes = iBytes;
4936 FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes);
4937}
dsinclair5b36f0a2016-07-19 10:56:23 -07004938
tsepezd19e9122016-11-02 15:43:18 -07004939bool CXFA_Node::GetMapModuleBuffer(void* pKey,
4940 void*& pValue,
4941 int32_t& iBytes,
4942 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07004943 XFA_MAPDATABLOCK* pBuffer = nullptr;
tsepez6bb3b892017-01-05 12:18:41 -08004944 for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004945 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004946 if (pModule) {
4947 auto it = pModule->m_BufferMap.find(pKey);
4948 if (it != pModule->m_BufferMap.end()) {
4949 pBuffer = it->second;
4950 break;
4951 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004952 }
tsepez6bb3b892017-01-05 12:18:41 -08004953 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4954 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004955 }
tsepez6bb3b892017-01-05 12:18:41 -08004956 if (!pBuffer)
tsepezd19e9122016-11-02 15:43:18 -07004957 return false;
tsepez6bb3b892017-01-05 12:18:41 -08004958
Dan Sinclair1770c022016-03-14 14:14:16 -04004959 pValue = pBuffer->GetData();
4960 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07004961 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004962}
dsinclair5b36f0a2016-07-19 10:56:23 -07004963
tsepezd19e9122016-11-02 15:43:18 -07004964bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
tsepez6bb3b892017-01-05 12:18:41 -08004965 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004966 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004967 if (pModule) {
4968 auto it1 = pModule->m_ValueMap.find(pKey);
4969 if (it1 != pModule->m_ValueMap.end())
4970 return true;
4971
4972 auto it2 = pModule->m_BufferMap.find(pKey);
4973 if (it2 != pModule->m_BufferMap.end())
4974 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004975 }
tsepez6bb3b892017-01-05 12:18:41 -08004976 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4977 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004978 }
tsepezd19e9122016-11-02 15:43:18 -07004979 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004980}
dsinclair5b36f0a2016-07-19 10:56:23 -07004981
Dan Sinclair1770c022016-03-14 14:14:16 -04004982void CXFA_Node::RemoveMapModuleKey(void* pKey) {
4983 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
4984 if (!pModule)
4985 return;
4986
4987 if (pKey) {
tsepez6bb3b892017-01-05 12:18:41 -08004988 auto it = pModule->m_BufferMap.find(pKey);
4989 if (it != pModule->m_BufferMap.end()) {
4990 XFA_MAPDATABLOCK* pBuffer = it->second;
Dan Sinclair1770c022016-03-14 14:14:16 -04004991 if (pBuffer) {
tsepez6bb3b892017-01-05 12:18:41 -08004992 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
Dan Sinclair1770c022016-03-14 14:14:16 -04004993 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004994 FX_Free(pBuffer);
4995 }
tsepez6bb3b892017-01-05 12:18:41 -08004996 pModule->m_BufferMap.erase(it);
Dan Sinclair1770c022016-03-14 14:14:16 -04004997 }
tsepez6bb3b892017-01-05 12:18:41 -08004998 pModule->m_ValueMap.erase(pKey);
4999 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04005000 }
tsepez6bb3b892017-01-05 12:18:41 -08005001
5002 for (auto& pair : pModule->m_BufferMap) {
5003 XFA_MAPDATABLOCK* pBuffer = pair.second;
5004 if (pBuffer) {
5005 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
5006 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5007 FX_Free(pBuffer);
5008 }
5009 }
5010 pModule->m_BufferMap.clear();
5011 pModule->m_ValueMap.clear();
5012 delete pModule;
Dan Sinclair1770c022016-03-14 14:14:16 -04005013}
dsinclair5b36f0a2016-07-19 10:56:23 -07005014
tsepez6bb3b892017-01-05 12:18:41 -08005015void CXFA_Node::MergeAllData(void* pDstModule) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005016 XFA_MAPMODULEDATA* pDstModuleData =
5017 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
5018 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08005019 if (!pSrcModuleData)
Dan Sinclair1770c022016-03-14 14:14:16 -04005020 return;
tsepez6bb3b892017-01-05 12:18:41 -08005021
5022 for (const auto& pair : pSrcModuleData->m_ValueMap)
5023 pDstModuleData->m_ValueMap[pair.first] = pair.second;
5024
5025 for (const auto& pair : pSrcModuleData->m_BufferMap) {
5026 XFA_MAPDATABLOCK* pSrcBuffer = pair.second;
5027 XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first];
Dan Sinclair1770c022016-03-14 14:14:16 -04005028 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
5029 !pSrcBuffer->pCallbackInfo->pCopy) {
tsepez6bb3b892017-01-05 12:18:41 -08005030 if (pDstBuffer) {
5031 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
5032 pDstModuleData->m_BufferMap.erase(pair.first);
Dan Sinclair1770c022016-03-14 14:14:16 -04005033 }
5034 continue;
5035 }
tsepez6bb3b892017-01-05 12:18:41 -08005036 if (!pDstBuffer) {
5037 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
Dan Sinclair1770c022016-03-14 14:14:16 -04005038 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08005039 } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) {
5040 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5041 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005042 }
tsepez6bb3b892017-01-05 12:18:41 -08005043 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
5044 uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5045 } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5046 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005047 }
tsepez6bb3b892017-01-05 12:18:41 -08005048 if (!pDstBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005049 continue;
5050 }
tsepez6bb3b892017-01-05 12:18:41 -08005051 pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5052 pDstBuffer->iBytes = pSrcBuffer->iBytes;
5053 FXSYS_memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(),
5054 pSrcBuffer->iBytes);
5055 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) {
5056 pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005057 }
5058 }
5059}
dsinclair5b36f0a2016-07-19 10:56:23 -07005060
Dan Sinclair1770c022016-03-14 14:14:16 -04005061void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5062 if (!pDstModule) {
5063 return;
5064 }
tsepezd19e9122016-11-02 15:43:18 -07005065 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005066 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005067 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005068 }
dsinclair070fcdf2016-06-22 22:04:54 -07005069 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005070 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005071 }
weili44f8faf2016-06-01 14:03:56 -07005072 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5073 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005074 if (bNeedMove) {
5075 pSrcModuleData = GetMapModuleData();
5076 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005077 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005078 }
5079 pDstModuleData = pDstModule->CreateMapModuleData();
5080 }
5081 if (bNeedMove) {
tsepez6bb3b892017-01-05 12:18:41 -08005082 auto it = pSrcModuleData->m_BufferMap.find(pKey);
5083 if (it != pSrcModuleData->m_BufferMap.end()) {
5084 XFA_MAPDATABLOCK* pBufferBlockData = it->second;
5085 if (pBufferBlockData) {
5086 pSrcModuleData->m_BufferMap.erase(pKey);
5087 pDstModuleData->m_BufferMap[pKey] = pBufferBlockData;
5088 }
Dan Sinclair1770c022016-03-14 14:14:16 -04005089 }
5090 }
dsinclairc5a8f212016-06-20 11:11:12 -07005091 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005092 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005093 CFX_WideString wsFormatValue(wsValue);
5094 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5095 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005096 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005097 }
tsepezd19e9122016-11-02 15:43:18 -07005098 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005099 }
5100}
dsinclair5b36f0a2016-07-19 10:56:23 -07005101
Dan Sinclair1770c022016-03-14 14:14:16 -04005102void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5103 CXFA_Node* pDstModule,
5104 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005105 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005106 if (!pSrcModule || !pDstModule || !pKey) {
5107 return;
5108 }
5109 if (bRecursive) {
5110 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5111 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5112 for (; pSrcChild && pDstChild;
5113 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5114 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005115 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005116 }
5117 }
5118 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5119}
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05005120
5121void CXFA_Node::ThrowMissingPropertyException(
5122 const CFX_WideString& obj,
5123 const CFX_WideString& prop) const {
5124 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(),
5125 prop.c_str());
5126}
5127
5128void CXFA_Node::ThrowTooManyOccurancesException(
5129 const CFX_WideString& obj) const {
5130 ThrowException(
5131 L"The element [%s] has violated its allowable number of occurrences.",
5132 obj.c_str());
5133}