blob: 16062f7b6fe8d16a9c91e3d5bbefae2943bffd40 [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>
tsepezaadedf92016-05-12 10:08:06 -070012
dsinclaira52ab742016-09-29 13:59:29 -070013#include "core/fxcrt/fx_ext.h"
dsinclair43554682016-09-29 17:29:48 -070014#include "fxjs/cfxjse_value.h"
tsepezaadedf92016-05-12 10:08:06 -070015#include "third_party/base/stl_util.h"
dsinclairae95f762016-03-29 16:58:29 -070016#include "xfa/fde/xml/fde_xml_imp.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040017#include "xfa/fgas/crt/fgas_codepage.h"
dsinclairdf4bc592016-03-31 20:34:43 -070018#include "xfa/fxfa/app/xfa_ffnotify.h"
dsinclair5b493092016-09-29 20:20:24 -070019#include "xfa/fxfa/cxfa_eventparam.h"
dsinclair16280242016-07-21 12:03:47 -070020#include "xfa/fxfa/parser/cxfa_document.h"
dsinclair0b851ff2016-07-21 12:03:01 -070021#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
dsinclair9eb0db12016-07-21 12:01:39 -070022#include "xfa/fxfa/parser/cxfa_measurement.h"
dsinclair44d054c2016-04-06 10:23:46 -070023#include "xfa/fxfa/parser/cxfa_occur.h"
dsinclair31f87402016-07-20 06:34:45 -070024#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
dsinclair34f86b02016-07-11 08:42:33 -070025#include "xfa/fxfa/parser/cxfa_simple_parser.h"
dsinclair5b36f0a2016-07-19 10:56:23 -070026#include "xfa/fxfa/parser/xfa_basic_data.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040027
weili44f8faf2016-06-01 14:03:56 -070028namespace {
29
30void XFA_DeleteWideString(void* pData) {
31 delete static_cast<CFX_WideString*>(pData);
32}
33
34void XFA_CopyWideString(void*& pData) {
35 if (pData) {
36 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
37 pData = pNewData;
38 }
39}
40
41XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
42 XFA_CopyWideString};
43
weili44f8faf2016-06-01 14:03:56 -070044void XFA_DataNodeDeleteBindItem(void* pData) {
45 delete static_cast<CXFA_NodeArray*>(pData);
46}
47
48XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
49 XFA_DataNodeDeleteBindItem, nullptr};
50
dsinclair5b36f0a2016-07-19 10:56:23 -070051int32_t GetCount(CXFA_Node* pInstMgrNode) {
52 ASSERT(pInstMgrNode);
53 int32_t iCount = 0;
54 uint32_t dwNameHash = 0;
55 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
56 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
57 XFA_Element eCurType = pNode->GetElementType();
58 if (eCurType == XFA_Element::InstanceManager)
59 break;
60 if ((eCurType != XFA_Element::Subform) &&
61 (eCurType != XFA_Element::SubformSet)) {
62 continue;
63 }
64 if (iCount == 0) {
65 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
66 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
67 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
68 wsInstName.Mid(1) != wsName) {
69 return iCount;
70 }
71 dwNameHash = pNode->GetNameHash();
72 }
73 if (dwNameHash != pNode->GetNameHash())
74 break;
weili44f8faf2016-06-01 14:03:56 -070075
dsinclair5b36f0a2016-07-19 10:56:23 -070076 iCount++;
77 }
78 return iCount;
Dan Sinclair1770c022016-03-14 14:14:16 -040079}
weili44f8faf2016-06-01 14:03:56 -070080
dsinclair5b36f0a2016-07-19 10:56:23 -070081void SortNodeArrayByDocumentIdx(const CXFA_NodeSet& rgNodeSet,
82 CXFA_NodeArray& rgNodeArray,
83 CFX_ArrayTemplate<int32_t>& rgIdxArray) {
84 int32_t iCount = pdfium::CollectionSize<int32_t>(rgNodeSet);
85 rgNodeArray.SetSize(iCount);
86 rgIdxArray.SetSize(iCount);
87 if (iCount == 0)
88 return;
weili44f8faf2016-06-01 14:03:56 -070089
dsinclair5b36f0a2016-07-19 10:56:23 -070090 int32_t iIndex = -1;
91 int32_t iTotalIndex = -1;
92 CXFA_Node* pCommonParent =
93 (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent);
94 for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild);
95 pNode && iIndex < iCount;
96 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
97 iTotalIndex++;
98 if (pdfium::ContainsValue(rgNodeSet, pNode)) {
99 iIndex++;
100 rgNodeArray[iIndex] = pNode;
101 rgIdxArray[iIndex] = iTotalIndex;
102 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400103 }
104}
weili44f8faf2016-06-01 14:03:56 -0700105
dsinclair5b36f0a2016-07-19 10:56:23 -0700106using CXFA_NodeSetPair = std::pair<CXFA_NodeSet, CXFA_NodeSet>;
107using CXFA_NodeSetPairMap =
108 std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>;
109using CXFA_NodeSetPairMapMap =
110 std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>;
111
112CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode,
113 CXFA_NodeSetPairMapMap* pMap) {
114 CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
115 uint32_t dwNameHash = pNode->GetNameHash();
116 if (!pParentNode || !dwNameHash)
117 return nullptr;
118
119 if (!(*pMap)[pParentNode])
120 (*pMap)[pParentNode].reset(new CXFA_NodeSetPairMap);
121
122 CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get();
123 if (!(*pNodeSetPairMap)[dwNameHash])
124 (*pNodeSetPairMap)[dwNameHash].reset(new CXFA_NodeSetPair);
125
126 return (*pNodeSetPairMap)[dwNameHash].get();
Dan Sinclair1770c022016-03-14 14:14:16 -0400127}
128
dsinclair5b36f0a2016-07-19 10:56:23 -0700129void ReorderDataNodes(const CXFA_NodeSet& sSet1,
130 const CXFA_NodeSet& sSet2,
tsepezd19e9122016-11-02 15:43:18 -0700131 bool bInsertBefore) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700132 CXFA_NodeSetPairMapMap rgMap;
133 for (CXFA_Node* pNode : sSet1) {
134 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
135 if (pNodeSetPair)
136 pNodeSetPair->first.insert(pNode);
137 }
138 for (CXFA_Node* pNode : sSet2) {
139 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
140 if (pNodeSetPair) {
141 if (pdfium::ContainsValue(pNodeSetPair->first, pNode))
142 pNodeSetPair->first.erase(pNode);
143 else
144 pNodeSetPair->second.insert(pNode);
145 }
146 }
147 for (const auto& iter1 : rgMap) {
148 CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get();
149 if (!pNodeSetPairMap)
150 continue;
151
152 for (const auto& iter2 : *pNodeSetPairMap) {
153 CXFA_NodeSetPair* pNodeSetPair = iter2.second.get();
154 if (!pNodeSetPair)
155 continue;
156 if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) {
157 CXFA_NodeArray rgNodeArray1;
158 CXFA_NodeArray rgNodeArray2;
159 CFX_ArrayTemplate<int32_t> rgIdxArray1;
160 CFX_ArrayTemplate<int32_t> rgIdxArray2;
161 SortNodeArrayByDocumentIdx(pNodeSetPair->first, rgNodeArray1,
162 rgIdxArray1);
163 SortNodeArrayByDocumentIdx(pNodeSetPair->second, rgNodeArray2,
164 rgIdxArray2);
165 CXFA_Node* pParentNode = nullptr;
166 CXFA_Node* pBeforeNode = nullptr;
167 if (bInsertBefore) {
168 pBeforeNode = rgNodeArray2[0];
169 pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent);
170 } else {
171 CXFA_Node* pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1];
172 pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent);
173 pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling);
174 }
175 for (int32_t iIdx = 0; iIdx < rgIdxArray1.GetSize(); iIdx++) {
176 CXFA_Node* pCurNode = rgNodeArray1[iIdx];
177 pParentNode->RemoveChild(pCurNode);
178 pParentNode->InsertChild(pCurNode, pBeforeNode);
179 }
180 }
181 }
182 pNodeSetPairMap->clear();
183 }
184}
185
186CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
187 ASSERT(pInstMgrNode);
188 int32_t iCount = 0;
189 uint32_t dwNameHash = 0;
190 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
191 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
192 XFA_Element eCurType = pNode->GetElementType();
193 if (eCurType == XFA_Element::InstanceManager)
194 break;
195 if ((eCurType != XFA_Element::Subform) &&
196 (eCurType != XFA_Element::SubformSet)) {
197 continue;
198 }
199 if (iCount == 0) {
200 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
201 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
202 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
203 wsInstName.Mid(1) != wsName) {
204 return nullptr;
205 }
206 dwNameHash = pNode->GetNameHash();
207 }
208 if (dwNameHash != pNode->GetNameHash())
209 break;
210
211 iCount++;
212 if (iCount > iIndex)
213 return pNode;
214 }
215 return nullptr;
216}
217
218void InsertItem(CXFA_Node* pInstMgrNode,
219 CXFA_Node* pNewInstance,
220 int32_t iPos,
221 int32_t iCount = -1,
tsepezd19e9122016-11-02 15:43:18 -0700222 bool bMoveDataBindingNodes = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700223 if (iCount < 0)
224 iCount = GetCount(pInstMgrNode);
225 if (iPos < 0)
226 iPos = iCount;
227 if (iPos == iCount) {
228 CXFA_Node* pNextSibling =
229 iCount > 0
230 ? GetItem(pInstMgrNode, iCount - 1)
231 ->GetNodeItem(XFA_NODEITEM_NextSibling)
232 : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
233 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
234 ->InsertChild(pNewInstance, pNextSibling);
235 if (bMoveDataBindingNodes) {
236 CXFA_NodeSet sNew;
237 CXFA_NodeSet sAfter;
238 CXFA_NodeIteratorTemplate<CXFA_Node,
239 CXFA_TraverseStrategy_XFAContainerNode>
240 sIteratorNew(pNewInstance);
241 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
242 pNode = sIteratorNew.MoveToNext()) {
243 CXFA_Node* pDataNode = pNode->GetBindData();
244 if (!pDataNode)
245 continue;
246
247 sNew.insert(pDataNode);
248 }
249 CXFA_NodeIteratorTemplate<CXFA_Node,
250 CXFA_TraverseStrategy_XFAContainerNode>
251 sIteratorAfter(pNextSibling);
252 for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode;
253 pNode = sIteratorAfter.MoveToNext()) {
254 CXFA_Node* pDataNode = pNode->GetBindData();
255 if (!pDataNode)
256 continue;
257
258 sAfter.insert(pDataNode);
259 }
tsepezd19e9122016-11-02 15:43:18 -0700260 ReorderDataNodes(sNew, sAfter, false);
dsinclair5b36f0a2016-07-19 10:56:23 -0700261 }
262 } else {
263 CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos);
264 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
265 ->InsertChild(pNewInstance, pBeforeInstance);
266 if (bMoveDataBindingNodes) {
267 CXFA_NodeSet sNew;
268 CXFA_NodeSet sBefore;
269 CXFA_NodeIteratorTemplate<CXFA_Node,
270 CXFA_TraverseStrategy_XFAContainerNode>
271 sIteratorNew(pNewInstance);
272 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
273 pNode = sIteratorNew.MoveToNext()) {
274 CXFA_Node* pDataNode = pNode->GetBindData();
275 if (!pDataNode)
276 continue;
277
278 sNew.insert(pDataNode);
279 }
280 CXFA_NodeIteratorTemplate<CXFA_Node,
281 CXFA_TraverseStrategy_XFAContainerNode>
282 sIteratorBefore(pBeforeInstance);
283 for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode;
284 pNode = sIteratorBefore.MoveToNext()) {
285 CXFA_Node* pDataNode = pNode->GetBindData();
286 if (!pDataNode)
287 continue;
288
289 sBefore.insert(pDataNode);
290 }
tsepezd19e9122016-11-02 15:43:18 -0700291 ReorderDataNodes(sNew, sBefore, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700292 }
293 }
294}
295
296void RemoveItem(CXFA_Node* pInstMgrNode,
297 CXFA_Node* pRemoveInstance,
tsepezd19e9122016-11-02 15:43:18 -0700298 bool bRemoveDataBinding = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700299 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);
300 if (!bRemoveDataBinding)
301 return;
302
303 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode>
304 sIterator(pRemoveInstance);
305 for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode;
306 pFormNode = sIterator.MoveToNext()) {
307 CXFA_Node* pDataNode = pFormNode->GetBindData();
308 if (!pDataNode)
309 continue;
310
311 if (pDataNode->RemoveBindItem(pFormNode) == 0) {
312 if (CXFA_Node* pDataParent =
313 pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) {
314 pDataParent->RemoveChild(pDataNode);
315 }
316 }
317 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
318 }
319}
320
tsepezd19e9122016-11-02 15:43:18 -0700321CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700322 CXFA_Document* pDocument = pInstMgrNode->GetDocument();
323 CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();
324 CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);
325 CXFA_Node* pDataScope = nullptr;
326 for (CXFA_Node* pRootBoundNode = pFormParent;
327 pRootBoundNode && pRootBoundNode->IsContainerNode();
328 pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) {
329 pDataScope = pRootBoundNode->GetBindData();
330 if (pDataScope)
331 break;
332 }
333 if (!pDataScope) {
334 pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record));
335 ASSERT(pDataScope);
336 }
337 CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer(
tsepezd19e9122016-11-02 15:43:18 -0700338 pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700339 if (pInstance) {
340 pDocument->DataMerge_UpdateBindingRelations(pInstance);
341 pFormParent->RemoveChild(pInstance);
342 }
343 return pInstance;
344}
345
346struct XFA_ExecEventParaInfo {
347 public:
348 uint32_t m_uHash;
349 const FX_WCHAR* m_lpcEventName;
350 XFA_EVENTTYPE m_eventType;
351 uint32_t m_validFlags;
352};
353static const XFA_ExecEventParaInfo gs_eventParaInfos[] = {
354 {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0},
355 {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0},
356 {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5},
357 {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0},
358 {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7},
359 {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1},
360 {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5},
361 {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0},
362 {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0},
363 {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6},
364 {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2},
365 {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0},
366 {0x7233018a, L"validate", XFA_EVENT_Validate, 1},
367 {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3},
368 {0x891f4606, L"change", XFA_EVENT_Change, 4},
369 {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0},
370 {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5},
371 {0xcdce56b3, L"full", XFA_EVENT_Full, 4},
372 {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5},
373 {0xd95657a6, L"click", XFA_EVENT_Click, 4},
374 {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1},
375 {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7},
376 {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2},
377 {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0},
378 {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6},
379};
380
381const XFA_ExecEventParaInfo* GetEventParaInfoByName(
382 const CFX_WideStringC& wsEventName) {
383 uint32_t uHash = FX_HashCode_GetW(wsEventName, false);
384 int32_t iStart = 0;
385 int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
386 do {
387 int32_t iMid = (iStart + iEnd) / 2;
388 const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid];
389 if (uHash == eventParaInfo->m_uHash)
390 return eventParaInfo;
391 if (uHash < eventParaInfo->m_uHash)
392 iEnd = iMid - 1;
393 else
394 iStart = iMid + 1;
395 } while (iStart <= iEnd);
396 return nullptr;
397}
398
399void StrToRGB(const CFX_WideString& strRGB,
400 int32_t& r,
401 int32_t& g,
402 int32_t& b) {
403 r = 0;
404 g = 0;
405 b = 0;
406
407 FX_WCHAR zero = '0';
408 int32_t iIndex = 0;
409 int32_t iLen = strRGB.GetLength();
410 for (int32_t i = 0; i < iLen; ++i) {
411 FX_WCHAR ch = strRGB.GetAt(i);
412 if (ch == L',')
413 ++iIndex;
414 if (iIndex > 2)
415 break;
416
417 int32_t iValue = ch - zero;
418 if (iValue >= 0 && iValue <= 9) {
419 switch (iIndex) {
420 case 0:
421 r = r * 10 + iValue;
422 break;
423 case 1:
424 g = g * 10 + iValue;
425 break;
426 default:
427 b = b * 10 + iValue;
428 break;
429 }
430 }
431 }
432}
433
434enum XFA_KEYTYPE {
435 XFA_KEYTYPE_Custom,
436 XFA_KEYTYPE_Element,
437};
438
439void* GetMapKey_Custom(const CFX_WideStringC& wsKey) {
440 uint32_t dwKey = FX_HashCode_GetW(wsKey, false);
441 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom);
442}
443
444void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) {
445 return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) |
446 (eAttribute << 8) | XFA_KEYTYPE_Element);
447}
448
dsinclair9eb0db12016-07-21 12:01:39 -0700449const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement,
450 XFA_ATTRIBUTE eAttribute,
451 uint32_t dwPacket) {
452 int32_t iCount = 0;
453 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount);
454 if (!pAttr || iCount < 1)
455 return nullptr;
456
457 if (!std::binary_search(pAttr, pAttr + iCount, eAttribute))
458 return nullptr;
459
460 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute);
461 ASSERT(pInfo);
462 if (dwPacket == XFA_XDPPACKET_UNKNOWN)
463 return pInfo;
464 return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr;
465}
466
467const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) {
468 return g_XFAEnumData + eName;
469}
470
dsinclair5b36f0a2016-07-19 10:56:23 -0700471} // namespace
472
473static void XFA_DefaultFreeData(void* pData) {}
474
475static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {
476 XFA_DefaultFreeData, nullptr};
477
weili47bcd4c2016-06-16 08:00:06 -0700478XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {}
479
480XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {}
481
dsinclairb9778472016-06-23 13:34:10 -0700482CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
483 uint16_t ePacket,
484 XFA_ObjectType oType,
dsinclairc1df5d42016-07-18 06:36:51 -0700485 XFA_Element eType,
486 const CFX_WideStringC& elementName)
487 : CXFA_Object(pDoc, oType, eType, elementName),
Dan Sinclair1770c022016-03-14 14:14:16 -0400488 m_pNext(nullptr),
489 m_pChild(nullptr),
490 m_pLastChild(nullptr),
491 m_pParent(nullptr),
492 m_pXMLNode(nullptr),
Dan Sinclair1770c022016-03-14 14:14:16 -0400493 m_ePacket(ePacket),
dsinclairc5a8f212016-06-20 11:11:12 -0700494 m_uNodeFlags(XFA_NodeFlag_None),
Dan Sinclair1770c022016-03-14 14:14:16 -0400495 m_dwNameHash(0),
496 m_pAuxNode(nullptr),
497 m_pMapModuleData(nullptr) {
498 ASSERT(m_pDocument);
499}
weili44f8faf2016-06-01 14:03:56 -0700500
Dan Sinclair1770c022016-03-14 14:14:16 -0400501CXFA_Node::~CXFA_Node() {
weili44f8faf2016-06-01 14:03:56 -0700502 ASSERT(!m_pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400503 RemoveMapModuleKey();
weili44f8faf2016-06-01 14:03:56 -0700504 CXFA_Node* pNode = m_pChild;
Dan Sinclair1770c022016-03-14 14:14:16 -0400505 while (pNode) {
weili44f8faf2016-06-01 14:03:56 -0700506 CXFA_Node* pNext = pNode->m_pNext;
507 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400508 delete pNode;
509 pNode = pNext;
510 }
dsinclairc5a8f212016-06-20 11:11:12 -0700511 if (m_pXMLNode && IsOwnXMLNode())
Tom Sepezd3743ea2016-05-16 15:56:53 -0700512 m_pXMLNode->Release();
Dan Sinclair1770c022016-03-14 14:14:16 -0400513}
weili44f8faf2016-06-01 14:03:56 -0700514
tsepezd19e9122016-11-02 15:43:18 -0700515CXFA_Node* CXFA_Node::Clone(bool bRecursive) {
dsinclaira1b07722016-07-11 08:20:58 -0700516 CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700517 if (!pClone)
518 return nullptr;
519
Dan Sinclair1770c022016-03-14 14:14:16 -0400520 MergeAllData(pClone);
521 pClone->UpdateNameHash();
522 if (IsNeedSavingXMLNode()) {
weili44f8faf2016-06-01 14:03:56 -0700523 CFDE_XMLNode* pCloneXML = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400524 if (IsAttributeInXML()) {
525 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -0700526 GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -0700527 CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -0400528 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
529 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -0700530 pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -0400531 }
532 pCloneXML = pCloneXMLElement;
weili44f8faf2016-06-01 14:03:56 -0700533 pCloneXMLElement = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400534 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
535 } else {
tsepezd19e9122016-11-02 15:43:18 -0700536 pCloneXML = m_pXMLNode->Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400537 }
538 pClone->SetXMLMappingNode(pCloneXML);
dsinclairc5a8f212016-06-20 11:11:12 -0700539 pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400540 }
541 if (bRecursive) {
542 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
543 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
544 pClone->InsertChild(pChild->Clone(bRecursive));
545 }
546 }
dsinclairc5a8f212016-06-20 11:11:12 -0700547 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
weili44f8faf2016-06-01 14:03:56 -0700548 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400549 return pClone;
550}
weili44f8faf2016-06-01 14:03:56 -0700551
Dan Sinclair1770c022016-03-14 14:14:16 -0400552CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
553 switch (eItem) {
554 case XFA_NODEITEM_NextSibling:
555 return m_pNext;
556 case XFA_NODEITEM_FirstChild:
557 return m_pChild;
558 case XFA_NODEITEM_Parent:
559 return m_pParent;
560 case XFA_NODEITEM_PrevSibling:
561 if (m_pParent) {
562 CXFA_Node* pSibling = m_pParent->m_pChild;
weili44f8faf2016-06-01 14:03:56 -0700563 CXFA_Node* pPrev = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400564 while (pSibling && pSibling != this) {
565 pPrev = pSibling;
566 pSibling = pSibling->m_pNext;
567 }
568 return pPrev;
569 }
weili44f8faf2016-06-01 14:03:56 -0700570 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400571 default:
572 break;
573 }
weili44f8faf2016-06-01 14:03:56 -0700574 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400575}
weili44f8faf2016-06-01 14:03:56 -0700576
Dan Sinclair1770c022016-03-14 14:14:16 -0400577CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
dsinclairc5a8f212016-06-20 11:11:12 -0700578 XFA_ObjectType eType) const {
weili44f8faf2016-06-01 14:03:56 -0700579 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400580 switch (eItem) {
581 case XFA_NODEITEM_NextSibling:
582 pNode = m_pNext;
dsinclairc5a8f212016-06-20 11:11:12 -0700583 while (pNode && pNode->GetObjectType() != eType)
584 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400585 break;
586 case XFA_NODEITEM_FirstChild:
587 pNode = m_pChild;
dsinclairc5a8f212016-06-20 11:11:12 -0700588 while (pNode && pNode->GetObjectType() != eType)
589 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400590 break;
591 case XFA_NODEITEM_Parent:
592 pNode = m_pParent;
dsinclairc5a8f212016-06-20 11:11:12 -0700593 while (pNode && pNode->GetObjectType() != eType)
594 pNode = pNode->m_pParent;
Dan Sinclair1770c022016-03-14 14:14:16 -0400595 break;
596 case XFA_NODEITEM_PrevSibling:
597 if (m_pParent) {
598 CXFA_Node* pSibling = m_pParent->m_pChild;
599 while (pSibling && pSibling != this) {
dsinclairc5a8f212016-06-20 11:11:12 -0700600 if (eType == pSibling->GetObjectType())
Dan Sinclair1770c022016-03-14 14:14:16 -0400601 pNode = pSibling;
dsinclairc5a8f212016-06-20 11:11:12 -0700602
Dan Sinclair1770c022016-03-14 14:14:16 -0400603 pSibling = pSibling->m_pNext;
604 }
605 }
606 break;
607 default:
608 break;
609 }
610 return pNode;
611}
weili44f8faf2016-06-01 14:03:56 -0700612
Dan Sinclair1770c022016-03-14 14:14:16 -0400613int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes,
tsepez736f28a2016-03-25 14:19:51 -0700614 uint32_t dwTypeFilter,
dsinclair41cb62e2016-06-23 09:20:32 -0700615 XFA_Element eTypeFilter,
Dan Sinclair1770c022016-03-14 14:14:16 -0400616 int32_t iLevel) {
617 if (--iLevel < 0) {
618 return nodes.GetSize();
619 }
dsinclair41cb62e2016-06-23 09:20:32 -0700620 if (eTypeFilter != XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400621 CXFA_Node* pChild = m_pChild;
622 while (pChild) {
dsinclair41cb62e2016-06-23 09:20:32 -0700623 if (pChild->GetElementType() == eTypeFilter) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400624 nodes.Add(pChild);
625 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700626 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400627 }
628 }
629 pChild = pChild->m_pNext;
630 }
631 } else if (dwTypeFilter ==
632 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
633 CXFA_Node* pChild = m_pChild;
634 while (pChild) {
635 nodes.Add(pChild);
636 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700637 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400638 }
639 pChild = pChild->m_pNext;
640 }
641 } else if (dwTypeFilter != 0) {
weili44f8faf2016-06-01 14:03:56 -0700642 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
643 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
644 bool bFilterOneOfProperties =
645 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
Dan Sinclair1770c022016-03-14 14:14:16 -0400646 CXFA_Node* pChild = m_pChild;
647 while (pChild) {
648 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -0700649 GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -0400650 if (pProperty) {
651 if (bFilterProperties) {
652 nodes.Add(pChild);
653 } else if (bFilterOneOfProperties &&
654 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
655 nodes.Add(pChild);
656 } else if (bFilterChildren &&
dsinclair070fcdf2016-06-22 22:04:54 -0700657 (pChild->GetElementType() == XFA_Element::Variables ||
658 pChild->GetElementType() == XFA_Element::PageSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400659 nodes.Add(pChild);
660 }
weili44f8faf2016-06-01 14:03:56 -0700661 } else if (bFilterChildren) {
662 nodes.Add(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400663 }
664 pChild = pChild->m_pNext;
665 }
666 if (bFilterOneOfProperties && nodes.GetSize() < 1) {
667 int32_t iProperties = 0;
668 const XFA_PROPERTY* pProperty =
dsinclair070fcdf2016-06-22 22:04:54 -0700669 XFA_GetElementProperties(GetElementType(), iProperties);
weili44f8faf2016-06-01 14:03:56 -0700670 if (!pProperty || iProperties < 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400671 return 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400672 for (int32_t i = 0; i < iProperties; i++) {
673 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400674 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
675 CXFA_Node* pNewNode =
dsinclaira1b07722016-07-11 08:20:58 -0700676 m_pDocument->CreateNode(pPacket, pProperty[i].eName);
weili44f8faf2016-06-01 14:03:56 -0700677 if (!pNewNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400678 break;
weili44f8faf2016-06-01 14:03:56 -0700679 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -0700680 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400681 nodes.Add(pNewNode);
682 break;
683 }
684 }
685 }
686 }
687 return nodes.GetSize();
688}
weili44f8faf2016-06-01 14:03:56 -0700689
dsinclair41cb62e2016-06-23 09:20:32 -0700690CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
tsepez736f28a2016-03-25 14:19:51 -0700691 uint32_t dwFlags) {
dsinclaira1b07722016-07-11 08:20:58 -0700692 CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
thestigb1a59592016-04-14 18:29:56 -0700693 pNode->SetFlag(dwFlags, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400694 return pNode;
695}
weili44f8faf2016-06-01 14:03:56 -0700696
tsepezd19e9122016-11-02 15:43:18 -0700697CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) {
dsinclair43854a52016-04-27 12:26:00 -0700698 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
dsinclaira1b07722016-07-11 08:20:58 -0700699 CXFA_Node* pClone =
700 m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700701 if (!pClone)
702 return nullptr;
703
Dan Sinclair1770c022016-03-14 14:14:16 -0400704 pClone->SetTemplateNode(this);
705 pClone->UpdateNameHash();
706 pClone->SetXMLMappingNode(GetXMLMappingNode());
707 if (bRecursive) {
708 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
709 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
710 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
711 }
712 }
dsinclairc5a8f212016-06-20 11:11:12 -0700713 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400714 return pClone;
715}
716
717CXFA_Node* CXFA_Node::GetTemplateNode() const {
718 return m_pAuxNode;
719}
720
721void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
722 m_pAuxNode = pTemplateNode;
723}
weili44f8faf2016-06-01 14:03:56 -0700724
Dan Sinclair1770c022016-03-14 14:14:16 -0400725CXFA_Node* CXFA_Node::GetBindData() {
726 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
727 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
728}
weili44f8faf2016-06-01 14:03:56 -0700729
Dan Sinclair1770c022016-03-14 14:14:16 -0400730int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) {
dsinclairc5a8f212016-06-20 11:11:12 -0700731 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700732 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400733 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
734 formItems.Copy(*pItems);
735 return formItems.GetSize();
736 }
737 CXFA_Node* pFormNode =
738 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
weili44f8faf2016-06-01 14:03:56 -0700739 if (pFormNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400740 formItems.Add(pFormNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400741 return formItems.GetSize();
742}
743
Dan Sinclair1770c022016-03-14 14:14:16 -0400744int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
745 ASSERT(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700746 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700747 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400748 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
749 ASSERT(pItems);
750 if (pItems->Find(pFormNode) < 0) {
751 pItems->Add(pFormNode);
752 }
753 return pItems->GetSize();
754 }
755 CXFA_Node* pOldFormItem =
756 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
757 if (!pOldFormItem) {
758 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
759 return 1;
760 } else if (pOldFormItem == pFormNode) {
761 return 1;
762 }
763 CXFA_NodeArray* pItems = new CXFA_NodeArray;
764 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
765 pItems->Add(pOldFormItem);
766 pItems->Add(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700767 m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400768 return 2;
769}
weili44f8faf2016-06-01 14:03:56 -0700770
Dan Sinclair1770c022016-03-14 14:14:16 -0400771int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
dsinclairc5a8f212016-06-20 11:11:12 -0700772 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700773 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400774 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
775 ASSERT(pItems);
776 int32_t iIndex = pItems->Find(pFormNode);
777 int32_t iCount = pItems->GetSize();
778 if (iIndex >= 0) {
weili44f8faf2016-06-01 14:03:56 -0700779 if (iIndex != iCount - 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400780 pItems->SetAt(iIndex, pItems->GetAt(iCount - 1));
Dan Sinclair1770c022016-03-14 14:14:16 -0400781 pItems->RemoveAt(iCount - 1);
782 if (iCount == 2) {
783 CXFA_Node* pLastFormNode = pItems->GetAt(0);
784 SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700785 m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400786 }
787 iCount--;
788 }
789 return iCount;
790 }
791 CXFA_Node* pOldFormItem =
792 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
793 if (pOldFormItem == pFormNode) {
weili44f8faf2016-06-01 14:03:56 -0700794 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
795 pOldFormItem = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400796 }
weili44f8faf2016-06-01 14:03:56 -0700797 return pOldFormItem ? 1 : 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400798}
weili44f8faf2016-06-01 14:03:56 -0700799
tsepezd19e9122016-11-02 15:43:18 -0700800bool CXFA_Node::HasBindItem() {
weili44f8faf2016-06-01 14:03:56 -0700801 return GetPacketID() == XFA_XDPPACKET_Datasets &&
802 GetObject(XFA_ATTRIBUTE_BindingNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400803}
weili44f8faf2016-06-01 14:03:56 -0700804
Dan Sinclair1770c022016-03-14 14:14:16 -0400805CXFA_WidgetData* CXFA_Node::GetWidgetData() {
806 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
807}
weili44f8faf2016-06-01 14:03:56 -0700808
Dan Sinclair1770c022016-03-14 14:14:16 -0400809CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
weili44f8faf2016-06-01 14:03:56 -0700810 if (GetPacketID() != XFA_XDPPACKET_Form)
811 return nullptr;
dsinclair41cb62e2016-06-23 09:20:32 -0700812 XFA_Element eType = GetElementType();
813 if (eType == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700814 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400815 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700816 if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700817 return nullptr;
818
dsinclair41cb62e2016-06-23 09:20:32 -0700819 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400820 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
821 if (pFieldWidgetData &&
822 pFieldWidgetData->GetChoiceListOpen() ==
823 XFA_ATTRIBUTEENUM_MultiSelect) {
weili44f8faf2016-06-01 14:03:56 -0700824 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400825 } else {
826 CFX_WideString wsPicture;
827 if (pFieldWidgetData) {
828 pFieldWidgetData->GetPictureContent(wsPicture,
829 XFA_VALUEPICTURE_DataBind);
830 }
weili44f8faf2016-06-01 14:03:56 -0700831 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400832 return pFieldWidgetData;
Dan Sinclair1770c022016-03-14 14:14:16 -0400833 CXFA_Node* pDataNode = GetBindData();
weili44f8faf2016-06-01 14:03:56 -0700834 if (!pDataNode)
835 return nullptr;
836 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400837 CXFA_NodeArray formNodes;
838 pDataNode->GetBindItems(formNodes);
839 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
840 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -0700841 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -0400842 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400843 pFieldWidgetData = pFormNode->GetWidgetData();
844 if (pFieldWidgetData) {
845 pFieldWidgetData->GetPictureContent(wsPicture,
846 XFA_VALUEPICTURE_DataBind);
847 }
weili44f8faf2016-06-01 14:03:56 -0700848 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400849 break;
weili44f8faf2016-06-01 14:03:56 -0700850 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400851 }
852 return pFieldWidgetData;
853 }
854 }
855 CXFA_Node* pGrandNode =
weili44f8faf2016-06-01 14:03:56 -0700856 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400857 CXFA_Node* pValueNode =
dsinclair070fcdf2016-06-22 22:04:54 -0700858 (pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
Dan Sinclair1770c022016-03-14 14:14:16 -0400859 ? pParentNode
weili44f8faf2016-06-01 14:03:56 -0700860 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400861 if (!pValueNode) {
dsinclair070fcdf2016-06-22 22:04:54 -0700862 pValueNode =
863 (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
864 ? pGrandNode
865 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400866 }
867 CXFA_Node* pParentOfValueNode =
weili44f8faf2016-06-01 14:03:56 -0700868 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400869 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
weili44f8faf2016-06-01 14:03:56 -0700870 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400871}
weili44f8faf2016-06-01 14:03:56 -0700872
tsepezd19e9122016-11-02 15:43:18 -0700873bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400874 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
dsinclair56a8b192016-06-21 14:15:25 -0700875 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
dsinclair43854a52016-04-27 12:26:00 -0700876 ASSERT(pTopSubform);
Dan Sinclair1770c022016-03-14 14:14:16 -0400877 CXFA_Node* pLocaleNode = this;
tsepezd19e9122016-11-02 15:43:18 -0700878 bool bLocale = false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400879 do {
tsepezd19e9122016-11-02 15:43:18 -0700880 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400881 if (!bLocale) {
882 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
883 }
884 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
weili44f8faf2016-06-01 14:03:56 -0700885 if (bLocale)
tsepezd19e9122016-11-02 15:43:18 -0700886 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400887 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
888 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
weili44f8faf2016-06-01 14:03:56 -0700889 if (!wsLocaleName.IsEmpty())
tsepezd19e9122016-11-02 15:43:18 -0700890 return true;
weili44f8faf2016-06-01 14:03:56 -0700891 if (pTopSubform &&
tsepezd19e9122016-11-02 15:43:18 -0700892 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) {
893 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400894 }
895 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
896 if (pLocale) {
897 wsLocaleName = pLocale->GetName();
tsepezd19e9122016-11-02 15:43:18 -0700898 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400899 }
tsepezd19e9122016-11-02 15:43:18 -0700900 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400901}
weili44f8faf2016-06-01 14:03:56 -0700902
Dan Sinclair1770c022016-03-14 14:14:16 -0400903XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
dsinclair56a8b192016-06-21 14:15:25 -0700904 CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
Dan Sinclair1770c022016-03-14 14:14:16 -0400905 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
906 if (pKeep) {
907 XFA_ATTRIBUTEENUM eIntact;
tsepezd19e9122016-11-02 15:43:18 -0700908 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400909 if (eIntact == XFA_ATTRIBUTEENUM_None &&
910 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
911 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
dsinclairc5a8f212016-06-20 11:11:12 -0700912 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
913 XFA_ObjectType::ContainerNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400914 if (pPreviewRow &&
915 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
916 XFA_ATTRIBUTEENUM_Row) {
917 XFA_ATTRIBUTEENUM eValue;
tsepezd19e9122016-11-02 15:43:18 -0700918 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700919 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
920 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
921 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400922 }
weili44f8faf2016-06-01 14:03:56 -0700923 CXFA_Node* pNode =
dsinclair56a8b192016-06-21 14:15:25 -0700924 pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
tsepezd19e9122016-11-02 15:43:18 -0700925 if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700926 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
927 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
928 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400929 }
930 }
931 }
932 return eIntact;
933 }
934 }
dsinclair41cb62e2016-06-23 09:20:32 -0700935 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700936 case XFA_Element::Subform:
Dan Sinclair1770c022016-03-14 14:14:16 -0400937 switch (eLayoutType) {
938 case XFA_ATTRIBUTEENUM_Position:
939 case XFA_ATTRIBUTEENUM_Row:
940 return XFA_ATTRIBUTEENUM_ContentArea;
941 case XFA_ATTRIBUTEENUM_Tb:
942 case XFA_ATTRIBUTEENUM_Table:
943 case XFA_ATTRIBUTEENUM_Lr_tb:
944 case XFA_ATTRIBUTEENUM_Rl_tb:
945 return XFA_ATTRIBUTEENUM_None;
946 default:
947 break;
948 }
949 break;
dsinclair56a8b192016-06-21 14:15:25 -0700950 case XFA_Element::Field: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400951 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700952 if (!pParentNode ||
953 pParentNode->GetElementType() == XFA_Element::PageArea)
Dan Sinclair1770c022016-03-14 14:14:16 -0400954 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400955 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
956 XFA_ATTRIBUTEENUM eParLayout =
957 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
958 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
959 eParLayout == XFA_ATTRIBUTEENUM_Row ||
960 eParLayout == XFA_ATTRIBUTEENUM_Table) {
961 return XFA_ATTRIBUTEENUM_None;
962 }
963 XFA_VERSION version = m_pDocument->GetCurVersionMode();
964 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
965 CXFA_Measurement measureH;
tsepezd19e9122016-11-02 15:43:18 -0700966 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false))
Dan Sinclair1770c022016-03-14 14:14:16 -0400967 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400968 }
969 return XFA_ATTRIBUTEENUM_None;
970 }
971 return XFA_ATTRIBUTEENUM_ContentArea;
972 }
dsinclair56a8b192016-06-21 14:15:25 -0700973 case XFA_Element::Draw:
Dan Sinclair1770c022016-03-14 14:14:16 -0400974 return XFA_ATTRIBUTEENUM_ContentArea;
975 default:
976 break;
977 }
978 return XFA_ATTRIBUTEENUM_None;
979}
weili44f8faf2016-06-01 14:03:56 -0700980
Dan Sinclair1770c022016-03-14 14:14:16 -0400981CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
weili44f8faf2016-06-01 14:03:56 -0700982 if (m_ePacket == XFA_XDPPACKET_Datasets)
Dan Sinclair1770c022016-03-14 14:14:16 -0400983 return m_pAuxNode;
weili44f8faf2016-06-01 14:03:56 -0700984 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400985}
weili44f8faf2016-06-01 14:03:56 -0700986
Dan Sinclair1770c022016-03-14 14:14:16 -0400987void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
dsinclair43854a52016-04-27 12:26:00 -0700988 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
Dan Sinclair1770c022016-03-14 14:14:16 -0400989 m_pAuxNode = pDataDescriptionNode;
990}
weili44f8faf2016-06-01 14:03:56 -0700991
Dan Sinclair1770c022016-03-14 14:14:16 -0400992void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
993 int32_t iLength = pArguments->GetLength();
994 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -0700995 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNode");
Dan Sinclair1770c022016-03-14 14:14:16 -0400996 return;
997 }
tsepez6fe7d212016-04-06 10:51:14 -0700998 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -0700999 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclairdf4bc592016-03-31 20:34:43 -07001000 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001001 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001002 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001003 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001004 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001005 refNode = ToNode(pScriptContext->GetThisObject());
tsepez736f28a2016-03-25 14:19:51 -07001006 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001007 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1008 XFA_RESOLVENODE_Siblings;
1009 XFA_RESOLVENODE_RS resoveNodeRS;
tsepezfc58ad12016-04-05 12:22:15 -07001010 int32_t iRet = pScriptContext->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001011 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
dsinclairf27aeec2016-06-07 19:36:18 -07001012 if (iRet < 1) {
1013 pArguments->GetReturnValue()->SetNull();
1014 return;
1015 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001016 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1017 CXFA_Object* pNode = resoveNodeRS.nodes[0];
dsinclairf27aeec2016-06-07 19:36:18 -07001018 pArguments->GetReturnValue()->Assign(
1019 pScriptContext->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001020 } else {
1021 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
1022 resoveNodeRS.pScriptAttribute;
1023 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
dsinclair86fad992016-05-31 11:34:04 -07001024 std::unique_ptr<CFXJSE_Value> pValue(
1025 new CFXJSE_Value(pScriptContext->GetRuntime()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001026 (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))(
tsepezd19e9122016-11-02 15:43:18 -07001027 pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
dsinclairf27aeec2016-06-07 19:36:18 -07001028 pArguments->GetReturnValue()->Assign(pValue.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001029 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001030 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001031 }
1032 }
1033}
weili44f8faf2016-06-01 14:03:56 -07001034
Dan Sinclair1770c022016-03-14 14:14:16 -04001035void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
1036 int32_t iLength = pArguments->GetLength();
1037 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001038 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04001039 return;
1040 }
tsepez6fe7d212016-04-06 10:51:14 -07001041 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001042 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclair12a6b0c2016-05-26 11:14:08 -07001043 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001044 if (!pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04001045 return;
tsepez736f28a2016-03-25 14:19:51 -07001046 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001047 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1048 XFA_RESOLVENODE_Siblings;
1049 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001050 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001051 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
dsinclair12a6b0c2016-05-26 11:14:08 -07001052 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001053}
weili44f8faf2016-06-01 14:03:56 -07001054
dsinclair12a6b0c2016-05-26 11:14:08 -07001055void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001056 CFX_WideString wsExpression,
tsepez736f28a2016-03-25 14:19:51 -07001057 uint32_t dwFlag,
Dan Sinclair1770c022016-03-14 14:14:16 -04001058 CXFA_Node* refNode) {
dsinclairdf4bc592016-03-31 20:34:43 -07001059 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001060 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001061 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001062 XFA_RESOLVENODE_RS resoveNodeRS;
weili44f8faf2016-06-01 14:03:56 -07001063 if (!refNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04001064 refNode = this;
tsepez4c3debb2016-04-08 12:20:38 -07001065 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
tsepezfc58ad12016-04-05 12:22:15 -07001066 resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001067 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
1068 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1069 for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) {
1070 if (resoveNodeRS.nodes[i]->IsNode())
1071 pNodeList->Append(resoveNodeRS.nodes[i]->AsNode());
1072 }
1073 } else {
dsinclair12a6b0c2016-05-26 11:14:08 -07001074 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
1075 if (resoveNodeRS.GetAttributeResult(valueArray) > 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001076 CXFA_ObjArray objectArray;
dsinclair12a6b0c2016-05-26 11:14:08 -07001077 valueArray.GetAttributeObject(objectArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04001078 for (int32_t i = 0; i < objectArray.GetSize(); i++) {
1079 if (objectArray[i]->IsNode())
1080 pNodeList->Append(objectArray[i]->AsNode());
1081 }
1082 }
1083 }
dsinclairf27aeec2016-06-07 19:36:18 -07001084 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001085}
weili44f8faf2016-06-01 14:03:56 -07001086
dsinclair12a6b0c2016-05-26 11:14:08 -07001087void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001088 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001089 XFA_ATTRIBUTE eAttribute) {
1090 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001091 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001092 } else {
tsepez736f28a2016-03-25 14:19:51 -07001093 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
Dan Sinclair1770c022016-03-14 14:14:16 -04001094 CFX_WideString wsName;
1095 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
1096 CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]");
dsinclair12a6b0c2016-05-26 11:14:08 -07001097 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001098 }
1099}
weili44f8faf2016-06-01 14:03:56 -07001100
dsinclair12a6b0c2016-05-26 11:14:08 -07001101void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001102 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001103 XFA_ATTRIBUTE eAttribute) {
dsinclairdf4bc592016-03-31 20:34:43 -07001104 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001105 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001106 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001107 if (bSetting) {
1108 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider();
dsinclair43854a52016-04-27 12:26:00 -07001109 ASSERT(pAppProvider);
Dan Sinclair1770c022016-03-14 14:14:16 -04001110 CFX_WideString wsMessage;
1111 pAppProvider->LoadString(XFA_IDS_Unable_TO_SET, wsMessage);
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) {
dsinclair2235b7b2016-06-02 07:42:25 -07001124 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001125 } else {
tsepez736f28a2016-03-25 14:19:51 -07001126 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
dsinclair017052a2016-06-28 07:43:51 -07001127 CFX_WideString wsExpression =
1128 FX_WSTRC(L"#") + GetClassName() + FX_WSTRC(L"[*]");
dsinclair12a6b0c2016-05-26 11:14:08 -07001129 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001130 }
1131}
weili44f8faf2016-06-01 14:03:56 -07001132
dsinclair12a6b0c2016-05-26 11:14:08 -07001133void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001134 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001135 XFA_ATTRIBUTE eAttribute) {
1136 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001137 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001138 } else {
1139 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
1140 if (pParent) {
dsinclairf27aeec2016-06-07 19:36:18 -07001141 pValue->Assign(
1142 m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001143 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001144 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001145 }
1146 }
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) {
weili44f8faf2016-06-01 14:03:56 -07001152 if (bSetting)
dsinclair2235b7b2016-06-02 07:42:25 -07001153 ThrowException(XFA_IDS_INVAlID_PROP_SET);
weili44f8faf2016-06-01 14:03:56 -07001154 else
dsinclairf27aeec2016-06-07 19:36:18 -07001155 pValue->SetInteger(GetNodeSameNameIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001156}
weili44f8faf2016-06-01 14:03:56 -07001157
dsinclair12a6b0c2016-05-26 11:14:08 -07001158void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001159 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001160 XFA_ATTRIBUTE eAttribute) {
weili44f8faf2016-06-01 14:03:56 -07001161 if (bSetting)
dsinclair2235b7b2016-06-02 07:42:25 -07001162 ThrowException(XFA_IDS_INVAlID_PROP_SET);
weili44f8faf2016-06-01 14:03:56 -07001163 else
dsinclairf27aeec2016-06-07 19:36:18 -07001164 pValue->SetInteger(GetNodeSameClassIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001165}
weili44f8faf2016-06-01 14:03:56 -07001166
dsinclair12a6b0c2016-05-26 11:14:08 -07001167void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001168 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001169 XFA_ATTRIBUTE eAttribute) {
1170 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001171 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001172 } else {
1173 CFX_WideString wsSOMExpression;
1174 GetSOMExpression(wsSOMExpression);
dsinclairf27aeec2016-06-07 19:36:18 -07001175 pValue->SetString(FX_UTF8Encode(wsSOMExpression).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001176 }
1177}
weili44f8faf2016-06-01 14:03:56 -07001178
Dan Sinclair1770c022016-03-14 14:14:16 -04001179void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
1180 int32_t iLength = pArguments->GetLength();
1181 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001182 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"applyXSL");
Dan Sinclair1770c022016-03-14 14:14:16 -04001183 return;
1184 }
tsepez6fe7d212016-04-06 10:51:14 -07001185 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001186 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili60607c32016-05-26 11:53:12 -07001187 // TODO(weili): check whether we need to implement this, pdfium:501.
1188 // For now, just put the variables here to avoid unused variable warning.
1189 (void)wsExpression;
Dan Sinclair1770c022016-03-14 14:14:16 -04001190}
weili60607c32016-05-26 11:53:12 -07001191
Dan Sinclair1770c022016-03-14 14:14:16 -04001192void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
1193 int32_t iLength = pArguments->GetLength();
1194 if (iLength < 1 || iLength > 3) {
dsinclair2235b7b2016-06-02 07:42:25 -07001195 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"assignNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04001196 return;
1197 }
1198 CFX_WideString wsExpression;
1199 CFX_WideString wsValue;
1200 int32_t iAction = 0;
weili44f8faf2016-06-01 14:03:56 -07001201 wsExpression =
1202 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001203 if (iLength >= 2) {
weili60607c32016-05-26 11:53:12 -07001204 wsValue =
1205 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001206 }
weili60607c32016-05-26 11:53:12 -07001207 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001208 iAction = pArguments->GetInt32(2);
weili60607c32016-05-26 11:53:12 -07001209 // TODO(weili): check whether we need to implement this, pdfium:501.
1210 // For now, just put the variables here to avoid unused variable warning.
1211 (void)wsExpression;
1212 (void)wsValue;
1213 (void)iAction;
Dan Sinclair1770c022016-03-14 14:14:16 -04001214}
weili60607c32016-05-26 11:53:12 -07001215
Dan Sinclair1770c022016-03-14 14:14:16 -04001216void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
1217 int32_t iLength = pArguments->GetLength();
1218 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001219 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clone");
Dan Sinclair1770c022016-03-14 14:14:16 -04001220 return;
1221 }
weili44f8faf2016-06-01 14:03:56 -07001222 bool bClone = !!pArguments->GetInt32(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001223 CXFA_Node* pCloneNode = Clone(bClone);
dsinclairf27aeec2016-06-07 19:36:18 -07001224 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001225 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
1226}
weili44f8faf2016-06-01 14:03:56 -07001227
Dan Sinclair1770c022016-03-14 14:14:16 -04001228void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
1229 int32_t iLength = pArguments->GetLength();
1230 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001231 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001232 return;
1233 }
tsepez6fe7d212016-04-06 10:51:14 -07001234 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001235 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001236 CFX_WideString wsValue;
tsepez4c3debb2016-04-08 12:20:38 -07001237 GetAttribute(wsExpression.AsStringC(), wsValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07001238 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001239 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001240 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001241}
weili44f8faf2016-06-01 14:03:56 -07001242
Dan Sinclair1770c022016-03-14 14:14:16 -04001243void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
1244 int32_t iLength = pArguments->GetLength();
1245 if (iLength < 1 || iLength > 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07001246 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001247 return;
1248 }
1249 CFX_WideString wsExpression;
1250 int32_t iValue = 0;
weili44f8faf2016-06-01 14:03:56 -07001251 wsExpression =
1252 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1253 if (iLength >= 2)
Dan Sinclair1770c022016-03-14 14:14:16 -04001254 iValue = pArguments->GetInt32(1);
dsinclair6e124782016-06-23 12:14:55 -07001255 CXFA_Node* pNode =
1256 GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
dsinclairf27aeec2016-06-07 19:36:18 -07001257 pArguments->GetReturnValue()->Assign(
1258 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001259}
weili65be4b12016-05-25 15:47:43 -07001260
Dan Sinclair1770c022016-03-14 14:14:16 -04001261void CXFA_Node::Script_NodeClass_IsPropertySpecified(
1262 CFXJSE_Arguments* pArguments) {
1263 int32_t iLength = pArguments->GetLength();
1264 if (iLength < 1 || iLength > 3) {
dsinclair2235b7b2016-06-02 07:42:25 -07001265 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isPropertySpecified");
Dan Sinclair1770c022016-03-14 14:14:16 -04001266 return;
1267 }
1268 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001269 bool bParent = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001270 int32_t iIndex = 0;
weili44f8faf2016-06-01 14:03:56 -07001271 wsExpression =
1272 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili65be4b12016-05-25 15:47:43 -07001273 if (iLength >= 2)
weili44f8faf2016-06-01 14:03:56 -07001274 bParent = !!pArguments->GetInt32(1);
weili65be4b12016-05-25 15:47:43 -07001275 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001276 iIndex = pArguments->GetInt32(2);
tsepezd19e9122016-11-02 15:43:18 -07001277 bool bHas = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001278 const XFA_ATTRIBUTEINFO* pAttributeInfo =
tsepez4c3debb2016-04-08 12:20:38 -07001279 XFA_GetAttributeByName(wsExpression.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001280 CFX_WideString wsValue;
weili65be4b12016-05-25 15:47:43 -07001281 if (pAttributeInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04001282 bHas = HasAttribute(pAttributeInfo->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04001283 if (!bHas) {
dsinclair6e124782016-06-23 12:14:55 -07001284 XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
1285 bHas = !!GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001286 if (!bHas && bParent && m_pParent) {
1287 // Also check on the parent.
1288 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
1289 if (!bHas)
dsinclair6e124782016-06-23 12:14:55 -07001290 bHas = !!m_pParent->GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001291 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001292 }
dsinclair12a6b0c2016-05-26 11:14:08 -07001293 CFXJSE_Value* pValue = pArguments->GetReturnValue();
1294 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001295 pValue->SetBoolean(bHas);
Dan Sinclair1770c022016-03-14 14:14:16 -04001296}
weili65be4b12016-05-25 15:47:43 -07001297
Dan Sinclair1770c022016-03-14 14:14:16 -04001298void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
1299 int32_t iLength = pArguments->GetLength();
1300 if (iLength < 1 || iLength > 3) {
dsinclair2235b7b2016-06-02 07:42:25 -07001301 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001302 return;
1303 }
1304 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001305 bool bIgnoreRoot = true;
1306 bool bOverwrite = 0;
1307 wsExpression =
1308 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1309 if (wsExpression.IsEmpty())
Tom Sepezd3743ea2016-05-16 15:56:53 -07001310 return;
weili44f8faf2016-06-01 14:03:56 -07001311 if (iLength >= 2)
1312 bIgnoreRoot = !!pArguments->GetInt32(1);
1313 if (iLength >= 3)
1314 bOverwrite = !!pArguments->GetInt32(2);
dsinclaira1b07722016-07-11 08:20:58 -07001315 std::unique_ptr<CXFA_SimpleParser> pParser(
1316 new CXFA_SimpleParser(m_pDocument, false));
weili44f8faf2016-06-01 14:03:56 -07001317 if (!pParser)
Dan Sinclair1770c022016-03-14 14:14:16 -04001318 return;
weili44f8faf2016-06-01 14:03:56 -07001319 CFDE_XMLNode* pXMLNode = nullptr;
1320 int32_t iParserStatus =
1321 pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
1322 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
1323 return;
dsinclairae95f762016-03-29 16:58:29 -07001324 if (bIgnoreRoot &&
1325 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
1326 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
weili44f8faf2016-06-01 14:03:56 -07001327 bIgnoreRoot = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001328 }
tsepezd19e9122016-11-02 15:43:18 -07001329 CXFA_Node* pFakeRoot = Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001330 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
1331 if (!wsContentType.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07001332 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
1333 CFX_WideString(wsContentType));
Dan Sinclair1770c022016-03-14 14:14:16 -04001334 }
dsinclairae95f762016-03-29 16:58:29 -07001335 CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001336 if (!pFakeXMLRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001337 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
tsepezd19e9122016-11-02 15:43:18 -07001338 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001339 }
dsinclair017052a2016-06-28 07:43:51 -07001340 if (!pFakeXMLRoot)
1341 pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName()));
1342
Dan Sinclair1770c022016-03-14 14:14:16 -04001343 if (bIgnoreRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001344 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001345 while (pXMLChild) {
dsinclairae95f762016-03-29 16:58:29 -07001346 CFDE_XMLNode* pXMLSibling =
1347 pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001348 pXMLNode->RemoveChildNode(pXMLChild);
1349 pFakeXMLRoot->InsertChildNode(pXMLChild);
1350 pXMLChild = pXMLSibling;
1351 }
1352 } else {
dsinclairae95f762016-03-29 16:58:29 -07001353 CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001354 if (pXMLParent) {
1355 pXMLParent->RemoveChildNode(pXMLNode);
1356 }
1357 pFakeXMLRoot->InsertChildNode(pXMLNode);
1358 }
1359 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot);
1360 pFakeRoot = pParser->GetRootNode();
1361 if (pFakeRoot) {
1362 if (bOverwrite) {
1363 CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1364 CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1365 int32_t index = 0;
1366 while (pNewChild) {
1367 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1368 pFakeRoot->RemoveChild(pNewChild);
1369 InsertChild(index++, pNewChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001370 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001371 pNewChild = pItem;
1372 }
1373 while (pChild) {
1374 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1375 RemoveChild(pChild);
1376 pFakeRoot->InsertChild(pChild);
1377 pChild = pItem;
1378 }
1379 if (GetPacketID() == XFA_XDPPACKET_Form &&
dsinclair070fcdf2016-06-22 22:04:54 -07001380 GetElementType() == XFA_Element::ExData) {
dsinclairae95f762016-03-29 16:58:29 -07001381 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001382 SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001383 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
weili44f8faf2016-06-01 14:03:56 -07001384 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001385 pFakeXMLRoot = pTempXMLNode;
1386 } else {
weili44f8faf2016-06-01 14:03:56 -07001387 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001388 }
1389 }
tsepezd19e9122016-11-02 15:43:18 -07001390 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001391 } else {
1392 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1393 while (pChild) {
1394 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1395 pFakeRoot->RemoveChild(pChild);
1396 InsertChild(pChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001397 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001398 pChild = pItem;
1399 }
1400 }
1401 if (pFakeXMLRoot) {
1402 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001403 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001404 }
dsinclairc5a8f212016-06-20 11:11:12 -07001405 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001406 } else {
Tom Sepezd3743ea2016-05-16 15:56:53 -07001407 if (pFakeXMLRoot) {
1408 pFakeXMLRoot->Release();
weili44f8faf2016-06-01 14:03:56 -07001409 pFakeXMLRoot = nullptr;
Tom Sepezd3743ea2016-05-16 15:56:53 -07001410 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001411 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001412}
weili44f8faf2016-06-01 14:03:56 -07001413
Dan Sinclair1770c022016-03-14 14:14:16 -04001414void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
weili44f8faf2016-06-01 14:03:56 -07001415 // TODO(weili): Check whether we need to implement this, pdfium:501.
Dan Sinclair1770c022016-03-14 14:14:16 -04001416}
1417
1418void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1419 int32_t iLength = pArguments->GetLength();
1420 if (iLength < 0 || iLength > 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001421 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001422 return;
1423 }
weili44f8faf2016-06-01 14:03:56 -07001424 bool bPrettyMode = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001425 if (iLength == 1) {
weili65be4b12016-05-25 15:47:43 -07001426 if (pArguments->GetUTF8String(0) != "pretty") {
dsinclair2235b7b2016-06-02 07:42:25 -07001427 ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
Dan Sinclair1770c022016-03-14 14:14:16 -04001428 return;
1429 }
weili44f8faf2016-06-01 14:03:56 -07001430 bPrettyMode = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001431 }
1432 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
weili65be4b12016-05-25 15:47:43 -07001433 if (GetPacketID() == XFA_XDPPACKET_Form ||
1434 GetPacketID() == XFA_XDPPACKET_Datasets) {
1435 CFDE_XMLNode* pElement = nullptr;
1436 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1437 pElement = GetXMLMappingNode();
1438 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
dsinclairf27aeec2016-06-07 19:36:18 -07001439 pArguments->GetReturnValue()->SetString(bsXMLHeader);
weili65be4b12016-05-25 15:47:43 -07001440 return;
1441 }
1442 XFA_DataExporter_DealWithDataGroupNode(this);
1443 }
weili44f8faf2016-06-01 14:03:56 -07001444 std::unique_ptr<IFX_MemoryStream, ReleaseDeleter<IFX_MemoryStream>>
tsepez345d4892016-11-30 15:10:55 -08001445 pMemoryStream(IFX_MemoryStream::Create(true));
tsepez0527ec52016-12-02 10:53:30 -08001446 std::unique_ptr<IFGAS_Stream, ReleaseDeleter<IFGAS_Stream>> pStream(
1447 IFGAS_Stream::CreateStream(
tsepezad2441e2016-10-24 10:19:11 -07001448 static_cast<IFX_SeekableWriteStream*>(pMemoryStream.get()),
weili44f8faf2016-06-01 14:03:56 -07001449 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write |
1450 FX_STREAMACCESS_Append));
Dan Sinclair1770c022016-03-14 14:14:16 -04001451 if (!pStream) {
dsinclairf27aeec2016-06-07 19:36:18 -07001452 pArguments->GetReturnValue()->SetString(bsXMLHeader);
Dan Sinclair1770c022016-03-14 14:14:16 -04001453 return;
1454 }
1455 pStream->SetCodePage(FX_CODEPAGE_UTF8);
dsinclair179bebb2016-04-05 11:02:18 -07001456 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
weili65be4b12016-05-25 15:47:43 -07001457 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepezd19e9122016-11-02 15:43:18 -07001458 XFA_DataExporter_RegenerateFormFile(this, pStream.get(), nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001459 else
1460 pElement->SaveXMLNode(pStream.get());
1461 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1462 // For now, just put it here to avoid unused variable warning.
1463 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001464 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001465 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001466 return;
1467 }
dsinclairf27aeec2016-06-07 19:36:18 -07001468 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001469}
1470
1471void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1472 int32_t iLength = pArguments->GetLength();
1473 if (iLength != 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07001474 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001475 return;
1476 }
tsepez6fe7d212016-04-06 10:51:14 -07001477 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001478 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001479 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001480 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001481 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001482}
weili60607c32016-05-26 11:53:12 -07001483
Dan Sinclair1770c022016-03-14 14:14:16 -04001484void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1485 int32_t iLength = pArguments->GetLength();
1486 if (iLength != 1 && iLength != 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07001487 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001488 return;
1489 }
weili60607c32016-05-26 11:53:12 -07001490 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001491 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001492 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1493 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001494 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001495 // TODO(weili): check whether we need to implement this, pdfium:501.
1496 // For now, just put the variables here to avoid unused variable warning.
1497 (void)pNode;
1498 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001499}
weili60607c32016-05-26 11:53:12 -07001500
dsinclair12a6b0c2016-05-26 11:14:08 -07001501void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001502 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001503 XFA_ATTRIBUTE eAttribute) {
1504 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001505 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001506 } else {
1507 CFX_WideString wsNameSpace;
1508 TryNamespace(wsNameSpace);
dsinclairf27aeec2016-06-07 19:36:18 -07001509 pValue->SetString(FX_UTF8Encode(wsNameSpace).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001510 }
1511}
weili44f8faf2016-06-01 14:03:56 -07001512
dsinclair12a6b0c2016-05-26 11:14:08 -07001513void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001514 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001515 XFA_ATTRIBUTE eAttribute) {
1516 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001517 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001518 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001519 pValue->Assign(
1520 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001521 }
1522}
weili44f8faf2016-06-01 14:03:56 -07001523
dsinclair12a6b0c2016-05-26 11:14:08 -07001524void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001525 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001526 XFA_ATTRIBUTE eAttribute) {
weili44f8faf2016-06-01 14:03:56 -07001527 if (bSetting)
dsinclair2235b7b2016-06-02 07:42:25 -07001528 ThrowException(XFA_IDS_INVAlID_PROP_SET);
weili44f8faf2016-06-01 14:03:56 -07001529 else
dsinclairf27aeec2016-06-07 19:36:18 -07001530 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001531}
weili44f8faf2016-06-01 14:03:56 -07001532
dsinclair12a6b0c2016-05-26 11:14:08 -07001533void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001534 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001535 XFA_ATTRIBUTE eAttribute) {
1536 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001537 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001538 } else {
dsinclair070fcdf2016-06-22 22:04:54 -07001539 if (GetElementType() == XFA_Element::Subform) {
tsepezd19e9122016-11-02 15:43:18 -07001540 pValue->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001541 return;
1542 }
1543 CFX_WideString strValue;
dsinclairf27aeec2016-06-07 19:36:18 -07001544 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001545 }
1546}
weili44f8faf2016-06-01 14:03:56 -07001547
dsinclair12a6b0c2016-05-26 11:14:08 -07001548void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001549 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001550 XFA_ATTRIBUTE eAttribute) {
1551 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001552 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001553 } else {
1554 CXFA_NodeArray properts;
1555 int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty);
1556 if (iSize > 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07001557 pValue->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001558 m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0]));
1559 }
1560 }
1561}
weili44f8faf2016-06-01 14:03:56 -07001562
Dan Sinclair1770c022016-03-14 14:14:16 -04001563void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001564
Dan Sinclair1770c022016-03-14 14:14:16 -04001565void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1566 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001567 pArguments->GetReturnValue()->SetObject(
1568 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001569}
1570void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1571}
dsinclair5b36f0a2016-07-19 10:56:23 -07001572
Dan Sinclair1770c022016-03-14 14:14:16 -04001573void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1574 Script_Template_CreateNode(pArguments);
1575}
dsinclair5b36f0a2016-07-19 10:56:23 -07001576
Dan Sinclair1770c022016-03-14 14:14:16 -04001577void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1578 int32_t iLength = pArguments->GetLength();
1579 if (iLength < 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001580 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001581 return;
1582 }
1583 CFX_WideString wsNameSpace;
1584 if (iLength >= 1) {
1585 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001586 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001587 }
1588 CFX_WideString wsNodeNameSpace;
1589 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001590 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001591 if (pValue)
1592 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001593}
dsinclair5b36f0a2016-07-19 10:56:23 -07001594
dsinclair12a6b0c2016-05-26 11:14:08 -07001595void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001596 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001597 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001598
dsinclair12a6b0c2016-05-26 11:14:08 -07001599void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001600 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001601 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001602
dsinclair12a6b0c2016-05-26 11:14:08 -07001603void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001604 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001605 XFA_ATTRIBUTE eAttribute) {
1606 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001607 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001608 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001609 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001610 }
1611}
dsinclair5b36f0a2016-07-19 10:56:23 -07001612
dsinclair12a6b0c2016-05-26 11:14:08 -07001613void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001614 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001615 XFA_ATTRIBUTE eAttribute) {
1616 if (!bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001617 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001618 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001619 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001620 }
1621}
dsinclair5b36f0a2016-07-19 10:56:23 -07001622
dsinclair12a6b0c2016-05-26 11:14:08 -07001623void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001624 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001625 XFA_ATTRIBUTE eAttribute) {
1626 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001627 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001628 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001629 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001630 }
1631}
dsinclair5b36f0a2016-07-19 10:56:23 -07001632
dsinclair12a6b0c2016-05-26 11:14:08 -07001633void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001634 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001635 XFA_ATTRIBUTE eAttribute) {
1636 if (!bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001637 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001638 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001639 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001640 }
1641}
thestigb1a59592016-04-14 18:29:56 -07001642
Dan Sinclair1770c022016-03-14 14:14:16 -04001643void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001644 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001645 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001646 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001647 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001648 return;
thestigb1a59592016-04-14 18:29:56 -07001649
dsinclaira1b07722016-07-11 08:20:58 -07001650 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001651 if (!pNotify)
1652 return;
1653
1654 uint32_t dwPacket = GetPacketID();
1655 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1656 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001657 return;
1658 }
thestigb1a59592016-04-14 18:29:56 -07001659
1660 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001661 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001662 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001663 bNeedFindContainer = true;
1664 pNotify->OnValueChanged(this, eAttribute, this,
1665 GetNodeItem(XFA_NODEITEM_Parent));
1666 break;
dsinclair56a8b192016-06-21 14:15:25 -07001667 case XFA_Element::Font:
1668 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001669 bNeedFindContainer = true;
1670 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001671 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001672 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1673 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1674 } else {
1675 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1676 }
1677 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001678 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001679 bNeedFindContainer = true;
1680 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001681 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001682 if (pParentNode->IsContainerNode()) {
1683 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001684 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001685 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1686 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1687 } else {
1688 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001689 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001690 pNotify->OnValueChanged(this, eAttribute, pNode,
1691 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001692 }
thestigb1a59592016-04-14 18:29:56 -07001693 }
1694 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001695 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001696 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001697 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001698 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1699 eUIType == XFA_Element::NumericEdit ||
1700 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001701 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001702 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001703 pNotify->OnValueChanged(this, eAttribute, pUINode,
1704 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001705 }
thestigb1a59592016-04-14 18:29:56 -07001706 }
1707 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001708 case XFA_Element::Button:
1709 case XFA_Element::Barcode:
1710 case XFA_Element::ChoiceList:
1711 case XFA_Element::DateTimeEdit:
1712 case XFA_Element::NumericEdit:
1713 case XFA_Element::PasswordEdit:
1714 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001715 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1716 if (pUINode) {
1717 pNotify->OnValueChanged(this, eAttribute, pUINode,
1718 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1719 }
1720 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001721 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001722 bNeedFindContainer = true;
1723 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1724 if (pUINode) {
1725 pNotify->OnValueChanged(this, eAttribute, pUINode,
1726 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1727 }
1728 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001729 case XFA_Element::Keep:
1730 case XFA_Element::Bookend:
1731 case XFA_Element::Break:
1732 case XFA_Element::BreakAfter:
1733 case XFA_Element::BreakBefore:
1734 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001735 bNeedFindContainer = true;
1736 break;
dsinclair56a8b192016-06-21 14:15:25 -07001737 case XFA_Element::Area:
1738 case XFA_Element::Draw:
1739 case XFA_Element::ExclGroup:
1740 case XFA_Element::Field:
1741 case XFA_Element::Subform:
1742 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001743 pLayoutPro->AddChangedContainer(this);
1744 pNotify->OnValueChanged(this, eAttribute, this, this);
1745 break;
dsinclair56a8b192016-06-21 14:15:25 -07001746 case XFA_Element::Sharptext:
1747 case XFA_Element::Sharpxml:
1748 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001749 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1750 if (!pTextNode) {
1751 return;
1752 }
1753 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1754 if (!pValueNode) {
1755 return;
1756 }
dsinclair41cb62e2016-06-23 09:20:32 -07001757 XFA_Element eType = pValueNode->GetElementType();
1758 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001759 bNeedFindContainer = true;
1760 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1761 if (pNode && pNode->IsContainerNode()) {
1762 if (bScriptModify) {
1763 pValueNode = pNode;
1764 }
1765 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1766 } else {
1767 pNotify->OnValueChanged(this, eAttribute, pNode,
1768 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001769 }
thestigb1a59592016-04-14 18:29:56 -07001770 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001771 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001772 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1773 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001774 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001775 }
1776 }
thestigb1a59592016-04-14 18:29:56 -07001777 }
1778 } break;
1779 default:
1780 break;
1781 }
1782 if (bNeedFindContainer) {
1783 CXFA_Node* pParent = this;
1784 while (pParent) {
1785 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001786 break;
thestigb1a59592016-04-14 18:29:56 -07001787
1788 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001789 }
thestigb1a59592016-04-14 18:29:56 -07001790 if (pParent) {
1791 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001792 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001793 }
1794}
thestigb1a59592016-04-14 18:29:56 -07001795
dsinclair12a6b0c2016-05-26 11:14:08 -07001796void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001797 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001798 XFA_ATTRIBUTE eAttribute) {
1799 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001800 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001801 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001802 if (eAttribute == XFA_ATTRIBUTE_Use &&
1803 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001804 CXFA_Node* pTemplateNode =
1805 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1806 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001807 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1808 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001809
1810 CFX_WideString wsID;
1811 CFX_WideString wsSOM;
1812 if (!wsValue.IsEmpty()) {
1813 if (wsValue[0] == '#') {
1814 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001815 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001816 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001817 }
1818 }
weili44f8faf2016-06-01 14:03:56 -07001819 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001820 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001821 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001822 XFA_RESOLVENODE_Attributes |
1823 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1824 XFA_RESOLVENODE_Siblings;
1825 XFA_RESOLVENODE_RS resoveNodeRS;
1826 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001827 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001828 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) {
1829 pProtoNode = resoveNodeRS.nodes[0]->AsNode();
1830 }
1831 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001832 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001833 }
1834 if (pProtoNode) {
1835 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1836 while (pHeadChild) {
1837 CXFA_Node* pSibling =
1838 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1839 RemoveChild(pHeadChild);
1840 pHeadChild = pSibling;
1841 }
tsepezd19e9122016-11-02 15:43:18 -07001842 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001843 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1844 while (pHeadChild) {
1845 CXFA_Node* pSibling =
1846 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1847 pProtoForm->RemoveChild(pHeadChild);
1848 InsertChild(pHeadChild);
1849 pHeadChild = pSibling;
1850 }
1851 m_pDocument->RemovePurgeNode(pProtoForm);
1852 delete pProtoForm;
1853 }
1854 }
1855 } else {
1856 CFX_WideString wsValue;
1857 GetAttribute(eAttribute, wsValue);
dsinclairf27aeec2016-06-07 19:36:18 -07001858 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07001859 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001860 }
1861}
dsinclair5b36f0a2016-07-19 10:56:23 -07001862
dsinclair12a6b0c2016-05-26 11:14:08 -07001863void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001864 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001865 XFA_ATTRIBUTE eAttribute) {
1866 if (!bSetting) {
1867 CFX_WideString wsValue;
1868 GetAttribute(eAttribute, wsValue);
dsinclairf27aeec2016-06-07 19:36:18 -07001869 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07001870 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001871 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001872 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001873 }
1874}
dsinclair5b36f0a2016-07-19 10:56:23 -07001875
Dan Sinclair1770c022016-03-14 14:14:16 -04001876void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1877 int32_t argc = pArguments->GetLength();
1878 if ((argc == 0) || (argc == 1)) {
tsepezd19e9122016-11-02 15:43:18 -07001879 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001880 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001881 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001882 }
1883}
dsinclair5b36f0a2016-07-19 10:56:23 -07001884
Dan Sinclair1770c022016-03-14 14:14:16 -04001885void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
1886 int32_t argc = pArguments->GetLength();
1887 if (argc == 0) {
1888 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001889 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001890 }
1891}
dsinclair5b36f0a2016-07-19 10:56:23 -07001892
dsinclair12a6b0c2016-05-26 11:14:08 -07001893void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001894 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001895 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001896
dsinclair12a6b0c2016-05-26 11:14:08 -07001897void CXFA_Node::Script_Delta_SavedValue(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_Target(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_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001906 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001907 XFA_SOM_MESSAGETYPE iMessageType) {
1908 CXFA_WidgetData* pWidgetData = GetWidgetData();
1909 if (!pWidgetData) {
1910 return;
1911 }
tsepezd19e9122016-11-02 15:43:18 -07001912 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001913 CXFA_Validate validate = pWidgetData->GetValidate();
1914 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001915 validate = pWidgetData->GetValidate(true);
1916 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001917 }
1918 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001919 switch (iMessageType) {
1920 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001921 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001922 break;
1923 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001924 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001925 break;
1926 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001927 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001928 break;
1929 default:
1930 break;
1931 }
1932 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001933 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001934 if (!pNotify) {
1935 return;
1936 }
1937 pNotify->AddCalcValidate(this);
1938 }
1939 } else {
1940 CFX_WideString wsMessage;
1941 switch (iMessageType) {
1942 case XFA_SOM_ValidationMessage:
1943 validate.GetScriptMessageText(wsMessage);
1944 break;
1945 case XFA_SOM_FormatMessage:
1946 validate.GetFormatMessageText(wsMessage);
1947 break;
1948 case XFA_SOM_MandatoryMessage:
1949 validate.GetNullMessageText(wsMessage);
1950 break;
1951 default:
1952 break;
1953 }
dsinclairf27aeec2016-06-07 19:36:18 -07001954 pValue->SetString(FX_UTF8Encode(wsMessage).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001955 }
1956}
dsinclair5b36f0a2016-07-19 10:56:23 -07001957
dsinclair12a6b0c2016-05-26 11:14:08 -07001958void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001959 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001960 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001961 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001962}
dsinclair5b36f0a2016-07-19 10:56:23 -07001963
dsinclair12a6b0c2016-05-26 11:14:08 -07001964void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001965 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001966 XFA_ATTRIBUTE eAttribute) {
1967 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001968 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001969 } else {
1970 CXFA_WidgetData* pWidgetData = GetWidgetData();
1971 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07001972 pValue->SetInteger(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001973 return;
1974 }
tsepezd19e9122016-11-02 15:43:18 -07001975 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001976 }
1977}
dsinclair5b36f0a2016-07-19 10:56:23 -07001978
dsinclair12a6b0c2016-05-26 11:14:08 -07001979void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001980 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001981 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001982 XFA_Element eType = GetElementType();
1983 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001984 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001985 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001986 }
1987 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001988 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001989 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001990 }
1991 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001992 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001993 return;
1994 }
1995 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001996 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07001997 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07001998 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07001999
Dan Sinclair1770c022016-03-14 14:14:16 -04002000 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07002001 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002002 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
2003 CXFA_NodeArray formNodes;
2004 GetBindItems(formNodes);
2005 CFX_WideString wsPicture;
2006 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
2007 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -07002008 if (!pFormNode || pFormNode->HasRemovedChildren()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002009 continue;
2010 }
2011 pContainerWidgetData = pFormNode->GetContainerWidgetData();
2012 if (pContainerWidgetData) {
2013 pContainerWidgetData->GetPictureContent(wsPicture,
2014 XFA_VALUEPICTURE_DataBind);
2015 }
2016 if (!wsPicture.IsEmpty()) {
2017 break;
2018 }
weili44f8faf2016-06-01 14:03:56 -07002019 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002020 }
2021 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
2022 pContainerWidgetData = GetContainerWidgetData();
2023 }
2024 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002025 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002026 }
tsepezd19e9122016-11-02 15:43:18 -07002027 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002028 } else {
tsepezd19e9122016-11-02 15:43:18 -07002029 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07002030 if (content.IsEmpty() && eType != XFA_Element::Text &&
2031 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07002032 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07002033 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002034 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07002035 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07002036 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002037 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002038 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002039 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002040 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002041 }
2042 }
2043}
dsinclair5b36f0a2016-07-19 10:56:23 -07002044
dsinclair12a6b0c2016-05-26 11:14:08 -07002045void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002046 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002047 XFA_ATTRIBUTE eAttribute) {
2048 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07002049 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002050 return;
2051 }
tsepezd19e9122016-11-02 15:43:18 -07002052 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002053 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002054 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002055 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002056 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002057 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002058 }
2059}
dsinclair5b36f0a2016-07-19 10:56:23 -07002060
dsinclair12a6b0c2016-05-26 11:14:08 -07002061void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002062 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002063 XFA_ATTRIBUTE eAttribute) {
2064 if (bSetting) {
2065 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002066 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002067 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002068
tsepezb4c9f3f2016-04-13 15:41:21 -07002069 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002070 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002071 CFX_WideString wsFormatValue(wsNewValue);
2072 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2073 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002074 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002075 }
tsepezd19e9122016-11-02 15:43:18 -07002076 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002077 } else {
tsepezd19e9122016-11-02 15:43:18 -07002078 CFX_WideString wsValue = GetScriptContent(true);
dsinclairf27aeec2016-06-07 19:36:18 -07002079 pValue->SetBoolean(wsValue == FX_WSTRC(L"1"));
Dan Sinclair1770c022016-03-14 14:14:16 -04002080 }
2081}
dsinclair2f5582f2016-06-09 11:48:23 -07002082
dsinclair12a6b0c2016-05-26 11:14:08 -07002083void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002084 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002085 XFA_ATTRIBUTE eAttribute) {
2086 CXFA_WidgetData* pWidgetData = GetWidgetData();
2087 if (!pWidgetData) {
2088 return;
2089 }
tsepezd19e9122016-11-02 15:43:18 -07002090 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002091 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002092 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002093 int32_t r = 0;
2094 int32_t g = 0;
2095 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002096 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002097 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2098 for (int32_t i = 0; i < iSize; ++i) {
2099 CXFA_Edge edge = border.GetEdge(i);
2100 edge.SetColor(rgb);
2101 }
2102 } else {
2103 CXFA_Edge edge = border.GetEdge(0);
2104 FX_ARGB color = edge.GetColor();
2105 int32_t a, r, g, b;
2106 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002107 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002108 strColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002109 pValue->SetString(FX_UTF8Encode(strColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002110 }
2111}
dsinclair5b36f0a2016-07-19 10:56:23 -07002112
dsinclair12a6b0c2016-05-26 11:14:08 -07002113void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002114 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002115 XFA_ATTRIBUTE eAttribute) {
2116 CXFA_WidgetData* pWidgetData = GetWidgetData();
2117 if (!pWidgetData) {
2118 return;
2119 }
tsepezd19e9122016-11-02 15:43:18 -07002120 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002121 int32_t iSize = border.CountEdges();
2122 CFX_WideString wsThickness;
2123 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002124 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002125 for (int32_t i = 0; i < iSize; ++i) {
2126 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002127 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002128 edge.SetMSThickness(thickness);
2129 }
2130 } else {
2131 CXFA_Edge edge = border.GetEdge(0);
2132 CXFA_Measurement thickness = edge.GetMSThickness();
2133 thickness.ToString(wsThickness);
dsinclairf27aeec2016-06-07 19:36:18 -07002134 pValue->SetString(FX_UTF8Encode(wsThickness).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002135 }
2136}
dsinclair5b36f0a2016-07-19 10:56:23 -07002137
dsinclair12a6b0c2016-05-26 11:14:08 -07002138void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002139 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002140 XFA_ATTRIBUTE eAttribute) {
2141 CXFA_WidgetData* pWidgetData = GetWidgetData();
2142 if (!pWidgetData) {
2143 return;
2144 }
tsepezd19e9122016-11-02 15:43:18 -07002145 CXFA_Border border = pWidgetData->GetBorder(true);
2146 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002147 CXFA_Node* pNode = borderfill.GetNode();
2148 if (!pNode) {
2149 return;
2150 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002151 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002152 int32_t r;
2153 int32_t g;
2154 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002155 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002156 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2157 borderfill.SetColor(color);
2158 } else {
2159 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002160 int32_t a;
2161 int32_t r;
2162 int32_t g;
2163 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002164 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002165 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002166 wsColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002167 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002168 }
2169}
dsinclair5b36f0a2016-07-19 10:56:23 -07002170
dsinclair12a6b0c2016-05-26 11:14:08 -07002171void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002172 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002173 XFA_ATTRIBUTE eAttribute) {
2174 if (!bSetting) {
2175 CXFA_Node* pDataNode = GetBindData();
2176 if (pDataNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002177 pValue->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002178 m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
2179 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002180 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002181 }
2182 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002183 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002184 }
2185}
dsinclair5b36f0a2016-07-19 10:56:23 -07002186
dsinclair12a6b0c2016-05-26 11:14:08 -07002187void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002188 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002189 XFA_ATTRIBUTE eAttribute) {
2190 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002191 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002192 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002193 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002194 XFA_Element uiType = pWidgetData->GetUIType();
2195 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002196 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002197 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002198 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002199 }
2200 }
2201 } else {
tsepezd19e9122016-11-02 15:43:18 -07002202 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002203 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002204 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002205 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002206 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002207 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002208 }
2209 }
2210}
dsinclair5b36f0a2016-07-19 10:56:23 -07002211
dsinclair12a6b0c2016-05-26 11:14:08 -07002212void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002213 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002214 XFA_ATTRIBUTE eAttribute) {
2215 CXFA_WidgetData* pWidgetData = GetWidgetData();
2216 if (!pWidgetData) {
2217 return;
2218 }
2219 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002220 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002221 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002222 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002223 } else {
2224 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002225 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002226 }
dsinclair2f5582f2016-06-09 11:48:23 -07002227 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002228 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002229 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002230
Dan Sinclair1770c022016-03-14 14:14:16 -04002231 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002232 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002233 int32_t iLeadDigits = 0;
2234 int32_t iFracDigits = 0;
2235 pWidgetData->GetLeadDigits(iLeadDigits);
2236 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002237 wsNewText =
2238 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002239 }
2240 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2241 CFX_WideString wsFormatText(wsNewText);
2242 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002243 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002244 }
tsepezd19e9122016-11-02 15:43:18 -07002245 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002246 } else {
tsepezd19e9122016-11-02 15:43:18 -07002247 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002248 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002249 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002250 } else {
2251 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002252 CXFA_Value defVal = pWidgetData->GetFormValue();
2253 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002254 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002255 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002256 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002257 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002258 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002259 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002260 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002261 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002262 }
dsinclair070fcdf2016-06-22 22:04:54 -07002263 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002264 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002265 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002266 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002267 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002268 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002269 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002270 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002271 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002272 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002273 }
2274 }
2275 }
2276}
dsinclair5b36f0a2016-07-19 10:56:23 -07002277
dsinclair12a6b0c2016-05-26 11:14:08 -07002278void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002279 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002280 XFA_ATTRIBUTE eAttribute) {
2281 CXFA_WidgetData* pWidgetData = GetWidgetData();
2282 if (!pWidgetData) {
2283 return;
2284 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002285 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002286 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002287 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002288 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002289 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
dsinclairf27aeec2016-06-07 19:36:18 -07002290 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002291 }
2292}
dsinclair5b36f0a2016-07-19 10:56:23 -07002293
dsinclair12a6b0c2016-05-26 11:14:08 -07002294void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002295 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002296 XFA_ATTRIBUTE eAttribute) {
2297 CXFA_WidgetData* pWidgetData = GetWidgetData();
2298 if (!pWidgetData) {
2299 return;
2300 }
tsepezd19e9122016-11-02 15:43:18 -07002301 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002302 CXFA_Node* pNode = font.GetNode();
2303 if (!pNode) {
2304 return;
2305 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002306 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002307 int32_t r;
2308 int32_t g;
2309 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002310 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002311 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2312 font.SetColor(color);
2313 } else {
2314 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002315 int32_t a;
2316 int32_t r;
2317 int32_t g;
2318 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002319 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002320 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002321 wsColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002322 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002323 }
2324}
dsinclair5b36f0a2016-07-19 10:56:23 -07002325
dsinclair12a6b0c2016-05-26 11:14:08 -07002326void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002327 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002328 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002329 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002330}
dsinclair5b36f0a2016-07-19 10:56:23 -07002331
dsinclair12a6b0c2016-05-26 11:14:08 -07002332void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002333 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002334 XFA_ATTRIBUTE eAttribute) {
2335 CXFA_WidgetData* pWidgetData = GetWidgetData();
2336 if (!pWidgetData) {
2337 return;
2338 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002339 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002340 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002341 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002342 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002343 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
dsinclairf27aeec2016-06-07 19:36:18 -07002344 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002345 }
2346}
dsinclair5b36f0a2016-07-19 10:56:23 -07002347
dsinclair12a6b0c2016-05-26 11:14:08 -07002348void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002349 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002350 XFA_ATTRIBUTE eAttribute) {
2351 CXFA_WidgetData* pWidgetData = GetWidgetData();
2352 if (!pWidgetData) {
2353 return;
2354 }
tsepezd19e9122016-11-02 15:43:18 -07002355 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002356 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002357 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002358 } else {
2359 int32_t iValue = validate.GetNullTest();
2360 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002361 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002362 CFX_WideString wsValue;
2363 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002364 wsValue = pInfo->pName;
dsinclairf27aeec2016-06-07 19:36:18 -07002365 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002366 }
2367}
dsinclair5b36f0a2016-07-19 10:56:23 -07002368
dsinclair12a6b0c2016-05-26 11:14:08 -07002369void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002370 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002371 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002372 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002373}
dsinclair5b36f0a2016-07-19 10:56:23 -07002374
dsinclair12a6b0c2016-05-26 11:14:08 -07002375void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002376 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002377 XFA_ATTRIBUTE eAttribute) {
2378 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07002379 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002380 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002381 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002382 }
2383}
dsinclair5b36f0a2016-07-19 10:56:23 -07002384
dsinclair12a6b0c2016-05-26 11:14:08 -07002385void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002386 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002387 XFA_ATTRIBUTE eAttribute) {
2388 CXFA_WidgetData* pWidgetData = GetWidgetData();
2389 if (!pWidgetData) {
2390 return;
2391 }
2392 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002393 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002394 if (iIndex == -1) {
2395 pWidgetData->ClearAllSelections();
2396 return;
2397 }
tsepezd19e9122016-11-02 15:43:18 -07002398 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002399 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002400 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002401 }
2402}
dsinclair5b36f0a2016-07-19 10:56:23 -07002403
Dan Sinclair1770c022016-03-14 14:14:16 -04002404void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2405 CXFA_WidgetData* pWidgetData = GetWidgetData();
2406 if (!pWidgetData) {
2407 return;
2408 }
tsepezd19e9122016-11-02 15:43:18 -07002409 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002410}
dsinclair5b36f0a2016-07-19 10:56:23 -07002411
Dan Sinclair1770c022016-03-14 14:14:16 -04002412void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
2413 int32_t argc = pArguments->GetLength();
2414 if (argc == 1) {
2415 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2416 int32_t iRet = execSingleEventByName(
tsepez4c3debb2016-04-08 12:20:38 -07002417 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
dsinclair56a8b192016-06-21 14:15:25 -07002418 XFA_Element::Field);
Dan Sinclair1770c022016-03-14 14:14:16 -04002419 if (eventString == "validate") {
dsinclairf27aeec2016-06-07 19:36:18 -07002420 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07002421 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002422 }
2423 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002424 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
Dan Sinclair1770c022016-03-14 14:14:16 -04002425 }
2426}
dsinclair5b36f0a2016-07-19 10:56:23 -07002427
Dan Sinclair1770c022016-03-14 14:14:16 -04002428void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
2429 int32_t argc = pArguments->GetLength();
2430 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002431 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002432 if (!pNotify) {
2433 return;
2434 }
tsepezd19e9122016-11-02 15:43:18 -07002435 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002436 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002437 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002438 }
2439}
dsinclair5b36f0a2016-07-19 10:56:23 -07002440
Dan Sinclair1770c022016-03-14 14:14:16 -04002441void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2442 int32_t iLength = pArguments->GetLength();
2443 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002444 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002445 return;
2446 }
2447 CXFA_WidgetData* pWidgetData = GetWidgetData();
2448 if (!pWidgetData) {
2449 return;
2450 }
2451 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002452 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002453 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002454 if (pValue)
2455 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002456}
dsinclair5b36f0a2016-07-19 10:56:23 -07002457
Dan Sinclair1770c022016-03-14 14:14:16 -04002458void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2459 int32_t iLength = pArguments->GetLength();
2460 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002461 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002462 return;
2463 }
2464 int32_t iIndex = pArguments->GetInt32(0);
2465 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002466 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002467 return;
2468 }
2469 CXFA_WidgetData* pWidgetData = GetWidgetData();
2470 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002471 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002472 return;
2473 }
2474 CFX_WideString wsValue;
tsepezd19e9122016-11-02 15:43:18 -07002475 bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002476 if (bHasItem) {
dsinclairf27aeec2016-06-07 19:36:18 -07002477 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002478 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002479 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002480 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002481 }
2482}
dsinclair5b36f0a2016-07-19 10:56:23 -07002483
Dan Sinclair1770c022016-03-14 14:14:16 -04002484void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2485 int32_t iLength = pArguments->GetLength();
2486 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002487 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002488 return;
2489 }
2490 CXFA_WidgetData* pWidgetData = GetWidgetData();
2491 if (!pWidgetData) {
2492 return;
2493 }
2494 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002495 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002496 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002497 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002498 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002499 if (pValue)
2500 pValue->SetString(FX_UTF8Encode(wsBoundValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002501}
dsinclair5b36f0a2016-07-19 10:56:23 -07002502
Dan Sinclair1770c022016-03-14 14:14:16 -04002503void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2504 int32_t iLength = pArguments->GetLength();
2505 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002506 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002507 return;
2508 }
2509 CXFA_WidgetData* pWidgetData = GetWidgetData();
2510 if (!pWidgetData) {
2511 return;
2512 }
2513 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002514 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002515 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002516 if (pValue)
2517 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002518}
dsinclair5b36f0a2016-07-19 10:56:23 -07002519
Dan Sinclair1770c022016-03-14 14:14:16 -04002520void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
2521 int32_t argc = pArguments->GetLength();
2522 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002523 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002524 if (!pNotify) {
2525 return;
2526 }
tsepezd19e9122016-11-02 15:43:18 -07002527 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002528 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002529 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002530 }
2531}
dsinclair5b36f0a2016-07-19 10:56:23 -07002532
Dan Sinclair1770c022016-03-14 14:14:16 -04002533void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002534
Dan Sinclair1770c022016-03-14 14:14:16 -04002535void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2536 int32_t iLength = pArguments->GetLength();
2537 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002538 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002539 return;
2540 }
2541 int32_t iIndex = pArguments->GetInt32(0);
2542 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002543 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002544 return;
2545 }
2546 CXFA_WidgetData* pWidgetData = GetWidgetData();
2547 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002548 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002549 return;
2550 }
2551 CFX_WideString wsValue;
tsepezd19e9122016-11-02 15:43:18 -07002552 bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002553 if (bHasItem) {
dsinclairf27aeec2016-06-07 19:36:18 -07002554 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002555 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002556 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002557 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002558 }
2559}
dsinclair5b36f0a2016-07-19 10:56:23 -07002560
Dan Sinclair1770c022016-03-14 14:14:16 -04002561void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2562 int32_t iLength = pArguments->GetLength();
2563 if (iLength != 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07002564 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002565 return;
2566 }
2567 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002568 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002569 return;
thestig800222e2016-05-26 22:00:29 -07002570
Dan Sinclair1770c022016-03-14 14:14:16 -04002571 int32_t iIndex = pArguments->GetInt32(0);
2572 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002573 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002574 } else {
thestig800222e2016-05-26 22:00:29 -07002575 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002576 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002577 }
2578}
dsinclair5b36f0a2016-07-19 10:56:23 -07002579
Dan Sinclair1770c022016-03-14 14:14:16 -04002580void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2581 int32_t iLength = pArguments->GetLength();
2582 if (iLength < 1 || iLength > 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07002583 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002584 return;
2585 }
2586 CXFA_WidgetData* pWidgetData = GetWidgetData();
2587 if (!pWidgetData) {
2588 return;
2589 }
2590 CFX_WideString wsLabel;
2591 CFX_WideString wsValue;
2592 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002593 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002594 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002595 }
2596 if (iLength >= 2) {
2597 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002598 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002599 }
tsepezd19e9122016-11-02 15:43:18 -07002600 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002601}
dsinclair5b36f0a2016-07-19 10:56:23 -07002602
Dan Sinclair1770c022016-03-14 14:14:16 -04002603void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
2604 int32_t argc = pArguments->GetLength();
2605 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002606 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002607 if (!pNotify) {
tsepezd19e9122016-11-02 15:43:18 -07002608 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002609 } else {
2610 int32_t iRet =
tsepezd19e9122016-11-02 15:43:18 -07002611 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
dsinclairf27aeec2016-06-07 19:36:18 -07002612 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07002613 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002614 }
2615 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002616 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002617 }
2618}
dsinclair5b36f0a2016-07-19 10:56:23 -07002619
dsinclair12a6b0c2016-05-26 11:14:08 -07002620void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002621 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002622 XFA_ATTRIBUTE eAttribute) {
2623 if (!bSetting) {
2624 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002625 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002626 }
2627}
dsinclair5b36f0a2016-07-19 10:56:23 -07002628
dsinclair12a6b0c2016-05-26 11:14:08 -07002629void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002630 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002631 XFA_ATTRIBUTE eAttribute) {
2632 CXFA_WidgetData* pWidgetData = GetWidgetData();
2633 if (!pWidgetData) {
2634 return;
2635 }
2636 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002637 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002638 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002639 } else {
tsepezd19e9122016-11-02 15:43:18 -07002640 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002641 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2642 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002643 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002644 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002645 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002646 }
2647 }
2648}
dsinclair5b36f0a2016-07-19 10:56:23 -07002649
dsinclair12a6b0c2016-05-26 11:14:08 -07002650void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002651 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002652 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002653
Dan Sinclair1770c022016-03-14 14:14:16 -04002654void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
2655 int32_t argc = pArguments->GetLength();
2656 if (argc == 1) {
2657 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2658 execSingleEventByName(
tsepez4c3debb2016-04-08 12:20:38 -07002659 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
dsinclair56a8b192016-06-21 14:15:25 -07002660 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002661 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002662 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
Dan Sinclair1770c022016-03-14 14:14:16 -04002663 }
2664}
thestig800222e2016-05-26 22:00:29 -07002665
Dan Sinclair1770c022016-03-14 14:14:16 -04002666void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2667 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002668 if (argc < 0 || argc > 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002669 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002670 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002671 }
thestig800222e2016-05-26 22:00:29 -07002672
2673 CXFA_WidgetData* pWidgetData = GetWidgetData();
2674 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002675 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002676 return;
2677 }
2678
2679 CXFA_Node* pReturnNode = nullptr;
2680 if (argc == 0) {
2681 pReturnNode = pWidgetData->GetSelectedMember();
2682 } else {
2683 CFX_ByteString szName;
2684 szName = pArguments->GetUTF8String(0);
2685 pReturnNode = pWidgetData->SetSelectedMember(
2686 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2687 }
2688 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002689 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002690 return;
2691 }
dsinclairf27aeec2016-06-07 19:36:18 -07002692 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002693 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002694}
thestig800222e2016-05-26 22:00:29 -07002695
Dan Sinclair1770c022016-03-14 14:14:16 -04002696void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
2697 int32_t argc = pArguments->GetLength();
2698 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002699 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002700 if (!pNotify) {
2701 return;
2702 }
2703 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
2704 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002705 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002706 }
2707}
dsinclair5b36f0a2016-07-19 10:56:23 -07002708
Dan Sinclair1770c022016-03-14 14:14:16 -04002709void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
2710 int32_t argc = pArguments->GetLength();
2711 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002712 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002713 if (!pNotify) {
2714 return;
2715 }
2716 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
2717 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002718 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002719 }
2720}
dsinclair5b36f0a2016-07-19 10:56:23 -07002721
Dan Sinclair1770c022016-03-14 14:14:16 -04002722void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
2723 int32_t argc = pArguments->GetLength();
2724 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002725 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002726 if (!pNotify) {
tsepezd19e9122016-11-02 15:43:18 -07002727 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002728 } else {
2729 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
dsinclairf27aeec2016-06-07 19:36:18 -07002730 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07002731 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002732 }
2733 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002734 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002735 }
2736}
dsinclair5b36f0a2016-07-19 10:56:23 -07002737
dsinclair12a6b0c2016-05-26 11:14:08 -07002738void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002739 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002740 XFA_ATTRIBUTE eAttribute) {
2741 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002742 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002743 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002744 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002745 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2746 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002747 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002748 pManagerNode = pNode;
2749 break;
2750 }
2751 }
2752 if (pManagerNode) {
2753 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002754 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002755 if (!pNotify) {
2756 return;
2757 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002758 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002759 if (pToInstance &&
2760 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002761 pNotify->RunSubformIndexChange(pToInstance);
2762 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002763 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002764 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002765 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002766 pNotify->RunSubformIndexChange(pFromInstance);
2767 }
2768 }
2769 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002770 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002771 }
2772}
dsinclair5b36f0a2016-07-19 10:56:23 -07002773
dsinclair12a6b0c2016-05-26 11:14:08 -07002774void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002775 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002776 XFA_ATTRIBUTE eAttribute) {
2777 if (!bSetting) {
2778 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
weili44f8faf2016-06-01 14:03:56 -07002779 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002780 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2781 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002782 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002783 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2784 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2785 wsInstMgrName.Mid(1) == wsName) {
2786 pInstanceMgr = pNode;
2787 }
2788 break;
2789 }
2790 }
2791 if (pInstanceMgr) {
dsinclairf27aeec2016-06-07 19:36:18 -07002792 pValue->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002793 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
2794 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002795 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002796 }
2797 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002798 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002799 }
2800}
dsinclair5b36f0a2016-07-19 10:56:23 -07002801
dsinclair12a6b0c2016-05-26 11:14:08 -07002802void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002803 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002804 XFA_ATTRIBUTE eAttribute) {
2805 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002806 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002807 } else {
2808 CFX_WideString wsLocaleName;
2809 GetLocaleName(wsLocaleName);
dsinclairf27aeec2016-06-07 19:36:18 -07002810 pValue->SetString(
2811 FX_UTF8Encode(wsLocaleName.c_str(), wsLocaleName.GetLength())
2812 .AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002813 }
2814}
dsinclair5b36f0a2016-07-19 10:56:23 -07002815
Dan Sinclair1770c022016-03-14 14:14:16 -04002816void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
2817 int32_t argc = pArguments->GetLength();
2818 if (argc == 1) {
2819 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2820 execSingleEventByName(
tsepez4c3debb2016-04-08 12:20:38 -07002821 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
dsinclair56a8b192016-06-21 14:15:25 -07002822 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002823 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002824 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
Dan Sinclair1770c022016-03-14 14:14:16 -04002825 }
2826}
dsinclair5b36f0a2016-07-19 10:56:23 -07002827
Dan Sinclair1770c022016-03-14 14:14:16 -04002828void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
2829 int32_t argc = pArguments->GetLength();
2830 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002831 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002832 if (!pNotify) {
2833 return;
2834 }
2835 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
2836 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002837 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002838 }
2839}
dsinclair5b36f0a2016-07-19 10:56:23 -07002840
Dan Sinclair1770c022016-03-14 14:14:16 -04002841void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
2842 int32_t argc = pArguments->GetLength();
2843 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002844 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002845 if (!pNotify) {
2846 return;
2847 }
2848 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
2849 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002850 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002851 }
2852}
dsinclair5b36f0a2016-07-19 10:56:23 -07002853
Dan Sinclair1770c022016-03-14 14:14:16 -04002854void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
2855 int32_t argc = pArguments->GetLength();
2856 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002857 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002858 if (!pNotify) {
tsepezd19e9122016-11-02 15:43:18 -07002859 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002860 } else {
2861 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
dsinclairf27aeec2016-06-07 19:36:18 -07002862 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07002863 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002864 }
2865 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002866 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002867 }
2868}
dsinclair5b36f0a2016-07-19 10:56:23 -07002869
Dan Sinclair1770c022016-03-14 14:14:16 -04002870void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
2871 int32_t argc = pArguments->GetLength();
2872 if (argc == 0) {
2873 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002874 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002875 }
2876}
dsinclair5b36f0a2016-07-19 10:56:23 -07002877
Dan Sinclair1770c022016-03-14 14:14:16 -04002878int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2879 int32_t index = 0;
2880 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2881 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002882 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2883 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002884 index++;
2885 } else {
2886 break;
2887 }
2888 }
2889 return index;
2890}
dsinclair5b36f0a2016-07-19 10:56:23 -07002891
Dan Sinclair1770c022016-03-14 14:14:16 -04002892void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
2893 int32_t argc = pArguments->GetLength();
2894 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07002895 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002896 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002897 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04002898 }
2899}
dsinclair5b36f0a2016-07-19 10:56:23 -07002900
Dan Sinclair1770c022016-03-14 14:14:16 -04002901void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
2902 int32_t argc = pArguments->GetLength();
2903 if (argc == 0) {
tsepezd19e9122016-11-02 15:43:18 -07002904 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002905 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002906 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge");
Dan Sinclair1770c022016-03-14 14:14:16 -04002907 }
2908}
dsinclair5b36f0a2016-07-19 10:56:23 -07002909
Dan Sinclair1770c022016-03-14 14:14:16 -04002910void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
2911 int32_t argc = pArguments->GetLength();
2912 if (argc == 0) {
2913 CXFA_WidgetData* pWidgetData = GetWidgetData();
2914 if (!pWidgetData) {
tsepezd19e9122016-11-02 15:43:18 -07002915 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002916 } else {
tsepezd19e9122016-11-02 15:43:18 -07002917 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002918 }
2919 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002920 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002921 }
2922}
dsinclair5b36f0a2016-07-19 10:56:23 -07002923
Dan Sinclair1770c022016-03-14 14:14:16 -04002924void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2925 int32_t argc = pArguments->GetLength();
2926 if ((argc > 0) && (argc < 4)) {
2927 CFX_WideString strTagName;
2928 CFX_WideString strName;
2929 CFX_WideString strNameSpace;
2930 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002931 strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002932 if (argc > 1) {
2933 CFX_ByteString bsName = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002934 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002935 if (argc == 3) {
2936 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
tsepez4c3debb2016-04-08 12:20:38 -07002937 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002938 }
2939 }
dsinclair6e124782016-06-23 12:14:55 -07002940 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2941 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
Dan Sinclair1770c022016-03-14 14:14:16 -04002942 if (!pNewNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002943 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002944 } else {
2945 if (!strName.IsEmpty()) {
dsinclair9eb0db12016-07-21 12:01:39 -07002946 if (GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2947 XFA_XDPPACKET_UNKNOWN)) {
thestigb1a59592016-04-14 18:29:56 -07002948 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002949 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) {
2950 pNewNode->CreateXMLMappingNode();
2951 }
dsinclairf27aeec2016-06-07 19:36:18 -07002952 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002953 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2954 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002955 ThrowException(XFA_IDS_NOT_HAVE_PROPERTY, strTagName.c_str(),
2956 L"name");
Dan Sinclair1770c022016-03-14 14:14:16 -04002957 }
2958 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002959 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002960 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2961 }
2962 }
2963 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002964 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"createNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04002965 }
2966}
dsinclair5b36f0a2016-07-19 10:56:23 -07002967
Dan Sinclair1770c022016-03-14 14:14:16 -04002968void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
2969 if (pArguments->GetLength() == 1) {
tsepezd19e9122016-11-02 15:43:18 -07002970 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002971 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002972 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002973 }
2974}
dsinclair5b36f0a2016-07-19 10:56:23 -07002975
Dan Sinclair1770c022016-03-14 14:14:16 -04002976void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
2977 int32_t argc = pArguments->GetLength();
2978 if (argc == 0) {
2979 CXFA_WidgetData* pWidgetData = GetWidgetData();
2980 if (!pWidgetData) {
tsepezd19e9122016-11-02 15:43:18 -07002981 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002982 } else {
tsepezd19e9122016-11-02 15:43:18 -07002983 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002984 }
2985 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002986 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002987 }
2988}
dsinclair5b36f0a2016-07-19 10:56:23 -07002989
Dan Sinclair1770c022016-03-14 14:14:16 -04002990void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
2991 int32_t argc = pArguments->GetLength();
2992 if (argc == 0) {
2993 CXFA_WidgetData* pWidgetData = GetWidgetData();
2994 if (!pWidgetData) {
tsepezd19e9122016-11-02 15:43:18 -07002995 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002996 } else {
tsepezd19e9122016-11-02 15:43:18 -07002997 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002998 }
2999 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003000 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003001 }
3002}
dsinclair5b36f0a2016-07-19 10:56:23 -07003003
Dan Sinclair1770c022016-03-14 14:14:16 -04003004void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
3005 int32_t argc = pArguments->GetLength();
3006 if (argc == 0) {
3007 CXFA_WidgetData* pWidgetData = GetWidgetData();
3008 if (!pWidgetData) {
tsepezd19e9122016-11-02 15:43:18 -07003009 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003010 } else {
tsepezd19e9122016-11-02 15:43:18 -07003011 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003012 }
3013 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003014 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"evaluate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003015 }
3016}
dsinclair5b36f0a2016-07-19 10:56:23 -07003017
dsinclair12a6b0c2016-05-26 11:14:08 -07003018void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003019 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003020 XFA_ATTRIBUTE eAttribute) {
3021 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07003022 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04003023 return;
3024 }
3025 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003026 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003027}
dsinclair5b36f0a2016-07-19 10:56:23 -07003028
dsinclair12a6b0c2016-05-26 11:14:08 -07003029void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003030 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003031 XFA_ATTRIBUTE eAttribute) {
3032 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07003033 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04003034 return;
3035 }
3036 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003037 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003038}
tsepezaadedf92016-05-12 10:08:06 -07003039
dsinclair12a6b0c2016-05-26 11:14:08 -07003040void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003041 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003042 XFA_ATTRIBUTE eAttribute) {
3043 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003044 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003045 InstanceManager_SetInstances(iDesired);
3046 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07003047 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04003048 }
3049}
dsinclair5b36f0a2016-07-19 10:56:23 -07003050
Dan Sinclair1770c022016-03-14 14:14:16 -04003051void CXFA_Node::Script_InstanceManager_MoveInstance(
3052 CFXJSE_Arguments* pArguments) {
3053 int32_t argc = pArguments->GetLength();
3054 if (argc != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003055 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003056 return;
3057 }
3058 int32_t iFrom = pArguments->GetInt32(0);
3059 int32_t iTo = pArguments->GetInt32(1);
3060 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003061 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003062 if (!pNotify) {
3063 return;
3064 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003065 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003066 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003067 pNotify->RunSubformIndexChange(pToInstance);
3068 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003069 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003070 if (pFromInstance &&
3071 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003072 pNotify->RunSubformIndexChange(pFromInstance);
3073 }
3074}
dsinclair5b36f0a2016-07-19 10:56:23 -07003075
Dan Sinclair1770c022016-03-14 14:14:16 -04003076void CXFA_Node::Script_InstanceManager_RemoveInstance(
3077 CFXJSE_Arguments* pArguments) {
3078 int32_t argc = pArguments->GetLength();
3079 if (argc != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003080 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003081 return;
3082 }
3083 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003084 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003085 if (iIndex < 0 || iIndex >= iCount) {
dsinclair2235b7b2016-06-02 07:42:25 -07003086 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
Dan Sinclair1770c022016-03-14 14:14:16 -04003087 return;
3088 }
3089 CXFA_Occur nodeOccur(GetOccurNode());
3090 int32_t iMin = nodeOccur.GetMin();
3091 if (iCount - 1 < iMin) {
dsinclair2235b7b2016-06-02 07:42:25 -07003092 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003093 return;
3094 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003095 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3096 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003097 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003098 if (pNotify) {
3099 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003100 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003101 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003102 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003103 pNotify->RunSubformIndexChange(pSubformInstance);
3104 }
3105 }
3106 }
3107 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3108 if (!pLayoutPro) {
3109 return;
3110 }
3111 pLayoutPro->AddChangedContainer(
3112 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3113}
dsinclair5b36f0a2016-07-19 10:56:23 -07003114
Dan Sinclair1770c022016-03-14 14:14:16 -04003115void CXFA_Node::Script_InstanceManager_SetInstances(
3116 CFXJSE_Arguments* pArguments) {
3117 int32_t argc = pArguments->GetLength();
3118 if (argc != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003119 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003120 return;
3121 }
3122 int32_t iDesired = pArguments->GetInt32(0);
3123 InstanceManager_SetInstances(iDesired);
3124}
dsinclair5b36f0a2016-07-19 10:56:23 -07003125
Dan Sinclair1770c022016-03-14 14:14:16 -04003126void CXFA_Node::Script_InstanceManager_AddInstance(
3127 CFXJSE_Arguments* pArguments) {
3128 int32_t argc = pArguments->GetLength();
3129 if ((argc != 0) && (argc != 1)) {
dsinclair2235b7b2016-06-02 07:42:25 -07003130 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003131 return;
3132 }
tsepezd19e9122016-11-02 15:43:18 -07003133 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003134 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003135 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003136 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003137 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003138 CXFA_Occur nodeOccur(GetOccurNode());
3139 int32_t iMax = nodeOccur.GetMax();
3140 if (iMax >= 0 && iCount >= iMax) {
dsinclair2235b7b2016-06-02 07:42:25 -07003141 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003142 return;
3143 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003144 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003145 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003146 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003147 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003148 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003149 if (!pNotify) {
3150 return;
3151 }
3152 pNotify->RunNodeInitialize(pNewInstance);
3153 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3154 if (!pLayoutPro) {
3155 return;
3156 }
3157 pLayoutPro->AddChangedContainer(
3158 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3159}
dsinclair5b36f0a2016-07-19 10:56:23 -07003160
Dan Sinclair1770c022016-03-14 14:14:16 -04003161void CXFA_Node::Script_InstanceManager_InsertInstance(
3162 CFXJSE_Arguments* pArguments) {
3163 int32_t argc = pArguments->GetLength();
3164 if ((argc != 1) && (argc != 2)) {
dsinclair2235b7b2016-06-02 07:42:25 -07003165 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003166 return;
3167 }
3168 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003169 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003170 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003171 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003172 }
3173 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003174 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003175 if (iIndex < 0 || iIndex > iCount) {
dsinclair2235b7b2016-06-02 07:42:25 -07003176 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
Dan Sinclair1770c022016-03-14 14:14:16 -04003177 return;
3178 }
3179 int32_t iMax = nodeOccur.GetMax();
3180 if (iMax >= 0 && iCount >= iMax) {
dsinclair2235b7b2016-06-02 07:42:25 -07003181 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003182 return;
3183 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003184 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003185 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003186 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003187 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003188 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003189 if (!pNotify) {
3190 return;
3191 }
3192 pNotify->RunNodeInitialize(pNewInstance);
3193 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3194 if (!pLayoutPro) {
3195 return;
3196 }
3197 pLayoutPro->AddChangedContainer(
3198 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3199}
dsinclair5b36f0a2016-07-19 10:56:23 -07003200
Dan Sinclair1770c022016-03-14 14:14:16 -04003201int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3202 CXFA_Occur nodeOccur(GetOccurNode());
3203 int32_t iMax = nodeOccur.GetMax();
3204 int32_t iMin = nodeOccur.GetMin();
3205 if (iDesired < iMin) {
dsinclair2235b7b2016-06-02 07:42:25 -07003206 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003207 return 1;
3208 }
3209 if ((iMax >= 0) && (iDesired > iMax)) {
dsinclair2235b7b2016-06-02 07:42:25 -07003210 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003211 return 2;
3212 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003213 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003214 if (iDesired == iCount) {
3215 return 0;
3216 }
3217 if (iDesired < iCount) {
3218 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003219 CFX_WideString wsInstanceName =
3220 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3221 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003222 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003223 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003224 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003225 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003226 while (iCount > iDesired) {
3227 CXFA_Node* pRemoveInstance =
3228 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003229 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3230 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003231 continue;
3232 }
dsinclair070fcdf2016-06-22 22:04:54 -07003233 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003234 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003235 break;
3236 }
3237 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003238 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003239 iCount--;
3240 }
3241 }
3242 } else if (iDesired > iCount) {
3243 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003244 CXFA_Node* pNewInstance = CreateInstance(this, true);
3245 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003246 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003247 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003248 if (!pNotify) {
3249 return 0;
3250 }
3251 pNotify->RunNodeInitialize(pNewInstance);
3252 }
3253 }
3254 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3255 if (pLayoutPro) {
3256 pLayoutPro->AddChangedContainer(
3257 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3258 }
3259 return 0;
3260}
dsinclair5b36f0a2016-07-19 10:56:23 -07003261
Dan Sinclair1770c022016-03-14 14:14:16 -04003262int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003263 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003264 if (iFrom > iCount || iTo > iCount - 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07003265 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
Dan Sinclair1770c022016-03-14 14:14:16 -04003266 return 1;
3267 }
3268 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3269 return 0;
3270 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003271 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003272 RemoveItem(this, pMoveInstance, false);
3273 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003274 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3275 if (pLayoutPro) {
3276 pLayoutPro->AddChangedContainer(
3277 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3278 }
3279 return 0;
3280}
dsinclair5b36f0a2016-07-19 10:56:23 -07003281
dsinclair12a6b0c2016-05-26 11:14:08 -07003282void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003283 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003284 XFA_ATTRIBUTE eAttribute) {
3285 CXFA_Occur occur(this);
3286 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003287 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003288 occur.SetMax(iMax);
3289 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003290 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003291 }
3292}
dsinclair5b36f0a2016-07-19 10:56:23 -07003293
dsinclair12a6b0c2016-05-26 11:14:08 -07003294void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003295 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003296 XFA_ATTRIBUTE eAttribute) {
3297 CXFA_Occur occur(this);
3298 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003299 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003300 occur.SetMin(iMin);
3301 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003302 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003303 }
3304}
dsinclair5b36f0a2016-07-19 10:56:23 -07003305
Dan Sinclair1770c022016-03-14 14:14:16 -04003306void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3307 int32_t argc = pArguments->GetLength();
3308 if ((argc == 0) || (argc == 1)) {
dsinclairf27aeec2016-06-07 19:36:18 -07003309 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003310 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003311 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"metadata");
Dan Sinclair1770c022016-03-14 14:14:16 -04003312 }
3313}
dsinclair5b36f0a2016-07-19 10:56:23 -07003314
Dan Sinclair1770c022016-03-14 14:14:16 -04003315void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
3316 int32_t argc = pArguments->GetLength();
3317 if (argc == 1) {
3318 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3319 if (pDataNode) {
3320 CXFA_NodeArray formItems;
3321 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3322 pFormNodes->SetArrayNodeList(formItems);
dsinclairf27aeec2016-06-07 19:36:18 -07003323 pArguments->GetReturnValue()->SetObject(
3324 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003325 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003326 ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
Dan Sinclair1770c022016-03-14 14:14:16 -04003327 }
3328 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003329 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04003330 }
3331}
dsinclair5b36f0a2016-07-19 10:56:23 -07003332
Dan Sinclair1770c022016-03-14 14:14:16 -04003333void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
3334 int32_t argc = pArguments->GetLength();
3335 if (argc == 0) {
tsepezd19e9122016-11-02 15:43:18 -07003336 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003337 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003338 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge");
Dan Sinclair1770c022016-03-14 14:14:16 -04003339 }
3340}
dsinclair5b36f0a2016-07-19 10:56:23 -07003341
Dan Sinclair1770c022016-03-14 14:14:16 -04003342void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
3343 int32_t argc = pArguments->GetLength();
3344 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07003345 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003346 if (!pNotify) {
3347 return;
3348 }
3349 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
3350 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003351 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04003352 }
3353}
dsinclair5b36f0a2016-07-19 10:56:23 -07003354
Dan Sinclair1770c022016-03-14 14:14:16 -04003355void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3356 CXFA_EventParam* pEventParam =
3357 m_pDocument->GetScriptContext()->GetEventParam();
3358 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3359 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3360 return;
3361 }
3362 int32_t argc = pArguments->GetLength();
3363 if (argc == 1) {
3364 const bool bScriptFlags = pArguments->GetInt32(0) != 0;
dsinclaira1b07722016-07-11 08:20:58 -07003365 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003366 if (!pNotify) {
3367 return;
3368 }
3369 if (bScriptFlags) {
3370 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3371 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
tsepezd19e9122016-11-02 15:43:18 -07003372 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003373 } else {
3374 }
3375 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003376 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003377 }
3378}
dsinclair5b36f0a2016-07-19 10:56:23 -07003379
Dan Sinclair1770c022016-03-14 14:14:16 -04003380void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
3381 int32_t argc = pArguments->GetLength();
3382 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07003383 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003384 if (!pNotify) {
3385 return;
3386 }
3387 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3388 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003389 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003390 }
3391}
dsinclair5b36f0a2016-07-19 10:56:23 -07003392
Dan Sinclair1770c022016-03-14 14:14:16 -04003393void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
3394 int32_t argc = pArguments->GetLength();
3395 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07003396 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003397 if (!pNotify) {
tsepezd19e9122016-11-02 15:43:18 -07003398 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003399 } else {
3400 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
dsinclairf27aeec2016-06-07 19:36:18 -07003401 pArguments->GetReturnValue()->SetBoolean(
tsepezd19e9122016-11-02 15:43:18 -07003402 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003403 }
3404 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003405 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003406 }
3407}
dsinclair5b36f0a2016-07-19 10:56:23 -07003408
dsinclair12a6b0c2016-05-26 11:14:08 -07003409void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003410 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003411 XFA_ATTRIBUTE eAttribute) {
3412 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003413 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003414 } else {
3415 CFX_WideString wsChecksum;
tsepezd19e9122016-11-02 15:43:18 -07003416 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003417 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003418 FX_UTF8Encode(wsChecksum.c_str(), wsChecksum.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003419 }
3420}
dsinclair5b36f0a2016-07-19 10:56:23 -07003421
Dan Sinclair1770c022016-03-14 14:14:16 -04003422void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
3423 int32_t argc = pArguments->GetLength();
3424 if (argc == 1) {
3425 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3426 CFX_WideString wsAttributeValue;
dsinclairae95f762016-03-29 16:58:29 -07003427 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003428 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
tsepezbd9748d2016-04-13 21:40:19 -07003429 static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3430 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(),
3431 wsAttributeValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003432 }
dsinclairf27aeec2016-06-07 19:36:18 -07003433 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003434 FX_UTF8Encode(wsAttributeValue.c_str(), wsAttributeValue.GetLength())
tsepez4c3debb2016-04-08 12:20:38 -07003435 .AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003436 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003437 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04003438 }
3439}
dsinclair5b36f0a2016-07-19 10:56:23 -07003440
Dan Sinclair1770c022016-03-14 14:14:16 -04003441void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
3442 int32_t argc = pArguments->GetLength();
3443 if (argc == 2) {
3444 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3445 CFX_ByteString bsName = pArguments->GetUTF8String(1);
dsinclairae95f762016-03-29 16:58:29 -07003446 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003447 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003448 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(
3449 CFX_WideString::FromUTF8(bsName.AsStringC()),
3450 CFX_WideString::FromUTF8(bsValue.AsStringC()));
Dan Sinclair1770c022016-03-14 14:14:16 -04003451 }
dsinclairf27aeec2016-06-07 19:36:18 -07003452 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003453 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003454 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04003455 }
3456}
dsinclair5b36f0a2016-07-19 10:56:23 -07003457
Dan Sinclair1770c022016-03-14 14:14:16 -04003458void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
3459 int32_t argc = pArguments->GetLength();
3460 if (argc == 1) {
3461 CFX_ByteString bsName = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07003462 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
dsinclairae95f762016-03-29 16:58:29 -07003463 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003464 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003465 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
tsepezbd9748d2016-04-13 21:40:19 -07003466 if (pXMLElement->HasAttribute(wsName.c_str())) {
3467 pXMLElement->RemoveAttribute(wsName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04003468 }
3469 }
dsinclairf27aeec2016-06-07 19:36:18 -07003470 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003471 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003472 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"removeAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04003473 }
3474}
dsinclair5b36f0a2016-07-19 10:56:23 -07003475
dsinclair12a6b0c2016-05-26 11:14:08 -07003476void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003477 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003478 XFA_ATTRIBUTE eAttribute) {
3479 if (bSetting) {
dsinclairae95f762016-03-29 16:58:29 -07003480 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003481 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003482 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003483 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003484 }
3485 } else {
3486 CFX_WideString wsTextData;
dsinclairae95f762016-03-29 16:58:29 -07003487 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003488 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003489 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04003490 pXMLElement->GetTextData(wsTextData);
3491 }
dsinclairf27aeec2016-06-07 19:36:18 -07003492 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003493 FX_UTF8Encode(wsTextData.c_str(), wsTextData.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003494 }
3495}
dsinclair5b36f0a2016-07-19 10:56:23 -07003496
Dan Sinclair1770c022016-03-14 14:14:16 -04003497void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
3498 int32_t argc = pArguments->GetLength();
3499 if (argc == 0) {
3500 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003501 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003502 }
3503}
dsinclair5b36f0a2016-07-19 10:56:23 -07003504
Dan Sinclair1770c022016-03-14 14:14:16 -04003505void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
3506 int32_t argc = pArguments->GetLength();
3507 if (argc == 0) {
3508 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003509 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003510 }
3511}
dsinclair5b36f0a2016-07-19 10:56:23 -07003512
Dan Sinclair1770c022016-03-14 14:14:16 -04003513void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
3514 int32_t argc = pArguments->GetLength();
3515 if (argc == 0) {
3516 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003517 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003518 }
3519}
dsinclair5b36f0a2016-07-19 10:56:23 -07003520
Dan Sinclair1770c022016-03-14 14:14:16 -04003521void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
3522 int32_t argc = pArguments->GetLength();
3523 if (argc == 0) {
3524 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003525 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003526 }
3527}
dsinclair5b36f0a2016-07-19 10:56:23 -07003528
Dan Sinclair1770c022016-03-14 14:14:16 -04003529void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
3530 int32_t argc = pArguments->GetLength();
3531 if (argc == 0) {
3532 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003533 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003534 }
3535}
dsinclair5b36f0a2016-07-19 10:56:23 -07003536
Dan Sinclair1770c022016-03-14 14:14:16 -04003537void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
3538 int32_t argc = pArguments->GetLength();
3539 if (argc == 0) {
3540 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003541 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003542 }
3543}
dsinclair5b36f0a2016-07-19 10:56:23 -07003544
Dan Sinclair1770c022016-03-14 14:14:16 -04003545void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
3546 int32_t argc = pArguments->GetLength();
3547 if (argc == 0) {
3548 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003549 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003550 }
3551}
dsinclair5b36f0a2016-07-19 10:56:23 -07003552
Dan Sinclair1770c022016-03-14 14:14:16 -04003553void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
3554 int32_t argc = pArguments->GetLength();
3555 if (argc == 0) {
3556 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003557 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003558 }
3559}
dsinclair5b36f0a2016-07-19 10:56:23 -07003560
Dan Sinclair1770c022016-03-14 14:14:16 -04003561void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
3562 int32_t argc = pArguments->GetLength();
3563 if (argc == 0) {
3564 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003565 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003566 }
3567}
dsinclair5b36f0a2016-07-19 10:56:23 -07003568
Dan Sinclair1770c022016-03-14 14:14:16 -04003569void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
3570 int32_t argc = pArguments->GetLength();
3571 if (argc == 0) {
3572 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003573 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003574 }
3575}
dsinclair5b36f0a2016-07-19 10:56:23 -07003576
Dan Sinclair1770c022016-03-14 14:14:16 -04003577void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
3578 int32_t argc = pArguments->GetLength();
3579 if (argc == 0) {
3580 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003581 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003582 }
3583}
dsinclair5b36f0a2016-07-19 10:56:23 -07003584
Dan Sinclair1770c022016-03-14 14:14:16 -04003585void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
3586 int32_t argc = pArguments->GetLength();
3587 if (argc == 0) {
3588 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003589 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003590 }
3591}
dsinclair5b36f0a2016-07-19 10:56:23 -07003592
Dan Sinclair1770c022016-03-14 14:14:16 -04003593void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
3594 int32_t argc = pArguments->GetLength();
3595 if (argc == 0) {
3596 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003597 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003598 }
3599}
dsinclair5b36f0a2016-07-19 10:56:23 -07003600
Dan Sinclair1770c022016-03-14 14:14:16 -04003601void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
3602 int32_t argc = pArguments->GetLength();
3603 if (argc == 0) {
3604 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003605 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003606 }
3607}
dsinclair5b36f0a2016-07-19 10:56:23 -07003608
Dan Sinclair1770c022016-03-14 14:14:16 -04003609void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
3610 int32_t argc = pArguments->GetLength();
3611 if (argc == 0) {
3612 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003613 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003614 }
3615}
dsinclair5b36f0a2016-07-19 10:56:23 -07003616
Dan Sinclair1770c022016-03-14 14:14:16 -04003617void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
3618 int32_t argc = pArguments->GetLength();
3619 if (argc == 0) {
3620 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003621 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003622 }
3623}
dsinclair5b36f0a2016-07-19 10:56:23 -07003624
Dan Sinclair1770c022016-03-14 14:14:16 -04003625void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
3626 int32_t argc = pArguments->GetLength();
3627 if (argc == 0) {
3628 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003629 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003630 }
3631}
dsinclair5b36f0a2016-07-19 10:56:23 -07003632
dsinclair12a6b0c2016-05-26 11:14:08 -07003633void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003634 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003635 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003636
dsinclair12a6b0c2016-05-26 11:14:08 -07003637void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003638 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003639 XFA_ATTRIBUTE eAttribute) {
3640 if (!bSetting) {
3641 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003642 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003643 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003644 }
3645}
dsinclair5b36f0a2016-07-19 10:56:23 -07003646
dsinclair12a6b0c2016-05-26 11:14:08 -07003647void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003648 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003649 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003650
dsinclair12a6b0c2016-05-26 11:14:08 -07003651void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003652 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003653 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003654
dsinclair12a6b0c2016-05-26 11:14:08 -07003655void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003656 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003657 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003658
dsinclair12a6b0c2016-05-26 11:14:08 -07003659void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003660 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003661 XFA_ATTRIBUTE eAttribute) {
3662 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07003663 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04003664 return;
3665 }
dsinclairf27aeec2016-06-07 19:36:18 -07003666 pValue->SetString(FX_UTF8Encode(FX_WSTRC(L"0")).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003667}
dsinclair5b36f0a2016-07-19 10:56:23 -07003668
dsinclair12a6b0c2016-05-26 11:14:08 -07003669void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003670 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003671 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003672
tsepezd19e9122016-11-02 15:43:18 -07003673bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003674 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003675 return HasMapModuleKey(pKey, bCanInherit);
3676}
dsinclair5b36f0a2016-07-19 10:56:23 -07003677
tsepezd19e9122016-11-02 15:43:18 -07003678bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3679 const CFX_WideStringC& wsValue,
3680 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003681 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003682 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003683 return false;
weili44f8faf2016-06-01 14:03:56 -07003684
Dan Sinclair1770c022016-03-14 14:14:16 -04003685 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3686 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3687 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003688 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003689 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3690 }
3691 switch (eType) {
3692 case XFA_ATTRIBUTETYPE_Enum: {
3693 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3694 return SetEnum(pAttr->eName,
3695 pEnum ? pEnum->eName
3696 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3697 bNotify);
3698 } break;
3699 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003700 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003701 case XFA_ATTRIBUTETYPE_Boolean:
3702 return SetBoolean(pAttr->eName, wsValue != FX_WSTRC(L"0"), bNotify);
3703 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003704 return SetInteger(pAttr->eName,
3705 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3706 wsValue.GetLength(), nullptr)),
3707 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003708 case XFA_ATTRIBUTETYPE_Measure:
3709 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3710 default:
3711 break;
3712 }
tsepezd19e9122016-11-02 15:43:18 -07003713 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003714}
dsinclair5b36f0a2016-07-19 10:56:23 -07003715
tsepezd19e9122016-11-02 15:43:18 -07003716bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3717 CFX_WideString& wsValue,
3718 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003719 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003720 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003721 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003722 }
3723 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3724 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3725 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003726 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003727 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3728 }
3729 switch (eType) {
3730 case XFA_ATTRIBUTETYPE_Enum: {
3731 XFA_ATTRIBUTEENUM eValue;
3732 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003733 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003734 }
dsinclair9eb0db12016-07-21 12:01:39 -07003735 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003736 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003737 } break;
3738 case XFA_ATTRIBUTETYPE_Cdata: {
3739 CFX_WideStringC wsValueC;
3740 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003741 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003742 }
3743 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003744 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003745 } break;
3746 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003747 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003748 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003749 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003750 }
3751 wsValue = bValue ? FX_WSTRC(L"1") : FX_WSTRC(L"0");
tsepezd19e9122016-11-02 15:43:18 -07003752 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003753 } break;
3754 case XFA_ATTRIBUTETYPE_Integer: {
3755 int32_t iValue;
3756 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003757 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003758 }
3759 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003760 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003761 } break;
3762 case XFA_ATTRIBUTETYPE_Measure: {
3763 CXFA_Measurement mValue;
3764 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003765 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003766 }
3767 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003768 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003769 } break;
3770 default:
3771 break;
3772 }
tsepezd19e9122016-11-02 15:43:18 -07003773 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003774}
dsinclair5b36f0a2016-07-19 10:56:23 -07003775
tsepezd19e9122016-11-02 15:43:18 -07003776bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3777 const CFX_WideStringC& wsValue,
3778 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003779 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3780 if (pAttributeInfo) {
3781 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3782 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003783 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003784 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003785 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003786}
dsinclair5b36f0a2016-07-19 10:56:23 -07003787
tsepezd19e9122016-11-02 15:43:18 -07003788bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3789 CFX_WideString& wsValue,
3790 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003791 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3792 if (pAttributeInfo) {
3793 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3794 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003795 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003796 CFX_WideStringC wsValueC;
3797 if (GetMapModuleString(pKey, wsValueC)) {
3798 wsValue = wsValueC;
3799 }
tsepezd19e9122016-11-02 15:43:18 -07003800 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003801}
dsinclair5b36f0a2016-07-19 10:56:23 -07003802
tsepezd19e9122016-11-02 15:43:18 -07003803bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003804 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003805 RemoveMapModuleKey(pKey);
tsepezd19e9122016-11-02 15:43:18 -07003806 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003807}
dsinclair5b36f0a2016-07-19 10:56:23 -07003808
tsepezd19e9122016-11-02 15:43:18 -07003809bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3810 bool& bValue,
3811 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003812 void* pValue = nullptr;
3813 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003814 return false;
tsepez478ed622016-10-27 14:32:33 -07003815 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003816 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003817}
dsinclair5b36f0a2016-07-19 10:56:23 -07003818
tsepezd19e9122016-11-02 15:43:18 -07003819bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3820 int32_t& iValue,
3821 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003822 void* pValue = nullptr;
3823 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003824 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003825 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003826 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003827}
dsinclair5b36f0a2016-07-19 10:56:23 -07003828
tsepezd19e9122016-11-02 15:43:18 -07003829bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3830 XFA_ATTRIBUTEENUM& eValue,
3831 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003832 void* pValue = nullptr;
3833 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003834 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003835 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003836 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003837}
thestigb1a59592016-04-14 18:29:56 -07003838
tsepezd19e9122016-11-02 15:43:18 -07003839bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3840 CXFA_Measurement mValue,
3841 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003842 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003843 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003844 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003845 OnChanged(eAttr, bNotify, false);
3846 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003847}
thestigb1a59592016-04-14 18:29:56 -07003848
tsepezd19e9122016-11-02 15:43:18 -07003849bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3850 CXFA_Measurement& mValue,
3851 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003852 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003853 void* pValue;
3854 int32_t iBytes;
3855 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
3856 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003857 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003858 }
3859 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003860 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003861 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
3862 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003863 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003864 }
tsepezd19e9122016-11-02 15:43:18 -07003865 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003866}
3867
3868CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3869 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003870 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003871}
3872
tsepezd19e9122016-11-02 15:43:18 -07003873bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3874 const CFX_WideString& wsValue,
3875 bool bNotify,
3876 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003877 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003878 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003879 if (eAttr == XFA_ATTRIBUTE_Value) {
3880 CFX_WideString* pClone = new CFX_WideString(wsValue);
3881 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3882 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003883 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003884 if (eAttr == XFA_ATTRIBUTE_Name)
3885 UpdateNameHash();
3886 }
thestigb1a59592016-04-14 18:29:56 -07003887 OnChanged(eAttr, bNotify, bScriptModify);
3888
3889 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3890 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003891 return true;
thestigb1a59592016-04-14 18:29:56 -07003892 }
3893
dsinclair070fcdf2016-06-22 22:04:54 -07003894 if (eAttr == XFA_ATTRIBUTE_Name &&
3895 (m_elementType == XFA_Element::DataValue ||
3896 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003897 return true;
thestigb1a59592016-04-14 18:29:56 -07003898 }
3899
3900 if (eAttr == XFA_ATTRIBUTE_Value) {
3901 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3902 switch (eXMLType) {
3903 case FDE_XMLNODE_Element:
3904 if (IsAttributeInXML()) {
3905 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003906 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3907 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003908 } else {
tsepezd19e9122016-11-02 15:43:18 -07003909 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003910 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3911 for (CXFA_Node* pChildDataNode =
3912 GetNodeItem(XFA_NODEITEM_FirstChild);
3913 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3914 XFA_NODEITEM_NextSibling)) {
3915 CXFA_NodeArray formNodes;
3916 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003917 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003918 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003919 }
3920 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003921 }
thestigb1a59592016-04-14 18:29:56 -07003922 if (bDeleteChildren) {
3923 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3924 }
3925 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3926 }
3927 break;
3928 case FDE_XMLNODE_Text:
3929 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3930 break;
3931 default:
dsinclair43854a52016-04-27 12:26:00 -07003932 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003933 }
tsepezd19e9122016-11-02 15:43:18 -07003934 return true;
thestigb1a59592016-04-14 18:29:56 -07003935 }
3936
3937 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3938 if (pInfo) {
dsinclair43854a52016-04-27 12:26:00 -07003939 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003940 CFX_WideString wsAttrName = pInfo->pName;
3941 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
3942 wsAttrName = FX_WSTRC(L"xfa:") + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003943 }
thestigb1a59592016-04-14 18:29:56 -07003944 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003945 }
tsepezd19e9122016-11-02 15:43:18 -07003946 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003947}
thestigb1a59592016-04-14 18:29:56 -07003948
tsepezd19e9122016-11-02 15:43:18 -07003949bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3950 const CFX_WideString& wsXMLValue,
3951 bool bNotify,
3952 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003953 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003954 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003955 CFX_WideString* pClone = new CFX_WideString(wsValue);
3956 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003957 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003958 if (IsNeedSavingXMLNode()) {
3959 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3960 switch (eXMLType) {
3961 case FDE_XMLNODE_Element:
3962 if (IsAttributeInXML()) {
dsinclairae95f762016-03-29 16:58:29 -07003963 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003964 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3965 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003966 } else {
tsepezd19e9122016-11-02 15:43:18 -07003967 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003968 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3969 for (CXFA_Node* pChildDataNode =
3970 GetNodeItem(XFA_NODEITEM_FirstChild);
3971 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3972 XFA_NODEITEM_NextSibling)) {
3973 CXFA_NodeArray formNodes;
3974 if (pChildDataNode->GetBindItems(formNodes) > 0) {
tsepezd19e9122016-11-02 15:43:18 -07003975 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003976 break;
3977 }
3978 }
3979 }
3980 if (bDeleteChildren) {
dsinclairae95f762016-03-29 16:58:29 -07003981 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003982 }
dsinclairae95f762016-03-29 16:58:29 -07003983 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003984 }
3985 break;
3986 case FDE_XMLNODE_Text:
dsinclairae95f762016-03-29 16:58:29 -07003987 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003988 break;
3989 default:
dsinclair43854a52016-04-27 12:26:00 -07003990 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003991 }
3992 }
tsepezd19e9122016-11-02 15:43:18 -07003993 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003994}
dsinclair5b36f0a2016-07-19 10:56:23 -07003995
tsepezd19e9122016-11-02 15:43:18 -07003996bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3997 CFX_WideString& wsValue,
3998 bool bUseDefault,
3999 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004000 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004001 if (eAttr == XFA_ATTRIBUTE_Value) {
4002 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
4003 if (pStr) {
4004 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07004005 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004006 }
4007 } else {
4008 CFX_WideStringC wsValueC;
4009 if (GetMapModuleString(pKey, wsValueC)) {
4010 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07004011 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004012 }
4013 }
4014 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004015 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004016 }
weili44f8faf2016-06-01 14:03:56 -07004017 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07004018 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04004019 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
4020 wsValue = (const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07004021 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004022 }
tsepezd19e9122016-11-02 15:43:18 -07004023 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004024}
dsinclair5b36f0a2016-07-19 10:56:23 -07004025
tsepezd19e9122016-11-02 15:43:18 -07004026bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
4027 CFX_WideStringC& wsValue,
4028 bool bUseDefault,
4029 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004030 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004031 if (eAttr == XFA_ATTRIBUTE_Value) {
4032 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
4033 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07004034 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07004035 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004036 }
4037 } else {
4038 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004039 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004040 }
4041 }
4042 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004043 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004044 }
weili44f8faf2016-06-01 14:03:56 -07004045 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07004046 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04004047 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
4048 wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07004049 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004050 }
tsepezd19e9122016-11-02 15:43:18 -07004051 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004052}
dsinclair5b36f0a2016-07-19 10:56:23 -07004053
tsepezd19e9122016-11-02 15:43:18 -07004054bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
4055 void* pData,
4056 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004057 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004058 return SetUserData(pKey, pData, pCallbackInfo);
4059}
dsinclair5b36f0a2016-07-19 10:56:23 -07004060
tsepezd19e9122016-11-02 15:43:18 -07004061bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004062 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004063 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07004064 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04004065}
dsinclair5b36f0a2016-07-19 10:56:23 -07004066
tsepezd19e9122016-11-02 15:43:18 -07004067bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
4068 XFA_ATTRIBUTETYPE eType,
4069 void* pValue,
4070 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004071 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07004072 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004073 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07004074 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004075 if (IsNeedSavingXMLNode()) {
dsinclair43854a52016-04-27 12:26:00 -07004076 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004077 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
4078 if (pInfo) {
4079 switch (eType) {
4080 case XFA_ATTRIBUTETYPE_Enum:
dsinclairae95f762016-03-29 16:58:29 -07004081 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004082 ->SetString(
4083 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07004084 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04004085 ->pName);
4086 break;
4087 case XFA_ATTRIBUTETYPE_Boolean:
dsinclairae95f762016-03-29 16:58:29 -07004088 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07004089 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04004090 break;
4091 case XFA_ATTRIBUTETYPE_Integer:
dsinclairae95f762016-03-29 16:58:29 -07004092 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004093 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue);
4094 break;
4095 default:
dsinclair43854a52016-04-27 12:26:00 -07004096 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04004097 }
4098 }
4099 }
tsepezd19e9122016-11-02 15:43:18 -07004100 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004101}
dsinclair5b36f0a2016-07-19 10:56:23 -07004102
tsepezd19e9122016-11-02 15:43:18 -07004103bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
4104 XFA_ATTRIBUTETYPE eType,
4105 bool bUseDefault,
4106 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004107 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004108 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004109 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004110 }
4111 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004112 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004113 }
dsinclair070fcdf2016-06-22 22:04:54 -07004114 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004115 m_ePacket);
4116}
dsinclair5b36f0a2016-07-19 10:56:23 -07004117
tsepezd19e9122016-11-02 15:43:18 -07004118bool CXFA_Node::SetUserData(void* pKey,
4119 void* pData,
4120 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004121 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4122 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004123 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004124}
dsinclair5b36f0a2016-07-19 10:56:23 -07004125
tsepezd19e9122016-11-02 15:43:18 -07004126bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004127 int32_t iBytes = 0;
4128 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004129 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004130 }
4131 return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes);
4132}
dsinclair5b36f0a2016-07-19 10:56:23 -07004133
tsepezd19e9122016-11-02 15:43:18 -07004134bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4135 const CFX_WideString& wsXMLValue,
4136 bool bNotify,
4137 bool bScriptModify,
4138 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004139 CXFA_Node* pNode = nullptr;
4140 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004141 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004142 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004143 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004144 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004145 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004146 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004147 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004148 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004149 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004150 CXFA_Node* pBind = GetBindData();
4151 if (bSyncData && pBind) {
4152 CFX_WideStringArray wsSaveTextArray;
4153 int32_t iSize = 0;
4154 if (!wsContent.IsEmpty()) {
4155 int32_t iStart = 0;
4156 int32_t iLength = wsContent.GetLength();
4157 int32_t iEnd = wsContent.Find(L'\n', iStart);
4158 iEnd = (iEnd == -1) ? iLength : iEnd;
4159 while (iEnd >= iStart) {
4160 wsSaveTextArray.Add(wsContent.Mid(iStart, iEnd - iStart));
4161 iStart = iEnd + 1;
4162 if (iStart >= iLength) {
4163 break;
4164 }
4165 iEnd = wsContent.Find(L'\n', iStart);
4166 if (iEnd < 0) {
4167 wsSaveTextArray.Add(wsContent.Mid(iStart, iLength - iStart));
4168 }
4169 }
4170 iSize = wsSaveTextArray.GetSize();
4171 }
4172 if (iSize == 0) {
4173 while (CXFA_Node* pChildNode =
4174 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4175 pBind->RemoveChild(pChildNode);
4176 }
4177 } else {
4178 CXFA_NodeArray valueNodes;
4179 int32_t iDatas = pBind->GetNodeList(
dsinclair56a8b192016-06-21 14:15:25 -07004180 valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004181 if (iDatas < iSize) {
4182 int32_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004183 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004184 while (iAddNodes-- > 0) {
4185 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004186 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004187 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004188 pValueNodes->CreateXMLMappingNode();
4189 pBind->InsertChild(pValueNodes);
4190 }
weili44f8faf2016-06-01 14:03:56 -07004191 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004192 } else if (iDatas > iSize) {
4193 int32_t iDelNodes = iDatas - iSize;
4194 while (iDelNodes-- > 0) {
4195 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4196 }
4197 }
4198 int32_t i = 0;
4199 for (CXFA_Node* pValueNode =
4200 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4201 pValueNode; pValueNode = pValueNode->GetNodeItem(
4202 XFA_NODEITEM_NextSibling)) {
4203 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004204 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004205 i++;
4206 }
4207 }
4208 CXFA_NodeArray nodeArray;
4209 pBind->GetBindItems(nodeArray);
4210 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004211 if (nodeArray[i] != this) {
4212 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004213 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004214 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004215 }
4216 }
4217 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004218 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004219 pNode = this;
4220 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004221 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004222 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004223 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004224 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004225 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004226 }
4227 pBindNode = GetBindData();
4228 if (pBindNode && bSyncData) {
4229 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004230 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004231 CXFA_NodeArray nodeArray;
4232 pBindNode->GetBindItems(nodeArray);
4233 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004234 if (nodeArray[i] != this) {
4235 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true,
tsepezd19e9122016-11-02 15:43:18 -07004236 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004237 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004238 }
4239 }
weili44f8faf2016-06-01 14:03:56 -07004240 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004241 break;
4242 }
dsinclairc5a8f212016-06-20 11:11:12 -07004243 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004244 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004245 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004246 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
tsepez9f2970c2016-04-01 10:23:04 -07004247 if (wsContentType == FX_WSTRC(L"text/html")) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004248 wsContentType = FX_WSTRC(L"");
tsepez4c3debb2016-04-08 12:20:38 -07004249 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004250 }
4251 }
4252 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4253 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004254 pContentRawDataNode = CreateSamePacketNode(
dsinclair56a8b192016-06-21 14:15:25 -07004255 (wsContentType == FX_WSTRC(L"text/xml")) ? XFA_Element::Sharpxml
4256 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004257 InsertChild(pContentRawDataNode);
4258 }
4259 return pContentRawDataNode->SetScriptContent(
4260 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4261 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004262 case XFA_ObjectType::NodeC:
4263 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004264 pNode = this;
4265 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004266 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004267 pNode = this;
4268 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4269 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4270 if (pParent) {
4271 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4272 }
dsinclair070fcdf2016-06-22 22:04:54 -07004273 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004274 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4275 if (pParent && pParent->IsContainerNode()) {
4276 pBindNode = pParent->GetBindData();
4277 if (pBindNode) {
4278 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004279 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004280 }
4281 }
4282 }
4283 }
4284 break;
4285 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004286 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004287 pNode = this;
4288 pBindNode = this;
4289 }
4290 break;
4291 }
4292 if (pNode) {
4293 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4294 if (pBindNode && bSyncData) {
4295 CXFA_NodeArray nodeArray;
4296 pBindNode->GetBindItems(nodeArray);
4297 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004298 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004299 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004300 }
4301 }
tsepezd19e9122016-11-02 15:43:18 -07004302 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004303 }
tsepezd19e9122016-11-02 15:43:18 -07004304 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004305}
dsinclair5b36f0a2016-07-19 10:56:23 -07004306
tsepezd19e9122016-11-02 15:43:18 -07004307bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4308 const CFX_WideString& wsXMLValue,
4309 bool bNotify,
4310 bool bScriptModify,
4311 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004312 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4313 bSyncData);
4314}
dsinclair5b36f0a2016-07-19 10:56:23 -07004315
tsepezd19e9122016-11-02 15:43:18 -07004316CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004317 CFX_WideString wsContent;
4318 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4319}
dsinclair5b36f0a2016-07-19 10:56:23 -07004320
Dan Sinclair1770c022016-03-14 14:14:16 -04004321CFX_WideString CXFA_Node::GetContent() {
4322 return GetScriptContent();
4323}
dsinclair5b36f0a2016-07-19 10:56:23 -07004324
tsepezd19e9122016-11-02 15:43:18 -07004325bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4326 bool bScriptModify,
4327 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004328 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004329 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004330 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004331 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004332 pNode = this;
4333 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004334 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004335 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004336 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004337 }
4338 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4339 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
4340 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType,
4341 FX_WSTRC(L"text/xml"));
4342 }
4343 return pChildValue
4344 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004345 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004346 }
4347 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004348 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004349 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4350 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004351 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004352 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004353 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004354 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
tsepez9f2970c2016-04-01 10:23:04 -07004355 if (wsContentType == FX_WSTRC(L"text/html")) {
dsinclair56a8b192016-06-21 14:15:25 -07004356 element = XFA_Element::SharpxHTML;
tsepez9f2970c2016-04-01 10:23:04 -07004357 } else if (wsContentType == FX_WSTRC(L"text/xml")) {
dsinclair56a8b192016-06-21 14:15:25 -07004358 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004359 }
4360 }
4361 pContentRawDataNode = CreateSamePacketNode(element);
4362 InsertChild(pContentRawDataNode);
4363 }
4364 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4365 }
dsinclairc5a8f212016-06-20 11:11:12 -07004366 case XFA_ObjectType::NodeC:
4367 case XFA_ObjectType::NodeV:
4368 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004369 pNode = this;
4370 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004371 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004372 pNode = this;
4373 }
4374 break;
4375 }
4376 if (pNode) {
4377 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004378 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004379 if (pScriptContext) {
4380 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4381 }
4382 }
tsepezd19e9122016-11-02 15:43:18 -07004383 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004384 }
tsepezd19e9122016-11-02 15:43:18 -07004385 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004386}
dsinclair5b36f0a2016-07-19 10:56:23 -07004387
Dan Sinclair1770c022016-03-14 14:14:16 -04004388CXFA_Node* CXFA_Node::GetModelNode() {
4389 switch (GetPacketID()) {
4390 case XFA_XDPPACKET_XDP:
4391 return m_pDocument->GetRoot();
4392 case XFA_XDPPACKET_Config:
4393 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4394 case XFA_XDPPACKET_Template:
4395 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4396 case XFA_XDPPACKET_Form:
4397 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4398 case XFA_XDPPACKET_Datasets:
4399 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4400 case XFA_XDPPACKET_LocaleSet:
4401 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4402 case XFA_XDPPACKET_ConnectionSet:
4403 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4404 case XFA_XDPPACKET_SourceSet:
4405 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4406 case XFA_XDPPACKET_Xdc:
4407 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4408 default:
4409 return this;
4410 }
4411}
dsinclair5b36f0a2016-07-19 10:56:23 -07004412
tsepezd19e9122016-11-02 15:43:18 -07004413bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004414 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004415 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
dsinclairae95f762016-03-29 16:58:29 -07004416 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004417 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004418 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004419 }
dsinclairae95f762016-03-29 16:58:29 -07004420 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004421 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004422 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
dsinclairae95f762016-03-29 16:58:29 -07004423 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004424 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004425 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004426 }
4427 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004428 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004429 }
dsinclair070fcdf2016-06-22 22:04:54 -07004430 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004431 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4432 return XFA_FDEExtension_ResolveNamespaceQualifier(
dsinclairae95f762016-03-29 16:58:29 -07004433 static_cast<CFDE_XMLElement*>(pXMLNode),
4434 GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004435 }
dsinclairae95f762016-03-29 16:58:29 -07004436 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004437 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004438 } else {
4439 CXFA_Node* pModelNode = GetModelNode();
4440 return pModelNode->TryNamespace(wsNamespace);
4441 }
4442}
dsinclair5b36f0a2016-07-19 10:56:23 -07004443
Dan Sinclair1770c022016-03-14 14:14:16 -04004444CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004445 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004446 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004447 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004448 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004449 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004450 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004451 if (!pProperty || index >= pProperty->uOccur)
4452 return nullptr;
4453
Dan Sinclair1770c022016-03-14 14:14:16 -04004454 CXFA_Node* pNode = m_pChild;
4455 int32_t iCount = 0;
4456 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004457 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004458 iCount++;
4459 if (iCount > index) {
4460 return pNode;
4461 }
4462 }
4463 }
weili44f8faf2016-06-01 14:03:56 -07004464 if (!bCreateProperty)
4465 return nullptr;
4466
Dan Sinclair1770c022016-03-14 14:14:16 -04004467 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4468 pNode = m_pChild;
4469 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4470 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004471 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004472 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4473 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004474 }
4475 }
dsinclaira1b07722016-07-11 08:20:58 -07004476
Dan Sinclair1770c022016-03-14 14:14:16 -04004477 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004478 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004479 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004480 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004481 if (!pNewNode)
4482 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004483 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004484 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004485 }
4486 return pNewNode;
4487}
dsinclair5b36f0a2016-07-19 10:56:23 -07004488
tsepezd19e9122016-11-02 15:43:18 -07004489int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004490 CXFA_Node* pNode = m_pChild;
4491 int32_t iCount = 0;
4492 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004493 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004494 if (bOnlyChild) {
4495 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004496 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004497 if (pProperty) {
4498 continue;
4499 }
4500 }
4501 iCount++;
4502 }
4503 }
4504 return iCount;
4505}
dsinclair5b36f0a2016-07-19 10:56:23 -07004506
Dan Sinclair1770c022016-03-14 14:14:16 -04004507CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004508 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004509 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004510 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004511 CXFA_Node* pNode = m_pChild;
4512 int32_t iCount = 0;
4513 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004514 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004515 if (bOnlyChild) {
4516 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004517 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004518 if (pProperty) {
4519 continue;
4520 }
4521 }
4522 iCount++;
4523 if (iCount > index) {
4524 return pNode;
4525 }
4526 }
4527 }
weili44f8faf2016-06-01 14:03:56 -07004528 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004529}
dsinclair5b36f0a2016-07-19 10:56:23 -07004530
Dan Sinclair1770c022016-03-14 14:14:16 -04004531int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4532 ASSERT(!pNode->m_pNext);
4533 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004534 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004535 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004536 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004537
weili44f8faf2016-06-01 14:03:56 -07004538 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004539 if (index > 0) {
4540 return -1;
4541 }
4542 pNode->m_pNext = m_pChild;
4543 m_pChild = pNode;
4544 index = 0;
4545 } else if (index < 0) {
4546 m_pLastChild->m_pNext = pNode;
4547 } else {
4548 CXFA_Node* pPrev = m_pChild;
4549 int32_t iCount = 0;
4550 while (++iCount != index && pPrev->m_pNext) {
4551 pPrev = pPrev->m_pNext;
4552 }
4553 if (index > 0 && index != iCount) {
4554 return -1;
4555 }
4556 pNode->m_pNext = pPrev->m_pNext;
4557 pPrev->m_pNext = pNode;
4558 index = iCount;
4559 }
weili44f8faf2016-06-01 14:03:56 -07004560 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004561 m_pLastChild = pNode;
4562 }
4563 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004564 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004565 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004566 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004567 if (pNotify)
4568 pNotify->OnChildAdded(this);
4569
Dan Sinclair1770c022016-03-14 14:14:16 -04004570 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004571 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004572 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004573 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004574 }
4575 return index;
4576}
weili6e1ae862016-05-04 18:25:27 -07004577
tsepezd19e9122016-11-02 15:43:18 -07004578bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004579 if (!pNode || pNode->m_pParent ||
4580 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004581 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004582 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004583 }
tsepezd19e9122016-11-02 15:43:18 -07004584 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004585 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004586 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004587
4588 int32_t nIndex = -1;
4589 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004590 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004591 pNode->m_pNext = m_pChild;
4592 m_pChild = pNode;
4593 nIndex = 0;
4594 } else if (!pBeforeNode) {
4595 pNode->m_pNext = m_pLastChild->m_pNext;
4596 m_pLastChild->m_pNext = pNode;
4597 } else {
4598 nIndex = 1;
4599 CXFA_Node* pPrev = m_pChild;
4600 while (pPrev->m_pNext != pBeforeNode) {
4601 pPrev = pPrev->m_pNext;
4602 nIndex++;
4603 }
4604 pNode->m_pNext = pPrev->m_pNext;
4605 pPrev->m_pNext = pNode;
4606 }
weili44f8faf2016-06-01 14:03:56 -07004607 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004608 m_pLastChild = pNode;
4609 }
4610 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004611 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004612 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004613 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004614 if (pNotify)
4615 pNotify->OnChildAdded(this);
4616
Dan Sinclair1770c022016-03-14 14:14:16 -04004617 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004618 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004619 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004620 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004621 }
tsepezd19e9122016-11-02 15:43:18 -07004622 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004623}
dsinclair5b36f0a2016-07-19 10:56:23 -07004624
Dan Sinclair1770c022016-03-14 14:14:16 -04004625CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4626 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004627 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004628 }
4629 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4630 pSibling = pSibling->m_pNext) {
4631 if (pSibling->m_pNext == this) {
4632 return pSibling;
4633 }
4634 }
weili44f8faf2016-06-01 14:03:56 -07004635 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004636}
dsinclair5b36f0a2016-07-19 10:56:23 -07004637
tsepezd19e9122016-11-02 15:43:18 -07004638bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004639 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004640 ASSERT(false);
4641 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004642 }
4643 if (m_pChild == pNode) {
4644 m_pChild = pNode->m_pNext;
4645 if (m_pLastChild == pNode) {
4646 m_pLastChild = pNode->m_pNext;
4647 }
weili44f8faf2016-06-01 14:03:56 -07004648 pNode->m_pNext = nullptr;
4649 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004650 } else {
4651 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4652 pPrev->m_pNext = pNode->m_pNext;
4653 if (m_pLastChild == pNode) {
4654 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4655 }
weili44f8faf2016-06-01 14:03:56 -07004656 pNode->m_pNext = nullptr;
4657 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004658 }
weili44f8faf2016-06-01 14:03:56 -07004659 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004660 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004661 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004662 m_pDocument->AddPurgeNode(pNode);
4663 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4664 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004665 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4666 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004667 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07004668 CFDE_XMLElement* pXMLElement =
4669 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004670 CFX_WideStringC wsAttributeName =
4671 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004672 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004673 }
4674 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004675 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -07004676 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004677 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4678 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004679 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004680 }
4681 pNode->m_pXMLNode = pNewXMLElement;
4682 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4683 } else {
4684 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4685 }
dsinclairc5a8f212016-06-20 11:11:12 -07004686 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004687 }
tsepezd19e9122016-11-02 15:43:18 -07004688 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004689}
dsinclair5b36f0a2016-07-19 10:56:23 -07004690
Dan Sinclair1770c022016-03-14 14:14:16 -04004691CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004692 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004693}
dsinclair5b36f0a2016-07-19 10:56:23 -07004694
tsepez736f28a2016-03-25 14:19:51 -07004695CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004696 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4697 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4698 if (pNode->GetNameHash() == dwNameHash) {
4699 return pNode;
4700 }
4701 }
weili44f8faf2016-06-01 14:03:56 -07004702 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004703}
dsinclair5b36f0a2016-07-19 10:56:23 -07004704
dsinclair41cb62e2016-06-23 09:20:32 -07004705CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004706 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4707 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004708 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004709 return pNode;
4710 }
4711 }
weili44f8faf2016-06-01 14:03:56 -07004712 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004713}
dsinclair5b36f0a2016-07-19 10:56:23 -07004714
tsepez736f28a2016-03-25 14:19:51 -07004715CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004716 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4717 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4718 if (pNode->GetNameHash() == dwNameHash) {
4719 return pNode;
4720 }
4721 }
weili44f8faf2016-06-01 14:03:56 -07004722 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004723}
dsinclair5b36f0a2016-07-19 10:56:23 -07004724
Dan Sinclair1770c022016-03-14 14:14:16 -04004725CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4726 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004727 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004728}
dsinclair5b36f0a2016-07-19 10:56:23 -07004729
dsinclair41cb62e2016-06-23 09:20:32 -07004730CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004731 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4732 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004733 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004734 return pNode;
4735 }
4736 }
weili44f8faf2016-06-01 14:03:56 -07004737 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004738}
dsinclair5b36f0a2016-07-19 10:56:23 -07004739
Dan Sinclair1770c022016-03-14 14:14:16 -04004740int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004741 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004742 if (!pScriptContext) {
4743 return -1;
4744 }
4745 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4746}
dsinclair5b36f0a2016-07-19 10:56:23 -07004747
Dan Sinclair1770c022016-03-14 14:14:16 -04004748int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004749 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004750 if (!pScriptContext) {
4751 return -1;
4752 }
4753 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4754}
dsinclair5b36f0a2016-07-19 10:56:23 -07004755
Dan Sinclair1770c022016-03-14 14:14:16 -04004756void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004757 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004758 if (!pScriptContext) {
4759 return;
4760 }
4761 pScriptContext->GetSomExpression(this, wsSOMExpression);
4762}
dsinclair5b36f0a2016-07-19 10:56:23 -07004763
Dan Sinclair1770c022016-03-14 14:14:16 -04004764CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004765 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004766 if (m_ePacket == XFA_XDPPACKET_Form) {
4767 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004768 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004769 return pInstanceMgr;
4770 }
4771 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4772 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004773 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004774 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004775 pNode->m_dwNameHash != m_dwNameHash) {
4776 break;
4777 }
dsinclair56a8b192016-06-21 14:15:25 -07004778 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004779 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4780 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4781 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4782 wsInstName.Mid(1) == wsName) {
4783 pInstanceMgr = pNode;
4784 }
4785 break;
4786 }
4787 }
4788 }
4789 return pInstanceMgr;
4790}
dsinclair5b36f0a2016-07-19 10:56:23 -07004791
Dan Sinclair1770c022016-03-14 14:14:16 -04004792CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004793 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004794}
dsinclair5b36f0a2016-07-19 10:56:23 -07004795
dsinclairc5a8f212016-06-20 11:11:12 -07004796bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4797 if (m_uNodeFlags & dwFlag)
4798 return true;
4799 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4800 return m_pParent && m_pParent->HasFlag(dwFlag);
4801 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004802}
thestigb1a59592016-04-14 18:29:56 -07004803
4804void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004805 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004806 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004807 if (pNotify) {
4808 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004809 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004810 }
dsinclairc5a8f212016-06-20 11:11:12 -07004811 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004812}
thestigb1a59592016-04-14 18:29:56 -07004813
4814void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004815 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004816}
4817
tsepezd19e9122016-11-02 15:43:18 -07004818bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004819 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4820}
thestigb1a59592016-04-14 18:29:56 -07004821
4822void CXFA_Node::OnRemoved(bool bNotify) {
4823 if (!bNotify)
4824 return;
4825
dsinclaira1b07722016-07-11 08:20:58 -07004826 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004827 if (pNotify)
4828 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004829}
thestigb1a59592016-04-14 18:29:56 -07004830
4831void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004832 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004833 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004834 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004835 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004836 }
4837 }
4838}
thestigb1a59592016-04-14 18:29:56 -07004839
Dan Sinclair1770c022016-03-14 14:14:16 -04004840void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004841 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004842 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004843 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004844 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004845 }
4846}
thestigb1a59592016-04-14 18:29:56 -07004847
Dan Sinclair1770c022016-03-14 14:14:16 -04004848int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004849 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004850 int32_t iRet = XFA_EVENTERROR_NotExist;
4851 const XFA_ExecEventParaInfo* eventParaInfo =
4852 GetEventParaInfoByName(wsEventName);
4853 if (eventParaInfo) {
4854 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004855 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004856 if (!pNotify) {
4857 return iRet;
4858 }
4859 if (validFlags == 1) {
4860 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4861 } else if (validFlags == 2) {
4862 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004863 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004864 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004865 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004866 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004867 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004868 }
4869 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004870 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004871 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004872 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004873 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004874 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004875 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004876 }
4877 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004878 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004879 }
4880 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004881 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004882 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004883 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004884 }
4885 } else if (validFlags == 6) {
4886 CXFA_WidgetData* pWidgetData = GetWidgetData();
4887 if (pWidgetData) {
4888 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004889 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004890 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004891 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004892 }
4893 }
4894 } else if (validFlags == 7) {
4895 CXFA_WidgetData* pWidgetData = GetWidgetData();
4896 if (pWidgetData) {
4897 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004898 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004899 (!pWidgetData->IsListBox())) {
4900 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004901 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004902 }
4903 }
4904 }
4905 }
4906 return iRet;
4907}
dsinclair5b36f0a2016-07-19 10:56:23 -07004908
Dan Sinclair1770c022016-03-14 14:14:16 -04004909void CXFA_Node::UpdateNameHash() {
4910 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004911 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004912 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004913 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004914 wsName = GetCData(XFA_ATTRIBUTE_Name);
4915 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004916 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004917 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004918 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004919 }
4920}
dsinclair5b36f0a2016-07-19 10:56:23 -07004921
dsinclairae95f762016-03-29 16:58:29 -07004922CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004923 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004924 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
dsinclairae95f762016-03-29 16:58:29 -07004925 m_pXMLNode = new CFDE_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004926 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004927 }
4928 return m_pXMLNode;
4929}
dsinclair5b36f0a2016-07-19 10:56:23 -07004930
tsepezd19e9122016-11-02 15:43:18 -07004931bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004932 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004933 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004934}
4935
4936XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4937 if (!m_pMapModuleData)
4938 m_pMapModuleData = new XFA_MAPMODULEDATA;
4939 return m_pMapModuleData;
4940}
4941
4942XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4943 return m_pMapModuleData;
4944}
4945
4946void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4947 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4948 pModule->m_ValueMap.SetAt(pKey, pValue);
4949}
4950
tsepezd19e9122016-11-02 15:43:18 -07004951bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004952 CXFA_Node* pNode = this;
4953 while (pNode) {
4954 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
4955 if (pModule && pModule->m_ValueMap.Lookup(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004956 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004957 }
4958 pNode = pNode->GetPacketID() != XFA_XDPPACKET_Datasets
4959 ? pNode->GetTemplateNode()
weili44f8faf2016-06-01 14:03:56 -07004960 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004961 }
tsepezd19e9122016-11-02 15:43:18 -07004962 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004963}
dsinclair5b36f0a2016-07-19 10:56:23 -07004964
Dan Sinclair1770c022016-03-14 14:14:16 -04004965void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004966 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair1770c022016-03-14 14:14:16 -04004967 wsValue.GetLength() * sizeof(FX_WCHAR));
4968}
dsinclair5b36f0a2016-07-19 10:56:23 -07004969
tsepezd19e9122016-11-02 15:43:18 -07004970bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004971 void* pValue;
4972 int32_t iBytes;
4973 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004974 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004975 }
4976 wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR));
tsepezd19e9122016-11-02 15:43:18 -07004977 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004978}
dsinclair5b36f0a2016-07-19 10:56:23 -07004979
Dan Sinclair1770c022016-03-14 14:14:16 -04004980void CXFA_Node::SetMapModuleBuffer(
4981 void* pKey,
4982 void* pValue,
4983 int32_t iBytes,
4984 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4985 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4986 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004987 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004988 pBuffer =
4989 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4990 } else if (pBuffer->iBytes != iBytes) {
4991 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4992 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4993 }
4994 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4995 sizeof(XFA_MAPDATABLOCK) + iBytes);
4996 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4997 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4998 }
weili44f8faf2016-06-01 14:03:56 -07004999 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04005000 return;
weili44f8faf2016-06-01 14:03:56 -07005001
Dan Sinclair1770c022016-03-14 14:14:16 -04005002 pBuffer->pCallbackInfo = pCallbackInfo;
5003 pBuffer->iBytes = iBytes;
5004 FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes);
5005}
dsinclair5b36f0a2016-07-19 10:56:23 -07005006
tsepezd19e9122016-11-02 15:43:18 -07005007bool CXFA_Node::GetMapModuleBuffer(void* pKey,
5008 void*& pValue,
5009 int32_t& iBytes,
5010 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07005011 XFA_MAPDATABLOCK* pBuffer = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005012 const CXFA_Node* pNode = this;
5013 while (pNode) {
5014 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
5015 if (pModule && pModule->m_BufferMap.Lookup(pKey, pBuffer)) {
5016 break;
5017 }
5018 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets)
5019 ? pNode->GetTemplateNode()
weili44f8faf2016-06-01 14:03:56 -07005020 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005021 }
weili44f8faf2016-06-01 14:03:56 -07005022 if (!pBuffer) {
tsepezd19e9122016-11-02 15:43:18 -07005023 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005024 }
5025 pValue = pBuffer->GetData();
5026 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07005027 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005028}
dsinclair5b36f0a2016-07-19 10:56:23 -07005029
tsepezd19e9122016-11-02 15:43:18 -07005030bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005031 CXFA_Node* pNode = this;
5032 while (pNode) {
5033 void* pVal;
5034 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
5035 if (pModule &&
5036 (pModule->m_ValueMap.Lookup(pKey, pVal) ||
5037 pModule->m_BufferMap.Lookup(pKey, (XFA_MAPDATABLOCK*&)pVal))) {
tsepezd19e9122016-11-02 15:43:18 -07005038 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005039 }
5040 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets)
5041 ? pNode->GetTemplateNode()
weili44f8faf2016-06-01 14:03:56 -07005042 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005043 }
tsepezd19e9122016-11-02 15:43:18 -07005044 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005045}
dsinclair5b36f0a2016-07-19 10:56:23 -07005046
Dan Sinclair1770c022016-03-14 14:14:16 -04005047void CXFA_Node::RemoveMapModuleKey(void* pKey) {
5048 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
5049 if (!pModule)
5050 return;
5051
5052 if (pKey) {
weili44f8faf2016-06-01 14:03:56 -07005053 XFA_MAPDATABLOCK* pBuffer = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005054 pModule->m_BufferMap.Lookup(pKey, pBuffer);
5055 if (pBuffer) {
5056 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5057 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5058 }
5059 FX_Free(pBuffer);
5060 }
5061 pModule->m_BufferMap.RemoveKey(pKey);
5062 pModule->m_ValueMap.RemoveKey(pKey);
5063 } else {
5064 XFA_MAPDATABLOCK* pBuffer;
5065 FX_POSITION posBuffer = pModule->m_BufferMap.GetStartPosition();
5066 while (posBuffer) {
5067 pModule->m_BufferMap.GetNextAssoc(posBuffer, pKey, pBuffer);
5068 if (pBuffer) {
5069 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5070 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5071 }
5072 FX_Free(pBuffer);
5073 }
5074 }
5075 pModule->m_BufferMap.RemoveAll();
5076 pModule->m_ValueMap.RemoveAll();
5077 delete pModule;
5078 }
5079}
dsinclair5b36f0a2016-07-19 10:56:23 -07005080
tsepezd19e9122016-11-02 15:43:18 -07005081void CXFA_Node::MergeAllData(void* pDstModule, bool bUseSrcAttr) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005082 XFA_MAPMODULEDATA* pDstModuleData =
5083 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
5084 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
5085 if (!pSrcModuleData) {
5086 return;
5087 }
5088 FX_POSITION psValue = pSrcModuleData->m_ValueMap.GetStartPosition();
5089 while (psValue) {
5090 void* pKey;
5091 void* pValue;
5092 pSrcModuleData->m_ValueMap.GetNextAssoc(psValue, pKey, pValue);
5093 if (bUseSrcAttr || !pDstModuleData->m_ValueMap.GetValueAt(pKey)) {
5094 pDstModuleData->m_ValueMap.SetAt(pKey, pValue);
5095 }
5096 }
5097 FX_POSITION psBuffer = pSrcModuleData->m_BufferMap.GetStartPosition();
5098 while (psBuffer) {
5099 void* pKey;
5100 XFA_MAPDATABLOCK* pSrcBuffer;
5101 pSrcModuleData->m_BufferMap.GetNextAssoc(psBuffer, pKey, pSrcBuffer);
5102 XFA_MAPDATABLOCK*& pBuffer = pDstModuleData->m_BufferMap[pKey];
5103 if (pBuffer && !bUseSrcAttr) {
5104 continue;
5105 }
5106 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
5107 !pSrcBuffer->pCallbackInfo->pCopy) {
5108 if (pBuffer) {
5109 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5110 pDstModuleData->m_BufferMap.RemoveKey(pKey);
5111 }
5112 continue;
5113 }
weili44f8faf2016-06-01 14:03:56 -07005114 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005115 pBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
5116 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5117 } else if (pBuffer->iBytes != pSrcBuffer->iBytes) {
5118 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5119 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5120 }
5121 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
5122 uint8_t, pBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5123 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5124 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5125 }
weili44f8faf2016-06-01 14:03:56 -07005126 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005127 continue;
5128 }
5129 pBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5130 pBuffer->iBytes = pSrcBuffer->iBytes;
5131 FXSYS_memcpy(pBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes);
5132 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pCopy) {
5133 pBuffer->pCallbackInfo->pCopy(*(void**)pBuffer->GetData());
5134 }
5135 }
5136}
dsinclair5b36f0a2016-07-19 10:56:23 -07005137
Dan Sinclair1770c022016-03-14 14:14:16 -04005138void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5139 if (!pDstModule) {
5140 return;
5141 }
tsepezd19e9122016-11-02 15:43:18 -07005142 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005143 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005144 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005145 }
dsinclair070fcdf2016-06-22 22:04:54 -07005146 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005147 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005148 }
weili44f8faf2016-06-01 14:03:56 -07005149 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5150 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005151 if (bNeedMove) {
5152 pSrcModuleData = GetMapModuleData();
5153 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005154 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005155 }
5156 pDstModuleData = pDstModule->CreateMapModuleData();
5157 }
5158 if (bNeedMove) {
5159 void* pBufferBlockData = pSrcModuleData->m_BufferMap.GetValueAt(pKey);
5160 if (pBufferBlockData) {
5161 pSrcModuleData->m_BufferMap.RemoveKey(pKey);
5162 pDstModuleData->m_BufferMap.RemoveKey(pKey);
5163 pDstModuleData->m_BufferMap.SetAt(pKey,
5164 (XFA_MAPDATABLOCK*)pBufferBlockData);
5165 }
5166 }
dsinclairc5a8f212016-06-20 11:11:12 -07005167 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005168 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005169 CFX_WideString wsFormatValue(wsValue);
5170 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5171 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005172 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005173 }
tsepezd19e9122016-11-02 15:43:18 -07005174 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005175 }
5176}
dsinclair5b36f0a2016-07-19 10:56:23 -07005177
Dan Sinclair1770c022016-03-14 14:14:16 -04005178void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5179 CXFA_Node* pDstModule,
5180 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005181 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005182 if (!pSrcModule || !pDstModule || !pKey) {
5183 return;
5184 }
5185 if (bRecursive) {
5186 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5187 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5188 for (; pSrcChild && pDstChild;
5189 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5190 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005191 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005192 }
5193 }
5194 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5195}