blob: 0fc114be1040834018cd5bf10924ece6d5b95adc [file] [log] [blame]
dsinclair5b36f0a2016-07-19 10:56:23 -07001// Copyright 2016 PDFium Authors. All rights reserved.
Dan Sinclair1770c022016-03-14 14:14:16 -04002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "xfa/fxfa/parser/xfa_object.h"
8
dsinclair5b36f0a2016-07-19 10:56:23 -07009#include <map>
tsepezaadedf92016-05-12 10:08:06 -070010#include <memory>
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050011#include <utility>
tsepez51709be2016-12-08 10:55:57 -080012#include <vector>
tsepezaadedf92016-05-12 10:08:06 -070013
dsinclaira52ab742016-09-29 13:59:29 -070014#include "core/fxcrt/fx_ext.h"
dsinclair43554682016-09-29 17:29:48 -070015#include "fxjs/cfxjse_value.h"
tsepeza9caab92016-12-14 05:57:10 -080016#include "third_party/base/ptr_util.h"
tsepezaadedf92016-05-12 10:08:06 -070017#include "third_party/base/stl_util.h"
dsinclairae95f762016-03-29 16:58:29 -070018#include "xfa/fde/xml/fde_xml_imp.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040019#include "xfa/fgas/crt/fgas_codepage.h"
dsinclairdf4bc592016-03-31 20:34:43 -070020#include "xfa/fxfa/app/xfa_ffnotify.h"
dsinclair5b493092016-09-29 20:20:24 -070021#include "xfa/fxfa/cxfa_eventparam.h"
dsinclair16280242016-07-21 12:03:47 -070022#include "xfa/fxfa/parser/cxfa_document.h"
dsinclair0b851ff2016-07-21 12:03:01 -070023#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
dsinclair9eb0db12016-07-21 12:01:39 -070024#include "xfa/fxfa/parser/cxfa_measurement.h"
dsinclair44d054c2016-04-06 10:23:46 -070025#include "xfa/fxfa/parser/cxfa_occur.h"
dsinclair31f87402016-07-20 06:34:45 -070026#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
dsinclair34f86b02016-07-11 08:42:33 -070027#include "xfa/fxfa/parser/cxfa_simple_parser.h"
dsinclair5b36f0a2016-07-19 10:56:23 -070028#include "xfa/fxfa/parser/xfa_basic_data.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040029
weili44f8faf2016-06-01 14:03:56 -070030namespace {
31
32void XFA_DeleteWideString(void* pData) {
33 delete static_cast<CFX_WideString*>(pData);
34}
35
36void XFA_CopyWideString(void*& pData) {
37 if (pData) {
38 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
39 pData = pNewData;
40 }
41}
42
43XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
44 XFA_CopyWideString};
45
weili44f8faf2016-06-01 14:03:56 -070046void XFA_DataNodeDeleteBindItem(void* pData) {
47 delete static_cast<CXFA_NodeArray*>(pData);
48}
49
50XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
51 XFA_DataNodeDeleteBindItem, nullptr};
52
dsinclair5b36f0a2016-07-19 10:56:23 -070053int32_t GetCount(CXFA_Node* pInstMgrNode) {
54 ASSERT(pInstMgrNode);
55 int32_t iCount = 0;
56 uint32_t dwNameHash = 0;
57 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
58 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
59 XFA_Element eCurType = pNode->GetElementType();
60 if (eCurType == XFA_Element::InstanceManager)
61 break;
62 if ((eCurType != XFA_Element::Subform) &&
63 (eCurType != XFA_Element::SubformSet)) {
64 continue;
65 }
66 if (iCount == 0) {
67 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
68 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
69 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
70 wsInstName.Mid(1) != wsName) {
71 return iCount;
72 }
73 dwNameHash = pNode->GetNameHash();
74 }
75 if (dwNameHash != pNode->GetNameHash())
76 break;
weili44f8faf2016-06-01 14:03:56 -070077
dsinclair5b36f0a2016-07-19 10:56:23 -070078 iCount++;
79 }
80 return iCount;
Dan Sinclair1770c022016-03-14 14:14:16 -040081}
weili44f8faf2016-06-01 14:03:56 -070082
dsinclair5b36f0a2016-07-19 10:56:23 -070083void SortNodeArrayByDocumentIdx(const CXFA_NodeSet& rgNodeSet,
84 CXFA_NodeArray& rgNodeArray,
85 CFX_ArrayTemplate<int32_t>& rgIdxArray) {
86 int32_t iCount = pdfium::CollectionSize<int32_t>(rgNodeSet);
87 rgNodeArray.SetSize(iCount);
88 rgIdxArray.SetSize(iCount);
89 if (iCount == 0)
90 return;
weili44f8faf2016-06-01 14:03:56 -070091
dsinclair5b36f0a2016-07-19 10:56:23 -070092 int32_t iIndex = -1;
93 int32_t iTotalIndex = -1;
94 CXFA_Node* pCommonParent =
95 (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent);
96 for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild);
97 pNode && iIndex < iCount;
98 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
99 iTotalIndex++;
100 if (pdfium::ContainsValue(rgNodeSet, pNode)) {
101 iIndex++;
102 rgNodeArray[iIndex] = pNode;
103 rgIdxArray[iIndex] = iTotalIndex;
104 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400105 }
106}
weili44f8faf2016-06-01 14:03:56 -0700107
dsinclair5b36f0a2016-07-19 10:56:23 -0700108using CXFA_NodeSetPair = std::pair<CXFA_NodeSet, CXFA_NodeSet>;
109using CXFA_NodeSetPairMap =
110 std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>;
111using CXFA_NodeSetPairMapMap =
112 std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>;
113
114CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode,
115 CXFA_NodeSetPairMapMap* pMap) {
116 CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
117 uint32_t dwNameHash = pNode->GetNameHash();
118 if (!pParentNode || !dwNameHash)
119 return nullptr;
120
121 if (!(*pMap)[pParentNode])
tsepeza9caab92016-12-14 05:57:10 -0800122 (*pMap)[pParentNode] = pdfium::MakeUnique<CXFA_NodeSetPairMap>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700123
124 CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get();
125 if (!(*pNodeSetPairMap)[dwNameHash])
tsepeza9caab92016-12-14 05:57:10 -0800126 (*pNodeSetPairMap)[dwNameHash] = pdfium::MakeUnique<CXFA_NodeSetPair>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700127
128 return (*pNodeSetPairMap)[dwNameHash].get();
Dan Sinclair1770c022016-03-14 14:14:16 -0400129}
130
dsinclair5b36f0a2016-07-19 10:56:23 -0700131void ReorderDataNodes(const CXFA_NodeSet& sSet1,
132 const CXFA_NodeSet& sSet2,
tsepezd19e9122016-11-02 15:43:18 -0700133 bool bInsertBefore) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700134 CXFA_NodeSetPairMapMap rgMap;
135 for (CXFA_Node* pNode : sSet1) {
136 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
137 if (pNodeSetPair)
138 pNodeSetPair->first.insert(pNode);
139 }
140 for (CXFA_Node* pNode : sSet2) {
141 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
142 if (pNodeSetPair) {
143 if (pdfium::ContainsValue(pNodeSetPair->first, pNode))
144 pNodeSetPair->first.erase(pNode);
145 else
146 pNodeSetPair->second.insert(pNode);
147 }
148 }
149 for (const auto& iter1 : rgMap) {
150 CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get();
151 if (!pNodeSetPairMap)
152 continue;
153
154 for (const auto& iter2 : *pNodeSetPairMap) {
155 CXFA_NodeSetPair* pNodeSetPair = iter2.second.get();
156 if (!pNodeSetPair)
157 continue;
158 if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) {
159 CXFA_NodeArray rgNodeArray1;
160 CXFA_NodeArray rgNodeArray2;
161 CFX_ArrayTemplate<int32_t> rgIdxArray1;
162 CFX_ArrayTemplate<int32_t> rgIdxArray2;
163 SortNodeArrayByDocumentIdx(pNodeSetPair->first, rgNodeArray1,
164 rgIdxArray1);
165 SortNodeArrayByDocumentIdx(pNodeSetPair->second, rgNodeArray2,
166 rgIdxArray2);
167 CXFA_Node* pParentNode = nullptr;
168 CXFA_Node* pBeforeNode = nullptr;
169 if (bInsertBefore) {
170 pBeforeNode = rgNodeArray2[0];
171 pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent);
172 } else {
173 CXFA_Node* pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1];
174 pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent);
175 pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling);
176 }
177 for (int32_t iIdx = 0; iIdx < rgIdxArray1.GetSize(); iIdx++) {
178 CXFA_Node* pCurNode = rgNodeArray1[iIdx];
179 pParentNode->RemoveChild(pCurNode);
180 pParentNode->InsertChild(pCurNode, pBeforeNode);
181 }
182 }
183 }
184 pNodeSetPairMap->clear();
185 }
186}
187
188CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
189 ASSERT(pInstMgrNode);
190 int32_t iCount = 0;
191 uint32_t dwNameHash = 0;
192 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
193 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
194 XFA_Element eCurType = pNode->GetElementType();
195 if (eCurType == XFA_Element::InstanceManager)
196 break;
197 if ((eCurType != XFA_Element::Subform) &&
198 (eCurType != XFA_Element::SubformSet)) {
199 continue;
200 }
201 if (iCount == 0) {
202 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
203 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
204 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
205 wsInstName.Mid(1) != wsName) {
206 return nullptr;
207 }
208 dwNameHash = pNode->GetNameHash();
209 }
210 if (dwNameHash != pNode->GetNameHash())
211 break;
212
213 iCount++;
214 if (iCount > iIndex)
215 return pNode;
216 }
217 return nullptr;
218}
219
220void InsertItem(CXFA_Node* pInstMgrNode,
221 CXFA_Node* pNewInstance,
222 int32_t iPos,
223 int32_t iCount = -1,
tsepezd19e9122016-11-02 15:43:18 -0700224 bool bMoveDataBindingNodes = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700225 if (iCount < 0)
226 iCount = GetCount(pInstMgrNode);
227 if (iPos < 0)
228 iPos = iCount;
229 if (iPos == iCount) {
230 CXFA_Node* pNextSibling =
231 iCount > 0
232 ? GetItem(pInstMgrNode, iCount - 1)
233 ->GetNodeItem(XFA_NODEITEM_NextSibling)
234 : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
235 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
236 ->InsertChild(pNewInstance, pNextSibling);
237 if (bMoveDataBindingNodes) {
238 CXFA_NodeSet sNew;
239 CXFA_NodeSet sAfter;
240 CXFA_NodeIteratorTemplate<CXFA_Node,
241 CXFA_TraverseStrategy_XFAContainerNode>
242 sIteratorNew(pNewInstance);
243 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
244 pNode = sIteratorNew.MoveToNext()) {
245 CXFA_Node* pDataNode = pNode->GetBindData();
246 if (!pDataNode)
247 continue;
248
249 sNew.insert(pDataNode);
250 }
251 CXFA_NodeIteratorTemplate<CXFA_Node,
252 CXFA_TraverseStrategy_XFAContainerNode>
253 sIteratorAfter(pNextSibling);
254 for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode;
255 pNode = sIteratorAfter.MoveToNext()) {
256 CXFA_Node* pDataNode = pNode->GetBindData();
257 if (!pDataNode)
258 continue;
259
260 sAfter.insert(pDataNode);
261 }
tsepezd19e9122016-11-02 15:43:18 -0700262 ReorderDataNodes(sNew, sAfter, false);
dsinclair5b36f0a2016-07-19 10:56:23 -0700263 }
264 } else {
265 CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos);
266 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
267 ->InsertChild(pNewInstance, pBeforeInstance);
268 if (bMoveDataBindingNodes) {
269 CXFA_NodeSet sNew;
270 CXFA_NodeSet sBefore;
271 CXFA_NodeIteratorTemplate<CXFA_Node,
272 CXFA_TraverseStrategy_XFAContainerNode>
273 sIteratorNew(pNewInstance);
274 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
275 pNode = sIteratorNew.MoveToNext()) {
276 CXFA_Node* pDataNode = pNode->GetBindData();
277 if (!pDataNode)
278 continue;
279
280 sNew.insert(pDataNode);
281 }
282 CXFA_NodeIteratorTemplate<CXFA_Node,
283 CXFA_TraverseStrategy_XFAContainerNode>
284 sIteratorBefore(pBeforeInstance);
285 for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode;
286 pNode = sIteratorBefore.MoveToNext()) {
287 CXFA_Node* pDataNode = pNode->GetBindData();
288 if (!pDataNode)
289 continue;
290
291 sBefore.insert(pDataNode);
292 }
tsepezd19e9122016-11-02 15:43:18 -0700293 ReorderDataNodes(sNew, sBefore, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700294 }
295 }
296}
297
298void RemoveItem(CXFA_Node* pInstMgrNode,
299 CXFA_Node* pRemoveInstance,
tsepezd19e9122016-11-02 15:43:18 -0700300 bool bRemoveDataBinding = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700301 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);
302 if (!bRemoveDataBinding)
303 return;
304
305 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode>
306 sIterator(pRemoveInstance);
307 for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode;
308 pFormNode = sIterator.MoveToNext()) {
309 CXFA_Node* pDataNode = pFormNode->GetBindData();
310 if (!pDataNode)
311 continue;
312
313 if (pDataNode->RemoveBindItem(pFormNode) == 0) {
314 if (CXFA_Node* pDataParent =
315 pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) {
316 pDataParent->RemoveChild(pDataNode);
317 }
318 }
319 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
320 }
321}
322
tsepezd19e9122016-11-02 15:43:18 -0700323CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700324 CXFA_Document* pDocument = pInstMgrNode->GetDocument();
325 CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();
326 CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);
327 CXFA_Node* pDataScope = nullptr;
328 for (CXFA_Node* pRootBoundNode = pFormParent;
329 pRootBoundNode && pRootBoundNode->IsContainerNode();
330 pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) {
331 pDataScope = pRootBoundNode->GetBindData();
332 if (pDataScope)
333 break;
334 }
335 if (!pDataScope) {
336 pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record));
337 ASSERT(pDataScope);
338 }
339 CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer(
tsepezd19e9122016-11-02 15:43:18 -0700340 pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700341 if (pInstance) {
342 pDocument->DataMerge_UpdateBindingRelations(pInstance);
343 pFormParent->RemoveChild(pInstance);
344 }
345 return pInstance;
346}
347
348struct XFA_ExecEventParaInfo {
349 public:
350 uint32_t m_uHash;
351 const FX_WCHAR* m_lpcEventName;
352 XFA_EVENTTYPE m_eventType;
353 uint32_t m_validFlags;
354};
355static const XFA_ExecEventParaInfo gs_eventParaInfos[] = {
356 {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0},
357 {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0},
358 {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5},
359 {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0},
360 {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7},
361 {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1},
362 {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5},
363 {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0},
364 {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0},
365 {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6},
366 {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2},
367 {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0},
368 {0x7233018a, L"validate", XFA_EVENT_Validate, 1},
369 {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3},
370 {0x891f4606, L"change", XFA_EVENT_Change, 4},
371 {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0},
372 {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5},
373 {0xcdce56b3, L"full", XFA_EVENT_Full, 4},
374 {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5},
375 {0xd95657a6, L"click", XFA_EVENT_Click, 4},
376 {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1},
377 {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7},
378 {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2},
379 {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0},
380 {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6},
381};
382
383const XFA_ExecEventParaInfo* GetEventParaInfoByName(
384 const CFX_WideStringC& wsEventName) {
385 uint32_t uHash = FX_HashCode_GetW(wsEventName, false);
386 int32_t iStart = 0;
387 int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
388 do {
389 int32_t iMid = (iStart + iEnd) / 2;
390 const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid];
391 if (uHash == eventParaInfo->m_uHash)
392 return eventParaInfo;
393 if (uHash < eventParaInfo->m_uHash)
394 iEnd = iMid - 1;
395 else
396 iStart = iMid + 1;
397 } while (iStart <= iEnd);
398 return nullptr;
399}
400
401void StrToRGB(const CFX_WideString& strRGB,
402 int32_t& r,
403 int32_t& g,
404 int32_t& b) {
405 r = 0;
406 g = 0;
407 b = 0;
408
409 FX_WCHAR zero = '0';
410 int32_t iIndex = 0;
411 int32_t iLen = strRGB.GetLength();
412 for (int32_t i = 0; i < iLen; ++i) {
413 FX_WCHAR ch = strRGB.GetAt(i);
414 if (ch == L',')
415 ++iIndex;
416 if (iIndex > 2)
417 break;
418
419 int32_t iValue = ch - zero;
420 if (iValue >= 0 && iValue <= 9) {
421 switch (iIndex) {
422 case 0:
423 r = r * 10 + iValue;
424 break;
425 case 1:
426 g = g * 10 + iValue;
427 break;
428 default:
429 b = b * 10 + iValue;
430 break;
431 }
432 }
433 }
434}
435
436enum XFA_KEYTYPE {
437 XFA_KEYTYPE_Custom,
438 XFA_KEYTYPE_Element,
439};
440
441void* GetMapKey_Custom(const CFX_WideStringC& wsKey) {
442 uint32_t dwKey = FX_HashCode_GetW(wsKey, false);
443 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom);
444}
445
446void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) {
447 return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) |
448 (eAttribute << 8) | XFA_KEYTYPE_Element);
449}
450
dsinclair9eb0db12016-07-21 12:01:39 -0700451const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement,
452 XFA_ATTRIBUTE eAttribute,
453 uint32_t dwPacket) {
454 int32_t iCount = 0;
455 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount);
456 if (!pAttr || iCount < 1)
457 return nullptr;
458
459 if (!std::binary_search(pAttr, pAttr + iCount, eAttribute))
460 return nullptr;
461
462 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute);
463 ASSERT(pInfo);
464 if (dwPacket == XFA_XDPPACKET_UNKNOWN)
465 return pInfo;
466 return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr;
467}
468
469const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) {
470 return g_XFAEnumData + eName;
471}
472
dsinclair5b36f0a2016-07-19 10:56:23 -0700473} // namespace
474
475static void XFA_DefaultFreeData(void* pData) {}
476
477static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {
478 XFA_DefaultFreeData, nullptr};
479
weili47bcd4c2016-06-16 08:00:06 -0700480XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {}
481
482XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {}
483
dsinclairb9778472016-06-23 13:34:10 -0700484CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
485 uint16_t ePacket,
486 XFA_ObjectType oType,
dsinclairc1df5d42016-07-18 06:36:51 -0700487 XFA_Element eType,
488 const CFX_WideStringC& elementName)
489 : CXFA_Object(pDoc, oType, eType, elementName),
Dan Sinclair1770c022016-03-14 14:14:16 -0400490 m_pNext(nullptr),
491 m_pChild(nullptr),
492 m_pLastChild(nullptr),
493 m_pParent(nullptr),
494 m_pXMLNode(nullptr),
Dan Sinclair1770c022016-03-14 14:14:16 -0400495 m_ePacket(ePacket),
dsinclairc5a8f212016-06-20 11:11:12 -0700496 m_uNodeFlags(XFA_NodeFlag_None),
Dan Sinclair1770c022016-03-14 14:14:16 -0400497 m_dwNameHash(0),
498 m_pAuxNode(nullptr),
499 m_pMapModuleData(nullptr) {
500 ASSERT(m_pDocument);
501}
weili44f8faf2016-06-01 14:03:56 -0700502
Dan Sinclair1770c022016-03-14 14:14:16 -0400503CXFA_Node::~CXFA_Node() {
weili44f8faf2016-06-01 14:03:56 -0700504 ASSERT(!m_pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400505 RemoveMapModuleKey();
weili44f8faf2016-06-01 14:03:56 -0700506 CXFA_Node* pNode = m_pChild;
Dan Sinclair1770c022016-03-14 14:14:16 -0400507 while (pNode) {
weili44f8faf2016-06-01 14:03:56 -0700508 CXFA_Node* pNext = pNode->m_pNext;
509 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400510 delete pNode;
511 pNode = pNext;
512 }
dsinclairc5a8f212016-06-20 11:11:12 -0700513 if (m_pXMLNode && IsOwnXMLNode())
tsepezc757d9a2017-01-23 11:01:42 -0800514 delete m_pXMLNode;
Dan Sinclair1770c022016-03-14 14:14:16 -0400515}
weili44f8faf2016-06-01 14:03:56 -0700516
tsepezd19e9122016-11-02 15:43:18 -0700517CXFA_Node* CXFA_Node::Clone(bool bRecursive) {
dsinclaira1b07722016-07-11 08:20:58 -0700518 CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700519 if (!pClone)
520 return nullptr;
521
Dan Sinclair1770c022016-03-14 14:14:16 -0400522 MergeAllData(pClone);
523 pClone->UpdateNameHash();
524 if (IsNeedSavingXMLNode()) {
weili44f8faf2016-06-01 14:03:56 -0700525 CFDE_XMLNode* pCloneXML = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400526 if (IsAttributeInXML()) {
527 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -0700528 GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -0700529 CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -0400530 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
531 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -0700532 pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -0400533 }
534 pCloneXML = pCloneXMLElement;
weili44f8faf2016-06-01 14:03:56 -0700535 pCloneXMLElement = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400536 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
537 } else {
tsepezd19e9122016-11-02 15:43:18 -0700538 pCloneXML = m_pXMLNode->Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400539 }
540 pClone->SetXMLMappingNode(pCloneXML);
dsinclairc5a8f212016-06-20 11:11:12 -0700541 pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400542 }
543 if (bRecursive) {
544 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
545 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
546 pClone->InsertChild(pChild->Clone(bRecursive));
547 }
548 }
dsinclairc5a8f212016-06-20 11:11:12 -0700549 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
weili44f8faf2016-06-01 14:03:56 -0700550 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400551 return pClone;
552}
weili44f8faf2016-06-01 14:03:56 -0700553
Dan Sinclair1770c022016-03-14 14:14:16 -0400554CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
555 switch (eItem) {
556 case XFA_NODEITEM_NextSibling:
557 return m_pNext;
558 case XFA_NODEITEM_FirstChild:
559 return m_pChild;
560 case XFA_NODEITEM_Parent:
561 return m_pParent;
562 case XFA_NODEITEM_PrevSibling:
563 if (m_pParent) {
564 CXFA_Node* pSibling = m_pParent->m_pChild;
weili44f8faf2016-06-01 14:03:56 -0700565 CXFA_Node* pPrev = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400566 while (pSibling && pSibling != this) {
567 pPrev = pSibling;
568 pSibling = pSibling->m_pNext;
569 }
570 return pPrev;
571 }
weili44f8faf2016-06-01 14:03:56 -0700572 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400573 default:
574 break;
575 }
weili44f8faf2016-06-01 14:03:56 -0700576 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400577}
weili44f8faf2016-06-01 14:03:56 -0700578
Dan Sinclair1770c022016-03-14 14:14:16 -0400579CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
dsinclairc5a8f212016-06-20 11:11:12 -0700580 XFA_ObjectType eType) const {
weili44f8faf2016-06-01 14:03:56 -0700581 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400582 switch (eItem) {
583 case XFA_NODEITEM_NextSibling:
584 pNode = m_pNext;
dsinclairc5a8f212016-06-20 11:11:12 -0700585 while (pNode && pNode->GetObjectType() != eType)
586 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400587 break;
588 case XFA_NODEITEM_FirstChild:
589 pNode = m_pChild;
dsinclairc5a8f212016-06-20 11:11:12 -0700590 while (pNode && pNode->GetObjectType() != eType)
591 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400592 break;
593 case XFA_NODEITEM_Parent:
594 pNode = m_pParent;
dsinclairc5a8f212016-06-20 11:11:12 -0700595 while (pNode && pNode->GetObjectType() != eType)
596 pNode = pNode->m_pParent;
Dan Sinclair1770c022016-03-14 14:14:16 -0400597 break;
598 case XFA_NODEITEM_PrevSibling:
599 if (m_pParent) {
600 CXFA_Node* pSibling = m_pParent->m_pChild;
601 while (pSibling && pSibling != this) {
dsinclairc5a8f212016-06-20 11:11:12 -0700602 if (eType == pSibling->GetObjectType())
Dan Sinclair1770c022016-03-14 14:14:16 -0400603 pNode = pSibling;
dsinclairc5a8f212016-06-20 11:11:12 -0700604
Dan Sinclair1770c022016-03-14 14:14:16 -0400605 pSibling = pSibling->m_pNext;
606 }
607 }
608 break;
609 default:
610 break;
611 }
612 return pNode;
613}
weili44f8faf2016-06-01 14:03:56 -0700614
Dan Sinclair1770c022016-03-14 14:14:16 -0400615int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes,
tsepez736f28a2016-03-25 14:19:51 -0700616 uint32_t dwTypeFilter,
dsinclair41cb62e2016-06-23 09:20:32 -0700617 XFA_Element eTypeFilter,
Dan Sinclair1770c022016-03-14 14:14:16 -0400618 int32_t iLevel) {
619 if (--iLevel < 0) {
620 return nodes.GetSize();
621 }
dsinclair41cb62e2016-06-23 09:20:32 -0700622 if (eTypeFilter != XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400623 CXFA_Node* pChild = m_pChild;
624 while (pChild) {
dsinclair41cb62e2016-06-23 09:20:32 -0700625 if (pChild->GetElementType() == eTypeFilter) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400626 nodes.Add(pChild);
627 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700628 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400629 }
630 }
631 pChild = pChild->m_pNext;
632 }
633 } else if (dwTypeFilter ==
634 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
635 CXFA_Node* pChild = m_pChild;
636 while (pChild) {
637 nodes.Add(pChild);
638 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700639 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400640 }
641 pChild = pChild->m_pNext;
642 }
643 } else if (dwTypeFilter != 0) {
weili44f8faf2016-06-01 14:03:56 -0700644 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
645 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
646 bool bFilterOneOfProperties =
647 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
Dan Sinclair1770c022016-03-14 14:14:16 -0400648 CXFA_Node* pChild = m_pChild;
649 while (pChild) {
650 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -0700651 GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -0400652 if (pProperty) {
653 if (bFilterProperties) {
654 nodes.Add(pChild);
655 } else if (bFilterOneOfProperties &&
656 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
657 nodes.Add(pChild);
658 } else if (bFilterChildren &&
dsinclair070fcdf2016-06-22 22:04:54 -0700659 (pChild->GetElementType() == XFA_Element::Variables ||
660 pChild->GetElementType() == XFA_Element::PageSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400661 nodes.Add(pChild);
662 }
weili44f8faf2016-06-01 14:03:56 -0700663 } else if (bFilterChildren) {
664 nodes.Add(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400665 }
666 pChild = pChild->m_pNext;
667 }
668 if (bFilterOneOfProperties && nodes.GetSize() < 1) {
669 int32_t iProperties = 0;
670 const XFA_PROPERTY* pProperty =
dsinclair070fcdf2016-06-22 22:04:54 -0700671 XFA_GetElementProperties(GetElementType(), iProperties);
weili44f8faf2016-06-01 14:03:56 -0700672 if (!pProperty || iProperties < 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400673 return 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400674 for (int32_t i = 0; i < iProperties; i++) {
675 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400676 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
677 CXFA_Node* pNewNode =
dsinclaira1b07722016-07-11 08:20:58 -0700678 m_pDocument->CreateNode(pPacket, pProperty[i].eName);
weili44f8faf2016-06-01 14:03:56 -0700679 if (!pNewNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400680 break;
weili44f8faf2016-06-01 14:03:56 -0700681 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -0700682 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400683 nodes.Add(pNewNode);
684 break;
685 }
686 }
687 }
688 }
689 return nodes.GetSize();
690}
weili44f8faf2016-06-01 14:03:56 -0700691
dsinclair41cb62e2016-06-23 09:20:32 -0700692CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
tsepez736f28a2016-03-25 14:19:51 -0700693 uint32_t dwFlags) {
dsinclaira1b07722016-07-11 08:20:58 -0700694 CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
thestigb1a59592016-04-14 18:29:56 -0700695 pNode->SetFlag(dwFlags, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400696 return pNode;
697}
weili44f8faf2016-06-01 14:03:56 -0700698
tsepezd19e9122016-11-02 15:43:18 -0700699CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) {
dsinclair43854a52016-04-27 12:26:00 -0700700 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
dsinclaira1b07722016-07-11 08:20:58 -0700701 CXFA_Node* pClone =
702 m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700703 if (!pClone)
704 return nullptr;
705
Dan Sinclair1770c022016-03-14 14:14:16 -0400706 pClone->SetTemplateNode(this);
707 pClone->UpdateNameHash();
708 pClone->SetXMLMappingNode(GetXMLMappingNode());
709 if (bRecursive) {
710 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
711 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
712 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
713 }
714 }
dsinclairc5a8f212016-06-20 11:11:12 -0700715 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400716 return pClone;
717}
718
719CXFA_Node* CXFA_Node::GetTemplateNode() const {
720 return m_pAuxNode;
721}
722
723void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
724 m_pAuxNode = pTemplateNode;
725}
weili44f8faf2016-06-01 14:03:56 -0700726
Dan Sinclair1770c022016-03-14 14:14:16 -0400727CXFA_Node* CXFA_Node::GetBindData() {
728 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
729 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
730}
weili44f8faf2016-06-01 14:03:56 -0700731
Dan Sinclair1770c022016-03-14 14:14:16 -0400732int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) {
dsinclairc5a8f212016-06-20 11:11:12 -0700733 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700734 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400735 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
736 formItems.Copy(*pItems);
737 return formItems.GetSize();
738 }
739 CXFA_Node* pFormNode =
740 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
weili44f8faf2016-06-01 14:03:56 -0700741 if (pFormNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400742 formItems.Add(pFormNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400743 return formItems.GetSize();
744}
745
Dan Sinclair1770c022016-03-14 14:14:16 -0400746int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
747 ASSERT(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700748 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700749 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400750 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
751 ASSERT(pItems);
752 if (pItems->Find(pFormNode) < 0) {
753 pItems->Add(pFormNode);
754 }
755 return pItems->GetSize();
756 }
757 CXFA_Node* pOldFormItem =
758 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
759 if (!pOldFormItem) {
760 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
761 return 1;
762 } else if (pOldFormItem == pFormNode) {
763 return 1;
764 }
765 CXFA_NodeArray* pItems = new CXFA_NodeArray;
766 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
767 pItems->Add(pOldFormItem);
768 pItems->Add(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700769 m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400770 return 2;
771}
weili44f8faf2016-06-01 14:03:56 -0700772
Dan Sinclair1770c022016-03-14 14:14:16 -0400773int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
dsinclairc5a8f212016-06-20 11:11:12 -0700774 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700775 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400776 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
777 ASSERT(pItems);
778 int32_t iIndex = pItems->Find(pFormNode);
779 int32_t iCount = pItems->GetSize();
780 if (iIndex >= 0) {
weili44f8faf2016-06-01 14:03:56 -0700781 if (iIndex != iCount - 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400782 pItems->SetAt(iIndex, pItems->GetAt(iCount - 1));
Dan Sinclair1770c022016-03-14 14:14:16 -0400783 pItems->RemoveAt(iCount - 1);
784 if (iCount == 2) {
785 CXFA_Node* pLastFormNode = pItems->GetAt(0);
786 SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700787 m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400788 }
789 iCount--;
790 }
791 return iCount;
792 }
793 CXFA_Node* pOldFormItem =
794 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
795 if (pOldFormItem == pFormNode) {
weili44f8faf2016-06-01 14:03:56 -0700796 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
797 pOldFormItem = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400798 }
weili44f8faf2016-06-01 14:03:56 -0700799 return pOldFormItem ? 1 : 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400800}
weili44f8faf2016-06-01 14:03:56 -0700801
tsepezd19e9122016-11-02 15:43:18 -0700802bool CXFA_Node::HasBindItem() {
weili44f8faf2016-06-01 14:03:56 -0700803 return GetPacketID() == XFA_XDPPACKET_Datasets &&
804 GetObject(XFA_ATTRIBUTE_BindingNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400805}
weili44f8faf2016-06-01 14:03:56 -0700806
Dan Sinclair1770c022016-03-14 14:14:16 -0400807CXFA_WidgetData* CXFA_Node::GetWidgetData() {
808 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
809}
weili44f8faf2016-06-01 14:03:56 -0700810
Dan Sinclair1770c022016-03-14 14:14:16 -0400811CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
weili44f8faf2016-06-01 14:03:56 -0700812 if (GetPacketID() != XFA_XDPPACKET_Form)
813 return nullptr;
dsinclair41cb62e2016-06-23 09:20:32 -0700814 XFA_Element eType = GetElementType();
815 if (eType == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700816 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400817 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700818 if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700819 return nullptr;
820
dsinclair41cb62e2016-06-23 09:20:32 -0700821 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400822 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
823 if (pFieldWidgetData &&
824 pFieldWidgetData->GetChoiceListOpen() ==
825 XFA_ATTRIBUTEENUM_MultiSelect) {
weili44f8faf2016-06-01 14:03:56 -0700826 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400827 } else {
828 CFX_WideString wsPicture;
829 if (pFieldWidgetData) {
830 pFieldWidgetData->GetPictureContent(wsPicture,
831 XFA_VALUEPICTURE_DataBind);
832 }
weili44f8faf2016-06-01 14:03:56 -0700833 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400834 return pFieldWidgetData;
Dan Sinclair1770c022016-03-14 14:14:16 -0400835 CXFA_Node* pDataNode = GetBindData();
weili44f8faf2016-06-01 14:03:56 -0700836 if (!pDataNode)
837 return nullptr;
838 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400839 CXFA_NodeArray formNodes;
840 pDataNode->GetBindItems(formNodes);
841 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
842 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -0700843 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -0400844 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400845 pFieldWidgetData = pFormNode->GetWidgetData();
846 if (pFieldWidgetData) {
847 pFieldWidgetData->GetPictureContent(wsPicture,
848 XFA_VALUEPICTURE_DataBind);
849 }
weili44f8faf2016-06-01 14:03:56 -0700850 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400851 break;
weili44f8faf2016-06-01 14:03:56 -0700852 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400853 }
854 return pFieldWidgetData;
855 }
856 }
857 CXFA_Node* pGrandNode =
weili44f8faf2016-06-01 14:03:56 -0700858 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400859 CXFA_Node* pValueNode =
dsinclair070fcdf2016-06-22 22:04:54 -0700860 (pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
Dan Sinclair1770c022016-03-14 14:14:16 -0400861 ? pParentNode
weili44f8faf2016-06-01 14:03:56 -0700862 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400863 if (!pValueNode) {
dsinclair070fcdf2016-06-22 22:04:54 -0700864 pValueNode =
865 (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
866 ? pGrandNode
867 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400868 }
869 CXFA_Node* pParentOfValueNode =
weili44f8faf2016-06-01 14:03:56 -0700870 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400871 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
weili44f8faf2016-06-01 14:03:56 -0700872 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400873}
weili44f8faf2016-06-01 14:03:56 -0700874
tsepezd19e9122016-11-02 15:43:18 -0700875bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400876 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
dsinclair56a8b192016-06-21 14:15:25 -0700877 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
dsinclair43854a52016-04-27 12:26:00 -0700878 ASSERT(pTopSubform);
Dan Sinclair1770c022016-03-14 14:14:16 -0400879 CXFA_Node* pLocaleNode = this;
tsepezd19e9122016-11-02 15:43:18 -0700880 bool bLocale = false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400881 do {
tsepezd19e9122016-11-02 15:43:18 -0700882 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400883 if (!bLocale) {
884 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
885 }
886 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
weili44f8faf2016-06-01 14:03:56 -0700887 if (bLocale)
tsepezd19e9122016-11-02 15:43:18 -0700888 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400889 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
890 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
weili44f8faf2016-06-01 14:03:56 -0700891 if (!wsLocaleName.IsEmpty())
tsepezd19e9122016-11-02 15:43:18 -0700892 return true;
weili44f8faf2016-06-01 14:03:56 -0700893 if (pTopSubform &&
tsepezd19e9122016-11-02 15:43:18 -0700894 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) {
895 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400896 }
897 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
898 if (pLocale) {
899 wsLocaleName = pLocale->GetName();
tsepezd19e9122016-11-02 15:43:18 -0700900 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400901 }
tsepezd19e9122016-11-02 15:43:18 -0700902 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400903}
weili44f8faf2016-06-01 14:03:56 -0700904
Dan Sinclair1770c022016-03-14 14:14:16 -0400905XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
dsinclair56a8b192016-06-21 14:15:25 -0700906 CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
Dan Sinclair1770c022016-03-14 14:14:16 -0400907 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
908 if (pKeep) {
909 XFA_ATTRIBUTEENUM eIntact;
tsepezd19e9122016-11-02 15:43:18 -0700910 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400911 if (eIntact == XFA_ATTRIBUTEENUM_None &&
912 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
913 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
dsinclairc5a8f212016-06-20 11:11:12 -0700914 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
915 XFA_ObjectType::ContainerNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400916 if (pPreviewRow &&
917 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
918 XFA_ATTRIBUTEENUM_Row) {
919 XFA_ATTRIBUTEENUM eValue;
tsepezd19e9122016-11-02 15:43:18 -0700920 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700921 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
922 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
923 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400924 }
weili44f8faf2016-06-01 14:03:56 -0700925 CXFA_Node* pNode =
dsinclair56a8b192016-06-21 14:15:25 -0700926 pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
tsepezd19e9122016-11-02 15:43:18 -0700927 if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700928 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
929 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
930 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400931 }
932 }
933 }
934 return eIntact;
935 }
936 }
dsinclair41cb62e2016-06-23 09:20:32 -0700937 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700938 case XFA_Element::Subform:
Dan Sinclair1770c022016-03-14 14:14:16 -0400939 switch (eLayoutType) {
940 case XFA_ATTRIBUTEENUM_Position:
941 case XFA_ATTRIBUTEENUM_Row:
942 return XFA_ATTRIBUTEENUM_ContentArea;
943 case XFA_ATTRIBUTEENUM_Tb:
944 case XFA_ATTRIBUTEENUM_Table:
945 case XFA_ATTRIBUTEENUM_Lr_tb:
946 case XFA_ATTRIBUTEENUM_Rl_tb:
947 return XFA_ATTRIBUTEENUM_None;
948 default:
949 break;
950 }
951 break;
dsinclair56a8b192016-06-21 14:15:25 -0700952 case XFA_Element::Field: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400953 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700954 if (!pParentNode ||
955 pParentNode->GetElementType() == XFA_Element::PageArea)
Dan Sinclair1770c022016-03-14 14:14:16 -0400956 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400957 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
958 XFA_ATTRIBUTEENUM eParLayout =
959 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
960 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
961 eParLayout == XFA_ATTRIBUTEENUM_Row ||
962 eParLayout == XFA_ATTRIBUTEENUM_Table) {
963 return XFA_ATTRIBUTEENUM_None;
964 }
965 XFA_VERSION version = m_pDocument->GetCurVersionMode();
966 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
967 CXFA_Measurement measureH;
tsepezd19e9122016-11-02 15:43:18 -0700968 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false))
Dan Sinclair1770c022016-03-14 14:14:16 -0400969 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400970 }
971 return XFA_ATTRIBUTEENUM_None;
972 }
973 return XFA_ATTRIBUTEENUM_ContentArea;
974 }
dsinclair56a8b192016-06-21 14:15:25 -0700975 case XFA_Element::Draw:
Dan Sinclair1770c022016-03-14 14:14:16 -0400976 return XFA_ATTRIBUTEENUM_ContentArea;
977 default:
978 break;
979 }
980 return XFA_ATTRIBUTEENUM_None;
981}
weili44f8faf2016-06-01 14:03:56 -0700982
Dan Sinclair1770c022016-03-14 14:14:16 -0400983CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
weili44f8faf2016-06-01 14:03:56 -0700984 if (m_ePacket == XFA_XDPPACKET_Datasets)
Dan Sinclair1770c022016-03-14 14:14:16 -0400985 return m_pAuxNode;
weili44f8faf2016-06-01 14:03:56 -0700986 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400987}
weili44f8faf2016-06-01 14:03:56 -0700988
Dan Sinclair1770c022016-03-14 14:14:16 -0400989void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
dsinclair43854a52016-04-27 12:26:00 -0700990 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
Dan Sinclair1770c022016-03-14 14:14:16 -0400991 m_pAuxNode = pDataDescriptionNode;
992}
weili44f8faf2016-06-01 14:03:56 -0700993
Dan Sinclair1770c022016-03-14 14:14:16 -0400994void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
995 int32_t iLength = pArguments->GetLength();
996 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -0500997 ThrowParamCountMismatchException(L"resolveNode");
Dan Sinclair1770c022016-03-14 14:14:16 -0400998 return;
999 }
tsepez6fe7d212016-04-06 10:51:14 -07001000 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001001 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclairdf4bc592016-03-31 20:34:43 -07001002 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001003 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001004 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001005 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001006 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001007 refNode = ToNode(pScriptContext->GetThisObject());
tsepez736f28a2016-03-25 14:19:51 -07001008 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001009 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1010 XFA_RESOLVENODE_Siblings;
1011 XFA_RESOLVENODE_RS resoveNodeRS;
tsepezfc58ad12016-04-05 12:22:15 -07001012 int32_t iRet = pScriptContext->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001013 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
dsinclairf27aeec2016-06-07 19:36:18 -07001014 if (iRet < 1) {
1015 pArguments->GetReturnValue()->SetNull();
1016 return;
1017 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001018 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1019 CXFA_Object* pNode = resoveNodeRS.nodes[0];
dsinclairf27aeec2016-06-07 19:36:18 -07001020 pArguments->GetReturnValue()->Assign(
1021 pScriptContext->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001022 } else {
1023 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
1024 resoveNodeRS.pScriptAttribute;
1025 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
dsinclair86fad992016-05-31 11:34:04 -07001026 std::unique_ptr<CFXJSE_Value> pValue(
1027 new CFXJSE_Value(pScriptContext->GetRuntime()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001028 (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))(
tsepezd19e9122016-11-02 15:43:18 -07001029 pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
dsinclairf27aeec2016-06-07 19:36:18 -07001030 pArguments->GetReturnValue()->Assign(pValue.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001031 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001032 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001033 }
1034 }
1035}
weili44f8faf2016-06-01 14:03:56 -07001036
Dan Sinclair1770c022016-03-14 14:14:16 -04001037void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
1038 int32_t iLength = pArguments->GetLength();
1039 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001040 ThrowParamCountMismatchException(L"resolveNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04001041 return;
1042 }
tsepez6fe7d212016-04-06 10:51:14 -07001043 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001044 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclair12a6b0c2016-05-26 11:14:08 -07001045 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001046 if (!pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04001047 return;
tsepez736f28a2016-03-25 14:19:51 -07001048 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001049 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1050 XFA_RESOLVENODE_Siblings;
1051 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001052 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001053 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
dsinclair12a6b0c2016-05-26 11:14:08 -07001054 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001055}
weili44f8faf2016-06-01 14:03:56 -07001056
dsinclair12a6b0c2016-05-26 11:14:08 -07001057void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001058 CFX_WideString wsExpression,
tsepez736f28a2016-03-25 14:19:51 -07001059 uint32_t dwFlag,
Dan Sinclair1770c022016-03-14 14:14:16 -04001060 CXFA_Node* refNode) {
dsinclairdf4bc592016-03-31 20:34:43 -07001061 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001062 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001063 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001064 XFA_RESOLVENODE_RS resoveNodeRS;
weili44f8faf2016-06-01 14:03:56 -07001065 if (!refNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04001066 refNode = this;
tsepez4c3debb2016-04-08 12:20:38 -07001067 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
tsepezfc58ad12016-04-05 12:22:15 -07001068 resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001069 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
1070 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1071 for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) {
1072 if (resoveNodeRS.nodes[i]->IsNode())
1073 pNodeList->Append(resoveNodeRS.nodes[i]->AsNode());
1074 }
1075 } else {
dsinclair12a6b0c2016-05-26 11:14:08 -07001076 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
1077 if (resoveNodeRS.GetAttributeResult(valueArray) > 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001078 CXFA_ObjArray objectArray;
dsinclair12a6b0c2016-05-26 11:14:08 -07001079 valueArray.GetAttributeObject(objectArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04001080 for (int32_t i = 0; i < objectArray.GetSize(); i++) {
1081 if (objectArray[i]->IsNode())
1082 pNodeList->Append(objectArray[i]->AsNode());
1083 }
1084 }
1085 }
dsinclairf27aeec2016-06-07 19:36:18 -07001086 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001087}
weili44f8faf2016-06-01 14:03:56 -07001088
dsinclair12a6b0c2016-05-26 11:14:08 -07001089void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001090 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001091 XFA_ATTRIBUTE eAttribute) {
1092 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001093 ThrowInvalidPropertyException();
1094 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001095 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001096
1097 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
1098 CFX_WideString wsName;
1099 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
dan sinclair65c7c232017-02-02 14:05:30 -08001100 CFX_WideString wsExpression = wsName + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001101 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001102}
weili44f8faf2016-06-01 14:03:56 -07001103
dsinclair12a6b0c2016-05-26 11:14:08 -07001104void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001105 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001106 XFA_ATTRIBUTE eAttribute) {
dsinclairdf4bc592016-03-31 20:34:43 -07001107 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001108 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001109 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001110 if (bSetting) {
Dan Sinclairc8fd3312017-01-02 17:17:02 -05001111 CFX_WideString wsMessage = L"Unable to set ";
tsepez28f97ff2016-04-04 16:41:35 -07001112 FXJSE_ThrowMessage(
tsepezbd9748d2016-04-13 21:40:19 -07001113 FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001114 } else {
1115 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
dsinclairf27aeec2016-06-07 19:36:18 -07001116 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001117 }
1118}
weili44f8faf2016-06-01 14:03:56 -07001119
dsinclair12a6b0c2016-05-26 11:14:08 -07001120void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001121 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001122 XFA_ATTRIBUTE eAttribute) {
1123 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001124 ThrowInvalidPropertyException();
1125 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001126 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001127
1128 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
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);
1177 pValue->SetString(FX_UTF8Encode(wsSOMExpression).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)
dsinclairf27aeec2016-06-07 19:36:18 -07001241 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001242}
weili44f8faf2016-06-01 14:03:56 -07001243
Dan Sinclair1770c022016-03-14 14:14:16 -04001244void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
1245 int32_t iLength = pArguments->GetLength();
1246 if (iLength < 1 || iLength > 2) {
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);
1511 pValue->SetString(FX_UTF8Encode(wsNameSpace).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);
dsinclairf27aeec2016-06-07 19:36:18 -07001861 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07001862 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001863 }
1864}
dsinclair5b36f0a2016-07-19 10:56:23 -07001865
dsinclair12a6b0c2016-05-26 11:14:08 -07001866void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001867 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001868 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001869 if (bSetting) {
1870 ThrowInvalidPropertyException();
1871 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001872 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001873
1874 CFX_WideString wsValue;
1875 GetAttribute(eAttribute, wsValue);
1876 pValue->SetString(
1877 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001878}
dsinclair5b36f0a2016-07-19 10:56:23 -07001879
Dan Sinclair1770c022016-03-14 14:14:16 -04001880void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1881 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001882 if (argc != 0 && argc != 1) {
1883 ThrowParamCountMismatchException(L"execute");
1884 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001885 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001886 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001887}
dsinclair5b36f0a2016-07-19 10:56:23 -07001888
Dan Sinclair1770c022016-03-14 14:14:16 -04001889void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001890 if (pArguments->GetLength() != 0)
1891 ThrowParamCountMismatchException(L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001892}
dsinclair5b36f0a2016-07-19 10:56:23 -07001893
dsinclair12a6b0c2016-05-26 11:14:08 -07001894void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001895 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001896 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001897
dsinclair12a6b0c2016-05-26 11:14:08 -07001898void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001899 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001900 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001901
dsinclair12a6b0c2016-05-26 11:14:08 -07001902void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001903 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001904 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001905
dsinclair12a6b0c2016-05-26 11:14:08 -07001906void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001907 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001908 XFA_SOM_MESSAGETYPE iMessageType) {
1909 CXFA_WidgetData* pWidgetData = GetWidgetData();
1910 if (!pWidgetData) {
1911 return;
1912 }
tsepezd19e9122016-11-02 15:43:18 -07001913 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001914 CXFA_Validate validate = pWidgetData->GetValidate();
1915 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001916 validate = pWidgetData->GetValidate(true);
1917 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001918 }
1919 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001920 switch (iMessageType) {
1921 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001922 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001923 break;
1924 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001925 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001926 break;
1927 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001928 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001929 break;
1930 default:
1931 break;
1932 }
1933 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001934 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001935 if (!pNotify) {
1936 return;
1937 }
1938 pNotify->AddCalcValidate(this);
1939 }
1940 } else {
1941 CFX_WideString wsMessage;
1942 switch (iMessageType) {
1943 case XFA_SOM_ValidationMessage:
1944 validate.GetScriptMessageText(wsMessage);
1945 break;
1946 case XFA_SOM_FormatMessage:
1947 validate.GetFormatMessageText(wsMessage);
1948 break;
1949 case XFA_SOM_MandatoryMessage:
1950 validate.GetNullMessageText(wsMessage);
1951 break;
1952 default:
1953 break;
1954 }
dsinclairf27aeec2016-06-07 19:36:18 -07001955 pValue->SetString(FX_UTF8Encode(wsMessage).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001956 }
1957}
dsinclair5b36f0a2016-07-19 10:56:23 -07001958
dsinclair12a6b0c2016-05-26 11:14:08 -07001959void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001960 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001961 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001962 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001963}
dsinclair5b36f0a2016-07-19 10:56:23 -07001964
dsinclair12a6b0c2016-05-26 11:14:08 -07001965void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001966 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001967 XFA_ATTRIBUTE eAttribute) {
1968 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001969 ThrowInvalidPropertyException();
1970 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001971 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001972
1973 CXFA_WidgetData* pWidgetData = GetWidgetData();
1974 if (!pWidgetData) {
1975 pValue->SetInteger(0);
1976 return;
1977 }
1978 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001979}
dsinclair5b36f0a2016-07-19 10:56:23 -07001980
dsinclair12a6b0c2016-05-26 11:14:08 -07001981void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001982 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001983 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001984 XFA_Element eType = GetElementType();
1985 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001986 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001987 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001988 }
1989 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001990 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001991 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001992 }
1993 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001994 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001995 return;
1996 }
1997 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001998 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07001999 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002000 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002001
Dan Sinclair1770c022016-03-14 14:14:16 -04002002 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07002003 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002004 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
2005 CXFA_NodeArray formNodes;
2006 GetBindItems(formNodes);
2007 CFX_WideString wsPicture;
2008 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
2009 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -07002010 if (!pFormNode || pFormNode->HasRemovedChildren()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002011 continue;
2012 }
2013 pContainerWidgetData = pFormNode->GetContainerWidgetData();
2014 if (pContainerWidgetData) {
2015 pContainerWidgetData->GetPictureContent(wsPicture,
2016 XFA_VALUEPICTURE_DataBind);
2017 }
2018 if (!wsPicture.IsEmpty()) {
2019 break;
2020 }
weili44f8faf2016-06-01 14:03:56 -07002021 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002022 }
2023 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
2024 pContainerWidgetData = GetContainerWidgetData();
2025 }
2026 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002027 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002028 }
tsepezd19e9122016-11-02 15:43:18 -07002029 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002030 } else {
tsepezd19e9122016-11-02 15:43:18 -07002031 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07002032 if (content.IsEmpty() && eType != XFA_Element::Text &&
2033 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07002034 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07002035 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002036 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07002037 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07002038 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002039 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002040 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002041 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002042 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002043 }
2044 }
2045}
dsinclair5b36f0a2016-07-19 10:56:23 -07002046
dsinclair12a6b0c2016-05-26 11:14:08 -07002047void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002048 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002049 XFA_ATTRIBUTE eAttribute) {
2050 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002051 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002052 return;
2053 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002054
tsepezd19e9122016-11-02 15:43:18 -07002055 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002056 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002057 pValue->SetNull();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002058 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002059 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002060 pValue->SetString(
2061 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002062}
dsinclair5b36f0a2016-07-19 10:56:23 -07002063
dsinclair12a6b0c2016-05-26 11:14:08 -07002064void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002065 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002066 XFA_ATTRIBUTE eAttribute) {
2067 if (bSetting) {
2068 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002069 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002070 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002071
tsepezb4c9f3f2016-04-13 15:41:21 -07002072 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002073 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002074 CFX_WideString wsFormatValue(wsNewValue);
2075 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2076 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002077 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002078 }
tsepezd19e9122016-11-02 15:43:18 -07002079 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002080 } else {
tsepezd19e9122016-11-02 15:43:18 -07002081 CFX_WideString wsValue = GetScriptContent(true);
dan sinclair65c7c232017-02-02 14:05:30 -08002082 pValue->SetBoolean(wsValue == L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002083 }
2084}
dsinclair2f5582f2016-06-09 11:48:23 -07002085
dsinclair12a6b0c2016-05-26 11:14:08 -07002086void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002087 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002088 XFA_ATTRIBUTE eAttribute) {
2089 CXFA_WidgetData* pWidgetData = GetWidgetData();
2090 if (!pWidgetData) {
2091 return;
2092 }
tsepezd19e9122016-11-02 15:43:18 -07002093 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002094 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002095 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002096 int32_t r = 0;
2097 int32_t g = 0;
2098 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002099 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002100 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2101 for (int32_t i = 0; i < iSize; ++i) {
2102 CXFA_Edge edge = border.GetEdge(i);
2103 edge.SetColor(rgb);
2104 }
2105 } else {
2106 CXFA_Edge edge = border.GetEdge(0);
2107 FX_ARGB color = edge.GetColor();
2108 int32_t a, r, g, b;
2109 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002110 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002111 strColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002112 pValue->SetString(FX_UTF8Encode(strColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002113 }
2114}
dsinclair5b36f0a2016-07-19 10:56:23 -07002115
dsinclair12a6b0c2016-05-26 11:14:08 -07002116void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002117 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002118 XFA_ATTRIBUTE eAttribute) {
2119 CXFA_WidgetData* pWidgetData = GetWidgetData();
2120 if (!pWidgetData) {
2121 return;
2122 }
tsepezd19e9122016-11-02 15:43:18 -07002123 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002124 int32_t iSize = border.CountEdges();
2125 CFX_WideString wsThickness;
2126 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002127 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002128 for (int32_t i = 0; i < iSize; ++i) {
2129 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002130 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002131 edge.SetMSThickness(thickness);
2132 }
2133 } else {
2134 CXFA_Edge edge = border.GetEdge(0);
2135 CXFA_Measurement thickness = edge.GetMSThickness();
2136 thickness.ToString(wsThickness);
dsinclairf27aeec2016-06-07 19:36:18 -07002137 pValue->SetString(FX_UTF8Encode(wsThickness).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002138 }
2139}
dsinclair5b36f0a2016-07-19 10:56:23 -07002140
dsinclair12a6b0c2016-05-26 11:14:08 -07002141void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002142 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002143 XFA_ATTRIBUTE eAttribute) {
2144 CXFA_WidgetData* pWidgetData = GetWidgetData();
2145 if (!pWidgetData) {
2146 return;
2147 }
tsepezd19e9122016-11-02 15:43:18 -07002148 CXFA_Border border = pWidgetData->GetBorder(true);
2149 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002150 CXFA_Node* pNode = borderfill.GetNode();
2151 if (!pNode) {
2152 return;
2153 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002154 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002155 int32_t r;
2156 int32_t g;
2157 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002158 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002159 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2160 borderfill.SetColor(color);
2161 } else {
2162 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002163 int32_t a;
2164 int32_t r;
2165 int32_t g;
2166 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002167 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002168 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002169 wsColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002170 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002171 }
2172}
dsinclair5b36f0a2016-07-19 10:56:23 -07002173
dsinclair12a6b0c2016-05-26 11:14:08 -07002174void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002175 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002176 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002177 if (bSetting) {
2178 ThrowInvalidPropertyException();
2179 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002180 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002181
2182 CXFA_Node* pDataNode = GetBindData();
2183 if (!pDataNode) {
2184 pValue->SetNull();
2185 return;
2186 }
2187
2188 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002189}
dsinclair5b36f0a2016-07-19 10:56:23 -07002190
dsinclair12a6b0c2016-05-26 11:14:08 -07002191void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002192 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002193 XFA_ATTRIBUTE eAttribute) {
2194 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002195 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002196 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002197 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002198 XFA_Element uiType = pWidgetData->GetUIType();
2199 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002200 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002201 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002202 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002203 }
2204 }
2205 } else {
tsepezd19e9122016-11-02 15:43:18 -07002206 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002207 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002208 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002209 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002210 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002211 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002212 }
2213 }
2214}
dsinclair5b36f0a2016-07-19 10:56:23 -07002215
dsinclair12a6b0c2016-05-26 11:14:08 -07002216void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002217 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002218 XFA_ATTRIBUTE eAttribute) {
2219 CXFA_WidgetData* pWidgetData = GetWidgetData();
2220 if (!pWidgetData) {
2221 return;
2222 }
2223 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002224 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002225 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002226 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002227 } else {
2228 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002229 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002230 }
dsinclair2f5582f2016-06-09 11:48:23 -07002231 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002232 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002233 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002234
Dan Sinclair1770c022016-03-14 14:14:16 -04002235 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002236 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002237 int32_t iLeadDigits = 0;
2238 int32_t iFracDigits = 0;
2239 pWidgetData->GetLeadDigits(iLeadDigits);
2240 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002241 wsNewText =
2242 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002243 }
2244 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2245 CFX_WideString wsFormatText(wsNewText);
2246 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002247 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002248 }
tsepezd19e9122016-11-02 15:43:18 -07002249 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002250 } else {
tsepezd19e9122016-11-02 15:43:18 -07002251 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002252 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002253 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002254 } else {
2255 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002256 CXFA_Value defVal = pWidgetData->GetFormValue();
2257 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002258 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002259 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002260 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002261 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002262 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002263 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002264 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002265 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002266 }
dsinclair070fcdf2016-06-22 22:04:54 -07002267 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002268 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002269 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002270 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002271 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002272 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002273 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002274 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002275 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002276 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002277 }
2278 }
2279 }
2280}
dsinclair5b36f0a2016-07-19 10:56:23 -07002281
dsinclair12a6b0c2016-05-26 11:14:08 -07002282void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002283 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002284 XFA_ATTRIBUTE eAttribute) {
2285 CXFA_WidgetData* pWidgetData = GetWidgetData();
2286 if (!pWidgetData) {
2287 return;
2288 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002289 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002290 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002291 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002292 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002293 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
dsinclairf27aeec2016-06-07 19:36:18 -07002294 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002295 }
2296}
dsinclair5b36f0a2016-07-19 10:56:23 -07002297
dsinclair12a6b0c2016-05-26 11:14:08 -07002298void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002299 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002300 XFA_ATTRIBUTE eAttribute) {
2301 CXFA_WidgetData* pWidgetData = GetWidgetData();
2302 if (!pWidgetData) {
2303 return;
2304 }
tsepezd19e9122016-11-02 15:43:18 -07002305 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002306 CXFA_Node* pNode = font.GetNode();
2307 if (!pNode) {
2308 return;
2309 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002310 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002311 int32_t r;
2312 int32_t g;
2313 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002314 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002315 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2316 font.SetColor(color);
2317 } else {
2318 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002319 int32_t a;
2320 int32_t r;
2321 int32_t g;
2322 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002323 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002324 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002325 wsColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002326 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002327 }
2328}
dsinclair5b36f0a2016-07-19 10:56:23 -07002329
dsinclair12a6b0c2016-05-26 11:14:08 -07002330void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002331 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002332 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002333 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002334}
dsinclair5b36f0a2016-07-19 10:56:23 -07002335
dsinclair12a6b0c2016-05-26 11:14:08 -07002336void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002337 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002338 XFA_ATTRIBUTE eAttribute) {
2339 CXFA_WidgetData* pWidgetData = GetWidgetData();
2340 if (!pWidgetData) {
2341 return;
2342 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002343 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002344 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002345 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002346 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002347 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
dsinclairf27aeec2016-06-07 19:36:18 -07002348 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002349 }
2350}
dsinclair5b36f0a2016-07-19 10:56:23 -07002351
dsinclair12a6b0c2016-05-26 11:14:08 -07002352void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002353 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002354 XFA_ATTRIBUTE eAttribute) {
2355 CXFA_WidgetData* pWidgetData = GetWidgetData();
2356 if (!pWidgetData) {
2357 return;
2358 }
tsepezd19e9122016-11-02 15:43:18 -07002359 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002360 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002361 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002362 } else {
2363 int32_t iValue = validate.GetNullTest();
2364 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002365 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002366 CFX_WideString wsValue;
2367 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002368 wsValue = pInfo->pName;
dsinclairf27aeec2016-06-07 19:36:18 -07002369 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002370 }
2371}
dsinclair5b36f0a2016-07-19 10:56:23 -07002372
dsinclair12a6b0c2016-05-26 11:14:08 -07002373void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002374 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002375 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002376 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002377}
dsinclair5b36f0a2016-07-19 10:56:23 -07002378
dsinclair12a6b0c2016-05-26 11:14:08 -07002379void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002380 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002381 XFA_ATTRIBUTE eAttribute) {
2382 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002383 ThrowInvalidPropertyException();
2384 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002385 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002386 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002387}
dsinclair5b36f0a2016-07-19 10:56:23 -07002388
dsinclair12a6b0c2016-05-26 11:14:08 -07002389void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002390 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002391 XFA_ATTRIBUTE eAttribute) {
2392 CXFA_WidgetData* pWidgetData = GetWidgetData();
2393 if (!pWidgetData) {
2394 return;
2395 }
2396 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002397 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002398 if (iIndex == -1) {
2399 pWidgetData->ClearAllSelections();
2400 return;
2401 }
tsepezd19e9122016-11-02 15:43:18 -07002402 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002403 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002404 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002405 }
2406}
dsinclair5b36f0a2016-07-19 10:56:23 -07002407
Dan Sinclair1770c022016-03-14 14:14:16 -04002408void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2409 CXFA_WidgetData* pWidgetData = GetWidgetData();
2410 if (!pWidgetData) {
2411 return;
2412 }
tsepezd19e9122016-11-02 15:43:18 -07002413 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002414}
dsinclair5b36f0a2016-07-19 10:56:23 -07002415
Dan Sinclair1770c022016-03-14 14:14:16 -04002416void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002417 if (pArguments->GetLength() != 1) {
2418 ThrowParamCountMismatchException(L"execEvent");
2419 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002420 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002421
2422 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2423 int32_t iRet = execSingleEventByName(
2424 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2425 XFA_Element::Field);
2426 if (eventString != "validate")
2427 return;
2428
2429 pArguments->GetReturnValue()->SetBoolean(
2430 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002431}
dsinclair5b36f0a2016-07-19 10:56:23 -07002432
Dan Sinclair1770c022016-03-14 14:14:16 -04002433void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002434 if (pArguments->GetLength() != 0) {
2435 ThrowParamCountMismatchException(L"execInitialize");
2436 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002437 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002438
2439 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2440 if (!pNotify)
2441 return;
2442
2443 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002444}
dsinclair5b36f0a2016-07-19 10:56:23 -07002445
Dan Sinclair1770c022016-03-14 14:14:16 -04002446void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2447 int32_t iLength = pArguments->GetLength();
2448 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002449 ThrowParamCountMismatchException(L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002450 return;
2451 }
2452 CXFA_WidgetData* pWidgetData = GetWidgetData();
2453 if (!pWidgetData) {
2454 return;
2455 }
2456 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002457 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002458 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002459 if (pValue)
2460 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002461}
dsinclair5b36f0a2016-07-19 10:56:23 -07002462
Dan Sinclair1770c022016-03-14 14:14:16 -04002463void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2464 int32_t iLength = pArguments->GetLength();
2465 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002466 ThrowParamCountMismatchException(L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002467 return;
2468 }
2469 int32_t iIndex = pArguments->GetInt32(0);
2470 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002471 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002472 return;
2473 }
2474 CXFA_WidgetData* pWidgetData = GetWidgetData();
2475 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002476 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002477 return;
2478 }
2479 CFX_WideString wsValue;
tsepezd19e9122016-11-02 15:43:18 -07002480 bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002481 if (bHasItem) {
dsinclairf27aeec2016-06-07 19:36:18 -07002482 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002483 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002484 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002485 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002486 }
2487}
dsinclair5b36f0a2016-07-19 10:56:23 -07002488
Dan Sinclair1770c022016-03-14 14:14:16 -04002489void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2490 int32_t iLength = pArguments->GetLength();
2491 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002492 ThrowParamCountMismatchException(L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002493 return;
2494 }
2495 CXFA_WidgetData* pWidgetData = GetWidgetData();
2496 if (!pWidgetData) {
2497 return;
2498 }
2499 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002500 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002501 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002502 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002503 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002504 if (pValue)
2505 pValue->SetString(FX_UTF8Encode(wsBoundValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002506}
dsinclair5b36f0a2016-07-19 10:56:23 -07002507
Dan Sinclair1770c022016-03-14 14:14:16 -04002508void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2509 int32_t iLength = pArguments->GetLength();
2510 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002511 ThrowParamCountMismatchException(L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002512 return;
2513 }
2514 CXFA_WidgetData* pWidgetData = GetWidgetData();
2515 if (!pWidgetData) {
2516 return;
2517 }
2518 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002519 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002520 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002521 if (pValue)
2522 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002523}
dsinclair5b36f0a2016-07-19 10:56:23 -07002524
Dan Sinclair1770c022016-03-14 14:14:16 -04002525void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002526 if (pArguments->GetLength() != 0) {
2527 ThrowParamCountMismatchException(L"execCalculate");
2528 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002529 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002530
2531 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2532 if (!pNotify)
2533 return;
2534
2535 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002536}
dsinclair5b36f0a2016-07-19 10:56:23 -07002537
Dan Sinclair1770c022016-03-14 14:14:16 -04002538void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002539
Dan Sinclair1770c022016-03-14 14:14:16 -04002540void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2541 int32_t iLength = pArguments->GetLength();
2542 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002543 ThrowParamCountMismatchException(L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002544 return;
2545 }
2546 int32_t iIndex = pArguments->GetInt32(0);
2547 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002548 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002549 return;
2550 }
2551 CXFA_WidgetData* pWidgetData = GetWidgetData();
2552 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002553 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002554 return;
2555 }
2556 CFX_WideString wsValue;
tsepezd19e9122016-11-02 15:43:18 -07002557 bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002558 if (bHasItem) {
dsinclairf27aeec2016-06-07 19:36:18 -07002559 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002560 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002561 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002562 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002563 }
2564}
dsinclair5b36f0a2016-07-19 10:56:23 -07002565
Dan Sinclair1770c022016-03-14 14:14:16 -04002566void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2567 int32_t iLength = pArguments->GetLength();
2568 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002569 ThrowParamCountMismatchException(L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002570 return;
2571 }
2572 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002573 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002574 return;
thestig800222e2016-05-26 22:00:29 -07002575
Dan Sinclair1770c022016-03-14 14:14:16 -04002576 int32_t iIndex = pArguments->GetInt32(0);
2577 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002578 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002579 } else {
thestig800222e2016-05-26 22:00:29 -07002580 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002581 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002582 }
2583}
dsinclair5b36f0a2016-07-19 10:56:23 -07002584
Dan Sinclair1770c022016-03-14 14:14:16 -04002585void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2586 int32_t iLength = pArguments->GetLength();
2587 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002588 ThrowParamCountMismatchException(L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002589 return;
2590 }
2591 CXFA_WidgetData* pWidgetData = GetWidgetData();
2592 if (!pWidgetData) {
2593 return;
2594 }
2595 CFX_WideString wsLabel;
2596 CFX_WideString wsValue;
2597 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002598 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002599 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002600 }
2601 if (iLength >= 2) {
2602 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002603 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002604 }
tsepezd19e9122016-11-02 15:43:18 -07002605 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002606}
dsinclair5b36f0a2016-07-19 10:56:23 -07002607
Dan Sinclair1770c022016-03-14 14:14:16 -04002608void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002609 if (pArguments->GetLength() != 0) {
2610 ThrowParamCountMismatchException(L"execValidate");
2611 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002612 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002613
2614 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2615 if (!pNotify) {
2616 pArguments->GetReturnValue()->SetBoolean(false);
2617 return;
2618 }
2619
2620 int32_t iRet =
2621 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
2622 pArguments->GetReturnValue()->SetBoolean(
2623 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002624}
dsinclair5b36f0a2016-07-19 10:56:23 -07002625
dsinclair12a6b0c2016-05-26 11:14:08 -07002626void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002627 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002628 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002629 if (bSetting)
2630 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002631}
dsinclair5b36f0a2016-07-19 10:56:23 -07002632
dsinclair12a6b0c2016-05-26 11:14:08 -07002633void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002634 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002635 XFA_ATTRIBUTE eAttribute) {
2636 CXFA_WidgetData* pWidgetData = GetWidgetData();
2637 if (!pWidgetData) {
2638 return;
2639 }
2640 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002641 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002642 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002643 } else {
tsepezd19e9122016-11-02 15:43:18 -07002644 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002645 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2646 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002647 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002648 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002649 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002650 }
2651 }
2652}
dsinclair5b36f0a2016-07-19 10:56:23 -07002653
dsinclair12a6b0c2016-05-26 11:14:08 -07002654void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002655 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002656 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002657
Dan Sinclair1770c022016-03-14 14:14:16 -04002658void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002659 if (pArguments->GetLength() != 1) {
2660 ThrowParamCountMismatchException(L"execEvent");
2661 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002662 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002663
2664 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2665 execSingleEventByName(
2666 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2667 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002668}
thestig800222e2016-05-26 22:00:29 -07002669
Dan Sinclair1770c022016-03-14 14:14:16 -04002670void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2671 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002672 if (argc < 0 || argc > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002673 ThrowParamCountMismatchException(L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002674 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002675 }
thestig800222e2016-05-26 22:00:29 -07002676
2677 CXFA_WidgetData* pWidgetData = GetWidgetData();
2678 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002679 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002680 return;
2681 }
2682
2683 CXFA_Node* pReturnNode = nullptr;
2684 if (argc == 0) {
2685 pReturnNode = pWidgetData->GetSelectedMember();
2686 } else {
2687 CFX_ByteString szName;
2688 szName = pArguments->GetUTF8String(0);
2689 pReturnNode = pWidgetData->SetSelectedMember(
2690 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2691 }
2692 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002693 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002694 return;
2695 }
dsinclairf27aeec2016-06-07 19:36:18 -07002696 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002697 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002698}
thestig800222e2016-05-26 22:00:29 -07002699
Dan Sinclair1770c022016-03-14 14:14:16 -04002700void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002701 if (pArguments->GetLength() != 0) {
2702 ThrowParamCountMismatchException(L"execInitialize");
2703 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002704 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002705
2706 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2707 if (!pNotify)
2708 return;
2709
2710 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002711}
dsinclair5b36f0a2016-07-19 10:56:23 -07002712
Dan Sinclair1770c022016-03-14 14:14:16 -04002713void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002714 if (pArguments->GetLength() != 0) {
2715 ThrowParamCountMismatchException(L"execCalculate");
2716 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002717 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002718
2719 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2720 if (!pNotify)
2721 return;
2722
2723 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002724}
dsinclair5b36f0a2016-07-19 10:56:23 -07002725
Dan Sinclair1770c022016-03-14 14:14:16 -04002726void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002727 if (pArguments->GetLength() != 0) {
2728 ThrowParamCountMismatchException(L"execValidate");
2729 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002730 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002731
2732 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2733 if (!pNotify) {
2734 pArguments->GetReturnValue()->SetBoolean(false);
2735 return;
2736 }
2737
2738 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2739 pArguments->GetReturnValue()->SetBoolean(
2740 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002741}
dsinclair5b36f0a2016-07-19 10:56:23 -07002742
dsinclair12a6b0c2016-05-26 11:14:08 -07002743void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002744 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002745 XFA_ATTRIBUTE eAttribute) {
2746 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002747 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002748 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002749 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002750 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2751 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002752 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002753 pManagerNode = pNode;
2754 break;
2755 }
2756 }
2757 if (pManagerNode) {
2758 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002759 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002760 if (!pNotify) {
2761 return;
2762 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002763 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002764 if (pToInstance &&
2765 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002766 pNotify->RunSubformIndexChange(pToInstance);
2767 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002768 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002769 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002770 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002771 pNotify->RunSubformIndexChange(pFromInstance);
2772 }
2773 }
2774 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002775 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002776 }
2777}
dsinclair5b36f0a2016-07-19 10:56:23 -07002778
dsinclair12a6b0c2016-05-26 11:14:08 -07002779void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002780 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002781 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002782 if (bSetting) {
2783 ThrowInvalidPropertyException();
2784 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002785 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002786
2787 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2788 CXFA_Node* pInstanceMgr = nullptr;
2789 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2790 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2791 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2792 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2793 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2794 wsInstMgrName.Mid(1) == wsName) {
2795 pInstanceMgr = pNode;
2796 }
2797 break;
2798 }
2799 }
2800 if (!pInstanceMgr) {
2801 pValue->SetNull();
2802 return;
2803 }
2804
2805 pValue->Assign(
2806 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
Dan Sinclair1770c022016-03-14 14:14:16 -04002807}
dsinclair5b36f0a2016-07-19 10:56:23 -07002808
dsinclair12a6b0c2016-05-26 11:14:08 -07002809void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002810 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002811 XFA_ATTRIBUTE eAttribute) {
2812 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002813 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002814 } else {
2815 CFX_WideString wsLocaleName;
2816 GetLocaleName(wsLocaleName);
dsinclairf27aeec2016-06-07 19:36:18 -07002817 pValue->SetString(
2818 FX_UTF8Encode(wsLocaleName.c_str(), wsLocaleName.GetLength())
2819 .AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002820 }
2821}
dsinclair5b36f0a2016-07-19 10:56:23 -07002822
Dan Sinclair1770c022016-03-14 14:14:16 -04002823void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002824 if (pArguments->GetLength() != 1) {
2825 ThrowParamCountMismatchException(L"execEvent");
2826 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002827 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002828
2829 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2830 execSingleEventByName(
2831 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2832 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002833}
dsinclair5b36f0a2016-07-19 10:56:23 -07002834
Dan Sinclair1770c022016-03-14 14:14:16 -04002835void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002836 if (pArguments->GetLength() != 0) {
2837 ThrowParamCountMismatchException(L"execInitialize");
2838 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002839 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002840
2841 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2842 if (!pNotify)
2843 return;
2844
2845 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002846}
dsinclair5b36f0a2016-07-19 10:56:23 -07002847
Dan Sinclair1770c022016-03-14 14:14:16 -04002848void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002849 if (pArguments->GetLength() != 0) {
2850 ThrowParamCountMismatchException(L"execCalculate");
2851 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002852 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002853
2854 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2855 if (!pNotify)
2856 return;
2857
2858 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002859}
dsinclair5b36f0a2016-07-19 10:56:23 -07002860
Dan Sinclair1770c022016-03-14 14:14:16 -04002861void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002862 if (pArguments->GetLength() != 0) {
2863 ThrowParamCountMismatchException(L"execValidate");
2864 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002865 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002866
2867 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2868 if (!pNotify) {
2869 pArguments->GetReturnValue()->SetBoolean(false);
2870 return;
2871 }
2872
2873 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2874 pArguments->GetReturnValue()->SetBoolean(
2875 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002876}
dsinclair5b36f0a2016-07-19 10:56:23 -07002877
Dan Sinclair1770c022016-03-14 14:14:16 -04002878void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002879 if (pArguments->GetLength() != 0)
2880 ThrowParamCountMismatchException(L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002881}
dsinclair5b36f0a2016-07-19 10:56:23 -07002882
Dan Sinclair1770c022016-03-14 14:14:16 -04002883int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2884 int32_t index = 0;
2885 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2886 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002887 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2888 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002889 index++;
2890 } else {
2891 break;
2892 }
2893 }
2894 return index;
2895}
dsinclair5b36f0a2016-07-19 10:56:23 -07002896
Dan Sinclair1770c022016-03-14 14:14:16 -04002897void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002898 if (pArguments->GetLength() != 1) {
2899 ThrowParamCountMismatchException(L"formNodes");
2900 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002901 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002902 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002903}
dsinclair5b36f0a2016-07-19 10:56:23 -07002904
Dan Sinclair1770c022016-03-14 14:14:16 -04002905void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002906 if (pArguments->GetLength() != 0) {
2907 ThrowParamCountMismatchException(L"remerge");
2908 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002909 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002910 m_pDocument->DoDataRemerge(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_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002914 if (pArguments->GetLength() != 0) {
2915 ThrowParamCountMismatchException(L"execInitialize");
2916 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002917 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002918
2919 CXFA_WidgetData* pWidgetData = GetWidgetData();
2920 if (!pWidgetData) {
2921 pArguments->GetReturnValue()->SetBoolean(false);
2922 return;
2923 }
2924 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002925}
dsinclair5b36f0a2016-07-19 10:56:23 -07002926
Dan Sinclair1770c022016-03-14 14:14:16 -04002927void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2928 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002929 if (argc <= 0 || argc >= 4) {
2930 ThrowParamCountMismatchException(L"createNode");
2931 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002932 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002933
2934 CFX_WideString strName;
2935 CFX_WideString strNameSpace;
2936 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
2937 CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
2938 if (argc > 1) {
2939 CFX_ByteString bsName = pArguments->GetUTF8String(1);
2940 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
2941 if (argc == 3) {
2942 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
2943 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
2944 }
2945 }
2946
2947 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2948 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
2949 if (!pNewNode) {
2950 pArguments->GetReturnValue()->SetNull();
2951 return;
2952 }
2953
2954 if (strName.IsEmpty()) {
2955 pArguments->GetReturnValue()->Assign(
2956 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2957 return;
2958 }
2959
2960 if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2961 XFA_XDPPACKET_UNKNOWN)) {
2962 ThrowMissingPropertyException(strTagName, L"name");
2963 return;
2964 }
2965
2966 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
2967 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets)
2968 pNewNode->CreateXMLMappingNode();
2969
2970 pArguments->GetReturnValue()->Assign(
2971 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002972}
dsinclair5b36f0a2016-07-19 10:56:23 -07002973
Dan Sinclair1770c022016-03-14 14:14:16 -04002974void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002975 if (pArguments->GetLength() != 1) {
2976 ThrowParamCountMismatchException(L"recalculate");
2977 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002978 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002979 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_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002983 if (pArguments->GetLength() != 0) {
2984 ThrowParamCountMismatchException(L"execCalculate");
2985 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002986 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002987
2988 CXFA_WidgetData* pWidgetData = GetWidgetData();
2989 if (!pWidgetData) {
2990 pArguments->GetReturnValue()->SetBoolean(false);
2991 return;
2992 }
2993 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002994}
dsinclair5b36f0a2016-07-19 10:56:23 -07002995
Dan Sinclair1770c022016-03-14 14:14:16 -04002996void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002997 if (pArguments->GetLength() != 0) {
2998 ThrowParamCountMismatchException(L"execValidate");
2999 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003000 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003001 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
Dan Sinclair1770c022016-03-14 14:14:16 -04003009void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003010 if (pArguments->GetLength() != 0) {
3011 ThrowParamCountMismatchException(L"evaluate");
3012 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003013 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003014
3015 CXFA_WidgetData* pWidgetData = GetWidgetData();
3016 if (!pWidgetData) {
3017 pArguments->GetReturnValue()->SetBoolean(false);
3018 return;
3019 }
3020 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003021}
dsinclair5b36f0a2016-07-19 10:56:23 -07003022
dsinclair12a6b0c2016-05-26 11:14:08 -07003023void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003024 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003025 XFA_ATTRIBUTE eAttribute) {
3026 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003027 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003028 return;
3029 }
3030 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003031 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003032}
dsinclair5b36f0a2016-07-19 10:56:23 -07003033
dsinclair12a6b0c2016-05-26 11:14:08 -07003034void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003035 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003036 XFA_ATTRIBUTE eAttribute) {
3037 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003038 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003039 return;
3040 }
3041 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003042 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003043}
tsepezaadedf92016-05-12 10:08:06 -07003044
dsinclair12a6b0c2016-05-26 11:14:08 -07003045void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003046 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003047 XFA_ATTRIBUTE eAttribute) {
3048 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003049 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003050 InstanceManager_SetInstances(iDesired);
3051 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07003052 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04003053 }
3054}
dsinclair5b36f0a2016-07-19 10:56:23 -07003055
Dan Sinclair1770c022016-03-14 14:14:16 -04003056void CXFA_Node::Script_InstanceManager_MoveInstance(
3057 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003058 if (pArguments->GetLength() != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003059 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003060 return;
3061 }
3062 int32_t iFrom = pArguments->GetInt32(0);
3063 int32_t iTo = pArguments->GetInt32(1);
3064 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003065 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003066 if (!pNotify) {
3067 return;
3068 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003069 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003070 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003071 pNotify->RunSubformIndexChange(pToInstance);
3072 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003073 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003074 if (pFromInstance &&
3075 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003076 pNotify->RunSubformIndexChange(pFromInstance);
3077 }
3078}
dsinclair5b36f0a2016-07-19 10:56:23 -07003079
Dan Sinclair1770c022016-03-14 14:14:16 -04003080void CXFA_Node::Script_InstanceManager_RemoveInstance(
3081 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003082 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003083 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003084 return;
3085 }
3086 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003087 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003088 if (iIndex < 0 || iIndex >= iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003089 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003090 return;
3091 }
3092 CXFA_Occur nodeOccur(GetOccurNode());
3093 int32_t iMin = nodeOccur.GetMin();
3094 if (iCount - 1 < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003095 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003096 return;
3097 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003098 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3099 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003100 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003101 if (pNotify) {
3102 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003103 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003104 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003105 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003106 pNotify->RunSubformIndexChange(pSubformInstance);
3107 }
3108 }
3109 }
3110 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3111 if (!pLayoutPro) {
3112 return;
3113 }
3114 pLayoutPro->AddChangedContainer(
3115 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3116}
dsinclair5b36f0a2016-07-19 10:56:23 -07003117
Dan Sinclair1770c022016-03-14 14:14:16 -04003118void CXFA_Node::Script_InstanceManager_SetInstances(
3119 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003120 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003121 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003122 return;
3123 }
3124 int32_t iDesired = pArguments->GetInt32(0);
3125 InstanceManager_SetInstances(iDesired);
3126}
dsinclair5b36f0a2016-07-19 10:56:23 -07003127
Dan Sinclair1770c022016-03-14 14:14:16 -04003128void CXFA_Node::Script_InstanceManager_AddInstance(
3129 CFXJSE_Arguments* pArguments) {
3130 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003131 if (argc != 0 && argc != 1) {
3132 ThrowParamCountMismatchException(L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003133 return;
3134 }
tsepezd19e9122016-11-02 15:43:18 -07003135 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003136 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003137 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003138 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003139 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003140 CXFA_Occur nodeOccur(GetOccurNode());
3141 int32_t iMax = nodeOccur.GetMax();
3142 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003143 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003144 return;
3145 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003146 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003147 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003148 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003149 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003150 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003151 if (!pNotify) {
3152 return;
3153 }
3154 pNotify->RunNodeInitialize(pNewInstance);
3155 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3156 if (!pLayoutPro) {
3157 return;
3158 }
3159 pLayoutPro->AddChangedContainer(
3160 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3161}
dsinclair5b36f0a2016-07-19 10:56:23 -07003162
Dan Sinclair1770c022016-03-14 14:14:16 -04003163void CXFA_Node::Script_InstanceManager_InsertInstance(
3164 CFXJSE_Arguments* pArguments) {
3165 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003166 if (argc != 1 && argc != 2) {
3167 ThrowParamCountMismatchException(L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003168 return;
3169 }
3170 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003171 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003172 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003173 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003174 }
3175 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003176 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003177 if (iIndex < 0 || iIndex > iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003178 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003179 return;
3180 }
3181 int32_t iMax = nodeOccur.GetMax();
3182 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003183 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003184 return;
3185 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003186 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003187 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003188 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003189 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003190 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003191 if (!pNotify) {
3192 return;
3193 }
3194 pNotify->RunNodeInitialize(pNewInstance);
3195 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3196 if (!pLayoutPro) {
3197 return;
3198 }
3199 pLayoutPro->AddChangedContainer(
3200 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3201}
dsinclair5b36f0a2016-07-19 10:56:23 -07003202
Dan Sinclair1770c022016-03-14 14:14:16 -04003203int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3204 CXFA_Occur nodeOccur(GetOccurNode());
3205 int32_t iMax = nodeOccur.GetMax();
3206 int32_t iMin = nodeOccur.GetMin();
3207 if (iDesired < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003208 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003209 return 1;
3210 }
3211 if ((iMax >= 0) && (iDesired > iMax)) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003212 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003213 return 2;
3214 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003215 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003216 if (iDesired == iCount) {
3217 return 0;
3218 }
3219 if (iDesired < iCount) {
3220 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003221 CFX_WideString wsInstanceName =
3222 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3223 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003224 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003225 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003226 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003227 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003228 while (iCount > iDesired) {
3229 CXFA_Node* pRemoveInstance =
3230 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003231 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3232 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003233 continue;
3234 }
dsinclair070fcdf2016-06-22 22:04:54 -07003235 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003236 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003237 break;
3238 }
3239 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003240 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003241 iCount--;
3242 }
3243 }
3244 } else if (iDesired > iCount) {
3245 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003246 CXFA_Node* pNewInstance = CreateInstance(this, true);
3247 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003248 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003249 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003250 if (!pNotify) {
3251 return 0;
3252 }
3253 pNotify->RunNodeInitialize(pNewInstance);
3254 }
3255 }
3256 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3257 if (pLayoutPro) {
3258 pLayoutPro->AddChangedContainer(
3259 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3260 }
3261 return 0;
3262}
dsinclair5b36f0a2016-07-19 10:56:23 -07003263
Dan Sinclair1770c022016-03-14 14:14:16 -04003264int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003265 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003266 if (iFrom > iCount || iTo > iCount - 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003267 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003268 return 1;
3269 }
3270 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3271 return 0;
3272 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003273 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003274 RemoveItem(this, pMoveInstance, false);
3275 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003276 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3277 if (pLayoutPro) {
3278 pLayoutPro->AddChangedContainer(
3279 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3280 }
3281 return 0;
3282}
dsinclair5b36f0a2016-07-19 10:56:23 -07003283
dsinclair12a6b0c2016-05-26 11:14:08 -07003284void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003285 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003286 XFA_ATTRIBUTE eAttribute) {
3287 CXFA_Occur occur(this);
3288 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003289 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003290 occur.SetMax(iMax);
3291 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003292 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003293 }
3294}
dsinclair5b36f0a2016-07-19 10:56:23 -07003295
dsinclair12a6b0c2016-05-26 11:14:08 -07003296void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003297 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003298 XFA_ATTRIBUTE eAttribute) {
3299 CXFA_Occur occur(this);
3300 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003301 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003302 occur.SetMin(iMin);
3303 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003304 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003305 }
3306}
dsinclair5b36f0a2016-07-19 10:56:23 -07003307
Dan Sinclair1770c022016-03-14 14:14:16 -04003308void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3309 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003310 if (argc != 0 && argc != 1) {
3311 ThrowParamCountMismatchException(L"metadata");
3312 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003313 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003314 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003315}
dsinclair5b36f0a2016-07-19 10:56:23 -07003316
Dan Sinclair1770c022016-03-14 14:14:16 -04003317void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003318 if (pArguments->GetLength() != 1) {
3319 ThrowParamCountMismatchException(L"formNodes");
3320 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003321 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003322
3323 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3324 if (!pDataNode) {
3325 ThrowArgumentMismatchException();
3326 return;
3327 }
3328
3329 CXFA_NodeArray formItems;
3330 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3331 pFormNodes->SetArrayNodeList(formItems);
3332 pArguments->GetReturnValue()->SetObject(
3333 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003334}
dsinclair5b36f0a2016-07-19 10:56:23 -07003335
Dan Sinclair1770c022016-03-14 14:14:16 -04003336void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003337 if (pArguments->GetLength() != 0) {
3338 ThrowParamCountMismatchException(L"remerge");
3339 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003340 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003341
3342 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003343}
dsinclair5b36f0a2016-07-19 10:56:23 -07003344
Dan Sinclair1770c022016-03-14 14:14:16 -04003345void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003346 if (pArguments->GetLength() != 0) {
3347 ThrowParamCountMismatchException(L"execInitialize");
3348 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003349 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003350
3351 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3352 if (!pNotify)
3353 return;
3354
3355 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04003356}
dsinclair5b36f0a2016-07-19 10:56:23 -07003357
Dan Sinclair1770c022016-03-14 14:14:16 -04003358void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3359 CXFA_EventParam* pEventParam =
3360 m_pDocument->GetScriptContext()->GetEventParam();
3361 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3362 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3363 return;
3364 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003365 if (pArguments->GetLength() != 1) {
3366 ThrowParamCountMismatchException(L"recalculate");
3367 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003368 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003369
3370 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3371 if (!pNotify)
3372 return;
3373 if (pArguments->GetInt32(0) != 0)
3374 return;
3375
3376 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3377 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3378 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003379}
dsinclair5b36f0a2016-07-19 10:56:23 -07003380
Dan Sinclair1770c022016-03-14 14:14:16 -04003381void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003382 if (pArguments->GetLength() != 0) {
3383 ThrowParamCountMismatchException(L"execCalculate");
3384 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003385 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003386
3387 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3388 if (!pNotify)
3389 return;
3390
3391 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04003392}
dsinclair5b36f0a2016-07-19 10:56:23 -07003393
Dan Sinclair1770c022016-03-14 14:14:16 -04003394void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003395 if (pArguments->GetLength() != 0) {
3396 ThrowParamCountMismatchException(L"execValidate");
3397 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003398 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003399
3400 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3401 if (!pNotify) {
3402 pArguments->GetReturnValue()->SetBoolean(false);
3403 return;
3404 }
3405
3406 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3407 pArguments->GetReturnValue()->SetBoolean(
3408 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003409}
dsinclair5b36f0a2016-07-19 10:56:23 -07003410
dsinclair12a6b0c2016-05-26 11:14:08 -07003411void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003412 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003413 XFA_ATTRIBUTE eAttribute) {
3414 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003415 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003416 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003417 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003418
3419 CFX_WideString wsChecksum;
3420 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
3421 pValue->SetString(
3422 FX_UTF8Encode(wsChecksum.c_str(), wsChecksum.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003423}
dsinclair5b36f0a2016-07-19 10:56:23 -07003424
Dan Sinclair1770c022016-03-14 14:14:16 -04003425void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003426 if (pArguments->GetLength() != 1) {
3427 ThrowParamCountMismatchException(L"getAttribute");
3428 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003429 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003430
3431 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3432 CFX_WideString wsAttributeValue;
3433 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3434 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3435 static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3436 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(),
3437 wsAttributeValue);
3438 }
3439 pArguments->GetReturnValue()->SetString(
3440 FX_UTF8Encode(wsAttributeValue.c_str(), wsAttributeValue.GetLength())
3441 .AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003442}
dsinclair5b36f0a2016-07-19 10:56:23 -07003443
Dan Sinclair1770c022016-03-14 14:14:16 -04003444void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003445 if (pArguments->GetLength() != 2) {
3446 ThrowParamCountMismatchException(L"setAttribute");
3447 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003448 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003449
3450 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3451 CFX_ByteString bsName = pArguments->GetUTF8String(1);
3452 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3453 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3454 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(
3455 CFX_WideString::FromUTF8(bsName.AsStringC()),
3456 CFX_WideString::FromUTF8(bsValue.AsStringC()));
3457 }
3458 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003459}
dsinclair5b36f0a2016-07-19 10:56:23 -07003460
Dan Sinclair1770c022016-03-14 14:14:16 -04003461void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003462 if (pArguments->GetLength() != 1) {
3463 ThrowParamCountMismatchException(L"removeAttribute");
3464 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003465 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003466
3467 CFX_ByteString bsName = pArguments->GetUTF8String(0);
3468 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
3469 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3470 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3471 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
3472 if (pXMLElement->HasAttribute(wsName.c_str())) {
3473 pXMLElement->RemoveAttribute(wsName.c_str());
3474 }
3475 }
3476 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003477}
dsinclair5b36f0a2016-07-19 10:56:23 -07003478
dsinclair12a6b0c2016-05-26 11:14:08 -07003479void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003480 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003481 XFA_ATTRIBUTE eAttribute) {
3482 if (bSetting) {
dsinclairae95f762016-03-29 16:58:29 -07003483 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003484 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003485 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003486 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003487 }
3488 } else {
3489 CFX_WideString wsTextData;
dsinclairae95f762016-03-29 16:58:29 -07003490 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003491 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003492 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04003493 pXMLElement->GetTextData(wsTextData);
3494 }
dsinclairf27aeec2016-06-07 19:36:18 -07003495 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003496 FX_UTF8Encode(wsTextData.c_str(), wsTextData.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003497 }
3498}
dsinclair5b36f0a2016-07-19 10:56:23 -07003499
Dan Sinclair1770c022016-03-14 14:14:16 -04003500void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003501 if (pArguments->GetLength() != 0)
3502 ThrowParamCountMismatchException(L"next");
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_CancelBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003506 if (pArguments->GetLength() != 0)
3507 ThrowParamCountMismatchException(L"cancelBatch");
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_First(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003511 if (pArguments->GetLength() != 0)
3512 ThrowParamCountMismatchException(L"first");
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_UpdateBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003516 if (pArguments->GetLength() != 0)
3517 ThrowParamCountMismatchException(L"updateBatch");
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_Previous(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003521 if (pArguments->GetLength() != 0)
3522 ThrowParamCountMismatchException(L"previous");
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_IsBOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003526 if (pArguments->GetLength() != 0)
3527 ThrowParamCountMismatchException(L"isBOF");
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_IsEOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003531 if (pArguments->GetLength() != 0)
3532 ThrowParamCountMismatchException(L"isEOF");
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_Cancel(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003536 if (pArguments->GetLength() != 0)
3537 ThrowParamCountMismatchException(L"cancel");
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_Update(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003541 if (pArguments->GetLength() != 0)
3542 ThrowParamCountMismatchException(L"update");
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_Open(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003546 if (pArguments->GetLength() != 0)
3547 ThrowParamCountMismatchException(L"open");
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_Delete(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003551 if (pArguments->GetLength() != 0)
3552 ThrowParamCountMismatchException(L"delete");
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_AddNew(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003556 if (pArguments->GetLength() != 0)
3557 ThrowParamCountMismatchException(L"addNew");
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_Requery(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003561 if (pArguments->GetLength() != 0)
3562 ThrowParamCountMismatchException(L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003563}
dsinclair5b36f0a2016-07-19 10:56:23 -07003564
Dan Sinclair1770c022016-03-14 14:14:16 -04003565void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003566 if (pArguments->GetLength() != 0)
3567 ThrowParamCountMismatchException(L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003568}
dsinclair5b36f0a2016-07-19 10:56:23 -07003569
Dan Sinclair1770c022016-03-14 14:14:16 -04003570void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003571 if (pArguments->GetLength() != 0)
3572 ThrowParamCountMismatchException(L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003573}
dsinclair5b36f0a2016-07-19 10:56:23 -07003574
Dan Sinclair1770c022016-03-14 14:14:16 -04003575void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003576 if (pArguments->GetLength() != 0)
3577 ThrowParamCountMismatchException(L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003578}
dsinclair5b36f0a2016-07-19 10:56:23 -07003579
Dan Sinclair1770c022016-03-14 14:14:16 -04003580void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003581 if (pArguments->GetLength() != 0)
3582 ThrowParamCountMismatchException(L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003583}
dsinclair5b36f0a2016-07-19 10:56:23 -07003584
dsinclair12a6b0c2016-05-26 11:14:08 -07003585void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003586 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003587 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003588
dsinclair12a6b0c2016-05-26 11:14:08 -07003589void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003590 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003591 XFA_ATTRIBUTE eAttribute) {
3592 if (!bSetting) {
3593 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003594 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003595 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003596 }
3597}
dsinclair5b36f0a2016-07-19 10:56:23 -07003598
dsinclair12a6b0c2016-05-26 11:14:08 -07003599void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003600 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003601 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003602
dsinclair12a6b0c2016-05-26 11:14:08 -07003603void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003604 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003605 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003606
dsinclair12a6b0c2016-05-26 11:14:08 -07003607void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003608 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003609 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003610
dsinclair12a6b0c2016-05-26 11:14:08 -07003611void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003612 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003613 XFA_ATTRIBUTE eAttribute) {
3614 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003615 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003616 return;
3617 }
dan sinclair65c7c232017-02-02 14:05:30 -08003618 pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003619}
dsinclair5b36f0a2016-07-19 10:56:23 -07003620
dsinclair12a6b0c2016-05-26 11:14:08 -07003621void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003622 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003623 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003624
tsepezd19e9122016-11-02 15:43:18 -07003625bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003626 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003627 return HasMapModuleKey(pKey, bCanInherit);
3628}
dsinclair5b36f0a2016-07-19 10:56:23 -07003629
tsepezd19e9122016-11-02 15:43:18 -07003630bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3631 const CFX_WideStringC& wsValue,
3632 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003633 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003634 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003635 return false;
weili44f8faf2016-06-01 14:03:56 -07003636
Dan Sinclair1770c022016-03-14 14:14:16 -04003637 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3638 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3639 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003640 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003641 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3642 }
3643 switch (eType) {
3644 case XFA_ATTRIBUTETYPE_Enum: {
3645 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3646 return SetEnum(pAttr->eName,
3647 pEnum ? pEnum->eName
3648 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3649 bNotify);
3650 } break;
3651 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003652 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003653 case XFA_ATTRIBUTETYPE_Boolean:
dan sinclair65c7c232017-02-02 14:05:30 -08003654 return SetBoolean(pAttr->eName, wsValue != L"0", bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003655 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003656 return SetInteger(pAttr->eName,
3657 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3658 wsValue.GetLength(), nullptr)),
3659 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003660 case XFA_ATTRIBUTETYPE_Measure:
3661 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3662 default:
3663 break;
3664 }
tsepezd19e9122016-11-02 15:43:18 -07003665 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003666}
dsinclair5b36f0a2016-07-19 10:56:23 -07003667
tsepezd19e9122016-11-02 15:43:18 -07003668bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3669 CFX_WideString& wsValue,
3670 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003671 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003672 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003673 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003674 }
3675 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3676 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3677 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003678 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003679 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3680 }
3681 switch (eType) {
3682 case XFA_ATTRIBUTETYPE_Enum: {
3683 XFA_ATTRIBUTEENUM eValue;
3684 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003685 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003686 }
dsinclair9eb0db12016-07-21 12:01:39 -07003687 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003688 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003689 } break;
3690 case XFA_ATTRIBUTETYPE_Cdata: {
3691 CFX_WideStringC wsValueC;
3692 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003693 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003694 }
3695 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003696 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003697 } break;
3698 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003699 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003700 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003701 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003702 }
dan sinclair65c7c232017-02-02 14:05:30 -08003703 wsValue = bValue ? L"1" : L"0";
tsepezd19e9122016-11-02 15:43:18 -07003704 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003705 } break;
3706 case XFA_ATTRIBUTETYPE_Integer: {
3707 int32_t iValue;
3708 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003709 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003710 }
3711 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003712 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003713 } break;
3714 case XFA_ATTRIBUTETYPE_Measure: {
3715 CXFA_Measurement mValue;
3716 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003717 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003718 }
3719 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003720 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003721 } break;
3722 default:
3723 break;
3724 }
tsepezd19e9122016-11-02 15:43:18 -07003725 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003726}
dsinclair5b36f0a2016-07-19 10:56:23 -07003727
tsepezd19e9122016-11-02 15:43:18 -07003728bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3729 const CFX_WideStringC& wsValue,
3730 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003731 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3732 if (pAttributeInfo) {
3733 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3734 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003735 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003736 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003737 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003738}
dsinclair5b36f0a2016-07-19 10:56:23 -07003739
tsepezd19e9122016-11-02 15:43:18 -07003740bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3741 CFX_WideString& wsValue,
3742 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003743 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3744 if (pAttributeInfo) {
3745 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3746 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003747 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003748 CFX_WideStringC wsValueC;
3749 if (GetMapModuleString(pKey, wsValueC)) {
3750 wsValue = wsValueC;
3751 }
tsepezd19e9122016-11-02 15:43:18 -07003752 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003753}
dsinclair5b36f0a2016-07-19 10:56:23 -07003754
tsepezd19e9122016-11-02 15:43:18 -07003755bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003756 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003757 RemoveMapModuleKey(pKey);
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::TryBoolean(XFA_ATTRIBUTE eAttr,
3762 bool& bValue,
3763 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003764 void* pValue = nullptr;
3765 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003766 return false;
tsepez478ed622016-10-27 14:32:33 -07003767 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003768 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003769}
dsinclair5b36f0a2016-07-19 10:56:23 -07003770
tsepezd19e9122016-11-02 15:43:18 -07003771bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3772 int32_t& iValue,
3773 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003774 void* pValue = nullptr;
3775 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003776 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003777 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003778 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003779}
dsinclair5b36f0a2016-07-19 10:56:23 -07003780
tsepezd19e9122016-11-02 15:43:18 -07003781bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3782 XFA_ATTRIBUTEENUM& eValue,
3783 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003784 void* pValue = nullptr;
3785 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003786 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003787 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003788 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003789}
thestigb1a59592016-04-14 18:29:56 -07003790
tsepezd19e9122016-11-02 15:43:18 -07003791bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3792 CXFA_Measurement mValue,
3793 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003794 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003795 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003796 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003797 OnChanged(eAttr, bNotify, false);
3798 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003799}
thestigb1a59592016-04-14 18:29:56 -07003800
tsepezd19e9122016-11-02 15:43:18 -07003801bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3802 CXFA_Measurement& mValue,
3803 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003804 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003805 void* pValue;
3806 int32_t iBytes;
3807 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
3808 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003809 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003810 }
3811 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003812 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003813 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
3814 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003815 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003816 }
tsepezd19e9122016-11-02 15:43:18 -07003817 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003818}
3819
3820CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3821 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003822 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003823}
3824
tsepezd19e9122016-11-02 15:43:18 -07003825bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3826 const CFX_WideString& wsValue,
3827 bool bNotify,
3828 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003829 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003830 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003831 if (eAttr == XFA_ATTRIBUTE_Value) {
3832 CFX_WideString* pClone = new CFX_WideString(wsValue);
3833 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3834 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003835 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003836 if (eAttr == XFA_ATTRIBUTE_Name)
3837 UpdateNameHash();
3838 }
thestigb1a59592016-04-14 18:29:56 -07003839 OnChanged(eAttr, bNotify, bScriptModify);
3840
3841 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3842 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003843 return true;
thestigb1a59592016-04-14 18:29:56 -07003844 }
3845
dsinclair070fcdf2016-06-22 22:04:54 -07003846 if (eAttr == XFA_ATTRIBUTE_Name &&
3847 (m_elementType == XFA_Element::DataValue ||
3848 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003849 return true;
thestigb1a59592016-04-14 18:29:56 -07003850 }
3851
3852 if (eAttr == XFA_ATTRIBUTE_Value) {
3853 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3854 switch (eXMLType) {
3855 case FDE_XMLNODE_Element:
3856 if (IsAttributeInXML()) {
3857 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003858 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3859 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003860 } else {
tsepezd19e9122016-11-02 15:43:18 -07003861 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003862 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3863 for (CXFA_Node* pChildDataNode =
3864 GetNodeItem(XFA_NODEITEM_FirstChild);
3865 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3866 XFA_NODEITEM_NextSibling)) {
3867 CXFA_NodeArray formNodes;
3868 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003869 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003870 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003871 }
3872 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003873 }
thestigb1a59592016-04-14 18:29:56 -07003874 if (bDeleteChildren) {
3875 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3876 }
3877 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3878 }
3879 break;
3880 case FDE_XMLNODE_Text:
3881 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3882 break;
3883 default:
dsinclair43854a52016-04-27 12:26:00 -07003884 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003885 }
tsepezd19e9122016-11-02 15:43:18 -07003886 return true;
thestigb1a59592016-04-14 18:29:56 -07003887 }
3888
3889 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3890 if (pInfo) {
dsinclair43854a52016-04-27 12:26:00 -07003891 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003892 CFX_WideString wsAttrName = pInfo->pName;
3893 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
dan sinclair65c7c232017-02-02 14:05:30 -08003894 wsAttrName = L"xfa:" + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003895 }
thestigb1a59592016-04-14 18:29:56 -07003896 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003897 }
tsepezd19e9122016-11-02 15:43:18 -07003898 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003899}
thestigb1a59592016-04-14 18:29:56 -07003900
tsepezd19e9122016-11-02 15:43:18 -07003901bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3902 const CFX_WideString& wsXMLValue,
3903 bool bNotify,
3904 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003905 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003906 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003907 CFX_WideString* pClone = new CFX_WideString(wsValue);
3908 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003909 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003910 if (IsNeedSavingXMLNode()) {
3911 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3912 switch (eXMLType) {
3913 case FDE_XMLNODE_Element:
3914 if (IsAttributeInXML()) {
dsinclairae95f762016-03-29 16:58:29 -07003915 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003916 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3917 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003918 } else {
tsepezd19e9122016-11-02 15:43:18 -07003919 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003920 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3921 for (CXFA_Node* pChildDataNode =
3922 GetNodeItem(XFA_NODEITEM_FirstChild);
3923 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3924 XFA_NODEITEM_NextSibling)) {
3925 CXFA_NodeArray formNodes;
3926 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003927 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003928 break;
3929 }
3930 }
3931 }
3932 if (bDeleteChildren) {
dsinclairae95f762016-03-29 16:58:29 -07003933 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003934 }
dsinclairae95f762016-03-29 16:58:29 -07003935 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003936 }
3937 break;
3938 case FDE_XMLNODE_Text:
dsinclairae95f762016-03-29 16:58:29 -07003939 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003940 break;
3941 default:
dsinclair43854a52016-04-27 12:26:00 -07003942 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003943 }
3944 }
tsepezd19e9122016-11-02 15:43:18 -07003945 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003946}
dsinclair5b36f0a2016-07-19 10:56:23 -07003947
tsepezd19e9122016-11-02 15:43:18 -07003948bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3949 CFX_WideString& wsValue,
3950 bool bUseDefault,
3951 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003952 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003953 if (eAttr == XFA_ATTRIBUTE_Value) {
3954 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3955 if (pStr) {
3956 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07003957 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003958 }
3959 } else {
3960 CFX_WideStringC wsValueC;
3961 if (GetMapModuleString(pKey, wsValueC)) {
3962 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003963 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003964 }
3965 }
3966 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003967 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003968 }
weili44f8faf2016-06-01 14:03:56 -07003969 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003970 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003971 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
3972 wsValue = (const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003973 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003974 }
tsepezd19e9122016-11-02 15:43:18 -07003975 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003976}
dsinclair5b36f0a2016-07-19 10:56:23 -07003977
tsepezd19e9122016-11-02 15:43:18 -07003978bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3979 CFX_WideStringC& wsValue,
3980 bool bUseDefault,
3981 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003982 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003983 if (eAttr == XFA_ATTRIBUTE_Value) {
3984 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3985 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07003986 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07003987 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003988 }
3989 } else {
3990 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003991 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003992 }
3993 }
3994 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003995 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003996 }
weili44f8faf2016-06-01 14:03:56 -07003997 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003998 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003999 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
4000 wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07004001 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004002 }
tsepezd19e9122016-11-02 15:43:18 -07004003 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004004}
dsinclair5b36f0a2016-07-19 10:56:23 -07004005
tsepezd19e9122016-11-02 15:43:18 -07004006bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
4007 void* pData,
4008 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004009 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004010 return SetUserData(pKey, pData, pCallbackInfo);
4011}
dsinclair5b36f0a2016-07-19 10:56:23 -07004012
tsepezd19e9122016-11-02 15:43:18 -07004013bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004014 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004015 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07004016 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04004017}
dsinclair5b36f0a2016-07-19 10:56:23 -07004018
tsepezd19e9122016-11-02 15:43:18 -07004019bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
4020 XFA_ATTRIBUTETYPE eType,
4021 void* pValue,
4022 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004023 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07004024 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004025 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07004026 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004027 if (IsNeedSavingXMLNode()) {
dsinclair43854a52016-04-27 12:26:00 -07004028 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004029 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
4030 if (pInfo) {
4031 switch (eType) {
4032 case XFA_ATTRIBUTETYPE_Enum:
dsinclairae95f762016-03-29 16:58:29 -07004033 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004034 ->SetString(
4035 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07004036 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04004037 ->pName);
4038 break;
4039 case XFA_ATTRIBUTETYPE_Boolean:
dsinclairae95f762016-03-29 16:58:29 -07004040 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07004041 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04004042 break;
4043 case XFA_ATTRIBUTETYPE_Integer:
dsinclairae95f762016-03-29 16:58:29 -07004044 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004045 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue);
4046 break;
4047 default:
dsinclair43854a52016-04-27 12:26:00 -07004048 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04004049 }
4050 }
4051 }
tsepezd19e9122016-11-02 15:43:18 -07004052 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004053}
dsinclair5b36f0a2016-07-19 10:56:23 -07004054
tsepezd19e9122016-11-02 15:43:18 -07004055bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
4056 XFA_ATTRIBUTETYPE eType,
4057 bool bUseDefault,
4058 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004059 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004060 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004061 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004062 }
4063 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004064 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004065 }
dsinclair070fcdf2016-06-22 22:04:54 -07004066 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004067 m_ePacket);
4068}
dsinclair5b36f0a2016-07-19 10:56:23 -07004069
tsepezd19e9122016-11-02 15:43:18 -07004070bool CXFA_Node::SetUserData(void* pKey,
4071 void* pData,
4072 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004073 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4074 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004075 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004076}
dsinclair5b36f0a2016-07-19 10:56:23 -07004077
tsepezd19e9122016-11-02 15:43:18 -07004078bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004079 int32_t iBytes = 0;
4080 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004081 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004082 }
4083 return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes);
4084}
dsinclair5b36f0a2016-07-19 10:56:23 -07004085
tsepezd19e9122016-11-02 15:43:18 -07004086bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4087 const CFX_WideString& wsXMLValue,
4088 bool bNotify,
4089 bool bScriptModify,
4090 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004091 CXFA_Node* pNode = nullptr;
4092 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004093 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004094 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004095 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004096 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004097 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004098 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004099 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004100 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004101 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004102 CXFA_Node* pBind = GetBindData();
4103 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004104 std::vector<CFX_WideString> wsSaveTextArray;
Dan Sinclair1770c022016-03-14 14:14:16 -04004105 int32_t iSize = 0;
4106 if (!wsContent.IsEmpty()) {
4107 int32_t iStart = 0;
4108 int32_t iLength = wsContent.GetLength();
4109 int32_t iEnd = wsContent.Find(L'\n', iStart);
4110 iEnd = (iEnd == -1) ? iLength : iEnd;
4111 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004112 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004113 iStart = iEnd + 1;
4114 if (iStart >= iLength) {
4115 break;
4116 }
4117 iEnd = wsContent.Find(L'\n', iStart);
4118 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004119 wsSaveTextArray.push_back(
4120 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004121 }
4122 }
tsepez51709be2016-12-08 10:55:57 -08004123 iSize = pdfium::CollectionSize<int32_t>(wsSaveTextArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04004124 }
4125 if (iSize == 0) {
4126 while (CXFA_Node* pChildNode =
4127 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4128 pBind->RemoveChild(pChildNode);
4129 }
4130 } else {
4131 CXFA_NodeArray valueNodes;
4132 int32_t iDatas = pBind->GetNodeList(
dsinclair56a8b192016-06-21 14:15:25 -07004133 valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004134 if (iDatas < iSize) {
4135 int32_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004136 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004137 while (iAddNodes-- > 0) {
4138 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004139 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004140 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004141 pValueNodes->CreateXMLMappingNode();
4142 pBind->InsertChild(pValueNodes);
4143 }
weili44f8faf2016-06-01 14:03:56 -07004144 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004145 } else if (iDatas > iSize) {
4146 int32_t iDelNodes = iDatas - iSize;
4147 while (iDelNodes-- > 0) {
4148 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4149 }
4150 }
4151 int32_t i = 0;
4152 for (CXFA_Node* pValueNode =
4153 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4154 pValueNode; pValueNode = pValueNode->GetNodeItem(
4155 XFA_NODEITEM_NextSibling)) {
4156 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004157 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004158 i++;
4159 }
4160 }
4161 CXFA_NodeArray nodeArray;
4162 pBind->GetBindItems(nodeArray);
4163 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004164 if (nodeArray[i] != this) {
4165 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004166 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004167 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004168 }
4169 }
4170 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004171 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004172 pNode = this;
4173 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004174 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004175 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004176 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004177 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004178 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004179 }
4180 pBindNode = GetBindData();
4181 if (pBindNode && bSyncData) {
4182 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004183 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004184 CXFA_NodeArray nodeArray;
4185 pBindNode->GetBindItems(nodeArray);
4186 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004187 if (nodeArray[i] != this) {
4188 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true,
tsepezd19e9122016-11-02 15:43:18 -07004189 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004190 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004191 }
4192 }
weili44f8faf2016-06-01 14:03:56 -07004193 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004194 break;
4195 }
dsinclairc5a8f212016-06-20 11:11:12 -07004196 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004197 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004198 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004199 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004200 if (wsContentType == L"text/html") {
4201 wsContentType = L"";
tsepez4c3debb2016-04-08 12:20:38 -07004202 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004203 }
4204 }
4205 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4206 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004207 pContentRawDataNode = CreateSamePacketNode(
dan sinclair65c7c232017-02-02 14:05:30 -08004208 (wsContentType == L"text/xml") ? XFA_Element::Sharpxml
4209 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004210 InsertChild(pContentRawDataNode);
4211 }
4212 return pContentRawDataNode->SetScriptContent(
4213 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4214 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004215 case XFA_ObjectType::NodeC:
4216 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004217 pNode = this;
4218 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004219 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004220 pNode = this;
4221 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4222 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4223 if (pParent) {
4224 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4225 }
dsinclair070fcdf2016-06-22 22:04:54 -07004226 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004227 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4228 if (pParent && pParent->IsContainerNode()) {
4229 pBindNode = pParent->GetBindData();
4230 if (pBindNode) {
4231 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004232 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004233 }
4234 }
4235 }
4236 }
4237 break;
4238 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004239 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004240 pNode = this;
4241 pBindNode = this;
4242 }
4243 break;
4244 }
4245 if (pNode) {
4246 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4247 if (pBindNode && bSyncData) {
4248 CXFA_NodeArray nodeArray;
4249 pBindNode->GetBindItems(nodeArray);
4250 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004251 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004252 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004253 }
4254 }
tsepezd19e9122016-11-02 15:43:18 -07004255 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004256 }
tsepezd19e9122016-11-02 15:43:18 -07004257 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004258}
dsinclair5b36f0a2016-07-19 10:56:23 -07004259
tsepezd19e9122016-11-02 15:43:18 -07004260bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4261 const CFX_WideString& wsXMLValue,
4262 bool bNotify,
4263 bool bScriptModify,
4264 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004265 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4266 bSyncData);
4267}
dsinclair5b36f0a2016-07-19 10:56:23 -07004268
tsepezd19e9122016-11-02 15:43:18 -07004269CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004270 CFX_WideString wsContent;
4271 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4272}
dsinclair5b36f0a2016-07-19 10:56:23 -07004273
Dan Sinclair1770c022016-03-14 14:14:16 -04004274CFX_WideString CXFA_Node::GetContent() {
4275 return GetScriptContent();
4276}
dsinclair5b36f0a2016-07-19 10:56:23 -07004277
tsepezd19e9122016-11-02 15:43:18 -07004278bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4279 bool bScriptModify,
4280 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004281 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004282 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004283 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004284 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004285 pNode = this;
4286 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004287 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004288 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004289 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004290 }
4291 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4292 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
dan sinclair65c7c232017-02-02 14:05:30 -08004293 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004294 }
4295 return pChildValue
4296 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004297 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004298 }
4299 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004300 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004301 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4302 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004303 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004304 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004305 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004306 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004307 if (wsContentType == L"text/html") {
dsinclair56a8b192016-06-21 14:15:25 -07004308 element = XFA_Element::SharpxHTML;
dan sinclair65c7c232017-02-02 14:05:30 -08004309 } else if (wsContentType == L"text/xml") {
dsinclair56a8b192016-06-21 14:15:25 -07004310 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004311 }
4312 }
4313 pContentRawDataNode = CreateSamePacketNode(element);
4314 InsertChild(pContentRawDataNode);
4315 }
4316 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4317 }
dsinclairc5a8f212016-06-20 11:11:12 -07004318 case XFA_ObjectType::NodeC:
4319 case XFA_ObjectType::NodeV:
4320 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004321 pNode = this;
4322 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004323 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004324 pNode = this;
4325 }
4326 break;
4327 }
4328 if (pNode) {
4329 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004330 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004331 if (pScriptContext) {
4332 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4333 }
4334 }
tsepezd19e9122016-11-02 15:43:18 -07004335 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004336 }
tsepezd19e9122016-11-02 15:43:18 -07004337 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004338}
dsinclair5b36f0a2016-07-19 10:56:23 -07004339
Dan Sinclair1770c022016-03-14 14:14:16 -04004340CXFA_Node* CXFA_Node::GetModelNode() {
4341 switch (GetPacketID()) {
4342 case XFA_XDPPACKET_XDP:
4343 return m_pDocument->GetRoot();
4344 case XFA_XDPPACKET_Config:
4345 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4346 case XFA_XDPPACKET_Template:
4347 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4348 case XFA_XDPPACKET_Form:
4349 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4350 case XFA_XDPPACKET_Datasets:
4351 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4352 case XFA_XDPPACKET_LocaleSet:
4353 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4354 case XFA_XDPPACKET_ConnectionSet:
4355 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4356 case XFA_XDPPACKET_SourceSet:
4357 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4358 case XFA_XDPPACKET_Xdc:
4359 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4360 default:
4361 return this;
4362 }
4363}
dsinclair5b36f0a2016-07-19 10:56:23 -07004364
tsepezd19e9122016-11-02 15:43:18 -07004365bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004366 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004367 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
dsinclairae95f762016-03-29 16:58:29 -07004368 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004369 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004370 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004371 }
dsinclairae95f762016-03-29 16:58:29 -07004372 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004373 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004374 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
dsinclairae95f762016-03-29 16:58:29 -07004375 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004376 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004377 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004378 }
4379 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004380 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004381 }
dsinclair070fcdf2016-06-22 22:04:54 -07004382 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004383 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4384 return XFA_FDEExtension_ResolveNamespaceQualifier(
dsinclairae95f762016-03-29 16:58:29 -07004385 static_cast<CFDE_XMLElement*>(pXMLNode),
4386 GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004387 }
dsinclairae95f762016-03-29 16:58:29 -07004388 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004389 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004390 } else {
4391 CXFA_Node* pModelNode = GetModelNode();
4392 return pModelNode->TryNamespace(wsNamespace);
4393 }
4394}
dsinclair5b36f0a2016-07-19 10:56:23 -07004395
Dan Sinclair1770c022016-03-14 14:14:16 -04004396CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004397 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004398 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004399 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004400 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004401 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004402 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004403 if (!pProperty || index >= pProperty->uOccur)
4404 return nullptr;
4405
Dan Sinclair1770c022016-03-14 14:14:16 -04004406 CXFA_Node* pNode = m_pChild;
4407 int32_t iCount = 0;
4408 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004409 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004410 iCount++;
4411 if (iCount > index) {
4412 return pNode;
4413 }
4414 }
4415 }
weili44f8faf2016-06-01 14:03:56 -07004416 if (!bCreateProperty)
4417 return nullptr;
4418
Dan Sinclair1770c022016-03-14 14:14:16 -04004419 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4420 pNode = m_pChild;
4421 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4422 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004423 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004424 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4425 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004426 }
4427 }
dsinclaira1b07722016-07-11 08:20:58 -07004428
Dan Sinclair1770c022016-03-14 14:14:16 -04004429 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004430 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004431 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004432 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004433 if (!pNewNode)
4434 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004435 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004436 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004437 }
4438 return pNewNode;
4439}
dsinclair5b36f0a2016-07-19 10:56:23 -07004440
tsepezd19e9122016-11-02 15:43:18 -07004441int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004442 CXFA_Node* pNode = m_pChild;
4443 int32_t iCount = 0;
4444 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004445 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004446 if (bOnlyChild) {
4447 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004448 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004449 if (pProperty) {
4450 continue;
4451 }
4452 }
4453 iCount++;
4454 }
4455 }
4456 return iCount;
4457}
dsinclair5b36f0a2016-07-19 10:56:23 -07004458
Dan Sinclair1770c022016-03-14 14:14:16 -04004459CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004460 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004461 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004462 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004463 CXFA_Node* pNode = m_pChild;
4464 int32_t iCount = 0;
4465 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004466 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004467 if (bOnlyChild) {
4468 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004469 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004470 if (pProperty) {
4471 continue;
4472 }
4473 }
4474 iCount++;
4475 if (iCount > index) {
4476 return pNode;
4477 }
4478 }
4479 }
weili44f8faf2016-06-01 14:03:56 -07004480 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004481}
dsinclair5b36f0a2016-07-19 10:56:23 -07004482
Dan Sinclair1770c022016-03-14 14:14:16 -04004483int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4484 ASSERT(!pNode->m_pNext);
4485 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004486 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004487 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004488 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004489
weili44f8faf2016-06-01 14:03:56 -07004490 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004491 if (index > 0) {
4492 return -1;
4493 }
4494 pNode->m_pNext = m_pChild;
4495 m_pChild = pNode;
4496 index = 0;
4497 } else if (index < 0) {
4498 m_pLastChild->m_pNext = pNode;
4499 } else {
4500 CXFA_Node* pPrev = m_pChild;
4501 int32_t iCount = 0;
4502 while (++iCount != index && pPrev->m_pNext) {
4503 pPrev = pPrev->m_pNext;
4504 }
4505 if (index > 0 && index != iCount) {
4506 return -1;
4507 }
4508 pNode->m_pNext = pPrev->m_pNext;
4509 pPrev->m_pNext = pNode;
4510 index = iCount;
4511 }
weili44f8faf2016-06-01 14:03:56 -07004512 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004513 m_pLastChild = pNode;
4514 }
4515 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004516 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004517 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004518 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004519 if (pNotify)
4520 pNotify->OnChildAdded(this);
4521
Dan Sinclair1770c022016-03-14 14:14:16 -04004522 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004523 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004524 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004525 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004526 }
4527 return index;
4528}
weili6e1ae862016-05-04 18:25:27 -07004529
tsepezd19e9122016-11-02 15:43:18 -07004530bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004531 if (!pNode || pNode->m_pParent ||
4532 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004533 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004534 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004535 }
tsepezd19e9122016-11-02 15:43:18 -07004536 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004537 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004538 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004539
4540 int32_t nIndex = -1;
4541 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004542 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004543 pNode->m_pNext = m_pChild;
4544 m_pChild = pNode;
4545 nIndex = 0;
4546 } else if (!pBeforeNode) {
4547 pNode->m_pNext = m_pLastChild->m_pNext;
4548 m_pLastChild->m_pNext = pNode;
4549 } else {
4550 nIndex = 1;
4551 CXFA_Node* pPrev = m_pChild;
4552 while (pPrev->m_pNext != pBeforeNode) {
4553 pPrev = pPrev->m_pNext;
4554 nIndex++;
4555 }
4556 pNode->m_pNext = pPrev->m_pNext;
4557 pPrev->m_pNext = pNode;
4558 }
weili44f8faf2016-06-01 14:03:56 -07004559 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004560 m_pLastChild = pNode;
4561 }
4562 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004563 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004564 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004565 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004566 if (pNotify)
4567 pNotify->OnChildAdded(this);
4568
Dan Sinclair1770c022016-03-14 14:14:16 -04004569 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004570 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004571 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004572 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004573 }
tsepezd19e9122016-11-02 15:43:18 -07004574 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004575}
dsinclair5b36f0a2016-07-19 10:56:23 -07004576
Dan Sinclair1770c022016-03-14 14:14:16 -04004577CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4578 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004579 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004580 }
4581 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4582 pSibling = pSibling->m_pNext) {
4583 if (pSibling->m_pNext == this) {
4584 return pSibling;
4585 }
4586 }
weili44f8faf2016-06-01 14:03:56 -07004587 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004588}
dsinclair5b36f0a2016-07-19 10:56:23 -07004589
tsepezd19e9122016-11-02 15:43:18 -07004590bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004591 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004592 ASSERT(false);
4593 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004594 }
4595 if (m_pChild == pNode) {
4596 m_pChild = pNode->m_pNext;
4597 if (m_pLastChild == pNode) {
4598 m_pLastChild = pNode->m_pNext;
4599 }
weili44f8faf2016-06-01 14:03:56 -07004600 pNode->m_pNext = nullptr;
4601 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004602 } else {
4603 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4604 pPrev->m_pNext = pNode->m_pNext;
4605 if (m_pLastChild == pNode) {
4606 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4607 }
weili44f8faf2016-06-01 14:03:56 -07004608 pNode->m_pNext = nullptr;
4609 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004610 }
weili44f8faf2016-06-01 14:03:56 -07004611 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004612 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004613 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004614 m_pDocument->AddPurgeNode(pNode);
4615 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4616 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004617 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4618 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004619 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07004620 CFDE_XMLElement* pXMLElement =
4621 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004622 CFX_WideStringC wsAttributeName =
4623 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004624 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004625 }
4626 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004627 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -07004628 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004629 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4630 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004631 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004632 }
4633 pNode->m_pXMLNode = pNewXMLElement;
4634 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4635 } else {
4636 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4637 }
dsinclairc5a8f212016-06-20 11:11:12 -07004638 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004639 }
tsepezd19e9122016-11-02 15:43:18 -07004640 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004641}
dsinclair5b36f0a2016-07-19 10:56:23 -07004642
Dan Sinclair1770c022016-03-14 14:14:16 -04004643CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004644 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
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::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004648 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); 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
dsinclair41cb62e2016-06-23 09:20:32 -07004657CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004658 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4659 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004660 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004661 return pNode;
4662 }
4663 }
weili44f8faf2016-06-01 14:03:56 -07004664 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004665}
dsinclair5b36f0a2016-07-19 10:56:23 -07004666
tsepez736f28a2016-03-25 14:19:51 -07004667CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004668 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4669 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4670 if (pNode->GetNameHash() == dwNameHash) {
4671 return pNode;
4672 }
4673 }
weili44f8faf2016-06-01 14:03:56 -07004674 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004675}
dsinclair5b36f0a2016-07-19 10:56:23 -07004676
Dan Sinclair1770c022016-03-14 14:14:16 -04004677CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4678 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004679 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004680}
dsinclair5b36f0a2016-07-19 10:56:23 -07004681
dsinclair41cb62e2016-06-23 09:20:32 -07004682CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004683 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4684 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004685 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004686 return pNode;
4687 }
4688 }
weili44f8faf2016-06-01 14:03:56 -07004689 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004690}
dsinclair5b36f0a2016-07-19 10:56:23 -07004691
Dan Sinclair1770c022016-03-14 14:14:16 -04004692int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004693 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004694 if (!pScriptContext) {
4695 return -1;
4696 }
4697 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4698}
dsinclair5b36f0a2016-07-19 10:56:23 -07004699
Dan Sinclair1770c022016-03-14 14:14:16 -04004700int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004701 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004702 if (!pScriptContext) {
4703 return -1;
4704 }
4705 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4706}
dsinclair5b36f0a2016-07-19 10:56:23 -07004707
Dan Sinclair1770c022016-03-14 14:14:16 -04004708void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004709 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004710 if (!pScriptContext) {
4711 return;
4712 }
4713 pScriptContext->GetSomExpression(this, wsSOMExpression);
4714}
dsinclair5b36f0a2016-07-19 10:56:23 -07004715
Dan Sinclair1770c022016-03-14 14:14:16 -04004716CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004717 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004718 if (m_ePacket == XFA_XDPPACKET_Form) {
4719 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004720 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004721 return pInstanceMgr;
4722 }
4723 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4724 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004725 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004726 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004727 pNode->m_dwNameHash != m_dwNameHash) {
4728 break;
4729 }
dsinclair56a8b192016-06-21 14:15:25 -07004730 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004731 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4732 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4733 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4734 wsInstName.Mid(1) == wsName) {
4735 pInstanceMgr = pNode;
4736 }
4737 break;
4738 }
4739 }
4740 }
4741 return pInstanceMgr;
4742}
dsinclair5b36f0a2016-07-19 10:56:23 -07004743
Dan Sinclair1770c022016-03-14 14:14:16 -04004744CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004745 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004746}
dsinclair5b36f0a2016-07-19 10:56:23 -07004747
dsinclairc5a8f212016-06-20 11:11:12 -07004748bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4749 if (m_uNodeFlags & dwFlag)
4750 return true;
4751 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4752 return m_pParent && m_pParent->HasFlag(dwFlag);
4753 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004754}
thestigb1a59592016-04-14 18:29:56 -07004755
4756void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004757 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004758 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004759 if (pNotify) {
4760 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004761 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004762 }
dsinclairc5a8f212016-06-20 11:11:12 -07004763 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004764}
thestigb1a59592016-04-14 18:29:56 -07004765
4766void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004767 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004768}
4769
tsepezd19e9122016-11-02 15:43:18 -07004770bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004771 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4772}
thestigb1a59592016-04-14 18:29:56 -07004773
4774void CXFA_Node::OnRemoved(bool bNotify) {
4775 if (!bNotify)
4776 return;
4777
dsinclaira1b07722016-07-11 08:20:58 -07004778 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004779 if (pNotify)
4780 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004781}
thestigb1a59592016-04-14 18:29:56 -07004782
4783void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004784 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004785 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004786 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004787 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004788 }
4789 }
4790}
thestigb1a59592016-04-14 18:29:56 -07004791
Dan Sinclair1770c022016-03-14 14:14:16 -04004792void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004793 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004794 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004795 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004796 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004797 }
4798}
thestigb1a59592016-04-14 18:29:56 -07004799
Dan Sinclair1770c022016-03-14 14:14:16 -04004800int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004801 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004802 int32_t iRet = XFA_EVENTERROR_NotExist;
4803 const XFA_ExecEventParaInfo* eventParaInfo =
4804 GetEventParaInfoByName(wsEventName);
4805 if (eventParaInfo) {
4806 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004807 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004808 if (!pNotify) {
4809 return iRet;
4810 }
4811 if (validFlags == 1) {
4812 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4813 } else if (validFlags == 2) {
4814 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004815 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004816 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004817 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004818 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004819 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004820 }
4821 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004822 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004823 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004824 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004825 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004826 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004827 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004828 }
4829 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004830 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004831 }
4832 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004833 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004834 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004835 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004836 }
4837 } else if (validFlags == 6) {
4838 CXFA_WidgetData* pWidgetData = GetWidgetData();
4839 if (pWidgetData) {
4840 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004841 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004842 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004843 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004844 }
4845 }
4846 } else if (validFlags == 7) {
4847 CXFA_WidgetData* pWidgetData = GetWidgetData();
4848 if (pWidgetData) {
4849 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004850 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004851 (!pWidgetData->IsListBox())) {
4852 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004853 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004854 }
4855 }
4856 }
4857 }
4858 return iRet;
4859}
dsinclair5b36f0a2016-07-19 10:56:23 -07004860
Dan Sinclair1770c022016-03-14 14:14:16 -04004861void CXFA_Node::UpdateNameHash() {
4862 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004863 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004864 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004865 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004866 wsName = GetCData(XFA_ATTRIBUTE_Name);
4867 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004868 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004869 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004870 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004871 }
4872}
dsinclair5b36f0a2016-07-19 10:56:23 -07004873
dsinclairae95f762016-03-29 16:58:29 -07004874CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004875 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004876 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
dsinclairae95f762016-03-29 16:58:29 -07004877 m_pXMLNode = new CFDE_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004878 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004879 }
4880 return m_pXMLNode;
4881}
dsinclair5b36f0a2016-07-19 10:56:23 -07004882
tsepezd19e9122016-11-02 15:43:18 -07004883bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004884 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004885 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004886}
4887
4888XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4889 if (!m_pMapModuleData)
4890 m_pMapModuleData = new XFA_MAPMODULEDATA;
4891 return m_pMapModuleData;
4892}
4893
4894XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4895 return m_pMapModuleData;
4896}
4897
4898void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4899 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004900 pModule->m_ValueMap[pKey] = pValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04004901}
4902
tsepezd19e9122016-11-02 15:43:18 -07004903bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
tsepez6bb3b892017-01-05 12:18:41 -08004904 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004905 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004906 if (pModule) {
4907 auto it = pModule->m_ValueMap.find(pKey);
4908 if (it != pModule->m_ValueMap.end()) {
4909 pValue = it->second;
4910 return true;
4911 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004912 }
tsepez6bb3b892017-01-05 12:18:41 -08004913 if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4914 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004915 }
tsepezd19e9122016-11-02 15:43:18 -07004916 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004917}
dsinclair5b36f0a2016-07-19 10:56:23 -07004918
Dan Sinclair1770c022016-03-14 14:14:16 -04004919void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004920 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair1770c022016-03-14 14:14:16 -04004921 wsValue.GetLength() * sizeof(FX_WCHAR));
4922}
dsinclair5b36f0a2016-07-19 10:56:23 -07004923
tsepezd19e9122016-11-02 15:43:18 -07004924bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004925 void* pValue;
4926 int32_t iBytes;
4927 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004928 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004929 }
4930 wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR));
tsepezd19e9122016-11-02 15:43:18 -07004931 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004932}
dsinclair5b36f0a2016-07-19 10:56:23 -07004933
Dan Sinclair1770c022016-03-14 14:14:16 -04004934void CXFA_Node::SetMapModuleBuffer(
4935 void* pKey,
4936 void* pValue,
4937 int32_t iBytes,
4938 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4939 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4940 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004941 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004942 pBuffer =
4943 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4944 } else if (pBuffer->iBytes != iBytes) {
4945 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4946 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4947 }
4948 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4949 sizeof(XFA_MAPDATABLOCK) + iBytes);
4950 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4951 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4952 }
weili44f8faf2016-06-01 14:03:56 -07004953 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04004954 return;
weili44f8faf2016-06-01 14:03:56 -07004955
Dan Sinclair1770c022016-03-14 14:14:16 -04004956 pBuffer->pCallbackInfo = pCallbackInfo;
4957 pBuffer->iBytes = iBytes;
4958 FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes);
4959}
dsinclair5b36f0a2016-07-19 10:56:23 -07004960
tsepezd19e9122016-11-02 15:43:18 -07004961bool CXFA_Node::GetMapModuleBuffer(void* pKey,
4962 void*& pValue,
4963 int32_t& iBytes,
4964 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07004965 XFA_MAPDATABLOCK* pBuffer = nullptr;
tsepez6bb3b892017-01-05 12:18:41 -08004966 for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004967 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004968 if (pModule) {
4969 auto it = pModule->m_BufferMap.find(pKey);
4970 if (it != pModule->m_BufferMap.end()) {
4971 pBuffer = it->second;
4972 break;
4973 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004974 }
tsepez6bb3b892017-01-05 12:18:41 -08004975 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4976 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004977 }
tsepez6bb3b892017-01-05 12:18:41 -08004978 if (!pBuffer)
tsepezd19e9122016-11-02 15:43:18 -07004979 return false;
tsepez6bb3b892017-01-05 12:18:41 -08004980
Dan Sinclair1770c022016-03-14 14:14:16 -04004981 pValue = pBuffer->GetData();
4982 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07004983 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004984}
dsinclair5b36f0a2016-07-19 10:56:23 -07004985
tsepezd19e9122016-11-02 15:43:18 -07004986bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
tsepez6bb3b892017-01-05 12:18:41 -08004987 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004988 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004989 if (pModule) {
4990 auto it1 = pModule->m_ValueMap.find(pKey);
4991 if (it1 != pModule->m_ValueMap.end())
4992 return true;
4993
4994 auto it2 = pModule->m_BufferMap.find(pKey);
4995 if (it2 != pModule->m_BufferMap.end())
4996 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004997 }
tsepez6bb3b892017-01-05 12:18:41 -08004998 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4999 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04005000 }
tsepezd19e9122016-11-02 15:43:18 -07005001 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005002}
dsinclair5b36f0a2016-07-19 10:56:23 -07005003
Dan Sinclair1770c022016-03-14 14:14:16 -04005004void CXFA_Node::RemoveMapModuleKey(void* pKey) {
5005 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
5006 if (!pModule)
5007 return;
5008
5009 if (pKey) {
tsepez6bb3b892017-01-05 12:18:41 -08005010 auto it = pModule->m_BufferMap.find(pKey);
5011 if (it != pModule->m_BufferMap.end()) {
5012 XFA_MAPDATABLOCK* pBuffer = it->second;
Dan Sinclair1770c022016-03-14 14:14:16 -04005013 if (pBuffer) {
tsepez6bb3b892017-01-05 12:18:41 -08005014 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
Dan Sinclair1770c022016-03-14 14:14:16 -04005015 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005016 FX_Free(pBuffer);
5017 }
tsepez6bb3b892017-01-05 12:18:41 -08005018 pModule->m_BufferMap.erase(it);
Dan Sinclair1770c022016-03-14 14:14:16 -04005019 }
tsepez6bb3b892017-01-05 12:18:41 -08005020 pModule->m_ValueMap.erase(pKey);
5021 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04005022 }
tsepez6bb3b892017-01-05 12:18:41 -08005023
5024 for (auto& pair : pModule->m_BufferMap) {
5025 XFA_MAPDATABLOCK* pBuffer = pair.second;
5026 if (pBuffer) {
5027 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
5028 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5029 FX_Free(pBuffer);
5030 }
5031 }
5032 pModule->m_BufferMap.clear();
5033 pModule->m_ValueMap.clear();
5034 delete pModule;
Dan Sinclair1770c022016-03-14 14:14:16 -04005035}
dsinclair5b36f0a2016-07-19 10:56:23 -07005036
tsepez6bb3b892017-01-05 12:18:41 -08005037void CXFA_Node::MergeAllData(void* pDstModule) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005038 XFA_MAPMODULEDATA* pDstModuleData =
5039 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
5040 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08005041 if (!pSrcModuleData)
Dan Sinclair1770c022016-03-14 14:14:16 -04005042 return;
tsepez6bb3b892017-01-05 12:18:41 -08005043
5044 for (const auto& pair : pSrcModuleData->m_ValueMap)
5045 pDstModuleData->m_ValueMap[pair.first] = pair.second;
5046
5047 for (const auto& pair : pSrcModuleData->m_BufferMap) {
5048 XFA_MAPDATABLOCK* pSrcBuffer = pair.second;
5049 XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first];
Dan Sinclair1770c022016-03-14 14:14:16 -04005050 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
5051 !pSrcBuffer->pCallbackInfo->pCopy) {
tsepez6bb3b892017-01-05 12:18:41 -08005052 if (pDstBuffer) {
5053 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
5054 pDstModuleData->m_BufferMap.erase(pair.first);
Dan Sinclair1770c022016-03-14 14:14:16 -04005055 }
5056 continue;
5057 }
tsepez6bb3b892017-01-05 12:18:41 -08005058 if (!pDstBuffer) {
5059 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
Dan Sinclair1770c022016-03-14 14:14:16 -04005060 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08005061 } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) {
5062 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5063 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005064 }
tsepez6bb3b892017-01-05 12:18:41 -08005065 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
5066 uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5067 } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5068 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005069 }
tsepez6bb3b892017-01-05 12:18:41 -08005070 if (!pDstBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005071 continue;
5072 }
tsepez6bb3b892017-01-05 12:18:41 -08005073 pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5074 pDstBuffer->iBytes = pSrcBuffer->iBytes;
5075 FXSYS_memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(),
5076 pSrcBuffer->iBytes);
5077 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) {
5078 pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005079 }
5080 }
5081}
dsinclair5b36f0a2016-07-19 10:56:23 -07005082
Dan Sinclair1770c022016-03-14 14:14:16 -04005083void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5084 if (!pDstModule) {
5085 return;
5086 }
tsepezd19e9122016-11-02 15:43:18 -07005087 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005088 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005089 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005090 }
dsinclair070fcdf2016-06-22 22:04:54 -07005091 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005092 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005093 }
weili44f8faf2016-06-01 14:03:56 -07005094 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5095 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005096 if (bNeedMove) {
5097 pSrcModuleData = GetMapModuleData();
5098 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005099 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005100 }
5101 pDstModuleData = pDstModule->CreateMapModuleData();
5102 }
5103 if (bNeedMove) {
tsepez6bb3b892017-01-05 12:18:41 -08005104 auto it = pSrcModuleData->m_BufferMap.find(pKey);
5105 if (it != pSrcModuleData->m_BufferMap.end()) {
5106 XFA_MAPDATABLOCK* pBufferBlockData = it->second;
5107 if (pBufferBlockData) {
5108 pSrcModuleData->m_BufferMap.erase(pKey);
5109 pDstModuleData->m_BufferMap[pKey] = pBufferBlockData;
5110 }
Dan Sinclair1770c022016-03-14 14:14:16 -04005111 }
5112 }
dsinclairc5a8f212016-06-20 11:11:12 -07005113 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005114 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005115 CFX_WideString wsFormatValue(wsValue);
5116 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5117 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005118 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005119 }
tsepezd19e9122016-11-02 15:43:18 -07005120 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005121 }
5122}
dsinclair5b36f0a2016-07-19 10:56:23 -07005123
Dan Sinclair1770c022016-03-14 14:14:16 -04005124void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5125 CXFA_Node* pDstModule,
5126 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005127 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005128 if (!pSrcModule || !pDstModule || !pKey) {
5129 return;
5130 }
5131 if (bRecursive) {
5132 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5133 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5134 for (; pSrcChild && pDstChild;
5135 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5136 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005137 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005138 }
5139 }
5140 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5141}
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05005142
5143void CXFA_Node::ThrowMissingPropertyException(
5144 const CFX_WideString& obj,
5145 const CFX_WideString& prop) const {
5146 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(),
5147 prop.c_str());
5148}
5149
5150void CXFA_Node::ThrowTooManyOccurancesException(
5151 const CFX_WideString& obj) const {
5152 ThrowException(
5153 L"The element [%s] has violated its allowable number of occurrences.",
5154 obj.c_str());
5155}