blob: 5411443e6ad3d1c1ed3a38f18b7af0896ea30617 [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);
1100 CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]");
1101 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 ";
tsepez28f97ff2016-04-04 16:41:35 -07001112 FXJSE_ThrowMessage(
tsepezbd9748d2016-04-13 21:40:19 -07001113 FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001114 } else {
1115 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
dsinclairf27aeec2016-06-07 19:36:18 -07001116 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001117 }
1118}
weili44f8faf2016-06-01 14:03:56 -07001119
dsinclair12a6b0c2016-05-26 11:14:08 -07001120void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001121 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001122 XFA_ATTRIBUTE eAttribute) {
1123 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001124 ThrowInvalidPropertyException();
1125 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001126 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001127
1128 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
1129 CFX_WideString wsExpression =
1130 FX_WSTRC(L"#") + GetClassName() + FX_WSTRC(L"[*]");
1131 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001132}
weili44f8faf2016-06-01 14:03:56 -07001133
dsinclair12a6b0c2016-05-26 11:14:08 -07001134void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001135 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001136 XFA_ATTRIBUTE eAttribute) {
1137 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001138 ThrowInvalidPropertyException();
1139 return;
1140 }
1141 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
1142 if (pParent) {
1143 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001144 } else {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001145 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001146 }
1147}
weili44f8faf2016-06-01 14:03:56 -07001148
dsinclair12a6b0c2016-05-26 11:14:08 -07001149void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001150 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001151 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001152 if (bSetting) {
1153 ThrowInvalidPropertyException();
1154 return;
1155 }
1156 pValue->SetInteger(GetNodeSameNameIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001157}
weili44f8faf2016-06-01 14:03:56 -07001158
dsinclair12a6b0c2016-05-26 11:14:08 -07001159void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001160 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001161 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001162 if (bSetting) {
1163 ThrowInvalidPropertyException();
1164 return;
1165 }
1166 pValue->SetInteger(GetNodeSameClassIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001167}
weili44f8faf2016-06-01 14:03:56 -07001168
dsinclair12a6b0c2016-05-26 11:14:08 -07001169void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001170 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001171 XFA_ATTRIBUTE eAttribute) {
1172 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001173 ThrowInvalidPropertyException();
1174 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001175 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001176 CFX_WideString wsSOMExpression;
1177 GetSOMExpression(wsSOMExpression);
1178 pValue->SetString(FX_UTF8Encode(wsSOMExpression).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001179}
weili44f8faf2016-06-01 14:03:56 -07001180
Dan Sinclair1770c022016-03-14 14:14:16 -04001181void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
1182 int32_t iLength = pArguments->GetLength();
1183 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001184 ThrowParamCountMismatchException(L"applyXSL");
Dan Sinclair1770c022016-03-14 14:14:16 -04001185 return;
1186 }
tsepez6fe7d212016-04-06 10:51:14 -07001187 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001188 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili60607c32016-05-26 11:53:12 -07001189 // TODO(weili): check whether we need to implement this, pdfium:501.
1190 // For now, just put the variables here to avoid unused variable warning.
1191 (void)wsExpression;
Dan Sinclair1770c022016-03-14 14:14:16 -04001192}
weili60607c32016-05-26 11:53:12 -07001193
Dan Sinclair1770c022016-03-14 14:14:16 -04001194void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
1195 int32_t iLength = pArguments->GetLength();
1196 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001197 ThrowParamCountMismatchException(L"assignNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04001198 return;
1199 }
1200 CFX_WideString wsExpression;
1201 CFX_WideString wsValue;
1202 int32_t iAction = 0;
weili44f8faf2016-06-01 14:03:56 -07001203 wsExpression =
1204 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001205 if (iLength >= 2) {
weili60607c32016-05-26 11:53:12 -07001206 wsValue =
1207 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001208 }
weili60607c32016-05-26 11:53:12 -07001209 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001210 iAction = pArguments->GetInt32(2);
weili60607c32016-05-26 11:53:12 -07001211 // TODO(weili): check whether we need to implement this, pdfium:501.
1212 // For now, just put the variables here to avoid unused variable warning.
1213 (void)wsExpression;
1214 (void)wsValue;
1215 (void)iAction;
Dan Sinclair1770c022016-03-14 14:14:16 -04001216}
weili60607c32016-05-26 11:53:12 -07001217
Dan Sinclair1770c022016-03-14 14:14:16 -04001218void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
1219 int32_t iLength = pArguments->GetLength();
1220 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001221 ThrowParamCountMismatchException(L"clone");
Dan Sinclair1770c022016-03-14 14:14:16 -04001222 return;
1223 }
weili44f8faf2016-06-01 14:03:56 -07001224 bool bClone = !!pArguments->GetInt32(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001225 CXFA_Node* pCloneNode = Clone(bClone);
dsinclairf27aeec2016-06-07 19:36:18 -07001226 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001227 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
1228}
weili44f8faf2016-06-01 14:03:56 -07001229
Dan Sinclair1770c022016-03-14 14:14:16 -04001230void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
1231 int32_t iLength = pArguments->GetLength();
1232 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001233 ThrowParamCountMismatchException(L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001234 return;
1235 }
tsepez6fe7d212016-04-06 10:51:14 -07001236 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001237 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001238 CFX_WideString wsValue;
tsepez4c3debb2016-04-08 12:20:38 -07001239 GetAttribute(wsExpression.AsStringC(), wsValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07001240 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001241 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001242 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001243}
weili44f8faf2016-06-01 14:03:56 -07001244
Dan Sinclair1770c022016-03-14 14:14:16 -04001245void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
1246 int32_t iLength = pArguments->GetLength();
1247 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001248 ThrowParamCountMismatchException(L"getElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001249 return;
1250 }
1251 CFX_WideString wsExpression;
1252 int32_t iValue = 0;
weili44f8faf2016-06-01 14:03:56 -07001253 wsExpression =
1254 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1255 if (iLength >= 2)
Dan Sinclair1770c022016-03-14 14:14:16 -04001256 iValue = pArguments->GetInt32(1);
dsinclair6e124782016-06-23 12:14:55 -07001257 CXFA_Node* pNode =
1258 GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
dsinclairf27aeec2016-06-07 19:36:18 -07001259 pArguments->GetReturnValue()->Assign(
1260 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001261}
weili65be4b12016-05-25 15:47:43 -07001262
Dan Sinclair1770c022016-03-14 14:14:16 -04001263void CXFA_Node::Script_NodeClass_IsPropertySpecified(
1264 CFXJSE_Arguments* pArguments) {
1265 int32_t iLength = pArguments->GetLength();
1266 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001267 ThrowParamCountMismatchException(L"isPropertySpecified");
Dan Sinclair1770c022016-03-14 14:14:16 -04001268 return;
1269 }
1270 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001271 bool bParent = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001272 int32_t iIndex = 0;
weili44f8faf2016-06-01 14:03:56 -07001273 wsExpression =
1274 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili65be4b12016-05-25 15:47:43 -07001275 if (iLength >= 2)
weili44f8faf2016-06-01 14:03:56 -07001276 bParent = !!pArguments->GetInt32(1);
weili65be4b12016-05-25 15:47:43 -07001277 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001278 iIndex = pArguments->GetInt32(2);
tsepezd19e9122016-11-02 15:43:18 -07001279 bool bHas = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001280 const XFA_ATTRIBUTEINFO* pAttributeInfo =
tsepez4c3debb2016-04-08 12:20:38 -07001281 XFA_GetAttributeByName(wsExpression.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001282 CFX_WideString wsValue;
weili65be4b12016-05-25 15:47:43 -07001283 if (pAttributeInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04001284 bHas = HasAttribute(pAttributeInfo->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04001285 if (!bHas) {
dsinclair6e124782016-06-23 12:14:55 -07001286 XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
1287 bHas = !!GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001288 if (!bHas && bParent && m_pParent) {
1289 // Also check on the parent.
1290 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
1291 if (!bHas)
dsinclair6e124782016-06-23 12:14:55 -07001292 bHas = !!m_pParent->GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001293 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001294 }
dsinclair12a6b0c2016-05-26 11:14:08 -07001295 CFXJSE_Value* pValue = pArguments->GetReturnValue();
1296 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001297 pValue->SetBoolean(bHas);
Dan Sinclair1770c022016-03-14 14:14:16 -04001298}
weili65be4b12016-05-25 15:47:43 -07001299
Dan Sinclair1770c022016-03-14 14:14:16 -04001300void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
1301 int32_t iLength = pArguments->GetLength();
1302 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001303 ThrowParamCountMismatchException(L"loadXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001304 return;
1305 }
1306 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001307 bool bIgnoreRoot = true;
1308 bool bOverwrite = 0;
1309 wsExpression =
1310 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1311 if (wsExpression.IsEmpty())
Tom Sepezd3743ea2016-05-16 15:56:53 -07001312 return;
weili44f8faf2016-06-01 14:03:56 -07001313 if (iLength >= 2)
1314 bIgnoreRoot = !!pArguments->GetInt32(1);
1315 if (iLength >= 3)
1316 bOverwrite = !!pArguments->GetInt32(2);
dsinclaira1b07722016-07-11 08:20:58 -07001317 std::unique_ptr<CXFA_SimpleParser> pParser(
1318 new CXFA_SimpleParser(m_pDocument, false));
weili44f8faf2016-06-01 14:03:56 -07001319 if (!pParser)
Dan Sinclair1770c022016-03-14 14:14:16 -04001320 return;
weili44f8faf2016-06-01 14:03:56 -07001321 CFDE_XMLNode* pXMLNode = nullptr;
1322 int32_t iParserStatus =
1323 pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
1324 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
1325 return;
dsinclairae95f762016-03-29 16:58:29 -07001326 if (bIgnoreRoot &&
1327 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
1328 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
weili44f8faf2016-06-01 14:03:56 -07001329 bIgnoreRoot = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001330 }
tsepezd19e9122016-11-02 15:43:18 -07001331 CXFA_Node* pFakeRoot = Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001332 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
1333 if (!wsContentType.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07001334 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
1335 CFX_WideString(wsContentType));
Dan Sinclair1770c022016-03-14 14:14:16 -04001336 }
dsinclairae95f762016-03-29 16:58:29 -07001337 CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001338 if (!pFakeXMLRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001339 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
tsepezd19e9122016-11-02 15:43:18 -07001340 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001341 }
dsinclair017052a2016-06-28 07:43:51 -07001342 if (!pFakeXMLRoot)
1343 pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName()));
1344
Dan Sinclair1770c022016-03-14 14:14:16 -04001345 if (bIgnoreRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001346 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001347 while (pXMLChild) {
dsinclairae95f762016-03-29 16:58:29 -07001348 CFDE_XMLNode* pXMLSibling =
1349 pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001350 pXMLNode->RemoveChildNode(pXMLChild);
1351 pFakeXMLRoot->InsertChildNode(pXMLChild);
1352 pXMLChild = pXMLSibling;
1353 }
1354 } else {
dsinclairae95f762016-03-29 16:58:29 -07001355 CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001356 if (pXMLParent) {
1357 pXMLParent->RemoveChildNode(pXMLNode);
1358 }
1359 pFakeXMLRoot->InsertChildNode(pXMLNode);
1360 }
1361 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot);
1362 pFakeRoot = pParser->GetRootNode();
1363 if (pFakeRoot) {
1364 if (bOverwrite) {
1365 CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1366 CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1367 int32_t index = 0;
1368 while (pNewChild) {
1369 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1370 pFakeRoot->RemoveChild(pNewChild);
1371 InsertChild(index++, pNewChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001372 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001373 pNewChild = pItem;
1374 }
1375 while (pChild) {
1376 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1377 RemoveChild(pChild);
1378 pFakeRoot->InsertChild(pChild);
1379 pChild = pItem;
1380 }
1381 if (GetPacketID() == XFA_XDPPACKET_Form &&
dsinclair070fcdf2016-06-22 22:04:54 -07001382 GetElementType() == XFA_Element::ExData) {
dsinclairae95f762016-03-29 16:58:29 -07001383 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001384 SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001385 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
weili44f8faf2016-06-01 14:03:56 -07001386 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001387 pFakeXMLRoot = pTempXMLNode;
1388 } else {
weili44f8faf2016-06-01 14:03:56 -07001389 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001390 }
1391 }
tsepezd19e9122016-11-02 15:43:18 -07001392 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001393 } else {
1394 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1395 while (pChild) {
1396 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1397 pFakeRoot->RemoveChild(pChild);
1398 InsertChild(pChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001399 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001400 pChild = pItem;
1401 }
1402 }
1403 if (pFakeXMLRoot) {
1404 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001405 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001406 }
dsinclairc5a8f212016-06-20 11:11:12 -07001407 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001408 } else {
tsepezc757d9a2017-01-23 11:01:42 -08001409 delete pFakeXMLRoot;
1410 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001411 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001412}
weili44f8faf2016-06-01 14:03:56 -07001413
Dan Sinclair1770c022016-03-14 14:14:16 -04001414void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
weili44f8faf2016-06-01 14:03:56 -07001415 // TODO(weili): Check whether we need to implement this, pdfium:501.
Dan Sinclair1770c022016-03-14 14:14:16 -04001416}
1417
1418void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1419 int32_t iLength = pArguments->GetLength();
1420 if (iLength < 0 || iLength > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001421 ThrowParamCountMismatchException(L"saveXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001422 return;
1423 }
weili44f8faf2016-06-01 14:03:56 -07001424 bool bPrettyMode = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001425 if (iLength == 1) {
weili65be4b12016-05-25 15:47:43 -07001426 if (pArguments->GetUTF8String(0) != "pretty") {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001427 ThrowArgumentMismatchException();
Dan Sinclair1770c022016-03-14 14:14:16 -04001428 return;
1429 }
weili44f8faf2016-06-01 14:03:56 -07001430 bPrettyMode = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001431 }
1432 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
weili65be4b12016-05-25 15:47:43 -07001433 if (GetPacketID() == XFA_XDPPACKET_Form ||
1434 GetPacketID() == XFA_XDPPACKET_Datasets) {
1435 CFDE_XMLNode* pElement = nullptr;
1436 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1437 pElement = GetXMLMappingNode();
1438 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
dsinclairf27aeec2016-06-07 19:36:18 -07001439 pArguments->GetReturnValue()->SetString(bsXMLHeader);
weili65be4b12016-05-25 15:47:43 -07001440 return;
1441 }
1442 XFA_DataExporter_DealWithDataGroupNode(this);
1443 }
tsepez833619b2016-12-07 09:21:17 -08001444 CFX_RetainPtr<IFX_MemoryStream> pMemoryStream =
1445 IFX_MemoryStream::Create(true);
1446
1447 // Note: ambiguious below without static_cast.
tsepez7cda31a2016-12-07 12:10:20 -08001448 CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream(
1449 CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream),
1450 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
tsepez833619b2016-12-07 09:21:17 -08001451
Dan Sinclair1770c022016-03-14 14:14:16 -04001452 if (!pStream) {
dsinclairf27aeec2016-06-07 19:36:18 -07001453 pArguments->GetReturnValue()->SetString(bsXMLHeader);
Dan Sinclair1770c022016-03-14 14:14:16 -04001454 return;
1455 }
1456 pStream->SetCodePage(FX_CODEPAGE_UTF8);
dsinclair179bebb2016-04-05 11:02:18 -07001457 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
weili65be4b12016-05-25 15:47:43 -07001458 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepez7cda31a2016-12-07 12:10:20 -08001459 XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001460 else
tsepez7cda31a2016-12-07 12:10:20 -08001461 pElement->SaveXMLNode(pStream);
weili65be4b12016-05-25 15:47:43 -07001462 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1463 // For now, just put it here to avoid unused variable warning.
1464 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001465 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001466 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001467 return;
1468 }
dsinclairf27aeec2016-06-07 19:36:18 -07001469 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001470}
1471
1472void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1473 int32_t iLength = pArguments->GetLength();
1474 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001475 ThrowParamCountMismatchException(L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001476 return;
1477 }
tsepez6fe7d212016-04-06 10:51:14 -07001478 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001479 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001480 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001481 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001482 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001483}
weili60607c32016-05-26 11:53:12 -07001484
Dan Sinclair1770c022016-03-14 14:14:16 -04001485void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1486 int32_t iLength = pArguments->GetLength();
1487 if (iLength != 1 && iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001488 ThrowParamCountMismatchException(L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001489 return;
1490 }
weili60607c32016-05-26 11:53:12 -07001491 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001492 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001493 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1494 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001495 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001496 // TODO(weili): check whether we need to implement this, pdfium:501.
1497 // For now, just put the variables here to avoid unused variable warning.
1498 (void)pNode;
1499 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001500}
weili60607c32016-05-26 11:53:12 -07001501
dsinclair12a6b0c2016-05-26 11:14:08 -07001502void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001503 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001504 XFA_ATTRIBUTE eAttribute) {
1505 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001506 ThrowInvalidPropertyException();
1507 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001508 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001509
1510 CFX_WideString wsNameSpace;
1511 TryNamespace(wsNameSpace);
1512 pValue->SetString(FX_UTF8Encode(wsNameSpace).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001513}
weili44f8faf2016-06-01 14:03:56 -07001514
dsinclair12a6b0c2016-05-26 11:14:08 -07001515void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001516 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001517 XFA_ATTRIBUTE eAttribute) {
1518 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001519 ThrowInvalidPropertyException();
1520 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001521 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001522 pValue->Assign(
1523 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001524}
weili44f8faf2016-06-01 14:03:56 -07001525
dsinclair12a6b0c2016-05-26 11:14:08 -07001526void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001527 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001528 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001529 if (bSetting) {
1530 ThrowInvalidPropertyException();
1531 return;
1532 }
1533 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001534}
weili44f8faf2016-06-01 14:03:56 -07001535
dsinclair12a6b0c2016-05-26 11:14:08 -07001536void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001537 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001538 XFA_ATTRIBUTE eAttribute) {
1539 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001540 ThrowInvalidPropertyException();
1541 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001542 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001543 if (GetElementType() == XFA_Element::Subform) {
1544 pValue->SetBoolean(false);
1545 return;
1546 }
1547 CFX_WideString strValue;
1548 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001549}
weili44f8faf2016-06-01 14:03:56 -07001550
dsinclair12a6b0c2016-05-26 11:14:08 -07001551void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001552 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001553 XFA_ATTRIBUTE eAttribute) {
1554 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001555 ThrowInvalidPropertyException();
1556 return;
1557 }
1558
1559 CXFA_NodeArray properts;
1560 int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty);
1561 if (iSize > 0) {
1562 pValue->Assign(
1563 m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0]));
Dan Sinclair1770c022016-03-14 14:14:16 -04001564 }
1565}
weili44f8faf2016-06-01 14:03:56 -07001566
Dan Sinclair1770c022016-03-14 14:14:16 -04001567void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001568
Dan Sinclair1770c022016-03-14 14:14:16 -04001569void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1570 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001571 pArguments->GetReturnValue()->SetObject(
1572 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001573}
1574void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1575}
dsinclair5b36f0a2016-07-19 10:56:23 -07001576
Dan Sinclair1770c022016-03-14 14:14:16 -04001577void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1578 Script_Template_CreateNode(pArguments);
1579}
dsinclair5b36f0a2016-07-19 10:56:23 -07001580
Dan Sinclair1770c022016-03-14 14:14:16 -04001581void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1582 int32_t iLength = pArguments->GetLength();
1583 if (iLength < 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001584 ThrowParamCountMismatchException(L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001585 return;
1586 }
1587 CFX_WideString wsNameSpace;
1588 if (iLength >= 1) {
1589 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001590 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001591 }
1592 CFX_WideString wsNodeNameSpace;
1593 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001594 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001595 if (pValue)
1596 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001597}
dsinclair5b36f0a2016-07-19 10:56:23 -07001598
dsinclair12a6b0c2016-05-26 11:14:08 -07001599void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001600 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001601 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001602
dsinclair12a6b0c2016-05-26 11:14:08 -07001603void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001604 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001605 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001606
dsinclair12a6b0c2016-05-26 11:14:08 -07001607void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001608 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001609 XFA_ATTRIBUTE eAttribute) {
1610 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001611 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001612 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001613 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001614 }
1615}
dsinclair5b36f0a2016-07-19 10:56:23 -07001616
dsinclair12a6b0c2016-05-26 11:14:08 -07001617void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001618 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001619 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001620 if (bSetting) {
1621 ThrowInvalidPropertyException();
1622 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001623 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001624 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001625}
dsinclair5b36f0a2016-07-19 10:56:23 -07001626
dsinclair12a6b0c2016-05-26 11:14:08 -07001627void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001628 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001629 XFA_ATTRIBUTE eAttribute) {
1630 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001631 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001632 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001633 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001634 }
1635}
dsinclair5b36f0a2016-07-19 10:56:23 -07001636
dsinclair12a6b0c2016-05-26 11:14:08 -07001637void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001638 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001639 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001640 if (bSetting) {
1641 ThrowInvalidPropertyException();
1642 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001643 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001644 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001645}
thestigb1a59592016-04-14 18:29:56 -07001646
Dan Sinclair1770c022016-03-14 14:14:16 -04001647void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001648 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001649 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001650 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001651 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001652 return;
thestigb1a59592016-04-14 18:29:56 -07001653
dsinclaira1b07722016-07-11 08:20:58 -07001654 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001655 if (!pNotify)
1656 return;
1657
1658 uint32_t dwPacket = GetPacketID();
1659 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1660 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001661 return;
1662 }
thestigb1a59592016-04-14 18:29:56 -07001663
1664 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001665 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001666 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001667 bNeedFindContainer = true;
1668 pNotify->OnValueChanged(this, eAttribute, this,
1669 GetNodeItem(XFA_NODEITEM_Parent));
1670 break;
dsinclair56a8b192016-06-21 14:15:25 -07001671 case XFA_Element::Font:
1672 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001673 bNeedFindContainer = true;
1674 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001675 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001676 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1677 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1678 } else {
1679 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1680 }
1681 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001682 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001683 bNeedFindContainer = true;
1684 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001685 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001686 if (pParentNode->IsContainerNode()) {
1687 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001688 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001689 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1690 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1691 } else {
1692 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001693 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001694 pNotify->OnValueChanged(this, eAttribute, pNode,
1695 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001696 }
thestigb1a59592016-04-14 18:29:56 -07001697 }
1698 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001699 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001700 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001701 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001702 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1703 eUIType == XFA_Element::NumericEdit ||
1704 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001705 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001706 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001707 pNotify->OnValueChanged(this, eAttribute, pUINode,
1708 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001709 }
thestigb1a59592016-04-14 18:29:56 -07001710 }
1711 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001712 case XFA_Element::Button:
1713 case XFA_Element::Barcode:
1714 case XFA_Element::ChoiceList:
1715 case XFA_Element::DateTimeEdit:
1716 case XFA_Element::NumericEdit:
1717 case XFA_Element::PasswordEdit:
1718 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001719 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1720 if (pUINode) {
1721 pNotify->OnValueChanged(this, eAttribute, pUINode,
1722 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1723 }
1724 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001725 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001726 bNeedFindContainer = true;
1727 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1728 if (pUINode) {
1729 pNotify->OnValueChanged(this, eAttribute, pUINode,
1730 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1731 }
1732 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001733 case XFA_Element::Keep:
1734 case XFA_Element::Bookend:
1735 case XFA_Element::Break:
1736 case XFA_Element::BreakAfter:
1737 case XFA_Element::BreakBefore:
1738 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001739 bNeedFindContainer = true;
1740 break;
dsinclair56a8b192016-06-21 14:15:25 -07001741 case XFA_Element::Area:
1742 case XFA_Element::Draw:
1743 case XFA_Element::ExclGroup:
1744 case XFA_Element::Field:
1745 case XFA_Element::Subform:
1746 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001747 pLayoutPro->AddChangedContainer(this);
1748 pNotify->OnValueChanged(this, eAttribute, this, this);
1749 break;
dsinclair56a8b192016-06-21 14:15:25 -07001750 case XFA_Element::Sharptext:
1751 case XFA_Element::Sharpxml:
1752 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001753 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1754 if (!pTextNode) {
1755 return;
1756 }
1757 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1758 if (!pValueNode) {
1759 return;
1760 }
dsinclair41cb62e2016-06-23 09:20:32 -07001761 XFA_Element eType = pValueNode->GetElementType();
1762 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001763 bNeedFindContainer = true;
1764 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1765 if (pNode && pNode->IsContainerNode()) {
1766 if (bScriptModify) {
1767 pValueNode = pNode;
1768 }
1769 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1770 } else {
1771 pNotify->OnValueChanged(this, eAttribute, pNode,
1772 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001773 }
thestigb1a59592016-04-14 18:29:56 -07001774 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001775 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001776 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1777 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001778 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001779 }
1780 }
thestigb1a59592016-04-14 18:29:56 -07001781 }
1782 } break;
1783 default:
1784 break;
1785 }
1786 if (bNeedFindContainer) {
1787 CXFA_Node* pParent = this;
1788 while (pParent) {
1789 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001790 break;
thestigb1a59592016-04-14 18:29:56 -07001791
1792 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001793 }
thestigb1a59592016-04-14 18:29:56 -07001794 if (pParent) {
1795 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001796 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001797 }
1798}
thestigb1a59592016-04-14 18:29:56 -07001799
dsinclair12a6b0c2016-05-26 11:14:08 -07001800void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001801 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001802 XFA_ATTRIBUTE eAttribute) {
1803 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001804 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001805 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001806 if (eAttribute == XFA_ATTRIBUTE_Use &&
1807 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001808 CXFA_Node* pTemplateNode =
1809 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1810 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001811 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1812 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001813
1814 CFX_WideString wsID;
1815 CFX_WideString wsSOM;
1816 if (!wsValue.IsEmpty()) {
1817 if (wsValue[0] == '#') {
1818 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001819 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001820 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001821 }
1822 }
weili44f8faf2016-06-01 14:03:56 -07001823 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001824 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001825 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001826 XFA_RESOLVENODE_Attributes |
1827 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1828 XFA_RESOLVENODE_Siblings;
1829 XFA_RESOLVENODE_RS resoveNodeRS;
1830 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001831 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001832 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) {
1833 pProtoNode = resoveNodeRS.nodes[0]->AsNode();
1834 }
1835 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001836 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001837 }
1838 if (pProtoNode) {
1839 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1840 while (pHeadChild) {
1841 CXFA_Node* pSibling =
1842 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1843 RemoveChild(pHeadChild);
1844 pHeadChild = pSibling;
1845 }
tsepezd19e9122016-11-02 15:43:18 -07001846 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001847 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1848 while (pHeadChild) {
1849 CXFA_Node* pSibling =
1850 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1851 pProtoForm->RemoveChild(pHeadChild);
1852 InsertChild(pHeadChild);
1853 pHeadChild = pSibling;
1854 }
1855 m_pDocument->RemovePurgeNode(pProtoForm);
1856 delete pProtoForm;
1857 }
1858 }
1859 } else {
1860 CFX_WideString wsValue;
1861 GetAttribute(eAttribute, wsValue);
dsinclairf27aeec2016-06-07 19:36:18 -07001862 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07001863 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001864 }
1865}
dsinclair5b36f0a2016-07-19 10:56:23 -07001866
dsinclair12a6b0c2016-05-26 11:14:08 -07001867void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001868 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001869 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001870 if (bSetting) {
1871 ThrowInvalidPropertyException();
1872 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001873 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001874
1875 CFX_WideString wsValue;
1876 GetAttribute(eAttribute, wsValue);
1877 pValue->SetString(
1878 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001879}
dsinclair5b36f0a2016-07-19 10:56:23 -07001880
Dan Sinclair1770c022016-03-14 14:14:16 -04001881void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1882 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001883 if (argc != 0 && argc != 1) {
1884 ThrowParamCountMismatchException(L"execute");
1885 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001886 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001887 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001888}
dsinclair5b36f0a2016-07-19 10:56:23 -07001889
Dan Sinclair1770c022016-03-14 14:14:16 -04001890void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001891 if (pArguments->GetLength() != 0)
1892 ThrowParamCountMismatchException(L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001893}
dsinclair5b36f0a2016-07-19 10:56:23 -07001894
dsinclair12a6b0c2016-05-26 11:14:08 -07001895void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001896 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001897 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001898
dsinclair12a6b0c2016-05-26 11:14:08 -07001899void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001900 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001901 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001902
dsinclair12a6b0c2016-05-26 11:14:08 -07001903void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001904 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001905 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001906
dsinclair12a6b0c2016-05-26 11:14:08 -07001907void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001908 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001909 XFA_SOM_MESSAGETYPE iMessageType) {
1910 CXFA_WidgetData* pWidgetData = GetWidgetData();
1911 if (!pWidgetData) {
1912 return;
1913 }
tsepezd19e9122016-11-02 15:43:18 -07001914 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001915 CXFA_Validate validate = pWidgetData->GetValidate();
1916 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001917 validate = pWidgetData->GetValidate(true);
1918 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001919 }
1920 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001921 switch (iMessageType) {
1922 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001923 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001924 break;
1925 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001926 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001927 break;
1928 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001929 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001930 break;
1931 default:
1932 break;
1933 }
1934 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001935 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001936 if (!pNotify) {
1937 return;
1938 }
1939 pNotify->AddCalcValidate(this);
1940 }
1941 } else {
1942 CFX_WideString wsMessage;
1943 switch (iMessageType) {
1944 case XFA_SOM_ValidationMessage:
1945 validate.GetScriptMessageText(wsMessage);
1946 break;
1947 case XFA_SOM_FormatMessage:
1948 validate.GetFormatMessageText(wsMessage);
1949 break;
1950 case XFA_SOM_MandatoryMessage:
1951 validate.GetNullMessageText(wsMessage);
1952 break;
1953 default:
1954 break;
1955 }
dsinclairf27aeec2016-06-07 19:36:18 -07001956 pValue->SetString(FX_UTF8Encode(wsMessage).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001957 }
1958}
dsinclair5b36f0a2016-07-19 10:56:23 -07001959
dsinclair12a6b0c2016-05-26 11:14:08 -07001960void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001961 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001962 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001963 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001964}
dsinclair5b36f0a2016-07-19 10:56:23 -07001965
dsinclair12a6b0c2016-05-26 11:14:08 -07001966void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001967 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001968 XFA_ATTRIBUTE eAttribute) {
1969 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001970 ThrowInvalidPropertyException();
1971 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001972 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001973
1974 CXFA_WidgetData* pWidgetData = GetWidgetData();
1975 if (!pWidgetData) {
1976 pValue->SetInteger(0);
1977 return;
1978 }
1979 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001980}
dsinclair5b36f0a2016-07-19 10:56:23 -07001981
dsinclair12a6b0c2016-05-26 11:14:08 -07001982void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001983 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001984 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001985 XFA_Element eType = GetElementType();
1986 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001987 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001988 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001989 }
1990 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001991 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001992 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001993 }
1994 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001995 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001996 return;
1997 }
1998 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001999 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07002000 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002001 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002002
Dan Sinclair1770c022016-03-14 14:14:16 -04002003 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07002004 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002005 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
2006 CXFA_NodeArray formNodes;
2007 GetBindItems(formNodes);
2008 CFX_WideString wsPicture;
2009 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
2010 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -07002011 if (!pFormNode || pFormNode->HasRemovedChildren()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002012 continue;
2013 }
2014 pContainerWidgetData = pFormNode->GetContainerWidgetData();
2015 if (pContainerWidgetData) {
2016 pContainerWidgetData->GetPictureContent(wsPicture,
2017 XFA_VALUEPICTURE_DataBind);
2018 }
2019 if (!wsPicture.IsEmpty()) {
2020 break;
2021 }
weili44f8faf2016-06-01 14:03:56 -07002022 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002023 }
2024 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
2025 pContainerWidgetData = GetContainerWidgetData();
2026 }
2027 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002028 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002029 }
tsepezd19e9122016-11-02 15:43:18 -07002030 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002031 } else {
tsepezd19e9122016-11-02 15:43:18 -07002032 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07002033 if (content.IsEmpty() && eType != XFA_Element::Text &&
2034 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07002035 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07002036 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002037 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07002038 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07002039 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002040 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002041 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002042 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002043 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002044 }
2045 }
2046}
dsinclair5b36f0a2016-07-19 10:56:23 -07002047
dsinclair12a6b0c2016-05-26 11:14:08 -07002048void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002049 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002050 XFA_ATTRIBUTE eAttribute) {
2051 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002052 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002053 return;
2054 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002055
tsepezd19e9122016-11-02 15:43:18 -07002056 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002057 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002058 pValue->SetNull();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002059 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002060 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002061 pValue->SetString(
2062 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002063}
dsinclair5b36f0a2016-07-19 10:56:23 -07002064
dsinclair12a6b0c2016-05-26 11:14:08 -07002065void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002066 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002067 XFA_ATTRIBUTE eAttribute) {
2068 if (bSetting) {
2069 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002070 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002071 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002072
tsepezb4c9f3f2016-04-13 15:41:21 -07002073 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002074 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002075 CFX_WideString wsFormatValue(wsNewValue);
2076 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2077 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002078 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002079 }
tsepezd19e9122016-11-02 15:43:18 -07002080 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002081 } else {
tsepezd19e9122016-11-02 15:43:18 -07002082 CFX_WideString wsValue = GetScriptContent(true);
dsinclairf27aeec2016-06-07 19:36:18 -07002083 pValue->SetBoolean(wsValue == FX_WSTRC(L"1"));
Dan Sinclair1770c022016-03-14 14:14:16 -04002084 }
2085}
dsinclair2f5582f2016-06-09 11:48:23 -07002086
dsinclair12a6b0c2016-05-26 11:14:08 -07002087void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002088 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002089 XFA_ATTRIBUTE eAttribute) {
2090 CXFA_WidgetData* pWidgetData = GetWidgetData();
2091 if (!pWidgetData) {
2092 return;
2093 }
tsepezd19e9122016-11-02 15:43:18 -07002094 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002095 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002096 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002097 int32_t r = 0;
2098 int32_t g = 0;
2099 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002100 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002101 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2102 for (int32_t i = 0; i < iSize; ++i) {
2103 CXFA_Edge edge = border.GetEdge(i);
2104 edge.SetColor(rgb);
2105 }
2106 } else {
2107 CXFA_Edge edge = border.GetEdge(0);
2108 FX_ARGB color = edge.GetColor();
2109 int32_t a, r, g, b;
2110 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002111 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002112 strColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002113 pValue->SetString(FX_UTF8Encode(strColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002114 }
2115}
dsinclair5b36f0a2016-07-19 10:56:23 -07002116
dsinclair12a6b0c2016-05-26 11:14:08 -07002117void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002118 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002119 XFA_ATTRIBUTE eAttribute) {
2120 CXFA_WidgetData* pWidgetData = GetWidgetData();
2121 if (!pWidgetData) {
2122 return;
2123 }
tsepezd19e9122016-11-02 15:43:18 -07002124 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002125 int32_t iSize = border.CountEdges();
2126 CFX_WideString wsThickness;
2127 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002128 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002129 for (int32_t i = 0; i < iSize; ++i) {
2130 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002131 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002132 edge.SetMSThickness(thickness);
2133 }
2134 } else {
2135 CXFA_Edge edge = border.GetEdge(0);
2136 CXFA_Measurement thickness = edge.GetMSThickness();
2137 thickness.ToString(wsThickness);
dsinclairf27aeec2016-06-07 19:36:18 -07002138 pValue->SetString(FX_UTF8Encode(wsThickness).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002139 }
2140}
dsinclair5b36f0a2016-07-19 10:56:23 -07002141
dsinclair12a6b0c2016-05-26 11:14:08 -07002142void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002143 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002144 XFA_ATTRIBUTE eAttribute) {
2145 CXFA_WidgetData* pWidgetData = GetWidgetData();
2146 if (!pWidgetData) {
2147 return;
2148 }
tsepezd19e9122016-11-02 15:43:18 -07002149 CXFA_Border border = pWidgetData->GetBorder(true);
2150 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002151 CXFA_Node* pNode = borderfill.GetNode();
2152 if (!pNode) {
2153 return;
2154 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002155 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002156 int32_t r;
2157 int32_t g;
2158 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002159 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002160 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2161 borderfill.SetColor(color);
2162 } else {
2163 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002164 int32_t a;
2165 int32_t r;
2166 int32_t g;
2167 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002168 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002169 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002170 wsColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002171 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002172 }
2173}
dsinclair5b36f0a2016-07-19 10:56:23 -07002174
dsinclair12a6b0c2016-05-26 11:14:08 -07002175void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002176 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002177 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002178 if (bSetting) {
2179 ThrowInvalidPropertyException();
2180 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002181 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002182
2183 CXFA_Node* pDataNode = GetBindData();
2184 if (!pDataNode) {
2185 pValue->SetNull();
2186 return;
2187 }
2188
2189 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002190}
dsinclair5b36f0a2016-07-19 10:56:23 -07002191
dsinclair12a6b0c2016-05-26 11:14:08 -07002192void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002193 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002194 XFA_ATTRIBUTE eAttribute) {
2195 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002196 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002197 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002198 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002199 XFA_Element uiType = pWidgetData->GetUIType();
2200 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002201 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002202 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002203 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002204 }
2205 }
2206 } else {
tsepezd19e9122016-11-02 15:43:18 -07002207 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002208 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002209 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002210 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002211 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002212 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002213 }
2214 }
2215}
dsinclair5b36f0a2016-07-19 10:56:23 -07002216
dsinclair12a6b0c2016-05-26 11:14:08 -07002217void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002218 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002219 XFA_ATTRIBUTE eAttribute) {
2220 CXFA_WidgetData* pWidgetData = GetWidgetData();
2221 if (!pWidgetData) {
2222 return;
2223 }
2224 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002225 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002226 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002227 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002228 } else {
2229 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002230 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002231 }
dsinclair2f5582f2016-06-09 11:48:23 -07002232 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002233 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002234 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002235
Dan Sinclair1770c022016-03-14 14:14:16 -04002236 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002237 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002238 int32_t iLeadDigits = 0;
2239 int32_t iFracDigits = 0;
2240 pWidgetData->GetLeadDigits(iLeadDigits);
2241 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002242 wsNewText =
2243 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002244 }
2245 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2246 CFX_WideString wsFormatText(wsNewText);
2247 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002248 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002249 }
tsepezd19e9122016-11-02 15:43:18 -07002250 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002251 } else {
tsepezd19e9122016-11-02 15:43:18 -07002252 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002253 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002254 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002255 } else {
2256 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002257 CXFA_Value defVal = pWidgetData->GetFormValue();
2258 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002259 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002260 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002261 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002262 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002263 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002264 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002265 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002266 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002267 }
dsinclair070fcdf2016-06-22 22:04:54 -07002268 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002269 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002270 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002271 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002272 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002273 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002274 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002275 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002276 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002277 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002278 }
2279 }
2280 }
2281}
dsinclair5b36f0a2016-07-19 10:56:23 -07002282
dsinclair12a6b0c2016-05-26 11:14:08 -07002283void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002284 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002285 XFA_ATTRIBUTE eAttribute) {
2286 CXFA_WidgetData* pWidgetData = GetWidgetData();
2287 if (!pWidgetData) {
2288 return;
2289 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002290 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002291 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002292 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002293 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002294 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
dsinclairf27aeec2016-06-07 19:36:18 -07002295 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002296 }
2297}
dsinclair5b36f0a2016-07-19 10:56:23 -07002298
dsinclair12a6b0c2016-05-26 11:14:08 -07002299void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002300 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002301 XFA_ATTRIBUTE eAttribute) {
2302 CXFA_WidgetData* pWidgetData = GetWidgetData();
2303 if (!pWidgetData) {
2304 return;
2305 }
tsepezd19e9122016-11-02 15:43:18 -07002306 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002307 CXFA_Node* pNode = font.GetNode();
2308 if (!pNode) {
2309 return;
2310 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002311 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002312 int32_t r;
2313 int32_t g;
2314 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002315 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002316 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2317 font.SetColor(color);
2318 } else {
2319 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002320 int32_t a;
2321 int32_t r;
2322 int32_t g;
2323 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002324 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002325 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002326 wsColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002327 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002328 }
2329}
dsinclair5b36f0a2016-07-19 10:56:23 -07002330
dsinclair12a6b0c2016-05-26 11:14:08 -07002331void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002332 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002333 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002334 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002335}
dsinclair5b36f0a2016-07-19 10:56:23 -07002336
dsinclair12a6b0c2016-05-26 11:14:08 -07002337void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002338 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002339 XFA_ATTRIBUTE eAttribute) {
2340 CXFA_WidgetData* pWidgetData = GetWidgetData();
2341 if (!pWidgetData) {
2342 return;
2343 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002344 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002345 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002346 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002347 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002348 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
dsinclairf27aeec2016-06-07 19:36:18 -07002349 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002350 }
2351}
dsinclair5b36f0a2016-07-19 10:56:23 -07002352
dsinclair12a6b0c2016-05-26 11:14:08 -07002353void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002354 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002355 XFA_ATTRIBUTE eAttribute) {
2356 CXFA_WidgetData* pWidgetData = GetWidgetData();
2357 if (!pWidgetData) {
2358 return;
2359 }
tsepezd19e9122016-11-02 15:43:18 -07002360 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002361 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002362 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002363 } else {
2364 int32_t iValue = validate.GetNullTest();
2365 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002366 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002367 CFX_WideString wsValue;
2368 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002369 wsValue = pInfo->pName;
dsinclairf27aeec2016-06-07 19:36:18 -07002370 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002371 }
2372}
dsinclair5b36f0a2016-07-19 10:56:23 -07002373
dsinclair12a6b0c2016-05-26 11:14:08 -07002374void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002375 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002376 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002377 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002378}
dsinclair5b36f0a2016-07-19 10:56:23 -07002379
dsinclair12a6b0c2016-05-26 11:14:08 -07002380void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002381 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002382 XFA_ATTRIBUTE eAttribute) {
2383 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002384 ThrowInvalidPropertyException();
2385 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002386 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002387 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002388}
dsinclair5b36f0a2016-07-19 10:56:23 -07002389
dsinclair12a6b0c2016-05-26 11:14:08 -07002390void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002391 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002392 XFA_ATTRIBUTE eAttribute) {
2393 CXFA_WidgetData* pWidgetData = GetWidgetData();
2394 if (!pWidgetData) {
2395 return;
2396 }
2397 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002398 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002399 if (iIndex == -1) {
2400 pWidgetData->ClearAllSelections();
2401 return;
2402 }
tsepezd19e9122016-11-02 15:43:18 -07002403 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002404 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002405 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002406 }
2407}
dsinclair5b36f0a2016-07-19 10:56:23 -07002408
Dan Sinclair1770c022016-03-14 14:14:16 -04002409void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2410 CXFA_WidgetData* pWidgetData = GetWidgetData();
2411 if (!pWidgetData) {
2412 return;
2413 }
tsepezd19e9122016-11-02 15:43:18 -07002414 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002415}
dsinclair5b36f0a2016-07-19 10:56:23 -07002416
Dan Sinclair1770c022016-03-14 14:14:16 -04002417void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002418 if (pArguments->GetLength() != 1) {
2419 ThrowParamCountMismatchException(L"execEvent");
2420 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002421 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002422
2423 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2424 int32_t iRet = execSingleEventByName(
2425 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2426 XFA_Element::Field);
2427 if (eventString != "validate")
2428 return;
2429
2430 pArguments->GetReturnValue()->SetBoolean(
2431 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002432}
dsinclair5b36f0a2016-07-19 10:56:23 -07002433
Dan Sinclair1770c022016-03-14 14:14:16 -04002434void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002435 if (pArguments->GetLength() != 0) {
2436 ThrowParamCountMismatchException(L"execInitialize");
2437 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002438 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002439
2440 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2441 if (!pNotify)
2442 return;
2443
2444 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002445}
dsinclair5b36f0a2016-07-19 10:56:23 -07002446
Dan Sinclair1770c022016-03-14 14:14:16 -04002447void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2448 int32_t iLength = pArguments->GetLength();
2449 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002450 ThrowParamCountMismatchException(L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002451 return;
2452 }
2453 CXFA_WidgetData* pWidgetData = GetWidgetData();
2454 if (!pWidgetData) {
2455 return;
2456 }
2457 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002458 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002459 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002460 if (pValue)
2461 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002462}
dsinclair5b36f0a2016-07-19 10:56:23 -07002463
Dan Sinclair1770c022016-03-14 14:14:16 -04002464void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2465 int32_t iLength = pArguments->GetLength();
2466 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002467 ThrowParamCountMismatchException(L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002468 return;
2469 }
2470 int32_t iIndex = pArguments->GetInt32(0);
2471 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002472 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002473 return;
2474 }
2475 CXFA_WidgetData* pWidgetData = GetWidgetData();
2476 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002477 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002478 return;
2479 }
2480 CFX_WideString wsValue;
tsepezd19e9122016-11-02 15:43:18 -07002481 bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002482 if (bHasItem) {
dsinclairf27aeec2016-06-07 19:36:18 -07002483 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002484 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002485 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002486 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002487 }
2488}
dsinclair5b36f0a2016-07-19 10:56:23 -07002489
Dan Sinclair1770c022016-03-14 14:14:16 -04002490void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2491 int32_t iLength = pArguments->GetLength();
2492 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002493 ThrowParamCountMismatchException(L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002494 return;
2495 }
2496 CXFA_WidgetData* pWidgetData = GetWidgetData();
2497 if (!pWidgetData) {
2498 return;
2499 }
2500 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002501 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002502 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002503 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002504 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002505 if (pValue)
2506 pValue->SetString(FX_UTF8Encode(wsBoundValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002507}
dsinclair5b36f0a2016-07-19 10:56:23 -07002508
Dan Sinclair1770c022016-03-14 14:14:16 -04002509void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2510 int32_t iLength = pArguments->GetLength();
2511 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002512 ThrowParamCountMismatchException(L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002513 return;
2514 }
2515 CXFA_WidgetData* pWidgetData = GetWidgetData();
2516 if (!pWidgetData) {
2517 return;
2518 }
2519 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002520 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002521 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002522 if (pValue)
2523 pValue->SetBoolean(bValue);
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_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002527 if (pArguments->GetLength() != 0) {
2528 ThrowParamCountMismatchException(L"execCalculate");
2529 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002530 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002531
2532 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2533 if (!pNotify)
2534 return;
2535
2536 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002537}
dsinclair5b36f0a2016-07-19 10:56:23 -07002538
Dan Sinclair1770c022016-03-14 14:14:16 -04002539void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002540
Dan Sinclair1770c022016-03-14 14:14:16 -04002541void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2542 int32_t iLength = pArguments->GetLength();
2543 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002544 ThrowParamCountMismatchException(L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002545 return;
2546 }
2547 int32_t iIndex = pArguments->GetInt32(0);
2548 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002549 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002550 return;
2551 }
2552 CXFA_WidgetData* pWidgetData = GetWidgetData();
2553 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002554 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002555 return;
2556 }
2557 CFX_WideString wsValue;
tsepezd19e9122016-11-02 15:43:18 -07002558 bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002559 if (bHasItem) {
dsinclairf27aeec2016-06-07 19:36:18 -07002560 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002561 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002562 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002563 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002564 }
2565}
dsinclair5b36f0a2016-07-19 10:56:23 -07002566
Dan Sinclair1770c022016-03-14 14:14:16 -04002567void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2568 int32_t iLength = pArguments->GetLength();
2569 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002570 ThrowParamCountMismatchException(L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002571 return;
2572 }
2573 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002574 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002575 return;
thestig800222e2016-05-26 22:00:29 -07002576
Dan Sinclair1770c022016-03-14 14:14:16 -04002577 int32_t iIndex = pArguments->GetInt32(0);
2578 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002579 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002580 } else {
thestig800222e2016-05-26 22:00:29 -07002581 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002582 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002583 }
2584}
dsinclair5b36f0a2016-07-19 10:56:23 -07002585
Dan Sinclair1770c022016-03-14 14:14:16 -04002586void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2587 int32_t iLength = pArguments->GetLength();
2588 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002589 ThrowParamCountMismatchException(L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002590 return;
2591 }
2592 CXFA_WidgetData* pWidgetData = GetWidgetData();
2593 if (!pWidgetData) {
2594 return;
2595 }
2596 CFX_WideString wsLabel;
2597 CFX_WideString wsValue;
2598 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002599 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002600 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002601 }
2602 if (iLength >= 2) {
2603 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002604 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002605 }
tsepezd19e9122016-11-02 15:43:18 -07002606 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002607}
dsinclair5b36f0a2016-07-19 10:56:23 -07002608
Dan Sinclair1770c022016-03-14 14:14:16 -04002609void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002610 if (pArguments->GetLength() != 0) {
2611 ThrowParamCountMismatchException(L"execValidate");
2612 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002613 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002614
2615 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2616 if (!pNotify) {
2617 pArguments->GetReturnValue()->SetBoolean(false);
2618 return;
2619 }
2620
2621 int32_t iRet =
2622 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
2623 pArguments->GetReturnValue()->SetBoolean(
2624 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002625}
dsinclair5b36f0a2016-07-19 10:56:23 -07002626
dsinclair12a6b0c2016-05-26 11:14:08 -07002627void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002628 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002629 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002630 if (bSetting)
2631 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002632}
dsinclair5b36f0a2016-07-19 10:56:23 -07002633
dsinclair12a6b0c2016-05-26 11:14:08 -07002634void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002635 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002636 XFA_ATTRIBUTE eAttribute) {
2637 CXFA_WidgetData* pWidgetData = GetWidgetData();
2638 if (!pWidgetData) {
2639 return;
2640 }
2641 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002642 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002643 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002644 } else {
tsepezd19e9122016-11-02 15:43:18 -07002645 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002646 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2647 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002648 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002649 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002650 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002651 }
2652 }
2653}
dsinclair5b36f0a2016-07-19 10:56:23 -07002654
dsinclair12a6b0c2016-05-26 11:14:08 -07002655void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002656 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002657 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002658
Dan Sinclair1770c022016-03-14 14:14:16 -04002659void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002660 if (pArguments->GetLength() != 1) {
2661 ThrowParamCountMismatchException(L"execEvent");
2662 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002663 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002664
2665 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2666 execSingleEventByName(
2667 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2668 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002669}
thestig800222e2016-05-26 22:00:29 -07002670
Dan Sinclair1770c022016-03-14 14:14:16 -04002671void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2672 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002673 if (argc < 0 || argc > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002674 ThrowParamCountMismatchException(L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002675 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002676 }
thestig800222e2016-05-26 22:00:29 -07002677
2678 CXFA_WidgetData* pWidgetData = GetWidgetData();
2679 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002680 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002681 return;
2682 }
2683
2684 CXFA_Node* pReturnNode = nullptr;
2685 if (argc == 0) {
2686 pReturnNode = pWidgetData->GetSelectedMember();
2687 } else {
2688 CFX_ByteString szName;
2689 szName = pArguments->GetUTF8String(0);
2690 pReturnNode = pWidgetData->SetSelectedMember(
2691 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2692 }
2693 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002694 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002695 return;
2696 }
dsinclairf27aeec2016-06-07 19:36:18 -07002697 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002698 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002699}
thestig800222e2016-05-26 22:00:29 -07002700
Dan Sinclair1770c022016-03-14 14:14:16 -04002701void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002702 if (pArguments->GetLength() != 0) {
2703 ThrowParamCountMismatchException(L"execInitialize");
2704 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002705 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002706
2707 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2708 if (!pNotify)
2709 return;
2710
2711 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002712}
dsinclair5b36f0a2016-07-19 10:56:23 -07002713
Dan Sinclair1770c022016-03-14 14:14:16 -04002714void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002715 if (pArguments->GetLength() != 0) {
2716 ThrowParamCountMismatchException(L"execCalculate");
2717 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002718 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002719
2720 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2721 if (!pNotify)
2722 return;
2723
2724 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002725}
dsinclair5b36f0a2016-07-19 10:56:23 -07002726
Dan Sinclair1770c022016-03-14 14:14:16 -04002727void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002728 if (pArguments->GetLength() != 0) {
2729 ThrowParamCountMismatchException(L"execValidate");
2730 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002731 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002732
2733 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2734 if (!pNotify) {
2735 pArguments->GetReturnValue()->SetBoolean(false);
2736 return;
2737 }
2738
2739 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2740 pArguments->GetReturnValue()->SetBoolean(
2741 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002742}
dsinclair5b36f0a2016-07-19 10:56:23 -07002743
dsinclair12a6b0c2016-05-26 11:14:08 -07002744void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002745 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002746 XFA_ATTRIBUTE eAttribute) {
2747 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002748 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002749 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002750 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002751 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2752 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002753 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002754 pManagerNode = pNode;
2755 break;
2756 }
2757 }
2758 if (pManagerNode) {
2759 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002760 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002761 if (!pNotify) {
2762 return;
2763 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002764 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002765 if (pToInstance &&
2766 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002767 pNotify->RunSubformIndexChange(pToInstance);
2768 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002769 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002770 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002771 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002772 pNotify->RunSubformIndexChange(pFromInstance);
2773 }
2774 }
2775 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002776 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002777 }
2778}
dsinclair5b36f0a2016-07-19 10:56:23 -07002779
dsinclair12a6b0c2016-05-26 11:14:08 -07002780void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002781 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002782 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002783 if (bSetting) {
2784 ThrowInvalidPropertyException();
2785 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002786 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002787
2788 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2789 CXFA_Node* pInstanceMgr = nullptr;
2790 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2791 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2792 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2793 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2794 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2795 wsInstMgrName.Mid(1) == wsName) {
2796 pInstanceMgr = pNode;
2797 }
2798 break;
2799 }
2800 }
2801 if (!pInstanceMgr) {
2802 pValue->SetNull();
2803 return;
2804 }
2805
2806 pValue->Assign(
2807 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
Dan Sinclair1770c022016-03-14 14:14:16 -04002808}
dsinclair5b36f0a2016-07-19 10:56:23 -07002809
dsinclair12a6b0c2016-05-26 11:14:08 -07002810void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002811 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002812 XFA_ATTRIBUTE eAttribute) {
2813 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002814 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002815 } else {
2816 CFX_WideString wsLocaleName;
2817 GetLocaleName(wsLocaleName);
dsinclairf27aeec2016-06-07 19:36:18 -07002818 pValue->SetString(
2819 FX_UTF8Encode(wsLocaleName.c_str(), wsLocaleName.GetLength())
2820 .AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002821 }
2822}
dsinclair5b36f0a2016-07-19 10:56:23 -07002823
Dan Sinclair1770c022016-03-14 14:14:16 -04002824void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002825 if (pArguments->GetLength() != 1) {
2826 ThrowParamCountMismatchException(L"execEvent");
2827 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002828 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002829
2830 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2831 execSingleEventByName(
2832 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2833 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002834}
dsinclair5b36f0a2016-07-19 10:56:23 -07002835
Dan Sinclair1770c022016-03-14 14:14:16 -04002836void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002837 if (pArguments->GetLength() != 0) {
2838 ThrowParamCountMismatchException(L"execInitialize");
2839 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002840 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002841
2842 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2843 if (!pNotify)
2844 return;
2845
2846 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002847}
dsinclair5b36f0a2016-07-19 10:56:23 -07002848
Dan Sinclair1770c022016-03-14 14:14:16 -04002849void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002850 if (pArguments->GetLength() != 0) {
2851 ThrowParamCountMismatchException(L"execCalculate");
2852 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002853 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002854
2855 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2856 if (!pNotify)
2857 return;
2858
2859 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
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_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002863 if (pArguments->GetLength() != 0) {
2864 ThrowParamCountMismatchException(L"execValidate");
2865 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002866 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002867
2868 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2869 if (!pNotify) {
2870 pArguments->GetReturnValue()->SetBoolean(false);
2871 return;
2872 }
2873
2874 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2875 pArguments->GetReturnValue()->SetBoolean(
2876 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002877}
dsinclair5b36f0a2016-07-19 10:56:23 -07002878
Dan Sinclair1770c022016-03-14 14:14:16 -04002879void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002880 if (pArguments->GetLength() != 0)
2881 ThrowParamCountMismatchException(L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002882}
dsinclair5b36f0a2016-07-19 10:56:23 -07002883
Dan Sinclair1770c022016-03-14 14:14:16 -04002884int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2885 int32_t index = 0;
2886 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2887 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002888 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2889 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002890 index++;
2891 } else {
2892 break;
2893 }
2894 }
2895 return index;
2896}
dsinclair5b36f0a2016-07-19 10:56:23 -07002897
Dan Sinclair1770c022016-03-14 14:14:16 -04002898void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002899 if (pArguments->GetLength() != 1) {
2900 ThrowParamCountMismatchException(L"formNodes");
2901 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002902 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002903 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002904}
dsinclair5b36f0a2016-07-19 10:56:23 -07002905
Dan Sinclair1770c022016-03-14 14:14:16 -04002906void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002907 if (pArguments->GetLength() != 0) {
2908 ThrowParamCountMismatchException(L"remerge");
2909 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002910 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002911 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002912}
dsinclair5b36f0a2016-07-19 10:56:23 -07002913
Dan Sinclair1770c022016-03-14 14:14:16 -04002914void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002915 if (pArguments->GetLength() != 0) {
2916 ThrowParamCountMismatchException(L"execInitialize");
2917 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002918 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002919
2920 CXFA_WidgetData* pWidgetData = GetWidgetData();
2921 if (!pWidgetData) {
2922 pArguments->GetReturnValue()->SetBoolean(false);
2923 return;
2924 }
2925 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002926}
dsinclair5b36f0a2016-07-19 10:56:23 -07002927
Dan Sinclair1770c022016-03-14 14:14:16 -04002928void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2929 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002930 if (argc <= 0 || argc >= 4) {
2931 ThrowParamCountMismatchException(L"createNode");
2932 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002933 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002934
2935 CFX_WideString strName;
2936 CFX_WideString strNameSpace;
2937 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
2938 CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
2939 if (argc > 1) {
2940 CFX_ByteString bsName = pArguments->GetUTF8String(1);
2941 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
2942 if (argc == 3) {
2943 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
2944 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
2945 }
2946 }
2947
2948 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2949 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
2950 if (!pNewNode) {
2951 pArguments->GetReturnValue()->SetNull();
2952 return;
2953 }
2954
2955 if (strName.IsEmpty()) {
2956 pArguments->GetReturnValue()->Assign(
2957 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2958 return;
2959 }
2960
2961 if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2962 XFA_XDPPACKET_UNKNOWN)) {
2963 ThrowMissingPropertyException(strTagName, L"name");
2964 return;
2965 }
2966
2967 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
2968 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets)
2969 pNewNode->CreateXMLMappingNode();
2970
2971 pArguments->GetReturnValue()->Assign(
2972 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002973}
dsinclair5b36f0a2016-07-19 10:56:23 -07002974
Dan Sinclair1770c022016-03-14 14:14:16 -04002975void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002976 if (pArguments->GetLength() != 1) {
2977 ThrowParamCountMismatchException(L"recalculate");
2978 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002979 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002980 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002981}
dsinclair5b36f0a2016-07-19 10:56:23 -07002982
Dan Sinclair1770c022016-03-14 14:14:16 -04002983void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002984 if (pArguments->GetLength() != 0) {
2985 ThrowParamCountMismatchException(L"execCalculate");
2986 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002987 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002988
2989 CXFA_WidgetData* pWidgetData = GetWidgetData();
2990 if (!pWidgetData) {
2991 pArguments->GetReturnValue()->SetBoolean(false);
2992 return;
2993 }
2994 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002995}
dsinclair5b36f0a2016-07-19 10:56:23 -07002996
Dan Sinclair1770c022016-03-14 14:14:16 -04002997void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002998 if (pArguments->GetLength() != 0) {
2999 ThrowParamCountMismatchException(L"execValidate");
3000 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003001 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003002 CXFA_WidgetData* pWidgetData = GetWidgetData();
3003 if (!pWidgetData) {
3004 pArguments->GetReturnValue()->SetBoolean(false);
3005 return;
3006 }
3007 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003008}
dsinclair5b36f0a2016-07-19 10:56:23 -07003009
Dan Sinclair1770c022016-03-14 14:14:16 -04003010void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003011 if (pArguments->GetLength() != 0) {
3012 ThrowParamCountMismatchException(L"evaluate");
3013 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003014 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003015
3016 CXFA_WidgetData* pWidgetData = GetWidgetData();
3017 if (!pWidgetData) {
3018 pArguments->GetReturnValue()->SetBoolean(false);
3019 return;
3020 }
3021 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003022}
dsinclair5b36f0a2016-07-19 10:56:23 -07003023
dsinclair12a6b0c2016-05-26 11:14:08 -07003024void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003025 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003026 XFA_ATTRIBUTE eAttribute) {
3027 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003028 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003029 return;
3030 }
3031 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003032 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003033}
dsinclair5b36f0a2016-07-19 10:56:23 -07003034
dsinclair12a6b0c2016-05-26 11:14:08 -07003035void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003036 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003037 XFA_ATTRIBUTE eAttribute) {
3038 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003039 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003040 return;
3041 }
3042 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003043 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003044}
tsepezaadedf92016-05-12 10:08:06 -07003045
dsinclair12a6b0c2016-05-26 11:14:08 -07003046void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003047 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003048 XFA_ATTRIBUTE eAttribute) {
3049 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003050 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003051 InstanceManager_SetInstances(iDesired);
3052 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07003053 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04003054 }
3055}
dsinclair5b36f0a2016-07-19 10:56:23 -07003056
Dan Sinclair1770c022016-03-14 14:14:16 -04003057void CXFA_Node::Script_InstanceManager_MoveInstance(
3058 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003059 if (pArguments->GetLength() != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003060 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003061 return;
3062 }
3063 int32_t iFrom = pArguments->GetInt32(0);
3064 int32_t iTo = pArguments->GetInt32(1);
3065 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003066 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003067 if (!pNotify) {
3068 return;
3069 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003070 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003071 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003072 pNotify->RunSubformIndexChange(pToInstance);
3073 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003074 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003075 if (pFromInstance &&
3076 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003077 pNotify->RunSubformIndexChange(pFromInstance);
3078 }
3079}
dsinclair5b36f0a2016-07-19 10:56:23 -07003080
Dan Sinclair1770c022016-03-14 14:14:16 -04003081void CXFA_Node::Script_InstanceManager_RemoveInstance(
3082 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003083 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003084 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003085 return;
3086 }
3087 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003088 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003089 if (iIndex < 0 || iIndex >= iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003090 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003091 return;
3092 }
3093 CXFA_Occur nodeOccur(GetOccurNode());
3094 int32_t iMin = nodeOccur.GetMin();
3095 if (iCount - 1 < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003096 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003097 return;
3098 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003099 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3100 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003101 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003102 if (pNotify) {
3103 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003104 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003105 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003106 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003107 pNotify->RunSubformIndexChange(pSubformInstance);
3108 }
3109 }
3110 }
3111 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3112 if (!pLayoutPro) {
3113 return;
3114 }
3115 pLayoutPro->AddChangedContainer(
3116 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3117}
dsinclair5b36f0a2016-07-19 10:56:23 -07003118
Dan Sinclair1770c022016-03-14 14:14:16 -04003119void CXFA_Node::Script_InstanceManager_SetInstances(
3120 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003121 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003122 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003123 return;
3124 }
3125 int32_t iDesired = pArguments->GetInt32(0);
3126 InstanceManager_SetInstances(iDesired);
3127}
dsinclair5b36f0a2016-07-19 10:56:23 -07003128
Dan Sinclair1770c022016-03-14 14:14:16 -04003129void CXFA_Node::Script_InstanceManager_AddInstance(
3130 CFXJSE_Arguments* pArguments) {
3131 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003132 if (argc != 0 && argc != 1) {
3133 ThrowParamCountMismatchException(L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003134 return;
3135 }
tsepezd19e9122016-11-02 15:43:18 -07003136 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003137 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003138 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003139 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003140 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003141 CXFA_Occur nodeOccur(GetOccurNode());
3142 int32_t iMax = nodeOccur.GetMax();
3143 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003144 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003145 return;
3146 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003147 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003148 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003149 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003150 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003151 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003152 if (!pNotify) {
3153 return;
3154 }
3155 pNotify->RunNodeInitialize(pNewInstance);
3156 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3157 if (!pLayoutPro) {
3158 return;
3159 }
3160 pLayoutPro->AddChangedContainer(
3161 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3162}
dsinclair5b36f0a2016-07-19 10:56:23 -07003163
Dan Sinclair1770c022016-03-14 14:14:16 -04003164void CXFA_Node::Script_InstanceManager_InsertInstance(
3165 CFXJSE_Arguments* pArguments) {
3166 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003167 if (argc != 1 && argc != 2) {
3168 ThrowParamCountMismatchException(L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003169 return;
3170 }
3171 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003172 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003173 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003174 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003175 }
3176 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003177 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003178 if (iIndex < 0 || iIndex > iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003179 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003180 return;
3181 }
3182 int32_t iMax = nodeOccur.GetMax();
3183 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003184 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003185 return;
3186 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003187 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003188 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003189 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003190 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003191 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003192 if (!pNotify) {
3193 return;
3194 }
3195 pNotify->RunNodeInitialize(pNewInstance);
3196 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3197 if (!pLayoutPro) {
3198 return;
3199 }
3200 pLayoutPro->AddChangedContainer(
3201 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3202}
dsinclair5b36f0a2016-07-19 10:56:23 -07003203
Dan Sinclair1770c022016-03-14 14:14:16 -04003204int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3205 CXFA_Occur nodeOccur(GetOccurNode());
3206 int32_t iMax = nodeOccur.GetMax();
3207 int32_t iMin = nodeOccur.GetMin();
3208 if (iDesired < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003209 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003210 return 1;
3211 }
3212 if ((iMax >= 0) && (iDesired > iMax)) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003213 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003214 return 2;
3215 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003216 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003217 if (iDesired == iCount) {
3218 return 0;
3219 }
3220 if (iDesired < iCount) {
3221 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003222 CFX_WideString wsInstanceName =
3223 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3224 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003225 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003226 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003227 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003228 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003229 while (iCount > iDesired) {
3230 CXFA_Node* pRemoveInstance =
3231 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003232 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3233 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003234 continue;
3235 }
dsinclair070fcdf2016-06-22 22:04:54 -07003236 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003237 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003238 break;
3239 }
3240 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003241 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003242 iCount--;
3243 }
3244 }
3245 } else if (iDesired > iCount) {
3246 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003247 CXFA_Node* pNewInstance = CreateInstance(this, true);
3248 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003249 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003250 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003251 if (!pNotify) {
3252 return 0;
3253 }
3254 pNotify->RunNodeInitialize(pNewInstance);
3255 }
3256 }
3257 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3258 if (pLayoutPro) {
3259 pLayoutPro->AddChangedContainer(
3260 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3261 }
3262 return 0;
3263}
dsinclair5b36f0a2016-07-19 10:56:23 -07003264
Dan Sinclair1770c022016-03-14 14:14:16 -04003265int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003266 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003267 if (iFrom > iCount || iTo > iCount - 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003268 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003269 return 1;
3270 }
3271 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3272 return 0;
3273 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003274 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003275 RemoveItem(this, pMoveInstance, false);
3276 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003277 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3278 if (pLayoutPro) {
3279 pLayoutPro->AddChangedContainer(
3280 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3281 }
3282 return 0;
3283}
dsinclair5b36f0a2016-07-19 10:56:23 -07003284
dsinclair12a6b0c2016-05-26 11:14:08 -07003285void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003286 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003287 XFA_ATTRIBUTE eAttribute) {
3288 CXFA_Occur occur(this);
3289 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003290 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003291 occur.SetMax(iMax);
3292 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003293 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003294 }
3295}
dsinclair5b36f0a2016-07-19 10:56:23 -07003296
dsinclair12a6b0c2016-05-26 11:14:08 -07003297void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003298 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003299 XFA_ATTRIBUTE eAttribute) {
3300 CXFA_Occur occur(this);
3301 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003302 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003303 occur.SetMin(iMin);
3304 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003305 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003306 }
3307}
dsinclair5b36f0a2016-07-19 10:56:23 -07003308
Dan Sinclair1770c022016-03-14 14:14:16 -04003309void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3310 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003311 if (argc != 0 && argc != 1) {
3312 ThrowParamCountMismatchException(L"metadata");
3313 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003314 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003315 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003316}
dsinclair5b36f0a2016-07-19 10:56:23 -07003317
Dan Sinclair1770c022016-03-14 14:14:16 -04003318void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003319 if (pArguments->GetLength() != 1) {
3320 ThrowParamCountMismatchException(L"formNodes");
3321 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003322 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003323
3324 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3325 if (!pDataNode) {
3326 ThrowArgumentMismatchException();
3327 return;
3328 }
3329
3330 CXFA_NodeArray formItems;
3331 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3332 pFormNodes->SetArrayNodeList(formItems);
3333 pArguments->GetReturnValue()->SetObject(
3334 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003335}
dsinclair5b36f0a2016-07-19 10:56:23 -07003336
Dan Sinclair1770c022016-03-14 14:14:16 -04003337void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003338 if (pArguments->GetLength() != 0) {
3339 ThrowParamCountMismatchException(L"remerge");
3340 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003341 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003342
3343 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003344}
dsinclair5b36f0a2016-07-19 10:56:23 -07003345
Dan Sinclair1770c022016-03-14 14:14:16 -04003346void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003347 if (pArguments->GetLength() != 0) {
3348 ThrowParamCountMismatchException(L"execInitialize");
3349 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003350 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003351
3352 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3353 if (!pNotify)
3354 return;
3355
3356 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04003357}
dsinclair5b36f0a2016-07-19 10:56:23 -07003358
Dan Sinclair1770c022016-03-14 14:14:16 -04003359void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3360 CXFA_EventParam* pEventParam =
3361 m_pDocument->GetScriptContext()->GetEventParam();
3362 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3363 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3364 return;
3365 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003366 if (pArguments->GetLength() != 1) {
3367 ThrowParamCountMismatchException(L"recalculate");
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 if (pArguments->GetInt32(0) != 0)
3375 return;
3376
3377 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3378 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3379 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003380}
dsinclair5b36f0a2016-07-19 10:56:23 -07003381
Dan Sinclair1770c022016-03-14 14:14:16 -04003382void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003383 if (pArguments->GetLength() != 0) {
3384 ThrowParamCountMismatchException(L"execCalculate");
3385 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003386 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003387
3388 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3389 if (!pNotify)
3390 return;
3391
3392 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04003393}
dsinclair5b36f0a2016-07-19 10:56:23 -07003394
Dan Sinclair1770c022016-03-14 14:14:16 -04003395void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003396 if (pArguments->GetLength() != 0) {
3397 ThrowParamCountMismatchException(L"execValidate");
3398 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003399 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003400
3401 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3402 if (!pNotify) {
3403 pArguments->GetReturnValue()->SetBoolean(false);
3404 return;
3405 }
3406
3407 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3408 pArguments->GetReturnValue()->SetBoolean(
3409 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003410}
dsinclair5b36f0a2016-07-19 10:56:23 -07003411
dsinclair12a6b0c2016-05-26 11:14:08 -07003412void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003413 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003414 XFA_ATTRIBUTE eAttribute) {
3415 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003416 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003417 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003418 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003419
3420 CFX_WideString wsChecksum;
3421 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
3422 pValue->SetString(
3423 FX_UTF8Encode(wsChecksum.c_str(), wsChecksum.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003424}
dsinclair5b36f0a2016-07-19 10:56:23 -07003425
Dan Sinclair1770c022016-03-14 14:14:16 -04003426void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003427 if (pArguments->GetLength() != 1) {
3428 ThrowParamCountMismatchException(L"getAttribute");
3429 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003430 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003431
3432 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3433 CFX_WideString wsAttributeValue;
3434 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3435 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3436 static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3437 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(),
3438 wsAttributeValue);
3439 }
3440 pArguments->GetReturnValue()->SetString(
3441 FX_UTF8Encode(wsAttributeValue.c_str(), wsAttributeValue.GetLength())
3442 .AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003443}
dsinclair5b36f0a2016-07-19 10:56:23 -07003444
Dan Sinclair1770c022016-03-14 14:14:16 -04003445void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003446 if (pArguments->GetLength() != 2) {
3447 ThrowParamCountMismatchException(L"setAttribute");
3448 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003449 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003450
3451 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3452 CFX_ByteString bsName = pArguments->GetUTF8String(1);
3453 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3454 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3455 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(
3456 CFX_WideString::FromUTF8(bsName.AsStringC()),
3457 CFX_WideString::FromUTF8(bsValue.AsStringC()));
3458 }
3459 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003460}
dsinclair5b36f0a2016-07-19 10:56:23 -07003461
Dan Sinclair1770c022016-03-14 14:14:16 -04003462void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003463 if (pArguments->GetLength() != 1) {
3464 ThrowParamCountMismatchException(L"removeAttribute");
3465 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003466 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003467
3468 CFX_ByteString bsName = pArguments->GetUTF8String(0);
3469 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
3470 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3471 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3472 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
3473 if (pXMLElement->HasAttribute(wsName.c_str())) {
3474 pXMLElement->RemoveAttribute(wsName.c_str());
3475 }
3476 }
3477 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003478}
dsinclair5b36f0a2016-07-19 10:56:23 -07003479
dsinclair12a6b0c2016-05-26 11:14:08 -07003480void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003481 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003482 XFA_ATTRIBUTE eAttribute) {
3483 if (bSetting) {
dsinclairae95f762016-03-29 16:58:29 -07003484 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003485 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003486 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003487 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003488 }
3489 } else {
3490 CFX_WideString wsTextData;
dsinclairae95f762016-03-29 16:58:29 -07003491 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003492 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003493 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04003494 pXMLElement->GetTextData(wsTextData);
3495 }
dsinclairf27aeec2016-06-07 19:36:18 -07003496 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003497 FX_UTF8Encode(wsTextData.c_str(), wsTextData.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003498 }
3499}
dsinclair5b36f0a2016-07-19 10:56:23 -07003500
Dan Sinclair1770c022016-03-14 14:14:16 -04003501void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003502 if (pArguments->GetLength() != 0)
3503 ThrowParamCountMismatchException(L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003504}
dsinclair5b36f0a2016-07-19 10:56:23 -07003505
Dan Sinclair1770c022016-03-14 14:14:16 -04003506void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003507 if (pArguments->GetLength() != 0)
3508 ThrowParamCountMismatchException(L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003509}
dsinclair5b36f0a2016-07-19 10:56:23 -07003510
Dan Sinclair1770c022016-03-14 14:14:16 -04003511void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003512 if (pArguments->GetLength() != 0)
3513 ThrowParamCountMismatchException(L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003514}
dsinclair5b36f0a2016-07-19 10:56:23 -07003515
Dan Sinclair1770c022016-03-14 14:14:16 -04003516void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003517 if (pArguments->GetLength() != 0)
3518 ThrowParamCountMismatchException(L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003519}
dsinclair5b36f0a2016-07-19 10:56:23 -07003520
Dan Sinclair1770c022016-03-14 14:14:16 -04003521void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003522 if (pArguments->GetLength() != 0)
3523 ThrowParamCountMismatchException(L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003524}
dsinclair5b36f0a2016-07-19 10:56:23 -07003525
Dan Sinclair1770c022016-03-14 14:14:16 -04003526void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003527 if (pArguments->GetLength() != 0)
3528 ThrowParamCountMismatchException(L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003529}
dsinclair5b36f0a2016-07-19 10:56:23 -07003530
Dan Sinclair1770c022016-03-14 14:14:16 -04003531void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003532 if (pArguments->GetLength() != 0)
3533 ThrowParamCountMismatchException(L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003534}
dsinclair5b36f0a2016-07-19 10:56:23 -07003535
Dan Sinclair1770c022016-03-14 14:14:16 -04003536void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003537 if (pArguments->GetLength() != 0)
3538 ThrowParamCountMismatchException(L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003539}
dsinclair5b36f0a2016-07-19 10:56:23 -07003540
Dan Sinclair1770c022016-03-14 14:14:16 -04003541void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003542 if (pArguments->GetLength() != 0)
3543 ThrowParamCountMismatchException(L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003544}
dsinclair5b36f0a2016-07-19 10:56:23 -07003545
Dan Sinclair1770c022016-03-14 14:14:16 -04003546void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003547 if (pArguments->GetLength() != 0)
3548 ThrowParamCountMismatchException(L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003549}
dsinclair5b36f0a2016-07-19 10:56:23 -07003550
Dan Sinclair1770c022016-03-14 14:14:16 -04003551void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003552 if (pArguments->GetLength() != 0)
3553 ThrowParamCountMismatchException(L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003554}
dsinclair5b36f0a2016-07-19 10:56:23 -07003555
Dan Sinclair1770c022016-03-14 14:14:16 -04003556void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003557 if (pArguments->GetLength() != 0)
3558 ThrowParamCountMismatchException(L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003559}
dsinclair5b36f0a2016-07-19 10:56:23 -07003560
Dan Sinclair1770c022016-03-14 14:14:16 -04003561void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003562 if (pArguments->GetLength() != 0)
3563 ThrowParamCountMismatchException(L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003564}
dsinclair5b36f0a2016-07-19 10:56:23 -07003565
Dan Sinclair1770c022016-03-14 14:14:16 -04003566void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003567 if (pArguments->GetLength() != 0)
3568 ThrowParamCountMismatchException(L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003569}
dsinclair5b36f0a2016-07-19 10:56:23 -07003570
Dan Sinclair1770c022016-03-14 14:14:16 -04003571void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003572 if (pArguments->GetLength() != 0)
3573 ThrowParamCountMismatchException(L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003574}
dsinclair5b36f0a2016-07-19 10:56:23 -07003575
Dan Sinclair1770c022016-03-14 14:14:16 -04003576void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003577 if (pArguments->GetLength() != 0)
3578 ThrowParamCountMismatchException(L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003579}
dsinclair5b36f0a2016-07-19 10:56:23 -07003580
Dan Sinclair1770c022016-03-14 14:14:16 -04003581void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003582 if (pArguments->GetLength() != 0)
3583 ThrowParamCountMismatchException(L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003584}
dsinclair5b36f0a2016-07-19 10:56:23 -07003585
dsinclair12a6b0c2016-05-26 11:14:08 -07003586void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003587 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003588 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003589
dsinclair12a6b0c2016-05-26 11:14:08 -07003590void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003591 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003592 XFA_ATTRIBUTE eAttribute) {
3593 if (!bSetting) {
3594 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003595 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003596 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003597 }
3598}
dsinclair5b36f0a2016-07-19 10:56:23 -07003599
dsinclair12a6b0c2016-05-26 11:14:08 -07003600void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003601 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003602 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003603
dsinclair12a6b0c2016-05-26 11:14:08 -07003604void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003605 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003606 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003607
dsinclair12a6b0c2016-05-26 11:14:08 -07003608void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003609 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003610 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003611
dsinclair12a6b0c2016-05-26 11:14:08 -07003612void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003613 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003614 XFA_ATTRIBUTE eAttribute) {
3615 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003616 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003617 return;
3618 }
dsinclairf27aeec2016-06-07 19:36:18 -07003619 pValue->SetString(FX_UTF8Encode(FX_WSTRC(L"0")).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003620}
dsinclair5b36f0a2016-07-19 10:56:23 -07003621
dsinclair12a6b0c2016-05-26 11:14:08 -07003622void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003623 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003624 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003625
tsepezd19e9122016-11-02 15:43:18 -07003626bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003627 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003628 return HasMapModuleKey(pKey, bCanInherit);
3629}
dsinclair5b36f0a2016-07-19 10:56:23 -07003630
tsepezd19e9122016-11-02 15:43:18 -07003631bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3632 const CFX_WideStringC& wsValue,
3633 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003634 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003635 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003636 return false;
weili44f8faf2016-06-01 14:03:56 -07003637
Dan Sinclair1770c022016-03-14 14:14:16 -04003638 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3639 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3640 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003641 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003642 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3643 }
3644 switch (eType) {
3645 case XFA_ATTRIBUTETYPE_Enum: {
3646 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3647 return SetEnum(pAttr->eName,
3648 pEnum ? pEnum->eName
3649 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3650 bNotify);
3651 } break;
3652 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003653 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003654 case XFA_ATTRIBUTETYPE_Boolean:
3655 return SetBoolean(pAttr->eName, wsValue != FX_WSTRC(L"0"), bNotify);
3656 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003657 return SetInteger(pAttr->eName,
3658 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3659 wsValue.GetLength(), nullptr)),
3660 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003661 case XFA_ATTRIBUTETYPE_Measure:
3662 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3663 default:
3664 break;
3665 }
tsepezd19e9122016-11-02 15:43:18 -07003666 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003667}
dsinclair5b36f0a2016-07-19 10:56:23 -07003668
tsepezd19e9122016-11-02 15:43:18 -07003669bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3670 CFX_WideString& wsValue,
3671 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003672 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003673 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003674 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003675 }
3676 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3677 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3678 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003679 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003680 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3681 }
3682 switch (eType) {
3683 case XFA_ATTRIBUTETYPE_Enum: {
3684 XFA_ATTRIBUTEENUM eValue;
3685 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003686 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003687 }
dsinclair9eb0db12016-07-21 12:01:39 -07003688 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003689 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003690 } break;
3691 case XFA_ATTRIBUTETYPE_Cdata: {
3692 CFX_WideStringC wsValueC;
3693 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003694 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003695 }
3696 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003697 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003698 } break;
3699 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003700 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003701 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003702 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003703 }
3704 wsValue = bValue ? FX_WSTRC(L"1") : FX_WSTRC(L"0");
tsepezd19e9122016-11-02 15:43:18 -07003705 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003706 } break;
3707 case XFA_ATTRIBUTETYPE_Integer: {
3708 int32_t iValue;
3709 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003710 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003711 }
3712 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003713 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003714 } break;
3715 case XFA_ATTRIBUTETYPE_Measure: {
3716 CXFA_Measurement mValue;
3717 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003718 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003719 }
3720 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003721 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003722 } break;
3723 default:
3724 break;
3725 }
tsepezd19e9122016-11-02 15:43:18 -07003726 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003727}
dsinclair5b36f0a2016-07-19 10:56:23 -07003728
tsepezd19e9122016-11-02 15:43:18 -07003729bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3730 const CFX_WideStringC& wsValue,
3731 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003732 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3733 if (pAttributeInfo) {
3734 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3735 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003736 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003737 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003738 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003739}
dsinclair5b36f0a2016-07-19 10:56:23 -07003740
tsepezd19e9122016-11-02 15:43:18 -07003741bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3742 CFX_WideString& wsValue,
3743 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003744 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3745 if (pAttributeInfo) {
3746 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3747 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003748 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003749 CFX_WideStringC wsValueC;
3750 if (GetMapModuleString(pKey, wsValueC)) {
3751 wsValue = wsValueC;
3752 }
tsepezd19e9122016-11-02 15:43:18 -07003753 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003754}
dsinclair5b36f0a2016-07-19 10:56:23 -07003755
tsepezd19e9122016-11-02 15:43:18 -07003756bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003757 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003758 RemoveMapModuleKey(pKey);
tsepezd19e9122016-11-02 15:43:18 -07003759 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003760}
dsinclair5b36f0a2016-07-19 10:56:23 -07003761
tsepezd19e9122016-11-02 15:43:18 -07003762bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3763 bool& bValue,
3764 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003765 void* pValue = nullptr;
3766 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003767 return false;
tsepez478ed622016-10-27 14:32:33 -07003768 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003769 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003770}
dsinclair5b36f0a2016-07-19 10:56:23 -07003771
tsepezd19e9122016-11-02 15:43:18 -07003772bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3773 int32_t& iValue,
3774 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003775 void* pValue = nullptr;
3776 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003777 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003778 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003779 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003780}
dsinclair5b36f0a2016-07-19 10:56:23 -07003781
tsepezd19e9122016-11-02 15:43:18 -07003782bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3783 XFA_ATTRIBUTEENUM& eValue,
3784 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003785 void* pValue = nullptr;
3786 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003787 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003788 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003789 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003790}
thestigb1a59592016-04-14 18:29:56 -07003791
tsepezd19e9122016-11-02 15:43:18 -07003792bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3793 CXFA_Measurement mValue,
3794 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003795 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003796 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003797 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003798 OnChanged(eAttr, bNotify, false);
3799 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003800}
thestigb1a59592016-04-14 18:29:56 -07003801
tsepezd19e9122016-11-02 15:43:18 -07003802bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3803 CXFA_Measurement& mValue,
3804 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003805 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003806 void* pValue;
3807 int32_t iBytes;
3808 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
3809 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003810 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003811 }
3812 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003813 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003814 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
3815 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003816 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003817 }
tsepezd19e9122016-11-02 15:43:18 -07003818 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003819}
3820
3821CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3822 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003823 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003824}
3825
tsepezd19e9122016-11-02 15:43:18 -07003826bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3827 const CFX_WideString& wsValue,
3828 bool bNotify,
3829 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003830 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003831 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003832 if (eAttr == XFA_ATTRIBUTE_Value) {
3833 CFX_WideString* pClone = new CFX_WideString(wsValue);
3834 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3835 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003836 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003837 if (eAttr == XFA_ATTRIBUTE_Name)
3838 UpdateNameHash();
3839 }
thestigb1a59592016-04-14 18:29:56 -07003840 OnChanged(eAttr, bNotify, bScriptModify);
3841
3842 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3843 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003844 return true;
thestigb1a59592016-04-14 18:29:56 -07003845 }
3846
dsinclair070fcdf2016-06-22 22:04:54 -07003847 if (eAttr == XFA_ATTRIBUTE_Name &&
3848 (m_elementType == XFA_Element::DataValue ||
3849 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003850 return true;
thestigb1a59592016-04-14 18:29:56 -07003851 }
3852
3853 if (eAttr == XFA_ATTRIBUTE_Value) {
3854 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3855 switch (eXMLType) {
3856 case FDE_XMLNODE_Element:
3857 if (IsAttributeInXML()) {
3858 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003859 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3860 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003861 } else {
tsepezd19e9122016-11-02 15:43:18 -07003862 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003863 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3864 for (CXFA_Node* pChildDataNode =
3865 GetNodeItem(XFA_NODEITEM_FirstChild);
3866 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3867 XFA_NODEITEM_NextSibling)) {
3868 CXFA_NodeArray formNodes;
3869 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003870 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003871 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003872 }
3873 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003874 }
thestigb1a59592016-04-14 18:29:56 -07003875 if (bDeleteChildren) {
3876 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3877 }
3878 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3879 }
3880 break;
3881 case FDE_XMLNODE_Text:
3882 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3883 break;
3884 default:
dsinclair43854a52016-04-27 12:26:00 -07003885 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003886 }
tsepezd19e9122016-11-02 15:43:18 -07003887 return true;
thestigb1a59592016-04-14 18:29:56 -07003888 }
3889
3890 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3891 if (pInfo) {
dsinclair43854a52016-04-27 12:26:00 -07003892 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003893 CFX_WideString wsAttrName = pInfo->pName;
3894 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
3895 wsAttrName = FX_WSTRC(L"xfa:") + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003896 }
thestigb1a59592016-04-14 18:29:56 -07003897 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003898 }
tsepezd19e9122016-11-02 15:43:18 -07003899 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003900}
thestigb1a59592016-04-14 18:29:56 -07003901
tsepezd19e9122016-11-02 15:43:18 -07003902bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3903 const CFX_WideString& wsXMLValue,
3904 bool bNotify,
3905 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003906 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003907 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003908 CFX_WideString* pClone = new CFX_WideString(wsValue);
3909 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003910 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003911 if (IsNeedSavingXMLNode()) {
3912 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3913 switch (eXMLType) {
3914 case FDE_XMLNODE_Element:
3915 if (IsAttributeInXML()) {
dsinclairae95f762016-03-29 16:58:29 -07003916 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003917 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3918 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003919 } else {
tsepezd19e9122016-11-02 15:43:18 -07003920 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003921 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3922 for (CXFA_Node* pChildDataNode =
3923 GetNodeItem(XFA_NODEITEM_FirstChild);
3924 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3925 XFA_NODEITEM_NextSibling)) {
3926 CXFA_NodeArray formNodes;
3927 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003928 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003929 break;
3930 }
3931 }
3932 }
3933 if (bDeleteChildren) {
dsinclairae95f762016-03-29 16:58:29 -07003934 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003935 }
dsinclairae95f762016-03-29 16:58:29 -07003936 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003937 }
3938 break;
3939 case FDE_XMLNODE_Text:
dsinclairae95f762016-03-29 16:58:29 -07003940 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003941 break;
3942 default:
dsinclair43854a52016-04-27 12:26:00 -07003943 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003944 }
3945 }
tsepezd19e9122016-11-02 15:43:18 -07003946 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003947}
dsinclair5b36f0a2016-07-19 10:56:23 -07003948
tsepezd19e9122016-11-02 15:43:18 -07003949bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3950 CFX_WideString& wsValue,
3951 bool bUseDefault,
3952 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003953 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003954 if (eAttr == XFA_ATTRIBUTE_Value) {
3955 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3956 if (pStr) {
3957 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07003958 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003959 }
3960 } else {
3961 CFX_WideStringC wsValueC;
3962 if (GetMapModuleString(pKey, wsValueC)) {
3963 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003964 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003965 }
3966 }
3967 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003968 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003969 }
weili44f8faf2016-06-01 14:03:56 -07003970 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003971 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003972 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
3973 wsValue = (const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003974 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003975 }
tsepezd19e9122016-11-02 15:43:18 -07003976 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003977}
dsinclair5b36f0a2016-07-19 10:56:23 -07003978
tsepezd19e9122016-11-02 15:43:18 -07003979bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3980 CFX_WideStringC& wsValue,
3981 bool bUseDefault,
3982 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003983 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003984 if (eAttr == XFA_ATTRIBUTE_Value) {
3985 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3986 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07003987 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07003988 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003989 }
3990 } else {
3991 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003992 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003993 }
3994 }
3995 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003996 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003997 }
weili44f8faf2016-06-01 14:03:56 -07003998 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003999 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04004000 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
4001 wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07004002 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004003 }
tsepezd19e9122016-11-02 15:43:18 -07004004 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004005}
dsinclair5b36f0a2016-07-19 10:56:23 -07004006
tsepezd19e9122016-11-02 15:43:18 -07004007bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
4008 void* pData,
4009 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004010 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004011 return SetUserData(pKey, pData, pCallbackInfo);
4012}
dsinclair5b36f0a2016-07-19 10:56:23 -07004013
tsepezd19e9122016-11-02 15:43:18 -07004014bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004015 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004016 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07004017 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04004018}
dsinclair5b36f0a2016-07-19 10:56:23 -07004019
tsepezd19e9122016-11-02 15:43:18 -07004020bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
4021 XFA_ATTRIBUTETYPE eType,
4022 void* pValue,
4023 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004024 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07004025 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004026 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07004027 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004028 if (IsNeedSavingXMLNode()) {
dsinclair43854a52016-04-27 12:26:00 -07004029 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004030 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
4031 if (pInfo) {
4032 switch (eType) {
4033 case XFA_ATTRIBUTETYPE_Enum:
dsinclairae95f762016-03-29 16:58:29 -07004034 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004035 ->SetString(
4036 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07004037 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04004038 ->pName);
4039 break;
4040 case XFA_ATTRIBUTETYPE_Boolean:
dsinclairae95f762016-03-29 16:58:29 -07004041 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07004042 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04004043 break;
4044 case XFA_ATTRIBUTETYPE_Integer:
dsinclairae95f762016-03-29 16:58:29 -07004045 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004046 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue);
4047 break;
4048 default:
dsinclair43854a52016-04-27 12:26:00 -07004049 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04004050 }
4051 }
4052 }
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::GetValue(XFA_ATTRIBUTE eAttr,
4057 XFA_ATTRIBUTETYPE eType,
4058 bool bUseDefault,
4059 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004060 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004061 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004062 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004063 }
4064 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004065 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004066 }
dsinclair070fcdf2016-06-22 22:04:54 -07004067 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004068 m_ePacket);
4069}
dsinclair5b36f0a2016-07-19 10:56:23 -07004070
tsepezd19e9122016-11-02 15:43:18 -07004071bool CXFA_Node::SetUserData(void* pKey,
4072 void* pData,
4073 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004074 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4075 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004076 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004077}
dsinclair5b36f0a2016-07-19 10:56:23 -07004078
tsepezd19e9122016-11-02 15:43:18 -07004079bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004080 int32_t iBytes = 0;
4081 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004082 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004083 }
4084 return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes);
4085}
dsinclair5b36f0a2016-07-19 10:56:23 -07004086
tsepezd19e9122016-11-02 15:43:18 -07004087bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4088 const CFX_WideString& wsXMLValue,
4089 bool bNotify,
4090 bool bScriptModify,
4091 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004092 CXFA_Node* pNode = nullptr;
4093 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004094 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004095 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004096 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004097 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004098 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004099 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004100 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004101 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004102 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004103 CXFA_Node* pBind = GetBindData();
4104 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004105 std::vector<CFX_WideString> wsSaveTextArray;
Dan Sinclair1770c022016-03-14 14:14:16 -04004106 int32_t iSize = 0;
4107 if (!wsContent.IsEmpty()) {
4108 int32_t iStart = 0;
4109 int32_t iLength = wsContent.GetLength();
4110 int32_t iEnd = wsContent.Find(L'\n', iStart);
4111 iEnd = (iEnd == -1) ? iLength : iEnd;
4112 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004113 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004114 iStart = iEnd + 1;
4115 if (iStart >= iLength) {
4116 break;
4117 }
4118 iEnd = wsContent.Find(L'\n', iStart);
4119 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004120 wsSaveTextArray.push_back(
4121 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004122 }
4123 }
tsepez51709be2016-12-08 10:55:57 -08004124 iSize = pdfium::CollectionSize<int32_t>(wsSaveTextArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04004125 }
4126 if (iSize == 0) {
4127 while (CXFA_Node* pChildNode =
4128 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4129 pBind->RemoveChild(pChildNode);
4130 }
4131 } else {
4132 CXFA_NodeArray valueNodes;
4133 int32_t iDatas = pBind->GetNodeList(
dsinclair56a8b192016-06-21 14:15:25 -07004134 valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004135 if (iDatas < iSize) {
4136 int32_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004137 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004138 while (iAddNodes-- > 0) {
4139 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004140 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004141 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004142 pValueNodes->CreateXMLMappingNode();
4143 pBind->InsertChild(pValueNodes);
4144 }
weili44f8faf2016-06-01 14:03:56 -07004145 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004146 } else if (iDatas > iSize) {
4147 int32_t iDelNodes = iDatas - iSize;
4148 while (iDelNodes-- > 0) {
4149 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4150 }
4151 }
4152 int32_t i = 0;
4153 for (CXFA_Node* pValueNode =
4154 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4155 pValueNode; pValueNode = pValueNode->GetNodeItem(
4156 XFA_NODEITEM_NextSibling)) {
4157 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004158 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004159 i++;
4160 }
4161 }
4162 CXFA_NodeArray nodeArray;
4163 pBind->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,
tsepezd19e9122016-11-02 15:43:18 -07004167 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004168 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004169 }
4170 }
4171 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004172 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004173 pNode = this;
4174 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004175 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004176 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004177 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004178 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004179 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004180 }
4181 pBindNode = GetBindData();
4182 if (pBindNode && bSyncData) {
4183 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004184 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004185 CXFA_NodeArray nodeArray;
4186 pBindNode->GetBindItems(nodeArray);
4187 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004188 if (nodeArray[i] != this) {
4189 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true,
tsepezd19e9122016-11-02 15:43:18 -07004190 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004191 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004192 }
4193 }
weili44f8faf2016-06-01 14:03:56 -07004194 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004195 break;
4196 }
dsinclairc5a8f212016-06-20 11:11:12 -07004197 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004198 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004199 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004200 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
tsepez9f2970c2016-04-01 10:23:04 -07004201 if (wsContentType == FX_WSTRC(L"text/html")) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004202 wsContentType = FX_WSTRC(L"");
tsepez4c3debb2016-04-08 12:20:38 -07004203 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004204 }
4205 }
4206 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4207 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004208 pContentRawDataNode = CreateSamePacketNode(
dsinclair56a8b192016-06-21 14:15:25 -07004209 (wsContentType == FX_WSTRC(L"text/xml")) ? XFA_Element::Sharpxml
4210 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004211 InsertChild(pContentRawDataNode);
4212 }
4213 return pContentRawDataNode->SetScriptContent(
4214 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4215 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004216 case XFA_ObjectType::NodeC:
4217 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004218 pNode = this;
4219 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004220 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004221 pNode = this;
4222 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4223 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4224 if (pParent) {
4225 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4226 }
dsinclair070fcdf2016-06-22 22:04:54 -07004227 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004228 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4229 if (pParent && pParent->IsContainerNode()) {
4230 pBindNode = pParent->GetBindData();
4231 if (pBindNode) {
4232 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004233 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004234 }
4235 }
4236 }
4237 }
4238 break;
4239 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004240 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004241 pNode = this;
4242 pBindNode = this;
4243 }
4244 break;
4245 }
4246 if (pNode) {
4247 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4248 if (pBindNode && bSyncData) {
4249 CXFA_NodeArray nodeArray;
4250 pBindNode->GetBindItems(nodeArray);
4251 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004252 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004253 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004254 }
4255 }
tsepezd19e9122016-11-02 15:43:18 -07004256 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004257 }
tsepezd19e9122016-11-02 15:43:18 -07004258 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004259}
dsinclair5b36f0a2016-07-19 10:56:23 -07004260
tsepezd19e9122016-11-02 15:43:18 -07004261bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4262 const CFX_WideString& wsXMLValue,
4263 bool bNotify,
4264 bool bScriptModify,
4265 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004266 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4267 bSyncData);
4268}
dsinclair5b36f0a2016-07-19 10:56:23 -07004269
tsepezd19e9122016-11-02 15:43:18 -07004270CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004271 CFX_WideString wsContent;
4272 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4273}
dsinclair5b36f0a2016-07-19 10:56:23 -07004274
Dan Sinclair1770c022016-03-14 14:14:16 -04004275CFX_WideString CXFA_Node::GetContent() {
4276 return GetScriptContent();
4277}
dsinclair5b36f0a2016-07-19 10:56:23 -07004278
tsepezd19e9122016-11-02 15:43:18 -07004279bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4280 bool bScriptModify,
4281 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004282 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004283 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004284 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004285 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004286 pNode = this;
4287 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004288 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004289 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004290 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004291 }
4292 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4293 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
4294 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType,
4295 FX_WSTRC(L"text/xml"));
4296 }
4297 return pChildValue
4298 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004299 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004300 }
4301 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004302 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004303 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4304 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004305 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004306 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004307 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004308 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
tsepez9f2970c2016-04-01 10:23:04 -07004309 if (wsContentType == FX_WSTRC(L"text/html")) {
dsinclair56a8b192016-06-21 14:15:25 -07004310 element = XFA_Element::SharpxHTML;
tsepez9f2970c2016-04-01 10:23:04 -07004311 } else if (wsContentType == FX_WSTRC(L"text/xml")) {
dsinclair56a8b192016-06-21 14:15:25 -07004312 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004313 }
4314 }
4315 pContentRawDataNode = CreateSamePacketNode(element);
4316 InsertChild(pContentRawDataNode);
4317 }
4318 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4319 }
dsinclairc5a8f212016-06-20 11:11:12 -07004320 case XFA_ObjectType::NodeC:
4321 case XFA_ObjectType::NodeV:
4322 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004323 pNode = this;
4324 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004325 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004326 pNode = this;
4327 }
4328 break;
4329 }
4330 if (pNode) {
4331 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004332 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004333 if (pScriptContext) {
4334 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4335 }
4336 }
tsepezd19e9122016-11-02 15:43:18 -07004337 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004338 }
tsepezd19e9122016-11-02 15:43:18 -07004339 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004340}
dsinclair5b36f0a2016-07-19 10:56:23 -07004341
Dan Sinclair1770c022016-03-14 14:14:16 -04004342CXFA_Node* CXFA_Node::GetModelNode() {
4343 switch (GetPacketID()) {
4344 case XFA_XDPPACKET_XDP:
4345 return m_pDocument->GetRoot();
4346 case XFA_XDPPACKET_Config:
4347 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4348 case XFA_XDPPACKET_Template:
4349 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4350 case XFA_XDPPACKET_Form:
4351 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4352 case XFA_XDPPACKET_Datasets:
4353 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4354 case XFA_XDPPACKET_LocaleSet:
4355 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4356 case XFA_XDPPACKET_ConnectionSet:
4357 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4358 case XFA_XDPPACKET_SourceSet:
4359 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4360 case XFA_XDPPACKET_Xdc:
4361 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4362 default:
4363 return this;
4364 }
4365}
dsinclair5b36f0a2016-07-19 10:56:23 -07004366
tsepezd19e9122016-11-02 15:43:18 -07004367bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004368 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004369 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
dsinclairae95f762016-03-29 16:58:29 -07004370 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004371 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004372 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004373 }
dsinclairae95f762016-03-29 16:58:29 -07004374 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004375 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004376 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
dsinclairae95f762016-03-29 16:58:29 -07004377 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004378 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004379 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004380 }
4381 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004382 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004383 }
dsinclair070fcdf2016-06-22 22:04:54 -07004384 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004385 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4386 return XFA_FDEExtension_ResolveNamespaceQualifier(
dsinclairae95f762016-03-29 16:58:29 -07004387 static_cast<CFDE_XMLElement*>(pXMLNode),
4388 GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004389 }
dsinclairae95f762016-03-29 16:58:29 -07004390 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004391 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004392 } else {
4393 CXFA_Node* pModelNode = GetModelNode();
4394 return pModelNode->TryNamespace(wsNamespace);
4395 }
4396}
dsinclair5b36f0a2016-07-19 10:56:23 -07004397
Dan Sinclair1770c022016-03-14 14:14:16 -04004398CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004399 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004400 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004401 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004402 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004403 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004404 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004405 if (!pProperty || index >= pProperty->uOccur)
4406 return nullptr;
4407
Dan Sinclair1770c022016-03-14 14:14:16 -04004408 CXFA_Node* pNode = m_pChild;
4409 int32_t iCount = 0;
4410 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004411 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004412 iCount++;
4413 if (iCount > index) {
4414 return pNode;
4415 }
4416 }
4417 }
weili44f8faf2016-06-01 14:03:56 -07004418 if (!bCreateProperty)
4419 return nullptr;
4420
Dan Sinclair1770c022016-03-14 14:14:16 -04004421 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4422 pNode = m_pChild;
4423 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4424 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004425 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004426 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4427 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004428 }
4429 }
dsinclaira1b07722016-07-11 08:20:58 -07004430
Dan Sinclair1770c022016-03-14 14:14:16 -04004431 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004432 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004433 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004434 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004435 if (!pNewNode)
4436 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004437 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004438 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004439 }
4440 return pNewNode;
4441}
dsinclair5b36f0a2016-07-19 10:56:23 -07004442
tsepezd19e9122016-11-02 15:43:18 -07004443int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004444 CXFA_Node* pNode = m_pChild;
4445 int32_t iCount = 0;
4446 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004447 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004448 if (bOnlyChild) {
4449 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004450 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004451 if (pProperty) {
4452 continue;
4453 }
4454 }
4455 iCount++;
4456 }
4457 }
4458 return iCount;
4459}
dsinclair5b36f0a2016-07-19 10:56:23 -07004460
Dan Sinclair1770c022016-03-14 14:14:16 -04004461CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004462 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004463 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004464 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004465 CXFA_Node* pNode = m_pChild;
4466 int32_t iCount = 0;
4467 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004468 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004469 if (bOnlyChild) {
4470 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004471 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004472 if (pProperty) {
4473 continue;
4474 }
4475 }
4476 iCount++;
4477 if (iCount > index) {
4478 return pNode;
4479 }
4480 }
4481 }
weili44f8faf2016-06-01 14:03:56 -07004482 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004483}
dsinclair5b36f0a2016-07-19 10:56:23 -07004484
Dan Sinclair1770c022016-03-14 14:14:16 -04004485int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4486 ASSERT(!pNode->m_pNext);
4487 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004488 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004489 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004490 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004491
weili44f8faf2016-06-01 14:03:56 -07004492 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004493 if (index > 0) {
4494 return -1;
4495 }
4496 pNode->m_pNext = m_pChild;
4497 m_pChild = pNode;
4498 index = 0;
4499 } else if (index < 0) {
4500 m_pLastChild->m_pNext = pNode;
4501 } else {
4502 CXFA_Node* pPrev = m_pChild;
4503 int32_t iCount = 0;
4504 while (++iCount != index && pPrev->m_pNext) {
4505 pPrev = pPrev->m_pNext;
4506 }
4507 if (index > 0 && index != iCount) {
4508 return -1;
4509 }
4510 pNode->m_pNext = pPrev->m_pNext;
4511 pPrev->m_pNext = pNode;
4512 index = iCount;
4513 }
weili44f8faf2016-06-01 14:03:56 -07004514 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004515 m_pLastChild = pNode;
4516 }
4517 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004518 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004519 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004520 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004521 if (pNotify)
4522 pNotify->OnChildAdded(this);
4523
Dan Sinclair1770c022016-03-14 14:14:16 -04004524 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004525 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004526 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004527 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004528 }
4529 return index;
4530}
weili6e1ae862016-05-04 18:25:27 -07004531
tsepezd19e9122016-11-02 15:43:18 -07004532bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004533 if (!pNode || pNode->m_pParent ||
4534 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004535 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004536 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004537 }
tsepezd19e9122016-11-02 15:43:18 -07004538 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004539 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004540 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004541
4542 int32_t nIndex = -1;
4543 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004544 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004545 pNode->m_pNext = m_pChild;
4546 m_pChild = pNode;
4547 nIndex = 0;
4548 } else if (!pBeforeNode) {
4549 pNode->m_pNext = m_pLastChild->m_pNext;
4550 m_pLastChild->m_pNext = pNode;
4551 } else {
4552 nIndex = 1;
4553 CXFA_Node* pPrev = m_pChild;
4554 while (pPrev->m_pNext != pBeforeNode) {
4555 pPrev = pPrev->m_pNext;
4556 nIndex++;
4557 }
4558 pNode->m_pNext = pPrev->m_pNext;
4559 pPrev->m_pNext = pNode;
4560 }
weili44f8faf2016-06-01 14:03:56 -07004561 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004562 m_pLastChild = pNode;
4563 }
4564 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004565 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004566 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004567 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004568 if (pNotify)
4569 pNotify->OnChildAdded(this);
4570
Dan Sinclair1770c022016-03-14 14:14:16 -04004571 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004572 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004573 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004574 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004575 }
tsepezd19e9122016-11-02 15:43:18 -07004576 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004577}
dsinclair5b36f0a2016-07-19 10:56:23 -07004578
Dan Sinclair1770c022016-03-14 14:14:16 -04004579CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4580 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004581 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004582 }
4583 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4584 pSibling = pSibling->m_pNext) {
4585 if (pSibling->m_pNext == this) {
4586 return pSibling;
4587 }
4588 }
weili44f8faf2016-06-01 14:03:56 -07004589 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004590}
dsinclair5b36f0a2016-07-19 10:56:23 -07004591
tsepezd19e9122016-11-02 15:43:18 -07004592bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004593 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004594 ASSERT(false);
4595 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004596 }
4597 if (m_pChild == pNode) {
4598 m_pChild = pNode->m_pNext;
4599 if (m_pLastChild == pNode) {
4600 m_pLastChild = pNode->m_pNext;
4601 }
weili44f8faf2016-06-01 14:03:56 -07004602 pNode->m_pNext = nullptr;
4603 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004604 } else {
4605 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4606 pPrev->m_pNext = pNode->m_pNext;
4607 if (m_pLastChild == pNode) {
4608 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4609 }
weili44f8faf2016-06-01 14:03:56 -07004610 pNode->m_pNext = nullptr;
4611 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004612 }
weili44f8faf2016-06-01 14:03:56 -07004613 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004614 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004615 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004616 m_pDocument->AddPurgeNode(pNode);
4617 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4618 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004619 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4620 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004621 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07004622 CFDE_XMLElement* pXMLElement =
4623 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004624 CFX_WideStringC wsAttributeName =
4625 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004626 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004627 }
4628 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004629 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -07004630 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004631 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4632 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004633 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004634 }
4635 pNode->m_pXMLNode = pNewXMLElement;
4636 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4637 } else {
4638 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4639 }
dsinclairc5a8f212016-06-20 11:11:12 -07004640 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004641 }
tsepezd19e9122016-11-02 15:43:18 -07004642 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004643}
dsinclair5b36f0a2016-07-19 10:56:23 -07004644
Dan Sinclair1770c022016-03-14 14:14:16 -04004645CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004646 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004647}
dsinclair5b36f0a2016-07-19 10:56:23 -07004648
tsepez736f28a2016-03-25 14:19:51 -07004649CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004650 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4651 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4652 if (pNode->GetNameHash() == dwNameHash) {
4653 return pNode;
4654 }
4655 }
weili44f8faf2016-06-01 14:03:56 -07004656 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004657}
dsinclair5b36f0a2016-07-19 10:56:23 -07004658
dsinclair41cb62e2016-06-23 09:20:32 -07004659CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004660 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4661 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004662 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004663 return pNode;
4664 }
4665 }
weili44f8faf2016-06-01 14:03:56 -07004666 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004667}
dsinclair5b36f0a2016-07-19 10:56:23 -07004668
tsepez736f28a2016-03-25 14:19:51 -07004669CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004670 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4671 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4672 if (pNode->GetNameHash() == dwNameHash) {
4673 return pNode;
4674 }
4675 }
weili44f8faf2016-06-01 14:03:56 -07004676 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004677}
dsinclair5b36f0a2016-07-19 10:56:23 -07004678
Dan Sinclair1770c022016-03-14 14:14:16 -04004679CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4680 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004681 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004682}
dsinclair5b36f0a2016-07-19 10:56:23 -07004683
dsinclair41cb62e2016-06-23 09:20:32 -07004684CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004685 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4686 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004687 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004688 return pNode;
4689 }
4690 }
weili44f8faf2016-06-01 14:03:56 -07004691 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004692}
dsinclair5b36f0a2016-07-19 10:56:23 -07004693
Dan Sinclair1770c022016-03-14 14:14:16 -04004694int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004695 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004696 if (!pScriptContext) {
4697 return -1;
4698 }
4699 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4700}
dsinclair5b36f0a2016-07-19 10:56:23 -07004701
Dan Sinclair1770c022016-03-14 14:14:16 -04004702int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004703 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004704 if (!pScriptContext) {
4705 return -1;
4706 }
4707 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4708}
dsinclair5b36f0a2016-07-19 10:56:23 -07004709
Dan Sinclair1770c022016-03-14 14:14:16 -04004710void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004711 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004712 if (!pScriptContext) {
4713 return;
4714 }
4715 pScriptContext->GetSomExpression(this, wsSOMExpression);
4716}
dsinclair5b36f0a2016-07-19 10:56:23 -07004717
Dan Sinclair1770c022016-03-14 14:14:16 -04004718CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004719 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004720 if (m_ePacket == XFA_XDPPACKET_Form) {
4721 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004722 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004723 return pInstanceMgr;
4724 }
4725 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4726 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004727 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004728 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004729 pNode->m_dwNameHash != m_dwNameHash) {
4730 break;
4731 }
dsinclair56a8b192016-06-21 14:15:25 -07004732 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004733 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4734 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4735 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4736 wsInstName.Mid(1) == wsName) {
4737 pInstanceMgr = pNode;
4738 }
4739 break;
4740 }
4741 }
4742 }
4743 return pInstanceMgr;
4744}
dsinclair5b36f0a2016-07-19 10:56:23 -07004745
Dan Sinclair1770c022016-03-14 14:14:16 -04004746CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004747 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004748}
dsinclair5b36f0a2016-07-19 10:56:23 -07004749
dsinclairc5a8f212016-06-20 11:11:12 -07004750bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4751 if (m_uNodeFlags & dwFlag)
4752 return true;
4753 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4754 return m_pParent && m_pParent->HasFlag(dwFlag);
4755 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004756}
thestigb1a59592016-04-14 18:29:56 -07004757
4758void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004759 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004760 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004761 if (pNotify) {
4762 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004763 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004764 }
dsinclairc5a8f212016-06-20 11:11:12 -07004765 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004766}
thestigb1a59592016-04-14 18:29:56 -07004767
4768void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004769 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004770}
4771
tsepezd19e9122016-11-02 15:43:18 -07004772bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004773 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4774}
thestigb1a59592016-04-14 18:29:56 -07004775
4776void CXFA_Node::OnRemoved(bool bNotify) {
4777 if (!bNotify)
4778 return;
4779
dsinclaira1b07722016-07-11 08:20:58 -07004780 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004781 if (pNotify)
4782 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004783}
thestigb1a59592016-04-14 18:29:56 -07004784
4785void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004786 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004787 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004788 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004789 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004790 }
4791 }
4792}
thestigb1a59592016-04-14 18:29:56 -07004793
Dan Sinclair1770c022016-03-14 14:14:16 -04004794void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004795 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004796 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004797 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004798 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004799 }
4800}
thestigb1a59592016-04-14 18:29:56 -07004801
Dan Sinclair1770c022016-03-14 14:14:16 -04004802int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004803 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004804 int32_t iRet = XFA_EVENTERROR_NotExist;
4805 const XFA_ExecEventParaInfo* eventParaInfo =
4806 GetEventParaInfoByName(wsEventName);
4807 if (eventParaInfo) {
4808 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004809 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004810 if (!pNotify) {
4811 return iRet;
4812 }
4813 if (validFlags == 1) {
4814 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4815 } else if (validFlags == 2) {
4816 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004817 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004818 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004819 if (eType == XFA_Element::Subform) {
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 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004824 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004825 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004826 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004827 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004828 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004829 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004830 }
4831 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004832 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004833 }
4834 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004835 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004836 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004837 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004838 }
4839 } else if (validFlags == 6) {
4840 CXFA_WidgetData* pWidgetData = GetWidgetData();
4841 if (pWidgetData) {
4842 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004843 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004844 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004845 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004846 }
4847 }
4848 } else if (validFlags == 7) {
4849 CXFA_WidgetData* pWidgetData = GetWidgetData();
4850 if (pWidgetData) {
4851 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004852 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004853 (!pWidgetData->IsListBox())) {
4854 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004855 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004856 }
4857 }
4858 }
4859 }
4860 return iRet;
4861}
dsinclair5b36f0a2016-07-19 10:56:23 -07004862
Dan Sinclair1770c022016-03-14 14:14:16 -04004863void CXFA_Node::UpdateNameHash() {
4864 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004865 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004866 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004867 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004868 wsName = GetCData(XFA_ATTRIBUTE_Name);
4869 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004870 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004871 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004872 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004873 }
4874}
dsinclair5b36f0a2016-07-19 10:56:23 -07004875
dsinclairae95f762016-03-29 16:58:29 -07004876CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004877 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004878 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
dsinclairae95f762016-03-29 16:58:29 -07004879 m_pXMLNode = new CFDE_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004880 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004881 }
4882 return m_pXMLNode;
4883}
dsinclair5b36f0a2016-07-19 10:56:23 -07004884
tsepezd19e9122016-11-02 15:43:18 -07004885bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004886 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004887 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004888}
4889
4890XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4891 if (!m_pMapModuleData)
4892 m_pMapModuleData = new XFA_MAPMODULEDATA;
4893 return m_pMapModuleData;
4894}
4895
4896XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4897 return m_pMapModuleData;
4898}
4899
4900void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4901 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004902 pModule->m_ValueMap[pKey] = pValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04004903}
4904
tsepezd19e9122016-11-02 15:43:18 -07004905bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
tsepez6bb3b892017-01-05 12:18:41 -08004906 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004907 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004908 if (pModule) {
4909 auto it = pModule->m_ValueMap.find(pKey);
4910 if (it != pModule->m_ValueMap.end()) {
4911 pValue = it->second;
4912 return true;
4913 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004914 }
tsepez6bb3b892017-01-05 12:18:41 -08004915 if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4916 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004917 }
tsepezd19e9122016-11-02 15:43:18 -07004918 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004919}
dsinclair5b36f0a2016-07-19 10:56:23 -07004920
Dan Sinclair1770c022016-03-14 14:14:16 -04004921void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004922 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair1770c022016-03-14 14:14:16 -04004923 wsValue.GetLength() * sizeof(FX_WCHAR));
4924}
dsinclair5b36f0a2016-07-19 10:56:23 -07004925
tsepezd19e9122016-11-02 15:43:18 -07004926bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004927 void* pValue;
4928 int32_t iBytes;
4929 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004930 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004931 }
4932 wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR));
tsepezd19e9122016-11-02 15:43:18 -07004933 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004934}
dsinclair5b36f0a2016-07-19 10:56:23 -07004935
Dan Sinclair1770c022016-03-14 14:14:16 -04004936void CXFA_Node::SetMapModuleBuffer(
4937 void* pKey,
4938 void* pValue,
4939 int32_t iBytes,
4940 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4941 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4942 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004943 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004944 pBuffer =
4945 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4946 } else if (pBuffer->iBytes != iBytes) {
4947 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4948 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4949 }
4950 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4951 sizeof(XFA_MAPDATABLOCK) + iBytes);
4952 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4953 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4954 }
weili44f8faf2016-06-01 14:03:56 -07004955 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04004956 return;
weili44f8faf2016-06-01 14:03:56 -07004957
Dan Sinclair1770c022016-03-14 14:14:16 -04004958 pBuffer->pCallbackInfo = pCallbackInfo;
4959 pBuffer->iBytes = iBytes;
4960 FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes);
4961}
dsinclair5b36f0a2016-07-19 10:56:23 -07004962
tsepezd19e9122016-11-02 15:43:18 -07004963bool CXFA_Node::GetMapModuleBuffer(void* pKey,
4964 void*& pValue,
4965 int32_t& iBytes,
4966 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07004967 XFA_MAPDATABLOCK* pBuffer = nullptr;
tsepez6bb3b892017-01-05 12:18:41 -08004968 for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004969 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004970 if (pModule) {
4971 auto it = pModule->m_BufferMap.find(pKey);
4972 if (it != pModule->m_BufferMap.end()) {
4973 pBuffer = it->second;
4974 break;
4975 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004976 }
tsepez6bb3b892017-01-05 12:18:41 -08004977 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4978 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004979 }
tsepez6bb3b892017-01-05 12:18:41 -08004980 if (!pBuffer)
tsepezd19e9122016-11-02 15:43:18 -07004981 return false;
tsepez6bb3b892017-01-05 12:18:41 -08004982
Dan Sinclair1770c022016-03-14 14:14:16 -04004983 pValue = pBuffer->GetData();
4984 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07004985 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004986}
dsinclair5b36f0a2016-07-19 10:56:23 -07004987
tsepezd19e9122016-11-02 15:43:18 -07004988bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
tsepez6bb3b892017-01-05 12:18:41 -08004989 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004990 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004991 if (pModule) {
4992 auto it1 = pModule->m_ValueMap.find(pKey);
4993 if (it1 != pModule->m_ValueMap.end())
4994 return true;
4995
4996 auto it2 = pModule->m_BufferMap.find(pKey);
4997 if (it2 != pModule->m_BufferMap.end())
4998 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004999 }
tsepez6bb3b892017-01-05 12:18:41 -08005000 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
5001 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04005002 }
tsepezd19e9122016-11-02 15:43:18 -07005003 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005004}
dsinclair5b36f0a2016-07-19 10:56:23 -07005005
Dan Sinclair1770c022016-03-14 14:14:16 -04005006void CXFA_Node::RemoveMapModuleKey(void* pKey) {
5007 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
5008 if (!pModule)
5009 return;
5010
5011 if (pKey) {
tsepez6bb3b892017-01-05 12:18:41 -08005012 auto it = pModule->m_BufferMap.find(pKey);
5013 if (it != pModule->m_BufferMap.end()) {
5014 XFA_MAPDATABLOCK* pBuffer = it->second;
Dan Sinclair1770c022016-03-14 14:14:16 -04005015 if (pBuffer) {
tsepez6bb3b892017-01-05 12:18:41 -08005016 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
Dan Sinclair1770c022016-03-14 14:14:16 -04005017 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005018 FX_Free(pBuffer);
5019 }
tsepez6bb3b892017-01-05 12:18:41 -08005020 pModule->m_BufferMap.erase(it);
Dan Sinclair1770c022016-03-14 14:14:16 -04005021 }
tsepez6bb3b892017-01-05 12:18:41 -08005022 pModule->m_ValueMap.erase(pKey);
5023 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04005024 }
tsepez6bb3b892017-01-05 12:18:41 -08005025
5026 for (auto& pair : pModule->m_BufferMap) {
5027 XFA_MAPDATABLOCK* pBuffer = pair.second;
5028 if (pBuffer) {
5029 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
5030 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5031 FX_Free(pBuffer);
5032 }
5033 }
5034 pModule->m_BufferMap.clear();
5035 pModule->m_ValueMap.clear();
5036 delete pModule;
Dan Sinclair1770c022016-03-14 14:14:16 -04005037}
dsinclair5b36f0a2016-07-19 10:56:23 -07005038
tsepez6bb3b892017-01-05 12:18:41 -08005039void CXFA_Node::MergeAllData(void* pDstModule) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005040 XFA_MAPMODULEDATA* pDstModuleData =
5041 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
5042 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08005043 if (!pSrcModuleData)
Dan Sinclair1770c022016-03-14 14:14:16 -04005044 return;
tsepez6bb3b892017-01-05 12:18:41 -08005045
5046 for (const auto& pair : pSrcModuleData->m_ValueMap)
5047 pDstModuleData->m_ValueMap[pair.first] = pair.second;
5048
5049 for (const auto& pair : pSrcModuleData->m_BufferMap) {
5050 XFA_MAPDATABLOCK* pSrcBuffer = pair.second;
5051 XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first];
Dan Sinclair1770c022016-03-14 14:14:16 -04005052 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
5053 !pSrcBuffer->pCallbackInfo->pCopy) {
tsepez6bb3b892017-01-05 12:18:41 -08005054 if (pDstBuffer) {
5055 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
5056 pDstModuleData->m_BufferMap.erase(pair.first);
Dan Sinclair1770c022016-03-14 14:14:16 -04005057 }
5058 continue;
5059 }
tsepez6bb3b892017-01-05 12:18:41 -08005060 if (!pDstBuffer) {
5061 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
Dan Sinclair1770c022016-03-14 14:14:16 -04005062 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08005063 } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) {
5064 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5065 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005066 }
tsepez6bb3b892017-01-05 12:18:41 -08005067 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
5068 uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5069 } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5070 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005071 }
tsepez6bb3b892017-01-05 12:18:41 -08005072 if (!pDstBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005073 continue;
5074 }
tsepez6bb3b892017-01-05 12:18:41 -08005075 pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5076 pDstBuffer->iBytes = pSrcBuffer->iBytes;
5077 FXSYS_memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(),
5078 pSrcBuffer->iBytes);
5079 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) {
5080 pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005081 }
5082 }
5083}
dsinclair5b36f0a2016-07-19 10:56:23 -07005084
Dan Sinclair1770c022016-03-14 14:14:16 -04005085void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5086 if (!pDstModule) {
5087 return;
5088 }
tsepezd19e9122016-11-02 15:43:18 -07005089 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005090 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005091 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005092 }
dsinclair070fcdf2016-06-22 22:04:54 -07005093 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005094 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005095 }
weili44f8faf2016-06-01 14:03:56 -07005096 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5097 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005098 if (bNeedMove) {
5099 pSrcModuleData = GetMapModuleData();
5100 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005101 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005102 }
5103 pDstModuleData = pDstModule->CreateMapModuleData();
5104 }
5105 if (bNeedMove) {
tsepez6bb3b892017-01-05 12:18:41 -08005106 auto it = pSrcModuleData->m_BufferMap.find(pKey);
5107 if (it != pSrcModuleData->m_BufferMap.end()) {
5108 XFA_MAPDATABLOCK* pBufferBlockData = it->second;
5109 if (pBufferBlockData) {
5110 pSrcModuleData->m_BufferMap.erase(pKey);
5111 pDstModuleData->m_BufferMap[pKey] = pBufferBlockData;
5112 }
Dan Sinclair1770c022016-03-14 14:14:16 -04005113 }
5114 }
dsinclairc5a8f212016-06-20 11:11:12 -07005115 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005116 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005117 CFX_WideString wsFormatValue(wsValue);
5118 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5119 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005120 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005121 }
tsepezd19e9122016-11-02 15:43:18 -07005122 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005123 }
5124}
dsinclair5b36f0a2016-07-19 10:56:23 -07005125
Dan Sinclair1770c022016-03-14 14:14:16 -04005126void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5127 CXFA_Node* pDstModule,
5128 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005129 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005130 if (!pSrcModule || !pDstModule || !pKey) {
5131 return;
5132 }
5133 if (bRecursive) {
5134 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5135 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5136 for (; pSrcChild && pDstChild;
5137 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5138 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005139 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005140 }
5141 }
5142 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5143}
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05005144
5145void CXFA_Node::ThrowMissingPropertyException(
5146 const CFX_WideString& obj,
5147 const CFX_WideString& prop) const {
5148 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(),
5149 prop.c_str());
5150}
5151
5152void CXFA_Node::ThrowTooManyOccurancesException(
5153 const CFX_WideString& obj) const {
5154 ThrowException(
5155 L"The element [%s] has violated its allowable number of occurrences.",
5156 obj.c_str());
5157}