blob: bc2a10c08b9d15aadf6ad7c657926d30e31a2cfe [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())
Tom Sepezd3743ea2016-05-16 15:56:53 -0700514 m_pXMLNode->Release();
Dan Sinclair1770c022016-03-14 14:14:16 -0400515}
weili44f8faf2016-06-01 14:03:56 -0700516
tsepezd19e9122016-11-02 15:43:18 -0700517CXFA_Node* CXFA_Node::Clone(bool bRecursive) {
dsinclaira1b07722016-07-11 08:20:58 -0700518 CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700519 if (!pClone)
520 return nullptr;
521
Dan Sinclair1770c022016-03-14 14:14:16 -0400522 MergeAllData(pClone);
523 pClone->UpdateNameHash();
524 if (IsNeedSavingXMLNode()) {
weili44f8faf2016-06-01 14:03:56 -0700525 CFDE_XMLNode* pCloneXML = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400526 if (IsAttributeInXML()) {
527 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -0700528 GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -0700529 CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -0400530 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
531 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -0700532 pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -0400533 }
534 pCloneXML = pCloneXMLElement;
weili44f8faf2016-06-01 14:03:56 -0700535 pCloneXMLElement = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400536 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
537 } else {
tsepezd19e9122016-11-02 15:43:18 -0700538 pCloneXML = m_pXMLNode->Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400539 }
540 pClone->SetXMLMappingNode(pCloneXML);
dsinclairc5a8f212016-06-20 11:11:12 -0700541 pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400542 }
543 if (bRecursive) {
544 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
545 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
546 pClone->InsertChild(pChild->Clone(bRecursive));
547 }
548 }
dsinclairc5a8f212016-06-20 11:11:12 -0700549 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
weili44f8faf2016-06-01 14:03:56 -0700550 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400551 return pClone;
552}
weili44f8faf2016-06-01 14:03:56 -0700553
Dan Sinclair1770c022016-03-14 14:14:16 -0400554CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
555 switch (eItem) {
556 case XFA_NODEITEM_NextSibling:
557 return m_pNext;
558 case XFA_NODEITEM_FirstChild:
559 return m_pChild;
560 case XFA_NODEITEM_Parent:
561 return m_pParent;
562 case XFA_NODEITEM_PrevSibling:
563 if (m_pParent) {
564 CXFA_Node* pSibling = m_pParent->m_pChild;
weili44f8faf2016-06-01 14:03:56 -0700565 CXFA_Node* pPrev = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400566 while (pSibling && pSibling != this) {
567 pPrev = pSibling;
568 pSibling = pSibling->m_pNext;
569 }
570 return pPrev;
571 }
weili44f8faf2016-06-01 14:03:56 -0700572 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400573 default:
574 break;
575 }
weili44f8faf2016-06-01 14:03:56 -0700576 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400577}
weili44f8faf2016-06-01 14:03:56 -0700578
Dan Sinclair1770c022016-03-14 14:14:16 -0400579CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
dsinclairc5a8f212016-06-20 11:11:12 -0700580 XFA_ObjectType eType) const {
weili44f8faf2016-06-01 14:03:56 -0700581 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400582 switch (eItem) {
583 case XFA_NODEITEM_NextSibling:
584 pNode = m_pNext;
dsinclairc5a8f212016-06-20 11:11:12 -0700585 while (pNode && pNode->GetObjectType() != eType)
586 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400587 break;
588 case XFA_NODEITEM_FirstChild:
589 pNode = m_pChild;
dsinclairc5a8f212016-06-20 11:11:12 -0700590 while (pNode && pNode->GetObjectType() != eType)
591 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400592 break;
593 case XFA_NODEITEM_Parent:
594 pNode = m_pParent;
dsinclairc5a8f212016-06-20 11:11:12 -0700595 while (pNode && pNode->GetObjectType() != eType)
596 pNode = pNode->m_pParent;
Dan Sinclair1770c022016-03-14 14:14:16 -0400597 break;
598 case XFA_NODEITEM_PrevSibling:
599 if (m_pParent) {
600 CXFA_Node* pSibling = m_pParent->m_pChild;
601 while (pSibling && pSibling != this) {
dsinclairc5a8f212016-06-20 11:11:12 -0700602 if (eType == pSibling->GetObjectType())
Dan Sinclair1770c022016-03-14 14:14:16 -0400603 pNode = pSibling;
dsinclairc5a8f212016-06-20 11:11:12 -0700604
Dan Sinclair1770c022016-03-14 14:14:16 -0400605 pSibling = pSibling->m_pNext;
606 }
607 }
608 break;
609 default:
610 break;
611 }
612 return pNode;
613}
weili44f8faf2016-06-01 14:03:56 -0700614
Dan Sinclair1770c022016-03-14 14:14:16 -0400615int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes,
tsepez736f28a2016-03-25 14:19:51 -0700616 uint32_t dwTypeFilter,
dsinclair41cb62e2016-06-23 09:20:32 -0700617 XFA_Element eTypeFilter,
Dan Sinclair1770c022016-03-14 14:14:16 -0400618 int32_t iLevel) {
619 if (--iLevel < 0) {
620 return nodes.GetSize();
621 }
dsinclair41cb62e2016-06-23 09:20:32 -0700622 if (eTypeFilter != XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400623 CXFA_Node* pChild = m_pChild;
624 while (pChild) {
dsinclair41cb62e2016-06-23 09:20:32 -0700625 if (pChild->GetElementType() == eTypeFilter) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400626 nodes.Add(pChild);
627 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700628 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400629 }
630 }
631 pChild = pChild->m_pNext;
632 }
633 } else if (dwTypeFilter ==
634 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
635 CXFA_Node* pChild = m_pChild;
636 while (pChild) {
637 nodes.Add(pChild);
638 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700639 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400640 }
641 pChild = pChild->m_pNext;
642 }
643 } else if (dwTypeFilter != 0) {
weili44f8faf2016-06-01 14:03:56 -0700644 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
645 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
646 bool bFilterOneOfProperties =
647 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
Dan Sinclair1770c022016-03-14 14:14:16 -0400648 CXFA_Node* pChild = m_pChild;
649 while (pChild) {
650 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -0700651 GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -0400652 if (pProperty) {
653 if (bFilterProperties) {
654 nodes.Add(pChild);
655 } else if (bFilterOneOfProperties &&
656 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
657 nodes.Add(pChild);
658 } else if (bFilterChildren &&
dsinclair070fcdf2016-06-22 22:04:54 -0700659 (pChild->GetElementType() == XFA_Element::Variables ||
660 pChild->GetElementType() == XFA_Element::PageSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400661 nodes.Add(pChild);
662 }
weili44f8faf2016-06-01 14:03:56 -0700663 } else if (bFilterChildren) {
664 nodes.Add(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400665 }
666 pChild = pChild->m_pNext;
667 }
668 if (bFilterOneOfProperties && nodes.GetSize() < 1) {
669 int32_t iProperties = 0;
670 const XFA_PROPERTY* pProperty =
dsinclair070fcdf2016-06-22 22:04:54 -0700671 XFA_GetElementProperties(GetElementType(), iProperties);
weili44f8faf2016-06-01 14:03:56 -0700672 if (!pProperty || iProperties < 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400673 return 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400674 for (int32_t i = 0; i < iProperties; i++) {
675 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400676 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
677 CXFA_Node* pNewNode =
dsinclaira1b07722016-07-11 08:20:58 -0700678 m_pDocument->CreateNode(pPacket, pProperty[i].eName);
weili44f8faf2016-06-01 14:03:56 -0700679 if (!pNewNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400680 break;
weili44f8faf2016-06-01 14:03:56 -0700681 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -0700682 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400683 nodes.Add(pNewNode);
684 break;
685 }
686 }
687 }
688 }
689 return nodes.GetSize();
690}
weili44f8faf2016-06-01 14:03:56 -0700691
dsinclair41cb62e2016-06-23 09:20:32 -0700692CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
tsepez736f28a2016-03-25 14:19:51 -0700693 uint32_t dwFlags) {
dsinclaira1b07722016-07-11 08:20:58 -0700694 CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
thestigb1a59592016-04-14 18:29:56 -0700695 pNode->SetFlag(dwFlags, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400696 return pNode;
697}
weili44f8faf2016-06-01 14:03:56 -0700698
tsepezd19e9122016-11-02 15:43:18 -0700699CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) {
dsinclair43854a52016-04-27 12:26:00 -0700700 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
dsinclaira1b07722016-07-11 08:20:58 -0700701 CXFA_Node* pClone =
702 m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700703 if (!pClone)
704 return nullptr;
705
Dan Sinclair1770c022016-03-14 14:14:16 -0400706 pClone->SetTemplateNode(this);
707 pClone->UpdateNameHash();
708 pClone->SetXMLMappingNode(GetXMLMappingNode());
709 if (bRecursive) {
710 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
711 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
712 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
713 }
714 }
dsinclairc5a8f212016-06-20 11:11:12 -0700715 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400716 return pClone;
717}
718
719CXFA_Node* CXFA_Node::GetTemplateNode() const {
720 return m_pAuxNode;
721}
722
723void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
724 m_pAuxNode = pTemplateNode;
725}
weili44f8faf2016-06-01 14:03:56 -0700726
Dan Sinclair1770c022016-03-14 14:14:16 -0400727CXFA_Node* CXFA_Node::GetBindData() {
728 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
729 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
730}
weili44f8faf2016-06-01 14:03:56 -0700731
Dan Sinclair1770c022016-03-14 14:14:16 -0400732int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) {
dsinclairc5a8f212016-06-20 11:11:12 -0700733 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700734 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400735 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
736 formItems.Copy(*pItems);
737 return formItems.GetSize();
738 }
739 CXFA_Node* pFormNode =
740 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
weili44f8faf2016-06-01 14:03:56 -0700741 if (pFormNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400742 formItems.Add(pFormNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400743 return formItems.GetSize();
744}
745
Dan Sinclair1770c022016-03-14 14:14:16 -0400746int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
747 ASSERT(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700748 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700749 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400750 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
751 ASSERT(pItems);
752 if (pItems->Find(pFormNode) < 0) {
753 pItems->Add(pFormNode);
754 }
755 return pItems->GetSize();
756 }
757 CXFA_Node* pOldFormItem =
758 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
759 if (!pOldFormItem) {
760 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
761 return 1;
762 } else if (pOldFormItem == pFormNode) {
763 return 1;
764 }
765 CXFA_NodeArray* pItems = new CXFA_NodeArray;
766 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
767 pItems->Add(pOldFormItem);
768 pItems->Add(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700769 m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400770 return 2;
771}
weili44f8faf2016-06-01 14:03:56 -0700772
Dan Sinclair1770c022016-03-14 14:14:16 -0400773int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
dsinclairc5a8f212016-06-20 11:11:12 -0700774 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700775 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400776 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
777 ASSERT(pItems);
778 int32_t iIndex = pItems->Find(pFormNode);
779 int32_t iCount = pItems->GetSize();
780 if (iIndex >= 0) {
weili44f8faf2016-06-01 14:03:56 -0700781 if (iIndex != iCount - 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400782 pItems->SetAt(iIndex, pItems->GetAt(iCount - 1));
Dan Sinclair1770c022016-03-14 14:14:16 -0400783 pItems->RemoveAt(iCount - 1);
784 if (iCount == 2) {
785 CXFA_Node* pLastFormNode = pItems->GetAt(0);
786 SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700787 m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400788 }
789 iCount--;
790 }
791 return iCount;
792 }
793 CXFA_Node* pOldFormItem =
794 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
795 if (pOldFormItem == pFormNode) {
weili44f8faf2016-06-01 14:03:56 -0700796 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
797 pOldFormItem = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400798 }
weili44f8faf2016-06-01 14:03:56 -0700799 return pOldFormItem ? 1 : 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400800}
weili44f8faf2016-06-01 14:03:56 -0700801
tsepezd19e9122016-11-02 15:43:18 -0700802bool CXFA_Node::HasBindItem() {
weili44f8faf2016-06-01 14:03:56 -0700803 return GetPacketID() == XFA_XDPPACKET_Datasets &&
804 GetObject(XFA_ATTRIBUTE_BindingNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400805}
weili44f8faf2016-06-01 14:03:56 -0700806
Dan Sinclair1770c022016-03-14 14:14:16 -0400807CXFA_WidgetData* CXFA_Node::GetWidgetData() {
808 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
809}
weili44f8faf2016-06-01 14:03:56 -0700810
Dan Sinclair1770c022016-03-14 14:14:16 -0400811CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
weili44f8faf2016-06-01 14:03:56 -0700812 if (GetPacketID() != XFA_XDPPACKET_Form)
813 return nullptr;
dsinclair41cb62e2016-06-23 09:20:32 -0700814 XFA_Element eType = GetElementType();
815 if (eType == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700816 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400817 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700818 if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700819 return nullptr;
820
dsinclair41cb62e2016-06-23 09:20:32 -0700821 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400822 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
823 if (pFieldWidgetData &&
824 pFieldWidgetData->GetChoiceListOpen() ==
825 XFA_ATTRIBUTEENUM_MultiSelect) {
weili44f8faf2016-06-01 14:03:56 -0700826 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400827 } else {
828 CFX_WideString wsPicture;
829 if (pFieldWidgetData) {
830 pFieldWidgetData->GetPictureContent(wsPicture,
831 XFA_VALUEPICTURE_DataBind);
832 }
weili44f8faf2016-06-01 14:03:56 -0700833 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400834 return pFieldWidgetData;
Dan Sinclair1770c022016-03-14 14:14:16 -0400835 CXFA_Node* pDataNode = GetBindData();
weili44f8faf2016-06-01 14:03:56 -0700836 if (!pDataNode)
837 return nullptr;
838 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400839 CXFA_NodeArray formNodes;
840 pDataNode->GetBindItems(formNodes);
841 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
842 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -0700843 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -0400844 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400845 pFieldWidgetData = pFormNode->GetWidgetData();
846 if (pFieldWidgetData) {
847 pFieldWidgetData->GetPictureContent(wsPicture,
848 XFA_VALUEPICTURE_DataBind);
849 }
weili44f8faf2016-06-01 14:03:56 -0700850 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400851 break;
weili44f8faf2016-06-01 14:03:56 -0700852 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400853 }
854 return pFieldWidgetData;
855 }
856 }
857 CXFA_Node* pGrandNode =
weili44f8faf2016-06-01 14:03:56 -0700858 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400859 CXFA_Node* pValueNode =
dsinclair070fcdf2016-06-22 22:04:54 -0700860 (pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
Dan Sinclair1770c022016-03-14 14:14:16 -0400861 ? pParentNode
weili44f8faf2016-06-01 14:03:56 -0700862 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400863 if (!pValueNode) {
dsinclair070fcdf2016-06-22 22:04:54 -0700864 pValueNode =
865 (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
866 ? pGrandNode
867 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400868 }
869 CXFA_Node* pParentOfValueNode =
weili44f8faf2016-06-01 14:03:56 -0700870 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400871 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
weili44f8faf2016-06-01 14:03:56 -0700872 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400873}
weili44f8faf2016-06-01 14:03:56 -0700874
tsepezd19e9122016-11-02 15:43:18 -0700875bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400876 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
dsinclair56a8b192016-06-21 14:15:25 -0700877 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
dsinclair43854a52016-04-27 12:26:00 -0700878 ASSERT(pTopSubform);
Dan Sinclair1770c022016-03-14 14:14:16 -0400879 CXFA_Node* pLocaleNode = this;
tsepezd19e9122016-11-02 15:43:18 -0700880 bool bLocale = false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400881 do {
tsepezd19e9122016-11-02 15:43:18 -0700882 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400883 if (!bLocale) {
884 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
885 }
886 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
weili44f8faf2016-06-01 14:03:56 -0700887 if (bLocale)
tsepezd19e9122016-11-02 15:43:18 -0700888 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400889 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
890 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
weili44f8faf2016-06-01 14:03:56 -0700891 if (!wsLocaleName.IsEmpty())
tsepezd19e9122016-11-02 15:43:18 -0700892 return true;
weili44f8faf2016-06-01 14:03:56 -0700893 if (pTopSubform &&
tsepezd19e9122016-11-02 15:43:18 -0700894 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) {
895 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400896 }
897 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
898 if (pLocale) {
899 wsLocaleName = pLocale->GetName();
tsepezd19e9122016-11-02 15:43:18 -0700900 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400901 }
tsepezd19e9122016-11-02 15:43:18 -0700902 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400903}
weili44f8faf2016-06-01 14:03:56 -0700904
Dan Sinclair1770c022016-03-14 14:14:16 -0400905XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
dsinclair56a8b192016-06-21 14:15:25 -0700906 CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
Dan Sinclair1770c022016-03-14 14:14:16 -0400907 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
908 if (pKeep) {
909 XFA_ATTRIBUTEENUM eIntact;
tsepezd19e9122016-11-02 15:43:18 -0700910 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400911 if (eIntact == XFA_ATTRIBUTEENUM_None &&
912 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
913 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
dsinclairc5a8f212016-06-20 11:11:12 -0700914 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
915 XFA_ObjectType::ContainerNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400916 if (pPreviewRow &&
917 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
918 XFA_ATTRIBUTEENUM_Row) {
919 XFA_ATTRIBUTEENUM eValue;
tsepezd19e9122016-11-02 15:43:18 -0700920 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700921 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
922 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
923 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400924 }
weili44f8faf2016-06-01 14:03:56 -0700925 CXFA_Node* pNode =
dsinclair56a8b192016-06-21 14:15:25 -0700926 pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
tsepezd19e9122016-11-02 15:43:18 -0700927 if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700928 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
929 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
930 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400931 }
932 }
933 }
934 return eIntact;
935 }
936 }
dsinclair41cb62e2016-06-23 09:20:32 -0700937 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700938 case XFA_Element::Subform:
Dan Sinclair1770c022016-03-14 14:14:16 -0400939 switch (eLayoutType) {
940 case XFA_ATTRIBUTEENUM_Position:
941 case XFA_ATTRIBUTEENUM_Row:
942 return XFA_ATTRIBUTEENUM_ContentArea;
943 case XFA_ATTRIBUTEENUM_Tb:
944 case XFA_ATTRIBUTEENUM_Table:
945 case XFA_ATTRIBUTEENUM_Lr_tb:
946 case XFA_ATTRIBUTEENUM_Rl_tb:
947 return XFA_ATTRIBUTEENUM_None;
948 default:
949 break;
950 }
951 break;
dsinclair56a8b192016-06-21 14:15:25 -0700952 case XFA_Element::Field: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400953 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700954 if (!pParentNode ||
955 pParentNode->GetElementType() == XFA_Element::PageArea)
Dan Sinclair1770c022016-03-14 14:14:16 -0400956 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400957 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
958 XFA_ATTRIBUTEENUM eParLayout =
959 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
960 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
961 eParLayout == XFA_ATTRIBUTEENUM_Row ||
962 eParLayout == XFA_ATTRIBUTEENUM_Table) {
963 return XFA_ATTRIBUTEENUM_None;
964 }
965 XFA_VERSION version = m_pDocument->GetCurVersionMode();
966 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
967 CXFA_Measurement measureH;
tsepezd19e9122016-11-02 15:43:18 -0700968 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false))
Dan Sinclair1770c022016-03-14 14:14:16 -0400969 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400970 }
971 return XFA_ATTRIBUTEENUM_None;
972 }
973 return XFA_ATTRIBUTEENUM_ContentArea;
974 }
dsinclair56a8b192016-06-21 14:15:25 -0700975 case XFA_Element::Draw:
Dan Sinclair1770c022016-03-14 14:14:16 -0400976 return XFA_ATTRIBUTEENUM_ContentArea;
977 default:
978 break;
979 }
980 return XFA_ATTRIBUTEENUM_None;
981}
weili44f8faf2016-06-01 14:03:56 -0700982
Dan Sinclair1770c022016-03-14 14:14:16 -0400983CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
weili44f8faf2016-06-01 14:03:56 -0700984 if (m_ePacket == XFA_XDPPACKET_Datasets)
Dan Sinclair1770c022016-03-14 14:14:16 -0400985 return m_pAuxNode;
weili44f8faf2016-06-01 14:03:56 -0700986 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400987}
weili44f8faf2016-06-01 14:03:56 -0700988
Dan Sinclair1770c022016-03-14 14:14:16 -0400989void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
dsinclair43854a52016-04-27 12:26:00 -0700990 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
Dan Sinclair1770c022016-03-14 14:14:16 -0400991 m_pAuxNode = pDataDescriptionNode;
992}
weili44f8faf2016-06-01 14:03:56 -0700993
Dan Sinclair1770c022016-03-14 14:14:16 -0400994void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
995 int32_t iLength = pArguments->GetLength();
996 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -0500997 ThrowParamCountMismatchException(L"resolveNode");
Dan Sinclair1770c022016-03-14 14:14:16 -0400998 return;
999 }
tsepez6fe7d212016-04-06 10:51:14 -07001000 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001001 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclairdf4bc592016-03-31 20:34:43 -07001002 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001003 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001004 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001005 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001006 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001007 refNode = ToNode(pScriptContext->GetThisObject());
tsepez736f28a2016-03-25 14:19:51 -07001008 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001009 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1010 XFA_RESOLVENODE_Siblings;
1011 XFA_RESOLVENODE_RS resoveNodeRS;
tsepezfc58ad12016-04-05 12:22:15 -07001012 int32_t iRet = pScriptContext->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001013 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
dsinclairf27aeec2016-06-07 19:36:18 -07001014 if (iRet < 1) {
1015 pArguments->GetReturnValue()->SetNull();
1016 return;
1017 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001018 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1019 CXFA_Object* pNode = resoveNodeRS.nodes[0];
dsinclairf27aeec2016-06-07 19:36:18 -07001020 pArguments->GetReturnValue()->Assign(
1021 pScriptContext->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001022 } else {
1023 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
1024 resoveNodeRS.pScriptAttribute;
1025 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
dsinclair86fad992016-05-31 11:34:04 -07001026 std::unique_ptr<CFXJSE_Value> pValue(
1027 new CFXJSE_Value(pScriptContext->GetRuntime()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001028 (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))(
tsepezd19e9122016-11-02 15:43:18 -07001029 pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
dsinclairf27aeec2016-06-07 19:36:18 -07001030 pArguments->GetReturnValue()->Assign(pValue.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001031 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001032 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001033 }
1034 }
1035}
weili44f8faf2016-06-01 14:03:56 -07001036
Dan Sinclair1770c022016-03-14 14:14:16 -04001037void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
1038 int32_t iLength = pArguments->GetLength();
1039 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001040 ThrowParamCountMismatchException(L"resolveNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04001041 return;
1042 }
tsepez6fe7d212016-04-06 10:51:14 -07001043 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001044 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclair12a6b0c2016-05-26 11:14:08 -07001045 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001046 if (!pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04001047 return;
tsepez736f28a2016-03-25 14:19:51 -07001048 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001049 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1050 XFA_RESOLVENODE_Siblings;
1051 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001052 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001053 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
dsinclair12a6b0c2016-05-26 11:14:08 -07001054 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001055}
weili44f8faf2016-06-01 14:03:56 -07001056
dsinclair12a6b0c2016-05-26 11:14:08 -07001057void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001058 CFX_WideString wsExpression,
tsepez736f28a2016-03-25 14:19:51 -07001059 uint32_t dwFlag,
Dan Sinclair1770c022016-03-14 14:14:16 -04001060 CXFA_Node* refNode) {
dsinclairdf4bc592016-03-31 20:34:43 -07001061 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001062 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001063 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001064 XFA_RESOLVENODE_RS resoveNodeRS;
weili44f8faf2016-06-01 14:03:56 -07001065 if (!refNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04001066 refNode = this;
tsepez4c3debb2016-04-08 12:20:38 -07001067 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
tsepezfc58ad12016-04-05 12:22:15 -07001068 resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001069 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
1070 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1071 for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) {
1072 if (resoveNodeRS.nodes[i]->IsNode())
1073 pNodeList->Append(resoveNodeRS.nodes[i]->AsNode());
1074 }
1075 } else {
dsinclair12a6b0c2016-05-26 11:14:08 -07001076 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
1077 if (resoveNodeRS.GetAttributeResult(valueArray) > 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001078 CXFA_ObjArray objectArray;
dsinclair12a6b0c2016-05-26 11:14:08 -07001079 valueArray.GetAttributeObject(objectArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04001080 for (int32_t i = 0; i < objectArray.GetSize(); i++) {
1081 if (objectArray[i]->IsNode())
1082 pNodeList->Append(objectArray[i]->AsNode());
1083 }
1084 }
1085 }
dsinclairf27aeec2016-06-07 19:36:18 -07001086 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001087}
weili44f8faf2016-06-01 14:03:56 -07001088
dsinclair12a6b0c2016-05-26 11:14:08 -07001089void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001090 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001091 XFA_ATTRIBUTE eAttribute) {
1092 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001093 ThrowInvalidPropertyException();
1094 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001095 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001096
1097 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
1098 CFX_WideString wsName;
1099 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
1100 CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]");
1101 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001102}
weili44f8faf2016-06-01 14:03:56 -07001103
dsinclair12a6b0c2016-05-26 11:14:08 -07001104void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001105 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001106 XFA_ATTRIBUTE eAttribute) {
dsinclairdf4bc592016-03-31 20:34:43 -07001107 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001108 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001109 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001110 if (bSetting) {
Dan Sinclairc8fd3312017-01-02 17:17:02 -05001111 CFX_WideString wsMessage = L"Unable to set ";
tsepez28f97ff2016-04-04 16:41:35 -07001112 FXJSE_ThrowMessage(
tsepezbd9748d2016-04-13 21:40:19 -07001113 FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001114 } else {
1115 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
dsinclairf27aeec2016-06-07 19:36:18 -07001116 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001117 }
1118}
weili44f8faf2016-06-01 14:03:56 -07001119
dsinclair12a6b0c2016-05-26 11:14:08 -07001120void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001121 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001122 XFA_ATTRIBUTE eAttribute) {
1123 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001124 ThrowInvalidPropertyException();
1125 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001126 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001127
1128 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
1129 CFX_WideString wsExpression =
1130 FX_WSTRC(L"#") + GetClassName() + FX_WSTRC(L"[*]");
1131 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001132}
weili44f8faf2016-06-01 14:03:56 -07001133
dsinclair12a6b0c2016-05-26 11:14:08 -07001134void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001135 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001136 XFA_ATTRIBUTE eAttribute) {
1137 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001138 ThrowInvalidPropertyException();
1139 return;
1140 }
1141 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
1142 if (pParent) {
1143 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001144 } else {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001145 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001146 }
1147}
weili44f8faf2016-06-01 14:03:56 -07001148
dsinclair12a6b0c2016-05-26 11:14:08 -07001149void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001150 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001151 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001152 if (bSetting) {
1153 ThrowInvalidPropertyException();
1154 return;
1155 }
1156 pValue->SetInteger(GetNodeSameNameIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001157}
weili44f8faf2016-06-01 14:03:56 -07001158
dsinclair12a6b0c2016-05-26 11:14:08 -07001159void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001160 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001161 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001162 if (bSetting) {
1163 ThrowInvalidPropertyException();
1164 return;
1165 }
1166 pValue->SetInteger(GetNodeSameClassIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001167}
weili44f8faf2016-06-01 14:03:56 -07001168
dsinclair12a6b0c2016-05-26 11:14:08 -07001169void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001170 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001171 XFA_ATTRIBUTE eAttribute) {
1172 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001173 ThrowInvalidPropertyException();
1174 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001175 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001176 CFX_WideString wsSOMExpression;
1177 GetSOMExpression(wsSOMExpression);
1178 pValue->SetString(FX_UTF8Encode(wsSOMExpression).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001179}
weili44f8faf2016-06-01 14:03:56 -07001180
Dan Sinclair1770c022016-03-14 14:14:16 -04001181void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
1182 int32_t iLength = pArguments->GetLength();
1183 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001184 ThrowParamCountMismatchException(L"applyXSL");
Dan Sinclair1770c022016-03-14 14:14:16 -04001185 return;
1186 }
tsepez6fe7d212016-04-06 10:51:14 -07001187 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001188 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili60607c32016-05-26 11:53:12 -07001189 // TODO(weili): check whether we need to implement this, pdfium:501.
1190 // For now, just put the variables here to avoid unused variable warning.
1191 (void)wsExpression;
Dan Sinclair1770c022016-03-14 14:14:16 -04001192}
weili60607c32016-05-26 11:53:12 -07001193
Dan Sinclair1770c022016-03-14 14:14:16 -04001194void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
1195 int32_t iLength = pArguments->GetLength();
1196 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001197 ThrowParamCountMismatchException(L"assignNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04001198 return;
1199 }
1200 CFX_WideString wsExpression;
1201 CFX_WideString wsValue;
1202 int32_t iAction = 0;
weili44f8faf2016-06-01 14:03:56 -07001203 wsExpression =
1204 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001205 if (iLength >= 2) {
weili60607c32016-05-26 11:53:12 -07001206 wsValue =
1207 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001208 }
weili60607c32016-05-26 11:53:12 -07001209 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001210 iAction = pArguments->GetInt32(2);
weili60607c32016-05-26 11:53:12 -07001211 // TODO(weili): check whether we need to implement this, pdfium:501.
1212 // For now, just put the variables here to avoid unused variable warning.
1213 (void)wsExpression;
1214 (void)wsValue;
1215 (void)iAction;
Dan Sinclair1770c022016-03-14 14:14:16 -04001216}
weili60607c32016-05-26 11:53:12 -07001217
Dan Sinclair1770c022016-03-14 14:14:16 -04001218void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
1219 int32_t iLength = pArguments->GetLength();
1220 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001221 ThrowParamCountMismatchException(L"clone");
Dan Sinclair1770c022016-03-14 14:14:16 -04001222 return;
1223 }
weili44f8faf2016-06-01 14:03:56 -07001224 bool bClone = !!pArguments->GetInt32(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001225 CXFA_Node* pCloneNode = Clone(bClone);
dsinclairf27aeec2016-06-07 19:36:18 -07001226 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001227 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
1228}
weili44f8faf2016-06-01 14:03:56 -07001229
Dan Sinclair1770c022016-03-14 14:14:16 -04001230void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
1231 int32_t iLength = pArguments->GetLength();
1232 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001233 ThrowParamCountMismatchException(L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001234 return;
1235 }
tsepez6fe7d212016-04-06 10:51:14 -07001236 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001237 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001238 CFX_WideString wsValue;
tsepez4c3debb2016-04-08 12:20:38 -07001239 GetAttribute(wsExpression.AsStringC(), wsValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07001240 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001241 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001242 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001243}
weili44f8faf2016-06-01 14:03:56 -07001244
Dan Sinclair1770c022016-03-14 14:14:16 -04001245void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
1246 int32_t iLength = pArguments->GetLength();
1247 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001248 ThrowParamCountMismatchException(L"getElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001249 return;
1250 }
1251 CFX_WideString wsExpression;
1252 int32_t iValue = 0;
weili44f8faf2016-06-01 14:03:56 -07001253 wsExpression =
1254 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1255 if (iLength >= 2)
Dan Sinclair1770c022016-03-14 14:14:16 -04001256 iValue = pArguments->GetInt32(1);
dsinclair6e124782016-06-23 12:14:55 -07001257 CXFA_Node* pNode =
1258 GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
dsinclairf27aeec2016-06-07 19:36:18 -07001259 pArguments->GetReturnValue()->Assign(
1260 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001261}
weili65be4b12016-05-25 15:47:43 -07001262
Dan Sinclair1770c022016-03-14 14:14:16 -04001263void CXFA_Node::Script_NodeClass_IsPropertySpecified(
1264 CFXJSE_Arguments* pArguments) {
1265 int32_t iLength = pArguments->GetLength();
1266 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001267 ThrowParamCountMismatchException(L"isPropertySpecified");
Dan Sinclair1770c022016-03-14 14:14:16 -04001268 return;
1269 }
1270 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001271 bool bParent = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001272 int32_t iIndex = 0;
weili44f8faf2016-06-01 14:03:56 -07001273 wsExpression =
1274 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili65be4b12016-05-25 15:47:43 -07001275 if (iLength >= 2)
weili44f8faf2016-06-01 14:03:56 -07001276 bParent = !!pArguments->GetInt32(1);
weili65be4b12016-05-25 15:47:43 -07001277 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001278 iIndex = pArguments->GetInt32(2);
tsepezd19e9122016-11-02 15:43:18 -07001279 bool bHas = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001280 const XFA_ATTRIBUTEINFO* pAttributeInfo =
tsepez4c3debb2016-04-08 12:20:38 -07001281 XFA_GetAttributeByName(wsExpression.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001282 CFX_WideString wsValue;
weili65be4b12016-05-25 15:47:43 -07001283 if (pAttributeInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04001284 bHas = HasAttribute(pAttributeInfo->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04001285 if (!bHas) {
dsinclair6e124782016-06-23 12:14:55 -07001286 XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
1287 bHas = !!GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001288 if (!bHas && bParent && m_pParent) {
1289 // Also check on the parent.
1290 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
1291 if (!bHas)
dsinclair6e124782016-06-23 12:14:55 -07001292 bHas = !!m_pParent->GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001293 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001294 }
dsinclair12a6b0c2016-05-26 11:14:08 -07001295 CFXJSE_Value* pValue = pArguments->GetReturnValue();
1296 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001297 pValue->SetBoolean(bHas);
Dan Sinclair1770c022016-03-14 14:14:16 -04001298}
weili65be4b12016-05-25 15:47:43 -07001299
Dan Sinclair1770c022016-03-14 14:14:16 -04001300void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
1301 int32_t iLength = pArguments->GetLength();
1302 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001303 ThrowParamCountMismatchException(L"loadXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001304 return;
1305 }
1306 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001307 bool bIgnoreRoot = true;
1308 bool bOverwrite = 0;
1309 wsExpression =
1310 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1311 if (wsExpression.IsEmpty())
Tom Sepezd3743ea2016-05-16 15:56:53 -07001312 return;
weili44f8faf2016-06-01 14:03:56 -07001313 if (iLength >= 2)
1314 bIgnoreRoot = !!pArguments->GetInt32(1);
1315 if (iLength >= 3)
1316 bOverwrite = !!pArguments->GetInt32(2);
dsinclaira1b07722016-07-11 08:20:58 -07001317 std::unique_ptr<CXFA_SimpleParser> pParser(
1318 new CXFA_SimpleParser(m_pDocument, false));
weili44f8faf2016-06-01 14:03:56 -07001319 if (!pParser)
Dan Sinclair1770c022016-03-14 14:14:16 -04001320 return;
weili44f8faf2016-06-01 14:03:56 -07001321 CFDE_XMLNode* pXMLNode = nullptr;
1322 int32_t iParserStatus =
1323 pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
1324 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
1325 return;
dsinclairae95f762016-03-29 16:58:29 -07001326 if (bIgnoreRoot &&
1327 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
1328 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
weili44f8faf2016-06-01 14:03:56 -07001329 bIgnoreRoot = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001330 }
tsepezd19e9122016-11-02 15:43:18 -07001331 CXFA_Node* pFakeRoot = Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001332 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
1333 if (!wsContentType.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07001334 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
1335 CFX_WideString(wsContentType));
Dan Sinclair1770c022016-03-14 14:14:16 -04001336 }
dsinclairae95f762016-03-29 16:58:29 -07001337 CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001338 if (!pFakeXMLRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001339 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
tsepezd19e9122016-11-02 15:43:18 -07001340 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001341 }
dsinclair017052a2016-06-28 07:43:51 -07001342 if (!pFakeXMLRoot)
1343 pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName()));
1344
Dan Sinclair1770c022016-03-14 14:14:16 -04001345 if (bIgnoreRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001346 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001347 while (pXMLChild) {
dsinclairae95f762016-03-29 16:58:29 -07001348 CFDE_XMLNode* pXMLSibling =
1349 pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001350 pXMLNode->RemoveChildNode(pXMLChild);
1351 pFakeXMLRoot->InsertChildNode(pXMLChild);
1352 pXMLChild = pXMLSibling;
1353 }
1354 } else {
dsinclairae95f762016-03-29 16:58:29 -07001355 CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001356 if (pXMLParent) {
1357 pXMLParent->RemoveChildNode(pXMLNode);
1358 }
1359 pFakeXMLRoot->InsertChildNode(pXMLNode);
1360 }
1361 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot);
1362 pFakeRoot = pParser->GetRootNode();
1363 if (pFakeRoot) {
1364 if (bOverwrite) {
1365 CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1366 CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1367 int32_t index = 0;
1368 while (pNewChild) {
1369 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1370 pFakeRoot->RemoveChild(pNewChild);
1371 InsertChild(index++, pNewChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001372 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001373 pNewChild = pItem;
1374 }
1375 while (pChild) {
1376 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1377 RemoveChild(pChild);
1378 pFakeRoot->InsertChild(pChild);
1379 pChild = pItem;
1380 }
1381 if (GetPacketID() == XFA_XDPPACKET_Form &&
dsinclair070fcdf2016-06-22 22:04:54 -07001382 GetElementType() == XFA_Element::ExData) {
dsinclairae95f762016-03-29 16:58:29 -07001383 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001384 SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001385 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
weili44f8faf2016-06-01 14:03:56 -07001386 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001387 pFakeXMLRoot = pTempXMLNode;
1388 } else {
weili44f8faf2016-06-01 14:03:56 -07001389 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001390 }
1391 }
tsepezd19e9122016-11-02 15:43:18 -07001392 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001393 } else {
1394 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1395 while (pChild) {
1396 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1397 pFakeRoot->RemoveChild(pChild);
1398 InsertChild(pChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001399 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001400 pChild = pItem;
1401 }
1402 }
1403 if (pFakeXMLRoot) {
1404 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001405 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001406 }
dsinclairc5a8f212016-06-20 11:11:12 -07001407 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001408 } else {
Tom Sepezd3743ea2016-05-16 15:56:53 -07001409 if (pFakeXMLRoot) {
1410 pFakeXMLRoot->Release();
weili44f8faf2016-06-01 14:03:56 -07001411 pFakeXMLRoot = nullptr;
Tom Sepezd3743ea2016-05-16 15:56:53 -07001412 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001413 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001414}
weili44f8faf2016-06-01 14:03:56 -07001415
Dan Sinclair1770c022016-03-14 14:14:16 -04001416void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
weili44f8faf2016-06-01 14:03:56 -07001417 // TODO(weili): Check whether we need to implement this, pdfium:501.
Dan Sinclair1770c022016-03-14 14:14:16 -04001418}
1419
1420void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1421 int32_t iLength = pArguments->GetLength();
1422 if (iLength < 0 || iLength > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001423 ThrowParamCountMismatchException(L"saveXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001424 return;
1425 }
weili44f8faf2016-06-01 14:03:56 -07001426 bool bPrettyMode = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001427 if (iLength == 1) {
weili65be4b12016-05-25 15:47:43 -07001428 if (pArguments->GetUTF8String(0) != "pretty") {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001429 ThrowArgumentMismatchException();
Dan Sinclair1770c022016-03-14 14:14:16 -04001430 return;
1431 }
weili44f8faf2016-06-01 14:03:56 -07001432 bPrettyMode = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001433 }
1434 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
weili65be4b12016-05-25 15:47:43 -07001435 if (GetPacketID() == XFA_XDPPACKET_Form ||
1436 GetPacketID() == XFA_XDPPACKET_Datasets) {
1437 CFDE_XMLNode* pElement = nullptr;
1438 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1439 pElement = GetXMLMappingNode();
1440 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
dsinclairf27aeec2016-06-07 19:36:18 -07001441 pArguments->GetReturnValue()->SetString(bsXMLHeader);
weili65be4b12016-05-25 15:47:43 -07001442 return;
1443 }
1444 XFA_DataExporter_DealWithDataGroupNode(this);
1445 }
tsepez833619b2016-12-07 09:21:17 -08001446 CFX_RetainPtr<IFX_MemoryStream> pMemoryStream =
1447 IFX_MemoryStream::Create(true);
1448
1449 // Note: ambiguious below without static_cast.
tsepez7cda31a2016-12-07 12:10:20 -08001450 CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream(
1451 CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream),
1452 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
tsepez833619b2016-12-07 09:21:17 -08001453
Dan Sinclair1770c022016-03-14 14:14:16 -04001454 if (!pStream) {
dsinclairf27aeec2016-06-07 19:36:18 -07001455 pArguments->GetReturnValue()->SetString(bsXMLHeader);
Dan Sinclair1770c022016-03-14 14:14:16 -04001456 return;
1457 }
1458 pStream->SetCodePage(FX_CODEPAGE_UTF8);
dsinclair179bebb2016-04-05 11:02:18 -07001459 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
weili65be4b12016-05-25 15:47:43 -07001460 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepez7cda31a2016-12-07 12:10:20 -08001461 XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001462 else
tsepez7cda31a2016-12-07 12:10:20 -08001463 pElement->SaveXMLNode(pStream);
weili65be4b12016-05-25 15:47:43 -07001464 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1465 // For now, just put it here to avoid unused variable warning.
1466 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001467 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001468 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001469 return;
1470 }
dsinclairf27aeec2016-06-07 19:36:18 -07001471 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001472}
1473
1474void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1475 int32_t iLength = pArguments->GetLength();
1476 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001477 ThrowParamCountMismatchException(L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001478 return;
1479 }
tsepez6fe7d212016-04-06 10:51:14 -07001480 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001481 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001482 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001483 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001484 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001485}
weili60607c32016-05-26 11:53:12 -07001486
Dan Sinclair1770c022016-03-14 14:14:16 -04001487void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1488 int32_t iLength = pArguments->GetLength();
1489 if (iLength != 1 && iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001490 ThrowParamCountMismatchException(L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001491 return;
1492 }
weili60607c32016-05-26 11:53:12 -07001493 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001494 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001495 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1496 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001497 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001498 // TODO(weili): check whether we need to implement this, pdfium:501.
1499 // For now, just put the variables here to avoid unused variable warning.
1500 (void)pNode;
1501 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001502}
weili60607c32016-05-26 11:53:12 -07001503
dsinclair12a6b0c2016-05-26 11:14:08 -07001504void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001505 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001506 XFA_ATTRIBUTE eAttribute) {
1507 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001508 ThrowInvalidPropertyException();
1509 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001510 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001511
1512 CFX_WideString wsNameSpace;
1513 TryNamespace(wsNameSpace);
1514 pValue->SetString(FX_UTF8Encode(wsNameSpace).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001515}
weili44f8faf2016-06-01 14:03:56 -07001516
dsinclair12a6b0c2016-05-26 11:14:08 -07001517void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001518 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001519 XFA_ATTRIBUTE eAttribute) {
1520 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001521 ThrowInvalidPropertyException();
1522 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001523 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001524 pValue->Assign(
1525 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001526}
weili44f8faf2016-06-01 14:03:56 -07001527
dsinclair12a6b0c2016-05-26 11:14:08 -07001528void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001529 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001530 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001531 if (bSetting) {
1532 ThrowInvalidPropertyException();
1533 return;
1534 }
1535 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001536}
weili44f8faf2016-06-01 14:03:56 -07001537
dsinclair12a6b0c2016-05-26 11:14:08 -07001538void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001539 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001540 XFA_ATTRIBUTE eAttribute) {
1541 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001542 ThrowInvalidPropertyException();
1543 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001544 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001545 if (GetElementType() == XFA_Element::Subform) {
1546 pValue->SetBoolean(false);
1547 return;
1548 }
1549 CFX_WideString strValue;
1550 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001551}
weili44f8faf2016-06-01 14:03:56 -07001552
dsinclair12a6b0c2016-05-26 11:14:08 -07001553void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001554 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001555 XFA_ATTRIBUTE eAttribute) {
1556 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001557 ThrowInvalidPropertyException();
1558 return;
1559 }
1560
1561 CXFA_NodeArray properts;
1562 int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty);
1563 if (iSize > 0) {
1564 pValue->Assign(
1565 m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0]));
Dan Sinclair1770c022016-03-14 14:14:16 -04001566 }
1567}
weili44f8faf2016-06-01 14:03:56 -07001568
Dan Sinclair1770c022016-03-14 14:14:16 -04001569void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001570
Dan Sinclair1770c022016-03-14 14:14:16 -04001571void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1572 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001573 pArguments->GetReturnValue()->SetObject(
1574 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001575}
1576void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1577}
dsinclair5b36f0a2016-07-19 10:56:23 -07001578
Dan Sinclair1770c022016-03-14 14:14:16 -04001579void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1580 Script_Template_CreateNode(pArguments);
1581}
dsinclair5b36f0a2016-07-19 10:56:23 -07001582
Dan Sinclair1770c022016-03-14 14:14:16 -04001583void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1584 int32_t iLength = pArguments->GetLength();
1585 if (iLength < 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001586 ThrowParamCountMismatchException(L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001587 return;
1588 }
1589 CFX_WideString wsNameSpace;
1590 if (iLength >= 1) {
1591 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001592 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001593 }
1594 CFX_WideString wsNodeNameSpace;
1595 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001596 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001597 if (pValue)
1598 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001599}
dsinclair5b36f0a2016-07-19 10:56:23 -07001600
dsinclair12a6b0c2016-05-26 11:14:08 -07001601void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001602 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001603 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001604
dsinclair12a6b0c2016-05-26 11:14:08 -07001605void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001606 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001607 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001608
dsinclair12a6b0c2016-05-26 11:14:08 -07001609void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001610 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001611 XFA_ATTRIBUTE eAttribute) {
1612 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001613 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001614 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001615 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001616 }
1617}
dsinclair5b36f0a2016-07-19 10:56:23 -07001618
dsinclair12a6b0c2016-05-26 11:14:08 -07001619void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001620 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001621 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001622 if (bSetting) {
1623 ThrowInvalidPropertyException();
1624 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001625 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001626 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001627}
dsinclair5b36f0a2016-07-19 10:56:23 -07001628
dsinclair12a6b0c2016-05-26 11:14:08 -07001629void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001630 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001631 XFA_ATTRIBUTE eAttribute) {
1632 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001633 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001634 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001635 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001636 }
1637}
dsinclair5b36f0a2016-07-19 10:56:23 -07001638
dsinclair12a6b0c2016-05-26 11:14:08 -07001639void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001640 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001641 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001642 if (bSetting) {
1643 ThrowInvalidPropertyException();
1644 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001645 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001646 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001647}
thestigb1a59592016-04-14 18:29:56 -07001648
Dan Sinclair1770c022016-03-14 14:14:16 -04001649void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001650 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001651 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001652 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001653 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001654 return;
thestigb1a59592016-04-14 18:29:56 -07001655
dsinclaira1b07722016-07-11 08:20:58 -07001656 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001657 if (!pNotify)
1658 return;
1659
1660 uint32_t dwPacket = GetPacketID();
1661 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1662 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001663 return;
1664 }
thestigb1a59592016-04-14 18:29:56 -07001665
1666 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001667 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001668 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001669 bNeedFindContainer = true;
1670 pNotify->OnValueChanged(this, eAttribute, this,
1671 GetNodeItem(XFA_NODEITEM_Parent));
1672 break;
dsinclair56a8b192016-06-21 14:15:25 -07001673 case XFA_Element::Font:
1674 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001675 bNeedFindContainer = true;
1676 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001677 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001678 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1679 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1680 } else {
1681 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1682 }
1683 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001684 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001685 bNeedFindContainer = true;
1686 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001687 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001688 if (pParentNode->IsContainerNode()) {
1689 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001690 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001691 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1692 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1693 } else {
1694 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001695 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001696 pNotify->OnValueChanged(this, eAttribute, pNode,
1697 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001698 }
thestigb1a59592016-04-14 18:29:56 -07001699 }
1700 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001701 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001702 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001703 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001704 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1705 eUIType == XFA_Element::NumericEdit ||
1706 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001707 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001708 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001709 pNotify->OnValueChanged(this, eAttribute, pUINode,
1710 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001711 }
thestigb1a59592016-04-14 18:29:56 -07001712 }
1713 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001714 case XFA_Element::Button:
1715 case XFA_Element::Barcode:
1716 case XFA_Element::ChoiceList:
1717 case XFA_Element::DateTimeEdit:
1718 case XFA_Element::NumericEdit:
1719 case XFA_Element::PasswordEdit:
1720 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001721 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1722 if (pUINode) {
1723 pNotify->OnValueChanged(this, eAttribute, pUINode,
1724 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1725 }
1726 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001727 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001728 bNeedFindContainer = true;
1729 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1730 if (pUINode) {
1731 pNotify->OnValueChanged(this, eAttribute, pUINode,
1732 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1733 }
1734 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001735 case XFA_Element::Keep:
1736 case XFA_Element::Bookend:
1737 case XFA_Element::Break:
1738 case XFA_Element::BreakAfter:
1739 case XFA_Element::BreakBefore:
1740 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001741 bNeedFindContainer = true;
1742 break;
dsinclair56a8b192016-06-21 14:15:25 -07001743 case XFA_Element::Area:
1744 case XFA_Element::Draw:
1745 case XFA_Element::ExclGroup:
1746 case XFA_Element::Field:
1747 case XFA_Element::Subform:
1748 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001749 pLayoutPro->AddChangedContainer(this);
1750 pNotify->OnValueChanged(this, eAttribute, this, this);
1751 break;
dsinclair56a8b192016-06-21 14:15:25 -07001752 case XFA_Element::Sharptext:
1753 case XFA_Element::Sharpxml:
1754 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001755 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1756 if (!pTextNode) {
1757 return;
1758 }
1759 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1760 if (!pValueNode) {
1761 return;
1762 }
dsinclair41cb62e2016-06-23 09:20:32 -07001763 XFA_Element eType = pValueNode->GetElementType();
1764 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001765 bNeedFindContainer = true;
1766 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1767 if (pNode && pNode->IsContainerNode()) {
1768 if (bScriptModify) {
1769 pValueNode = pNode;
1770 }
1771 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1772 } else {
1773 pNotify->OnValueChanged(this, eAttribute, pNode,
1774 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001775 }
thestigb1a59592016-04-14 18:29:56 -07001776 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001777 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001778 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1779 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001780 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001781 }
1782 }
thestigb1a59592016-04-14 18:29:56 -07001783 }
1784 } break;
1785 default:
1786 break;
1787 }
1788 if (bNeedFindContainer) {
1789 CXFA_Node* pParent = this;
1790 while (pParent) {
1791 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001792 break;
thestigb1a59592016-04-14 18:29:56 -07001793
1794 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001795 }
thestigb1a59592016-04-14 18:29:56 -07001796 if (pParent) {
1797 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001798 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001799 }
1800}
thestigb1a59592016-04-14 18:29:56 -07001801
dsinclair12a6b0c2016-05-26 11:14:08 -07001802void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001803 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001804 XFA_ATTRIBUTE eAttribute) {
1805 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001806 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001807 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001808 if (eAttribute == XFA_ATTRIBUTE_Use &&
1809 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001810 CXFA_Node* pTemplateNode =
1811 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1812 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001813 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1814 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001815
1816 CFX_WideString wsID;
1817 CFX_WideString wsSOM;
1818 if (!wsValue.IsEmpty()) {
1819 if (wsValue[0] == '#') {
1820 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001821 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001822 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001823 }
1824 }
weili44f8faf2016-06-01 14:03:56 -07001825 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001826 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001827 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001828 XFA_RESOLVENODE_Attributes |
1829 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1830 XFA_RESOLVENODE_Siblings;
1831 XFA_RESOLVENODE_RS resoveNodeRS;
1832 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001833 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001834 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) {
1835 pProtoNode = resoveNodeRS.nodes[0]->AsNode();
1836 }
1837 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001838 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001839 }
1840 if (pProtoNode) {
1841 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1842 while (pHeadChild) {
1843 CXFA_Node* pSibling =
1844 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1845 RemoveChild(pHeadChild);
1846 pHeadChild = pSibling;
1847 }
tsepezd19e9122016-11-02 15:43:18 -07001848 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001849 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1850 while (pHeadChild) {
1851 CXFA_Node* pSibling =
1852 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1853 pProtoForm->RemoveChild(pHeadChild);
1854 InsertChild(pHeadChild);
1855 pHeadChild = pSibling;
1856 }
1857 m_pDocument->RemovePurgeNode(pProtoForm);
1858 delete pProtoForm;
1859 }
1860 }
1861 } else {
1862 CFX_WideString wsValue;
1863 GetAttribute(eAttribute, wsValue);
dsinclairf27aeec2016-06-07 19:36:18 -07001864 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07001865 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001866 }
1867}
dsinclair5b36f0a2016-07-19 10:56:23 -07001868
dsinclair12a6b0c2016-05-26 11:14:08 -07001869void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001870 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001871 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001872 if (bSetting) {
1873 ThrowInvalidPropertyException();
1874 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001875 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001876
1877 CFX_WideString wsValue;
1878 GetAttribute(eAttribute, wsValue);
1879 pValue->SetString(
1880 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001881}
dsinclair5b36f0a2016-07-19 10:56:23 -07001882
Dan Sinclair1770c022016-03-14 14:14:16 -04001883void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1884 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001885 if (argc != 0 && argc != 1) {
1886 ThrowParamCountMismatchException(L"execute");
1887 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001888 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001889 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001890}
dsinclair5b36f0a2016-07-19 10:56:23 -07001891
Dan Sinclair1770c022016-03-14 14:14:16 -04001892void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001893 if (pArguments->GetLength() != 0)
1894 ThrowParamCountMismatchException(L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001895}
dsinclair5b36f0a2016-07-19 10:56:23 -07001896
dsinclair12a6b0c2016-05-26 11:14:08 -07001897void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001898 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001899 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001900
dsinclair12a6b0c2016-05-26 11:14:08 -07001901void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001902 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001903 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001904
dsinclair12a6b0c2016-05-26 11:14:08 -07001905void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001906 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001907 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001908
dsinclair12a6b0c2016-05-26 11:14:08 -07001909void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001910 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001911 XFA_SOM_MESSAGETYPE iMessageType) {
1912 CXFA_WidgetData* pWidgetData = GetWidgetData();
1913 if (!pWidgetData) {
1914 return;
1915 }
tsepezd19e9122016-11-02 15:43:18 -07001916 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001917 CXFA_Validate validate = pWidgetData->GetValidate();
1918 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001919 validate = pWidgetData->GetValidate(true);
1920 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001921 }
1922 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001923 switch (iMessageType) {
1924 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001925 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001926 break;
1927 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001928 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001929 break;
1930 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001931 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001932 break;
1933 default:
1934 break;
1935 }
1936 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001937 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001938 if (!pNotify) {
1939 return;
1940 }
1941 pNotify->AddCalcValidate(this);
1942 }
1943 } else {
1944 CFX_WideString wsMessage;
1945 switch (iMessageType) {
1946 case XFA_SOM_ValidationMessage:
1947 validate.GetScriptMessageText(wsMessage);
1948 break;
1949 case XFA_SOM_FormatMessage:
1950 validate.GetFormatMessageText(wsMessage);
1951 break;
1952 case XFA_SOM_MandatoryMessage:
1953 validate.GetNullMessageText(wsMessage);
1954 break;
1955 default:
1956 break;
1957 }
dsinclairf27aeec2016-06-07 19:36:18 -07001958 pValue->SetString(FX_UTF8Encode(wsMessage).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001959 }
1960}
dsinclair5b36f0a2016-07-19 10:56:23 -07001961
dsinclair12a6b0c2016-05-26 11:14:08 -07001962void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001963 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001964 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001965 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001966}
dsinclair5b36f0a2016-07-19 10:56:23 -07001967
dsinclair12a6b0c2016-05-26 11:14:08 -07001968void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001969 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001970 XFA_ATTRIBUTE eAttribute) {
1971 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001972 ThrowInvalidPropertyException();
1973 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001974 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001975
1976 CXFA_WidgetData* pWidgetData = GetWidgetData();
1977 if (!pWidgetData) {
1978 pValue->SetInteger(0);
1979 return;
1980 }
1981 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001982}
dsinclair5b36f0a2016-07-19 10:56:23 -07001983
dsinclair12a6b0c2016-05-26 11:14:08 -07001984void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001985 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001986 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001987 XFA_Element eType = GetElementType();
1988 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001989 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001990 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001991 }
1992 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001993 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001994 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001995 }
1996 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001997 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001998 return;
1999 }
2000 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002001 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07002002 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002003 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002004
Dan Sinclair1770c022016-03-14 14:14:16 -04002005 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07002006 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002007 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
2008 CXFA_NodeArray formNodes;
2009 GetBindItems(formNodes);
2010 CFX_WideString wsPicture;
2011 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
2012 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -07002013 if (!pFormNode || pFormNode->HasRemovedChildren()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002014 continue;
2015 }
2016 pContainerWidgetData = pFormNode->GetContainerWidgetData();
2017 if (pContainerWidgetData) {
2018 pContainerWidgetData->GetPictureContent(wsPicture,
2019 XFA_VALUEPICTURE_DataBind);
2020 }
2021 if (!wsPicture.IsEmpty()) {
2022 break;
2023 }
weili44f8faf2016-06-01 14:03:56 -07002024 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002025 }
2026 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
2027 pContainerWidgetData = GetContainerWidgetData();
2028 }
2029 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002030 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002031 }
tsepezd19e9122016-11-02 15:43:18 -07002032 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002033 } else {
tsepezd19e9122016-11-02 15:43:18 -07002034 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07002035 if (content.IsEmpty() && eType != XFA_Element::Text &&
2036 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07002037 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07002038 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002039 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07002040 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07002041 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002042 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002043 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002044 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002045 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002046 }
2047 }
2048}
dsinclair5b36f0a2016-07-19 10:56:23 -07002049
dsinclair12a6b0c2016-05-26 11:14:08 -07002050void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002051 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002052 XFA_ATTRIBUTE eAttribute) {
2053 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002054 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002055 return;
2056 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002057
tsepezd19e9122016-11-02 15:43:18 -07002058 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002059 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002060 pValue->SetNull();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002061 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002062 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002063 pValue->SetString(
2064 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002065}
dsinclair5b36f0a2016-07-19 10:56:23 -07002066
dsinclair12a6b0c2016-05-26 11:14:08 -07002067void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002068 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002069 XFA_ATTRIBUTE eAttribute) {
2070 if (bSetting) {
2071 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002072 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002073 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002074
tsepezb4c9f3f2016-04-13 15:41:21 -07002075 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002076 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002077 CFX_WideString wsFormatValue(wsNewValue);
2078 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2079 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002080 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002081 }
tsepezd19e9122016-11-02 15:43:18 -07002082 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002083 } else {
tsepezd19e9122016-11-02 15:43:18 -07002084 CFX_WideString wsValue = GetScriptContent(true);
dsinclairf27aeec2016-06-07 19:36:18 -07002085 pValue->SetBoolean(wsValue == FX_WSTRC(L"1"));
Dan Sinclair1770c022016-03-14 14:14:16 -04002086 }
2087}
dsinclair2f5582f2016-06-09 11:48:23 -07002088
dsinclair12a6b0c2016-05-26 11:14:08 -07002089void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002090 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002091 XFA_ATTRIBUTE eAttribute) {
2092 CXFA_WidgetData* pWidgetData = GetWidgetData();
2093 if (!pWidgetData) {
2094 return;
2095 }
tsepezd19e9122016-11-02 15:43:18 -07002096 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002097 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002098 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002099 int32_t r = 0;
2100 int32_t g = 0;
2101 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002102 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002103 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2104 for (int32_t i = 0; i < iSize; ++i) {
2105 CXFA_Edge edge = border.GetEdge(i);
2106 edge.SetColor(rgb);
2107 }
2108 } else {
2109 CXFA_Edge edge = border.GetEdge(0);
2110 FX_ARGB color = edge.GetColor();
2111 int32_t a, r, g, b;
2112 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002113 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002114 strColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002115 pValue->SetString(FX_UTF8Encode(strColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002116 }
2117}
dsinclair5b36f0a2016-07-19 10:56:23 -07002118
dsinclair12a6b0c2016-05-26 11:14:08 -07002119void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002120 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002121 XFA_ATTRIBUTE eAttribute) {
2122 CXFA_WidgetData* pWidgetData = GetWidgetData();
2123 if (!pWidgetData) {
2124 return;
2125 }
tsepezd19e9122016-11-02 15:43:18 -07002126 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002127 int32_t iSize = border.CountEdges();
2128 CFX_WideString wsThickness;
2129 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002130 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002131 for (int32_t i = 0; i < iSize; ++i) {
2132 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002133 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002134 edge.SetMSThickness(thickness);
2135 }
2136 } else {
2137 CXFA_Edge edge = border.GetEdge(0);
2138 CXFA_Measurement thickness = edge.GetMSThickness();
2139 thickness.ToString(wsThickness);
dsinclairf27aeec2016-06-07 19:36:18 -07002140 pValue->SetString(FX_UTF8Encode(wsThickness).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002141 }
2142}
dsinclair5b36f0a2016-07-19 10:56:23 -07002143
dsinclair12a6b0c2016-05-26 11:14:08 -07002144void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002145 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002146 XFA_ATTRIBUTE eAttribute) {
2147 CXFA_WidgetData* pWidgetData = GetWidgetData();
2148 if (!pWidgetData) {
2149 return;
2150 }
tsepezd19e9122016-11-02 15:43:18 -07002151 CXFA_Border border = pWidgetData->GetBorder(true);
2152 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002153 CXFA_Node* pNode = borderfill.GetNode();
2154 if (!pNode) {
2155 return;
2156 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002157 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002158 int32_t r;
2159 int32_t g;
2160 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002161 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002162 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2163 borderfill.SetColor(color);
2164 } else {
2165 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002166 int32_t a;
2167 int32_t r;
2168 int32_t g;
2169 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002170 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002171 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002172 wsColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002173 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002174 }
2175}
dsinclair5b36f0a2016-07-19 10:56:23 -07002176
dsinclair12a6b0c2016-05-26 11:14:08 -07002177void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002178 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002179 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002180 if (bSetting) {
2181 ThrowInvalidPropertyException();
2182 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002183 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002184
2185 CXFA_Node* pDataNode = GetBindData();
2186 if (!pDataNode) {
2187 pValue->SetNull();
2188 return;
2189 }
2190
2191 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002192}
dsinclair5b36f0a2016-07-19 10:56:23 -07002193
dsinclair12a6b0c2016-05-26 11:14:08 -07002194void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002195 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002196 XFA_ATTRIBUTE eAttribute) {
2197 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002198 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002199 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002200 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002201 XFA_Element uiType = pWidgetData->GetUIType();
2202 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002203 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002204 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002205 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002206 }
2207 }
2208 } else {
tsepezd19e9122016-11-02 15:43:18 -07002209 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002210 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002211 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002212 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002213 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002214 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002215 }
2216 }
2217}
dsinclair5b36f0a2016-07-19 10:56:23 -07002218
dsinclair12a6b0c2016-05-26 11:14:08 -07002219void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002220 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002221 XFA_ATTRIBUTE eAttribute) {
2222 CXFA_WidgetData* pWidgetData = GetWidgetData();
2223 if (!pWidgetData) {
2224 return;
2225 }
2226 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002227 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002228 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002229 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002230 } else {
2231 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002232 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002233 }
dsinclair2f5582f2016-06-09 11:48:23 -07002234 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002235 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002236 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002237
Dan Sinclair1770c022016-03-14 14:14:16 -04002238 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002239 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002240 int32_t iLeadDigits = 0;
2241 int32_t iFracDigits = 0;
2242 pWidgetData->GetLeadDigits(iLeadDigits);
2243 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002244 wsNewText =
2245 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002246 }
2247 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2248 CFX_WideString wsFormatText(wsNewText);
2249 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002250 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002251 }
tsepezd19e9122016-11-02 15:43:18 -07002252 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002253 } else {
tsepezd19e9122016-11-02 15:43:18 -07002254 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002255 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002256 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002257 } else {
2258 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002259 CXFA_Value defVal = pWidgetData->GetFormValue();
2260 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002261 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002262 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002263 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002264 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002265 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002266 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002267 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002268 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002269 }
dsinclair070fcdf2016-06-22 22:04:54 -07002270 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002271 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002272 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002273 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002274 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002275 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002276 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002277 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002278 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002279 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002280 }
2281 }
2282 }
2283}
dsinclair5b36f0a2016-07-19 10:56:23 -07002284
dsinclair12a6b0c2016-05-26 11:14:08 -07002285void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002286 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002287 XFA_ATTRIBUTE eAttribute) {
2288 CXFA_WidgetData* pWidgetData = GetWidgetData();
2289 if (!pWidgetData) {
2290 return;
2291 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002292 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002293 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002294 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002295 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002296 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
dsinclairf27aeec2016-06-07 19:36:18 -07002297 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002298 }
2299}
dsinclair5b36f0a2016-07-19 10:56:23 -07002300
dsinclair12a6b0c2016-05-26 11:14:08 -07002301void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002302 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002303 XFA_ATTRIBUTE eAttribute) {
2304 CXFA_WidgetData* pWidgetData = GetWidgetData();
2305 if (!pWidgetData) {
2306 return;
2307 }
tsepezd19e9122016-11-02 15:43:18 -07002308 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002309 CXFA_Node* pNode = font.GetNode();
2310 if (!pNode) {
2311 return;
2312 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002313 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002314 int32_t r;
2315 int32_t g;
2316 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002317 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002318 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2319 font.SetColor(color);
2320 } else {
2321 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002322 int32_t a;
2323 int32_t r;
2324 int32_t g;
2325 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002326 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002327 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002328 wsColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002329 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002330 }
2331}
dsinclair5b36f0a2016-07-19 10:56:23 -07002332
dsinclair12a6b0c2016-05-26 11:14:08 -07002333void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002334 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002335 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002336 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002337}
dsinclair5b36f0a2016-07-19 10:56:23 -07002338
dsinclair12a6b0c2016-05-26 11:14:08 -07002339void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002340 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002341 XFA_ATTRIBUTE eAttribute) {
2342 CXFA_WidgetData* pWidgetData = GetWidgetData();
2343 if (!pWidgetData) {
2344 return;
2345 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002346 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002347 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002348 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002349 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002350 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
dsinclairf27aeec2016-06-07 19:36:18 -07002351 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002352 }
2353}
dsinclair5b36f0a2016-07-19 10:56:23 -07002354
dsinclair12a6b0c2016-05-26 11:14:08 -07002355void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002356 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002357 XFA_ATTRIBUTE eAttribute) {
2358 CXFA_WidgetData* pWidgetData = GetWidgetData();
2359 if (!pWidgetData) {
2360 return;
2361 }
tsepezd19e9122016-11-02 15:43:18 -07002362 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002363 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002364 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002365 } else {
2366 int32_t iValue = validate.GetNullTest();
2367 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002368 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002369 CFX_WideString wsValue;
2370 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002371 wsValue = pInfo->pName;
dsinclairf27aeec2016-06-07 19:36:18 -07002372 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002373 }
2374}
dsinclair5b36f0a2016-07-19 10:56:23 -07002375
dsinclair12a6b0c2016-05-26 11:14:08 -07002376void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002377 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002378 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002379 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002380}
dsinclair5b36f0a2016-07-19 10:56:23 -07002381
dsinclair12a6b0c2016-05-26 11:14:08 -07002382void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002383 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002384 XFA_ATTRIBUTE eAttribute) {
2385 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002386 ThrowInvalidPropertyException();
2387 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002388 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002389 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002390}
dsinclair5b36f0a2016-07-19 10:56:23 -07002391
dsinclair12a6b0c2016-05-26 11:14:08 -07002392void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002393 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002394 XFA_ATTRIBUTE eAttribute) {
2395 CXFA_WidgetData* pWidgetData = GetWidgetData();
2396 if (!pWidgetData) {
2397 return;
2398 }
2399 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002400 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002401 if (iIndex == -1) {
2402 pWidgetData->ClearAllSelections();
2403 return;
2404 }
tsepezd19e9122016-11-02 15:43:18 -07002405 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002406 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002407 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002408 }
2409}
dsinclair5b36f0a2016-07-19 10:56:23 -07002410
Dan Sinclair1770c022016-03-14 14:14:16 -04002411void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2412 CXFA_WidgetData* pWidgetData = GetWidgetData();
2413 if (!pWidgetData) {
2414 return;
2415 }
tsepezd19e9122016-11-02 15:43:18 -07002416 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002417}
dsinclair5b36f0a2016-07-19 10:56:23 -07002418
Dan Sinclair1770c022016-03-14 14:14:16 -04002419void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002420 if (pArguments->GetLength() != 1) {
2421 ThrowParamCountMismatchException(L"execEvent");
2422 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002423 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002424
2425 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2426 int32_t iRet = execSingleEventByName(
2427 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2428 XFA_Element::Field);
2429 if (eventString != "validate")
2430 return;
2431
2432 pArguments->GetReturnValue()->SetBoolean(
2433 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002434}
dsinclair5b36f0a2016-07-19 10:56:23 -07002435
Dan Sinclair1770c022016-03-14 14:14:16 -04002436void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002437 if (pArguments->GetLength() != 0) {
2438 ThrowParamCountMismatchException(L"execInitialize");
2439 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002440 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002441
2442 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2443 if (!pNotify)
2444 return;
2445
2446 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002447}
dsinclair5b36f0a2016-07-19 10:56:23 -07002448
Dan Sinclair1770c022016-03-14 14:14:16 -04002449void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2450 int32_t iLength = pArguments->GetLength();
2451 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002452 ThrowParamCountMismatchException(L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002453 return;
2454 }
2455 CXFA_WidgetData* pWidgetData = GetWidgetData();
2456 if (!pWidgetData) {
2457 return;
2458 }
2459 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002460 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002461 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002462 if (pValue)
2463 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002464}
dsinclair5b36f0a2016-07-19 10:56:23 -07002465
Dan Sinclair1770c022016-03-14 14:14:16 -04002466void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2467 int32_t iLength = pArguments->GetLength();
2468 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002469 ThrowParamCountMismatchException(L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002470 return;
2471 }
2472 int32_t iIndex = pArguments->GetInt32(0);
2473 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002474 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002475 return;
2476 }
2477 CXFA_WidgetData* pWidgetData = GetWidgetData();
2478 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002479 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002480 return;
2481 }
2482 CFX_WideString wsValue;
tsepezd19e9122016-11-02 15:43:18 -07002483 bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002484 if (bHasItem) {
dsinclairf27aeec2016-06-07 19:36:18 -07002485 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002486 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002487 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002488 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002489 }
2490}
dsinclair5b36f0a2016-07-19 10:56:23 -07002491
Dan Sinclair1770c022016-03-14 14:14:16 -04002492void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2493 int32_t iLength = pArguments->GetLength();
2494 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002495 ThrowParamCountMismatchException(L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002496 return;
2497 }
2498 CXFA_WidgetData* pWidgetData = GetWidgetData();
2499 if (!pWidgetData) {
2500 return;
2501 }
2502 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002503 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002504 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002505 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002506 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002507 if (pValue)
2508 pValue->SetString(FX_UTF8Encode(wsBoundValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002509}
dsinclair5b36f0a2016-07-19 10:56:23 -07002510
Dan Sinclair1770c022016-03-14 14:14:16 -04002511void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2512 int32_t iLength = pArguments->GetLength();
2513 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002514 ThrowParamCountMismatchException(L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002515 return;
2516 }
2517 CXFA_WidgetData* pWidgetData = GetWidgetData();
2518 if (!pWidgetData) {
2519 return;
2520 }
2521 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002522 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002523 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002524 if (pValue)
2525 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002526}
dsinclair5b36f0a2016-07-19 10:56:23 -07002527
Dan Sinclair1770c022016-03-14 14:14:16 -04002528void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002529 if (pArguments->GetLength() != 0) {
2530 ThrowParamCountMismatchException(L"execCalculate");
2531 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002532 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002533
2534 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2535 if (!pNotify)
2536 return;
2537
2538 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002539}
dsinclair5b36f0a2016-07-19 10:56:23 -07002540
Dan Sinclair1770c022016-03-14 14:14:16 -04002541void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002542
Dan Sinclair1770c022016-03-14 14:14:16 -04002543void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2544 int32_t iLength = pArguments->GetLength();
2545 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002546 ThrowParamCountMismatchException(L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002547 return;
2548 }
2549 int32_t iIndex = pArguments->GetInt32(0);
2550 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002551 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002552 return;
2553 }
2554 CXFA_WidgetData* pWidgetData = GetWidgetData();
2555 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002556 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002557 return;
2558 }
2559 CFX_WideString wsValue;
tsepezd19e9122016-11-02 15:43:18 -07002560 bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002561 if (bHasItem) {
dsinclairf27aeec2016-06-07 19:36:18 -07002562 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002563 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002564 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002565 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002566 }
2567}
dsinclair5b36f0a2016-07-19 10:56:23 -07002568
Dan Sinclair1770c022016-03-14 14:14:16 -04002569void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2570 int32_t iLength = pArguments->GetLength();
2571 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002572 ThrowParamCountMismatchException(L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002573 return;
2574 }
2575 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002576 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002577 return;
thestig800222e2016-05-26 22:00:29 -07002578
Dan Sinclair1770c022016-03-14 14:14:16 -04002579 int32_t iIndex = pArguments->GetInt32(0);
2580 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002581 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002582 } else {
thestig800222e2016-05-26 22:00:29 -07002583 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002584 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002585 }
2586}
dsinclair5b36f0a2016-07-19 10:56:23 -07002587
Dan Sinclair1770c022016-03-14 14:14:16 -04002588void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2589 int32_t iLength = pArguments->GetLength();
2590 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002591 ThrowParamCountMismatchException(L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002592 return;
2593 }
2594 CXFA_WidgetData* pWidgetData = GetWidgetData();
2595 if (!pWidgetData) {
2596 return;
2597 }
2598 CFX_WideString wsLabel;
2599 CFX_WideString wsValue;
2600 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002601 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002602 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002603 }
2604 if (iLength >= 2) {
2605 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002606 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002607 }
tsepezd19e9122016-11-02 15:43:18 -07002608 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002609}
dsinclair5b36f0a2016-07-19 10:56:23 -07002610
Dan Sinclair1770c022016-03-14 14:14:16 -04002611void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002612 if (pArguments->GetLength() != 0) {
2613 ThrowParamCountMismatchException(L"execValidate");
2614 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002615 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002616
2617 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2618 if (!pNotify) {
2619 pArguments->GetReturnValue()->SetBoolean(false);
2620 return;
2621 }
2622
2623 int32_t iRet =
2624 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
2625 pArguments->GetReturnValue()->SetBoolean(
2626 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002627}
dsinclair5b36f0a2016-07-19 10:56:23 -07002628
dsinclair12a6b0c2016-05-26 11:14:08 -07002629void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002630 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002631 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002632 if (bSetting)
2633 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002634}
dsinclair5b36f0a2016-07-19 10:56:23 -07002635
dsinclair12a6b0c2016-05-26 11:14:08 -07002636void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002637 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002638 XFA_ATTRIBUTE eAttribute) {
2639 CXFA_WidgetData* pWidgetData = GetWidgetData();
2640 if (!pWidgetData) {
2641 return;
2642 }
2643 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002644 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002645 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002646 } else {
tsepezd19e9122016-11-02 15:43:18 -07002647 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002648 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2649 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002650 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002651 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002652 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002653 }
2654 }
2655}
dsinclair5b36f0a2016-07-19 10:56:23 -07002656
dsinclair12a6b0c2016-05-26 11:14:08 -07002657void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002658 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002659 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002660
Dan Sinclair1770c022016-03-14 14:14:16 -04002661void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002662 if (pArguments->GetLength() != 1) {
2663 ThrowParamCountMismatchException(L"execEvent");
2664 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002665 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002666
2667 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2668 execSingleEventByName(
2669 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2670 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002671}
thestig800222e2016-05-26 22:00:29 -07002672
Dan Sinclair1770c022016-03-14 14:14:16 -04002673void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2674 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002675 if (argc < 0 || argc > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002676 ThrowParamCountMismatchException(L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002677 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002678 }
thestig800222e2016-05-26 22:00:29 -07002679
2680 CXFA_WidgetData* pWidgetData = GetWidgetData();
2681 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002682 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002683 return;
2684 }
2685
2686 CXFA_Node* pReturnNode = nullptr;
2687 if (argc == 0) {
2688 pReturnNode = pWidgetData->GetSelectedMember();
2689 } else {
2690 CFX_ByteString szName;
2691 szName = pArguments->GetUTF8String(0);
2692 pReturnNode = pWidgetData->SetSelectedMember(
2693 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2694 }
2695 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002696 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002697 return;
2698 }
dsinclairf27aeec2016-06-07 19:36:18 -07002699 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002700 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002701}
thestig800222e2016-05-26 22:00:29 -07002702
Dan Sinclair1770c022016-03-14 14:14:16 -04002703void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002704 if (pArguments->GetLength() != 0) {
2705 ThrowParamCountMismatchException(L"execInitialize");
2706 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002707 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002708
2709 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2710 if (!pNotify)
2711 return;
2712
2713 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002714}
dsinclair5b36f0a2016-07-19 10:56:23 -07002715
Dan Sinclair1770c022016-03-14 14:14:16 -04002716void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002717 if (pArguments->GetLength() != 0) {
2718 ThrowParamCountMismatchException(L"execCalculate");
2719 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002720 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002721
2722 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2723 if (!pNotify)
2724 return;
2725
2726 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002727}
dsinclair5b36f0a2016-07-19 10:56:23 -07002728
Dan Sinclair1770c022016-03-14 14:14:16 -04002729void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002730 if (pArguments->GetLength() != 0) {
2731 ThrowParamCountMismatchException(L"execValidate");
2732 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002733 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002734
2735 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2736 if (!pNotify) {
2737 pArguments->GetReturnValue()->SetBoolean(false);
2738 return;
2739 }
2740
2741 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2742 pArguments->GetReturnValue()->SetBoolean(
2743 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002744}
dsinclair5b36f0a2016-07-19 10:56:23 -07002745
dsinclair12a6b0c2016-05-26 11:14:08 -07002746void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002747 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002748 XFA_ATTRIBUTE eAttribute) {
2749 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002750 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002751 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002752 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002753 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2754 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002755 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002756 pManagerNode = pNode;
2757 break;
2758 }
2759 }
2760 if (pManagerNode) {
2761 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002762 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002763 if (!pNotify) {
2764 return;
2765 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002766 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002767 if (pToInstance &&
2768 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002769 pNotify->RunSubformIndexChange(pToInstance);
2770 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002771 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002772 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002773 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002774 pNotify->RunSubformIndexChange(pFromInstance);
2775 }
2776 }
2777 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002778 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002779 }
2780}
dsinclair5b36f0a2016-07-19 10:56:23 -07002781
dsinclair12a6b0c2016-05-26 11:14:08 -07002782void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002783 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002784 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002785 if (bSetting) {
2786 ThrowInvalidPropertyException();
2787 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002788 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002789
2790 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2791 CXFA_Node* pInstanceMgr = nullptr;
2792 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2793 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2794 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2795 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2796 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2797 wsInstMgrName.Mid(1) == wsName) {
2798 pInstanceMgr = pNode;
2799 }
2800 break;
2801 }
2802 }
2803 if (!pInstanceMgr) {
2804 pValue->SetNull();
2805 return;
2806 }
2807
2808 pValue->Assign(
2809 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
Dan Sinclair1770c022016-03-14 14:14:16 -04002810}
dsinclair5b36f0a2016-07-19 10:56:23 -07002811
dsinclair12a6b0c2016-05-26 11:14:08 -07002812void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002813 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002814 XFA_ATTRIBUTE eAttribute) {
2815 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002816 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002817 } else {
2818 CFX_WideString wsLocaleName;
2819 GetLocaleName(wsLocaleName);
dsinclairf27aeec2016-06-07 19:36:18 -07002820 pValue->SetString(
2821 FX_UTF8Encode(wsLocaleName.c_str(), wsLocaleName.GetLength())
2822 .AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002823 }
2824}
dsinclair5b36f0a2016-07-19 10:56:23 -07002825
Dan Sinclair1770c022016-03-14 14:14:16 -04002826void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002827 if (pArguments->GetLength() != 1) {
2828 ThrowParamCountMismatchException(L"execEvent");
2829 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002830 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002831
2832 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2833 execSingleEventByName(
2834 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2835 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002836}
dsinclair5b36f0a2016-07-19 10:56:23 -07002837
Dan Sinclair1770c022016-03-14 14:14:16 -04002838void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002839 if (pArguments->GetLength() != 0) {
2840 ThrowParamCountMismatchException(L"execInitialize");
2841 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002842 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002843
2844 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2845 if (!pNotify)
2846 return;
2847
2848 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002849}
dsinclair5b36f0a2016-07-19 10:56:23 -07002850
Dan Sinclair1770c022016-03-14 14:14:16 -04002851void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002852 if (pArguments->GetLength() != 0) {
2853 ThrowParamCountMismatchException(L"execCalculate");
2854 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002855 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002856
2857 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2858 if (!pNotify)
2859 return;
2860
2861 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002862}
dsinclair5b36f0a2016-07-19 10:56:23 -07002863
Dan Sinclair1770c022016-03-14 14:14:16 -04002864void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002865 if (pArguments->GetLength() != 0) {
2866 ThrowParamCountMismatchException(L"execValidate");
2867 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002868 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002869
2870 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2871 if (!pNotify) {
2872 pArguments->GetReturnValue()->SetBoolean(false);
2873 return;
2874 }
2875
2876 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2877 pArguments->GetReturnValue()->SetBoolean(
2878 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002879}
dsinclair5b36f0a2016-07-19 10:56:23 -07002880
Dan Sinclair1770c022016-03-14 14:14:16 -04002881void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002882 if (pArguments->GetLength() != 0)
2883 ThrowParamCountMismatchException(L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002884}
dsinclair5b36f0a2016-07-19 10:56:23 -07002885
Dan Sinclair1770c022016-03-14 14:14:16 -04002886int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2887 int32_t index = 0;
2888 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2889 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002890 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2891 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002892 index++;
2893 } else {
2894 break;
2895 }
2896 }
2897 return index;
2898}
dsinclair5b36f0a2016-07-19 10:56:23 -07002899
Dan Sinclair1770c022016-03-14 14:14:16 -04002900void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002901 if (pArguments->GetLength() != 1) {
2902 ThrowParamCountMismatchException(L"formNodes");
2903 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002904 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002905 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002906}
dsinclair5b36f0a2016-07-19 10:56:23 -07002907
Dan Sinclair1770c022016-03-14 14:14:16 -04002908void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002909 if (pArguments->GetLength() != 0) {
2910 ThrowParamCountMismatchException(L"remerge");
2911 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002912 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002913 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002914}
dsinclair5b36f0a2016-07-19 10:56:23 -07002915
Dan Sinclair1770c022016-03-14 14:14:16 -04002916void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002917 if (pArguments->GetLength() != 0) {
2918 ThrowParamCountMismatchException(L"execInitialize");
2919 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002920 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002921
2922 CXFA_WidgetData* pWidgetData = GetWidgetData();
2923 if (!pWidgetData) {
2924 pArguments->GetReturnValue()->SetBoolean(false);
2925 return;
2926 }
2927 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002928}
dsinclair5b36f0a2016-07-19 10:56:23 -07002929
Dan Sinclair1770c022016-03-14 14:14:16 -04002930void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2931 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002932 if (argc <= 0 || argc >= 4) {
2933 ThrowParamCountMismatchException(L"createNode");
2934 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002935 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002936
2937 CFX_WideString strName;
2938 CFX_WideString strNameSpace;
2939 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
2940 CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
2941 if (argc > 1) {
2942 CFX_ByteString bsName = pArguments->GetUTF8String(1);
2943 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
2944 if (argc == 3) {
2945 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
2946 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
2947 }
2948 }
2949
2950 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2951 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
2952 if (!pNewNode) {
2953 pArguments->GetReturnValue()->SetNull();
2954 return;
2955 }
2956
2957 if (strName.IsEmpty()) {
2958 pArguments->GetReturnValue()->Assign(
2959 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2960 return;
2961 }
2962
2963 if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2964 XFA_XDPPACKET_UNKNOWN)) {
2965 ThrowMissingPropertyException(strTagName, L"name");
2966 return;
2967 }
2968
2969 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
2970 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets)
2971 pNewNode->CreateXMLMappingNode();
2972
2973 pArguments->GetReturnValue()->Assign(
2974 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002975}
dsinclair5b36f0a2016-07-19 10:56:23 -07002976
Dan Sinclair1770c022016-03-14 14:14:16 -04002977void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002978 if (pArguments->GetLength() != 1) {
2979 ThrowParamCountMismatchException(L"recalculate");
2980 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002981 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002982 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002983}
dsinclair5b36f0a2016-07-19 10:56:23 -07002984
Dan Sinclair1770c022016-03-14 14:14:16 -04002985void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002986 if (pArguments->GetLength() != 0) {
2987 ThrowParamCountMismatchException(L"execCalculate");
2988 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002989 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002990
2991 CXFA_WidgetData* pWidgetData = GetWidgetData();
2992 if (!pWidgetData) {
2993 pArguments->GetReturnValue()->SetBoolean(false);
2994 return;
2995 }
2996 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002997}
dsinclair5b36f0a2016-07-19 10:56:23 -07002998
Dan Sinclair1770c022016-03-14 14:14:16 -04002999void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003000 if (pArguments->GetLength() != 0) {
3001 ThrowParamCountMismatchException(L"execValidate");
3002 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003003 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003004 CXFA_WidgetData* pWidgetData = GetWidgetData();
3005 if (!pWidgetData) {
3006 pArguments->GetReturnValue()->SetBoolean(false);
3007 return;
3008 }
3009 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003010}
dsinclair5b36f0a2016-07-19 10:56:23 -07003011
Dan Sinclair1770c022016-03-14 14:14:16 -04003012void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003013 if (pArguments->GetLength() != 0) {
3014 ThrowParamCountMismatchException(L"evaluate");
3015 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003016 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003017
3018 CXFA_WidgetData* pWidgetData = GetWidgetData();
3019 if (!pWidgetData) {
3020 pArguments->GetReturnValue()->SetBoolean(false);
3021 return;
3022 }
3023 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003024}
dsinclair5b36f0a2016-07-19 10:56:23 -07003025
dsinclair12a6b0c2016-05-26 11:14:08 -07003026void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003027 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003028 XFA_ATTRIBUTE eAttribute) {
3029 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003030 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003031 return;
3032 }
3033 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003034 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003035}
dsinclair5b36f0a2016-07-19 10:56:23 -07003036
dsinclair12a6b0c2016-05-26 11:14:08 -07003037void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003038 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003039 XFA_ATTRIBUTE eAttribute) {
3040 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003041 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003042 return;
3043 }
3044 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003045 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003046}
tsepezaadedf92016-05-12 10:08:06 -07003047
dsinclair12a6b0c2016-05-26 11:14:08 -07003048void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003049 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003050 XFA_ATTRIBUTE eAttribute) {
3051 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003052 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003053 InstanceManager_SetInstances(iDesired);
3054 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07003055 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04003056 }
3057}
dsinclair5b36f0a2016-07-19 10:56:23 -07003058
Dan Sinclair1770c022016-03-14 14:14:16 -04003059void CXFA_Node::Script_InstanceManager_MoveInstance(
3060 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003061 if (pArguments->GetLength() != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003062 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003063 return;
3064 }
3065 int32_t iFrom = pArguments->GetInt32(0);
3066 int32_t iTo = pArguments->GetInt32(1);
3067 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003068 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003069 if (!pNotify) {
3070 return;
3071 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003072 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003073 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003074 pNotify->RunSubformIndexChange(pToInstance);
3075 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003076 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003077 if (pFromInstance &&
3078 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003079 pNotify->RunSubformIndexChange(pFromInstance);
3080 }
3081}
dsinclair5b36f0a2016-07-19 10:56:23 -07003082
Dan Sinclair1770c022016-03-14 14:14:16 -04003083void CXFA_Node::Script_InstanceManager_RemoveInstance(
3084 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003085 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003086 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003087 return;
3088 }
3089 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003090 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003091 if (iIndex < 0 || iIndex >= iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003092 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003093 return;
3094 }
3095 CXFA_Occur nodeOccur(GetOccurNode());
3096 int32_t iMin = nodeOccur.GetMin();
3097 if (iCount - 1 < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003098 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003099 return;
3100 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003101 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3102 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003103 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003104 if (pNotify) {
3105 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003106 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003107 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003108 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003109 pNotify->RunSubformIndexChange(pSubformInstance);
3110 }
3111 }
3112 }
3113 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3114 if (!pLayoutPro) {
3115 return;
3116 }
3117 pLayoutPro->AddChangedContainer(
3118 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3119}
dsinclair5b36f0a2016-07-19 10:56:23 -07003120
Dan Sinclair1770c022016-03-14 14:14:16 -04003121void CXFA_Node::Script_InstanceManager_SetInstances(
3122 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003123 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003124 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003125 return;
3126 }
3127 int32_t iDesired = pArguments->GetInt32(0);
3128 InstanceManager_SetInstances(iDesired);
3129}
dsinclair5b36f0a2016-07-19 10:56:23 -07003130
Dan Sinclair1770c022016-03-14 14:14:16 -04003131void CXFA_Node::Script_InstanceManager_AddInstance(
3132 CFXJSE_Arguments* pArguments) {
3133 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003134 if (argc != 0 && argc != 1) {
3135 ThrowParamCountMismatchException(L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003136 return;
3137 }
tsepezd19e9122016-11-02 15:43:18 -07003138 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003139 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003140 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003141 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003142 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003143 CXFA_Occur nodeOccur(GetOccurNode());
3144 int32_t iMax = nodeOccur.GetMax();
3145 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003146 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003147 return;
3148 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003149 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003150 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003151 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003152 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003153 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003154 if (!pNotify) {
3155 return;
3156 }
3157 pNotify->RunNodeInitialize(pNewInstance);
3158 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3159 if (!pLayoutPro) {
3160 return;
3161 }
3162 pLayoutPro->AddChangedContainer(
3163 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3164}
dsinclair5b36f0a2016-07-19 10:56:23 -07003165
Dan Sinclair1770c022016-03-14 14:14:16 -04003166void CXFA_Node::Script_InstanceManager_InsertInstance(
3167 CFXJSE_Arguments* pArguments) {
3168 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003169 if (argc != 1 && argc != 2) {
3170 ThrowParamCountMismatchException(L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003171 return;
3172 }
3173 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003174 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003175 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003176 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003177 }
3178 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003179 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003180 if (iIndex < 0 || iIndex > iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003181 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003182 return;
3183 }
3184 int32_t iMax = nodeOccur.GetMax();
3185 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003186 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003187 return;
3188 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003189 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003190 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003191 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003192 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003193 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003194 if (!pNotify) {
3195 return;
3196 }
3197 pNotify->RunNodeInitialize(pNewInstance);
3198 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3199 if (!pLayoutPro) {
3200 return;
3201 }
3202 pLayoutPro->AddChangedContainer(
3203 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3204}
dsinclair5b36f0a2016-07-19 10:56:23 -07003205
Dan Sinclair1770c022016-03-14 14:14:16 -04003206int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3207 CXFA_Occur nodeOccur(GetOccurNode());
3208 int32_t iMax = nodeOccur.GetMax();
3209 int32_t iMin = nodeOccur.GetMin();
3210 if (iDesired < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003211 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003212 return 1;
3213 }
3214 if ((iMax >= 0) && (iDesired > iMax)) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003215 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003216 return 2;
3217 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003218 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003219 if (iDesired == iCount) {
3220 return 0;
3221 }
3222 if (iDesired < iCount) {
3223 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003224 CFX_WideString wsInstanceName =
3225 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3226 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003227 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003228 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003229 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003230 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003231 while (iCount > iDesired) {
3232 CXFA_Node* pRemoveInstance =
3233 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003234 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3235 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003236 continue;
3237 }
dsinclair070fcdf2016-06-22 22:04:54 -07003238 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003239 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003240 break;
3241 }
3242 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003243 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003244 iCount--;
3245 }
3246 }
3247 } else if (iDesired > iCount) {
3248 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003249 CXFA_Node* pNewInstance = CreateInstance(this, true);
3250 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003251 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003252 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003253 if (!pNotify) {
3254 return 0;
3255 }
3256 pNotify->RunNodeInitialize(pNewInstance);
3257 }
3258 }
3259 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3260 if (pLayoutPro) {
3261 pLayoutPro->AddChangedContainer(
3262 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3263 }
3264 return 0;
3265}
dsinclair5b36f0a2016-07-19 10:56:23 -07003266
Dan Sinclair1770c022016-03-14 14:14:16 -04003267int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003268 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003269 if (iFrom > iCount || iTo > iCount - 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003270 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003271 return 1;
3272 }
3273 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3274 return 0;
3275 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003276 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003277 RemoveItem(this, pMoveInstance, false);
3278 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003279 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3280 if (pLayoutPro) {
3281 pLayoutPro->AddChangedContainer(
3282 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3283 }
3284 return 0;
3285}
dsinclair5b36f0a2016-07-19 10:56:23 -07003286
dsinclair12a6b0c2016-05-26 11:14:08 -07003287void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003288 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003289 XFA_ATTRIBUTE eAttribute) {
3290 CXFA_Occur occur(this);
3291 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003292 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003293 occur.SetMax(iMax);
3294 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003295 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003296 }
3297}
dsinclair5b36f0a2016-07-19 10:56:23 -07003298
dsinclair12a6b0c2016-05-26 11:14:08 -07003299void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003300 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003301 XFA_ATTRIBUTE eAttribute) {
3302 CXFA_Occur occur(this);
3303 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003304 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003305 occur.SetMin(iMin);
3306 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003307 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003308 }
3309}
dsinclair5b36f0a2016-07-19 10:56:23 -07003310
Dan Sinclair1770c022016-03-14 14:14:16 -04003311void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3312 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003313 if (argc != 0 && argc != 1) {
3314 ThrowParamCountMismatchException(L"metadata");
3315 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003316 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003317 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003318}
dsinclair5b36f0a2016-07-19 10:56:23 -07003319
Dan Sinclair1770c022016-03-14 14:14:16 -04003320void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003321 if (pArguments->GetLength() != 1) {
3322 ThrowParamCountMismatchException(L"formNodes");
3323 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003324 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003325
3326 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3327 if (!pDataNode) {
3328 ThrowArgumentMismatchException();
3329 return;
3330 }
3331
3332 CXFA_NodeArray formItems;
3333 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3334 pFormNodes->SetArrayNodeList(formItems);
3335 pArguments->GetReturnValue()->SetObject(
3336 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003337}
dsinclair5b36f0a2016-07-19 10:56:23 -07003338
Dan Sinclair1770c022016-03-14 14:14:16 -04003339void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003340 if (pArguments->GetLength() != 0) {
3341 ThrowParamCountMismatchException(L"remerge");
3342 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003343 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003344
3345 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003346}
dsinclair5b36f0a2016-07-19 10:56:23 -07003347
Dan Sinclair1770c022016-03-14 14:14:16 -04003348void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003349 if (pArguments->GetLength() != 0) {
3350 ThrowParamCountMismatchException(L"execInitialize");
3351 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003352 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003353
3354 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3355 if (!pNotify)
3356 return;
3357
3358 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04003359}
dsinclair5b36f0a2016-07-19 10:56:23 -07003360
Dan Sinclair1770c022016-03-14 14:14:16 -04003361void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3362 CXFA_EventParam* pEventParam =
3363 m_pDocument->GetScriptContext()->GetEventParam();
3364 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3365 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3366 return;
3367 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003368 if (pArguments->GetLength() != 1) {
3369 ThrowParamCountMismatchException(L"recalculate");
3370 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003371 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003372
3373 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3374 if (!pNotify)
3375 return;
3376 if (pArguments->GetInt32(0) != 0)
3377 return;
3378
3379 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3380 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3381 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003382}
dsinclair5b36f0a2016-07-19 10:56:23 -07003383
Dan Sinclair1770c022016-03-14 14:14:16 -04003384void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003385 if (pArguments->GetLength() != 0) {
3386 ThrowParamCountMismatchException(L"execCalculate");
3387 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003388 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003389
3390 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3391 if (!pNotify)
3392 return;
3393
3394 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04003395}
dsinclair5b36f0a2016-07-19 10:56:23 -07003396
Dan Sinclair1770c022016-03-14 14:14:16 -04003397void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003398 if (pArguments->GetLength() != 0) {
3399 ThrowParamCountMismatchException(L"execValidate");
3400 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003401 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003402
3403 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3404 if (!pNotify) {
3405 pArguments->GetReturnValue()->SetBoolean(false);
3406 return;
3407 }
3408
3409 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3410 pArguments->GetReturnValue()->SetBoolean(
3411 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003412}
dsinclair5b36f0a2016-07-19 10:56:23 -07003413
dsinclair12a6b0c2016-05-26 11:14:08 -07003414void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003415 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003416 XFA_ATTRIBUTE eAttribute) {
3417 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003418 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003419 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003420 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003421
3422 CFX_WideString wsChecksum;
3423 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
3424 pValue->SetString(
3425 FX_UTF8Encode(wsChecksum.c_str(), wsChecksum.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003426}
dsinclair5b36f0a2016-07-19 10:56:23 -07003427
Dan Sinclair1770c022016-03-14 14:14:16 -04003428void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003429 if (pArguments->GetLength() != 1) {
3430 ThrowParamCountMismatchException(L"getAttribute");
3431 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003432 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003433
3434 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3435 CFX_WideString wsAttributeValue;
3436 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3437 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3438 static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3439 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(),
3440 wsAttributeValue);
3441 }
3442 pArguments->GetReturnValue()->SetString(
3443 FX_UTF8Encode(wsAttributeValue.c_str(), wsAttributeValue.GetLength())
3444 .AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003445}
dsinclair5b36f0a2016-07-19 10:56:23 -07003446
Dan Sinclair1770c022016-03-14 14:14:16 -04003447void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003448 if (pArguments->GetLength() != 2) {
3449 ThrowParamCountMismatchException(L"setAttribute");
3450 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003451 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003452
3453 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3454 CFX_ByteString bsName = pArguments->GetUTF8String(1);
3455 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3456 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3457 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(
3458 CFX_WideString::FromUTF8(bsName.AsStringC()),
3459 CFX_WideString::FromUTF8(bsValue.AsStringC()));
3460 }
3461 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003462}
dsinclair5b36f0a2016-07-19 10:56:23 -07003463
Dan Sinclair1770c022016-03-14 14:14:16 -04003464void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003465 if (pArguments->GetLength() != 1) {
3466 ThrowParamCountMismatchException(L"removeAttribute");
3467 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003468 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003469
3470 CFX_ByteString bsName = pArguments->GetUTF8String(0);
3471 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
3472 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3473 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3474 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
3475 if (pXMLElement->HasAttribute(wsName.c_str())) {
3476 pXMLElement->RemoveAttribute(wsName.c_str());
3477 }
3478 }
3479 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003480}
dsinclair5b36f0a2016-07-19 10:56:23 -07003481
dsinclair12a6b0c2016-05-26 11:14:08 -07003482void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003483 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003484 XFA_ATTRIBUTE eAttribute) {
3485 if (bSetting) {
dsinclairae95f762016-03-29 16:58:29 -07003486 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003487 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003488 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003489 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003490 }
3491 } else {
3492 CFX_WideString wsTextData;
dsinclairae95f762016-03-29 16:58:29 -07003493 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003494 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003495 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04003496 pXMLElement->GetTextData(wsTextData);
3497 }
dsinclairf27aeec2016-06-07 19:36:18 -07003498 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003499 FX_UTF8Encode(wsTextData.c_str(), wsTextData.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003500 }
3501}
dsinclair5b36f0a2016-07-19 10:56:23 -07003502
Dan Sinclair1770c022016-03-14 14:14:16 -04003503void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003504 if (pArguments->GetLength() != 0)
3505 ThrowParamCountMismatchException(L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003506}
dsinclair5b36f0a2016-07-19 10:56:23 -07003507
Dan Sinclair1770c022016-03-14 14:14:16 -04003508void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003509 if (pArguments->GetLength() != 0)
3510 ThrowParamCountMismatchException(L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003511}
dsinclair5b36f0a2016-07-19 10:56:23 -07003512
Dan Sinclair1770c022016-03-14 14:14:16 -04003513void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003514 if (pArguments->GetLength() != 0)
3515 ThrowParamCountMismatchException(L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003516}
dsinclair5b36f0a2016-07-19 10:56:23 -07003517
Dan Sinclair1770c022016-03-14 14:14:16 -04003518void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003519 if (pArguments->GetLength() != 0)
3520 ThrowParamCountMismatchException(L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003521}
dsinclair5b36f0a2016-07-19 10:56:23 -07003522
Dan Sinclair1770c022016-03-14 14:14:16 -04003523void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003524 if (pArguments->GetLength() != 0)
3525 ThrowParamCountMismatchException(L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003526}
dsinclair5b36f0a2016-07-19 10:56:23 -07003527
Dan Sinclair1770c022016-03-14 14:14:16 -04003528void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003529 if (pArguments->GetLength() != 0)
3530 ThrowParamCountMismatchException(L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003531}
dsinclair5b36f0a2016-07-19 10:56:23 -07003532
Dan Sinclair1770c022016-03-14 14:14:16 -04003533void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003534 if (pArguments->GetLength() != 0)
3535 ThrowParamCountMismatchException(L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003536}
dsinclair5b36f0a2016-07-19 10:56:23 -07003537
Dan Sinclair1770c022016-03-14 14:14:16 -04003538void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003539 if (pArguments->GetLength() != 0)
3540 ThrowParamCountMismatchException(L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003541}
dsinclair5b36f0a2016-07-19 10:56:23 -07003542
Dan Sinclair1770c022016-03-14 14:14:16 -04003543void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003544 if (pArguments->GetLength() != 0)
3545 ThrowParamCountMismatchException(L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003546}
dsinclair5b36f0a2016-07-19 10:56:23 -07003547
Dan Sinclair1770c022016-03-14 14:14:16 -04003548void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003549 if (pArguments->GetLength() != 0)
3550 ThrowParamCountMismatchException(L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003551}
dsinclair5b36f0a2016-07-19 10:56:23 -07003552
Dan Sinclair1770c022016-03-14 14:14:16 -04003553void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003554 if (pArguments->GetLength() != 0)
3555 ThrowParamCountMismatchException(L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003556}
dsinclair5b36f0a2016-07-19 10:56:23 -07003557
Dan Sinclair1770c022016-03-14 14:14:16 -04003558void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003559 if (pArguments->GetLength() != 0)
3560 ThrowParamCountMismatchException(L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003561}
dsinclair5b36f0a2016-07-19 10:56:23 -07003562
Dan Sinclair1770c022016-03-14 14:14:16 -04003563void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003564 if (pArguments->GetLength() != 0)
3565 ThrowParamCountMismatchException(L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003566}
dsinclair5b36f0a2016-07-19 10:56:23 -07003567
Dan Sinclair1770c022016-03-14 14:14:16 -04003568void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003569 if (pArguments->GetLength() != 0)
3570 ThrowParamCountMismatchException(L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003571}
dsinclair5b36f0a2016-07-19 10:56:23 -07003572
Dan Sinclair1770c022016-03-14 14:14:16 -04003573void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003574 if (pArguments->GetLength() != 0)
3575 ThrowParamCountMismatchException(L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003576}
dsinclair5b36f0a2016-07-19 10:56:23 -07003577
Dan Sinclair1770c022016-03-14 14:14:16 -04003578void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003579 if (pArguments->GetLength() != 0)
3580 ThrowParamCountMismatchException(L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003581}
dsinclair5b36f0a2016-07-19 10:56:23 -07003582
Dan Sinclair1770c022016-03-14 14:14:16 -04003583void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003584 if (pArguments->GetLength() != 0)
3585 ThrowParamCountMismatchException(L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003586}
dsinclair5b36f0a2016-07-19 10:56:23 -07003587
dsinclair12a6b0c2016-05-26 11:14:08 -07003588void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003589 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003590 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003591
dsinclair12a6b0c2016-05-26 11:14:08 -07003592void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003593 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003594 XFA_ATTRIBUTE eAttribute) {
3595 if (!bSetting) {
3596 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003597 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003598 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003599 }
3600}
dsinclair5b36f0a2016-07-19 10:56:23 -07003601
dsinclair12a6b0c2016-05-26 11:14:08 -07003602void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003603 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003604 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003605
dsinclair12a6b0c2016-05-26 11:14:08 -07003606void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003607 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003608 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003609
dsinclair12a6b0c2016-05-26 11:14:08 -07003610void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003611 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003612 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003613
dsinclair12a6b0c2016-05-26 11:14:08 -07003614void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003615 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003616 XFA_ATTRIBUTE eAttribute) {
3617 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003618 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003619 return;
3620 }
dsinclairf27aeec2016-06-07 19:36:18 -07003621 pValue->SetString(FX_UTF8Encode(FX_WSTRC(L"0")).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003622}
dsinclair5b36f0a2016-07-19 10:56:23 -07003623
dsinclair12a6b0c2016-05-26 11:14:08 -07003624void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003625 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003626 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003627
tsepezd19e9122016-11-02 15:43:18 -07003628bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003629 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003630 return HasMapModuleKey(pKey, bCanInherit);
3631}
dsinclair5b36f0a2016-07-19 10:56:23 -07003632
tsepezd19e9122016-11-02 15:43:18 -07003633bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3634 const CFX_WideStringC& wsValue,
3635 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003636 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003637 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003638 return false;
weili44f8faf2016-06-01 14:03:56 -07003639
Dan Sinclair1770c022016-03-14 14:14:16 -04003640 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3641 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3642 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003643 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003644 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3645 }
3646 switch (eType) {
3647 case XFA_ATTRIBUTETYPE_Enum: {
3648 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3649 return SetEnum(pAttr->eName,
3650 pEnum ? pEnum->eName
3651 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3652 bNotify);
3653 } break;
3654 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003655 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003656 case XFA_ATTRIBUTETYPE_Boolean:
3657 return SetBoolean(pAttr->eName, wsValue != FX_WSTRC(L"0"), bNotify);
3658 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003659 return SetInteger(pAttr->eName,
3660 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3661 wsValue.GetLength(), nullptr)),
3662 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003663 case XFA_ATTRIBUTETYPE_Measure:
3664 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3665 default:
3666 break;
3667 }
tsepezd19e9122016-11-02 15:43:18 -07003668 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003669}
dsinclair5b36f0a2016-07-19 10:56:23 -07003670
tsepezd19e9122016-11-02 15:43:18 -07003671bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3672 CFX_WideString& wsValue,
3673 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003674 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003675 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003676 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003677 }
3678 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3679 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3680 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003681 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003682 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3683 }
3684 switch (eType) {
3685 case XFA_ATTRIBUTETYPE_Enum: {
3686 XFA_ATTRIBUTEENUM eValue;
3687 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003688 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003689 }
dsinclair9eb0db12016-07-21 12:01:39 -07003690 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003691 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003692 } break;
3693 case XFA_ATTRIBUTETYPE_Cdata: {
3694 CFX_WideStringC wsValueC;
3695 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003696 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003697 }
3698 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003699 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003700 } break;
3701 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003702 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003703 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003704 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003705 }
3706 wsValue = bValue ? FX_WSTRC(L"1") : FX_WSTRC(L"0");
tsepezd19e9122016-11-02 15:43:18 -07003707 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003708 } break;
3709 case XFA_ATTRIBUTETYPE_Integer: {
3710 int32_t iValue;
3711 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003712 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003713 }
3714 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003715 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003716 } break;
3717 case XFA_ATTRIBUTETYPE_Measure: {
3718 CXFA_Measurement mValue;
3719 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003720 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003721 }
3722 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003723 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003724 } break;
3725 default:
3726 break;
3727 }
tsepezd19e9122016-11-02 15:43:18 -07003728 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003729}
dsinclair5b36f0a2016-07-19 10:56:23 -07003730
tsepezd19e9122016-11-02 15:43:18 -07003731bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3732 const CFX_WideStringC& wsValue,
3733 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003734 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3735 if (pAttributeInfo) {
3736 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3737 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003738 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003739 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003740 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003741}
dsinclair5b36f0a2016-07-19 10:56:23 -07003742
tsepezd19e9122016-11-02 15:43:18 -07003743bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3744 CFX_WideString& wsValue,
3745 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003746 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3747 if (pAttributeInfo) {
3748 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3749 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003750 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003751 CFX_WideStringC wsValueC;
3752 if (GetMapModuleString(pKey, wsValueC)) {
3753 wsValue = wsValueC;
3754 }
tsepezd19e9122016-11-02 15:43:18 -07003755 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003756}
dsinclair5b36f0a2016-07-19 10:56:23 -07003757
tsepezd19e9122016-11-02 15:43:18 -07003758bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003759 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003760 RemoveMapModuleKey(pKey);
tsepezd19e9122016-11-02 15:43:18 -07003761 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003762}
dsinclair5b36f0a2016-07-19 10:56:23 -07003763
tsepezd19e9122016-11-02 15:43:18 -07003764bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3765 bool& bValue,
3766 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003767 void* pValue = nullptr;
3768 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003769 return false;
tsepez478ed622016-10-27 14:32:33 -07003770 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003771 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003772}
dsinclair5b36f0a2016-07-19 10:56:23 -07003773
tsepezd19e9122016-11-02 15:43:18 -07003774bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3775 int32_t& iValue,
3776 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003777 void* pValue = nullptr;
3778 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003779 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003780 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003781 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003782}
dsinclair5b36f0a2016-07-19 10:56:23 -07003783
tsepezd19e9122016-11-02 15:43:18 -07003784bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3785 XFA_ATTRIBUTEENUM& eValue,
3786 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003787 void* pValue = nullptr;
3788 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003789 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003790 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003791 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003792}
thestigb1a59592016-04-14 18:29:56 -07003793
tsepezd19e9122016-11-02 15:43:18 -07003794bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3795 CXFA_Measurement mValue,
3796 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003797 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003798 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003799 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003800 OnChanged(eAttr, bNotify, false);
3801 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003802}
thestigb1a59592016-04-14 18:29:56 -07003803
tsepezd19e9122016-11-02 15:43:18 -07003804bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3805 CXFA_Measurement& mValue,
3806 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003807 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003808 void* pValue;
3809 int32_t iBytes;
3810 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
3811 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003812 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003813 }
3814 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003815 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003816 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
3817 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003818 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003819 }
tsepezd19e9122016-11-02 15:43:18 -07003820 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003821}
3822
3823CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3824 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003825 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003826}
3827
tsepezd19e9122016-11-02 15:43:18 -07003828bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3829 const CFX_WideString& wsValue,
3830 bool bNotify,
3831 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003832 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003833 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003834 if (eAttr == XFA_ATTRIBUTE_Value) {
3835 CFX_WideString* pClone = new CFX_WideString(wsValue);
3836 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3837 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003838 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003839 if (eAttr == XFA_ATTRIBUTE_Name)
3840 UpdateNameHash();
3841 }
thestigb1a59592016-04-14 18:29:56 -07003842 OnChanged(eAttr, bNotify, bScriptModify);
3843
3844 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3845 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003846 return true;
thestigb1a59592016-04-14 18:29:56 -07003847 }
3848
dsinclair070fcdf2016-06-22 22:04:54 -07003849 if (eAttr == XFA_ATTRIBUTE_Name &&
3850 (m_elementType == XFA_Element::DataValue ||
3851 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003852 return true;
thestigb1a59592016-04-14 18:29:56 -07003853 }
3854
3855 if (eAttr == XFA_ATTRIBUTE_Value) {
3856 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3857 switch (eXMLType) {
3858 case FDE_XMLNODE_Element:
3859 if (IsAttributeInXML()) {
3860 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003861 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3862 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003863 } else {
tsepezd19e9122016-11-02 15:43:18 -07003864 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003865 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3866 for (CXFA_Node* pChildDataNode =
3867 GetNodeItem(XFA_NODEITEM_FirstChild);
3868 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3869 XFA_NODEITEM_NextSibling)) {
3870 CXFA_NodeArray formNodes;
3871 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003872 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003873 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003874 }
3875 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003876 }
thestigb1a59592016-04-14 18:29:56 -07003877 if (bDeleteChildren) {
3878 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3879 }
3880 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3881 }
3882 break;
3883 case FDE_XMLNODE_Text:
3884 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3885 break;
3886 default:
dsinclair43854a52016-04-27 12:26:00 -07003887 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003888 }
tsepezd19e9122016-11-02 15:43:18 -07003889 return true;
thestigb1a59592016-04-14 18:29:56 -07003890 }
3891
3892 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3893 if (pInfo) {
dsinclair43854a52016-04-27 12:26:00 -07003894 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003895 CFX_WideString wsAttrName = pInfo->pName;
3896 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
3897 wsAttrName = FX_WSTRC(L"xfa:") + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003898 }
thestigb1a59592016-04-14 18:29:56 -07003899 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003900 }
tsepezd19e9122016-11-02 15:43:18 -07003901 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003902}
thestigb1a59592016-04-14 18:29:56 -07003903
tsepezd19e9122016-11-02 15:43:18 -07003904bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3905 const CFX_WideString& wsXMLValue,
3906 bool bNotify,
3907 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003908 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003909 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003910 CFX_WideString* pClone = new CFX_WideString(wsValue);
3911 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003912 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003913 if (IsNeedSavingXMLNode()) {
3914 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3915 switch (eXMLType) {
3916 case FDE_XMLNODE_Element:
3917 if (IsAttributeInXML()) {
dsinclairae95f762016-03-29 16:58:29 -07003918 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003919 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3920 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003921 } else {
tsepezd19e9122016-11-02 15:43:18 -07003922 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003923 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3924 for (CXFA_Node* pChildDataNode =
3925 GetNodeItem(XFA_NODEITEM_FirstChild);
3926 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3927 XFA_NODEITEM_NextSibling)) {
3928 CXFA_NodeArray formNodes;
3929 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003930 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003931 break;
3932 }
3933 }
3934 }
3935 if (bDeleteChildren) {
dsinclairae95f762016-03-29 16:58:29 -07003936 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003937 }
dsinclairae95f762016-03-29 16:58:29 -07003938 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003939 }
3940 break;
3941 case FDE_XMLNODE_Text:
dsinclairae95f762016-03-29 16:58:29 -07003942 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003943 break;
3944 default:
dsinclair43854a52016-04-27 12:26:00 -07003945 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003946 }
3947 }
tsepezd19e9122016-11-02 15:43:18 -07003948 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003949}
dsinclair5b36f0a2016-07-19 10:56:23 -07003950
tsepezd19e9122016-11-02 15:43:18 -07003951bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3952 CFX_WideString& wsValue,
3953 bool bUseDefault,
3954 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003955 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003956 if (eAttr == XFA_ATTRIBUTE_Value) {
3957 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3958 if (pStr) {
3959 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07003960 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003961 }
3962 } else {
3963 CFX_WideStringC wsValueC;
3964 if (GetMapModuleString(pKey, wsValueC)) {
3965 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003966 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003967 }
3968 }
3969 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003970 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003971 }
weili44f8faf2016-06-01 14:03:56 -07003972 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003973 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003974 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
3975 wsValue = (const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003976 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003977 }
tsepezd19e9122016-11-02 15:43:18 -07003978 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003979}
dsinclair5b36f0a2016-07-19 10:56:23 -07003980
tsepezd19e9122016-11-02 15:43:18 -07003981bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3982 CFX_WideStringC& wsValue,
3983 bool bUseDefault,
3984 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003985 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003986 if (eAttr == XFA_ATTRIBUTE_Value) {
3987 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3988 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07003989 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07003990 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003991 }
3992 } else {
3993 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003994 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003995 }
3996 }
3997 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003998 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003999 }
weili44f8faf2016-06-01 14:03:56 -07004000 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07004001 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04004002 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
4003 wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07004004 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004005 }
tsepezd19e9122016-11-02 15:43:18 -07004006 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004007}
dsinclair5b36f0a2016-07-19 10:56:23 -07004008
tsepezd19e9122016-11-02 15:43:18 -07004009bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
4010 void* pData,
4011 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004012 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004013 return SetUserData(pKey, pData, pCallbackInfo);
4014}
dsinclair5b36f0a2016-07-19 10:56:23 -07004015
tsepezd19e9122016-11-02 15:43:18 -07004016bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004017 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004018 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07004019 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04004020}
dsinclair5b36f0a2016-07-19 10:56:23 -07004021
tsepezd19e9122016-11-02 15:43:18 -07004022bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
4023 XFA_ATTRIBUTETYPE eType,
4024 void* pValue,
4025 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004026 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07004027 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004028 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07004029 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004030 if (IsNeedSavingXMLNode()) {
dsinclair43854a52016-04-27 12:26:00 -07004031 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004032 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
4033 if (pInfo) {
4034 switch (eType) {
4035 case XFA_ATTRIBUTETYPE_Enum:
dsinclairae95f762016-03-29 16:58:29 -07004036 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004037 ->SetString(
4038 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07004039 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04004040 ->pName);
4041 break;
4042 case XFA_ATTRIBUTETYPE_Boolean:
dsinclairae95f762016-03-29 16:58:29 -07004043 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07004044 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04004045 break;
4046 case XFA_ATTRIBUTETYPE_Integer:
dsinclairae95f762016-03-29 16:58:29 -07004047 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004048 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue);
4049 break;
4050 default:
dsinclair43854a52016-04-27 12:26:00 -07004051 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04004052 }
4053 }
4054 }
tsepezd19e9122016-11-02 15:43:18 -07004055 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004056}
dsinclair5b36f0a2016-07-19 10:56:23 -07004057
tsepezd19e9122016-11-02 15:43:18 -07004058bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
4059 XFA_ATTRIBUTETYPE eType,
4060 bool bUseDefault,
4061 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004062 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004063 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004064 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004065 }
4066 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004067 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004068 }
dsinclair070fcdf2016-06-22 22:04:54 -07004069 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004070 m_ePacket);
4071}
dsinclair5b36f0a2016-07-19 10:56:23 -07004072
tsepezd19e9122016-11-02 15:43:18 -07004073bool CXFA_Node::SetUserData(void* pKey,
4074 void* pData,
4075 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004076 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4077 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004078 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004079}
dsinclair5b36f0a2016-07-19 10:56:23 -07004080
tsepezd19e9122016-11-02 15:43:18 -07004081bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004082 int32_t iBytes = 0;
4083 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004084 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004085 }
4086 return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes);
4087}
dsinclair5b36f0a2016-07-19 10:56:23 -07004088
tsepezd19e9122016-11-02 15:43:18 -07004089bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4090 const CFX_WideString& wsXMLValue,
4091 bool bNotify,
4092 bool bScriptModify,
4093 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004094 CXFA_Node* pNode = nullptr;
4095 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004096 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004097 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004098 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004099 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004100 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004101 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004102 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004103 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004104 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004105 CXFA_Node* pBind = GetBindData();
4106 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004107 std::vector<CFX_WideString> wsSaveTextArray;
Dan Sinclair1770c022016-03-14 14:14:16 -04004108 int32_t iSize = 0;
4109 if (!wsContent.IsEmpty()) {
4110 int32_t iStart = 0;
4111 int32_t iLength = wsContent.GetLength();
4112 int32_t iEnd = wsContent.Find(L'\n', iStart);
4113 iEnd = (iEnd == -1) ? iLength : iEnd;
4114 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004115 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004116 iStart = iEnd + 1;
4117 if (iStart >= iLength) {
4118 break;
4119 }
4120 iEnd = wsContent.Find(L'\n', iStart);
4121 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004122 wsSaveTextArray.push_back(
4123 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004124 }
4125 }
tsepez51709be2016-12-08 10:55:57 -08004126 iSize = pdfium::CollectionSize<int32_t>(wsSaveTextArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04004127 }
4128 if (iSize == 0) {
4129 while (CXFA_Node* pChildNode =
4130 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4131 pBind->RemoveChild(pChildNode);
4132 }
4133 } else {
4134 CXFA_NodeArray valueNodes;
4135 int32_t iDatas = pBind->GetNodeList(
dsinclair56a8b192016-06-21 14:15:25 -07004136 valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004137 if (iDatas < iSize) {
4138 int32_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004139 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004140 while (iAddNodes-- > 0) {
4141 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004142 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004143 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004144 pValueNodes->CreateXMLMappingNode();
4145 pBind->InsertChild(pValueNodes);
4146 }
weili44f8faf2016-06-01 14:03:56 -07004147 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004148 } else if (iDatas > iSize) {
4149 int32_t iDelNodes = iDatas - iSize;
4150 while (iDelNodes-- > 0) {
4151 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4152 }
4153 }
4154 int32_t i = 0;
4155 for (CXFA_Node* pValueNode =
4156 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4157 pValueNode; pValueNode = pValueNode->GetNodeItem(
4158 XFA_NODEITEM_NextSibling)) {
4159 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004160 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004161 i++;
4162 }
4163 }
4164 CXFA_NodeArray nodeArray;
4165 pBind->GetBindItems(nodeArray);
4166 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004167 if (nodeArray[i] != this) {
4168 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004169 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004170 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004171 }
4172 }
4173 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004174 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004175 pNode = this;
4176 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004177 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004178 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004179 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004180 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004181 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004182 }
4183 pBindNode = GetBindData();
4184 if (pBindNode && bSyncData) {
4185 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004186 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004187 CXFA_NodeArray nodeArray;
4188 pBindNode->GetBindItems(nodeArray);
4189 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004190 if (nodeArray[i] != this) {
4191 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true,
tsepezd19e9122016-11-02 15:43:18 -07004192 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004193 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004194 }
4195 }
weili44f8faf2016-06-01 14:03:56 -07004196 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004197 break;
4198 }
dsinclairc5a8f212016-06-20 11:11:12 -07004199 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004200 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004201 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004202 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
tsepez9f2970c2016-04-01 10:23:04 -07004203 if (wsContentType == FX_WSTRC(L"text/html")) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004204 wsContentType = FX_WSTRC(L"");
tsepez4c3debb2016-04-08 12:20:38 -07004205 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004206 }
4207 }
4208 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4209 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004210 pContentRawDataNode = CreateSamePacketNode(
dsinclair56a8b192016-06-21 14:15:25 -07004211 (wsContentType == FX_WSTRC(L"text/xml")) ? XFA_Element::Sharpxml
4212 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004213 InsertChild(pContentRawDataNode);
4214 }
4215 return pContentRawDataNode->SetScriptContent(
4216 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4217 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004218 case XFA_ObjectType::NodeC:
4219 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004220 pNode = this;
4221 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004222 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004223 pNode = this;
4224 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4225 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4226 if (pParent) {
4227 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4228 }
dsinclair070fcdf2016-06-22 22:04:54 -07004229 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004230 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4231 if (pParent && pParent->IsContainerNode()) {
4232 pBindNode = pParent->GetBindData();
4233 if (pBindNode) {
4234 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004235 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004236 }
4237 }
4238 }
4239 }
4240 break;
4241 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004242 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004243 pNode = this;
4244 pBindNode = this;
4245 }
4246 break;
4247 }
4248 if (pNode) {
4249 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4250 if (pBindNode && bSyncData) {
4251 CXFA_NodeArray nodeArray;
4252 pBindNode->GetBindItems(nodeArray);
4253 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004254 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004255 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004256 }
4257 }
tsepezd19e9122016-11-02 15:43:18 -07004258 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004259 }
tsepezd19e9122016-11-02 15:43:18 -07004260 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004261}
dsinclair5b36f0a2016-07-19 10:56:23 -07004262
tsepezd19e9122016-11-02 15:43:18 -07004263bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4264 const CFX_WideString& wsXMLValue,
4265 bool bNotify,
4266 bool bScriptModify,
4267 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004268 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4269 bSyncData);
4270}
dsinclair5b36f0a2016-07-19 10:56:23 -07004271
tsepezd19e9122016-11-02 15:43:18 -07004272CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004273 CFX_WideString wsContent;
4274 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4275}
dsinclair5b36f0a2016-07-19 10:56:23 -07004276
Dan Sinclair1770c022016-03-14 14:14:16 -04004277CFX_WideString CXFA_Node::GetContent() {
4278 return GetScriptContent();
4279}
dsinclair5b36f0a2016-07-19 10:56:23 -07004280
tsepezd19e9122016-11-02 15:43:18 -07004281bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4282 bool bScriptModify,
4283 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004284 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004285 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004286 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004287 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004288 pNode = this;
4289 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004290 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004291 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004292 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004293 }
4294 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4295 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
4296 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType,
4297 FX_WSTRC(L"text/xml"));
4298 }
4299 return pChildValue
4300 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004301 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004302 }
4303 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004304 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004305 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4306 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004307 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004308 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004309 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004310 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
tsepez9f2970c2016-04-01 10:23:04 -07004311 if (wsContentType == FX_WSTRC(L"text/html")) {
dsinclair56a8b192016-06-21 14:15:25 -07004312 element = XFA_Element::SharpxHTML;
tsepez9f2970c2016-04-01 10:23:04 -07004313 } else if (wsContentType == FX_WSTRC(L"text/xml")) {
dsinclair56a8b192016-06-21 14:15:25 -07004314 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004315 }
4316 }
4317 pContentRawDataNode = CreateSamePacketNode(element);
4318 InsertChild(pContentRawDataNode);
4319 }
4320 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4321 }
dsinclairc5a8f212016-06-20 11:11:12 -07004322 case XFA_ObjectType::NodeC:
4323 case XFA_ObjectType::NodeV:
4324 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004325 pNode = this;
4326 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004327 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004328 pNode = this;
4329 }
4330 break;
4331 }
4332 if (pNode) {
4333 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004334 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004335 if (pScriptContext) {
4336 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4337 }
4338 }
tsepezd19e9122016-11-02 15:43:18 -07004339 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004340 }
tsepezd19e9122016-11-02 15:43:18 -07004341 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004342}
dsinclair5b36f0a2016-07-19 10:56:23 -07004343
Dan Sinclair1770c022016-03-14 14:14:16 -04004344CXFA_Node* CXFA_Node::GetModelNode() {
4345 switch (GetPacketID()) {
4346 case XFA_XDPPACKET_XDP:
4347 return m_pDocument->GetRoot();
4348 case XFA_XDPPACKET_Config:
4349 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4350 case XFA_XDPPACKET_Template:
4351 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4352 case XFA_XDPPACKET_Form:
4353 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4354 case XFA_XDPPACKET_Datasets:
4355 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4356 case XFA_XDPPACKET_LocaleSet:
4357 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4358 case XFA_XDPPACKET_ConnectionSet:
4359 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4360 case XFA_XDPPACKET_SourceSet:
4361 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4362 case XFA_XDPPACKET_Xdc:
4363 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4364 default:
4365 return this;
4366 }
4367}
dsinclair5b36f0a2016-07-19 10:56:23 -07004368
tsepezd19e9122016-11-02 15:43:18 -07004369bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004370 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004371 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
dsinclairae95f762016-03-29 16:58:29 -07004372 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004373 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004374 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004375 }
dsinclairae95f762016-03-29 16:58:29 -07004376 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004377 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004378 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
dsinclairae95f762016-03-29 16:58:29 -07004379 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004380 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004381 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004382 }
4383 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004384 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004385 }
dsinclair070fcdf2016-06-22 22:04:54 -07004386 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004387 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4388 return XFA_FDEExtension_ResolveNamespaceQualifier(
dsinclairae95f762016-03-29 16:58:29 -07004389 static_cast<CFDE_XMLElement*>(pXMLNode),
4390 GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004391 }
dsinclairae95f762016-03-29 16:58:29 -07004392 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004393 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004394 } else {
4395 CXFA_Node* pModelNode = GetModelNode();
4396 return pModelNode->TryNamespace(wsNamespace);
4397 }
4398}
dsinclair5b36f0a2016-07-19 10:56:23 -07004399
Dan Sinclair1770c022016-03-14 14:14:16 -04004400CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004401 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004402 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004403 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004404 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004405 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004406 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004407 if (!pProperty || index >= pProperty->uOccur)
4408 return nullptr;
4409
Dan Sinclair1770c022016-03-14 14:14:16 -04004410 CXFA_Node* pNode = m_pChild;
4411 int32_t iCount = 0;
4412 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004413 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004414 iCount++;
4415 if (iCount > index) {
4416 return pNode;
4417 }
4418 }
4419 }
weili44f8faf2016-06-01 14:03:56 -07004420 if (!bCreateProperty)
4421 return nullptr;
4422
Dan Sinclair1770c022016-03-14 14:14:16 -04004423 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4424 pNode = m_pChild;
4425 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4426 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004427 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004428 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4429 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004430 }
4431 }
dsinclaira1b07722016-07-11 08:20:58 -07004432
Dan Sinclair1770c022016-03-14 14:14:16 -04004433 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004434 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004435 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004436 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004437 if (!pNewNode)
4438 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004439 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004440 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004441 }
4442 return pNewNode;
4443}
dsinclair5b36f0a2016-07-19 10:56:23 -07004444
tsepezd19e9122016-11-02 15:43:18 -07004445int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004446 CXFA_Node* pNode = m_pChild;
4447 int32_t iCount = 0;
4448 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004449 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004450 if (bOnlyChild) {
4451 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004452 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004453 if (pProperty) {
4454 continue;
4455 }
4456 }
4457 iCount++;
4458 }
4459 }
4460 return iCount;
4461}
dsinclair5b36f0a2016-07-19 10:56:23 -07004462
Dan Sinclair1770c022016-03-14 14:14:16 -04004463CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004464 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004465 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004466 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004467 CXFA_Node* pNode = m_pChild;
4468 int32_t iCount = 0;
4469 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004470 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004471 if (bOnlyChild) {
4472 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004473 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004474 if (pProperty) {
4475 continue;
4476 }
4477 }
4478 iCount++;
4479 if (iCount > index) {
4480 return pNode;
4481 }
4482 }
4483 }
weili44f8faf2016-06-01 14:03:56 -07004484 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004485}
dsinclair5b36f0a2016-07-19 10:56:23 -07004486
Dan Sinclair1770c022016-03-14 14:14:16 -04004487int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4488 ASSERT(!pNode->m_pNext);
4489 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004490 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004491 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004492 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004493
weili44f8faf2016-06-01 14:03:56 -07004494 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004495 if (index > 0) {
4496 return -1;
4497 }
4498 pNode->m_pNext = m_pChild;
4499 m_pChild = pNode;
4500 index = 0;
4501 } else if (index < 0) {
4502 m_pLastChild->m_pNext = pNode;
4503 } else {
4504 CXFA_Node* pPrev = m_pChild;
4505 int32_t iCount = 0;
4506 while (++iCount != index && pPrev->m_pNext) {
4507 pPrev = pPrev->m_pNext;
4508 }
4509 if (index > 0 && index != iCount) {
4510 return -1;
4511 }
4512 pNode->m_pNext = pPrev->m_pNext;
4513 pPrev->m_pNext = pNode;
4514 index = iCount;
4515 }
weili44f8faf2016-06-01 14:03:56 -07004516 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004517 m_pLastChild = pNode;
4518 }
4519 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004520 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004521 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004522 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004523 if (pNotify)
4524 pNotify->OnChildAdded(this);
4525
Dan Sinclair1770c022016-03-14 14:14:16 -04004526 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004527 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004528 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004529 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004530 }
4531 return index;
4532}
weili6e1ae862016-05-04 18:25:27 -07004533
tsepezd19e9122016-11-02 15:43:18 -07004534bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004535 if (!pNode || pNode->m_pParent ||
4536 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004537 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004538 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004539 }
tsepezd19e9122016-11-02 15:43:18 -07004540 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004541 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004542 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004543
4544 int32_t nIndex = -1;
4545 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004546 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004547 pNode->m_pNext = m_pChild;
4548 m_pChild = pNode;
4549 nIndex = 0;
4550 } else if (!pBeforeNode) {
4551 pNode->m_pNext = m_pLastChild->m_pNext;
4552 m_pLastChild->m_pNext = pNode;
4553 } else {
4554 nIndex = 1;
4555 CXFA_Node* pPrev = m_pChild;
4556 while (pPrev->m_pNext != pBeforeNode) {
4557 pPrev = pPrev->m_pNext;
4558 nIndex++;
4559 }
4560 pNode->m_pNext = pPrev->m_pNext;
4561 pPrev->m_pNext = pNode;
4562 }
weili44f8faf2016-06-01 14:03:56 -07004563 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004564 m_pLastChild = pNode;
4565 }
4566 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004567 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004568 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004569 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004570 if (pNotify)
4571 pNotify->OnChildAdded(this);
4572
Dan Sinclair1770c022016-03-14 14:14:16 -04004573 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004574 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004575 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004576 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004577 }
tsepezd19e9122016-11-02 15:43:18 -07004578 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004579}
dsinclair5b36f0a2016-07-19 10:56:23 -07004580
Dan Sinclair1770c022016-03-14 14:14:16 -04004581CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4582 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004583 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004584 }
4585 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4586 pSibling = pSibling->m_pNext) {
4587 if (pSibling->m_pNext == this) {
4588 return pSibling;
4589 }
4590 }
weili44f8faf2016-06-01 14:03:56 -07004591 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004592}
dsinclair5b36f0a2016-07-19 10:56:23 -07004593
tsepezd19e9122016-11-02 15:43:18 -07004594bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004595 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004596 ASSERT(false);
4597 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004598 }
4599 if (m_pChild == pNode) {
4600 m_pChild = pNode->m_pNext;
4601 if (m_pLastChild == pNode) {
4602 m_pLastChild = pNode->m_pNext;
4603 }
weili44f8faf2016-06-01 14:03:56 -07004604 pNode->m_pNext = nullptr;
4605 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004606 } else {
4607 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4608 pPrev->m_pNext = pNode->m_pNext;
4609 if (m_pLastChild == pNode) {
4610 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4611 }
weili44f8faf2016-06-01 14:03:56 -07004612 pNode->m_pNext = nullptr;
4613 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004614 }
weili44f8faf2016-06-01 14:03:56 -07004615 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004616 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004617 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004618 m_pDocument->AddPurgeNode(pNode);
4619 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4620 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004621 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4622 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004623 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07004624 CFDE_XMLElement* pXMLElement =
4625 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004626 CFX_WideStringC wsAttributeName =
4627 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004628 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004629 }
4630 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004631 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -07004632 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004633 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4634 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004635 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004636 }
4637 pNode->m_pXMLNode = pNewXMLElement;
4638 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4639 } else {
4640 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4641 }
dsinclairc5a8f212016-06-20 11:11:12 -07004642 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004643 }
tsepezd19e9122016-11-02 15:43:18 -07004644 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004645}
dsinclair5b36f0a2016-07-19 10:56:23 -07004646
Dan Sinclair1770c022016-03-14 14:14:16 -04004647CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004648 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004649}
dsinclair5b36f0a2016-07-19 10:56:23 -07004650
tsepez736f28a2016-03-25 14:19:51 -07004651CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004652 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4653 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4654 if (pNode->GetNameHash() == dwNameHash) {
4655 return pNode;
4656 }
4657 }
weili44f8faf2016-06-01 14:03:56 -07004658 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004659}
dsinclair5b36f0a2016-07-19 10:56:23 -07004660
dsinclair41cb62e2016-06-23 09:20:32 -07004661CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004662 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4663 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004664 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004665 return pNode;
4666 }
4667 }
weili44f8faf2016-06-01 14:03:56 -07004668 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004669}
dsinclair5b36f0a2016-07-19 10:56:23 -07004670
tsepez736f28a2016-03-25 14:19:51 -07004671CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004672 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4673 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4674 if (pNode->GetNameHash() == dwNameHash) {
4675 return pNode;
4676 }
4677 }
weili44f8faf2016-06-01 14:03:56 -07004678 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004679}
dsinclair5b36f0a2016-07-19 10:56:23 -07004680
Dan Sinclair1770c022016-03-14 14:14:16 -04004681CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4682 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004683 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004684}
dsinclair5b36f0a2016-07-19 10:56:23 -07004685
dsinclair41cb62e2016-06-23 09:20:32 -07004686CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004687 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4688 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004689 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004690 return pNode;
4691 }
4692 }
weili44f8faf2016-06-01 14:03:56 -07004693 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004694}
dsinclair5b36f0a2016-07-19 10:56:23 -07004695
Dan Sinclair1770c022016-03-14 14:14:16 -04004696int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004697 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004698 if (!pScriptContext) {
4699 return -1;
4700 }
4701 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4702}
dsinclair5b36f0a2016-07-19 10:56:23 -07004703
Dan Sinclair1770c022016-03-14 14:14:16 -04004704int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004705 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004706 if (!pScriptContext) {
4707 return -1;
4708 }
4709 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4710}
dsinclair5b36f0a2016-07-19 10:56:23 -07004711
Dan Sinclair1770c022016-03-14 14:14:16 -04004712void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004713 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004714 if (!pScriptContext) {
4715 return;
4716 }
4717 pScriptContext->GetSomExpression(this, wsSOMExpression);
4718}
dsinclair5b36f0a2016-07-19 10:56:23 -07004719
Dan Sinclair1770c022016-03-14 14:14:16 -04004720CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004721 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004722 if (m_ePacket == XFA_XDPPACKET_Form) {
4723 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004724 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004725 return pInstanceMgr;
4726 }
4727 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4728 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004729 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004730 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004731 pNode->m_dwNameHash != m_dwNameHash) {
4732 break;
4733 }
dsinclair56a8b192016-06-21 14:15:25 -07004734 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004735 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4736 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4737 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4738 wsInstName.Mid(1) == wsName) {
4739 pInstanceMgr = pNode;
4740 }
4741 break;
4742 }
4743 }
4744 }
4745 return pInstanceMgr;
4746}
dsinclair5b36f0a2016-07-19 10:56:23 -07004747
Dan Sinclair1770c022016-03-14 14:14:16 -04004748CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004749 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004750}
dsinclair5b36f0a2016-07-19 10:56:23 -07004751
dsinclairc5a8f212016-06-20 11:11:12 -07004752bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4753 if (m_uNodeFlags & dwFlag)
4754 return true;
4755 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4756 return m_pParent && m_pParent->HasFlag(dwFlag);
4757 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004758}
thestigb1a59592016-04-14 18:29:56 -07004759
4760void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004761 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004762 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004763 if (pNotify) {
4764 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004765 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004766 }
dsinclairc5a8f212016-06-20 11:11:12 -07004767 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004768}
thestigb1a59592016-04-14 18:29:56 -07004769
4770void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004771 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004772}
4773
tsepezd19e9122016-11-02 15:43:18 -07004774bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004775 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4776}
thestigb1a59592016-04-14 18:29:56 -07004777
4778void CXFA_Node::OnRemoved(bool bNotify) {
4779 if (!bNotify)
4780 return;
4781
dsinclaira1b07722016-07-11 08:20:58 -07004782 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004783 if (pNotify)
4784 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004785}
thestigb1a59592016-04-14 18:29:56 -07004786
4787void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004788 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004789 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004790 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004791 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004792 }
4793 }
4794}
thestigb1a59592016-04-14 18:29:56 -07004795
Dan Sinclair1770c022016-03-14 14:14:16 -04004796void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004797 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004798 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004799 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004800 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004801 }
4802}
thestigb1a59592016-04-14 18:29:56 -07004803
Dan Sinclair1770c022016-03-14 14:14:16 -04004804int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004805 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004806 int32_t iRet = XFA_EVENTERROR_NotExist;
4807 const XFA_ExecEventParaInfo* eventParaInfo =
4808 GetEventParaInfoByName(wsEventName);
4809 if (eventParaInfo) {
4810 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004811 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004812 if (!pNotify) {
4813 return iRet;
4814 }
4815 if (validFlags == 1) {
4816 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4817 } else if (validFlags == 2) {
4818 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004819 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004820 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004821 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004822 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004823 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004824 }
4825 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004826 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004827 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004828 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004829 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004830 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004831 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004832 }
4833 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004834 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004835 }
4836 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004837 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004838 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004839 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004840 }
4841 } else if (validFlags == 6) {
4842 CXFA_WidgetData* pWidgetData = GetWidgetData();
4843 if (pWidgetData) {
4844 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004845 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004846 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004847 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004848 }
4849 }
4850 } else if (validFlags == 7) {
4851 CXFA_WidgetData* pWidgetData = GetWidgetData();
4852 if (pWidgetData) {
4853 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004854 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004855 (!pWidgetData->IsListBox())) {
4856 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004857 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004858 }
4859 }
4860 }
4861 }
4862 return iRet;
4863}
dsinclair5b36f0a2016-07-19 10:56:23 -07004864
Dan Sinclair1770c022016-03-14 14:14:16 -04004865void CXFA_Node::UpdateNameHash() {
4866 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004867 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004868 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004869 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004870 wsName = GetCData(XFA_ATTRIBUTE_Name);
4871 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004872 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004873 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004874 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004875 }
4876}
dsinclair5b36f0a2016-07-19 10:56:23 -07004877
dsinclairae95f762016-03-29 16:58:29 -07004878CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004879 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004880 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
dsinclairae95f762016-03-29 16:58:29 -07004881 m_pXMLNode = new CFDE_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004882 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004883 }
4884 return m_pXMLNode;
4885}
dsinclair5b36f0a2016-07-19 10:56:23 -07004886
tsepezd19e9122016-11-02 15:43:18 -07004887bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004888 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004889 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004890}
4891
4892XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4893 if (!m_pMapModuleData)
4894 m_pMapModuleData = new XFA_MAPMODULEDATA;
4895 return m_pMapModuleData;
4896}
4897
4898XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4899 return m_pMapModuleData;
4900}
4901
4902void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4903 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004904 pModule->m_ValueMap[pKey] = pValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04004905}
4906
tsepezd19e9122016-11-02 15:43:18 -07004907bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
tsepez6bb3b892017-01-05 12:18:41 -08004908 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004909 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004910 if (pModule) {
4911 auto it = pModule->m_ValueMap.find(pKey);
4912 if (it != pModule->m_ValueMap.end()) {
4913 pValue = it->second;
4914 return true;
4915 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004916 }
tsepez6bb3b892017-01-05 12:18:41 -08004917 if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4918 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004919 }
tsepezd19e9122016-11-02 15:43:18 -07004920 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004921}
dsinclair5b36f0a2016-07-19 10:56:23 -07004922
Dan Sinclair1770c022016-03-14 14:14:16 -04004923void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004924 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair1770c022016-03-14 14:14:16 -04004925 wsValue.GetLength() * sizeof(FX_WCHAR));
4926}
dsinclair5b36f0a2016-07-19 10:56:23 -07004927
tsepezd19e9122016-11-02 15:43:18 -07004928bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004929 void* pValue;
4930 int32_t iBytes;
4931 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004932 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004933 }
4934 wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR));
tsepezd19e9122016-11-02 15:43:18 -07004935 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004936}
dsinclair5b36f0a2016-07-19 10:56:23 -07004937
Dan Sinclair1770c022016-03-14 14:14:16 -04004938void CXFA_Node::SetMapModuleBuffer(
4939 void* pKey,
4940 void* pValue,
4941 int32_t iBytes,
4942 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4943 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4944 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004945 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004946 pBuffer =
4947 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4948 } else if (pBuffer->iBytes != iBytes) {
4949 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4950 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4951 }
4952 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4953 sizeof(XFA_MAPDATABLOCK) + iBytes);
4954 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4955 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4956 }
weili44f8faf2016-06-01 14:03:56 -07004957 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04004958 return;
weili44f8faf2016-06-01 14:03:56 -07004959
Dan Sinclair1770c022016-03-14 14:14:16 -04004960 pBuffer->pCallbackInfo = pCallbackInfo;
4961 pBuffer->iBytes = iBytes;
4962 FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes);
4963}
dsinclair5b36f0a2016-07-19 10:56:23 -07004964
tsepezd19e9122016-11-02 15:43:18 -07004965bool CXFA_Node::GetMapModuleBuffer(void* pKey,
4966 void*& pValue,
4967 int32_t& iBytes,
4968 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07004969 XFA_MAPDATABLOCK* pBuffer = nullptr;
tsepez6bb3b892017-01-05 12:18:41 -08004970 for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004971 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004972 if (pModule) {
4973 auto it = pModule->m_BufferMap.find(pKey);
4974 if (it != pModule->m_BufferMap.end()) {
4975 pBuffer = it->second;
4976 break;
4977 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004978 }
tsepez6bb3b892017-01-05 12:18:41 -08004979 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4980 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004981 }
tsepez6bb3b892017-01-05 12:18:41 -08004982 if (!pBuffer)
tsepezd19e9122016-11-02 15:43:18 -07004983 return false;
tsepez6bb3b892017-01-05 12:18:41 -08004984
Dan Sinclair1770c022016-03-14 14:14:16 -04004985 pValue = pBuffer->GetData();
4986 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07004987 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004988}
dsinclair5b36f0a2016-07-19 10:56:23 -07004989
tsepezd19e9122016-11-02 15:43:18 -07004990bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
tsepez6bb3b892017-01-05 12:18:41 -08004991 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004992 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004993 if (pModule) {
4994 auto it1 = pModule->m_ValueMap.find(pKey);
4995 if (it1 != pModule->m_ValueMap.end())
4996 return true;
4997
4998 auto it2 = pModule->m_BufferMap.find(pKey);
4999 if (it2 != pModule->m_BufferMap.end())
5000 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005001 }
tsepez6bb3b892017-01-05 12:18:41 -08005002 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
5003 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04005004 }
tsepezd19e9122016-11-02 15:43:18 -07005005 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005006}
dsinclair5b36f0a2016-07-19 10:56:23 -07005007
Dan Sinclair1770c022016-03-14 14:14:16 -04005008void CXFA_Node::RemoveMapModuleKey(void* pKey) {
5009 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
5010 if (!pModule)
5011 return;
5012
5013 if (pKey) {
tsepez6bb3b892017-01-05 12:18:41 -08005014 auto it = pModule->m_BufferMap.find(pKey);
5015 if (it != pModule->m_BufferMap.end()) {
5016 XFA_MAPDATABLOCK* pBuffer = it->second;
Dan Sinclair1770c022016-03-14 14:14:16 -04005017 if (pBuffer) {
tsepez6bb3b892017-01-05 12:18:41 -08005018 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
Dan Sinclair1770c022016-03-14 14:14:16 -04005019 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005020 FX_Free(pBuffer);
5021 }
tsepez6bb3b892017-01-05 12:18:41 -08005022 pModule->m_BufferMap.erase(it);
Dan Sinclair1770c022016-03-14 14:14:16 -04005023 }
tsepez6bb3b892017-01-05 12:18:41 -08005024 pModule->m_ValueMap.erase(pKey);
5025 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04005026 }
tsepez6bb3b892017-01-05 12:18:41 -08005027
5028 for (auto& pair : pModule->m_BufferMap) {
5029 XFA_MAPDATABLOCK* pBuffer = pair.second;
5030 if (pBuffer) {
5031 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
5032 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5033 FX_Free(pBuffer);
5034 }
5035 }
5036 pModule->m_BufferMap.clear();
5037 pModule->m_ValueMap.clear();
5038 delete pModule;
Dan Sinclair1770c022016-03-14 14:14:16 -04005039}
dsinclair5b36f0a2016-07-19 10:56:23 -07005040
tsepez6bb3b892017-01-05 12:18:41 -08005041void CXFA_Node::MergeAllData(void* pDstModule) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005042 XFA_MAPMODULEDATA* pDstModuleData =
5043 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
5044 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08005045 if (!pSrcModuleData)
Dan Sinclair1770c022016-03-14 14:14:16 -04005046 return;
tsepez6bb3b892017-01-05 12:18:41 -08005047
5048 for (const auto& pair : pSrcModuleData->m_ValueMap)
5049 pDstModuleData->m_ValueMap[pair.first] = pair.second;
5050
5051 for (const auto& pair : pSrcModuleData->m_BufferMap) {
5052 XFA_MAPDATABLOCK* pSrcBuffer = pair.second;
5053 XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first];
Dan Sinclair1770c022016-03-14 14:14:16 -04005054 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
5055 !pSrcBuffer->pCallbackInfo->pCopy) {
tsepez6bb3b892017-01-05 12:18:41 -08005056 if (pDstBuffer) {
5057 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
5058 pDstModuleData->m_BufferMap.erase(pair.first);
Dan Sinclair1770c022016-03-14 14:14:16 -04005059 }
5060 continue;
5061 }
tsepez6bb3b892017-01-05 12:18:41 -08005062 if (!pDstBuffer) {
5063 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
Dan Sinclair1770c022016-03-14 14:14:16 -04005064 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08005065 } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) {
5066 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5067 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005068 }
tsepez6bb3b892017-01-05 12:18:41 -08005069 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
5070 uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5071 } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5072 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005073 }
tsepez6bb3b892017-01-05 12:18:41 -08005074 if (!pDstBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005075 continue;
5076 }
tsepez6bb3b892017-01-05 12:18:41 -08005077 pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5078 pDstBuffer->iBytes = pSrcBuffer->iBytes;
5079 FXSYS_memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(),
5080 pSrcBuffer->iBytes);
5081 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) {
5082 pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005083 }
5084 }
5085}
dsinclair5b36f0a2016-07-19 10:56:23 -07005086
Dan Sinclair1770c022016-03-14 14:14:16 -04005087void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5088 if (!pDstModule) {
5089 return;
5090 }
tsepezd19e9122016-11-02 15:43:18 -07005091 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005092 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005093 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005094 }
dsinclair070fcdf2016-06-22 22:04:54 -07005095 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005096 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005097 }
weili44f8faf2016-06-01 14:03:56 -07005098 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5099 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005100 if (bNeedMove) {
5101 pSrcModuleData = GetMapModuleData();
5102 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005103 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005104 }
5105 pDstModuleData = pDstModule->CreateMapModuleData();
5106 }
5107 if (bNeedMove) {
tsepez6bb3b892017-01-05 12:18:41 -08005108 auto it = pSrcModuleData->m_BufferMap.find(pKey);
5109 if (it != pSrcModuleData->m_BufferMap.end()) {
5110 XFA_MAPDATABLOCK* pBufferBlockData = it->second;
5111 if (pBufferBlockData) {
5112 pSrcModuleData->m_BufferMap.erase(pKey);
5113 pDstModuleData->m_BufferMap[pKey] = pBufferBlockData;
5114 }
Dan Sinclair1770c022016-03-14 14:14:16 -04005115 }
5116 }
dsinclairc5a8f212016-06-20 11:11:12 -07005117 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005118 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005119 CFX_WideString wsFormatValue(wsValue);
5120 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5121 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005122 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005123 }
tsepezd19e9122016-11-02 15:43:18 -07005124 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005125 }
5126}
dsinclair5b36f0a2016-07-19 10:56:23 -07005127
Dan Sinclair1770c022016-03-14 14:14:16 -04005128void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5129 CXFA_Node* pDstModule,
5130 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005131 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005132 if (!pSrcModule || !pDstModule || !pKey) {
5133 return;
5134 }
5135 if (bRecursive) {
5136 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5137 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5138 for (; pSrcChild && pDstChild;
5139 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5140 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005141 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005142 }
5143 }
5144 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5145}
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05005146
5147void CXFA_Node::ThrowMissingPropertyException(
5148 const CFX_WideString& obj,
5149 const CFX_WideString& prop) const {
5150 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(),
5151 prop.c_str());
5152}
5153
5154void CXFA_Node::ThrowTooManyOccurancesException(
5155 const CFX_WideString& obj) const {
5156 ThrowException(
5157 L"The element [%s] has violated its allowable number of occurrences.",
5158 obj.c_str());
5159}