blob: cd6b84424c00157e5cd22d6579031dc89355e6b2 [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>
Tom Sepezd4db58f2017-03-02 14:57:59 -080011#include <unordered_set>
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050012#include <utility>
tsepez51709be2016-12-08 10:55:57 -080013#include <vector>
tsepezaadedf92016-05-12 10:08:06 -070014
dsinclaira52ab742016-09-29 13:59:29 -070015#include "core/fxcrt/fx_ext.h"
dsinclair43554682016-09-29 17:29:48 -070016#include "fxjs/cfxjse_value.h"
tsepeza9caab92016-12-14 05:57:10 -080017#include "third_party/base/ptr_util.h"
tsepezaadedf92016-05-12 10:08:06 -070018#include "third_party/base/stl_util.h"
dsinclairae95f762016-03-29 16:58:29 -070019#include "xfa/fde/xml/fde_xml_imp.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040020#include "xfa/fgas/crt/fgas_codepage.h"
dsinclairdf4bc592016-03-31 20:34:43 -070021#include "xfa/fxfa/app/xfa_ffnotify.h"
dsinclair5b493092016-09-29 20:20:24 -070022#include "xfa/fxfa/cxfa_eventparam.h"
dsinclair16280242016-07-21 12:03:47 -070023#include "xfa/fxfa/parser/cxfa_document.h"
dsinclair0b851ff2016-07-21 12:03:01 -070024#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
dsinclair9eb0db12016-07-21 12:01:39 -070025#include "xfa/fxfa/parser/cxfa_measurement.h"
dsinclair44d054c2016-04-06 10:23:46 -070026#include "xfa/fxfa/parser/cxfa_occur.h"
dsinclair31f87402016-07-20 06:34:45 -070027#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
dsinclair34f86b02016-07-11 08:42:33 -070028#include "xfa/fxfa/parser/cxfa_simple_parser.h"
dsinclair5b36f0a2016-07-19 10:56:23 -070029#include "xfa/fxfa/parser/xfa_basic_data.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040030
weili44f8faf2016-06-01 14:03:56 -070031namespace {
32
33void XFA_DeleteWideString(void* pData) {
34 delete static_cast<CFX_WideString*>(pData);
35}
36
37void XFA_CopyWideString(void*& pData) {
38 if (pData) {
39 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
40 pData = pNewData;
41 }
42}
43
44XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
45 XFA_CopyWideString};
46
weili44f8faf2016-06-01 14:03:56 -070047void XFA_DataNodeDeleteBindItem(void* pData) {
48 delete static_cast<CXFA_NodeArray*>(pData);
49}
50
51XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
52 XFA_DataNodeDeleteBindItem, nullptr};
53
dsinclair5b36f0a2016-07-19 10:56:23 -070054int32_t GetCount(CXFA_Node* pInstMgrNode) {
55 ASSERT(pInstMgrNode);
56 int32_t iCount = 0;
57 uint32_t dwNameHash = 0;
58 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
59 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
60 XFA_Element eCurType = pNode->GetElementType();
61 if (eCurType == XFA_Element::InstanceManager)
62 break;
63 if ((eCurType != XFA_Element::Subform) &&
64 (eCurType != XFA_Element::SubformSet)) {
65 continue;
66 }
67 if (iCount == 0) {
68 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
69 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
70 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
71 wsInstName.Mid(1) != wsName) {
72 return iCount;
73 }
74 dwNameHash = pNode->GetNameHash();
75 }
76 if (dwNameHash != pNode->GetNameHash())
77 break;
weili44f8faf2016-06-01 14:03:56 -070078
dsinclair5b36f0a2016-07-19 10:56:23 -070079 iCount++;
80 }
81 return iCount;
Dan Sinclair1770c022016-03-14 14:14:16 -040082}
weili44f8faf2016-06-01 14:03:56 -070083
Tom Sepezd4db58f2017-03-02 14:57:59 -080084void SortNodeArrayByDocumentIdx(const std::unordered_set<CXFA_Node*>& rgNodeSet,
dsinclair5b36f0a2016-07-19 10:56:23 -070085 CXFA_NodeArray& rgNodeArray,
86 CFX_ArrayTemplate<int32_t>& rgIdxArray) {
87 int32_t iCount = pdfium::CollectionSize<int32_t>(rgNodeSet);
88 rgNodeArray.SetSize(iCount);
89 rgIdxArray.SetSize(iCount);
90 if (iCount == 0)
91 return;
weili44f8faf2016-06-01 14:03:56 -070092
dsinclair5b36f0a2016-07-19 10:56:23 -070093 int32_t iIndex = -1;
94 int32_t iTotalIndex = -1;
95 CXFA_Node* pCommonParent =
96 (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent);
97 for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild);
98 pNode && iIndex < iCount;
99 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
100 iTotalIndex++;
101 if (pdfium::ContainsValue(rgNodeSet, pNode)) {
102 iIndex++;
103 rgNodeArray[iIndex] = pNode;
104 rgIdxArray[iIndex] = iTotalIndex;
105 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400106 }
107}
weili44f8faf2016-06-01 14:03:56 -0700108
Tom Sepezd4db58f2017-03-02 14:57:59 -0800109using CXFA_NodeSetPair =
110 std::pair<std::unordered_set<CXFA_Node*>, std::unordered_set<CXFA_Node*>>;
dsinclair5b36f0a2016-07-19 10:56:23 -0700111using CXFA_NodeSetPairMap =
112 std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>;
113using CXFA_NodeSetPairMapMap =
114 std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>;
115
116CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode,
117 CXFA_NodeSetPairMapMap* pMap) {
118 CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
119 uint32_t dwNameHash = pNode->GetNameHash();
120 if (!pParentNode || !dwNameHash)
121 return nullptr;
122
123 if (!(*pMap)[pParentNode])
tsepeza9caab92016-12-14 05:57:10 -0800124 (*pMap)[pParentNode] = pdfium::MakeUnique<CXFA_NodeSetPairMap>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700125
126 CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get();
127 if (!(*pNodeSetPairMap)[dwNameHash])
tsepeza9caab92016-12-14 05:57:10 -0800128 (*pNodeSetPairMap)[dwNameHash] = pdfium::MakeUnique<CXFA_NodeSetPair>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700129
130 return (*pNodeSetPairMap)[dwNameHash].get();
Dan Sinclair1770c022016-03-14 14:14:16 -0400131}
132
Tom Sepezd4db58f2017-03-02 14:57:59 -0800133void ReorderDataNodes(const std::unordered_set<CXFA_Node*>& sSet1,
134 const std::unordered_set<CXFA_Node*>& sSet2,
tsepezd19e9122016-11-02 15:43:18 -0700135 bool bInsertBefore) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700136 CXFA_NodeSetPairMapMap rgMap;
137 for (CXFA_Node* pNode : sSet1) {
138 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
139 if (pNodeSetPair)
140 pNodeSetPair->first.insert(pNode);
141 }
142 for (CXFA_Node* pNode : sSet2) {
143 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
144 if (pNodeSetPair) {
145 if (pdfium::ContainsValue(pNodeSetPair->first, pNode))
146 pNodeSetPair->first.erase(pNode);
147 else
148 pNodeSetPair->second.insert(pNode);
149 }
150 }
151 for (const auto& iter1 : rgMap) {
152 CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get();
153 if (!pNodeSetPairMap)
154 continue;
155
156 for (const auto& iter2 : *pNodeSetPairMap) {
157 CXFA_NodeSetPair* pNodeSetPair = iter2.second.get();
158 if (!pNodeSetPair)
159 continue;
160 if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) {
161 CXFA_NodeArray rgNodeArray1;
162 CXFA_NodeArray rgNodeArray2;
163 CFX_ArrayTemplate<int32_t> rgIdxArray1;
164 CFX_ArrayTemplate<int32_t> rgIdxArray2;
165 SortNodeArrayByDocumentIdx(pNodeSetPair->first, rgNodeArray1,
166 rgIdxArray1);
167 SortNodeArrayByDocumentIdx(pNodeSetPair->second, rgNodeArray2,
168 rgIdxArray2);
169 CXFA_Node* pParentNode = nullptr;
170 CXFA_Node* pBeforeNode = nullptr;
171 if (bInsertBefore) {
172 pBeforeNode = rgNodeArray2[0];
173 pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent);
174 } else {
175 CXFA_Node* pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1];
176 pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent);
177 pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling);
178 }
179 for (int32_t iIdx = 0; iIdx < rgIdxArray1.GetSize(); iIdx++) {
180 CXFA_Node* pCurNode = rgNodeArray1[iIdx];
181 pParentNode->RemoveChild(pCurNode);
182 pParentNode->InsertChild(pCurNode, pBeforeNode);
183 }
184 }
185 }
186 pNodeSetPairMap->clear();
187 }
188}
189
190CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
191 ASSERT(pInstMgrNode);
192 int32_t iCount = 0;
193 uint32_t dwNameHash = 0;
194 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
195 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
196 XFA_Element eCurType = pNode->GetElementType();
197 if (eCurType == XFA_Element::InstanceManager)
198 break;
199 if ((eCurType != XFA_Element::Subform) &&
200 (eCurType != XFA_Element::SubformSet)) {
201 continue;
202 }
203 if (iCount == 0) {
204 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
205 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
206 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
207 wsInstName.Mid(1) != wsName) {
208 return nullptr;
209 }
210 dwNameHash = pNode->GetNameHash();
211 }
212 if (dwNameHash != pNode->GetNameHash())
213 break;
214
215 iCount++;
216 if (iCount > iIndex)
217 return pNode;
218 }
219 return nullptr;
220}
221
222void InsertItem(CXFA_Node* pInstMgrNode,
223 CXFA_Node* pNewInstance,
224 int32_t iPos,
225 int32_t iCount = -1,
tsepezd19e9122016-11-02 15:43:18 -0700226 bool bMoveDataBindingNodes = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700227 if (iCount < 0)
228 iCount = GetCount(pInstMgrNode);
229 if (iPos < 0)
230 iPos = iCount;
231 if (iPos == iCount) {
232 CXFA_Node* pNextSibling =
233 iCount > 0
234 ? GetItem(pInstMgrNode, iCount - 1)
235 ->GetNodeItem(XFA_NODEITEM_NextSibling)
236 : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
237 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
238 ->InsertChild(pNewInstance, pNextSibling);
239 if (bMoveDataBindingNodes) {
Tom Sepezd4db58f2017-03-02 14:57:59 -0800240 std::unordered_set<CXFA_Node*> sNew;
241 std::unordered_set<CXFA_Node*> sAfter;
dsinclair5b36f0a2016-07-19 10:56:23 -0700242 CXFA_NodeIteratorTemplate<CXFA_Node,
243 CXFA_TraverseStrategy_XFAContainerNode>
244 sIteratorNew(pNewInstance);
245 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
246 pNode = sIteratorNew.MoveToNext()) {
247 CXFA_Node* pDataNode = pNode->GetBindData();
248 if (!pDataNode)
249 continue;
250
251 sNew.insert(pDataNode);
252 }
253 CXFA_NodeIteratorTemplate<CXFA_Node,
254 CXFA_TraverseStrategy_XFAContainerNode>
255 sIteratorAfter(pNextSibling);
256 for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode;
257 pNode = sIteratorAfter.MoveToNext()) {
258 CXFA_Node* pDataNode = pNode->GetBindData();
259 if (!pDataNode)
260 continue;
261
262 sAfter.insert(pDataNode);
263 }
tsepezd19e9122016-11-02 15:43:18 -0700264 ReorderDataNodes(sNew, sAfter, false);
dsinclair5b36f0a2016-07-19 10:56:23 -0700265 }
266 } else {
267 CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos);
268 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
269 ->InsertChild(pNewInstance, pBeforeInstance);
270 if (bMoveDataBindingNodes) {
Tom Sepezd4db58f2017-03-02 14:57:59 -0800271 std::unordered_set<CXFA_Node*> sNew;
272 std::unordered_set<CXFA_Node*> sBefore;
dsinclair5b36f0a2016-07-19 10:56:23 -0700273 CXFA_NodeIteratorTemplate<CXFA_Node,
274 CXFA_TraverseStrategy_XFAContainerNode>
275 sIteratorNew(pNewInstance);
276 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
277 pNode = sIteratorNew.MoveToNext()) {
278 CXFA_Node* pDataNode = pNode->GetBindData();
279 if (!pDataNode)
280 continue;
281
282 sNew.insert(pDataNode);
283 }
284 CXFA_NodeIteratorTemplate<CXFA_Node,
285 CXFA_TraverseStrategy_XFAContainerNode>
286 sIteratorBefore(pBeforeInstance);
287 for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode;
288 pNode = sIteratorBefore.MoveToNext()) {
289 CXFA_Node* pDataNode = pNode->GetBindData();
290 if (!pDataNode)
291 continue;
292
293 sBefore.insert(pDataNode);
294 }
tsepezd19e9122016-11-02 15:43:18 -0700295 ReorderDataNodes(sNew, sBefore, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700296 }
297 }
298}
299
300void RemoveItem(CXFA_Node* pInstMgrNode,
301 CXFA_Node* pRemoveInstance,
tsepezd19e9122016-11-02 15:43:18 -0700302 bool bRemoveDataBinding = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700303 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);
304 if (!bRemoveDataBinding)
305 return;
306
307 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode>
308 sIterator(pRemoveInstance);
309 for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode;
310 pFormNode = sIterator.MoveToNext()) {
311 CXFA_Node* pDataNode = pFormNode->GetBindData();
312 if (!pDataNode)
313 continue;
314
315 if (pDataNode->RemoveBindItem(pFormNode) == 0) {
316 if (CXFA_Node* pDataParent =
317 pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) {
318 pDataParent->RemoveChild(pDataNode);
319 }
320 }
321 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
322 }
323}
324
tsepezd19e9122016-11-02 15:43:18 -0700325CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700326 CXFA_Document* pDocument = pInstMgrNode->GetDocument();
327 CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();
328 CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);
329 CXFA_Node* pDataScope = nullptr;
330 for (CXFA_Node* pRootBoundNode = pFormParent;
331 pRootBoundNode && pRootBoundNode->IsContainerNode();
332 pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) {
333 pDataScope = pRootBoundNode->GetBindData();
334 if (pDataScope)
335 break;
336 }
337 if (!pDataScope) {
338 pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record));
339 ASSERT(pDataScope);
340 }
341 CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer(
tsepezd19e9122016-11-02 15:43:18 -0700342 pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700343 if (pInstance) {
344 pDocument->DataMerge_UpdateBindingRelations(pInstance);
345 pFormParent->RemoveChild(pInstance);
346 }
347 return pInstance;
348}
349
350struct XFA_ExecEventParaInfo {
351 public:
352 uint32_t m_uHash;
353 const FX_WCHAR* m_lpcEventName;
354 XFA_EVENTTYPE m_eventType;
355 uint32_t m_validFlags;
356};
357static const XFA_ExecEventParaInfo gs_eventParaInfos[] = {
358 {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0},
359 {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0},
360 {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5},
361 {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0},
362 {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7},
363 {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1},
364 {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5},
365 {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0},
366 {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0},
367 {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6},
368 {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2},
369 {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0},
370 {0x7233018a, L"validate", XFA_EVENT_Validate, 1},
371 {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3},
372 {0x891f4606, L"change", XFA_EVENT_Change, 4},
373 {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0},
374 {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5},
375 {0xcdce56b3, L"full", XFA_EVENT_Full, 4},
376 {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5},
377 {0xd95657a6, L"click", XFA_EVENT_Click, 4},
378 {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1},
379 {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7},
380 {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2},
381 {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0},
382 {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6},
383};
384
385const XFA_ExecEventParaInfo* GetEventParaInfoByName(
386 const CFX_WideStringC& wsEventName) {
387 uint32_t uHash = FX_HashCode_GetW(wsEventName, false);
388 int32_t iStart = 0;
389 int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
390 do {
391 int32_t iMid = (iStart + iEnd) / 2;
392 const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid];
393 if (uHash == eventParaInfo->m_uHash)
394 return eventParaInfo;
395 if (uHash < eventParaInfo->m_uHash)
396 iEnd = iMid - 1;
397 else
398 iStart = iMid + 1;
399 } while (iStart <= iEnd);
400 return nullptr;
401}
402
403void StrToRGB(const CFX_WideString& strRGB,
404 int32_t& r,
405 int32_t& g,
406 int32_t& b) {
407 r = 0;
408 g = 0;
409 b = 0;
410
411 FX_WCHAR zero = '0';
412 int32_t iIndex = 0;
413 int32_t iLen = strRGB.GetLength();
414 for (int32_t i = 0; i < iLen; ++i) {
415 FX_WCHAR ch = strRGB.GetAt(i);
416 if (ch == L',')
417 ++iIndex;
418 if (iIndex > 2)
419 break;
420
421 int32_t iValue = ch - zero;
422 if (iValue >= 0 && iValue <= 9) {
423 switch (iIndex) {
424 case 0:
425 r = r * 10 + iValue;
426 break;
427 case 1:
428 g = g * 10 + iValue;
429 break;
430 default:
431 b = b * 10 + iValue;
432 break;
433 }
434 }
435 }
436}
437
438enum XFA_KEYTYPE {
439 XFA_KEYTYPE_Custom,
440 XFA_KEYTYPE_Element,
441};
442
443void* GetMapKey_Custom(const CFX_WideStringC& wsKey) {
444 uint32_t dwKey = FX_HashCode_GetW(wsKey, false);
445 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom);
446}
447
448void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) {
449 return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) |
450 (eAttribute << 8) | XFA_KEYTYPE_Element);
451}
452
dsinclair9eb0db12016-07-21 12:01:39 -0700453const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement,
454 XFA_ATTRIBUTE eAttribute,
455 uint32_t dwPacket) {
456 int32_t iCount = 0;
457 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount);
458 if (!pAttr || iCount < 1)
459 return nullptr;
460
461 if (!std::binary_search(pAttr, pAttr + iCount, eAttribute))
462 return nullptr;
463
464 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute);
465 ASSERT(pInfo);
466 if (dwPacket == XFA_XDPPACKET_UNKNOWN)
467 return pInfo;
468 return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr;
469}
470
471const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) {
472 return g_XFAEnumData + eName;
473}
474
dsinclair5b36f0a2016-07-19 10:56:23 -0700475} // namespace
476
477static void XFA_DefaultFreeData(void* pData) {}
478
479static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {
480 XFA_DefaultFreeData, nullptr};
481
weili47bcd4c2016-06-16 08:00:06 -0700482XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {}
483
484XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {}
485
dsinclairb9778472016-06-23 13:34:10 -0700486CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
487 uint16_t ePacket,
488 XFA_ObjectType oType,
dsinclairc1df5d42016-07-18 06:36:51 -0700489 XFA_Element eType,
490 const CFX_WideStringC& elementName)
491 : CXFA_Object(pDoc, oType, eType, elementName),
Dan Sinclair1770c022016-03-14 14:14:16 -0400492 m_pNext(nullptr),
493 m_pChild(nullptr),
494 m_pLastChild(nullptr),
495 m_pParent(nullptr),
496 m_pXMLNode(nullptr),
Dan Sinclair1770c022016-03-14 14:14:16 -0400497 m_ePacket(ePacket),
dsinclairc5a8f212016-06-20 11:11:12 -0700498 m_uNodeFlags(XFA_NodeFlag_None),
Dan Sinclair1770c022016-03-14 14:14:16 -0400499 m_dwNameHash(0),
500 m_pAuxNode(nullptr),
501 m_pMapModuleData(nullptr) {
502 ASSERT(m_pDocument);
503}
weili44f8faf2016-06-01 14:03:56 -0700504
Dan Sinclair1770c022016-03-14 14:14:16 -0400505CXFA_Node::~CXFA_Node() {
weili44f8faf2016-06-01 14:03:56 -0700506 ASSERT(!m_pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400507 RemoveMapModuleKey();
weili44f8faf2016-06-01 14:03:56 -0700508 CXFA_Node* pNode = m_pChild;
Dan Sinclair1770c022016-03-14 14:14:16 -0400509 while (pNode) {
weili44f8faf2016-06-01 14:03:56 -0700510 CXFA_Node* pNext = pNode->m_pNext;
511 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400512 delete pNode;
513 pNode = pNext;
514 }
dsinclairc5a8f212016-06-20 11:11:12 -0700515 if (m_pXMLNode && IsOwnXMLNode())
tsepezc757d9a2017-01-23 11:01:42 -0800516 delete m_pXMLNode;
Dan Sinclair1770c022016-03-14 14:14:16 -0400517}
weili44f8faf2016-06-01 14:03:56 -0700518
tsepezd19e9122016-11-02 15:43:18 -0700519CXFA_Node* CXFA_Node::Clone(bool bRecursive) {
dsinclaira1b07722016-07-11 08:20:58 -0700520 CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700521 if (!pClone)
522 return nullptr;
523
Dan Sinclair1770c022016-03-14 14:14:16 -0400524 MergeAllData(pClone);
525 pClone->UpdateNameHash();
526 if (IsNeedSavingXMLNode()) {
weili44f8faf2016-06-01 14:03:56 -0700527 CFDE_XMLNode* pCloneXML = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400528 if (IsAttributeInXML()) {
529 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -0700530 GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -0700531 CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -0400532 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
533 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -0700534 pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -0400535 }
536 pCloneXML = pCloneXMLElement;
weili44f8faf2016-06-01 14:03:56 -0700537 pCloneXMLElement = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400538 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
539 } else {
tsepezd19e9122016-11-02 15:43:18 -0700540 pCloneXML = m_pXMLNode->Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400541 }
542 pClone->SetXMLMappingNode(pCloneXML);
dsinclairc5a8f212016-06-20 11:11:12 -0700543 pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400544 }
545 if (bRecursive) {
546 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
547 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
548 pClone->InsertChild(pChild->Clone(bRecursive));
549 }
550 }
dsinclairc5a8f212016-06-20 11:11:12 -0700551 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
weili44f8faf2016-06-01 14:03:56 -0700552 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400553 return pClone;
554}
weili44f8faf2016-06-01 14:03:56 -0700555
Dan Sinclair1770c022016-03-14 14:14:16 -0400556CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
557 switch (eItem) {
558 case XFA_NODEITEM_NextSibling:
559 return m_pNext;
560 case XFA_NODEITEM_FirstChild:
561 return m_pChild;
562 case XFA_NODEITEM_Parent:
563 return m_pParent;
564 case XFA_NODEITEM_PrevSibling:
565 if (m_pParent) {
566 CXFA_Node* pSibling = m_pParent->m_pChild;
weili44f8faf2016-06-01 14:03:56 -0700567 CXFA_Node* pPrev = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400568 while (pSibling && pSibling != this) {
569 pPrev = pSibling;
570 pSibling = pSibling->m_pNext;
571 }
572 return pPrev;
573 }
weili44f8faf2016-06-01 14:03:56 -0700574 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400575 default:
576 break;
577 }
weili44f8faf2016-06-01 14:03:56 -0700578 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400579}
weili44f8faf2016-06-01 14:03:56 -0700580
Dan Sinclair1770c022016-03-14 14:14:16 -0400581CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
dsinclairc5a8f212016-06-20 11:11:12 -0700582 XFA_ObjectType eType) const {
weili44f8faf2016-06-01 14:03:56 -0700583 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400584 switch (eItem) {
585 case XFA_NODEITEM_NextSibling:
586 pNode = m_pNext;
dsinclairc5a8f212016-06-20 11:11:12 -0700587 while (pNode && pNode->GetObjectType() != eType)
588 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400589 break;
590 case XFA_NODEITEM_FirstChild:
591 pNode = m_pChild;
dsinclairc5a8f212016-06-20 11:11:12 -0700592 while (pNode && pNode->GetObjectType() != eType)
593 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400594 break;
595 case XFA_NODEITEM_Parent:
596 pNode = m_pParent;
dsinclairc5a8f212016-06-20 11:11:12 -0700597 while (pNode && pNode->GetObjectType() != eType)
598 pNode = pNode->m_pParent;
Dan Sinclair1770c022016-03-14 14:14:16 -0400599 break;
600 case XFA_NODEITEM_PrevSibling:
601 if (m_pParent) {
602 CXFA_Node* pSibling = m_pParent->m_pChild;
603 while (pSibling && pSibling != this) {
dsinclairc5a8f212016-06-20 11:11:12 -0700604 if (eType == pSibling->GetObjectType())
Dan Sinclair1770c022016-03-14 14:14:16 -0400605 pNode = pSibling;
dsinclairc5a8f212016-06-20 11:11:12 -0700606
Dan Sinclair1770c022016-03-14 14:14:16 -0400607 pSibling = pSibling->m_pNext;
608 }
609 }
610 break;
611 default:
612 break;
613 }
614 return pNode;
615}
weili44f8faf2016-06-01 14:03:56 -0700616
Dan Sinclair1770c022016-03-14 14:14:16 -0400617int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes,
tsepez736f28a2016-03-25 14:19:51 -0700618 uint32_t dwTypeFilter,
dsinclair41cb62e2016-06-23 09:20:32 -0700619 XFA_Element eTypeFilter,
Dan Sinclair1770c022016-03-14 14:14:16 -0400620 int32_t iLevel) {
621 if (--iLevel < 0) {
622 return nodes.GetSize();
623 }
dsinclair41cb62e2016-06-23 09:20:32 -0700624 if (eTypeFilter != XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400625 CXFA_Node* pChild = m_pChild;
626 while (pChild) {
dsinclair41cb62e2016-06-23 09:20:32 -0700627 if (pChild->GetElementType() == eTypeFilter) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400628 nodes.Add(pChild);
629 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700630 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400631 }
632 }
633 pChild = pChild->m_pNext;
634 }
635 } else if (dwTypeFilter ==
636 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
637 CXFA_Node* pChild = m_pChild;
638 while (pChild) {
639 nodes.Add(pChild);
640 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700641 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400642 }
643 pChild = pChild->m_pNext;
644 }
645 } else if (dwTypeFilter != 0) {
weili44f8faf2016-06-01 14:03:56 -0700646 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
647 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
648 bool bFilterOneOfProperties =
649 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
Dan Sinclair1770c022016-03-14 14:14:16 -0400650 CXFA_Node* pChild = m_pChild;
651 while (pChild) {
652 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -0700653 GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -0400654 if (pProperty) {
655 if (bFilterProperties) {
656 nodes.Add(pChild);
657 } else if (bFilterOneOfProperties &&
658 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
659 nodes.Add(pChild);
660 } else if (bFilterChildren &&
dsinclair070fcdf2016-06-22 22:04:54 -0700661 (pChild->GetElementType() == XFA_Element::Variables ||
662 pChild->GetElementType() == XFA_Element::PageSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400663 nodes.Add(pChild);
664 }
weili44f8faf2016-06-01 14:03:56 -0700665 } else if (bFilterChildren) {
666 nodes.Add(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400667 }
668 pChild = pChild->m_pNext;
669 }
670 if (bFilterOneOfProperties && nodes.GetSize() < 1) {
671 int32_t iProperties = 0;
672 const XFA_PROPERTY* pProperty =
dsinclair070fcdf2016-06-22 22:04:54 -0700673 XFA_GetElementProperties(GetElementType(), iProperties);
weili44f8faf2016-06-01 14:03:56 -0700674 if (!pProperty || iProperties < 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400675 return 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400676 for (int32_t i = 0; i < iProperties; i++) {
677 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400678 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
679 CXFA_Node* pNewNode =
dsinclaira1b07722016-07-11 08:20:58 -0700680 m_pDocument->CreateNode(pPacket, pProperty[i].eName);
weili44f8faf2016-06-01 14:03:56 -0700681 if (!pNewNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400682 break;
weili44f8faf2016-06-01 14:03:56 -0700683 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -0700684 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400685 nodes.Add(pNewNode);
686 break;
687 }
688 }
689 }
690 }
691 return nodes.GetSize();
692}
weili44f8faf2016-06-01 14:03:56 -0700693
dsinclair41cb62e2016-06-23 09:20:32 -0700694CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
tsepez736f28a2016-03-25 14:19:51 -0700695 uint32_t dwFlags) {
dsinclaira1b07722016-07-11 08:20:58 -0700696 CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
thestigb1a59592016-04-14 18:29:56 -0700697 pNode->SetFlag(dwFlags, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400698 return pNode;
699}
weili44f8faf2016-06-01 14:03:56 -0700700
tsepezd19e9122016-11-02 15:43:18 -0700701CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) {
dsinclair43854a52016-04-27 12:26:00 -0700702 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
dsinclaira1b07722016-07-11 08:20:58 -0700703 CXFA_Node* pClone =
704 m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700705 if (!pClone)
706 return nullptr;
707
Dan Sinclair1770c022016-03-14 14:14:16 -0400708 pClone->SetTemplateNode(this);
709 pClone->UpdateNameHash();
710 pClone->SetXMLMappingNode(GetXMLMappingNode());
711 if (bRecursive) {
712 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
713 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
714 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
715 }
716 }
dsinclairc5a8f212016-06-20 11:11:12 -0700717 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400718 return pClone;
719}
720
721CXFA_Node* CXFA_Node::GetTemplateNode() const {
722 return m_pAuxNode;
723}
724
725void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
726 m_pAuxNode = pTemplateNode;
727}
weili44f8faf2016-06-01 14:03:56 -0700728
Dan Sinclair1770c022016-03-14 14:14:16 -0400729CXFA_Node* CXFA_Node::GetBindData() {
730 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
731 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
732}
weili44f8faf2016-06-01 14:03:56 -0700733
Dan Sinclair1770c022016-03-14 14:14:16 -0400734int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) {
dsinclairc5a8f212016-06-20 11:11:12 -0700735 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700736 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400737 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
738 formItems.Copy(*pItems);
739 return formItems.GetSize();
740 }
741 CXFA_Node* pFormNode =
742 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
weili44f8faf2016-06-01 14:03:56 -0700743 if (pFormNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400744 formItems.Add(pFormNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400745 return formItems.GetSize();
746}
747
Dan Sinclair1770c022016-03-14 14:14:16 -0400748int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
749 ASSERT(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700750 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700751 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400752 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
753 ASSERT(pItems);
754 if (pItems->Find(pFormNode) < 0) {
755 pItems->Add(pFormNode);
756 }
757 return pItems->GetSize();
758 }
759 CXFA_Node* pOldFormItem =
760 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
761 if (!pOldFormItem) {
762 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
763 return 1;
764 } else if (pOldFormItem == pFormNode) {
765 return 1;
766 }
767 CXFA_NodeArray* pItems = new CXFA_NodeArray;
768 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
769 pItems->Add(pOldFormItem);
770 pItems->Add(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700771 m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400772 return 2;
773}
weili44f8faf2016-06-01 14:03:56 -0700774
Dan Sinclair1770c022016-03-14 14:14:16 -0400775int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
dsinclairc5a8f212016-06-20 11:11:12 -0700776 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700777 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400778 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
779 ASSERT(pItems);
780 int32_t iIndex = pItems->Find(pFormNode);
781 int32_t iCount = pItems->GetSize();
782 if (iIndex >= 0) {
weili44f8faf2016-06-01 14:03:56 -0700783 if (iIndex != iCount - 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400784 pItems->SetAt(iIndex, pItems->GetAt(iCount - 1));
Dan Sinclair1770c022016-03-14 14:14:16 -0400785 pItems->RemoveAt(iCount - 1);
786 if (iCount == 2) {
787 CXFA_Node* pLastFormNode = pItems->GetAt(0);
788 SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700789 m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400790 }
791 iCount--;
792 }
793 return iCount;
794 }
795 CXFA_Node* pOldFormItem =
796 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
797 if (pOldFormItem == pFormNode) {
weili44f8faf2016-06-01 14:03:56 -0700798 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
799 pOldFormItem = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400800 }
weili44f8faf2016-06-01 14:03:56 -0700801 return pOldFormItem ? 1 : 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400802}
weili44f8faf2016-06-01 14:03:56 -0700803
tsepezd19e9122016-11-02 15:43:18 -0700804bool CXFA_Node::HasBindItem() {
weili44f8faf2016-06-01 14:03:56 -0700805 return GetPacketID() == XFA_XDPPACKET_Datasets &&
806 GetObject(XFA_ATTRIBUTE_BindingNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400807}
weili44f8faf2016-06-01 14:03:56 -0700808
Dan Sinclair1770c022016-03-14 14:14:16 -0400809CXFA_WidgetData* CXFA_Node::GetWidgetData() {
810 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
811}
weili44f8faf2016-06-01 14:03:56 -0700812
Dan Sinclair1770c022016-03-14 14:14:16 -0400813CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
weili44f8faf2016-06-01 14:03:56 -0700814 if (GetPacketID() != XFA_XDPPACKET_Form)
815 return nullptr;
dsinclair41cb62e2016-06-23 09:20:32 -0700816 XFA_Element eType = GetElementType();
817 if (eType == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700818 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400819 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700820 if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700821 return nullptr;
822
dsinclair41cb62e2016-06-23 09:20:32 -0700823 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400824 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
825 if (pFieldWidgetData &&
826 pFieldWidgetData->GetChoiceListOpen() ==
827 XFA_ATTRIBUTEENUM_MultiSelect) {
weili44f8faf2016-06-01 14:03:56 -0700828 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400829 } else {
830 CFX_WideString wsPicture;
831 if (pFieldWidgetData) {
832 pFieldWidgetData->GetPictureContent(wsPicture,
833 XFA_VALUEPICTURE_DataBind);
834 }
weili44f8faf2016-06-01 14:03:56 -0700835 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400836 return pFieldWidgetData;
Dan Sinclair1770c022016-03-14 14:14:16 -0400837 CXFA_Node* pDataNode = GetBindData();
weili44f8faf2016-06-01 14:03:56 -0700838 if (!pDataNode)
839 return nullptr;
840 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400841 CXFA_NodeArray formNodes;
842 pDataNode->GetBindItems(formNodes);
843 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
844 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -0700845 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -0400846 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400847 pFieldWidgetData = pFormNode->GetWidgetData();
848 if (pFieldWidgetData) {
849 pFieldWidgetData->GetPictureContent(wsPicture,
850 XFA_VALUEPICTURE_DataBind);
851 }
weili44f8faf2016-06-01 14:03:56 -0700852 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400853 break;
weili44f8faf2016-06-01 14:03:56 -0700854 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400855 }
856 return pFieldWidgetData;
857 }
858 }
859 CXFA_Node* pGrandNode =
weili44f8faf2016-06-01 14:03:56 -0700860 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400861 CXFA_Node* pValueNode =
dsinclair070fcdf2016-06-22 22:04:54 -0700862 (pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
Dan Sinclair1770c022016-03-14 14:14:16 -0400863 ? pParentNode
weili44f8faf2016-06-01 14:03:56 -0700864 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400865 if (!pValueNode) {
dsinclair070fcdf2016-06-22 22:04:54 -0700866 pValueNode =
867 (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
868 ? pGrandNode
869 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400870 }
871 CXFA_Node* pParentOfValueNode =
weili44f8faf2016-06-01 14:03:56 -0700872 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400873 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
weili44f8faf2016-06-01 14:03:56 -0700874 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400875}
weili44f8faf2016-06-01 14:03:56 -0700876
tsepezd19e9122016-11-02 15:43:18 -0700877bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400878 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
dsinclair56a8b192016-06-21 14:15:25 -0700879 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
dsinclair43854a52016-04-27 12:26:00 -0700880 ASSERT(pTopSubform);
Dan Sinclair1770c022016-03-14 14:14:16 -0400881 CXFA_Node* pLocaleNode = this;
tsepezd19e9122016-11-02 15:43:18 -0700882 bool bLocale = false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400883 do {
tsepezd19e9122016-11-02 15:43:18 -0700884 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400885 if (!bLocale) {
886 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
887 }
888 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
weili44f8faf2016-06-01 14:03:56 -0700889 if (bLocale)
tsepezd19e9122016-11-02 15:43:18 -0700890 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400891 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
892 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
weili44f8faf2016-06-01 14:03:56 -0700893 if (!wsLocaleName.IsEmpty())
tsepezd19e9122016-11-02 15:43:18 -0700894 return true;
weili44f8faf2016-06-01 14:03:56 -0700895 if (pTopSubform &&
tsepezd19e9122016-11-02 15:43:18 -0700896 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) {
897 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400898 }
899 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
900 if (pLocale) {
901 wsLocaleName = pLocale->GetName();
tsepezd19e9122016-11-02 15:43:18 -0700902 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400903 }
tsepezd19e9122016-11-02 15:43:18 -0700904 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400905}
weili44f8faf2016-06-01 14:03:56 -0700906
Dan Sinclair1770c022016-03-14 14:14:16 -0400907XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
dsinclair56a8b192016-06-21 14:15:25 -0700908 CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
Dan Sinclair1770c022016-03-14 14:14:16 -0400909 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
910 if (pKeep) {
911 XFA_ATTRIBUTEENUM eIntact;
tsepezd19e9122016-11-02 15:43:18 -0700912 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400913 if (eIntact == XFA_ATTRIBUTEENUM_None &&
914 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
915 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
dsinclairc5a8f212016-06-20 11:11:12 -0700916 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
917 XFA_ObjectType::ContainerNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400918 if (pPreviewRow &&
919 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
920 XFA_ATTRIBUTEENUM_Row) {
921 XFA_ATTRIBUTEENUM eValue;
tsepezd19e9122016-11-02 15:43:18 -0700922 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700923 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
924 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
925 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400926 }
weili44f8faf2016-06-01 14:03:56 -0700927 CXFA_Node* pNode =
dsinclair56a8b192016-06-21 14:15:25 -0700928 pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
tsepezd19e9122016-11-02 15:43:18 -0700929 if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700930 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
931 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
932 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400933 }
934 }
935 }
936 return eIntact;
937 }
938 }
dsinclair41cb62e2016-06-23 09:20:32 -0700939 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700940 case XFA_Element::Subform:
Dan Sinclair1770c022016-03-14 14:14:16 -0400941 switch (eLayoutType) {
942 case XFA_ATTRIBUTEENUM_Position:
943 case XFA_ATTRIBUTEENUM_Row:
944 return XFA_ATTRIBUTEENUM_ContentArea;
945 case XFA_ATTRIBUTEENUM_Tb:
946 case XFA_ATTRIBUTEENUM_Table:
947 case XFA_ATTRIBUTEENUM_Lr_tb:
948 case XFA_ATTRIBUTEENUM_Rl_tb:
949 return XFA_ATTRIBUTEENUM_None;
950 default:
951 break;
952 }
953 break;
dsinclair56a8b192016-06-21 14:15:25 -0700954 case XFA_Element::Field: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400955 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700956 if (!pParentNode ||
957 pParentNode->GetElementType() == XFA_Element::PageArea)
Dan Sinclair1770c022016-03-14 14:14:16 -0400958 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400959 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
960 XFA_ATTRIBUTEENUM eParLayout =
961 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
962 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
963 eParLayout == XFA_ATTRIBUTEENUM_Row ||
964 eParLayout == XFA_ATTRIBUTEENUM_Table) {
965 return XFA_ATTRIBUTEENUM_None;
966 }
967 XFA_VERSION version = m_pDocument->GetCurVersionMode();
968 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
969 CXFA_Measurement measureH;
tsepezd19e9122016-11-02 15:43:18 -0700970 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false))
Dan Sinclair1770c022016-03-14 14:14:16 -0400971 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400972 }
973 return XFA_ATTRIBUTEENUM_None;
974 }
975 return XFA_ATTRIBUTEENUM_ContentArea;
976 }
dsinclair56a8b192016-06-21 14:15:25 -0700977 case XFA_Element::Draw:
Dan Sinclair1770c022016-03-14 14:14:16 -0400978 return XFA_ATTRIBUTEENUM_ContentArea;
979 default:
980 break;
981 }
982 return XFA_ATTRIBUTEENUM_None;
983}
weili44f8faf2016-06-01 14:03:56 -0700984
Dan Sinclair1770c022016-03-14 14:14:16 -0400985CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
weili44f8faf2016-06-01 14:03:56 -0700986 if (m_ePacket == XFA_XDPPACKET_Datasets)
Dan Sinclair1770c022016-03-14 14:14:16 -0400987 return m_pAuxNode;
weili44f8faf2016-06-01 14:03:56 -0700988 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400989}
weili44f8faf2016-06-01 14:03:56 -0700990
Dan Sinclair1770c022016-03-14 14:14:16 -0400991void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
dsinclair43854a52016-04-27 12:26:00 -0700992 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
Dan Sinclair1770c022016-03-14 14:14:16 -0400993 m_pAuxNode = pDataDescriptionNode;
994}
weili44f8faf2016-06-01 14:03:56 -0700995
Dan Sinclair1770c022016-03-14 14:14:16 -0400996void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
997 int32_t iLength = pArguments->GetLength();
998 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -0500999 ThrowParamCountMismatchException(L"resolveNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04001000 return;
1001 }
tsepez6fe7d212016-04-06 10:51:14 -07001002 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001003 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclairdf4bc592016-03-31 20:34:43 -07001004 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001005 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001006 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001007 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001008 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001009 refNode = ToNode(pScriptContext->GetThisObject());
tsepez736f28a2016-03-25 14:19:51 -07001010 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001011 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1012 XFA_RESOLVENODE_Siblings;
1013 XFA_RESOLVENODE_RS resoveNodeRS;
tsepezfc58ad12016-04-05 12:22:15 -07001014 int32_t iRet = pScriptContext->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001015 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
dsinclairf27aeec2016-06-07 19:36:18 -07001016 if (iRet < 1) {
1017 pArguments->GetReturnValue()->SetNull();
1018 return;
1019 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001020 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1021 CXFA_Object* pNode = resoveNodeRS.nodes[0];
dsinclairf27aeec2016-06-07 19:36:18 -07001022 pArguments->GetReturnValue()->Assign(
1023 pScriptContext->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001024 } else {
1025 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
1026 resoveNodeRS.pScriptAttribute;
1027 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
dsinclair86fad992016-05-31 11:34:04 -07001028 std::unique_ptr<CFXJSE_Value> pValue(
1029 new CFXJSE_Value(pScriptContext->GetRuntime()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001030 (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))(
tsepezd19e9122016-11-02 15:43:18 -07001031 pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
dsinclairf27aeec2016-06-07 19:36:18 -07001032 pArguments->GetReturnValue()->Assign(pValue.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001033 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001034 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001035 }
1036 }
1037}
weili44f8faf2016-06-01 14:03:56 -07001038
Dan Sinclair1770c022016-03-14 14:14:16 -04001039void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
1040 int32_t iLength = pArguments->GetLength();
1041 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001042 ThrowParamCountMismatchException(L"resolveNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04001043 return;
1044 }
tsepez6fe7d212016-04-06 10:51:14 -07001045 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001046 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclair12a6b0c2016-05-26 11:14:08 -07001047 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001048 if (!pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04001049 return;
tsepez736f28a2016-03-25 14:19:51 -07001050 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001051 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1052 XFA_RESOLVENODE_Siblings;
1053 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001054 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001055 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
dsinclair12a6b0c2016-05-26 11:14:08 -07001056 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001057}
weili44f8faf2016-06-01 14:03:56 -07001058
dsinclair12a6b0c2016-05-26 11:14:08 -07001059void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001060 CFX_WideString wsExpression,
tsepez736f28a2016-03-25 14:19:51 -07001061 uint32_t dwFlag,
Dan Sinclair1770c022016-03-14 14:14:16 -04001062 CXFA_Node* refNode) {
dsinclairdf4bc592016-03-31 20:34:43 -07001063 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001064 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001065 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001066 XFA_RESOLVENODE_RS resoveNodeRS;
weili44f8faf2016-06-01 14:03:56 -07001067 if (!refNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04001068 refNode = this;
tsepez4c3debb2016-04-08 12:20:38 -07001069 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
tsepezfc58ad12016-04-05 12:22:15 -07001070 resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001071 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
1072 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1073 for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) {
1074 if (resoveNodeRS.nodes[i]->IsNode())
1075 pNodeList->Append(resoveNodeRS.nodes[i]->AsNode());
1076 }
1077 } else {
dsinclair12a6b0c2016-05-26 11:14:08 -07001078 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
1079 if (resoveNodeRS.GetAttributeResult(valueArray) > 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001080 CXFA_ObjArray objectArray;
dsinclair12a6b0c2016-05-26 11:14:08 -07001081 valueArray.GetAttributeObject(objectArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04001082 for (int32_t i = 0; i < objectArray.GetSize(); i++) {
1083 if (objectArray[i]->IsNode())
1084 pNodeList->Append(objectArray[i]->AsNode());
1085 }
1086 }
1087 }
dsinclairf27aeec2016-06-07 19:36:18 -07001088 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001089}
weili44f8faf2016-06-01 14:03:56 -07001090
dsinclair12a6b0c2016-05-26 11:14:08 -07001091void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001092 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001093 XFA_ATTRIBUTE eAttribute) {
1094 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001095 ThrowInvalidPropertyException();
1096 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001097 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001098
1099 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
1100 CFX_WideString wsName;
1101 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
dan sinclair65c7c232017-02-02 14:05:30 -08001102 CFX_WideString wsExpression = wsName + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001103 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001104}
weili44f8faf2016-06-01 14:03:56 -07001105
dsinclair12a6b0c2016-05-26 11:14:08 -07001106void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001107 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001108 XFA_ATTRIBUTE eAttribute) {
dsinclairdf4bc592016-03-31 20:34:43 -07001109 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001110 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001111 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001112 if (bSetting) {
Dan Sinclairc8fd3312017-01-02 17:17:02 -05001113 CFX_WideString wsMessage = L"Unable to set ";
Tom Sepezf0b65542017-02-13 10:26:01 -08001114 FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001115 } else {
1116 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
dsinclairf27aeec2016-06-07 19:36:18 -07001117 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001118 }
1119}
weili44f8faf2016-06-01 14:03:56 -07001120
dsinclair12a6b0c2016-05-26 11:14:08 -07001121void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001122 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001123 XFA_ATTRIBUTE eAttribute) {
1124 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001125 ThrowInvalidPropertyException();
1126 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001127 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001128 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
dan sinclair65c7c232017-02-02 14:05:30 -08001129 CFX_WideString wsExpression = L"#" + GetClassName() + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001130 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001131}
weili44f8faf2016-06-01 14:03:56 -07001132
dsinclair12a6b0c2016-05-26 11:14:08 -07001133void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001134 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001135 XFA_ATTRIBUTE eAttribute) {
1136 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001137 ThrowInvalidPropertyException();
1138 return;
1139 }
1140 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
1141 if (pParent) {
1142 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001143 } else {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001144 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001145 }
1146}
weili44f8faf2016-06-01 14:03:56 -07001147
dsinclair12a6b0c2016-05-26 11:14:08 -07001148void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001149 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001150 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001151 if (bSetting) {
1152 ThrowInvalidPropertyException();
1153 return;
1154 }
1155 pValue->SetInteger(GetNodeSameNameIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001156}
weili44f8faf2016-06-01 14:03:56 -07001157
dsinclair12a6b0c2016-05-26 11:14:08 -07001158void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001159 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001160 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001161 if (bSetting) {
1162 ThrowInvalidPropertyException();
1163 return;
1164 }
1165 pValue->SetInteger(GetNodeSameClassIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001166}
weili44f8faf2016-06-01 14:03:56 -07001167
dsinclair12a6b0c2016-05-26 11:14:08 -07001168void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001169 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001170 XFA_ATTRIBUTE eAttribute) {
1171 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001172 ThrowInvalidPropertyException();
1173 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001174 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001175 CFX_WideString wsSOMExpression;
1176 GetSOMExpression(wsSOMExpression);
Tom Sepezf0b65542017-02-13 10:26:01 -08001177 pValue->SetString(wsSOMExpression.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001178}
weili44f8faf2016-06-01 14:03:56 -07001179
Dan Sinclair1770c022016-03-14 14:14:16 -04001180void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
1181 int32_t iLength = pArguments->GetLength();
1182 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001183 ThrowParamCountMismatchException(L"applyXSL");
Dan Sinclair1770c022016-03-14 14:14:16 -04001184 return;
1185 }
tsepez6fe7d212016-04-06 10:51:14 -07001186 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001187 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili60607c32016-05-26 11:53:12 -07001188 // TODO(weili): check whether we need to implement this, pdfium:501.
1189 // For now, just put the variables here to avoid unused variable warning.
1190 (void)wsExpression;
Dan Sinclair1770c022016-03-14 14:14:16 -04001191}
weili60607c32016-05-26 11:53:12 -07001192
Dan Sinclair1770c022016-03-14 14:14:16 -04001193void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
1194 int32_t iLength = pArguments->GetLength();
1195 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001196 ThrowParamCountMismatchException(L"assignNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04001197 return;
1198 }
1199 CFX_WideString wsExpression;
1200 CFX_WideString wsValue;
1201 int32_t iAction = 0;
weili44f8faf2016-06-01 14:03:56 -07001202 wsExpression =
1203 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001204 if (iLength >= 2) {
weili60607c32016-05-26 11:53:12 -07001205 wsValue =
1206 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001207 }
weili60607c32016-05-26 11:53:12 -07001208 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001209 iAction = pArguments->GetInt32(2);
weili60607c32016-05-26 11:53:12 -07001210 // TODO(weili): check whether we need to implement this, pdfium:501.
1211 // For now, just put the variables here to avoid unused variable warning.
1212 (void)wsExpression;
1213 (void)wsValue;
1214 (void)iAction;
Dan Sinclair1770c022016-03-14 14:14:16 -04001215}
weili60607c32016-05-26 11:53:12 -07001216
Dan Sinclair1770c022016-03-14 14:14:16 -04001217void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
1218 int32_t iLength = pArguments->GetLength();
1219 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001220 ThrowParamCountMismatchException(L"clone");
Dan Sinclair1770c022016-03-14 14:14:16 -04001221 return;
1222 }
weili44f8faf2016-06-01 14:03:56 -07001223 bool bClone = !!pArguments->GetInt32(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001224 CXFA_Node* pCloneNode = Clone(bClone);
dsinclairf27aeec2016-06-07 19:36:18 -07001225 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001226 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
1227}
weili44f8faf2016-06-01 14:03:56 -07001228
Dan Sinclair1770c022016-03-14 14:14:16 -04001229void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
1230 int32_t iLength = pArguments->GetLength();
1231 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001232 ThrowParamCountMismatchException(L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001233 return;
1234 }
tsepez6fe7d212016-04-06 10:51:14 -07001235 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001236 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001237 CFX_WideString wsValue;
tsepez4c3debb2016-04-08 12:20:38 -07001238 GetAttribute(wsExpression.AsStringC(), wsValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07001239 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001240 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08001241 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001242}
weili44f8faf2016-06-01 14:03:56 -07001243
Dan Sinclair1770c022016-03-14 14:14:16 -04001244void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
1245 int32_t iLength = pArguments->GetLength();
1246 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001247 ThrowParamCountMismatchException(L"getElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001248 return;
1249 }
1250 CFX_WideString wsExpression;
1251 int32_t iValue = 0;
weili44f8faf2016-06-01 14:03:56 -07001252 wsExpression =
1253 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1254 if (iLength >= 2)
Dan Sinclair1770c022016-03-14 14:14:16 -04001255 iValue = pArguments->GetInt32(1);
dsinclair6e124782016-06-23 12:14:55 -07001256 CXFA_Node* pNode =
1257 GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
dsinclairf27aeec2016-06-07 19:36:18 -07001258 pArguments->GetReturnValue()->Assign(
1259 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001260}
weili65be4b12016-05-25 15:47:43 -07001261
Dan Sinclair1770c022016-03-14 14:14:16 -04001262void CXFA_Node::Script_NodeClass_IsPropertySpecified(
1263 CFXJSE_Arguments* pArguments) {
1264 int32_t iLength = pArguments->GetLength();
1265 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001266 ThrowParamCountMismatchException(L"isPropertySpecified");
Dan Sinclair1770c022016-03-14 14:14:16 -04001267 return;
1268 }
1269 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001270 bool bParent = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001271 int32_t iIndex = 0;
weili44f8faf2016-06-01 14:03:56 -07001272 wsExpression =
1273 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili65be4b12016-05-25 15:47:43 -07001274 if (iLength >= 2)
weili44f8faf2016-06-01 14:03:56 -07001275 bParent = !!pArguments->GetInt32(1);
weili65be4b12016-05-25 15:47:43 -07001276 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001277 iIndex = pArguments->GetInt32(2);
tsepezd19e9122016-11-02 15:43:18 -07001278 bool bHas = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001279 const XFA_ATTRIBUTEINFO* pAttributeInfo =
tsepez4c3debb2016-04-08 12:20:38 -07001280 XFA_GetAttributeByName(wsExpression.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001281 CFX_WideString wsValue;
weili65be4b12016-05-25 15:47:43 -07001282 if (pAttributeInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04001283 bHas = HasAttribute(pAttributeInfo->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04001284 if (!bHas) {
dsinclair6e124782016-06-23 12:14:55 -07001285 XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
1286 bHas = !!GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001287 if (!bHas && bParent && m_pParent) {
1288 // Also check on the parent.
1289 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
1290 if (!bHas)
dsinclair6e124782016-06-23 12:14:55 -07001291 bHas = !!m_pParent->GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001292 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001293 }
dsinclair12a6b0c2016-05-26 11:14:08 -07001294 CFXJSE_Value* pValue = pArguments->GetReturnValue();
1295 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001296 pValue->SetBoolean(bHas);
Dan Sinclair1770c022016-03-14 14:14:16 -04001297}
weili65be4b12016-05-25 15:47:43 -07001298
Dan Sinclair1770c022016-03-14 14:14:16 -04001299void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
1300 int32_t iLength = pArguments->GetLength();
1301 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001302 ThrowParamCountMismatchException(L"loadXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001303 return;
1304 }
1305 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001306 bool bIgnoreRoot = true;
1307 bool bOverwrite = 0;
1308 wsExpression =
1309 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1310 if (wsExpression.IsEmpty())
Tom Sepezd3743ea2016-05-16 15:56:53 -07001311 return;
weili44f8faf2016-06-01 14:03:56 -07001312 if (iLength >= 2)
1313 bIgnoreRoot = !!pArguments->GetInt32(1);
1314 if (iLength >= 3)
1315 bOverwrite = !!pArguments->GetInt32(2);
dsinclaira1b07722016-07-11 08:20:58 -07001316 std::unique_ptr<CXFA_SimpleParser> pParser(
1317 new CXFA_SimpleParser(m_pDocument, false));
weili44f8faf2016-06-01 14:03:56 -07001318 if (!pParser)
Dan Sinclair1770c022016-03-14 14:14:16 -04001319 return;
weili44f8faf2016-06-01 14:03:56 -07001320 CFDE_XMLNode* pXMLNode = nullptr;
1321 int32_t iParserStatus =
1322 pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
1323 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
1324 return;
dsinclairae95f762016-03-29 16:58:29 -07001325 if (bIgnoreRoot &&
1326 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
1327 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
weili44f8faf2016-06-01 14:03:56 -07001328 bIgnoreRoot = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001329 }
tsepezd19e9122016-11-02 15:43:18 -07001330 CXFA_Node* pFakeRoot = Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001331 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
1332 if (!wsContentType.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07001333 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
1334 CFX_WideString(wsContentType));
Dan Sinclair1770c022016-03-14 14:14:16 -04001335 }
dsinclairae95f762016-03-29 16:58:29 -07001336 CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001337 if (!pFakeXMLRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001338 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
tsepezd19e9122016-11-02 15:43:18 -07001339 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001340 }
dsinclair017052a2016-06-28 07:43:51 -07001341 if (!pFakeXMLRoot)
1342 pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName()));
1343
Dan Sinclair1770c022016-03-14 14:14:16 -04001344 if (bIgnoreRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001345 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001346 while (pXMLChild) {
dsinclairae95f762016-03-29 16:58:29 -07001347 CFDE_XMLNode* pXMLSibling =
1348 pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001349 pXMLNode->RemoveChildNode(pXMLChild);
1350 pFakeXMLRoot->InsertChildNode(pXMLChild);
1351 pXMLChild = pXMLSibling;
1352 }
1353 } else {
dsinclairae95f762016-03-29 16:58:29 -07001354 CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001355 if (pXMLParent) {
1356 pXMLParent->RemoveChildNode(pXMLNode);
1357 }
1358 pFakeXMLRoot->InsertChildNode(pXMLNode);
1359 }
1360 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot);
1361 pFakeRoot = pParser->GetRootNode();
1362 if (pFakeRoot) {
1363 if (bOverwrite) {
1364 CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1365 CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1366 int32_t index = 0;
1367 while (pNewChild) {
1368 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1369 pFakeRoot->RemoveChild(pNewChild);
1370 InsertChild(index++, pNewChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001371 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001372 pNewChild = pItem;
1373 }
1374 while (pChild) {
1375 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1376 RemoveChild(pChild);
1377 pFakeRoot->InsertChild(pChild);
1378 pChild = pItem;
1379 }
1380 if (GetPacketID() == XFA_XDPPACKET_Form &&
dsinclair070fcdf2016-06-22 22:04:54 -07001381 GetElementType() == XFA_Element::ExData) {
dsinclairae95f762016-03-29 16:58:29 -07001382 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001383 SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001384 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
weili44f8faf2016-06-01 14:03:56 -07001385 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001386 pFakeXMLRoot = pTempXMLNode;
1387 } else {
weili44f8faf2016-06-01 14:03:56 -07001388 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001389 }
1390 }
tsepezd19e9122016-11-02 15:43:18 -07001391 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001392 } else {
1393 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1394 while (pChild) {
1395 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1396 pFakeRoot->RemoveChild(pChild);
1397 InsertChild(pChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001398 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001399 pChild = pItem;
1400 }
1401 }
1402 if (pFakeXMLRoot) {
1403 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001404 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001405 }
dsinclairc5a8f212016-06-20 11:11:12 -07001406 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001407 } else {
tsepezc757d9a2017-01-23 11:01:42 -08001408 delete pFakeXMLRoot;
1409 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001410 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001411}
weili44f8faf2016-06-01 14:03:56 -07001412
Dan Sinclair1770c022016-03-14 14:14:16 -04001413void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
weili44f8faf2016-06-01 14:03:56 -07001414 // TODO(weili): Check whether we need to implement this, pdfium:501.
Dan Sinclair1770c022016-03-14 14:14:16 -04001415}
1416
1417void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1418 int32_t iLength = pArguments->GetLength();
1419 if (iLength < 0 || iLength > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001420 ThrowParamCountMismatchException(L"saveXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001421 return;
1422 }
weili44f8faf2016-06-01 14:03:56 -07001423 bool bPrettyMode = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001424 if (iLength == 1) {
weili65be4b12016-05-25 15:47:43 -07001425 if (pArguments->GetUTF8String(0) != "pretty") {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001426 ThrowArgumentMismatchException();
Dan Sinclair1770c022016-03-14 14:14:16 -04001427 return;
1428 }
weili44f8faf2016-06-01 14:03:56 -07001429 bPrettyMode = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001430 }
1431 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
weili65be4b12016-05-25 15:47:43 -07001432 if (GetPacketID() == XFA_XDPPACKET_Form ||
1433 GetPacketID() == XFA_XDPPACKET_Datasets) {
1434 CFDE_XMLNode* pElement = nullptr;
1435 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1436 pElement = GetXMLMappingNode();
1437 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
dsinclairf27aeec2016-06-07 19:36:18 -07001438 pArguments->GetReturnValue()->SetString(bsXMLHeader);
weili65be4b12016-05-25 15:47:43 -07001439 return;
1440 }
1441 XFA_DataExporter_DealWithDataGroupNode(this);
1442 }
tsepez833619b2016-12-07 09:21:17 -08001443 CFX_RetainPtr<IFX_MemoryStream> pMemoryStream =
1444 IFX_MemoryStream::Create(true);
1445
1446 // Note: ambiguious below without static_cast.
tsepez7cda31a2016-12-07 12:10:20 -08001447 CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream(
1448 CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream),
1449 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
tsepez833619b2016-12-07 09:21:17 -08001450
Dan Sinclair1770c022016-03-14 14:14:16 -04001451 if (!pStream) {
dsinclairf27aeec2016-06-07 19:36:18 -07001452 pArguments->GetReturnValue()->SetString(bsXMLHeader);
Dan Sinclair1770c022016-03-14 14:14:16 -04001453 return;
1454 }
1455 pStream->SetCodePage(FX_CODEPAGE_UTF8);
dsinclair179bebb2016-04-05 11:02:18 -07001456 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
weili65be4b12016-05-25 15:47:43 -07001457 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepez7cda31a2016-12-07 12:10:20 -08001458 XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001459 else
tsepez7cda31a2016-12-07 12:10:20 -08001460 pElement->SaveXMLNode(pStream);
weili65be4b12016-05-25 15:47:43 -07001461 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1462 // For now, just put it here to avoid unused variable warning.
1463 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001464 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001465 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001466 return;
1467 }
dsinclairf27aeec2016-06-07 19:36:18 -07001468 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001469}
1470
1471void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1472 int32_t iLength = pArguments->GetLength();
1473 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001474 ThrowParamCountMismatchException(L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001475 return;
1476 }
tsepez6fe7d212016-04-06 10:51:14 -07001477 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001478 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001479 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001480 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001481 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001482}
weili60607c32016-05-26 11:53:12 -07001483
Dan Sinclair1770c022016-03-14 14:14:16 -04001484void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1485 int32_t iLength = pArguments->GetLength();
1486 if (iLength != 1 && iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001487 ThrowParamCountMismatchException(L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001488 return;
1489 }
weili60607c32016-05-26 11:53:12 -07001490 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001491 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001492 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1493 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001494 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001495 // TODO(weili): check whether we need to implement this, pdfium:501.
1496 // For now, just put the variables here to avoid unused variable warning.
1497 (void)pNode;
1498 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001499}
weili60607c32016-05-26 11:53:12 -07001500
dsinclair12a6b0c2016-05-26 11:14:08 -07001501void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001502 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001503 XFA_ATTRIBUTE eAttribute) {
1504 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001505 ThrowInvalidPropertyException();
1506 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001507 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001508
1509 CFX_WideString wsNameSpace;
1510 TryNamespace(wsNameSpace);
Tom Sepezf0b65542017-02-13 10:26:01 -08001511 pValue->SetString(wsNameSpace.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001512}
weili44f8faf2016-06-01 14:03:56 -07001513
dsinclair12a6b0c2016-05-26 11:14:08 -07001514void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001515 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001516 XFA_ATTRIBUTE eAttribute) {
1517 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001518 ThrowInvalidPropertyException();
1519 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001520 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001521 pValue->Assign(
1522 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001523}
weili44f8faf2016-06-01 14:03:56 -07001524
dsinclair12a6b0c2016-05-26 11:14:08 -07001525void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001526 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001527 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001528 if (bSetting) {
1529 ThrowInvalidPropertyException();
1530 return;
1531 }
1532 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001533}
weili44f8faf2016-06-01 14:03:56 -07001534
dsinclair12a6b0c2016-05-26 11:14:08 -07001535void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001536 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001537 XFA_ATTRIBUTE eAttribute) {
1538 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001539 ThrowInvalidPropertyException();
1540 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001541 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001542 if (GetElementType() == XFA_Element::Subform) {
1543 pValue->SetBoolean(false);
1544 return;
1545 }
1546 CFX_WideString strValue;
1547 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001548}
weili44f8faf2016-06-01 14:03:56 -07001549
dsinclair12a6b0c2016-05-26 11:14:08 -07001550void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001551 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001552 XFA_ATTRIBUTE eAttribute) {
1553 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001554 ThrowInvalidPropertyException();
1555 return;
1556 }
1557
1558 CXFA_NodeArray properts;
1559 int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty);
1560 if (iSize > 0) {
1561 pValue->Assign(
1562 m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0]));
Dan Sinclair1770c022016-03-14 14:14:16 -04001563 }
1564}
weili44f8faf2016-06-01 14:03:56 -07001565
Dan Sinclair1770c022016-03-14 14:14:16 -04001566void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001567
Dan Sinclair1770c022016-03-14 14:14:16 -04001568void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1569 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001570 pArguments->GetReturnValue()->SetObject(
1571 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001572}
1573void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1574}
dsinclair5b36f0a2016-07-19 10:56:23 -07001575
Dan Sinclair1770c022016-03-14 14:14:16 -04001576void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1577 Script_Template_CreateNode(pArguments);
1578}
dsinclair5b36f0a2016-07-19 10:56:23 -07001579
Dan Sinclair1770c022016-03-14 14:14:16 -04001580void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1581 int32_t iLength = pArguments->GetLength();
1582 if (iLength < 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001583 ThrowParamCountMismatchException(L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001584 return;
1585 }
1586 CFX_WideString wsNameSpace;
1587 if (iLength >= 1) {
1588 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001589 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001590 }
1591 CFX_WideString wsNodeNameSpace;
1592 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001593 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001594 if (pValue)
1595 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001596}
dsinclair5b36f0a2016-07-19 10:56:23 -07001597
dsinclair12a6b0c2016-05-26 11:14:08 -07001598void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001599 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001600 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001601
dsinclair12a6b0c2016-05-26 11:14:08 -07001602void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001603 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001604 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001605
dsinclair12a6b0c2016-05-26 11:14:08 -07001606void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001607 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001608 XFA_ATTRIBUTE eAttribute) {
1609 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001610 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001611 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001612 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001613 }
1614}
dsinclair5b36f0a2016-07-19 10:56:23 -07001615
dsinclair12a6b0c2016-05-26 11:14:08 -07001616void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001617 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001618 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001619 if (bSetting) {
1620 ThrowInvalidPropertyException();
1621 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001622 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001623 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001624}
dsinclair5b36f0a2016-07-19 10:56:23 -07001625
dsinclair12a6b0c2016-05-26 11:14:08 -07001626void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001627 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001628 XFA_ATTRIBUTE eAttribute) {
1629 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001630 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001631 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001632 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001633 }
1634}
dsinclair5b36f0a2016-07-19 10:56:23 -07001635
dsinclair12a6b0c2016-05-26 11:14:08 -07001636void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001637 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001638 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001639 if (bSetting) {
1640 ThrowInvalidPropertyException();
1641 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001642 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001643 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001644}
thestigb1a59592016-04-14 18:29:56 -07001645
Dan Sinclair1770c022016-03-14 14:14:16 -04001646void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001647 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001648 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001649 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001650 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001651 return;
thestigb1a59592016-04-14 18:29:56 -07001652
dsinclaira1b07722016-07-11 08:20:58 -07001653 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001654 if (!pNotify)
1655 return;
1656
1657 uint32_t dwPacket = GetPacketID();
1658 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1659 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001660 return;
1661 }
thestigb1a59592016-04-14 18:29:56 -07001662
1663 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001664 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001665 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001666 bNeedFindContainer = true;
1667 pNotify->OnValueChanged(this, eAttribute, this,
1668 GetNodeItem(XFA_NODEITEM_Parent));
1669 break;
dsinclair56a8b192016-06-21 14:15:25 -07001670 case XFA_Element::Font:
1671 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001672 bNeedFindContainer = true;
1673 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001674 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001675 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1676 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1677 } else {
1678 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1679 }
1680 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001681 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001682 bNeedFindContainer = true;
1683 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001684 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001685 if (pParentNode->IsContainerNode()) {
1686 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001687 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001688 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1689 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1690 } else {
1691 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001692 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001693 pNotify->OnValueChanged(this, eAttribute, pNode,
1694 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001695 }
thestigb1a59592016-04-14 18:29:56 -07001696 }
1697 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001698 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001699 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001700 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001701 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1702 eUIType == XFA_Element::NumericEdit ||
1703 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001704 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001705 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001706 pNotify->OnValueChanged(this, eAttribute, pUINode,
1707 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001708 }
thestigb1a59592016-04-14 18:29:56 -07001709 }
1710 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001711 case XFA_Element::Button:
1712 case XFA_Element::Barcode:
1713 case XFA_Element::ChoiceList:
1714 case XFA_Element::DateTimeEdit:
1715 case XFA_Element::NumericEdit:
1716 case XFA_Element::PasswordEdit:
1717 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001718 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1719 if (pUINode) {
1720 pNotify->OnValueChanged(this, eAttribute, pUINode,
1721 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1722 }
1723 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001724 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001725 bNeedFindContainer = true;
1726 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1727 if (pUINode) {
1728 pNotify->OnValueChanged(this, eAttribute, pUINode,
1729 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1730 }
1731 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001732 case XFA_Element::Keep:
1733 case XFA_Element::Bookend:
1734 case XFA_Element::Break:
1735 case XFA_Element::BreakAfter:
1736 case XFA_Element::BreakBefore:
1737 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001738 bNeedFindContainer = true;
1739 break;
dsinclair56a8b192016-06-21 14:15:25 -07001740 case XFA_Element::Area:
1741 case XFA_Element::Draw:
1742 case XFA_Element::ExclGroup:
1743 case XFA_Element::Field:
1744 case XFA_Element::Subform:
1745 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001746 pLayoutPro->AddChangedContainer(this);
1747 pNotify->OnValueChanged(this, eAttribute, this, this);
1748 break;
dsinclair56a8b192016-06-21 14:15:25 -07001749 case XFA_Element::Sharptext:
1750 case XFA_Element::Sharpxml:
1751 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001752 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1753 if (!pTextNode) {
1754 return;
1755 }
1756 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1757 if (!pValueNode) {
1758 return;
1759 }
dsinclair41cb62e2016-06-23 09:20:32 -07001760 XFA_Element eType = pValueNode->GetElementType();
1761 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001762 bNeedFindContainer = true;
1763 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1764 if (pNode && pNode->IsContainerNode()) {
1765 if (bScriptModify) {
1766 pValueNode = pNode;
1767 }
1768 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1769 } else {
1770 pNotify->OnValueChanged(this, eAttribute, pNode,
1771 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001772 }
thestigb1a59592016-04-14 18:29:56 -07001773 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001774 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001775 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1776 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001777 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001778 }
1779 }
thestigb1a59592016-04-14 18:29:56 -07001780 }
1781 } break;
1782 default:
1783 break;
1784 }
1785 if (bNeedFindContainer) {
1786 CXFA_Node* pParent = this;
1787 while (pParent) {
1788 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001789 break;
thestigb1a59592016-04-14 18:29:56 -07001790
1791 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001792 }
thestigb1a59592016-04-14 18:29:56 -07001793 if (pParent) {
1794 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001795 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001796 }
1797}
thestigb1a59592016-04-14 18:29:56 -07001798
dsinclair12a6b0c2016-05-26 11:14:08 -07001799void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001800 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001801 XFA_ATTRIBUTE eAttribute) {
1802 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001803 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001804 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001805 if (eAttribute == XFA_ATTRIBUTE_Use &&
1806 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001807 CXFA_Node* pTemplateNode =
1808 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1809 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001810 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1811 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001812
1813 CFX_WideString wsID;
1814 CFX_WideString wsSOM;
1815 if (!wsValue.IsEmpty()) {
1816 if (wsValue[0] == '#') {
1817 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001818 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001819 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001820 }
1821 }
weili44f8faf2016-06-01 14:03:56 -07001822 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001823 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001824 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001825 XFA_RESOLVENODE_Attributes |
1826 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1827 XFA_RESOLVENODE_Siblings;
1828 XFA_RESOLVENODE_RS resoveNodeRS;
1829 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001830 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001831 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) {
1832 pProtoNode = resoveNodeRS.nodes[0]->AsNode();
1833 }
1834 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001835 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001836 }
1837 if (pProtoNode) {
1838 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1839 while (pHeadChild) {
1840 CXFA_Node* pSibling =
1841 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1842 RemoveChild(pHeadChild);
1843 pHeadChild = pSibling;
1844 }
tsepezd19e9122016-11-02 15:43:18 -07001845 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001846 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1847 while (pHeadChild) {
1848 CXFA_Node* pSibling =
1849 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1850 pProtoForm->RemoveChild(pHeadChild);
1851 InsertChild(pHeadChild);
1852 pHeadChild = pSibling;
1853 }
1854 m_pDocument->RemovePurgeNode(pProtoForm);
1855 delete pProtoForm;
1856 }
1857 }
1858 } else {
1859 CFX_WideString wsValue;
1860 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001861 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001862 }
1863}
dsinclair5b36f0a2016-07-19 10:56:23 -07001864
dsinclair12a6b0c2016-05-26 11:14:08 -07001865void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001866 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001867 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001868 if (bSetting) {
1869 ThrowInvalidPropertyException();
1870 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001871 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001872
1873 CFX_WideString wsValue;
1874 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001875 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001876}
dsinclair5b36f0a2016-07-19 10:56:23 -07001877
Dan Sinclair1770c022016-03-14 14:14:16 -04001878void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1879 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001880 if (argc != 0 && argc != 1) {
1881 ThrowParamCountMismatchException(L"execute");
1882 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001883 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001884 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001885}
dsinclair5b36f0a2016-07-19 10:56:23 -07001886
Dan Sinclair1770c022016-03-14 14:14:16 -04001887void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001888 if (pArguments->GetLength() != 0)
1889 ThrowParamCountMismatchException(L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001890}
dsinclair5b36f0a2016-07-19 10:56:23 -07001891
dsinclair12a6b0c2016-05-26 11:14:08 -07001892void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001893 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001894 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001895
dsinclair12a6b0c2016-05-26 11:14:08 -07001896void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001897 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001898 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001899
dsinclair12a6b0c2016-05-26 11:14:08 -07001900void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001901 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001902 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001903
dsinclair12a6b0c2016-05-26 11:14:08 -07001904void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001905 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001906 XFA_SOM_MESSAGETYPE iMessageType) {
1907 CXFA_WidgetData* pWidgetData = GetWidgetData();
1908 if (!pWidgetData) {
1909 return;
1910 }
tsepezd19e9122016-11-02 15:43:18 -07001911 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001912 CXFA_Validate validate = pWidgetData->GetValidate();
1913 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001914 validate = pWidgetData->GetValidate(true);
1915 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001916 }
1917 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001918 switch (iMessageType) {
1919 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001920 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001921 break;
1922 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001923 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001924 break;
1925 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001926 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001927 break;
1928 default:
1929 break;
1930 }
1931 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001932 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001933 if (!pNotify) {
1934 return;
1935 }
1936 pNotify->AddCalcValidate(this);
1937 }
1938 } else {
1939 CFX_WideString wsMessage;
1940 switch (iMessageType) {
1941 case XFA_SOM_ValidationMessage:
1942 validate.GetScriptMessageText(wsMessage);
1943 break;
1944 case XFA_SOM_FormatMessage:
1945 validate.GetFormatMessageText(wsMessage);
1946 break;
1947 case XFA_SOM_MandatoryMessage:
1948 validate.GetNullMessageText(wsMessage);
1949 break;
1950 default:
1951 break;
1952 }
Tom Sepezf0b65542017-02-13 10:26:01 -08001953 pValue->SetString(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001954 }
1955}
dsinclair5b36f0a2016-07-19 10:56:23 -07001956
dsinclair12a6b0c2016-05-26 11:14:08 -07001957void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001958 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001959 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001960 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001961}
dsinclair5b36f0a2016-07-19 10:56:23 -07001962
dsinclair12a6b0c2016-05-26 11:14:08 -07001963void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001964 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001965 XFA_ATTRIBUTE eAttribute) {
1966 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001967 ThrowInvalidPropertyException();
1968 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001969 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001970
1971 CXFA_WidgetData* pWidgetData = GetWidgetData();
1972 if (!pWidgetData) {
1973 pValue->SetInteger(0);
1974 return;
1975 }
1976 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001977}
dsinclair5b36f0a2016-07-19 10:56:23 -07001978
dsinclair12a6b0c2016-05-26 11:14:08 -07001979void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001980 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001981 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001982 XFA_Element eType = GetElementType();
1983 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001984 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001985 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001986 }
1987 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001988 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001989 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001990 }
1991 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001992 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001993 return;
1994 }
1995 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001996 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07001997 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07001998 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07001999
Dan Sinclair1770c022016-03-14 14:14:16 -04002000 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07002001 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002002 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
2003 CXFA_NodeArray formNodes;
2004 GetBindItems(formNodes);
2005 CFX_WideString wsPicture;
2006 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
2007 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -07002008 if (!pFormNode || pFormNode->HasRemovedChildren()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002009 continue;
2010 }
2011 pContainerWidgetData = pFormNode->GetContainerWidgetData();
2012 if (pContainerWidgetData) {
2013 pContainerWidgetData->GetPictureContent(wsPicture,
2014 XFA_VALUEPICTURE_DataBind);
2015 }
2016 if (!wsPicture.IsEmpty()) {
2017 break;
2018 }
weili44f8faf2016-06-01 14:03:56 -07002019 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002020 }
2021 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
2022 pContainerWidgetData = GetContainerWidgetData();
2023 }
2024 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002025 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002026 }
tsepezd19e9122016-11-02 15:43:18 -07002027 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002028 } else {
tsepezd19e9122016-11-02 15:43:18 -07002029 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07002030 if (content.IsEmpty() && eType != XFA_Element::Text &&
2031 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07002032 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07002033 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002034 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07002035 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07002036 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002037 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002038 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002039 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002040 }
2041 }
2042}
dsinclair5b36f0a2016-07-19 10:56:23 -07002043
dsinclair12a6b0c2016-05-26 11:14:08 -07002044void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002045 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002046 XFA_ATTRIBUTE eAttribute) {
2047 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002048 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002049 return;
2050 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002051
tsepezd19e9122016-11-02 15:43:18 -07002052 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002053 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002054 pValue->SetNull();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002055 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002056 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002057 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002058}
dsinclair5b36f0a2016-07-19 10:56:23 -07002059
dsinclair12a6b0c2016-05-26 11:14:08 -07002060void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002061 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002062 XFA_ATTRIBUTE eAttribute) {
2063 if (bSetting) {
2064 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002065 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002066 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002067
tsepezb4c9f3f2016-04-13 15:41:21 -07002068 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002069 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002070 CFX_WideString wsFormatValue(wsNewValue);
2071 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2072 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002073 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002074 }
tsepezd19e9122016-11-02 15:43:18 -07002075 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002076 } else {
tsepezd19e9122016-11-02 15:43:18 -07002077 CFX_WideString wsValue = GetScriptContent(true);
dan sinclair65c7c232017-02-02 14:05:30 -08002078 pValue->SetBoolean(wsValue == L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002079 }
2080}
dsinclair2f5582f2016-06-09 11:48:23 -07002081
dsinclair12a6b0c2016-05-26 11:14:08 -07002082void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002083 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002084 XFA_ATTRIBUTE eAttribute) {
2085 CXFA_WidgetData* pWidgetData = GetWidgetData();
2086 if (!pWidgetData) {
2087 return;
2088 }
tsepezd19e9122016-11-02 15:43:18 -07002089 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002090 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002091 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002092 int32_t r = 0;
2093 int32_t g = 0;
2094 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002095 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002096 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2097 for (int32_t i = 0; i < iSize; ++i) {
2098 CXFA_Edge edge = border.GetEdge(i);
2099 edge.SetColor(rgb);
2100 }
2101 } else {
2102 CXFA_Edge edge = border.GetEdge(0);
2103 FX_ARGB color = edge.GetColor();
2104 int32_t a, r, g, b;
2105 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002106 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002107 strColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002108 pValue->SetString(strColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002109 }
2110}
dsinclair5b36f0a2016-07-19 10:56:23 -07002111
dsinclair12a6b0c2016-05-26 11:14:08 -07002112void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002113 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002114 XFA_ATTRIBUTE eAttribute) {
2115 CXFA_WidgetData* pWidgetData = GetWidgetData();
2116 if (!pWidgetData) {
2117 return;
2118 }
tsepezd19e9122016-11-02 15:43:18 -07002119 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002120 int32_t iSize = border.CountEdges();
2121 CFX_WideString wsThickness;
2122 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002123 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002124 for (int32_t i = 0; i < iSize; ++i) {
2125 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002126 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002127 edge.SetMSThickness(thickness);
2128 }
2129 } else {
2130 CXFA_Edge edge = border.GetEdge(0);
2131 CXFA_Measurement thickness = edge.GetMSThickness();
2132 thickness.ToString(wsThickness);
Tom Sepezf0b65542017-02-13 10:26:01 -08002133 pValue->SetString(wsThickness.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002134 }
2135}
dsinclair5b36f0a2016-07-19 10:56:23 -07002136
dsinclair12a6b0c2016-05-26 11:14:08 -07002137void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002138 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002139 XFA_ATTRIBUTE eAttribute) {
2140 CXFA_WidgetData* pWidgetData = GetWidgetData();
2141 if (!pWidgetData) {
2142 return;
2143 }
tsepezd19e9122016-11-02 15:43:18 -07002144 CXFA_Border border = pWidgetData->GetBorder(true);
2145 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002146 CXFA_Node* pNode = borderfill.GetNode();
2147 if (!pNode) {
2148 return;
2149 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002150 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002151 int32_t r;
2152 int32_t g;
2153 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002154 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002155 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2156 borderfill.SetColor(color);
2157 } else {
2158 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002159 int32_t a;
2160 int32_t r;
2161 int32_t g;
2162 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002163 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002164 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002165 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002166 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002167 }
2168}
dsinclair5b36f0a2016-07-19 10:56:23 -07002169
dsinclair12a6b0c2016-05-26 11:14:08 -07002170void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002171 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002172 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002173 if (bSetting) {
2174 ThrowInvalidPropertyException();
2175 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002176 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002177
2178 CXFA_Node* pDataNode = GetBindData();
2179 if (!pDataNode) {
2180 pValue->SetNull();
2181 return;
2182 }
2183
2184 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002185}
dsinclair5b36f0a2016-07-19 10:56:23 -07002186
dsinclair12a6b0c2016-05-26 11:14:08 -07002187void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002188 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002189 XFA_ATTRIBUTE eAttribute) {
2190 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002191 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002192 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002193 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002194 XFA_Element uiType = pWidgetData->GetUIType();
2195 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002196 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002197 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002198 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002199 }
2200 }
2201 } else {
tsepezd19e9122016-11-02 15:43:18 -07002202 CFX_WideString content = GetScriptContent(true);
Tom Sepezf0b65542017-02-13 10:26:01 -08002203 if (content.IsEmpty())
dsinclairf27aeec2016-06-07 19:36:18 -07002204 pValue->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002205 else
2206 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002207 }
2208}
dsinclair5b36f0a2016-07-19 10:56:23 -07002209
dsinclair12a6b0c2016-05-26 11:14:08 -07002210void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002211 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002212 XFA_ATTRIBUTE eAttribute) {
2213 CXFA_WidgetData* pWidgetData = GetWidgetData();
2214 if (!pWidgetData) {
2215 return;
2216 }
2217 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002218 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002219 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002220 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002221 } else {
2222 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002223 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002224 }
dsinclair2f5582f2016-06-09 11:48:23 -07002225 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002226 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002227 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002228
Dan Sinclair1770c022016-03-14 14:14:16 -04002229 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002230 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002231 int32_t iLeadDigits = 0;
2232 int32_t iFracDigits = 0;
2233 pWidgetData->GetLeadDigits(iLeadDigits);
2234 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002235 wsNewText =
2236 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002237 }
2238 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2239 CFX_WideString wsFormatText(wsNewText);
2240 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002241 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002242 }
tsepezd19e9122016-11-02 15:43:18 -07002243 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002244 } else {
tsepezd19e9122016-11-02 15:43:18 -07002245 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002246 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002247 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002248 } else {
2249 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002250 CXFA_Value defVal = pWidgetData->GetFormValue();
2251 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002252 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002253 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002254 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
Tom Sepezf0b65542017-02-13 10:26:01 -08002255 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002256 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002257 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002258 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002259 }
dsinclair070fcdf2016-06-22 22:04:54 -07002260 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002261 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002262 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002263 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002264 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
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 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002268 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002269 }
2270 }
2271 }
2272}
dsinclair5b36f0a2016-07-19 10:56:23 -07002273
dsinclair12a6b0c2016-05-26 11:14:08 -07002274void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002275 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002276 XFA_ATTRIBUTE eAttribute) {
2277 CXFA_WidgetData* pWidgetData = GetWidgetData();
2278 if (!pWidgetData) {
2279 return;
2280 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002281 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002282 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002283 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002284 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002285 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
Tom Sepezf0b65542017-02-13 10:26:01 -08002286 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002287 }
2288}
dsinclair5b36f0a2016-07-19 10:56:23 -07002289
dsinclair12a6b0c2016-05-26 11:14:08 -07002290void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002291 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002292 XFA_ATTRIBUTE eAttribute) {
2293 CXFA_WidgetData* pWidgetData = GetWidgetData();
2294 if (!pWidgetData) {
2295 return;
2296 }
tsepezd19e9122016-11-02 15:43:18 -07002297 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002298 CXFA_Node* pNode = font.GetNode();
2299 if (!pNode) {
2300 return;
2301 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002302 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002303 int32_t r;
2304 int32_t g;
2305 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002306 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002307 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2308 font.SetColor(color);
2309 } else {
2310 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002311 int32_t a;
2312 int32_t r;
2313 int32_t g;
2314 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002315 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002316 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002317 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002318 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002319 }
2320}
dsinclair5b36f0a2016-07-19 10:56:23 -07002321
dsinclair12a6b0c2016-05-26 11:14:08 -07002322void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002323 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002324 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002325 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002326}
dsinclair5b36f0a2016-07-19 10:56:23 -07002327
dsinclair12a6b0c2016-05-26 11:14:08 -07002328void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002329 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002330 XFA_ATTRIBUTE eAttribute) {
2331 CXFA_WidgetData* pWidgetData = GetWidgetData();
2332 if (!pWidgetData) {
2333 return;
2334 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002335 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002336 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002337 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002338 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002339 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
Tom Sepezf0b65542017-02-13 10:26:01 -08002340 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002341 }
2342}
dsinclair5b36f0a2016-07-19 10:56:23 -07002343
dsinclair12a6b0c2016-05-26 11:14:08 -07002344void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002345 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002346 XFA_ATTRIBUTE eAttribute) {
2347 CXFA_WidgetData* pWidgetData = GetWidgetData();
2348 if (!pWidgetData) {
2349 return;
2350 }
tsepezd19e9122016-11-02 15:43:18 -07002351 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002352 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002353 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002354 } else {
2355 int32_t iValue = validate.GetNullTest();
2356 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002357 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002358 CFX_WideString wsValue;
2359 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002360 wsValue = pInfo->pName;
Tom Sepezf0b65542017-02-13 10:26:01 -08002361 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002362 }
2363}
dsinclair5b36f0a2016-07-19 10:56:23 -07002364
dsinclair12a6b0c2016-05-26 11:14:08 -07002365void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002366 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002367 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002368 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002369}
dsinclair5b36f0a2016-07-19 10:56:23 -07002370
dsinclair12a6b0c2016-05-26 11:14:08 -07002371void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002372 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002373 XFA_ATTRIBUTE eAttribute) {
2374 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002375 ThrowInvalidPropertyException();
2376 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002377 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002378 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002379}
dsinclair5b36f0a2016-07-19 10:56:23 -07002380
dsinclair12a6b0c2016-05-26 11:14:08 -07002381void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002382 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002383 XFA_ATTRIBUTE eAttribute) {
2384 CXFA_WidgetData* pWidgetData = GetWidgetData();
2385 if (!pWidgetData) {
2386 return;
2387 }
2388 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002389 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002390 if (iIndex == -1) {
2391 pWidgetData->ClearAllSelections();
2392 return;
2393 }
tsepezd19e9122016-11-02 15:43:18 -07002394 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002395 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002396 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002397 }
2398}
dsinclair5b36f0a2016-07-19 10:56:23 -07002399
Dan Sinclair1770c022016-03-14 14:14:16 -04002400void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2401 CXFA_WidgetData* pWidgetData = GetWidgetData();
2402 if (!pWidgetData) {
2403 return;
2404 }
tsepezd19e9122016-11-02 15:43:18 -07002405 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002406}
dsinclair5b36f0a2016-07-19 10:56:23 -07002407
Dan Sinclair1770c022016-03-14 14:14:16 -04002408void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002409 if (pArguments->GetLength() != 1) {
2410 ThrowParamCountMismatchException(L"execEvent");
2411 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002412 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002413
2414 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2415 int32_t iRet = execSingleEventByName(
2416 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2417 XFA_Element::Field);
2418 if (eventString != "validate")
2419 return;
2420
2421 pArguments->GetReturnValue()->SetBoolean(
2422 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002423}
dsinclair5b36f0a2016-07-19 10:56:23 -07002424
Dan Sinclair1770c022016-03-14 14:14:16 -04002425void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002426 if (pArguments->GetLength() != 0) {
2427 ThrowParamCountMismatchException(L"execInitialize");
2428 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002429 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002430
2431 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2432 if (!pNotify)
2433 return;
2434
2435 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002436}
dsinclair5b36f0a2016-07-19 10:56:23 -07002437
Dan Sinclair1770c022016-03-14 14:14:16 -04002438void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2439 int32_t iLength = pArguments->GetLength();
2440 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002441 ThrowParamCountMismatchException(L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002442 return;
2443 }
2444 CXFA_WidgetData* pWidgetData = GetWidgetData();
2445 if (!pWidgetData) {
2446 return;
2447 }
2448 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002449 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002450 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002451 if (pValue)
2452 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002453}
dsinclair5b36f0a2016-07-19 10:56:23 -07002454
Dan Sinclair1770c022016-03-14 14:14:16 -04002455void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2456 int32_t iLength = pArguments->GetLength();
2457 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002458 ThrowParamCountMismatchException(L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002459 return;
2460 }
2461 int32_t iIndex = pArguments->GetInt32(0);
2462 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002463 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002464 return;
2465 }
2466 CXFA_WidgetData* pWidgetData = GetWidgetData();
2467 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002468 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002469 return;
2470 }
2471 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002472 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002473 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002474 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002475 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002476 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002477}
dsinclair5b36f0a2016-07-19 10:56:23 -07002478
Dan Sinclair1770c022016-03-14 14:14:16 -04002479void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2480 int32_t iLength = pArguments->GetLength();
2481 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002482 ThrowParamCountMismatchException(L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002483 return;
2484 }
2485 CXFA_WidgetData* pWidgetData = GetWidgetData();
2486 if (!pWidgetData) {
2487 return;
2488 }
2489 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002490 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002491 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002492 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002493 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002494 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08002495 pValue->SetString(wsBoundValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002496}
dsinclair5b36f0a2016-07-19 10:56:23 -07002497
Dan Sinclair1770c022016-03-14 14:14:16 -04002498void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2499 int32_t iLength = pArguments->GetLength();
2500 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002501 ThrowParamCountMismatchException(L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002502 return;
2503 }
2504 CXFA_WidgetData* pWidgetData = GetWidgetData();
2505 if (!pWidgetData) {
2506 return;
2507 }
2508 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002509 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002510 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002511 if (pValue)
2512 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002513}
dsinclair5b36f0a2016-07-19 10:56:23 -07002514
Dan Sinclair1770c022016-03-14 14:14:16 -04002515void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002516 if (pArguments->GetLength() != 0) {
2517 ThrowParamCountMismatchException(L"execCalculate");
2518 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002519 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002520
2521 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2522 if (!pNotify)
2523 return;
2524
2525 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002526}
dsinclair5b36f0a2016-07-19 10:56:23 -07002527
Dan Sinclair1770c022016-03-14 14:14:16 -04002528void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002529
Dan Sinclair1770c022016-03-14 14:14:16 -04002530void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2531 int32_t iLength = pArguments->GetLength();
2532 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002533 ThrowParamCountMismatchException(L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002534 return;
2535 }
2536 int32_t iIndex = pArguments->GetInt32(0);
2537 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002538 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002539 return;
2540 }
2541 CXFA_WidgetData* pWidgetData = GetWidgetData();
2542 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002543 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002544 return;
2545 }
2546 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002547 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002548 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002549 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002550 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002551 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002552}
dsinclair5b36f0a2016-07-19 10:56:23 -07002553
Dan Sinclair1770c022016-03-14 14:14:16 -04002554void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2555 int32_t iLength = pArguments->GetLength();
2556 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002557 ThrowParamCountMismatchException(L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002558 return;
2559 }
2560 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002561 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002562 return;
thestig800222e2016-05-26 22:00:29 -07002563
Dan Sinclair1770c022016-03-14 14:14:16 -04002564 int32_t iIndex = pArguments->GetInt32(0);
2565 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002566 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002567 } else {
thestig800222e2016-05-26 22:00:29 -07002568 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002569 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002570 }
2571}
dsinclair5b36f0a2016-07-19 10:56:23 -07002572
Dan Sinclair1770c022016-03-14 14:14:16 -04002573void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2574 int32_t iLength = pArguments->GetLength();
2575 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002576 ThrowParamCountMismatchException(L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002577 return;
2578 }
2579 CXFA_WidgetData* pWidgetData = GetWidgetData();
2580 if (!pWidgetData) {
2581 return;
2582 }
2583 CFX_WideString wsLabel;
2584 CFX_WideString wsValue;
2585 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002586 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002587 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002588 }
2589 if (iLength >= 2) {
2590 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002591 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002592 }
tsepezd19e9122016-11-02 15:43:18 -07002593 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002594}
dsinclair5b36f0a2016-07-19 10:56:23 -07002595
Dan Sinclair1770c022016-03-14 14:14:16 -04002596void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002597 if (pArguments->GetLength() != 0) {
2598 ThrowParamCountMismatchException(L"execValidate");
2599 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002600 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002601
2602 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2603 if (!pNotify) {
2604 pArguments->GetReturnValue()->SetBoolean(false);
2605 return;
2606 }
2607
2608 int32_t iRet =
2609 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
2610 pArguments->GetReturnValue()->SetBoolean(
2611 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002612}
dsinclair5b36f0a2016-07-19 10:56:23 -07002613
dsinclair12a6b0c2016-05-26 11:14:08 -07002614void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002615 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002616 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002617 if (bSetting)
2618 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002619}
dsinclair5b36f0a2016-07-19 10:56:23 -07002620
dsinclair12a6b0c2016-05-26 11:14:08 -07002621void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002622 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002623 XFA_ATTRIBUTE eAttribute) {
2624 CXFA_WidgetData* pWidgetData = GetWidgetData();
2625 if (!pWidgetData) {
2626 return;
2627 }
2628 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002629 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002630 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002631 } else {
tsepezd19e9122016-11-02 15:43:18 -07002632 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002633 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2634 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002635 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002636 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002637 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002638 }
2639 }
2640}
dsinclair5b36f0a2016-07-19 10:56:23 -07002641
dsinclair12a6b0c2016-05-26 11:14:08 -07002642void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002643 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002644 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002645
Dan Sinclair1770c022016-03-14 14:14:16 -04002646void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002647 if (pArguments->GetLength() != 1) {
2648 ThrowParamCountMismatchException(L"execEvent");
2649 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002650 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002651
2652 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2653 execSingleEventByName(
2654 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2655 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002656}
thestig800222e2016-05-26 22:00:29 -07002657
Dan Sinclair1770c022016-03-14 14:14:16 -04002658void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2659 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002660 if (argc < 0 || argc > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002661 ThrowParamCountMismatchException(L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002662 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002663 }
thestig800222e2016-05-26 22:00:29 -07002664
2665 CXFA_WidgetData* pWidgetData = GetWidgetData();
2666 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002667 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002668 return;
2669 }
2670
2671 CXFA_Node* pReturnNode = nullptr;
2672 if (argc == 0) {
2673 pReturnNode = pWidgetData->GetSelectedMember();
2674 } else {
2675 CFX_ByteString szName;
2676 szName = pArguments->GetUTF8String(0);
2677 pReturnNode = pWidgetData->SetSelectedMember(
2678 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2679 }
2680 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002681 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002682 return;
2683 }
dsinclairf27aeec2016-06-07 19:36:18 -07002684 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002685 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002686}
thestig800222e2016-05-26 22:00:29 -07002687
Dan Sinclair1770c022016-03-14 14:14:16 -04002688void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002689 if (pArguments->GetLength() != 0) {
2690 ThrowParamCountMismatchException(L"execInitialize");
2691 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002692 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002693
2694 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2695 if (!pNotify)
2696 return;
2697
2698 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002699}
dsinclair5b36f0a2016-07-19 10:56:23 -07002700
Dan Sinclair1770c022016-03-14 14:14:16 -04002701void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002702 if (pArguments->GetLength() != 0) {
2703 ThrowParamCountMismatchException(L"execCalculate");
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_Calculate);
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_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002715 if (pArguments->GetLength() != 0) {
2716 ThrowParamCountMismatchException(L"execValidate");
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 pArguments->GetReturnValue()->SetBoolean(false);
2723 return;
2724 }
2725
2726 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2727 pArguments->GetReturnValue()->SetBoolean(
2728 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002729}
dsinclair5b36f0a2016-07-19 10:56:23 -07002730
dsinclair12a6b0c2016-05-26 11:14:08 -07002731void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002732 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002733 XFA_ATTRIBUTE eAttribute) {
2734 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002735 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002736 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002737 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002738 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2739 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002740 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002741 pManagerNode = pNode;
2742 break;
2743 }
2744 }
2745 if (pManagerNode) {
2746 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002747 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002748 if (!pNotify) {
2749 return;
2750 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002751 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002752 if (pToInstance &&
2753 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002754 pNotify->RunSubformIndexChange(pToInstance);
2755 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002756 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002757 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002758 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002759 pNotify->RunSubformIndexChange(pFromInstance);
2760 }
2761 }
2762 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002763 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002764 }
2765}
dsinclair5b36f0a2016-07-19 10:56:23 -07002766
dsinclair12a6b0c2016-05-26 11:14:08 -07002767void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002768 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002769 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002770 if (bSetting) {
2771 ThrowInvalidPropertyException();
2772 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002773 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002774
2775 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2776 CXFA_Node* pInstanceMgr = nullptr;
2777 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2778 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2779 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2780 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2781 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2782 wsInstMgrName.Mid(1) == wsName) {
2783 pInstanceMgr = pNode;
2784 }
2785 break;
2786 }
2787 }
2788 if (!pInstanceMgr) {
2789 pValue->SetNull();
2790 return;
2791 }
2792
2793 pValue->Assign(
2794 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
Dan Sinclair1770c022016-03-14 14:14:16 -04002795}
dsinclair5b36f0a2016-07-19 10:56:23 -07002796
dsinclair12a6b0c2016-05-26 11:14:08 -07002797void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002798 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002799 XFA_ATTRIBUTE eAttribute) {
2800 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002801 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002802 } else {
2803 CFX_WideString wsLocaleName;
2804 GetLocaleName(wsLocaleName);
Tom Sepezf0b65542017-02-13 10:26:01 -08002805 pValue->SetString(wsLocaleName.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002806 }
2807}
dsinclair5b36f0a2016-07-19 10:56:23 -07002808
Dan Sinclair1770c022016-03-14 14:14:16 -04002809void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002810 if (pArguments->GetLength() != 1) {
2811 ThrowParamCountMismatchException(L"execEvent");
2812 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002813 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002814
2815 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2816 execSingleEventByName(
2817 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2818 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002819}
dsinclair5b36f0a2016-07-19 10:56:23 -07002820
Dan Sinclair1770c022016-03-14 14:14:16 -04002821void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002822 if (pArguments->GetLength() != 0) {
2823 ThrowParamCountMismatchException(L"execInitialize");
2824 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002825 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002826
2827 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2828 if (!pNotify)
2829 return;
2830
2831 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002832}
dsinclair5b36f0a2016-07-19 10:56:23 -07002833
Dan Sinclair1770c022016-03-14 14:14:16 -04002834void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002835 if (pArguments->GetLength() != 0) {
2836 ThrowParamCountMismatchException(L"execCalculate");
2837 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002838 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002839
2840 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2841 if (!pNotify)
2842 return;
2843
2844 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002845}
dsinclair5b36f0a2016-07-19 10:56:23 -07002846
Dan Sinclair1770c022016-03-14 14:14:16 -04002847void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002848 if (pArguments->GetLength() != 0) {
2849 ThrowParamCountMismatchException(L"execValidate");
2850 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002851 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002852
2853 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2854 if (!pNotify) {
2855 pArguments->GetReturnValue()->SetBoolean(false);
2856 return;
2857 }
2858
2859 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2860 pArguments->GetReturnValue()->SetBoolean(
2861 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002862}
dsinclair5b36f0a2016-07-19 10:56:23 -07002863
Dan Sinclair1770c022016-03-14 14:14:16 -04002864void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002865 if (pArguments->GetLength() != 0)
2866 ThrowParamCountMismatchException(L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002867}
dsinclair5b36f0a2016-07-19 10:56:23 -07002868
Dan Sinclair1770c022016-03-14 14:14:16 -04002869int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2870 int32_t index = 0;
2871 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2872 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002873 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2874 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002875 index++;
2876 } else {
2877 break;
2878 }
2879 }
2880 return index;
2881}
dsinclair5b36f0a2016-07-19 10:56:23 -07002882
Dan Sinclair1770c022016-03-14 14:14:16 -04002883void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002884 if (pArguments->GetLength() != 1) {
2885 ThrowParamCountMismatchException(L"formNodes");
2886 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002887 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002888 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002889}
dsinclair5b36f0a2016-07-19 10:56:23 -07002890
Dan Sinclair1770c022016-03-14 14:14:16 -04002891void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002892 if (pArguments->GetLength() != 0) {
2893 ThrowParamCountMismatchException(L"remerge");
2894 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002895 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002896 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002897}
dsinclair5b36f0a2016-07-19 10:56:23 -07002898
Dan Sinclair1770c022016-03-14 14:14:16 -04002899void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002900 if (pArguments->GetLength() != 0) {
2901 ThrowParamCountMismatchException(L"execInitialize");
2902 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002903 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002904
2905 CXFA_WidgetData* pWidgetData = GetWidgetData();
2906 if (!pWidgetData) {
2907 pArguments->GetReturnValue()->SetBoolean(false);
2908 return;
2909 }
2910 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002911}
dsinclair5b36f0a2016-07-19 10:56:23 -07002912
Dan Sinclair1770c022016-03-14 14:14:16 -04002913void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2914 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002915 if (argc <= 0 || argc >= 4) {
2916 ThrowParamCountMismatchException(L"createNode");
2917 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002918 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002919
2920 CFX_WideString strName;
2921 CFX_WideString strNameSpace;
2922 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
2923 CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
2924 if (argc > 1) {
2925 CFX_ByteString bsName = pArguments->GetUTF8String(1);
2926 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
2927 if (argc == 3) {
2928 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
2929 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
2930 }
2931 }
2932
2933 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2934 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
2935 if (!pNewNode) {
2936 pArguments->GetReturnValue()->SetNull();
2937 return;
2938 }
2939
2940 if (strName.IsEmpty()) {
2941 pArguments->GetReturnValue()->Assign(
2942 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2943 return;
2944 }
2945
2946 if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2947 XFA_XDPPACKET_UNKNOWN)) {
2948 ThrowMissingPropertyException(strTagName, L"name");
2949 return;
2950 }
2951
2952 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
2953 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets)
2954 pNewNode->CreateXMLMappingNode();
2955
2956 pArguments->GetReturnValue()->Assign(
2957 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002958}
dsinclair5b36f0a2016-07-19 10:56:23 -07002959
Dan Sinclair1770c022016-03-14 14:14:16 -04002960void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002961 if (pArguments->GetLength() != 1) {
2962 ThrowParamCountMismatchException(L"recalculate");
2963 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002964 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002965 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002966}
dsinclair5b36f0a2016-07-19 10:56:23 -07002967
Dan Sinclair1770c022016-03-14 14:14:16 -04002968void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002969 if (pArguments->GetLength() != 0) {
2970 ThrowParamCountMismatchException(L"execCalculate");
2971 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002972 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002973
2974 CXFA_WidgetData* pWidgetData = GetWidgetData();
2975 if (!pWidgetData) {
2976 pArguments->GetReturnValue()->SetBoolean(false);
2977 return;
2978 }
2979 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002980}
dsinclair5b36f0a2016-07-19 10:56:23 -07002981
Dan Sinclair1770c022016-03-14 14:14:16 -04002982void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002983 if (pArguments->GetLength() != 0) {
2984 ThrowParamCountMismatchException(L"execValidate");
2985 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002986 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002987 CXFA_WidgetData* pWidgetData = GetWidgetData();
2988 if (!pWidgetData) {
2989 pArguments->GetReturnValue()->SetBoolean(false);
2990 return;
2991 }
2992 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002993}
dsinclair5b36f0a2016-07-19 10:56:23 -07002994
Dan Sinclair1770c022016-03-14 14:14:16 -04002995void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002996 if (pArguments->GetLength() != 0) {
2997 ThrowParamCountMismatchException(L"evaluate");
2998 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002999 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003000
3001 CXFA_WidgetData* pWidgetData = GetWidgetData();
3002 if (!pWidgetData) {
3003 pArguments->GetReturnValue()->SetBoolean(false);
3004 return;
3005 }
3006 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003007}
dsinclair5b36f0a2016-07-19 10:56:23 -07003008
dsinclair12a6b0c2016-05-26 11:14:08 -07003009void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003010 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003011 XFA_ATTRIBUTE eAttribute) {
3012 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003013 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003014 return;
3015 }
3016 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003017 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003018}
dsinclair5b36f0a2016-07-19 10:56:23 -07003019
dsinclair12a6b0c2016-05-26 11:14:08 -07003020void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003021 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003022 XFA_ATTRIBUTE eAttribute) {
3023 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003024 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003025 return;
3026 }
3027 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003028 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003029}
tsepezaadedf92016-05-12 10:08:06 -07003030
dsinclair12a6b0c2016-05-26 11:14:08 -07003031void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003032 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003033 XFA_ATTRIBUTE eAttribute) {
3034 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003035 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003036 InstanceManager_SetInstances(iDesired);
3037 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07003038 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04003039 }
3040}
dsinclair5b36f0a2016-07-19 10:56:23 -07003041
Dan Sinclair1770c022016-03-14 14:14:16 -04003042void CXFA_Node::Script_InstanceManager_MoveInstance(
3043 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003044 if (pArguments->GetLength() != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003045 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003046 return;
3047 }
3048 int32_t iFrom = pArguments->GetInt32(0);
3049 int32_t iTo = pArguments->GetInt32(1);
3050 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003051 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003052 if (!pNotify) {
3053 return;
3054 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003055 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003056 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003057 pNotify->RunSubformIndexChange(pToInstance);
3058 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003059 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003060 if (pFromInstance &&
3061 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003062 pNotify->RunSubformIndexChange(pFromInstance);
3063 }
3064}
dsinclair5b36f0a2016-07-19 10:56:23 -07003065
Dan Sinclair1770c022016-03-14 14:14:16 -04003066void CXFA_Node::Script_InstanceManager_RemoveInstance(
3067 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003068 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003069 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003070 return;
3071 }
3072 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003073 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003074 if (iIndex < 0 || iIndex >= iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003075 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003076 return;
3077 }
3078 CXFA_Occur nodeOccur(GetOccurNode());
3079 int32_t iMin = nodeOccur.GetMin();
3080 if (iCount - 1 < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003081 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003082 return;
3083 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003084 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3085 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003086 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003087 if (pNotify) {
3088 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003089 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003090 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003091 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003092 pNotify->RunSubformIndexChange(pSubformInstance);
3093 }
3094 }
3095 }
3096 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3097 if (!pLayoutPro) {
3098 return;
3099 }
3100 pLayoutPro->AddChangedContainer(
3101 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3102}
dsinclair5b36f0a2016-07-19 10:56:23 -07003103
Dan Sinclair1770c022016-03-14 14:14:16 -04003104void CXFA_Node::Script_InstanceManager_SetInstances(
3105 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003106 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003107 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003108 return;
3109 }
3110 int32_t iDesired = pArguments->GetInt32(0);
3111 InstanceManager_SetInstances(iDesired);
3112}
dsinclair5b36f0a2016-07-19 10:56:23 -07003113
Dan Sinclair1770c022016-03-14 14:14:16 -04003114void CXFA_Node::Script_InstanceManager_AddInstance(
3115 CFXJSE_Arguments* pArguments) {
3116 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003117 if (argc != 0 && argc != 1) {
3118 ThrowParamCountMismatchException(L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003119 return;
3120 }
tsepezd19e9122016-11-02 15:43:18 -07003121 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003122 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003123 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003124 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003125 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003126 CXFA_Occur nodeOccur(GetOccurNode());
3127 int32_t iMax = nodeOccur.GetMax();
3128 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003129 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003130 return;
3131 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003132 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003133 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003134 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003135 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003136 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003137 if (!pNotify) {
3138 return;
3139 }
3140 pNotify->RunNodeInitialize(pNewInstance);
3141 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3142 if (!pLayoutPro) {
3143 return;
3144 }
3145 pLayoutPro->AddChangedContainer(
3146 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3147}
dsinclair5b36f0a2016-07-19 10:56:23 -07003148
Dan Sinclair1770c022016-03-14 14:14:16 -04003149void CXFA_Node::Script_InstanceManager_InsertInstance(
3150 CFXJSE_Arguments* pArguments) {
3151 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003152 if (argc != 1 && argc != 2) {
3153 ThrowParamCountMismatchException(L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003154 return;
3155 }
3156 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003157 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003158 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003159 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003160 }
3161 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003162 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003163 if (iIndex < 0 || iIndex > iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003164 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003165 return;
3166 }
3167 int32_t iMax = nodeOccur.GetMax();
3168 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003169 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003170 return;
3171 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003172 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003173 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003174 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003175 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003176 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003177 if (!pNotify) {
3178 return;
3179 }
3180 pNotify->RunNodeInitialize(pNewInstance);
3181 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3182 if (!pLayoutPro) {
3183 return;
3184 }
3185 pLayoutPro->AddChangedContainer(
3186 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3187}
dsinclair5b36f0a2016-07-19 10:56:23 -07003188
Dan Sinclair1770c022016-03-14 14:14:16 -04003189int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3190 CXFA_Occur nodeOccur(GetOccurNode());
3191 int32_t iMax = nodeOccur.GetMax();
3192 int32_t iMin = nodeOccur.GetMin();
3193 if (iDesired < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003194 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003195 return 1;
3196 }
3197 if ((iMax >= 0) && (iDesired > iMax)) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003198 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003199 return 2;
3200 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003201 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003202 if (iDesired == iCount) {
3203 return 0;
3204 }
3205 if (iDesired < iCount) {
3206 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003207 CFX_WideString wsInstanceName =
3208 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3209 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003210 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003211 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003212 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003213 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003214 while (iCount > iDesired) {
3215 CXFA_Node* pRemoveInstance =
3216 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003217 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3218 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003219 continue;
3220 }
dsinclair070fcdf2016-06-22 22:04:54 -07003221 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003222 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003223 break;
3224 }
3225 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003226 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003227 iCount--;
3228 }
3229 }
3230 } else if (iDesired > iCount) {
3231 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003232 CXFA_Node* pNewInstance = CreateInstance(this, true);
3233 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003234 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003235 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003236 if (!pNotify) {
3237 return 0;
3238 }
3239 pNotify->RunNodeInitialize(pNewInstance);
3240 }
3241 }
3242 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3243 if (pLayoutPro) {
3244 pLayoutPro->AddChangedContainer(
3245 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3246 }
3247 return 0;
3248}
dsinclair5b36f0a2016-07-19 10:56:23 -07003249
Dan Sinclair1770c022016-03-14 14:14:16 -04003250int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003251 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003252 if (iFrom > iCount || iTo > iCount - 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003253 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003254 return 1;
3255 }
3256 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3257 return 0;
3258 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003259 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003260 RemoveItem(this, pMoveInstance, false);
3261 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003262 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3263 if (pLayoutPro) {
3264 pLayoutPro->AddChangedContainer(
3265 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3266 }
3267 return 0;
3268}
dsinclair5b36f0a2016-07-19 10:56:23 -07003269
dsinclair12a6b0c2016-05-26 11:14:08 -07003270void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003271 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003272 XFA_ATTRIBUTE eAttribute) {
3273 CXFA_Occur occur(this);
3274 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003275 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003276 occur.SetMax(iMax);
3277 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003278 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003279 }
3280}
dsinclair5b36f0a2016-07-19 10:56:23 -07003281
dsinclair12a6b0c2016-05-26 11:14:08 -07003282void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003283 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003284 XFA_ATTRIBUTE eAttribute) {
3285 CXFA_Occur occur(this);
3286 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003287 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003288 occur.SetMin(iMin);
3289 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003290 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003291 }
3292}
dsinclair5b36f0a2016-07-19 10:56:23 -07003293
Dan Sinclair1770c022016-03-14 14:14:16 -04003294void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3295 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003296 if (argc != 0 && argc != 1) {
3297 ThrowParamCountMismatchException(L"metadata");
3298 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003299 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003300 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003301}
dsinclair5b36f0a2016-07-19 10:56:23 -07003302
Dan Sinclair1770c022016-03-14 14:14:16 -04003303void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003304 if (pArguments->GetLength() != 1) {
3305 ThrowParamCountMismatchException(L"formNodes");
3306 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003307 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003308
3309 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3310 if (!pDataNode) {
3311 ThrowArgumentMismatchException();
3312 return;
3313 }
3314
3315 CXFA_NodeArray formItems;
3316 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3317 pFormNodes->SetArrayNodeList(formItems);
3318 pArguments->GetReturnValue()->SetObject(
3319 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003320}
dsinclair5b36f0a2016-07-19 10:56:23 -07003321
Dan Sinclair1770c022016-03-14 14:14:16 -04003322void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003323 if (pArguments->GetLength() != 0) {
3324 ThrowParamCountMismatchException(L"remerge");
3325 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003326 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003327
3328 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003329}
dsinclair5b36f0a2016-07-19 10:56:23 -07003330
Dan Sinclair1770c022016-03-14 14:14:16 -04003331void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003332 if (pArguments->GetLength() != 0) {
3333 ThrowParamCountMismatchException(L"execInitialize");
3334 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003335 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003336
3337 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3338 if (!pNotify)
3339 return;
3340
3341 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04003342}
dsinclair5b36f0a2016-07-19 10:56:23 -07003343
Dan Sinclair1770c022016-03-14 14:14:16 -04003344void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3345 CXFA_EventParam* pEventParam =
3346 m_pDocument->GetScriptContext()->GetEventParam();
3347 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3348 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3349 return;
3350 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003351 if (pArguments->GetLength() != 1) {
3352 ThrowParamCountMismatchException(L"recalculate");
3353 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003354 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003355
3356 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3357 if (!pNotify)
3358 return;
3359 if (pArguments->GetInt32(0) != 0)
3360 return;
3361
3362 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3363 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3364 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003365}
dsinclair5b36f0a2016-07-19 10:56:23 -07003366
Dan Sinclair1770c022016-03-14 14:14:16 -04003367void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003368 if (pArguments->GetLength() != 0) {
3369 ThrowParamCountMismatchException(L"execCalculate");
3370 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003371 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003372
3373 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3374 if (!pNotify)
3375 return;
3376
3377 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04003378}
dsinclair5b36f0a2016-07-19 10:56:23 -07003379
Dan Sinclair1770c022016-03-14 14:14:16 -04003380void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003381 if (pArguments->GetLength() != 0) {
3382 ThrowParamCountMismatchException(L"execValidate");
3383 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003384 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003385
3386 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3387 if (!pNotify) {
3388 pArguments->GetReturnValue()->SetBoolean(false);
3389 return;
3390 }
3391
3392 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3393 pArguments->GetReturnValue()->SetBoolean(
3394 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003395}
dsinclair5b36f0a2016-07-19 10:56:23 -07003396
dsinclair12a6b0c2016-05-26 11:14:08 -07003397void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003398 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003399 XFA_ATTRIBUTE eAttribute) {
3400 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003401 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003402 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003403 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003404 CFX_WideString wsChecksum;
3405 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
Tom Sepezf0b65542017-02-13 10:26:01 -08003406 pValue->SetString(wsChecksum.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003407}
dsinclair5b36f0a2016-07-19 10:56:23 -07003408
Dan Sinclair1770c022016-03-14 14:14:16 -04003409void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003410 if (pArguments->GetLength() != 1) {
3411 ThrowParamCountMismatchException(L"getAttribute");
3412 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003413 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003414 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3415 CFX_WideString wsAttributeValue;
3416 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3417 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3418 static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3419 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(),
3420 wsAttributeValue);
3421 }
3422 pArguments->GetReturnValue()->SetString(
Tom Sepezf0b65542017-02-13 10:26:01 -08003423 wsAttributeValue.UTF8Encode().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_SetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003427 if (pArguments->GetLength() != 2) {
3428 ThrowParamCountMismatchException(L"setAttribute");
3429 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003430 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003431 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3432 CFX_ByteString bsName = pArguments->GetUTF8String(1);
3433 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3434 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3435 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(
3436 CFX_WideString::FromUTF8(bsName.AsStringC()),
3437 CFX_WideString::FromUTF8(bsValue.AsStringC()));
3438 }
3439 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003440}
dsinclair5b36f0a2016-07-19 10:56:23 -07003441
Dan Sinclair1770c022016-03-14 14:14:16 -04003442void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003443 if (pArguments->GetLength() != 1) {
3444 ThrowParamCountMismatchException(L"removeAttribute");
3445 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003446 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003447
3448 CFX_ByteString bsName = pArguments->GetUTF8String(0);
3449 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
3450 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3451 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3452 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
3453 if (pXMLElement->HasAttribute(wsName.c_str())) {
3454 pXMLElement->RemoveAttribute(wsName.c_str());
3455 }
3456 }
3457 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003458}
dsinclair5b36f0a2016-07-19 10:56:23 -07003459
dsinclair12a6b0c2016-05-26 11:14:08 -07003460void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003461 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003462 XFA_ATTRIBUTE eAttribute) {
3463 if (bSetting) {
dsinclairae95f762016-03-29 16:58:29 -07003464 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003465 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003466 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003467 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003468 }
3469 } else {
3470 CFX_WideString wsTextData;
dsinclairae95f762016-03-29 16:58:29 -07003471 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003472 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003473 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04003474 pXMLElement->GetTextData(wsTextData);
3475 }
Tom Sepezf0b65542017-02-13 10:26:01 -08003476 pValue->SetString(wsTextData.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003477 }
3478}
dsinclair5b36f0a2016-07-19 10:56:23 -07003479
Dan Sinclair1770c022016-03-14 14:14:16 -04003480void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003481 if (pArguments->GetLength() != 0)
3482 ThrowParamCountMismatchException(L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003483}
dsinclair5b36f0a2016-07-19 10:56:23 -07003484
Dan Sinclair1770c022016-03-14 14:14:16 -04003485void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003486 if (pArguments->GetLength() != 0)
3487 ThrowParamCountMismatchException(L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003488}
dsinclair5b36f0a2016-07-19 10:56:23 -07003489
Dan Sinclair1770c022016-03-14 14:14:16 -04003490void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003491 if (pArguments->GetLength() != 0)
3492 ThrowParamCountMismatchException(L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003493}
dsinclair5b36f0a2016-07-19 10:56:23 -07003494
Dan Sinclair1770c022016-03-14 14:14:16 -04003495void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003496 if (pArguments->GetLength() != 0)
3497 ThrowParamCountMismatchException(L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003498}
dsinclair5b36f0a2016-07-19 10:56:23 -07003499
Dan Sinclair1770c022016-03-14 14:14:16 -04003500void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003501 if (pArguments->GetLength() != 0)
3502 ThrowParamCountMismatchException(L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003503}
dsinclair5b36f0a2016-07-19 10:56:23 -07003504
Dan Sinclair1770c022016-03-14 14:14:16 -04003505void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003506 if (pArguments->GetLength() != 0)
3507 ThrowParamCountMismatchException(L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003508}
dsinclair5b36f0a2016-07-19 10:56:23 -07003509
Dan Sinclair1770c022016-03-14 14:14:16 -04003510void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003511 if (pArguments->GetLength() != 0)
3512 ThrowParamCountMismatchException(L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003513}
dsinclair5b36f0a2016-07-19 10:56:23 -07003514
Dan Sinclair1770c022016-03-14 14:14:16 -04003515void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003516 if (pArguments->GetLength() != 0)
3517 ThrowParamCountMismatchException(L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003518}
dsinclair5b36f0a2016-07-19 10:56:23 -07003519
Dan Sinclair1770c022016-03-14 14:14:16 -04003520void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003521 if (pArguments->GetLength() != 0)
3522 ThrowParamCountMismatchException(L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003523}
dsinclair5b36f0a2016-07-19 10:56:23 -07003524
Dan Sinclair1770c022016-03-14 14:14:16 -04003525void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003526 if (pArguments->GetLength() != 0)
3527 ThrowParamCountMismatchException(L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003528}
dsinclair5b36f0a2016-07-19 10:56:23 -07003529
Dan Sinclair1770c022016-03-14 14:14:16 -04003530void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003531 if (pArguments->GetLength() != 0)
3532 ThrowParamCountMismatchException(L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003533}
dsinclair5b36f0a2016-07-19 10:56:23 -07003534
Dan Sinclair1770c022016-03-14 14:14:16 -04003535void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003536 if (pArguments->GetLength() != 0)
3537 ThrowParamCountMismatchException(L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003538}
dsinclair5b36f0a2016-07-19 10:56:23 -07003539
Dan Sinclair1770c022016-03-14 14:14:16 -04003540void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003541 if (pArguments->GetLength() != 0)
3542 ThrowParamCountMismatchException(L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003543}
dsinclair5b36f0a2016-07-19 10:56:23 -07003544
Dan Sinclair1770c022016-03-14 14:14:16 -04003545void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003546 if (pArguments->GetLength() != 0)
3547 ThrowParamCountMismatchException(L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003548}
dsinclair5b36f0a2016-07-19 10:56:23 -07003549
Dan Sinclair1770c022016-03-14 14:14:16 -04003550void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003551 if (pArguments->GetLength() != 0)
3552 ThrowParamCountMismatchException(L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003553}
dsinclair5b36f0a2016-07-19 10:56:23 -07003554
Dan Sinclair1770c022016-03-14 14:14:16 -04003555void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003556 if (pArguments->GetLength() != 0)
3557 ThrowParamCountMismatchException(L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003558}
dsinclair5b36f0a2016-07-19 10:56:23 -07003559
Dan Sinclair1770c022016-03-14 14:14:16 -04003560void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003561 if (pArguments->GetLength() != 0)
3562 ThrowParamCountMismatchException(L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003563}
dsinclair5b36f0a2016-07-19 10:56:23 -07003564
dsinclair12a6b0c2016-05-26 11:14:08 -07003565void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003566 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003567 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003568
dsinclair12a6b0c2016-05-26 11:14:08 -07003569void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003570 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003571 XFA_ATTRIBUTE eAttribute) {
3572 if (!bSetting) {
3573 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003574 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003575 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003576 }
3577}
dsinclair5b36f0a2016-07-19 10:56:23 -07003578
dsinclair12a6b0c2016-05-26 11:14:08 -07003579void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003580 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003581 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003582
dsinclair12a6b0c2016-05-26 11:14:08 -07003583void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003584 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003585 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003586
dsinclair12a6b0c2016-05-26 11:14:08 -07003587void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003588 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003589 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003590
dsinclair12a6b0c2016-05-26 11:14:08 -07003591void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003592 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003593 XFA_ATTRIBUTE eAttribute) {
3594 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003595 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003596 return;
3597 }
dan sinclair65c7c232017-02-02 14:05:30 -08003598 pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003599}
dsinclair5b36f0a2016-07-19 10:56:23 -07003600
dsinclair12a6b0c2016-05-26 11:14:08 -07003601void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003602 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003603 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003604
tsepezd19e9122016-11-02 15:43:18 -07003605bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003606 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003607 return HasMapModuleKey(pKey, bCanInherit);
3608}
dsinclair5b36f0a2016-07-19 10:56:23 -07003609
tsepezd19e9122016-11-02 15:43:18 -07003610bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3611 const CFX_WideStringC& wsValue,
3612 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003613 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003614 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003615 return false;
weili44f8faf2016-06-01 14:03:56 -07003616
Dan Sinclair1770c022016-03-14 14:14:16 -04003617 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3618 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3619 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003620 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003621 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3622 }
3623 switch (eType) {
3624 case XFA_ATTRIBUTETYPE_Enum: {
3625 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3626 return SetEnum(pAttr->eName,
3627 pEnum ? pEnum->eName
3628 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3629 bNotify);
3630 } break;
3631 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003632 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003633 case XFA_ATTRIBUTETYPE_Boolean:
dan sinclair65c7c232017-02-02 14:05:30 -08003634 return SetBoolean(pAttr->eName, wsValue != L"0", bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003635 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003636 return SetInteger(pAttr->eName,
3637 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3638 wsValue.GetLength(), nullptr)),
3639 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003640 case XFA_ATTRIBUTETYPE_Measure:
3641 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3642 default:
3643 break;
3644 }
tsepezd19e9122016-11-02 15:43:18 -07003645 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003646}
dsinclair5b36f0a2016-07-19 10:56:23 -07003647
tsepezd19e9122016-11-02 15:43:18 -07003648bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3649 CFX_WideString& wsValue,
3650 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003651 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003652 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003653 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003654 }
3655 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3656 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3657 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003658 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003659 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3660 }
3661 switch (eType) {
3662 case XFA_ATTRIBUTETYPE_Enum: {
3663 XFA_ATTRIBUTEENUM eValue;
3664 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003665 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003666 }
dsinclair9eb0db12016-07-21 12:01:39 -07003667 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003668 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003669 } break;
3670 case XFA_ATTRIBUTETYPE_Cdata: {
3671 CFX_WideStringC wsValueC;
3672 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003673 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003674 }
3675 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003676 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003677 } break;
3678 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003679 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003680 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003681 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003682 }
dan sinclair65c7c232017-02-02 14:05:30 -08003683 wsValue = bValue ? L"1" : L"0";
tsepezd19e9122016-11-02 15:43:18 -07003684 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003685 } break;
3686 case XFA_ATTRIBUTETYPE_Integer: {
3687 int32_t iValue;
3688 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003689 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003690 }
3691 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003692 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003693 } break;
3694 case XFA_ATTRIBUTETYPE_Measure: {
3695 CXFA_Measurement mValue;
3696 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003697 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003698 }
3699 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003700 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003701 } break;
3702 default:
3703 break;
3704 }
tsepezd19e9122016-11-02 15:43:18 -07003705 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003706}
dsinclair5b36f0a2016-07-19 10:56:23 -07003707
tsepezd19e9122016-11-02 15:43:18 -07003708bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3709 const CFX_WideStringC& wsValue,
3710 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003711 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3712 if (pAttributeInfo) {
3713 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3714 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003715 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003716 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003717 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003718}
dsinclair5b36f0a2016-07-19 10:56:23 -07003719
tsepezd19e9122016-11-02 15:43:18 -07003720bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3721 CFX_WideString& wsValue,
3722 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003723 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3724 if (pAttributeInfo) {
3725 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3726 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003727 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003728 CFX_WideStringC wsValueC;
3729 if (GetMapModuleString(pKey, wsValueC)) {
3730 wsValue = wsValueC;
3731 }
tsepezd19e9122016-11-02 15:43:18 -07003732 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003733}
dsinclair5b36f0a2016-07-19 10:56:23 -07003734
tsepezd19e9122016-11-02 15:43:18 -07003735bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003736 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003737 RemoveMapModuleKey(pKey);
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::TryBoolean(XFA_ATTRIBUTE eAttr,
3742 bool& bValue,
3743 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003744 void* pValue = nullptr;
3745 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003746 return false;
tsepez478ed622016-10-27 14:32:33 -07003747 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003748 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003749}
dsinclair5b36f0a2016-07-19 10:56:23 -07003750
tsepezd19e9122016-11-02 15:43:18 -07003751bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3752 int32_t& iValue,
3753 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003754 void* pValue = nullptr;
3755 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003756 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003757 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003758 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003759}
dsinclair5b36f0a2016-07-19 10:56:23 -07003760
tsepezd19e9122016-11-02 15:43:18 -07003761bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3762 XFA_ATTRIBUTEENUM& eValue,
3763 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003764 void* pValue = nullptr;
3765 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003766 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003767 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003768 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003769}
thestigb1a59592016-04-14 18:29:56 -07003770
tsepezd19e9122016-11-02 15:43:18 -07003771bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3772 CXFA_Measurement mValue,
3773 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003774 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003775 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003776 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003777 OnChanged(eAttr, bNotify, false);
3778 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003779}
thestigb1a59592016-04-14 18:29:56 -07003780
tsepezd19e9122016-11-02 15:43:18 -07003781bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3782 CXFA_Measurement& mValue,
3783 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003784 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003785 void* pValue;
3786 int32_t iBytes;
3787 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
3788 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003789 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003790 }
3791 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003792 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003793 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
3794 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003795 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003796 }
tsepezd19e9122016-11-02 15:43:18 -07003797 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003798}
3799
3800CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3801 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003802 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003803}
3804
tsepezd19e9122016-11-02 15:43:18 -07003805bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3806 const CFX_WideString& wsValue,
3807 bool bNotify,
3808 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003809 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003810 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003811 if (eAttr == XFA_ATTRIBUTE_Value) {
3812 CFX_WideString* pClone = new CFX_WideString(wsValue);
3813 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3814 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003815 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003816 if (eAttr == XFA_ATTRIBUTE_Name)
3817 UpdateNameHash();
3818 }
thestigb1a59592016-04-14 18:29:56 -07003819 OnChanged(eAttr, bNotify, bScriptModify);
3820
3821 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3822 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003823 return true;
thestigb1a59592016-04-14 18:29:56 -07003824 }
3825
dsinclair070fcdf2016-06-22 22:04:54 -07003826 if (eAttr == XFA_ATTRIBUTE_Name &&
3827 (m_elementType == XFA_Element::DataValue ||
3828 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003829 return true;
thestigb1a59592016-04-14 18:29:56 -07003830 }
3831
3832 if (eAttr == XFA_ATTRIBUTE_Value) {
3833 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3834 switch (eXMLType) {
3835 case FDE_XMLNODE_Element:
3836 if (IsAttributeInXML()) {
3837 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003838 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3839 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003840 } else {
tsepezd19e9122016-11-02 15:43:18 -07003841 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003842 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3843 for (CXFA_Node* pChildDataNode =
3844 GetNodeItem(XFA_NODEITEM_FirstChild);
3845 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3846 XFA_NODEITEM_NextSibling)) {
3847 CXFA_NodeArray formNodes;
3848 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003849 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003850 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003851 }
3852 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003853 }
thestigb1a59592016-04-14 18:29:56 -07003854 if (bDeleteChildren) {
3855 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3856 }
3857 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3858 }
3859 break;
3860 case FDE_XMLNODE_Text:
3861 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3862 break;
3863 default:
dsinclair43854a52016-04-27 12:26:00 -07003864 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003865 }
tsepezd19e9122016-11-02 15:43:18 -07003866 return true;
thestigb1a59592016-04-14 18:29:56 -07003867 }
3868
3869 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3870 if (pInfo) {
dsinclair43854a52016-04-27 12:26:00 -07003871 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003872 CFX_WideString wsAttrName = pInfo->pName;
3873 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
dan sinclair65c7c232017-02-02 14:05:30 -08003874 wsAttrName = L"xfa:" + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003875 }
thestigb1a59592016-04-14 18:29:56 -07003876 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003877 }
tsepezd19e9122016-11-02 15:43:18 -07003878 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003879}
thestigb1a59592016-04-14 18:29:56 -07003880
tsepezd19e9122016-11-02 15:43:18 -07003881bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3882 const CFX_WideString& wsXMLValue,
3883 bool bNotify,
3884 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003885 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003886 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003887 CFX_WideString* pClone = new CFX_WideString(wsValue);
3888 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003889 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003890 if (IsNeedSavingXMLNode()) {
3891 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3892 switch (eXMLType) {
3893 case FDE_XMLNODE_Element:
3894 if (IsAttributeInXML()) {
dsinclairae95f762016-03-29 16:58:29 -07003895 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003896 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3897 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003898 } else {
tsepezd19e9122016-11-02 15:43:18 -07003899 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003900 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3901 for (CXFA_Node* pChildDataNode =
3902 GetNodeItem(XFA_NODEITEM_FirstChild);
3903 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3904 XFA_NODEITEM_NextSibling)) {
3905 CXFA_NodeArray formNodes;
3906 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003907 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003908 break;
3909 }
3910 }
3911 }
3912 if (bDeleteChildren) {
dsinclairae95f762016-03-29 16:58:29 -07003913 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003914 }
dsinclairae95f762016-03-29 16:58:29 -07003915 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003916 }
3917 break;
3918 case FDE_XMLNODE_Text:
dsinclairae95f762016-03-29 16:58:29 -07003919 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003920 break;
3921 default:
dsinclair43854a52016-04-27 12:26:00 -07003922 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003923 }
3924 }
tsepezd19e9122016-11-02 15:43:18 -07003925 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003926}
dsinclair5b36f0a2016-07-19 10:56:23 -07003927
tsepezd19e9122016-11-02 15:43:18 -07003928bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3929 CFX_WideString& wsValue,
3930 bool bUseDefault,
3931 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003932 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003933 if (eAttr == XFA_ATTRIBUTE_Value) {
3934 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3935 if (pStr) {
3936 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07003937 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003938 }
3939 } else {
3940 CFX_WideStringC wsValueC;
3941 if (GetMapModuleString(pKey, wsValueC)) {
3942 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003943 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003944 }
3945 }
3946 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003947 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003948 }
weili44f8faf2016-06-01 14:03:56 -07003949 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003950 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003951 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
3952 wsValue = (const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003953 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003954 }
tsepezd19e9122016-11-02 15:43:18 -07003955 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003956}
dsinclair5b36f0a2016-07-19 10:56:23 -07003957
tsepezd19e9122016-11-02 15:43:18 -07003958bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3959 CFX_WideStringC& wsValue,
3960 bool bUseDefault,
3961 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003962 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003963 if (eAttr == XFA_ATTRIBUTE_Value) {
3964 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3965 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07003966 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07003967 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003968 }
3969 } else {
3970 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003971 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003972 }
3973 }
3974 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003975 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003976 }
weili44f8faf2016-06-01 14:03:56 -07003977 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003978 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003979 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
3980 wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003981 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003982 }
tsepezd19e9122016-11-02 15:43:18 -07003983 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003984}
dsinclair5b36f0a2016-07-19 10:56:23 -07003985
tsepezd19e9122016-11-02 15:43:18 -07003986bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
3987 void* pData,
3988 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003989 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003990 return SetUserData(pKey, pData, pCallbackInfo);
3991}
dsinclair5b36f0a2016-07-19 10:56:23 -07003992
tsepezd19e9122016-11-02 15:43:18 -07003993bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003994 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003995 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07003996 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04003997}
dsinclair5b36f0a2016-07-19 10:56:23 -07003998
tsepezd19e9122016-11-02 15:43:18 -07003999bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
4000 XFA_ATTRIBUTETYPE eType,
4001 void* pValue,
4002 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004003 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07004004 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004005 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07004006 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004007 if (IsNeedSavingXMLNode()) {
dsinclair43854a52016-04-27 12:26:00 -07004008 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004009 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
4010 if (pInfo) {
4011 switch (eType) {
4012 case XFA_ATTRIBUTETYPE_Enum:
dsinclairae95f762016-03-29 16:58:29 -07004013 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004014 ->SetString(
4015 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07004016 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04004017 ->pName);
4018 break;
4019 case XFA_ATTRIBUTETYPE_Boolean:
dsinclairae95f762016-03-29 16:58:29 -07004020 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07004021 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04004022 break;
4023 case XFA_ATTRIBUTETYPE_Integer:
dsinclairae95f762016-03-29 16:58:29 -07004024 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004025 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue);
4026 break;
4027 default:
dsinclair43854a52016-04-27 12:26:00 -07004028 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04004029 }
4030 }
4031 }
tsepezd19e9122016-11-02 15:43:18 -07004032 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004033}
dsinclair5b36f0a2016-07-19 10:56:23 -07004034
tsepezd19e9122016-11-02 15:43:18 -07004035bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
4036 XFA_ATTRIBUTETYPE eType,
4037 bool bUseDefault,
4038 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004039 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004040 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004041 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004042 }
4043 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004044 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004045 }
dsinclair070fcdf2016-06-22 22:04:54 -07004046 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004047 m_ePacket);
4048}
dsinclair5b36f0a2016-07-19 10:56:23 -07004049
tsepezd19e9122016-11-02 15:43:18 -07004050bool CXFA_Node::SetUserData(void* pKey,
4051 void* pData,
4052 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004053 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4054 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004055 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004056}
dsinclair5b36f0a2016-07-19 10:56:23 -07004057
tsepezd19e9122016-11-02 15:43:18 -07004058bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004059 int32_t iBytes = 0;
4060 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004061 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004062 }
4063 return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes);
4064}
dsinclair5b36f0a2016-07-19 10:56:23 -07004065
tsepezd19e9122016-11-02 15:43:18 -07004066bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4067 const CFX_WideString& wsXMLValue,
4068 bool bNotify,
4069 bool bScriptModify,
4070 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004071 CXFA_Node* pNode = nullptr;
4072 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004073 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004074 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004075 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004076 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004077 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004078 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004079 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004080 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004081 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004082 CXFA_Node* pBind = GetBindData();
4083 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004084 std::vector<CFX_WideString> wsSaveTextArray;
Dan Sinclair1770c022016-03-14 14:14:16 -04004085 int32_t iSize = 0;
4086 if (!wsContent.IsEmpty()) {
4087 int32_t iStart = 0;
4088 int32_t iLength = wsContent.GetLength();
4089 int32_t iEnd = wsContent.Find(L'\n', iStart);
4090 iEnd = (iEnd == -1) ? iLength : iEnd;
4091 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004092 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004093 iStart = iEnd + 1;
4094 if (iStart >= iLength) {
4095 break;
4096 }
4097 iEnd = wsContent.Find(L'\n', iStart);
4098 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004099 wsSaveTextArray.push_back(
4100 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004101 }
4102 }
tsepez51709be2016-12-08 10:55:57 -08004103 iSize = pdfium::CollectionSize<int32_t>(wsSaveTextArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04004104 }
4105 if (iSize == 0) {
4106 while (CXFA_Node* pChildNode =
4107 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4108 pBind->RemoveChild(pChildNode);
4109 }
4110 } else {
4111 CXFA_NodeArray valueNodes;
4112 int32_t iDatas = pBind->GetNodeList(
dsinclair56a8b192016-06-21 14:15:25 -07004113 valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004114 if (iDatas < iSize) {
4115 int32_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004116 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004117 while (iAddNodes-- > 0) {
4118 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004119 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004120 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004121 pValueNodes->CreateXMLMappingNode();
4122 pBind->InsertChild(pValueNodes);
4123 }
weili44f8faf2016-06-01 14:03:56 -07004124 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004125 } else if (iDatas > iSize) {
4126 int32_t iDelNodes = iDatas - iSize;
4127 while (iDelNodes-- > 0) {
4128 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4129 }
4130 }
4131 int32_t i = 0;
4132 for (CXFA_Node* pValueNode =
4133 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4134 pValueNode; pValueNode = pValueNode->GetNodeItem(
4135 XFA_NODEITEM_NextSibling)) {
4136 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004137 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004138 i++;
4139 }
4140 }
4141 CXFA_NodeArray nodeArray;
4142 pBind->GetBindItems(nodeArray);
4143 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004144 if (nodeArray[i] != this) {
4145 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004146 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004147 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004148 }
4149 }
4150 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004151 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004152 pNode = this;
4153 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004154 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004155 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004156 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004157 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004158 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004159 }
4160 pBindNode = GetBindData();
4161 if (pBindNode && bSyncData) {
4162 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004163 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004164 CXFA_NodeArray nodeArray;
4165 pBindNode->GetBindItems(nodeArray);
4166 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004167 if (nodeArray[i] != this) {
4168 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true,
tsepezd19e9122016-11-02 15:43:18 -07004169 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004170 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004171 }
4172 }
weili44f8faf2016-06-01 14:03:56 -07004173 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004174 break;
4175 }
dsinclairc5a8f212016-06-20 11:11:12 -07004176 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004177 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004178 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004179 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004180 if (wsContentType == L"text/html") {
4181 wsContentType = L"";
tsepez4c3debb2016-04-08 12:20:38 -07004182 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004183 }
4184 }
4185 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4186 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004187 pContentRawDataNode = CreateSamePacketNode(
dan sinclair65c7c232017-02-02 14:05:30 -08004188 (wsContentType == L"text/xml") ? XFA_Element::Sharpxml
4189 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004190 InsertChild(pContentRawDataNode);
4191 }
4192 return pContentRawDataNode->SetScriptContent(
4193 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4194 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004195 case XFA_ObjectType::NodeC:
4196 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004197 pNode = this;
4198 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004199 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004200 pNode = this;
4201 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4202 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4203 if (pParent) {
4204 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4205 }
dsinclair070fcdf2016-06-22 22:04:54 -07004206 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004207 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4208 if (pParent && pParent->IsContainerNode()) {
4209 pBindNode = pParent->GetBindData();
4210 if (pBindNode) {
4211 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004212 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004213 }
4214 }
4215 }
4216 }
4217 break;
4218 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004219 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004220 pNode = this;
4221 pBindNode = this;
4222 }
4223 break;
4224 }
4225 if (pNode) {
4226 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4227 if (pBindNode && bSyncData) {
4228 CXFA_NodeArray nodeArray;
4229 pBindNode->GetBindItems(nodeArray);
4230 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004231 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004232 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004233 }
4234 }
tsepezd19e9122016-11-02 15:43:18 -07004235 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004236 }
tsepezd19e9122016-11-02 15:43:18 -07004237 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004238}
dsinclair5b36f0a2016-07-19 10:56:23 -07004239
tsepezd19e9122016-11-02 15:43:18 -07004240bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4241 const CFX_WideString& wsXMLValue,
4242 bool bNotify,
4243 bool bScriptModify,
4244 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004245 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4246 bSyncData);
4247}
dsinclair5b36f0a2016-07-19 10:56:23 -07004248
tsepezd19e9122016-11-02 15:43:18 -07004249CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004250 CFX_WideString wsContent;
4251 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4252}
dsinclair5b36f0a2016-07-19 10:56:23 -07004253
Dan Sinclair1770c022016-03-14 14:14:16 -04004254CFX_WideString CXFA_Node::GetContent() {
4255 return GetScriptContent();
4256}
dsinclair5b36f0a2016-07-19 10:56:23 -07004257
tsepezd19e9122016-11-02 15:43:18 -07004258bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4259 bool bScriptModify,
4260 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004261 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004262 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004263 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004264 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004265 pNode = this;
4266 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004267 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004268 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004269 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004270 }
4271 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4272 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
dan sinclair65c7c232017-02-02 14:05:30 -08004273 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004274 }
4275 return pChildValue
4276 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004277 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004278 }
4279 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004280 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004281 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4282 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004283 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004284 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004285 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004286 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004287 if (wsContentType == L"text/html") {
dsinclair56a8b192016-06-21 14:15:25 -07004288 element = XFA_Element::SharpxHTML;
dan sinclair65c7c232017-02-02 14:05:30 -08004289 } else if (wsContentType == L"text/xml") {
dsinclair56a8b192016-06-21 14:15:25 -07004290 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004291 }
4292 }
4293 pContentRawDataNode = CreateSamePacketNode(element);
4294 InsertChild(pContentRawDataNode);
4295 }
4296 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4297 }
dsinclairc5a8f212016-06-20 11:11:12 -07004298 case XFA_ObjectType::NodeC:
4299 case XFA_ObjectType::NodeV:
4300 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004301 pNode = this;
4302 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004303 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004304 pNode = this;
4305 }
4306 break;
4307 }
4308 if (pNode) {
4309 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004310 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004311 if (pScriptContext) {
4312 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4313 }
4314 }
tsepezd19e9122016-11-02 15:43:18 -07004315 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004316 }
tsepezd19e9122016-11-02 15:43:18 -07004317 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004318}
dsinclair5b36f0a2016-07-19 10:56:23 -07004319
Dan Sinclair1770c022016-03-14 14:14:16 -04004320CXFA_Node* CXFA_Node::GetModelNode() {
4321 switch (GetPacketID()) {
4322 case XFA_XDPPACKET_XDP:
4323 return m_pDocument->GetRoot();
4324 case XFA_XDPPACKET_Config:
4325 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4326 case XFA_XDPPACKET_Template:
4327 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4328 case XFA_XDPPACKET_Form:
4329 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4330 case XFA_XDPPACKET_Datasets:
4331 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4332 case XFA_XDPPACKET_LocaleSet:
4333 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4334 case XFA_XDPPACKET_ConnectionSet:
4335 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4336 case XFA_XDPPACKET_SourceSet:
4337 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4338 case XFA_XDPPACKET_Xdc:
4339 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4340 default:
4341 return this;
4342 }
4343}
dsinclair5b36f0a2016-07-19 10:56:23 -07004344
tsepezd19e9122016-11-02 15:43:18 -07004345bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004346 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004347 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
dsinclairae95f762016-03-29 16:58:29 -07004348 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004349 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004350 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004351 }
dsinclairae95f762016-03-29 16:58:29 -07004352 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004353 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004354 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
dsinclairae95f762016-03-29 16:58:29 -07004355 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004356 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004357 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004358 }
4359 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004360 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004361 }
dsinclair070fcdf2016-06-22 22:04:54 -07004362 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004363 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4364 return XFA_FDEExtension_ResolveNamespaceQualifier(
dsinclairae95f762016-03-29 16:58:29 -07004365 static_cast<CFDE_XMLElement*>(pXMLNode),
4366 GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004367 }
dsinclairae95f762016-03-29 16:58:29 -07004368 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004369 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004370 } else {
4371 CXFA_Node* pModelNode = GetModelNode();
4372 return pModelNode->TryNamespace(wsNamespace);
4373 }
4374}
dsinclair5b36f0a2016-07-19 10:56:23 -07004375
Dan Sinclair1770c022016-03-14 14:14:16 -04004376CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004377 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004378 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004379 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004380 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004381 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004382 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004383 if (!pProperty || index >= pProperty->uOccur)
4384 return nullptr;
4385
Dan Sinclair1770c022016-03-14 14:14:16 -04004386 CXFA_Node* pNode = m_pChild;
4387 int32_t iCount = 0;
4388 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004389 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004390 iCount++;
4391 if (iCount > index) {
4392 return pNode;
4393 }
4394 }
4395 }
weili44f8faf2016-06-01 14:03:56 -07004396 if (!bCreateProperty)
4397 return nullptr;
4398
Dan Sinclair1770c022016-03-14 14:14:16 -04004399 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4400 pNode = m_pChild;
4401 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4402 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004403 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004404 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4405 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004406 }
4407 }
dsinclaira1b07722016-07-11 08:20:58 -07004408
Dan Sinclair1770c022016-03-14 14:14:16 -04004409 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004410 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004411 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004412 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004413 if (!pNewNode)
4414 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004415 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004416 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004417 }
4418 return pNewNode;
4419}
dsinclair5b36f0a2016-07-19 10:56:23 -07004420
tsepezd19e9122016-11-02 15:43:18 -07004421int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004422 CXFA_Node* pNode = m_pChild;
4423 int32_t iCount = 0;
4424 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004425 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004426 if (bOnlyChild) {
4427 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004428 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004429 if (pProperty) {
4430 continue;
4431 }
4432 }
4433 iCount++;
4434 }
4435 }
4436 return iCount;
4437}
dsinclair5b36f0a2016-07-19 10:56:23 -07004438
Dan Sinclair1770c022016-03-14 14:14:16 -04004439CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004440 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004441 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004442 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004443 CXFA_Node* pNode = m_pChild;
4444 int32_t iCount = 0;
4445 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004446 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004447 if (bOnlyChild) {
4448 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004449 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004450 if (pProperty) {
4451 continue;
4452 }
4453 }
4454 iCount++;
4455 if (iCount > index) {
4456 return pNode;
4457 }
4458 }
4459 }
weili44f8faf2016-06-01 14:03:56 -07004460 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004461}
dsinclair5b36f0a2016-07-19 10:56:23 -07004462
Dan Sinclair1770c022016-03-14 14:14:16 -04004463int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4464 ASSERT(!pNode->m_pNext);
4465 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004466 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004467 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004468 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004469
weili44f8faf2016-06-01 14:03:56 -07004470 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004471 if (index > 0) {
4472 return -1;
4473 }
4474 pNode->m_pNext = m_pChild;
4475 m_pChild = pNode;
4476 index = 0;
4477 } else if (index < 0) {
4478 m_pLastChild->m_pNext = pNode;
4479 } else {
4480 CXFA_Node* pPrev = m_pChild;
4481 int32_t iCount = 0;
4482 while (++iCount != index && pPrev->m_pNext) {
4483 pPrev = pPrev->m_pNext;
4484 }
4485 if (index > 0 && index != iCount) {
4486 return -1;
4487 }
4488 pNode->m_pNext = pPrev->m_pNext;
4489 pPrev->m_pNext = pNode;
4490 index = iCount;
4491 }
weili44f8faf2016-06-01 14:03:56 -07004492 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004493 m_pLastChild = pNode;
4494 }
4495 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004496 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004497 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004498 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004499 if (pNotify)
4500 pNotify->OnChildAdded(this);
4501
Dan Sinclair1770c022016-03-14 14:14:16 -04004502 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004503 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004504 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004505 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004506 }
4507 return index;
4508}
weili6e1ae862016-05-04 18:25:27 -07004509
tsepezd19e9122016-11-02 15:43:18 -07004510bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004511 if (!pNode || pNode->m_pParent ||
4512 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004513 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004514 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004515 }
tsepezd19e9122016-11-02 15:43:18 -07004516 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004517 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004518 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004519
4520 int32_t nIndex = -1;
4521 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004522 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004523 pNode->m_pNext = m_pChild;
4524 m_pChild = pNode;
4525 nIndex = 0;
4526 } else if (!pBeforeNode) {
4527 pNode->m_pNext = m_pLastChild->m_pNext;
4528 m_pLastChild->m_pNext = pNode;
4529 } else {
4530 nIndex = 1;
4531 CXFA_Node* pPrev = m_pChild;
4532 while (pPrev->m_pNext != pBeforeNode) {
4533 pPrev = pPrev->m_pNext;
4534 nIndex++;
4535 }
4536 pNode->m_pNext = pPrev->m_pNext;
4537 pPrev->m_pNext = pNode;
4538 }
weili44f8faf2016-06-01 14:03:56 -07004539 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004540 m_pLastChild = pNode;
4541 }
4542 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004543 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004544 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004545 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004546 if (pNotify)
4547 pNotify->OnChildAdded(this);
4548
Dan Sinclair1770c022016-03-14 14:14:16 -04004549 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004550 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004551 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004552 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004553 }
tsepezd19e9122016-11-02 15:43:18 -07004554 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004555}
dsinclair5b36f0a2016-07-19 10:56:23 -07004556
Dan Sinclair1770c022016-03-14 14:14:16 -04004557CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4558 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004559 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004560 }
4561 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4562 pSibling = pSibling->m_pNext) {
4563 if (pSibling->m_pNext == this) {
4564 return pSibling;
4565 }
4566 }
weili44f8faf2016-06-01 14:03:56 -07004567 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004568}
dsinclair5b36f0a2016-07-19 10:56:23 -07004569
tsepezd19e9122016-11-02 15:43:18 -07004570bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004571 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004572 ASSERT(false);
4573 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004574 }
4575 if (m_pChild == pNode) {
4576 m_pChild = pNode->m_pNext;
4577 if (m_pLastChild == pNode) {
4578 m_pLastChild = pNode->m_pNext;
4579 }
weili44f8faf2016-06-01 14:03:56 -07004580 pNode->m_pNext = nullptr;
4581 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004582 } else {
4583 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4584 pPrev->m_pNext = pNode->m_pNext;
4585 if (m_pLastChild == pNode) {
4586 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4587 }
weili44f8faf2016-06-01 14:03:56 -07004588 pNode->m_pNext = nullptr;
4589 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004590 }
weili44f8faf2016-06-01 14:03:56 -07004591 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004592 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004593 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004594 m_pDocument->AddPurgeNode(pNode);
4595 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4596 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004597 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4598 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004599 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07004600 CFDE_XMLElement* pXMLElement =
4601 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004602 CFX_WideStringC wsAttributeName =
4603 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004604 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004605 }
4606 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004607 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -07004608 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004609 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4610 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004611 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004612 }
4613 pNode->m_pXMLNode = pNewXMLElement;
4614 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4615 } else {
4616 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4617 }
dsinclairc5a8f212016-06-20 11:11:12 -07004618 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004619 }
tsepezd19e9122016-11-02 15:43:18 -07004620 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004621}
dsinclair5b36f0a2016-07-19 10:56:23 -07004622
Dan Sinclair1770c022016-03-14 14:14:16 -04004623CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004624 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004625}
dsinclair5b36f0a2016-07-19 10:56:23 -07004626
tsepez736f28a2016-03-25 14:19:51 -07004627CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004628 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4629 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4630 if (pNode->GetNameHash() == dwNameHash) {
4631 return pNode;
4632 }
4633 }
weili44f8faf2016-06-01 14:03:56 -07004634 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004635}
dsinclair5b36f0a2016-07-19 10:56:23 -07004636
dsinclair41cb62e2016-06-23 09:20:32 -07004637CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004638 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4639 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004640 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004641 return pNode;
4642 }
4643 }
weili44f8faf2016-06-01 14:03:56 -07004644 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004645}
dsinclair5b36f0a2016-07-19 10:56:23 -07004646
tsepez736f28a2016-03-25 14:19:51 -07004647CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004648 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4649 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4650 if (pNode->GetNameHash() == dwNameHash) {
4651 return pNode;
4652 }
4653 }
weili44f8faf2016-06-01 14:03:56 -07004654 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004655}
dsinclair5b36f0a2016-07-19 10:56:23 -07004656
Dan Sinclair1770c022016-03-14 14:14:16 -04004657CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4658 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004659 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004660}
dsinclair5b36f0a2016-07-19 10:56:23 -07004661
dsinclair41cb62e2016-06-23 09:20:32 -07004662CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004663 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4664 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004665 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004666 return pNode;
4667 }
4668 }
weili44f8faf2016-06-01 14:03:56 -07004669 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004670}
dsinclair5b36f0a2016-07-19 10:56:23 -07004671
Dan Sinclair1770c022016-03-14 14:14:16 -04004672int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004673 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004674 if (!pScriptContext) {
4675 return -1;
4676 }
4677 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4678}
dsinclair5b36f0a2016-07-19 10:56:23 -07004679
Dan Sinclair1770c022016-03-14 14:14:16 -04004680int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004681 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004682 if (!pScriptContext) {
4683 return -1;
4684 }
4685 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4686}
dsinclair5b36f0a2016-07-19 10:56:23 -07004687
Dan Sinclair1770c022016-03-14 14:14:16 -04004688void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004689 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004690 if (!pScriptContext) {
4691 return;
4692 }
4693 pScriptContext->GetSomExpression(this, wsSOMExpression);
4694}
dsinclair5b36f0a2016-07-19 10:56:23 -07004695
Dan Sinclair1770c022016-03-14 14:14:16 -04004696CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004697 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004698 if (m_ePacket == XFA_XDPPACKET_Form) {
4699 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004700 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004701 return pInstanceMgr;
4702 }
4703 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4704 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004705 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004706 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004707 pNode->m_dwNameHash != m_dwNameHash) {
4708 break;
4709 }
dsinclair56a8b192016-06-21 14:15:25 -07004710 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004711 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4712 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4713 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4714 wsInstName.Mid(1) == wsName) {
4715 pInstanceMgr = pNode;
4716 }
4717 break;
4718 }
4719 }
4720 }
4721 return pInstanceMgr;
4722}
dsinclair5b36f0a2016-07-19 10:56:23 -07004723
Dan Sinclair1770c022016-03-14 14:14:16 -04004724CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004725 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004726}
dsinclair5b36f0a2016-07-19 10:56:23 -07004727
dsinclairc5a8f212016-06-20 11:11:12 -07004728bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4729 if (m_uNodeFlags & dwFlag)
4730 return true;
4731 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4732 return m_pParent && m_pParent->HasFlag(dwFlag);
4733 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004734}
thestigb1a59592016-04-14 18:29:56 -07004735
4736void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004737 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004738 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004739 if (pNotify) {
4740 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004741 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004742 }
dsinclairc5a8f212016-06-20 11:11:12 -07004743 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004744}
thestigb1a59592016-04-14 18:29:56 -07004745
4746void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004747 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004748}
4749
tsepezd19e9122016-11-02 15:43:18 -07004750bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004751 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4752}
thestigb1a59592016-04-14 18:29:56 -07004753
4754void CXFA_Node::OnRemoved(bool bNotify) {
4755 if (!bNotify)
4756 return;
4757
dsinclaira1b07722016-07-11 08:20:58 -07004758 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004759 if (pNotify)
4760 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004761}
thestigb1a59592016-04-14 18:29:56 -07004762
4763void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004764 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004765 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004766 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004767 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004768 }
4769 }
4770}
thestigb1a59592016-04-14 18:29:56 -07004771
Dan Sinclair1770c022016-03-14 14:14:16 -04004772void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004773 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004774 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004775 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004776 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004777 }
4778}
thestigb1a59592016-04-14 18:29:56 -07004779
Dan Sinclair1770c022016-03-14 14:14:16 -04004780int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004781 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004782 int32_t iRet = XFA_EVENTERROR_NotExist;
4783 const XFA_ExecEventParaInfo* eventParaInfo =
4784 GetEventParaInfoByName(wsEventName);
4785 if (eventParaInfo) {
4786 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004787 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004788 if (!pNotify) {
4789 return iRet;
4790 }
4791 if (validFlags == 1) {
4792 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4793 } else if (validFlags == 2) {
4794 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004795 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004796 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004797 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004798 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004799 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004800 }
4801 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004802 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004803 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004804 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004805 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004806 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004807 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004808 }
4809 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004810 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004811 }
4812 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004813 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004814 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004815 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004816 }
4817 } else if (validFlags == 6) {
4818 CXFA_WidgetData* pWidgetData = GetWidgetData();
4819 if (pWidgetData) {
4820 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004821 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004822 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004823 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004824 }
4825 }
4826 } else if (validFlags == 7) {
4827 CXFA_WidgetData* pWidgetData = GetWidgetData();
4828 if (pWidgetData) {
4829 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004830 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004831 (!pWidgetData->IsListBox())) {
4832 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004833 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004834 }
4835 }
4836 }
4837 }
4838 return iRet;
4839}
dsinclair5b36f0a2016-07-19 10:56:23 -07004840
Dan Sinclair1770c022016-03-14 14:14:16 -04004841void CXFA_Node::UpdateNameHash() {
4842 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004843 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004844 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004845 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004846 wsName = GetCData(XFA_ATTRIBUTE_Name);
4847 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004848 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004849 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004850 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004851 }
4852}
dsinclair5b36f0a2016-07-19 10:56:23 -07004853
dsinclairae95f762016-03-29 16:58:29 -07004854CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004855 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004856 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
dsinclairae95f762016-03-29 16:58:29 -07004857 m_pXMLNode = new CFDE_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004858 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004859 }
4860 return m_pXMLNode;
4861}
dsinclair5b36f0a2016-07-19 10:56:23 -07004862
tsepezd19e9122016-11-02 15:43:18 -07004863bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004864 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004865 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004866}
4867
4868XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4869 if (!m_pMapModuleData)
4870 m_pMapModuleData = new XFA_MAPMODULEDATA;
4871 return m_pMapModuleData;
4872}
4873
4874XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4875 return m_pMapModuleData;
4876}
4877
4878void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4879 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004880 pModule->m_ValueMap[pKey] = pValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04004881}
4882
tsepezd19e9122016-11-02 15:43:18 -07004883bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
tsepez6bb3b892017-01-05 12:18:41 -08004884 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004885 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004886 if (pModule) {
4887 auto it = pModule->m_ValueMap.find(pKey);
4888 if (it != pModule->m_ValueMap.end()) {
4889 pValue = it->second;
4890 return true;
4891 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004892 }
tsepez6bb3b892017-01-05 12:18:41 -08004893 if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4894 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004895 }
tsepezd19e9122016-11-02 15:43:18 -07004896 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004897}
dsinclair5b36f0a2016-07-19 10:56:23 -07004898
Dan Sinclair1770c022016-03-14 14:14:16 -04004899void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004900 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair1770c022016-03-14 14:14:16 -04004901 wsValue.GetLength() * sizeof(FX_WCHAR));
4902}
dsinclair5b36f0a2016-07-19 10:56:23 -07004903
tsepezd19e9122016-11-02 15:43:18 -07004904bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004905 void* pValue;
4906 int32_t iBytes;
4907 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004908 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004909 }
4910 wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR));
tsepezd19e9122016-11-02 15:43:18 -07004911 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004912}
dsinclair5b36f0a2016-07-19 10:56:23 -07004913
Dan Sinclair1770c022016-03-14 14:14:16 -04004914void CXFA_Node::SetMapModuleBuffer(
4915 void* pKey,
4916 void* pValue,
4917 int32_t iBytes,
4918 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4919 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4920 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004921 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004922 pBuffer =
4923 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4924 } else if (pBuffer->iBytes != iBytes) {
4925 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4926 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4927 }
4928 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4929 sizeof(XFA_MAPDATABLOCK) + iBytes);
4930 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4931 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4932 }
weili44f8faf2016-06-01 14:03:56 -07004933 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04004934 return;
weili44f8faf2016-06-01 14:03:56 -07004935
Dan Sinclair1770c022016-03-14 14:14:16 -04004936 pBuffer->pCallbackInfo = pCallbackInfo;
4937 pBuffer->iBytes = iBytes;
4938 FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes);
4939}
dsinclair5b36f0a2016-07-19 10:56:23 -07004940
tsepezd19e9122016-11-02 15:43:18 -07004941bool CXFA_Node::GetMapModuleBuffer(void* pKey,
4942 void*& pValue,
4943 int32_t& iBytes,
4944 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07004945 XFA_MAPDATABLOCK* pBuffer = nullptr;
tsepez6bb3b892017-01-05 12:18:41 -08004946 for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004947 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004948 if (pModule) {
4949 auto it = pModule->m_BufferMap.find(pKey);
4950 if (it != pModule->m_BufferMap.end()) {
4951 pBuffer = it->second;
4952 break;
4953 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004954 }
tsepez6bb3b892017-01-05 12:18:41 -08004955 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4956 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004957 }
tsepez6bb3b892017-01-05 12:18:41 -08004958 if (!pBuffer)
tsepezd19e9122016-11-02 15:43:18 -07004959 return false;
tsepez6bb3b892017-01-05 12:18:41 -08004960
Dan Sinclair1770c022016-03-14 14:14:16 -04004961 pValue = pBuffer->GetData();
4962 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07004963 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004964}
dsinclair5b36f0a2016-07-19 10:56:23 -07004965
tsepezd19e9122016-11-02 15:43:18 -07004966bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
tsepez6bb3b892017-01-05 12:18:41 -08004967 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004968 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004969 if (pModule) {
4970 auto it1 = pModule->m_ValueMap.find(pKey);
4971 if (it1 != pModule->m_ValueMap.end())
4972 return true;
4973
4974 auto it2 = pModule->m_BufferMap.find(pKey);
4975 if (it2 != pModule->m_BufferMap.end())
4976 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004977 }
tsepez6bb3b892017-01-05 12:18:41 -08004978 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4979 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004980 }
tsepezd19e9122016-11-02 15:43:18 -07004981 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004982}
dsinclair5b36f0a2016-07-19 10:56:23 -07004983
Dan Sinclair1770c022016-03-14 14:14:16 -04004984void CXFA_Node::RemoveMapModuleKey(void* pKey) {
4985 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
4986 if (!pModule)
4987 return;
4988
4989 if (pKey) {
tsepez6bb3b892017-01-05 12:18:41 -08004990 auto it = pModule->m_BufferMap.find(pKey);
4991 if (it != pModule->m_BufferMap.end()) {
4992 XFA_MAPDATABLOCK* pBuffer = it->second;
Dan Sinclair1770c022016-03-14 14:14:16 -04004993 if (pBuffer) {
tsepez6bb3b892017-01-05 12:18:41 -08004994 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
Dan Sinclair1770c022016-03-14 14:14:16 -04004995 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004996 FX_Free(pBuffer);
4997 }
tsepez6bb3b892017-01-05 12:18:41 -08004998 pModule->m_BufferMap.erase(it);
Dan Sinclair1770c022016-03-14 14:14:16 -04004999 }
tsepez6bb3b892017-01-05 12:18:41 -08005000 pModule->m_ValueMap.erase(pKey);
5001 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04005002 }
tsepez6bb3b892017-01-05 12:18:41 -08005003
5004 for (auto& pair : pModule->m_BufferMap) {
5005 XFA_MAPDATABLOCK* pBuffer = pair.second;
5006 if (pBuffer) {
5007 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
5008 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5009 FX_Free(pBuffer);
5010 }
5011 }
5012 pModule->m_BufferMap.clear();
5013 pModule->m_ValueMap.clear();
5014 delete pModule;
Dan Sinclair1770c022016-03-14 14:14:16 -04005015}
dsinclair5b36f0a2016-07-19 10:56:23 -07005016
tsepez6bb3b892017-01-05 12:18:41 -08005017void CXFA_Node::MergeAllData(void* pDstModule) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005018 XFA_MAPMODULEDATA* pDstModuleData =
5019 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
5020 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08005021 if (!pSrcModuleData)
Dan Sinclair1770c022016-03-14 14:14:16 -04005022 return;
tsepez6bb3b892017-01-05 12:18:41 -08005023
5024 for (const auto& pair : pSrcModuleData->m_ValueMap)
5025 pDstModuleData->m_ValueMap[pair.first] = pair.second;
5026
5027 for (const auto& pair : pSrcModuleData->m_BufferMap) {
5028 XFA_MAPDATABLOCK* pSrcBuffer = pair.second;
5029 XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first];
Dan Sinclair1770c022016-03-14 14:14:16 -04005030 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
5031 !pSrcBuffer->pCallbackInfo->pCopy) {
tsepez6bb3b892017-01-05 12:18:41 -08005032 if (pDstBuffer) {
5033 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
5034 pDstModuleData->m_BufferMap.erase(pair.first);
Dan Sinclair1770c022016-03-14 14:14:16 -04005035 }
5036 continue;
5037 }
tsepez6bb3b892017-01-05 12:18:41 -08005038 if (!pDstBuffer) {
5039 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
Dan Sinclair1770c022016-03-14 14:14:16 -04005040 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08005041 } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) {
5042 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5043 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005044 }
tsepez6bb3b892017-01-05 12:18:41 -08005045 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
5046 uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5047 } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5048 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005049 }
tsepez6bb3b892017-01-05 12:18:41 -08005050 if (!pDstBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005051 continue;
5052 }
tsepez6bb3b892017-01-05 12:18:41 -08005053 pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5054 pDstBuffer->iBytes = pSrcBuffer->iBytes;
5055 FXSYS_memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(),
5056 pSrcBuffer->iBytes);
5057 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) {
5058 pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005059 }
5060 }
5061}
dsinclair5b36f0a2016-07-19 10:56:23 -07005062
Dan Sinclair1770c022016-03-14 14:14:16 -04005063void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5064 if (!pDstModule) {
5065 return;
5066 }
tsepezd19e9122016-11-02 15:43:18 -07005067 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005068 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005069 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005070 }
dsinclair070fcdf2016-06-22 22:04:54 -07005071 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005072 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005073 }
weili44f8faf2016-06-01 14:03:56 -07005074 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5075 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005076 if (bNeedMove) {
5077 pSrcModuleData = GetMapModuleData();
5078 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005079 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005080 }
5081 pDstModuleData = pDstModule->CreateMapModuleData();
5082 }
5083 if (bNeedMove) {
tsepez6bb3b892017-01-05 12:18:41 -08005084 auto it = pSrcModuleData->m_BufferMap.find(pKey);
5085 if (it != pSrcModuleData->m_BufferMap.end()) {
5086 XFA_MAPDATABLOCK* pBufferBlockData = it->second;
5087 if (pBufferBlockData) {
5088 pSrcModuleData->m_BufferMap.erase(pKey);
5089 pDstModuleData->m_BufferMap[pKey] = pBufferBlockData;
5090 }
Dan Sinclair1770c022016-03-14 14:14:16 -04005091 }
5092 }
dsinclairc5a8f212016-06-20 11:11:12 -07005093 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005094 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005095 CFX_WideString wsFormatValue(wsValue);
5096 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5097 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005098 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005099 }
tsepezd19e9122016-11-02 15:43:18 -07005100 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005101 }
5102}
dsinclair5b36f0a2016-07-19 10:56:23 -07005103
Dan Sinclair1770c022016-03-14 14:14:16 -04005104void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5105 CXFA_Node* pDstModule,
5106 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005107 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005108 if (!pSrcModule || !pDstModule || !pKey) {
5109 return;
5110 }
5111 if (bRecursive) {
5112 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5113 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5114 for (; pSrcChild && pDstChild;
5115 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5116 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005117 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005118 }
5119 }
5120 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5121}
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05005122
5123void CXFA_Node::ThrowMissingPropertyException(
5124 const CFX_WideString& obj,
5125 const CFX_WideString& prop) const {
5126 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(),
5127 prop.c_str());
5128}
5129
5130void CXFA_Node::ThrowTooManyOccurancesException(
5131 const CFX_WideString& obj) const {
5132 ThrowException(
5133 L"The element [%s] has violated its allowable number of occurrences.",
5134 obj.c_str());
5135}