blob: 9c209b23b75a2f5332af0a89a9d9fd9a801e1c74 [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>
11
dsinclaira52ab742016-09-29 13:59:29 -070012#include "core/fxcrt/fx_ext.h"
dsinclair43554682016-09-29 17:29:48 -070013#include "fxjs/cfxjse_value.h"
tsepezaadedf92016-05-12 10:08:06 -070014#include "third_party/base/stl_util.h"
dsinclairae95f762016-03-29 16:58:29 -070015#include "xfa/fde/xml/fde_xml_imp.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040016#include "xfa/fgas/crt/fgas_codepage.h"
dsinclairdf4bc592016-03-31 20:34:43 -070017#include "xfa/fxfa/app/xfa_ffnotify.h"
dsinclair5b493092016-09-29 20:20:24 -070018#include "xfa/fxfa/cxfa_eventparam.h"
dsinclair16280242016-07-21 12:03:47 -070019#include "xfa/fxfa/parser/cxfa_document.h"
dsinclair0b851ff2016-07-21 12:03:01 -070020#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
dsinclair9eb0db12016-07-21 12:01:39 -070021#include "xfa/fxfa/parser/cxfa_measurement.h"
dsinclair44d054c2016-04-06 10:23:46 -070022#include "xfa/fxfa/parser/cxfa_occur.h"
dsinclair31f87402016-07-20 06:34:45 -070023#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
dsinclair34f86b02016-07-11 08:42:33 -070024#include "xfa/fxfa/parser/cxfa_simple_parser.h"
dsinclair5b36f0a2016-07-19 10:56:23 -070025#include "xfa/fxfa/parser/xfa_basic_data.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040026
weili44f8faf2016-06-01 14:03:56 -070027namespace {
28
29void XFA_DeleteWideString(void* pData) {
30 delete static_cast<CFX_WideString*>(pData);
31}
32
33void XFA_CopyWideString(void*& pData) {
34 if (pData) {
35 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
36 pData = pNewData;
37 }
38}
39
40XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
41 XFA_CopyWideString};
42
weili44f8faf2016-06-01 14:03:56 -070043void XFA_DataNodeDeleteBindItem(void* pData) {
44 delete static_cast<CXFA_NodeArray*>(pData);
45}
46
47XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
48 XFA_DataNodeDeleteBindItem, nullptr};
49
dsinclair5b36f0a2016-07-19 10:56:23 -070050int32_t GetCount(CXFA_Node* pInstMgrNode) {
51 ASSERT(pInstMgrNode);
52 int32_t iCount = 0;
53 uint32_t dwNameHash = 0;
54 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
55 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
56 XFA_Element eCurType = pNode->GetElementType();
57 if (eCurType == XFA_Element::InstanceManager)
58 break;
59 if ((eCurType != XFA_Element::Subform) &&
60 (eCurType != XFA_Element::SubformSet)) {
61 continue;
62 }
63 if (iCount == 0) {
64 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
65 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
66 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
67 wsInstName.Mid(1) != wsName) {
68 return iCount;
69 }
70 dwNameHash = pNode->GetNameHash();
71 }
72 if (dwNameHash != pNode->GetNameHash())
73 break;
weili44f8faf2016-06-01 14:03:56 -070074
dsinclair5b36f0a2016-07-19 10:56:23 -070075 iCount++;
76 }
77 return iCount;
Dan Sinclair1770c022016-03-14 14:14:16 -040078}
weili44f8faf2016-06-01 14:03:56 -070079
dsinclair5b36f0a2016-07-19 10:56:23 -070080void SortNodeArrayByDocumentIdx(const CXFA_NodeSet& rgNodeSet,
81 CXFA_NodeArray& rgNodeArray,
82 CFX_ArrayTemplate<int32_t>& rgIdxArray) {
83 int32_t iCount = pdfium::CollectionSize<int32_t>(rgNodeSet);
84 rgNodeArray.SetSize(iCount);
85 rgIdxArray.SetSize(iCount);
86 if (iCount == 0)
87 return;
weili44f8faf2016-06-01 14:03:56 -070088
dsinclair5b36f0a2016-07-19 10:56:23 -070089 int32_t iIndex = -1;
90 int32_t iTotalIndex = -1;
91 CXFA_Node* pCommonParent =
92 (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent);
93 for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild);
94 pNode && iIndex < iCount;
95 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
96 iTotalIndex++;
97 if (pdfium::ContainsValue(rgNodeSet, pNode)) {
98 iIndex++;
99 rgNodeArray[iIndex] = pNode;
100 rgIdxArray[iIndex] = iTotalIndex;
101 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400102 }
103}
weili44f8faf2016-06-01 14:03:56 -0700104
dsinclair5b36f0a2016-07-19 10:56:23 -0700105using CXFA_NodeSetPair = std::pair<CXFA_NodeSet, CXFA_NodeSet>;
106using CXFA_NodeSetPairMap =
107 std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>;
108using CXFA_NodeSetPairMapMap =
109 std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>;
110
111CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode,
112 CXFA_NodeSetPairMapMap* pMap) {
113 CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
114 uint32_t dwNameHash = pNode->GetNameHash();
115 if (!pParentNode || !dwNameHash)
116 return nullptr;
117
118 if (!(*pMap)[pParentNode])
119 (*pMap)[pParentNode].reset(new CXFA_NodeSetPairMap);
120
121 CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get();
122 if (!(*pNodeSetPairMap)[dwNameHash])
123 (*pNodeSetPairMap)[dwNameHash].reset(new CXFA_NodeSetPair);
124
125 return (*pNodeSetPairMap)[dwNameHash].get();
Dan Sinclair1770c022016-03-14 14:14:16 -0400126}
127
dsinclair5b36f0a2016-07-19 10:56:23 -0700128void ReorderDataNodes(const CXFA_NodeSet& sSet1,
129 const CXFA_NodeSet& sSet2,
130 FX_BOOL bInsertBefore) {
131 CXFA_NodeSetPairMapMap rgMap;
132 for (CXFA_Node* pNode : sSet1) {
133 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
134 if (pNodeSetPair)
135 pNodeSetPair->first.insert(pNode);
136 }
137 for (CXFA_Node* pNode : sSet2) {
138 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
139 if (pNodeSetPair) {
140 if (pdfium::ContainsValue(pNodeSetPair->first, pNode))
141 pNodeSetPair->first.erase(pNode);
142 else
143 pNodeSetPair->second.insert(pNode);
144 }
145 }
146 for (const auto& iter1 : rgMap) {
147 CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get();
148 if (!pNodeSetPairMap)
149 continue;
150
151 for (const auto& iter2 : *pNodeSetPairMap) {
152 CXFA_NodeSetPair* pNodeSetPair = iter2.second.get();
153 if (!pNodeSetPair)
154 continue;
155 if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) {
156 CXFA_NodeArray rgNodeArray1;
157 CXFA_NodeArray rgNodeArray2;
158 CFX_ArrayTemplate<int32_t> rgIdxArray1;
159 CFX_ArrayTemplate<int32_t> rgIdxArray2;
160 SortNodeArrayByDocumentIdx(pNodeSetPair->first, rgNodeArray1,
161 rgIdxArray1);
162 SortNodeArrayByDocumentIdx(pNodeSetPair->second, rgNodeArray2,
163 rgIdxArray2);
164 CXFA_Node* pParentNode = nullptr;
165 CXFA_Node* pBeforeNode = nullptr;
166 if (bInsertBefore) {
167 pBeforeNode = rgNodeArray2[0];
168 pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent);
169 } else {
170 CXFA_Node* pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1];
171 pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent);
172 pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling);
173 }
174 for (int32_t iIdx = 0; iIdx < rgIdxArray1.GetSize(); iIdx++) {
175 CXFA_Node* pCurNode = rgNodeArray1[iIdx];
176 pParentNode->RemoveChild(pCurNode);
177 pParentNode->InsertChild(pCurNode, pBeforeNode);
178 }
179 }
180 }
181 pNodeSetPairMap->clear();
182 }
183}
184
185CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
186 ASSERT(pInstMgrNode);
187 int32_t iCount = 0;
188 uint32_t dwNameHash = 0;
189 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
190 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
191 XFA_Element eCurType = pNode->GetElementType();
192 if (eCurType == XFA_Element::InstanceManager)
193 break;
194 if ((eCurType != XFA_Element::Subform) &&
195 (eCurType != XFA_Element::SubformSet)) {
196 continue;
197 }
198 if (iCount == 0) {
199 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
200 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
201 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
202 wsInstName.Mid(1) != wsName) {
203 return nullptr;
204 }
205 dwNameHash = pNode->GetNameHash();
206 }
207 if (dwNameHash != pNode->GetNameHash())
208 break;
209
210 iCount++;
211 if (iCount > iIndex)
212 return pNode;
213 }
214 return nullptr;
215}
216
217void InsertItem(CXFA_Node* pInstMgrNode,
218 CXFA_Node* pNewInstance,
219 int32_t iPos,
220 int32_t iCount = -1,
221 FX_BOOL bMoveDataBindingNodes = TRUE) {
222 if (iCount < 0)
223 iCount = GetCount(pInstMgrNode);
224 if (iPos < 0)
225 iPos = iCount;
226 if (iPos == iCount) {
227 CXFA_Node* pNextSibling =
228 iCount > 0
229 ? GetItem(pInstMgrNode, iCount - 1)
230 ->GetNodeItem(XFA_NODEITEM_NextSibling)
231 : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
232 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
233 ->InsertChild(pNewInstance, pNextSibling);
234 if (bMoveDataBindingNodes) {
235 CXFA_NodeSet sNew;
236 CXFA_NodeSet sAfter;
237 CXFA_NodeIteratorTemplate<CXFA_Node,
238 CXFA_TraverseStrategy_XFAContainerNode>
239 sIteratorNew(pNewInstance);
240 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
241 pNode = sIteratorNew.MoveToNext()) {
242 CXFA_Node* pDataNode = pNode->GetBindData();
243 if (!pDataNode)
244 continue;
245
246 sNew.insert(pDataNode);
247 }
248 CXFA_NodeIteratorTemplate<CXFA_Node,
249 CXFA_TraverseStrategy_XFAContainerNode>
250 sIteratorAfter(pNextSibling);
251 for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode;
252 pNode = sIteratorAfter.MoveToNext()) {
253 CXFA_Node* pDataNode = pNode->GetBindData();
254 if (!pDataNode)
255 continue;
256
257 sAfter.insert(pDataNode);
258 }
259 ReorderDataNodes(sNew, sAfter, FALSE);
260 }
261 } else {
262 CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos);
263 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
264 ->InsertChild(pNewInstance, pBeforeInstance);
265 if (bMoveDataBindingNodes) {
266 CXFA_NodeSet sNew;
267 CXFA_NodeSet sBefore;
268 CXFA_NodeIteratorTemplate<CXFA_Node,
269 CXFA_TraverseStrategy_XFAContainerNode>
270 sIteratorNew(pNewInstance);
271 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
272 pNode = sIteratorNew.MoveToNext()) {
273 CXFA_Node* pDataNode = pNode->GetBindData();
274 if (!pDataNode)
275 continue;
276
277 sNew.insert(pDataNode);
278 }
279 CXFA_NodeIteratorTemplate<CXFA_Node,
280 CXFA_TraverseStrategy_XFAContainerNode>
281 sIteratorBefore(pBeforeInstance);
282 for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode;
283 pNode = sIteratorBefore.MoveToNext()) {
284 CXFA_Node* pDataNode = pNode->GetBindData();
285 if (!pDataNode)
286 continue;
287
288 sBefore.insert(pDataNode);
289 }
290 ReorderDataNodes(sNew, sBefore, TRUE);
291 }
292 }
293}
294
295void RemoveItem(CXFA_Node* pInstMgrNode,
296 CXFA_Node* pRemoveInstance,
297 FX_BOOL bRemoveDataBinding = TRUE) {
298 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);
299 if (!bRemoveDataBinding)
300 return;
301
302 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode>
303 sIterator(pRemoveInstance);
304 for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode;
305 pFormNode = sIterator.MoveToNext()) {
306 CXFA_Node* pDataNode = pFormNode->GetBindData();
307 if (!pDataNode)
308 continue;
309
310 if (pDataNode->RemoveBindItem(pFormNode) == 0) {
311 if (CXFA_Node* pDataParent =
312 pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) {
313 pDataParent->RemoveChild(pDataNode);
314 }
315 }
316 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
317 }
318}
319
320CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, FX_BOOL bDataMerge) {
321 CXFA_Document* pDocument = pInstMgrNode->GetDocument();
322 CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();
323 CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);
324 CXFA_Node* pDataScope = nullptr;
325 for (CXFA_Node* pRootBoundNode = pFormParent;
326 pRootBoundNode && pRootBoundNode->IsContainerNode();
327 pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) {
328 pDataScope = pRootBoundNode->GetBindData();
329 if (pDataScope)
330 break;
331 }
332 if (!pDataScope) {
333 pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record));
334 ASSERT(pDataScope);
335 }
336 CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer(
337 pTemplateNode, pFormParent, pDataScope, TRUE, bDataMerge, TRUE);
338 if (pInstance) {
339 pDocument->DataMerge_UpdateBindingRelations(pInstance);
340 pFormParent->RemoveChild(pInstance);
341 }
342 return pInstance;
343}
344
345struct XFA_ExecEventParaInfo {
346 public:
347 uint32_t m_uHash;
348 const FX_WCHAR* m_lpcEventName;
349 XFA_EVENTTYPE m_eventType;
350 uint32_t m_validFlags;
351};
352static const XFA_ExecEventParaInfo gs_eventParaInfos[] = {
353 {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0},
354 {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0},
355 {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5},
356 {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0},
357 {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7},
358 {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1},
359 {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5},
360 {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0},
361 {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0},
362 {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6},
363 {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2},
364 {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0},
365 {0x7233018a, L"validate", XFA_EVENT_Validate, 1},
366 {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3},
367 {0x891f4606, L"change", XFA_EVENT_Change, 4},
368 {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0},
369 {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5},
370 {0xcdce56b3, L"full", XFA_EVENT_Full, 4},
371 {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5},
372 {0xd95657a6, L"click", XFA_EVENT_Click, 4},
373 {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1},
374 {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7},
375 {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2},
376 {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0},
377 {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6},
378};
379
380const XFA_ExecEventParaInfo* GetEventParaInfoByName(
381 const CFX_WideStringC& wsEventName) {
382 uint32_t uHash = FX_HashCode_GetW(wsEventName, false);
383 int32_t iStart = 0;
384 int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
385 do {
386 int32_t iMid = (iStart + iEnd) / 2;
387 const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid];
388 if (uHash == eventParaInfo->m_uHash)
389 return eventParaInfo;
390 if (uHash < eventParaInfo->m_uHash)
391 iEnd = iMid - 1;
392 else
393 iStart = iMid + 1;
394 } while (iStart <= iEnd);
395 return nullptr;
396}
397
398void StrToRGB(const CFX_WideString& strRGB,
399 int32_t& r,
400 int32_t& g,
401 int32_t& b) {
402 r = 0;
403 g = 0;
404 b = 0;
405
406 FX_WCHAR zero = '0';
407 int32_t iIndex = 0;
408 int32_t iLen = strRGB.GetLength();
409 for (int32_t i = 0; i < iLen; ++i) {
410 FX_WCHAR ch = strRGB.GetAt(i);
411 if (ch == L',')
412 ++iIndex;
413 if (iIndex > 2)
414 break;
415
416 int32_t iValue = ch - zero;
417 if (iValue >= 0 && iValue <= 9) {
418 switch (iIndex) {
419 case 0:
420 r = r * 10 + iValue;
421 break;
422 case 1:
423 g = g * 10 + iValue;
424 break;
425 default:
426 b = b * 10 + iValue;
427 break;
428 }
429 }
430 }
431}
432
433enum XFA_KEYTYPE {
434 XFA_KEYTYPE_Custom,
435 XFA_KEYTYPE_Element,
436};
437
438void* GetMapKey_Custom(const CFX_WideStringC& wsKey) {
439 uint32_t dwKey = FX_HashCode_GetW(wsKey, false);
440 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom);
441}
442
443void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) {
444 return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) |
445 (eAttribute << 8) | XFA_KEYTYPE_Element);
446}
447
dsinclair9eb0db12016-07-21 12:01:39 -0700448const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement,
449 XFA_ATTRIBUTE eAttribute,
450 uint32_t dwPacket) {
451 int32_t iCount = 0;
452 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount);
453 if (!pAttr || iCount < 1)
454 return nullptr;
455
456 if (!std::binary_search(pAttr, pAttr + iCount, eAttribute))
457 return nullptr;
458
459 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute);
460 ASSERT(pInfo);
461 if (dwPacket == XFA_XDPPACKET_UNKNOWN)
462 return pInfo;
463 return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr;
464}
465
466const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) {
467 return g_XFAEnumData + eName;
468}
469
dsinclair5b36f0a2016-07-19 10:56:23 -0700470} // namespace
471
472static void XFA_DefaultFreeData(void* pData) {}
473
474static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {
475 XFA_DefaultFreeData, nullptr};
476
weili47bcd4c2016-06-16 08:00:06 -0700477XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {}
478
479XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {}
480
dsinclairb9778472016-06-23 13:34:10 -0700481CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
482 uint16_t ePacket,
483 XFA_ObjectType oType,
dsinclairc1df5d42016-07-18 06:36:51 -0700484 XFA_Element eType,
485 const CFX_WideStringC& elementName)
486 : CXFA_Object(pDoc, oType, eType, elementName),
Dan Sinclair1770c022016-03-14 14:14:16 -0400487 m_pNext(nullptr),
488 m_pChild(nullptr),
489 m_pLastChild(nullptr),
490 m_pParent(nullptr),
491 m_pXMLNode(nullptr),
Dan Sinclair1770c022016-03-14 14:14:16 -0400492 m_ePacket(ePacket),
dsinclairc5a8f212016-06-20 11:11:12 -0700493 m_uNodeFlags(XFA_NodeFlag_None),
Dan Sinclair1770c022016-03-14 14:14:16 -0400494 m_dwNameHash(0),
495 m_pAuxNode(nullptr),
496 m_pMapModuleData(nullptr) {
497 ASSERT(m_pDocument);
498}
weili44f8faf2016-06-01 14:03:56 -0700499
Dan Sinclair1770c022016-03-14 14:14:16 -0400500CXFA_Node::~CXFA_Node() {
weili44f8faf2016-06-01 14:03:56 -0700501 ASSERT(!m_pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400502 RemoveMapModuleKey();
weili44f8faf2016-06-01 14:03:56 -0700503 CXFA_Node* pNode = m_pChild;
Dan Sinclair1770c022016-03-14 14:14:16 -0400504 while (pNode) {
weili44f8faf2016-06-01 14:03:56 -0700505 CXFA_Node* pNext = pNode->m_pNext;
506 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400507 delete pNode;
508 pNode = pNext;
509 }
dsinclairc5a8f212016-06-20 11:11:12 -0700510 if (m_pXMLNode && IsOwnXMLNode())
Tom Sepezd3743ea2016-05-16 15:56:53 -0700511 m_pXMLNode->Release();
Dan Sinclair1770c022016-03-14 14:14:16 -0400512}
weili44f8faf2016-06-01 14:03:56 -0700513
Dan Sinclair1770c022016-03-14 14:14:16 -0400514CXFA_Node* CXFA_Node::Clone(FX_BOOL bRecursive) {
dsinclaira1b07722016-07-11 08:20:58 -0700515 CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700516 if (!pClone)
517 return nullptr;
518
Dan Sinclair1770c022016-03-14 14:14:16 -0400519 MergeAllData(pClone);
520 pClone->UpdateNameHash();
521 if (IsNeedSavingXMLNode()) {
weili44f8faf2016-06-01 14:03:56 -0700522 CFDE_XMLNode* pCloneXML = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400523 if (IsAttributeInXML()) {
524 CFX_WideString wsName;
525 GetAttribute(XFA_ATTRIBUTE_Name, wsName, FALSE);
dsinclairae95f762016-03-29 16:58:29 -0700526 CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -0400527 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
528 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -0700529 pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -0400530 }
531 pCloneXML = pCloneXMLElement;
weili44f8faf2016-06-01 14:03:56 -0700532 pCloneXMLElement = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400533 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
534 } else {
535 pCloneXML = m_pXMLNode->Clone(FALSE);
536 }
537 pClone->SetXMLMappingNode(pCloneXML);
dsinclairc5a8f212016-06-20 11:11:12 -0700538 pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400539 }
540 if (bRecursive) {
541 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
542 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
543 pClone->InsertChild(pChild->Clone(bRecursive));
544 }
545 }
dsinclairc5a8f212016-06-20 11:11:12 -0700546 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
weili44f8faf2016-06-01 14:03:56 -0700547 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400548 return pClone;
549}
weili44f8faf2016-06-01 14:03:56 -0700550
Dan Sinclair1770c022016-03-14 14:14:16 -0400551CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
552 switch (eItem) {
553 case XFA_NODEITEM_NextSibling:
554 return m_pNext;
555 case XFA_NODEITEM_FirstChild:
556 return m_pChild;
557 case XFA_NODEITEM_Parent:
558 return m_pParent;
559 case XFA_NODEITEM_PrevSibling:
560 if (m_pParent) {
561 CXFA_Node* pSibling = m_pParent->m_pChild;
weili44f8faf2016-06-01 14:03:56 -0700562 CXFA_Node* pPrev = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400563 while (pSibling && pSibling != this) {
564 pPrev = pSibling;
565 pSibling = pSibling->m_pNext;
566 }
567 return pPrev;
568 }
weili44f8faf2016-06-01 14:03:56 -0700569 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400570 default:
571 break;
572 }
weili44f8faf2016-06-01 14:03:56 -0700573 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400574}
weili44f8faf2016-06-01 14:03:56 -0700575
Dan Sinclair1770c022016-03-14 14:14:16 -0400576CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
dsinclairc5a8f212016-06-20 11:11:12 -0700577 XFA_ObjectType eType) const {
weili44f8faf2016-06-01 14:03:56 -0700578 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400579 switch (eItem) {
580 case XFA_NODEITEM_NextSibling:
581 pNode = m_pNext;
dsinclairc5a8f212016-06-20 11:11:12 -0700582 while (pNode && pNode->GetObjectType() != eType)
583 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400584 break;
585 case XFA_NODEITEM_FirstChild:
586 pNode = m_pChild;
dsinclairc5a8f212016-06-20 11:11:12 -0700587 while (pNode && pNode->GetObjectType() != eType)
588 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400589 break;
590 case XFA_NODEITEM_Parent:
591 pNode = m_pParent;
dsinclairc5a8f212016-06-20 11:11:12 -0700592 while (pNode && pNode->GetObjectType() != eType)
593 pNode = pNode->m_pParent;
Dan Sinclair1770c022016-03-14 14:14:16 -0400594 break;
595 case XFA_NODEITEM_PrevSibling:
596 if (m_pParent) {
597 CXFA_Node* pSibling = m_pParent->m_pChild;
598 while (pSibling && pSibling != this) {
dsinclairc5a8f212016-06-20 11:11:12 -0700599 if (eType == pSibling->GetObjectType())
Dan Sinclair1770c022016-03-14 14:14:16 -0400600 pNode = pSibling;
dsinclairc5a8f212016-06-20 11:11:12 -0700601
Dan Sinclair1770c022016-03-14 14:14:16 -0400602 pSibling = pSibling->m_pNext;
603 }
604 }
605 break;
606 default:
607 break;
608 }
609 return pNode;
610}
weili44f8faf2016-06-01 14:03:56 -0700611
Dan Sinclair1770c022016-03-14 14:14:16 -0400612int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes,
tsepez736f28a2016-03-25 14:19:51 -0700613 uint32_t dwTypeFilter,
dsinclair41cb62e2016-06-23 09:20:32 -0700614 XFA_Element eTypeFilter,
Dan Sinclair1770c022016-03-14 14:14:16 -0400615 int32_t iLevel) {
616 if (--iLevel < 0) {
617 return nodes.GetSize();
618 }
dsinclair41cb62e2016-06-23 09:20:32 -0700619 if (eTypeFilter != XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400620 CXFA_Node* pChild = m_pChild;
621 while (pChild) {
dsinclair41cb62e2016-06-23 09:20:32 -0700622 if (pChild->GetElementType() == eTypeFilter) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400623 nodes.Add(pChild);
624 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700625 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400626 }
627 }
628 pChild = pChild->m_pNext;
629 }
630 } else if (dwTypeFilter ==
631 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
632 CXFA_Node* pChild = m_pChild;
633 while (pChild) {
634 nodes.Add(pChild);
635 if (iLevel > 0) {
dsinclair41cb62e2016-06-23 09:20:32 -0700636 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
Dan Sinclair1770c022016-03-14 14:14:16 -0400637 }
638 pChild = pChild->m_pNext;
639 }
640 } else if (dwTypeFilter != 0) {
weili44f8faf2016-06-01 14:03:56 -0700641 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
642 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
643 bool bFilterOneOfProperties =
644 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
Dan Sinclair1770c022016-03-14 14:14:16 -0400645 CXFA_Node* pChild = m_pChild;
646 while (pChild) {
647 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -0700648 GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -0400649 if (pProperty) {
650 if (bFilterProperties) {
651 nodes.Add(pChild);
652 } else if (bFilterOneOfProperties &&
653 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
654 nodes.Add(pChild);
655 } else if (bFilterChildren &&
dsinclair070fcdf2016-06-22 22:04:54 -0700656 (pChild->GetElementType() == XFA_Element::Variables ||
657 pChild->GetElementType() == XFA_Element::PageSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400658 nodes.Add(pChild);
659 }
weili44f8faf2016-06-01 14:03:56 -0700660 } else if (bFilterChildren) {
661 nodes.Add(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400662 }
663 pChild = pChild->m_pNext;
664 }
665 if (bFilterOneOfProperties && nodes.GetSize() < 1) {
666 int32_t iProperties = 0;
667 const XFA_PROPERTY* pProperty =
dsinclair070fcdf2016-06-22 22:04:54 -0700668 XFA_GetElementProperties(GetElementType(), iProperties);
weili44f8faf2016-06-01 14:03:56 -0700669 if (!pProperty || iProperties < 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400670 return 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400671 for (int32_t i = 0; i < iProperties; i++) {
672 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400673 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
674 CXFA_Node* pNewNode =
dsinclaira1b07722016-07-11 08:20:58 -0700675 m_pDocument->CreateNode(pPacket, pProperty[i].eName);
weili44f8faf2016-06-01 14:03:56 -0700676 if (!pNewNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400677 break;
weili44f8faf2016-06-01 14:03:56 -0700678 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -0700679 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400680 nodes.Add(pNewNode);
681 break;
682 }
683 }
684 }
685 }
686 return nodes.GetSize();
687}
weili44f8faf2016-06-01 14:03:56 -0700688
dsinclair41cb62e2016-06-23 09:20:32 -0700689CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
tsepez736f28a2016-03-25 14:19:51 -0700690 uint32_t dwFlags) {
dsinclaira1b07722016-07-11 08:20:58 -0700691 CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
thestigb1a59592016-04-14 18:29:56 -0700692 pNode->SetFlag(dwFlags, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400693 return pNode;
694}
weili44f8faf2016-06-01 14:03:56 -0700695
Dan Sinclair1770c022016-03-14 14:14:16 -0400696CXFA_Node* CXFA_Node::CloneTemplateToForm(FX_BOOL bRecursive) {
dsinclair43854a52016-04-27 12:26:00 -0700697 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
dsinclaira1b07722016-07-11 08:20:58 -0700698 CXFA_Node* pClone =
699 m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700700 if (!pClone)
701 return nullptr;
702
Dan Sinclair1770c022016-03-14 14:14:16 -0400703 pClone->SetTemplateNode(this);
704 pClone->UpdateNameHash();
705 pClone->SetXMLMappingNode(GetXMLMappingNode());
706 if (bRecursive) {
707 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
708 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
709 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
710 }
711 }
dsinclairc5a8f212016-06-20 11:11:12 -0700712 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400713 return pClone;
714}
715
716CXFA_Node* CXFA_Node::GetTemplateNode() const {
717 return m_pAuxNode;
718}
719
720void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
721 m_pAuxNode = pTemplateNode;
722}
weili44f8faf2016-06-01 14:03:56 -0700723
Dan Sinclair1770c022016-03-14 14:14:16 -0400724CXFA_Node* CXFA_Node::GetBindData() {
725 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
726 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
727}
weili44f8faf2016-06-01 14:03:56 -0700728
Dan Sinclair1770c022016-03-14 14:14:16 -0400729int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) {
dsinclairc5a8f212016-06-20 11:11:12 -0700730 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700731 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400732 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
733 formItems.Copy(*pItems);
734 return formItems.GetSize();
735 }
736 CXFA_Node* pFormNode =
737 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
weili44f8faf2016-06-01 14:03:56 -0700738 if (pFormNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400739 formItems.Add(pFormNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400740 return formItems.GetSize();
741}
742
Dan Sinclair1770c022016-03-14 14:14:16 -0400743int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
744 ASSERT(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700745 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700746 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400747 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
748 ASSERT(pItems);
749 if (pItems->Find(pFormNode) < 0) {
750 pItems->Add(pFormNode);
751 }
752 return pItems->GetSize();
753 }
754 CXFA_Node* pOldFormItem =
755 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
756 if (!pOldFormItem) {
757 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
758 return 1;
759 } else if (pOldFormItem == pFormNode) {
760 return 1;
761 }
762 CXFA_NodeArray* pItems = new CXFA_NodeArray;
763 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
764 pItems->Add(pOldFormItem);
765 pItems->Add(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700766 m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400767 return 2;
768}
weili44f8faf2016-06-01 14:03:56 -0700769
Dan Sinclair1770c022016-03-14 14:14:16 -0400770int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
dsinclairc5a8f212016-06-20 11:11:12 -0700771 if (BindsFormItems()) {
weili44f8faf2016-06-01 14:03:56 -0700772 CXFA_NodeArray* pItems = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400773 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
774 ASSERT(pItems);
775 int32_t iIndex = pItems->Find(pFormNode);
776 int32_t iCount = pItems->GetSize();
777 if (iIndex >= 0) {
weili44f8faf2016-06-01 14:03:56 -0700778 if (iIndex != iCount - 1)
Dan Sinclair1770c022016-03-14 14:14:16 -0400779 pItems->SetAt(iIndex, pItems->GetAt(iCount - 1));
Dan Sinclair1770c022016-03-14 14:14:16 -0400780 pItems->RemoveAt(iCount - 1);
781 if (iCount == 2) {
782 CXFA_Node* pLastFormNode = pItems->GetAt(0);
783 SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700784 m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400785 }
786 iCount--;
787 }
788 return iCount;
789 }
790 CXFA_Node* pOldFormItem =
791 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
792 if (pOldFormItem == pFormNode) {
weili44f8faf2016-06-01 14:03:56 -0700793 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
794 pOldFormItem = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400795 }
weili44f8faf2016-06-01 14:03:56 -0700796 return pOldFormItem ? 1 : 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400797}
weili44f8faf2016-06-01 14:03:56 -0700798
Dan Sinclair1770c022016-03-14 14:14:16 -0400799FX_BOOL CXFA_Node::HasBindItem() {
weili44f8faf2016-06-01 14:03:56 -0700800 return GetPacketID() == XFA_XDPPACKET_Datasets &&
801 GetObject(XFA_ATTRIBUTE_BindingNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400802}
weili44f8faf2016-06-01 14:03:56 -0700803
Dan Sinclair1770c022016-03-14 14:14:16 -0400804CXFA_WidgetData* CXFA_Node::GetWidgetData() {
805 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
806}
weili44f8faf2016-06-01 14:03:56 -0700807
Dan Sinclair1770c022016-03-14 14:14:16 -0400808CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
weili44f8faf2016-06-01 14:03:56 -0700809 if (GetPacketID() != XFA_XDPPACKET_Form)
810 return nullptr;
dsinclair41cb62e2016-06-23 09:20:32 -0700811 XFA_Element eType = GetElementType();
812 if (eType == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700813 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400814 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700815 if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700816 return nullptr;
817
dsinclair41cb62e2016-06-23 09:20:32 -0700818 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400819 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
820 if (pFieldWidgetData &&
821 pFieldWidgetData->GetChoiceListOpen() ==
822 XFA_ATTRIBUTEENUM_MultiSelect) {
weili44f8faf2016-06-01 14:03:56 -0700823 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400824 } else {
825 CFX_WideString wsPicture;
826 if (pFieldWidgetData) {
827 pFieldWidgetData->GetPictureContent(wsPicture,
828 XFA_VALUEPICTURE_DataBind);
829 }
weili44f8faf2016-06-01 14:03:56 -0700830 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400831 return pFieldWidgetData;
Dan Sinclair1770c022016-03-14 14:14:16 -0400832 CXFA_Node* pDataNode = GetBindData();
weili44f8faf2016-06-01 14:03:56 -0700833 if (!pDataNode)
834 return nullptr;
835 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400836 CXFA_NodeArray formNodes;
837 pDataNode->GetBindItems(formNodes);
838 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
839 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -0700840 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -0400841 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400842 pFieldWidgetData = pFormNode->GetWidgetData();
843 if (pFieldWidgetData) {
844 pFieldWidgetData->GetPictureContent(wsPicture,
845 XFA_VALUEPICTURE_DataBind);
846 }
weili44f8faf2016-06-01 14:03:56 -0700847 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400848 break;
weili44f8faf2016-06-01 14:03:56 -0700849 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400850 }
851 return pFieldWidgetData;
852 }
853 }
854 CXFA_Node* pGrandNode =
weili44f8faf2016-06-01 14:03:56 -0700855 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400856 CXFA_Node* pValueNode =
dsinclair070fcdf2016-06-22 22:04:54 -0700857 (pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
Dan Sinclair1770c022016-03-14 14:14:16 -0400858 ? pParentNode
weili44f8faf2016-06-01 14:03:56 -0700859 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400860 if (!pValueNode) {
dsinclair070fcdf2016-06-22 22:04:54 -0700861 pValueNode =
862 (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
863 ? pGrandNode
864 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400865 }
866 CXFA_Node* pParentOfValueNode =
weili44f8faf2016-06-01 14:03:56 -0700867 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400868 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
weili44f8faf2016-06-01 14:03:56 -0700869 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400870}
weili44f8faf2016-06-01 14:03:56 -0700871
Dan Sinclair1770c022016-03-14 14:14:16 -0400872FX_BOOL CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
873 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
dsinclair56a8b192016-06-21 14:15:25 -0700874 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
dsinclair43854a52016-04-27 12:26:00 -0700875 ASSERT(pTopSubform);
Dan Sinclair1770c022016-03-14 14:14:16 -0400876 CXFA_Node* pLocaleNode = this;
877 FX_BOOL bLocale = FALSE;
878 do {
879 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, FALSE);
880 if (!bLocale) {
881 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
882 }
883 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
weili44f8faf2016-06-01 14:03:56 -0700884 if (bLocale)
885 return TRUE;
Dan Sinclair1770c022016-03-14 14:14:16 -0400886 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
887 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
weili44f8faf2016-06-01 14:03:56 -0700888 if (!wsLocaleName.IsEmpty())
889 return TRUE;
890 if (pTopSubform &&
891 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, FALSE)) {
892 return TRUE;
Dan Sinclair1770c022016-03-14 14:14:16 -0400893 }
894 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
895 if (pLocale) {
896 wsLocaleName = pLocale->GetName();
weili44f8faf2016-06-01 14:03:56 -0700897 return TRUE;
Dan Sinclair1770c022016-03-14 14:14:16 -0400898 }
weili44f8faf2016-06-01 14:03:56 -0700899 return FALSE;
Dan Sinclair1770c022016-03-14 14:14:16 -0400900}
weili44f8faf2016-06-01 14:03:56 -0700901
Dan Sinclair1770c022016-03-14 14:14:16 -0400902XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
dsinclair56a8b192016-06-21 14:15:25 -0700903 CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
Dan Sinclair1770c022016-03-14 14:14:16 -0400904 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
905 if (pKeep) {
906 XFA_ATTRIBUTEENUM eIntact;
907 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, FALSE)) {
908 if (eIntact == XFA_ATTRIBUTEENUM_None &&
909 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
910 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
dsinclairc5a8f212016-06-20 11:11:12 -0700911 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
912 XFA_ObjectType::ContainerNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400913 if (pPreviewRow &&
914 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
915 XFA_ATTRIBUTEENUM_Row) {
916 XFA_ATTRIBUTEENUM eValue;
weili44f8faf2016-06-01 14:03:56 -0700917 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, FALSE) &&
918 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
919 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
920 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400921 }
weili44f8faf2016-06-01 14:03:56 -0700922 CXFA_Node* pNode =
dsinclair56a8b192016-06-21 14:15:25 -0700923 pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
weili44f8faf2016-06-01 14:03:56 -0700924 if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, FALSE) &&
925 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
926 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
927 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400928 }
929 }
930 }
931 return eIntact;
932 }
933 }
dsinclair41cb62e2016-06-23 09:20:32 -0700934 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700935 case XFA_Element::Subform:
Dan Sinclair1770c022016-03-14 14:14:16 -0400936 switch (eLayoutType) {
937 case XFA_ATTRIBUTEENUM_Position:
938 case XFA_ATTRIBUTEENUM_Row:
939 return XFA_ATTRIBUTEENUM_ContentArea;
940 case XFA_ATTRIBUTEENUM_Tb:
941 case XFA_ATTRIBUTEENUM_Table:
942 case XFA_ATTRIBUTEENUM_Lr_tb:
943 case XFA_ATTRIBUTEENUM_Rl_tb:
944 return XFA_ATTRIBUTEENUM_None;
945 default:
946 break;
947 }
948 break;
dsinclair56a8b192016-06-21 14:15:25 -0700949 case XFA_Element::Field: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400950 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700951 if (!pParentNode ||
952 pParentNode->GetElementType() == XFA_Element::PageArea)
Dan Sinclair1770c022016-03-14 14:14:16 -0400953 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400954 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
955 XFA_ATTRIBUTEENUM eParLayout =
956 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
957 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
958 eParLayout == XFA_ATTRIBUTEENUM_Row ||
959 eParLayout == XFA_ATTRIBUTEENUM_Table) {
960 return XFA_ATTRIBUTEENUM_None;
961 }
962 XFA_VERSION version = m_pDocument->GetCurVersionMode();
963 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
964 CXFA_Measurement measureH;
weili44f8faf2016-06-01 14:03:56 -0700965 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, FALSE))
Dan Sinclair1770c022016-03-14 14:14:16 -0400966 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400967 }
968 return XFA_ATTRIBUTEENUM_None;
969 }
970 return XFA_ATTRIBUTEENUM_ContentArea;
971 }
dsinclair56a8b192016-06-21 14:15:25 -0700972 case XFA_Element::Draw:
Dan Sinclair1770c022016-03-14 14:14:16 -0400973 return XFA_ATTRIBUTEENUM_ContentArea;
974 default:
975 break;
976 }
977 return XFA_ATTRIBUTEENUM_None;
978}
weili44f8faf2016-06-01 14:03:56 -0700979
Dan Sinclair1770c022016-03-14 14:14:16 -0400980CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
weili44f8faf2016-06-01 14:03:56 -0700981 if (m_ePacket == XFA_XDPPACKET_Datasets)
Dan Sinclair1770c022016-03-14 14:14:16 -0400982 return m_pAuxNode;
weili44f8faf2016-06-01 14:03:56 -0700983 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400984}
weili44f8faf2016-06-01 14:03:56 -0700985
Dan Sinclair1770c022016-03-14 14:14:16 -0400986void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
dsinclair43854a52016-04-27 12:26:00 -0700987 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
Dan Sinclair1770c022016-03-14 14:14:16 -0400988 m_pAuxNode = pDataDescriptionNode;
989}
weili44f8faf2016-06-01 14:03:56 -0700990
Dan Sinclair1770c022016-03-14 14:14:16 -0400991void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
992 int32_t iLength = pArguments->GetLength();
993 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -0700994 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNode");
Dan Sinclair1770c022016-03-14 14:14:16 -0400995 return;
996 }
tsepez6fe7d212016-04-06 10:51:14 -0700997 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -0700998 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclairdf4bc592016-03-31 20:34:43 -0700999 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001000 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001001 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001002 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001003 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001004 refNode = ToNode(pScriptContext->GetThisObject());
tsepez736f28a2016-03-25 14:19:51 -07001005 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001006 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1007 XFA_RESOLVENODE_Siblings;
1008 XFA_RESOLVENODE_RS resoveNodeRS;
tsepezfc58ad12016-04-05 12:22:15 -07001009 int32_t iRet = pScriptContext->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001010 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
dsinclairf27aeec2016-06-07 19:36:18 -07001011 if (iRet < 1) {
1012 pArguments->GetReturnValue()->SetNull();
1013 return;
1014 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001015 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1016 CXFA_Object* pNode = resoveNodeRS.nodes[0];
dsinclairf27aeec2016-06-07 19:36:18 -07001017 pArguments->GetReturnValue()->Assign(
1018 pScriptContext->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001019 } else {
1020 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
1021 resoveNodeRS.pScriptAttribute;
1022 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
dsinclair86fad992016-05-31 11:34:04 -07001023 std::unique_ptr<CFXJSE_Value> pValue(
1024 new CFXJSE_Value(pScriptContext->GetRuntime()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001025 (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))(
dsinclair86fad992016-05-31 11:34:04 -07001026 pValue.get(), FALSE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
dsinclairf27aeec2016-06-07 19:36:18 -07001027 pArguments->GetReturnValue()->Assign(pValue.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001028 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001029 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001030 }
1031 }
1032}
weili44f8faf2016-06-01 14:03:56 -07001033
Dan Sinclair1770c022016-03-14 14:14:16 -04001034void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
1035 int32_t iLength = pArguments->GetLength();
1036 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001037 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04001038 return;
1039 }
tsepez6fe7d212016-04-06 10:51:14 -07001040 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001041 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclair12a6b0c2016-05-26 11:14:08 -07001042 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001043 if (!pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04001044 return;
tsepez736f28a2016-03-25 14:19:51 -07001045 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001046 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1047 XFA_RESOLVENODE_Siblings;
1048 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001049 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001050 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
dsinclair12a6b0c2016-05-26 11:14:08 -07001051 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001052}
weili44f8faf2016-06-01 14:03:56 -07001053
dsinclair12a6b0c2016-05-26 11:14:08 -07001054void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001055 CFX_WideString wsExpression,
tsepez736f28a2016-03-25 14:19:51 -07001056 uint32_t dwFlag,
Dan Sinclair1770c022016-03-14 14:14:16 -04001057 CXFA_Node* refNode) {
dsinclairdf4bc592016-03-31 20:34:43 -07001058 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001059 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001060 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001061 XFA_RESOLVENODE_RS resoveNodeRS;
weili44f8faf2016-06-01 14:03:56 -07001062 if (!refNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04001063 refNode = this;
tsepez4c3debb2016-04-08 12:20:38 -07001064 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
tsepezfc58ad12016-04-05 12:22:15 -07001065 resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001066 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
1067 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
1068 for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) {
1069 if (resoveNodeRS.nodes[i]->IsNode())
1070 pNodeList->Append(resoveNodeRS.nodes[i]->AsNode());
1071 }
1072 } else {
dsinclair12a6b0c2016-05-26 11:14:08 -07001073 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
1074 if (resoveNodeRS.GetAttributeResult(valueArray) > 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001075 CXFA_ObjArray objectArray;
dsinclair12a6b0c2016-05-26 11:14:08 -07001076 valueArray.GetAttributeObject(objectArray);
Dan Sinclair1770c022016-03-14 14:14:16 -04001077 for (int32_t i = 0; i < objectArray.GetSize(); i++) {
1078 if (objectArray[i]->IsNode())
1079 pNodeList->Append(objectArray[i]->AsNode());
1080 }
1081 }
1082 }
dsinclairf27aeec2016-06-07 19:36:18 -07001083 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001084}
weili44f8faf2016-06-01 14:03:56 -07001085
dsinclair12a6b0c2016-05-26 11:14:08 -07001086void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001087 FX_BOOL bSetting,
1088 XFA_ATTRIBUTE eAttribute) {
1089 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001090 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001091 } else {
tsepez736f28a2016-03-25 14:19:51 -07001092 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
Dan Sinclair1770c022016-03-14 14:14:16 -04001093 CFX_WideString wsName;
1094 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
1095 CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]");
dsinclair12a6b0c2016-05-26 11:14:08 -07001096 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001097 }
1098}
weili44f8faf2016-06-01 14:03:56 -07001099
dsinclair12a6b0c2016-05-26 11:14:08 -07001100void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001101 FX_BOOL bSetting,
1102 XFA_ATTRIBUTE eAttribute) {
dsinclairdf4bc592016-03-31 20:34:43 -07001103 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001104 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001105 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001106 if (bSetting) {
1107 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider();
dsinclair43854a52016-04-27 12:26:00 -07001108 ASSERT(pAppProvider);
Dan Sinclair1770c022016-03-14 14:14:16 -04001109 CFX_WideString wsMessage;
1110 pAppProvider->LoadString(XFA_IDS_Unable_TO_SET, wsMessage);
tsepez28f97ff2016-04-04 16:41:35 -07001111 FXJSE_ThrowMessage(
tsepezbd9748d2016-04-13 21:40:19 -07001112 FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001113 } else {
1114 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
dsinclairf27aeec2016-06-07 19:36:18 -07001115 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001116 }
1117}
weili44f8faf2016-06-01 14:03:56 -07001118
dsinclair12a6b0c2016-05-26 11:14:08 -07001119void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001120 FX_BOOL bSetting,
1121 XFA_ATTRIBUTE eAttribute) {
1122 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001123 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001124 } else {
tsepez736f28a2016-03-25 14:19:51 -07001125 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
dsinclair017052a2016-06-28 07:43:51 -07001126 CFX_WideString wsExpression =
1127 FX_WSTRC(L"#") + GetClassName() + FX_WSTRC(L"[*]");
dsinclair12a6b0c2016-05-26 11:14:08 -07001128 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001129 }
1130}
weili44f8faf2016-06-01 14:03:56 -07001131
dsinclair12a6b0c2016-05-26 11:14:08 -07001132void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001133 FX_BOOL bSetting,
1134 XFA_ATTRIBUTE eAttribute) {
1135 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001136 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001137 } else {
1138 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
1139 if (pParent) {
dsinclairf27aeec2016-06-07 19:36:18 -07001140 pValue->Assign(
1141 m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001142 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001143 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001144 }
1145 }
1146}
weili44f8faf2016-06-01 14:03:56 -07001147
dsinclair12a6b0c2016-05-26 11:14:08 -07001148void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001149 FX_BOOL bSetting,
1150 XFA_ATTRIBUTE eAttribute) {
weili44f8faf2016-06-01 14:03:56 -07001151 if (bSetting)
dsinclair2235b7b2016-06-02 07:42:25 -07001152 ThrowException(XFA_IDS_INVAlID_PROP_SET);
weili44f8faf2016-06-01 14:03:56 -07001153 else
dsinclairf27aeec2016-06-07 19:36:18 -07001154 pValue->SetInteger(GetNodeSameNameIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001155}
weili44f8faf2016-06-01 14:03:56 -07001156
dsinclair12a6b0c2016-05-26 11:14:08 -07001157void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001158 FX_BOOL bSetting,
1159 XFA_ATTRIBUTE eAttribute) {
weili44f8faf2016-06-01 14:03:56 -07001160 if (bSetting)
dsinclair2235b7b2016-06-02 07:42:25 -07001161 ThrowException(XFA_IDS_INVAlID_PROP_SET);
weili44f8faf2016-06-01 14:03:56 -07001162 else
dsinclairf27aeec2016-06-07 19:36:18 -07001163 pValue->SetInteger(GetNodeSameClassIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001164}
weili44f8faf2016-06-01 14:03:56 -07001165
dsinclair12a6b0c2016-05-26 11:14:08 -07001166void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001167 FX_BOOL bSetting,
1168 XFA_ATTRIBUTE eAttribute) {
1169 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001170 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001171 } else {
1172 CFX_WideString wsSOMExpression;
1173 GetSOMExpression(wsSOMExpression);
dsinclairf27aeec2016-06-07 19:36:18 -07001174 pValue->SetString(FX_UTF8Encode(wsSOMExpression).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001175 }
1176}
weili44f8faf2016-06-01 14:03:56 -07001177
Dan Sinclair1770c022016-03-14 14:14:16 -04001178void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
1179 int32_t iLength = pArguments->GetLength();
1180 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001181 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"applyXSL");
Dan Sinclair1770c022016-03-14 14:14:16 -04001182 return;
1183 }
tsepez6fe7d212016-04-06 10:51:14 -07001184 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001185 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili60607c32016-05-26 11:53:12 -07001186 // TODO(weili): check whether we need to implement this, pdfium:501.
1187 // For now, just put the variables here to avoid unused variable warning.
1188 (void)wsExpression;
Dan Sinclair1770c022016-03-14 14:14:16 -04001189}
weili60607c32016-05-26 11:53:12 -07001190
Dan Sinclair1770c022016-03-14 14:14:16 -04001191void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
1192 int32_t iLength = pArguments->GetLength();
1193 if (iLength < 1 || iLength > 3) {
dsinclair2235b7b2016-06-02 07:42:25 -07001194 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"assignNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04001195 return;
1196 }
1197 CFX_WideString wsExpression;
1198 CFX_WideString wsValue;
1199 int32_t iAction = 0;
weili44f8faf2016-06-01 14:03:56 -07001200 wsExpression =
1201 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001202 if (iLength >= 2) {
weili60607c32016-05-26 11:53:12 -07001203 wsValue =
1204 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001205 }
weili60607c32016-05-26 11:53:12 -07001206 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001207 iAction = pArguments->GetInt32(2);
weili60607c32016-05-26 11:53:12 -07001208 // TODO(weili): check whether we need to implement this, pdfium:501.
1209 // For now, just put the variables here to avoid unused variable warning.
1210 (void)wsExpression;
1211 (void)wsValue;
1212 (void)iAction;
Dan Sinclair1770c022016-03-14 14:14:16 -04001213}
weili60607c32016-05-26 11:53:12 -07001214
Dan Sinclair1770c022016-03-14 14:14:16 -04001215void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
1216 int32_t iLength = pArguments->GetLength();
1217 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001218 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clone");
Dan Sinclair1770c022016-03-14 14:14:16 -04001219 return;
1220 }
weili44f8faf2016-06-01 14:03:56 -07001221 bool bClone = !!pArguments->GetInt32(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001222 CXFA_Node* pCloneNode = Clone(bClone);
dsinclairf27aeec2016-06-07 19:36:18 -07001223 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001224 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
1225}
weili44f8faf2016-06-01 14:03:56 -07001226
Dan Sinclair1770c022016-03-14 14:14:16 -04001227void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
1228 int32_t iLength = pArguments->GetLength();
1229 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001230 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001231 return;
1232 }
tsepez6fe7d212016-04-06 10:51:14 -07001233 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001234 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001235 CFX_WideString wsValue;
tsepez4c3debb2016-04-08 12:20:38 -07001236 GetAttribute(wsExpression.AsStringC(), wsValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07001237 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001238 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001239 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001240}
weili44f8faf2016-06-01 14:03:56 -07001241
Dan Sinclair1770c022016-03-14 14:14:16 -04001242void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
1243 int32_t iLength = pArguments->GetLength();
1244 if (iLength < 1 || iLength > 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07001245 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001246 return;
1247 }
1248 CFX_WideString wsExpression;
1249 int32_t iValue = 0;
weili44f8faf2016-06-01 14:03:56 -07001250 wsExpression =
1251 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1252 if (iLength >= 2)
Dan Sinclair1770c022016-03-14 14:14:16 -04001253 iValue = pArguments->GetInt32(1);
dsinclair6e124782016-06-23 12:14:55 -07001254 CXFA_Node* pNode =
1255 GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
dsinclairf27aeec2016-06-07 19:36:18 -07001256 pArguments->GetReturnValue()->Assign(
1257 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001258}
weili65be4b12016-05-25 15:47:43 -07001259
Dan Sinclair1770c022016-03-14 14:14:16 -04001260void CXFA_Node::Script_NodeClass_IsPropertySpecified(
1261 CFXJSE_Arguments* pArguments) {
1262 int32_t iLength = pArguments->GetLength();
1263 if (iLength < 1 || iLength > 3) {
dsinclair2235b7b2016-06-02 07:42:25 -07001264 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isPropertySpecified");
Dan Sinclair1770c022016-03-14 14:14:16 -04001265 return;
1266 }
1267 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001268 bool bParent = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001269 int32_t iIndex = 0;
weili44f8faf2016-06-01 14:03:56 -07001270 wsExpression =
1271 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili65be4b12016-05-25 15:47:43 -07001272 if (iLength >= 2)
weili44f8faf2016-06-01 14:03:56 -07001273 bParent = !!pArguments->GetInt32(1);
weili65be4b12016-05-25 15:47:43 -07001274 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001275 iIndex = pArguments->GetInt32(2);
Dan Sinclair1770c022016-03-14 14:14:16 -04001276 FX_BOOL bHas = FALSE;
1277 const XFA_ATTRIBUTEINFO* pAttributeInfo =
tsepez4c3debb2016-04-08 12:20:38 -07001278 XFA_GetAttributeByName(wsExpression.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001279 CFX_WideString wsValue;
weili65be4b12016-05-25 15:47:43 -07001280 if (pAttributeInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04001281 bHas = HasAttribute(pAttributeInfo->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04001282 if (!bHas) {
dsinclair6e124782016-06-23 12:14:55 -07001283 XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
1284 bHas = !!GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001285 if (!bHas && bParent && m_pParent) {
1286 // Also check on the parent.
1287 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
1288 if (!bHas)
dsinclair6e124782016-06-23 12:14:55 -07001289 bHas = !!m_pParent->GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001290 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001291 }
dsinclair12a6b0c2016-05-26 11:14:08 -07001292 CFXJSE_Value* pValue = pArguments->GetReturnValue();
1293 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001294 pValue->SetBoolean(bHas);
Dan Sinclair1770c022016-03-14 14:14:16 -04001295}
weili65be4b12016-05-25 15:47:43 -07001296
Dan Sinclair1770c022016-03-14 14:14:16 -04001297void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
1298 int32_t iLength = pArguments->GetLength();
1299 if (iLength < 1 || iLength > 3) {
dsinclair2235b7b2016-06-02 07:42:25 -07001300 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001301 return;
1302 }
1303 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001304 bool bIgnoreRoot = true;
1305 bool bOverwrite = 0;
1306 wsExpression =
1307 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1308 if (wsExpression.IsEmpty())
Tom Sepezd3743ea2016-05-16 15:56:53 -07001309 return;
weili44f8faf2016-06-01 14:03:56 -07001310 if (iLength >= 2)
1311 bIgnoreRoot = !!pArguments->GetInt32(1);
1312 if (iLength >= 3)
1313 bOverwrite = !!pArguments->GetInt32(2);
dsinclaira1b07722016-07-11 08:20:58 -07001314 std::unique_ptr<CXFA_SimpleParser> pParser(
1315 new CXFA_SimpleParser(m_pDocument, false));
weili44f8faf2016-06-01 14:03:56 -07001316 if (!pParser)
Dan Sinclair1770c022016-03-14 14:14:16 -04001317 return;
weili44f8faf2016-06-01 14:03:56 -07001318 CFDE_XMLNode* pXMLNode = nullptr;
1319 int32_t iParserStatus =
1320 pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
1321 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
1322 return;
dsinclairae95f762016-03-29 16:58:29 -07001323 if (bIgnoreRoot &&
1324 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
1325 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
weili44f8faf2016-06-01 14:03:56 -07001326 bIgnoreRoot = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001327 }
1328 CXFA_Node* pFakeRoot = Clone(FALSE);
1329 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
1330 if (!wsContentType.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07001331 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
1332 CFX_WideString(wsContentType));
Dan Sinclair1770c022016-03-14 14:14:16 -04001333 }
dsinclairae95f762016-03-29 16:58:29 -07001334 CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001335 if (!pFakeXMLRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001336 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
weili44f8faf2016-06-01 14:03:56 -07001337 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(FALSE) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001338 }
dsinclair017052a2016-06-28 07:43:51 -07001339 if (!pFakeXMLRoot)
1340 pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName()));
1341
Dan Sinclair1770c022016-03-14 14:14:16 -04001342 if (bIgnoreRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001343 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001344 while (pXMLChild) {
dsinclairae95f762016-03-29 16:58:29 -07001345 CFDE_XMLNode* pXMLSibling =
1346 pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001347 pXMLNode->RemoveChildNode(pXMLChild);
1348 pFakeXMLRoot->InsertChildNode(pXMLChild);
1349 pXMLChild = pXMLSibling;
1350 }
1351 } else {
dsinclairae95f762016-03-29 16:58:29 -07001352 CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001353 if (pXMLParent) {
1354 pXMLParent->RemoveChildNode(pXMLNode);
1355 }
1356 pFakeXMLRoot->InsertChildNode(pXMLNode);
1357 }
1358 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot);
1359 pFakeRoot = pParser->GetRootNode();
1360 if (pFakeRoot) {
1361 if (bOverwrite) {
1362 CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1363 CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1364 int32_t index = 0;
1365 while (pNewChild) {
1366 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1367 pFakeRoot->RemoveChild(pNewChild);
1368 InsertChild(index++, pNewChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001369 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001370 pNewChild = pItem;
1371 }
1372 while (pChild) {
1373 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1374 RemoveChild(pChild);
1375 pFakeRoot->InsertChild(pChild);
1376 pChild = pItem;
1377 }
1378 if (GetPacketID() == XFA_XDPPACKET_Form &&
dsinclair070fcdf2016-06-22 22:04:54 -07001379 GetElementType() == XFA_Element::ExData) {
dsinclairae95f762016-03-29 16:58:29 -07001380 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001381 SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001382 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
weili44f8faf2016-06-01 14:03:56 -07001383 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001384 pFakeXMLRoot = pTempXMLNode;
1385 } else {
weili44f8faf2016-06-01 14:03:56 -07001386 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001387 }
1388 }
1389 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, TRUE);
1390 } else {
1391 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1392 while (pChild) {
1393 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1394 pFakeRoot->RemoveChild(pChild);
1395 InsertChild(pChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001396 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001397 pChild = pItem;
1398 }
1399 }
1400 if (pFakeXMLRoot) {
1401 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001402 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001403 }
dsinclairc5a8f212016-06-20 11:11:12 -07001404 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001405 } else {
Tom Sepezd3743ea2016-05-16 15:56:53 -07001406 if (pFakeXMLRoot) {
1407 pFakeXMLRoot->Release();
weili44f8faf2016-06-01 14:03:56 -07001408 pFakeXMLRoot = nullptr;
Tom Sepezd3743ea2016-05-16 15:56:53 -07001409 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001410 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001411}
weili44f8faf2016-06-01 14:03:56 -07001412
Dan Sinclair1770c022016-03-14 14:14:16 -04001413void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
weili44f8faf2016-06-01 14:03:56 -07001414 // TODO(weili): Check whether we need to implement this, pdfium:501.
Dan Sinclair1770c022016-03-14 14:14:16 -04001415}
1416
1417void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1418 int32_t iLength = pArguments->GetLength();
1419 if (iLength < 0 || iLength > 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001420 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001421 return;
1422 }
weili44f8faf2016-06-01 14:03:56 -07001423 bool bPrettyMode = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001424 if (iLength == 1) {
weili65be4b12016-05-25 15:47:43 -07001425 if (pArguments->GetUTF8String(0) != "pretty") {
dsinclair2235b7b2016-06-02 07:42:25 -07001426 ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
Dan Sinclair1770c022016-03-14 14:14:16 -04001427 return;
1428 }
weili44f8faf2016-06-01 14:03:56 -07001429 bPrettyMode = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001430 }
1431 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
weili65be4b12016-05-25 15:47:43 -07001432 if (GetPacketID() == XFA_XDPPACKET_Form ||
1433 GetPacketID() == XFA_XDPPACKET_Datasets) {
1434 CFDE_XMLNode* pElement = nullptr;
1435 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1436 pElement = GetXMLMappingNode();
1437 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
dsinclairf27aeec2016-06-07 19:36:18 -07001438 pArguments->GetReturnValue()->SetString(bsXMLHeader);
weili65be4b12016-05-25 15:47:43 -07001439 return;
1440 }
1441 XFA_DataExporter_DealWithDataGroupNode(this);
1442 }
weili44f8faf2016-06-01 14:03:56 -07001443 std::unique_ptr<IFX_MemoryStream, ReleaseDeleter<IFX_MemoryStream>>
1444 pMemoryStream(FX_CreateMemoryStream(TRUE));
1445 std::unique_ptr<IFX_Stream, ReleaseDeleter<IFX_Stream>> pStream(
1446 IFX_Stream::CreateStream(
tsepezad2441e2016-10-24 10:19:11 -07001447 static_cast<IFX_SeekableWriteStream*>(pMemoryStream.get()),
weili44f8faf2016-06-01 14:03:56 -07001448 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write |
1449 FX_STREAMACCESS_Append));
Dan Sinclair1770c022016-03-14 14:14:16 -04001450 if (!pStream) {
dsinclairf27aeec2016-06-07 19:36:18 -07001451 pArguments->GetReturnValue()->SetString(bsXMLHeader);
Dan Sinclair1770c022016-03-14 14:14:16 -04001452 return;
1453 }
1454 pStream->SetCodePage(FX_CODEPAGE_UTF8);
dsinclair179bebb2016-04-05 11:02:18 -07001455 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
weili65be4b12016-05-25 15:47:43 -07001456 if (GetPacketID() == XFA_XDPPACKET_Form)
weili44f8faf2016-06-01 14:03:56 -07001457 XFA_DataExporter_RegenerateFormFile(this, pStream.get(), nullptr, TRUE);
weili65be4b12016-05-25 15:47:43 -07001458 else
1459 pElement->SaveXMLNode(pStream.get());
1460 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1461 // For now, just put it here to avoid unused variable warning.
1462 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001463 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001464 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001465 return;
1466 }
dsinclairf27aeec2016-06-07 19:36:18 -07001467 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001468}
1469
1470void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1471 int32_t iLength = pArguments->GetLength();
1472 if (iLength != 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07001473 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001474 return;
1475 }
tsepez6fe7d212016-04-06 10:51:14 -07001476 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001477 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001478 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001479 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001480 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001481}
weili60607c32016-05-26 11:53:12 -07001482
Dan Sinclair1770c022016-03-14 14:14:16 -04001483void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1484 int32_t iLength = pArguments->GetLength();
1485 if (iLength != 1 && iLength != 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07001486 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001487 return;
1488 }
weili60607c32016-05-26 11:53:12 -07001489 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001490 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001491 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1492 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001493 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001494 // TODO(weili): check whether we need to implement this, pdfium:501.
1495 // For now, just put the variables here to avoid unused variable warning.
1496 (void)pNode;
1497 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001498}
weili60607c32016-05-26 11:53:12 -07001499
dsinclair12a6b0c2016-05-26 11:14:08 -07001500void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001501 FX_BOOL bSetting,
1502 XFA_ATTRIBUTE eAttribute) {
1503 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001504 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001505 } else {
1506 CFX_WideString wsNameSpace;
1507 TryNamespace(wsNameSpace);
dsinclairf27aeec2016-06-07 19:36:18 -07001508 pValue->SetString(FX_UTF8Encode(wsNameSpace).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001509 }
1510}
weili44f8faf2016-06-01 14:03:56 -07001511
dsinclair12a6b0c2016-05-26 11:14:08 -07001512void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001513 FX_BOOL bSetting,
1514 XFA_ATTRIBUTE eAttribute) {
1515 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001516 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001517 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001518 pValue->Assign(
1519 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001520 }
1521}
weili44f8faf2016-06-01 14:03:56 -07001522
dsinclair12a6b0c2016-05-26 11:14:08 -07001523void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001524 FX_BOOL bSetting,
1525 XFA_ATTRIBUTE eAttribute) {
weili44f8faf2016-06-01 14:03:56 -07001526 if (bSetting)
dsinclair2235b7b2016-06-02 07:42:25 -07001527 ThrowException(XFA_IDS_INVAlID_PROP_SET);
weili44f8faf2016-06-01 14:03:56 -07001528 else
dsinclairf27aeec2016-06-07 19:36:18 -07001529 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001530}
weili44f8faf2016-06-01 14:03:56 -07001531
dsinclair12a6b0c2016-05-26 11:14:08 -07001532void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001533 FX_BOOL bSetting,
1534 XFA_ATTRIBUTE eAttribute) {
1535 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001536 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001537 } else {
dsinclair070fcdf2016-06-22 22:04:54 -07001538 if (GetElementType() == XFA_Element::Subform) {
dsinclairf27aeec2016-06-07 19:36:18 -07001539 pValue->SetBoolean(FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04001540 return;
1541 }
1542 CFX_WideString strValue;
dsinclairf27aeec2016-06-07 19:36:18 -07001543 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001544 }
1545}
weili44f8faf2016-06-01 14:03:56 -07001546
dsinclair12a6b0c2016-05-26 11:14:08 -07001547void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001548 FX_BOOL bSetting,
1549 XFA_ATTRIBUTE eAttribute) {
1550 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001551 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001552 } else {
1553 CXFA_NodeArray properts;
1554 int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty);
1555 if (iSize > 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07001556 pValue->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001557 m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0]));
1558 }
1559 }
1560}
weili44f8faf2016-06-01 14:03:56 -07001561
Dan Sinclair1770c022016-03-14 14:14:16 -04001562void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001563
Dan Sinclair1770c022016-03-14 14:14:16 -04001564void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1565 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001566 pArguments->GetReturnValue()->SetObject(
1567 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001568}
1569void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1570}
dsinclair5b36f0a2016-07-19 10:56:23 -07001571
Dan Sinclair1770c022016-03-14 14:14:16 -04001572void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1573 Script_Template_CreateNode(pArguments);
1574}
dsinclair5b36f0a2016-07-19 10:56:23 -07001575
Dan Sinclair1770c022016-03-14 14:14:16 -04001576void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1577 int32_t iLength = pArguments->GetLength();
1578 if (iLength < 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07001579 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001580 return;
1581 }
1582 CFX_WideString wsNameSpace;
1583 if (iLength >= 1) {
1584 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001585 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001586 }
1587 CFX_WideString wsNodeNameSpace;
1588 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001589 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001590 if (pValue)
1591 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001592}
dsinclair5b36f0a2016-07-19 10:56:23 -07001593
dsinclair12a6b0c2016-05-26 11:14:08 -07001594void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001595 FX_BOOL bSetting,
1596 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001597
dsinclair12a6b0c2016-05-26 11:14:08 -07001598void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001599 FX_BOOL bSetting,
1600 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001601
dsinclair12a6b0c2016-05-26 11:14:08 -07001602void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001603 FX_BOOL bSetting,
1604 XFA_ATTRIBUTE eAttribute) {
1605 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001606 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001607 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001608 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001609 }
1610}
dsinclair5b36f0a2016-07-19 10:56:23 -07001611
dsinclair12a6b0c2016-05-26 11:14:08 -07001612void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001613 FX_BOOL bSetting,
1614 XFA_ATTRIBUTE eAttribute) {
1615 if (!bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001616 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001617 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001618 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001619 }
1620}
dsinclair5b36f0a2016-07-19 10:56:23 -07001621
dsinclair12a6b0c2016-05-26 11:14:08 -07001622void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001623 FX_BOOL bSetting,
1624 XFA_ATTRIBUTE eAttribute) {
1625 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001626 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001627 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001628 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001629 }
1630}
dsinclair5b36f0a2016-07-19 10:56:23 -07001631
dsinclair12a6b0c2016-05-26 11:14:08 -07001632void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001633 FX_BOOL bSetting,
1634 XFA_ATTRIBUTE eAttribute) {
1635 if (!bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001636 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001637 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001638 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001639 }
1640}
thestigb1a59592016-04-14 18:29:56 -07001641
Dan Sinclair1770c022016-03-14 14:14:16 -04001642void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001643 XFA_ATTRIBUTE eAttribute,
Dan Sinclair1770c022016-03-14 14:14:16 -04001644 FX_BOOL bScriptModify) {
1645 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001646 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001647 return;
thestigb1a59592016-04-14 18:29:56 -07001648
dsinclaira1b07722016-07-11 08:20:58 -07001649 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001650 if (!pNotify)
1651 return;
1652
1653 uint32_t dwPacket = GetPacketID();
1654 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1655 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001656 return;
1657 }
thestigb1a59592016-04-14 18:29:56 -07001658
1659 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001660 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001661 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001662 bNeedFindContainer = true;
1663 pNotify->OnValueChanged(this, eAttribute, this,
1664 GetNodeItem(XFA_NODEITEM_Parent));
1665 break;
dsinclair56a8b192016-06-21 14:15:25 -07001666 case XFA_Element::Font:
1667 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001668 bNeedFindContainer = true;
1669 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001670 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001671 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1672 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1673 } else {
1674 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1675 }
1676 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001677 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001678 bNeedFindContainer = true;
1679 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001680 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001681 if (pParentNode->IsContainerNode()) {
1682 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001683 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001684 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1685 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1686 } else {
1687 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001688 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001689 pNotify->OnValueChanged(this, eAttribute, pNode,
1690 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001691 }
thestigb1a59592016-04-14 18:29:56 -07001692 }
1693 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001694 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001695 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001696 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001697 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1698 eUIType == XFA_Element::NumericEdit ||
1699 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001700 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001701 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001702 pNotify->OnValueChanged(this, eAttribute, pUINode,
1703 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001704 }
thestigb1a59592016-04-14 18:29:56 -07001705 }
1706 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001707 case XFA_Element::Button:
1708 case XFA_Element::Barcode:
1709 case XFA_Element::ChoiceList:
1710 case XFA_Element::DateTimeEdit:
1711 case XFA_Element::NumericEdit:
1712 case XFA_Element::PasswordEdit:
1713 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001714 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1715 if (pUINode) {
1716 pNotify->OnValueChanged(this, eAttribute, pUINode,
1717 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1718 }
1719 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001720 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001721 bNeedFindContainer = true;
1722 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1723 if (pUINode) {
1724 pNotify->OnValueChanged(this, eAttribute, pUINode,
1725 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1726 }
1727 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001728 case XFA_Element::Keep:
1729 case XFA_Element::Bookend:
1730 case XFA_Element::Break:
1731 case XFA_Element::BreakAfter:
1732 case XFA_Element::BreakBefore:
1733 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001734 bNeedFindContainer = true;
1735 break;
dsinclair56a8b192016-06-21 14:15:25 -07001736 case XFA_Element::Area:
1737 case XFA_Element::Draw:
1738 case XFA_Element::ExclGroup:
1739 case XFA_Element::Field:
1740 case XFA_Element::Subform:
1741 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001742 pLayoutPro->AddChangedContainer(this);
1743 pNotify->OnValueChanged(this, eAttribute, this, this);
1744 break;
dsinclair56a8b192016-06-21 14:15:25 -07001745 case XFA_Element::Sharptext:
1746 case XFA_Element::Sharpxml:
1747 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001748 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1749 if (!pTextNode) {
1750 return;
1751 }
1752 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1753 if (!pValueNode) {
1754 return;
1755 }
dsinclair41cb62e2016-06-23 09:20:32 -07001756 XFA_Element eType = pValueNode->GetElementType();
1757 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001758 bNeedFindContainer = true;
1759 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1760 if (pNode && pNode->IsContainerNode()) {
1761 if (bScriptModify) {
1762 pValueNode = pNode;
1763 }
1764 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1765 } else {
1766 pNotify->OnValueChanged(this, eAttribute, pNode,
1767 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001768 }
thestigb1a59592016-04-14 18:29:56 -07001769 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001770 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001771 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1772 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001773 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001774 }
1775 }
thestigb1a59592016-04-14 18:29:56 -07001776 }
1777 } break;
1778 default:
1779 break;
1780 }
1781 if (bNeedFindContainer) {
1782 CXFA_Node* pParent = this;
1783 while (pParent) {
1784 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001785 break;
thestigb1a59592016-04-14 18:29:56 -07001786
1787 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001788 }
thestigb1a59592016-04-14 18:29:56 -07001789 if (pParent) {
1790 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001791 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001792 }
1793}
thestigb1a59592016-04-14 18:29:56 -07001794
dsinclair12a6b0c2016-05-26 11:14:08 -07001795void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001796 FX_BOOL bSetting,
1797 XFA_ATTRIBUTE eAttribute) {
1798 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001799 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001800 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001801 if (eAttribute == XFA_ATTRIBUTE_Use &&
1802 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001803 CXFA_Node* pTemplateNode =
1804 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1805 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001806 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1807 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001808
1809 CFX_WideString wsID;
1810 CFX_WideString wsSOM;
1811 if (!wsValue.IsEmpty()) {
1812 if (wsValue[0] == '#') {
1813 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001814 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001815 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001816 }
1817 }
weili44f8faf2016-06-01 14:03:56 -07001818 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001819 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001820 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001821 XFA_RESOLVENODE_Attributes |
1822 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1823 XFA_RESOLVENODE_Siblings;
1824 XFA_RESOLVENODE_RS resoveNodeRS;
1825 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001826 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001827 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) {
1828 pProtoNode = resoveNodeRS.nodes[0]->AsNode();
1829 }
1830 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001831 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001832 }
1833 if (pProtoNode) {
1834 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1835 while (pHeadChild) {
1836 CXFA_Node* pSibling =
1837 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1838 RemoveChild(pHeadChild);
1839 pHeadChild = pSibling;
1840 }
1841 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(TRUE);
1842 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1843 while (pHeadChild) {
1844 CXFA_Node* pSibling =
1845 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1846 pProtoForm->RemoveChild(pHeadChild);
1847 InsertChild(pHeadChild);
1848 pHeadChild = pSibling;
1849 }
1850 m_pDocument->RemovePurgeNode(pProtoForm);
1851 delete pProtoForm;
1852 }
1853 }
1854 } else {
1855 CFX_WideString wsValue;
1856 GetAttribute(eAttribute, wsValue);
dsinclairf27aeec2016-06-07 19:36:18 -07001857 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07001858 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001859 }
1860}
dsinclair5b36f0a2016-07-19 10:56:23 -07001861
dsinclair12a6b0c2016-05-26 11:14:08 -07001862void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001863 FX_BOOL bSetting,
1864 XFA_ATTRIBUTE eAttribute) {
1865 if (!bSetting) {
1866 CFX_WideString wsValue;
1867 GetAttribute(eAttribute, wsValue);
dsinclairf27aeec2016-06-07 19:36:18 -07001868 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07001869 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001870 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001871 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001872 }
1873}
dsinclair5b36f0a2016-07-19 10:56:23 -07001874
Dan Sinclair1770c022016-03-14 14:14:16 -04001875void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1876 int32_t argc = pArguments->GetLength();
1877 if ((argc == 0) || (argc == 1)) {
dsinclairf27aeec2016-06-07 19:36:18 -07001878 pArguments->GetReturnValue()->SetBoolean(FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04001879 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001880 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001881 }
1882}
dsinclair5b36f0a2016-07-19 10:56:23 -07001883
Dan Sinclair1770c022016-03-14 14:14:16 -04001884void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
1885 int32_t argc = pArguments->GetLength();
1886 if (argc == 0) {
1887 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07001888 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001889 }
1890}
dsinclair5b36f0a2016-07-19 10:56:23 -07001891
dsinclair12a6b0c2016-05-26 11:14:08 -07001892void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001893 FX_BOOL bSetting,
1894 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001895
dsinclair12a6b0c2016-05-26 11:14:08 -07001896void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001897 FX_BOOL bSetting,
1898 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001899
dsinclair12a6b0c2016-05-26 11:14:08 -07001900void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001901 FX_BOOL bSetting,
1902 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001903
dsinclair12a6b0c2016-05-26 11:14:08 -07001904void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001905 FX_BOOL bSetting,
1906 XFA_SOM_MESSAGETYPE iMessageType) {
1907 CXFA_WidgetData* pWidgetData = GetWidgetData();
1908 if (!pWidgetData) {
1909 return;
1910 }
1911 FX_BOOL bNew = FALSE;
1912 CXFA_Validate validate = pWidgetData->GetValidate();
1913 if (!validate) {
1914 validate = pWidgetData->GetValidate(TRUE);
1915 bNew = TRUE;
1916 }
1917 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001918 switch (iMessageType) {
1919 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001920 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001921 break;
1922 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001923 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001924 break;
1925 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001926 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001927 break;
1928 default:
1929 break;
1930 }
1931 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001932 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001933 if (!pNotify) {
1934 return;
1935 }
1936 pNotify->AddCalcValidate(this);
1937 }
1938 } else {
1939 CFX_WideString wsMessage;
1940 switch (iMessageType) {
1941 case XFA_SOM_ValidationMessage:
1942 validate.GetScriptMessageText(wsMessage);
1943 break;
1944 case XFA_SOM_FormatMessage:
1945 validate.GetFormatMessageText(wsMessage);
1946 break;
1947 case XFA_SOM_MandatoryMessage:
1948 validate.GetNullMessageText(wsMessage);
1949 break;
1950 default:
1951 break;
1952 }
dsinclairf27aeec2016-06-07 19:36:18 -07001953 pValue->SetString(FX_UTF8Encode(wsMessage).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001954 }
1955}
dsinclair5b36f0a2016-07-19 10:56:23 -07001956
dsinclair12a6b0c2016-05-26 11:14:08 -07001957void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001958 FX_BOOL bSetting,
1959 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001960 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001961}
dsinclair5b36f0a2016-07-19 10:56:23 -07001962
dsinclair12a6b0c2016-05-26 11:14:08 -07001963void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001964 FX_BOOL bSetting,
1965 XFA_ATTRIBUTE eAttribute) {
1966 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07001967 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04001968 } else {
1969 CXFA_WidgetData* pWidgetData = GetWidgetData();
1970 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07001971 pValue->SetInteger(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001972 return;
1973 }
dsinclairf27aeec2016-06-07 19:36:18 -07001974 pValue->SetInteger(pWidgetData->CountChoiceListItems(TRUE));
Dan Sinclair1770c022016-03-14 14:14:16 -04001975 }
1976}
dsinclair5b36f0a2016-07-19 10:56:23 -07001977
dsinclair12a6b0c2016-05-26 11:14:08 -07001978void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001979 FX_BOOL bSetting,
1980 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001981 XFA_Element eType = GetElementType();
1982 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001983 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001984 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001985 }
1986 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001987 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001988 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001989 }
1990 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001991 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001992 return;
1993 }
1994 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001995 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07001996 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07001997 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07001998
Dan Sinclair1770c022016-03-14 14:14:16 -04001999 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07002000 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002001 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
2002 CXFA_NodeArray formNodes;
2003 GetBindItems(formNodes);
2004 CFX_WideString wsPicture;
2005 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
2006 CXFA_Node* pFormNode = formNodes.GetAt(i);
dsinclairc5a8f212016-06-20 11:11:12 -07002007 if (!pFormNode || pFormNode->HasRemovedChildren()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002008 continue;
2009 }
2010 pContainerWidgetData = pFormNode->GetContainerWidgetData();
2011 if (pContainerWidgetData) {
2012 pContainerWidgetData->GetPictureContent(wsPicture,
2013 XFA_VALUEPICTURE_DataBind);
2014 }
2015 if (!wsPicture.IsEmpty()) {
2016 break;
2017 }
weili44f8faf2016-06-01 14:03:56 -07002018 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002019 }
2020 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
2021 pContainerWidgetData = GetContainerWidgetData();
2022 }
2023 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002024 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002025 }
thestigb1a59592016-04-14 18:29:56 -07002026 SetScriptContent(wsNewValue, wsFormatValue, true, TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002027 } else {
2028 CFX_WideString content = GetScriptContent(TRUE);
dsinclair41cb62e2016-06-23 09:20:32 -07002029 if (content.IsEmpty() && eType != XFA_Element::Text &&
2030 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07002031 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07002032 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002033 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07002034 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07002035 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002036 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002037 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002038 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002039 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002040 }
2041 }
2042}
dsinclair5b36f0a2016-07-19 10:56:23 -07002043
dsinclair12a6b0c2016-05-26 11:14:08 -07002044void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002045 FX_BOOL bSetting,
2046 XFA_ATTRIBUTE eAttribute) {
2047 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07002048 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002049 return;
2050 }
2051 CFX_WideString content = GetScriptContent(TRUE);
2052 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002053 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002054 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002055 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002056 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002057 }
2058}
dsinclair5b36f0a2016-07-19 10:56:23 -07002059
dsinclair12a6b0c2016-05-26 11:14:08 -07002060void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002061 FX_BOOL bSetting,
2062 XFA_ATTRIBUTE eAttribute) {
2063 if (bSetting) {
2064 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002065 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002066 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002067
tsepezb4c9f3f2016-04-13 15:41:21 -07002068 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002069 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002070 CFX_WideString wsFormatValue(wsNewValue);
2071 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2072 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002073 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002074 }
thestigb1a59592016-04-14 18:29:56 -07002075 SetScriptContent(wsNewValue, wsFormatValue, true, TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002076 } else {
2077 CFX_WideString wsValue = GetScriptContent(TRUE);
dsinclairf27aeec2016-06-07 19:36:18 -07002078 pValue->SetBoolean(wsValue == FX_WSTRC(L"1"));
Dan Sinclair1770c022016-03-14 14:14:16 -04002079 }
2080}
dsinclair2f5582f2016-06-09 11:48:23 -07002081
dsinclair12a6b0c2016-05-26 11:14:08 -07002082void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002083 FX_BOOL bSetting,
2084 XFA_ATTRIBUTE eAttribute) {
2085 CXFA_WidgetData* pWidgetData = GetWidgetData();
2086 if (!pWidgetData) {
2087 return;
2088 }
2089 CXFA_Border border = pWidgetData->GetBorder(TRUE);
2090 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002091 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002092 int32_t r = 0;
2093 int32_t g = 0;
2094 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002095 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002096 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2097 for (int32_t i = 0; i < iSize; ++i) {
2098 CXFA_Edge edge = border.GetEdge(i);
2099 edge.SetColor(rgb);
2100 }
2101 } else {
2102 CXFA_Edge edge = border.GetEdge(0);
2103 FX_ARGB color = edge.GetColor();
2104 int32_t a, r, g, b;
2105 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002106 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002107 strColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002108 pValue->SetString(FX_UTF8Encode(strColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002109 }
2110}
dsinclair5b36f0a2016-07-19 10:56:23 -07002111
dsinclair12a6b0c2016-05-26 11:14:08 -07002112void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002113 FX_BOOL bSetting,
2114 XFA_ATTRIBUTE eAttribute) {
2115 CXFA_WidgetData* pWidgetData = GetWidgetData();
2116 if (!pWidgetData) {
2117 return;
2118 }
2119 CXFA_Border border = pWidgetData->GetBorder(TRUE);
2120 int32_t iSize = border.CountEdges();
2121 CFX_WideString wsThickness;
2122 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002123 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002124 for (int32_t i = 0; i < iSize; ++i) {
2125 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002126 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002127 edge.SetMSThickness(thickness);
2128 }
2129 } else {
2130 CXFA_Edge edge = border.GetEdge(0);
2131 CXFA_Measurement thickness = edge.GetMSThickness();
2132 thickness.ToString(wsThickness);
dsinclairf27aeec2016-06-07 19:36:18 -07002133 pValue->SetString(FX_UTF8Encode(wsThickness).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002134 }
2135}
dsinclair5b36f0a2016-07-19 10:56:23 -07002136
dsinclair12a6b0c2016-05-26 11:14:08 -07002137void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002138 FX_BOOL bSetting,
2139 XFA_ATTRIBUTE eAttribute) {
2140 CXFA_WidgetData* pWidgetData = GetWidgetData();
2141 if (!pWidgetData) {
2142 return;
2143 }
2144 CXFA_Border border = pWidgetData->GetBorder(TRUE);
2145 CXFA_Fill borderfill = border.GetFill(TRUE);
2146 CXFA_Node* pNode = borderfill.GetNode();
2147 if (!pNode) {
2148 return;
2149 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002150 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002151 int32_t r;
2152 int32_t g;
2153 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002154 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002155 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2156 borderfill.SetColor(color);
2157 } else {
2158 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002159 int32_t a;
2160 int32_t r;
2161 int32_t g;
2162 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002163 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002164 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002165 wsColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002166 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002167 }
2168}
dsinclair5b36f0a2016-07-19 10:56:23 -07002169
dsinclair12a6b0c2016-05-26 11:14:08 -07002170void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002171 FX_BOOL bSetting,
2172 XFA_ATTRIBUTE eAttribute) {
2173 if (!bSetting) {
2174 CXFA_Node* pDataNode = GetBindData();
2175 if (pDataNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002176 pValue->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002177 m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
2178 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002179 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002180 }
2181 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002182 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002183 }
2184}
dsinclair5b36f0a2016-07-19 10:56:23 -07002185
dsinclair12a6b0c2016-05-26 11:14:08 -07002186void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002187 FX_BOOL bSetting,
2188 XFA_ATTRIBUTE eAttribute) {
2189 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002190 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002191 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002192 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002193 XFA_Element uiType = pWidgetData->GetUIType();
2194 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002195 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002196 CFX_WideString wsFormatValue(wsNewValue);
thestigb1a59592016-04-14 18:29:56 -07002197 SetScriptContent(wsNewValue, wsFormatValue, true, TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002198 }
2199 }
2200 } else {
2201 CFX_WideString content = GetScriptContent(TRUE);
2202 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002203 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002204 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002205 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002206 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002207 }
2208 }
2209}
dsinclair5b36f0a2016-07-19 10:56:23 -07002210
dsinclair12a6b0c2016-05-26 11:14:08 -07002211void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002212 FX_BOOL bSetting,
2213 XFA_ATTRIBUTE eAttribute) {
2214 CXFA_WidgetData* pWidgetData = GetWidgetData();
2215 if (!pWidgetData) {
2216 return;
2217 }
2218 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002219 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002220 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
2221 pWidgetData->m_bIsNull = TRUE;
2222 } else {
2223 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
2224 pWidgetData->m_bIsNull = FALSE;
2225 }
dsinclair2f5582f2016-06-09 11:48:23 -07002226 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002227 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002228 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002229
Dan Sinclair1770c022016-03-14 14:14:16 -04002230 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002231 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002232 int32_t iLeadDigits = 0;
2233 int32_t iFracDigits = 0;
2234 pWidgetData->GetLeadDigits(iLeadDigits);
2235 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002236 wsNewText =
2237 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002238 }
2239 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2240 CFX_WideString wsFormatText(wsNewText);
2241 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002242 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002243 }
thestigb1a59592016-04-14 18:29:56 -07002244 SetScriptContent(wsNewText, wsFormatText, true, TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002245 } else {
2246 CFX_WideString content = GetScriptContent(TRUE);
2247 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002248 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002249 } else {
2250 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002251 CXFA_Value defVal = pWidgetData->GetFormValue();
2252 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002253 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002254 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002255 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002256 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002257 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002258 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002259 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002260 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002261 }
dsinclair070fcdf2016-06-22 22:04:54 -07002262 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002263 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002264 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
dsinclairf27aeec2016-06-07 19:36:18 -07002265 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? FALSE : TRUE);
dsinclair070fcdf2016-06-22 22:04:54 -07002266 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002267 CFX_Decimal decimal(content.AsStringC());
dsinclairf27aeec2016-06-07 19:36:18 -07002268 pValue->SetFloat((FX_FLOAT)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002269 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002270 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002271 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002272 }
2273 }
2274 }
2275}
dsinclair5b36f0a2016-07-19 10:56:23 -07002276
dsinclair12a6b0c2016-05-26 11:14:08 -07002277void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002278 FX_BOOL bSetting,
2279 XFA_ATTRIBUTE eAttribute) {
2280 CXFA_WidgetData* pWidgetData = GetWidgetData();
2281 if (!pWidgetData) {
2282 return;
2283 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002284 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002285 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002286 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002287 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002288 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
dsinclairf27aeec2016-06-07 19:36:18 -07002289 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002290 }
2291}
dsinclair5b36f0a2016-07-19 10:56:23 -07002292
dsinclair12a6b0c2016-05-26 11:14:08 -07002293void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002294 FX_BOOL bSetting,
2295 XFA_ATTRIBUTE eAttribute) {
2296 CXFA_WidgetData* pWidgetData = GetWidgetData();
2297 if (!pWidgetData) {
2298 return;
2299 }
2300 CXFA_Font font = pWidgetData->GetFont(TRUE);
2301 CXFA_Node* pNode = font.GetNode();
2302 if (!pNode) {
2303 return;
2304 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002305 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002306 int32_t r;
2307 int32_t g;
2308 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002309 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002310 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2311 font.SetColor(color);
2312 } else {
2313 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002314 int32_t a;
2315 int32_t r;
2316 int32_t g;
2317 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002318 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002319 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002320 wsColor.Format(L"%d,%d,%d", r, g, b);
dsinclairf27aeec2016-06-07 19:36:18 -07002321 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002322 }
2323}
dsinclair5b36f0a2016-07-19 10:56:23 -07002324
dsinclair12a6b0c2016-05-26 11:14:08 -07002325void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002326 FX_BOOL bSetting,
2327 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002328 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002329}
dsinclair5b36f0a2016-07-19 10:56:23 -07002330
dsinclair12a6b0c2016-05-26 11:14:08 -07002331void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002332 FX_BOOL bSetting,
2333 XFA_ATTRIBUTE eAttribute) {
2334 CXFA_WidgetData* pWidgetData = GetWidgetData();
2335 if (!pWidgetData) {
2336 return;
2337 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002338 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002339 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002340 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002341 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002342 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
dsinclairf27aeec2016-06-07 19:36:18 -07002343 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002344 }
2345}
dsinclair5b36f0a2016-07-19 10:56:23 -07002346
dsinclair12a6b0c2016-05-26 11:14:08 -07002347void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002348 FX_BOOL bSetting,
2349 XFA_ATTRIBUTE eAttribute) {
2350 CXFA_WidgetData* pWidgetData = GetWidgetData();
2351 if (!pWidgetData) {
2352 return;
2353 }
2354 CXFA_Validate validate = pWidgetData->GetValidate(TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002355 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002356 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002357 } else {
2358 int32_t iValue = validate.GetNullTest();
2359 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002360 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002361 CFX_WideString wsValue;
2362 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002363 wsValue = pInfo->pName;
dsinclairf27aeec2016-06-07 19:36:18 -07002364 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002365 }
2366}
dsinclair5b36f0a2016-07-19 10:56:23 -07002367
dsinclair12a6b0c2016-05-26 11:14:08 -07002368void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002369 FX_BOOL bSetting,
2370 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002371 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002372}
dsinclair5b36f0a2016-07-19 10:56:23 -07002373
dsinclair12a6b0c2016-05-26 11:14:08 -07002374void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002375 FX_BOOL bSetting,
2376 XFA_ATTRIBUTE eAttribute) {
2377 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07002378 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002379 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002380 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002381 }
2382}
dsinclair5b36f0a2016-07-19 10:56:23 -07002383
dsinclair12a6b0c2016-05-26 11:14:08 -07002384void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002385 FX_BOOL bSetting,
2386 XFA_ATTRIBUTE eAttribute) {
2387 CXFA_WidgetData* pWidgetData = GetWidgetData();
2388 if (!pWidgetData) {
2389 return;
2390 }
2391 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002392 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002393 if (iIndex == -1) {
2394 pWidgetData->ClearAllSelections();
2395 return;
2396 }
thestig800222e2016-05-26 22:00:29 -07002397 pWidgetData->SetItemState(iIndex, TRUE, true, TRUE, TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002398 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002399 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002400 }
2401}
dsinclair5b36f0a2016-07-19 10:56:23 -07002402
Dan Sinclair1770c022016-03-14 14:14:16 -04002403void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2404 CXFA_WidgetData* pWidgetData = GetWidgetData();
2405 if (!pWidgetData) {
2406 return;
2407 }
2408 pWidgetData->DeleteItem(-1, TRUE);
2409}
dsinclair5b36f0a2016-07-19 10:56:23 -07002410
Dan Sinclair1770c022016-03-14 14:14:16 -04002411void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
2412 int32_t argc = pArguments->GetLength();
2413 if (argc == 1) {
2414 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2415 int32_t iRet = execSingleEventByName(
tsepez4c3debb2016-04-08 12:20:38 -07002416 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
dsinclair56a8b192016-06-21 14:15:25 -07002417 XFA_Element::Field);
Dan Sinclair1770c022016-03-14 14:14:16 -04002418 if (eventString == "validate") {
dsinclairf27aeec2016-06-07 19:36:18 -07002419 pArguments->GetReturnValue()->SetBoolean(
2420 (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002421 }
2422 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002423 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
Dan Sinclair1770c022016-03-14 14:14:16 -04002424 }
2425}
dsinclair5b36f0a2016-07-19 10:56:23 -07002426
Dan Sinclair1770c022016-03-14 14:14:16 -04002427void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
2428 int32_t argc = pArguments->GetLength();
2429 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002430 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002431 if (!pNotify) {
2432 return;
2433 }
2434 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, FALSE, FALSE);
2435 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002436 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002437 }
2438}
dsinclair5b36f0a2016-07-19 10:56:23 -07002439
Dan Sinclair1770c022016-03-14 14:14:16 -04002440void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2441 int32_t iLength = pArguments->GetLength();
2442 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002443 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002444 return;
2445 }
2446 CXFA_WidgetData* pWidgetData = GetWidgetData();
2447 if (!pWidgetData) {
2448 return;
2449 }
2450 int32_t iIndex = pArguments->GetInt32(0);
2451 FX_BOOL bValue = pWidgetData->DeleteItem(iIndex, TRUE, TRUE);
dsinclair12a6b0c2016-05-26 11:14:08 -07002452 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002453 if (pValue)
2454 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002455}
dsinclair5b36f0a2016-07-19 10:56:23 -07002456
Dan Sinclair1770c022016-03-14 14:14:16 -04002457void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2458 int32_t iLength = pArguments->GetLength();
2459 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002460 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002461 return;
2462 }
2463 int32_t iIndex = pArguments->GetInt32(0);
2464 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002465 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002466 return;
2467 }
2468 CXFA_WidgetData* pWidgetData = GetWidgetData();
2469 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002470 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002471 return;
2472 }
2473 CFX_WideString wsValue;
2474 FX_BOOL bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, TRUE);
2475 if (bHasItem) {
dsinclairf27aeec2016-06-07 19:36:18 -07002476 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002477 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002478 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002479 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002480 }
2481}
dsinclair5b36f0a2016-07-19 10:56:23 -07002482
Dan Sinclair1770c022016-03-14 14:14:16 -04002483void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2484 int32_t iLength = pArguments->GetLength();
2485 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002486 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002487 return;
2488 }
2489 CXFA_WidgetData* pWidgetData = GetWidgetData();
2490 if (!pWidgetData) {
2491 return;
2492 }
2493 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002494 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002495 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002496 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002497 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002498 if (pValue)
2499 pValue->SetString(FX_UTF8Encode(wsBoundValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002500}
dsinclair5b36f0a2016-07-19 10:56:23 -07002501
Dan Sinclair1770c022016-03-14 14:14:16 -04002502void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2503 int32_t iLength = pArguments->GetLength();
2504 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002505 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002506 return;
2507 }
2508 CXFA_WidgetData* pWidgetData = GetWidgetData();
2509 if (!pWidgetData) {
2510 return;
2511 }
2512 int32_t iIndex = pArguments->GetInt32(0);
2513 FX_BOOL bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002514 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002515 if (pValue)
2516 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002517}
dsinclair5b36f0a2016-07-19 10:56:23 -07002518
Dan Sinclair1770c022016-03-14 14:14:16 -04002519void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
2520 int32_t argc = pArguments->GetLength();
2521 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002522 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002523 if (!pNotify) {
2524 return;
2525 }
2526 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, FALSE, FALSE);
2527 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002528 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002529 }
2530}
dsinclair5b36f0a2016-07-19 10:56:23 -07002531
Dan Sinclair1770c022016-03-14 14:14:16 -04002532void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002533
Dan Sinclair1770c022016-03-14 14:14:16 -04002534void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2535 int32_t iLength = pArguments->GetLength();
2536 if (iLength != 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002537 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002538 return;
2539 }
2540 int32_t iIndex = pArguments->GetInt32(0);
2541 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002542 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002543 return;
2544 }
2545 CXFA_WidgetData* pWidgetData = GetWidgetData();
2546 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002547 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002548 return;
2549 }
2550 CFX_WideString wsValue;
2551 FX_BOOL bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, FALSE);
2552 if (bHasItem) {
dsinclairf27aeec2016-06-07 19:36:18 -07002553 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07002554 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002555 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002556 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002557 }
2558}
dsinclair5b36f0a2016-07-19 10:56:23 -07002559
Dan Sinclair1770c022016-03-14 14:14:16 -04002560void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2561 int32_t iLength = pArguments->GetLength();
2562 if (iLength != 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07002563 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002564 return;
2565 }
2566 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002567 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002568 return;
thestig800222e2016-05-26 22:00:29 -07002569
Dan Sinclair1770c022016-03-14 14:14:16 -04002570 int32_t iIndex = pArguments->GetInt32(0);
2571 if (pArguments->GetInt32(1) != 0) {
thestig800222e2016-05-26 22:00:29 -07002572 pWidgetData->SetItemState(iIndex, TRUE, true, TRUE, TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002573 } else {
thestig800222e2016-05-26 22:00:29 -07002574 if (pWidgetData->GetItemState(iIndex))
2575 pWidgetData->SetItemState(iIndex, FALSE, true, TRUE, TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002576 }
2577}
dsinclair5b36f0a2016-07-19 10:56:23 -07002578
Dan Sinclair1770c022016-03-14 14:14:16 -04002579void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2580 int32_t iLength = pArguments->GetLength();
2581 if (iLength < 1 || iLength > 2) {
dsinclair2235b7b2016-06-02 07:42:25 -07002582 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002583 return;
2584 }
2585 CXFA_WidgetData* pWidgetData = GetWidgetData();
2586 if (!pWidgetData) {
2587 return;
2588 }
2589 CFX_WideString wsLabel;
2590 CFX_WideString wsValue;
2591 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002592 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002593 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002594 }
2595 if (iLength >= 2) {
2596 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002597 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002598 }
2599 pWidgetData->InsertItem(wsLabel, wsValue, -1, TRUE);
2600}
dsinclair5b36f0a2016-07-19 10:56:23 -07002601
Dan Sinclair1770c022016-03-14 14:14:16 -04002602void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
2603 int32_t argc = pArguments->GetLength();
2604 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002605 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002606 if (!pNotify) {
dsinclairf27aeec2016-06-07 19:36:18 -07002607 pArguments->GetReturnValue()->SetBoolean(FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002608 } else {
2609 int32_t iRet =
2610 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, FALSE, FALSE);
dsinclairf27aeec2016-06-07 19:36:18 -07002611 pArguments->GetReturnValue()->SetBoolean(
2612 (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002613 }
2614 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002615 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002616 }
2617}
dsinclair5b36f0a2016-07-19 10:56:23 -07002618
dsinclair12a6b0c2016-05-26 11:14:08 -07002619void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002620 FX_BOOL bSetting,
2621 XFA_ATTRIBUTE eAttribute) {
2622 if (!bSetting) {
2623 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002624 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002625 }
2626}
dsinclair5b36f0a2016-07-19 10:56:23 -07002627
dsinclair12a6b0c2016-05-26 11:14:08 -07002628void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002629 FX_BOOL bSetting,
2630 XFA_ATTRIBUTE eAttribute) {
2631 CXFA_WidgetData* pWidgetData = GetWidgetData();
2632 if (!pWidgetData) {
2633 return;
2634 }
2635 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002636 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
2637 true, TRUE, TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002638 } else {
2639 CFX_WideString wsValue = GetScriptContent(TRUE);
2640 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2641 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002642 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002643 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002644 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002645 }
2646 }
2647}
dsinclair5b36f0a2016-07-19 10:56:23 -07002648
dsinclair12a6b0c2016-05-26 11:14:08 -07002649void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002650 FX_BOOL bSetting,
2651 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002652
Dan Sinclair1770c022016-03-14 14:14:16 -04002653void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
2654 int32_t argc = pArguments->GetLength();
2655 if (argc == 1) {
2656 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2657 execSingleEventByName(
tsepez4c3debb2016-04-08 12:20:38 -07002658 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
dsinclair56a8b192016-06-21 14:15:25 -07002659 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002660 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002661 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
Dan Sinclair1770c022016-03-14 14:14:16 -04002662 }
2663}
thestig800222e2016-05-26 22:00:29 -07002664
Dan Sinclair1770c022016-03-14 14:14:16 -04002665void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2666 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002667 if (argc < 0 || argc > 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07002668 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002669 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002670 }
thestig800222e2016-05-26 22:00:29 -07002671
2672 CXFA_WidgetData* pWidgetData = GetWidgetData();
2673 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002674 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002675 return;
2676 }
2677
2678 CXFA_Node* pReturnNode = nullptr;
2679 if (argc == 0) {
2680 pReturnNode = pWidgetData->GetSelectedMember();
2681 } else {
2682 CFX_ByteString szName;
2683 szName = pArguments->GetUTF8String(0);
2684 pReturnNode = pWidgetData->SetSelectedMember(
2685 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2686 }
2687 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002688 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002689 return;
2690 }
dsinclairf27aeec2016-06-07 19:36:18 -07002691 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002692 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002693}
thestig800222e2016-05-26 22:00:29 -07002694
Dan Sinclair1770c022016-03-14 14:14:16 -04002695void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
2696 int32_t argc = pArguments->GetLength();
2697 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002698 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002699 if (!pNotify) {
2700 return;
2701 }
2702 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
2703 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002704 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002705 }
2706}
dsinclair5b36f0a2016-07-19 10:56:23 -07002707
Dan Sinclair1770c022016-03-14 14:14:16 -04002708void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
2709 int32_t argc = pArguments->GetLength();
2710 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002711 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002712 if (!pNotify) {
2713 return;
2714 }
2715 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
2716 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002717 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002718 }
2719}
dsinclair5b36f0a2016-07-19 10:56:23 -07002720
Dan Sinclair1770c022016-03-14 14:14:16 -04002721void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
2722 int32_t argc = pArguments->GetLength();
2723 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002724 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002725 if (!pNotify) {
dsinclairf27aeec2016-06-07 19:36:18 -07002726 pArguments->GetReturnValue()->SetBoolean(FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002727 } else {
2728 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
dsinclairf27aeec2016-06-07 19:36:18 -07002729 pArguments->GetReturnValue()->SetBoolean(
2730 (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002731 }
2732 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002733 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002734 }
2735}
dsinclair5b36f0a2016-07-19 10:56:23 -07002736
dsinclair12a6b0c2016-05-26 11:14:08 -07002737void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002738 FX_BOOL bSetting,
2739 XFA_ATTRIBUTE eAttribute) {
2740 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002741 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002742 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002743 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002744 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2745 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002746 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002747 pManagerNode = pNode;
2748 break;
2749 }
2750 }
2751 if (pManagerNode) {
2752 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002753 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002754 if (!pNotify) {
2755 return;
2756 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002757 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002758 if (pToInstance &&
2759 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002760 pNotify->RunSubformIndexChange(pToInstance);
2761 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002762 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002763 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002764 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002765 pNotify->RunSubformIndexChange(pFromInstance);
2766 }
2767 }
2768 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002769 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002770 }
2771}
dsinclair5b36f0a2016-07-19 10:56:23 -07002772
dsinclair12a6b0c2016-05-26 11:14:08 -07002773void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002774 FX_BOOL bSetting,
2775 XFA_ATTRIBUTE eAttribute) {
2776 if (!bSetting) {
2777 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
weili44f8faf2016-06-01 14:03:56 -07002778 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002779 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2780 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002781 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002782 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2783 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2784 wsInstMgrName.Mid(1) == wsName) {
2785 pInstanceMgr = pNode;
2786 }
2787 break;
2788 }
2789 }
2790 if (pInstanceMgr) {
dsinclairf27aeec2016-06-07 19:36:18 -07002791 pValue->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002792 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
2793 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002794 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002795 }
2796 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002797 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04002798 }
2799}
dsinclair5b36f0a2016-07-19 10:56:23 -07002800
dsinclair12a6b0c2016-05-26 11:14:08 -07002801void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04002802 FX_BOOL bSetting,
2803 XFA_ATTRIBUTE eAttribute) {
2804 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002805 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002806 } else {
2807 CFX_WideString wsLocaleName;
2808 GetLocaleName(wsLocaleName);
dsinclairf27aeec2016-06-07 19:36:18 -07002809 pValue->SetString(
2810 FX_UTF8Encode(wsLocaleName.c_str(), wsLocaleName.GetLength())
2811 .AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002812 }
2813}
dsinclair5b36f0a2016-07-19 10:56:23 -07002814
Dan Sinclair1770c022016-03-14 14:14:16 -04002815void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
2816 int32_t argc = pArguments->GetLength();
2817 if (argc == 1) {
2818 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2819 execSingleEventByName(
tsepez4c3debb2016-04-08 12:20:38 -07002820 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
dsinclair56a8b192016-06-21 14:15:25 -07002821 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002822 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002823 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
Dan Sinclair1770c022016-03-14 14:14:16 -04002824 }
2825}
dsinclair5b36f0a2016-07-19 10:56:23 -07002826
Dan Sinclair1770c022016-03-14 14:14:16 -04002827void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
2828 int32_t argc = pArguments->GetLength();
2829 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002830 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002831 if (!pNotify) {
2832 return;
2833 }
2834 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
2835 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002836 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002837 }
2838}
dsinclair5b36f0a2016-07-19 10:56:23 -07002839
Dan Sinclair1770c022016-03-14 14:14:16 -04002840void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
2841 int32_t argc = pArguments->GetLength();
2842 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002843 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002844 if (!pNotify) {
2845 return;
2846 }
2847 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
2848 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002849 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002850 }
2851}
dsinclair5b36f0a2016-07-19 10:56:23 -07002852
Dan Sinclair1770c022016-03-14 14:14:16 -04002853void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
2854 int32_t argc = pArguments->GetLength();
2855 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07002856 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002857 if (!pNotify) {
dsinclairf27aeec2016-06-07 19:36:18 -07002858 pArguments->GetReturnValue()->SetBoolean(FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002859 } else {
2860 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
dsinclairf27aeec2016-06-07 19:36:18 -07002861 pArguments->GetReturnValue()->SetBoolean(
2862 (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002863 }
2864 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002865 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002866 }
2867}
dsinclair5b36f0a2016-07-19 10:56:23 -07002868
Dan Sinclair1770c022016-03-14 14:14:16 -04002869void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
2870 int32_t argc = pArguments->GetLength();
2871 if (argc == 0) {
2872 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002873 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002874 }
2875}
dsinclair5b36f0a2016-07-19 10:56:23 -07002876
Dan Sinclair1770c022016-03-14 14:14:16 -04002877int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2878 int32_t index = 0;
2879 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2880 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002881 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2882 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002883 index++;
2884 } else {
2885 break;
2886 }
2887 }
2888 return index;
2889}
dsinclair5b36f0a2016-07-19 10:56:23 -07002890
Dan Sinclair1770c022016-03-14 14:14:16 -04002891void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
2892 int32_t argc = pArguments->GetLength();
2893 if (argc == 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07002894 pArguments->GetReturnValue()->SetBoolean(TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002895 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002896 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04002897 }
2898}
dsinclair5b36f0a2016-07-19 10:56:23 -07002899
Dan Sinclair1770c022016-03-14 14:14:16 -04002900void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
2901 int32_t argc = pArguments->GetLength();
2902 if (argc == 0) {
2903 m_pDocument->DoDataRemerge(TRUE);
2904 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002905 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge");
Dan Sinclair1770c022016-03-14 14:14:16 -04002906 }
2907}
dsinclair5b36f0a2016-07-19 10:56:23 -07002908
Dan Sinclair1770c022016-03-14 14:14:16 -04002909void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
2910 int32_t argc = pArguments->GetLength();
2911 if (argc == 0) {
2912 CXFA_WidgetData* pWidgetData = GetWidgetData();
2913 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002914 pArguments->GetReturnValue()->SetBoolean(FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002915 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002916 pArguments->GetReturnValue()->SetBoolean(TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002917 }
2918 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002919 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04002920 }
2921}
dsinclair5b36f0a2016-07-19 10:56:23 -07002922
Dan Sinclair1770c022016-03-14 14:14:16 -04002923void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2924 int32_t argc = pArguments->GetLength();
2925 if ((argc > 0) && (argc < 4)) {
2926 CFX_WideString strTagName;
2927 CFX_WideString strName;
2928 CFX_WideString strNameSpace;
2929 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002930 strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002931 if (argc > 1) {
2932 CFX_ByteString bsName = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002933 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002934 if (argc == 3) {
2935 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
tsepez4c3debb2016-04-08 12:20:38 -07002936 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002937 }
2938 }
dsinclair6e124782016-06-23 12:14:55 -07002939 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2940 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
Dan Sinclair1770c022016-03-14 14:14:16 -04002941 if (!pNewNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002942 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002943 } else {
2944 if (!strName.IsEmpty()) {
dsinclair9eb0db12016-07-21 12:01:39 -07002945 if (GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2946 XFA_XDPPACKET_UNKNOWN)) {
thestigb1a59592016-04-14 18:29:56 -07002947 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002948 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) {
2949 pNewNode->CreateXMLMappingNode();
2950 }
dsinclairf27aeec2016-06-07 19:36:18 -07002951 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002952 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2953 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002954 ThrowException(XFA_IDS_NOT_HAVE_PROPERTY, strTagName.c_str(),
2955 L"name");
Dan Sinclair1770c022016-03-14 14:14:16 -04002956 }
2957 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002958 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04002959 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2960 }
2961 }
2962 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002963 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"createNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04002964 }
2965}
dsinclair5b36f0a2016-07-19 10:56:23 -07002966
Dan Sinclair1770c022016-03-14 14:14:16 -04002967void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
2968 if (pArguments->GetLength() == 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07002969 pArguments->GetReturnValue()->SetBoolean(TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002970 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002971 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002972 }
2973}
dsinclair5b36f0a2016-07-19 10:56:23 -07002974
Dan Sinclair1770c022016-03-14 14:14:16 -04002975void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
2976 int32_t argc = pArguments->GetLength();
2977 if (argc == 0) {
2978 CXFA_WidgetData* pWidgetData = GetWidgetData();
2979 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002980 pArguments->GetReturnValue()->SetBoolean(FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002981 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002982 pArguments->GetReturnValue()->SetBoolean(TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002983 }
2984 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002985 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04002986 }
2987}
dsinclair5b36f0a2016-07-19 10:56:23 -07002988
Dan Sinclair1770c022016-03-14 14:14:16 -04002989void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
2990 int32_t argc = pArguments->GetLength();
2991 if (argc == 0) {
2992 CXFA_WidgetData* pWidgetData = GetWidgetData();
2993 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002994 pArguments->GetReturnValue()->SetBoolean(FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002995 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002996 pArguments->GetReturnValue()->SetBoolean(TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04002997 }
2998 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07002999 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003000 }
3001}
dsinclair5b36f0a2016-07-19 10:56:23 -07003002
Dan Sinclair1770c022016-03-14 14:14:16 -04003003void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
3004 int32_t argc = pArguments->GetLength();
3005 if (argc == 0) {
3006 CXFA_WidgetData* pWidgetData = GetWidgetData();
3007 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07003008 pArguments->GetReturnValue()->SetBoolean(FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04003009 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003010 pArguments->GetReturnValue()->SetBoolean(TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04003011 }
3012 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003013 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"evaluate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003014 }
3015}
dsinclair5b36f0a2016-07-19 10:56:23 -07003016
dsinclair12a6b0c2016-05-26 11:14:08 -07003017void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04003018 FX_BOOL bSetting,
3019 XFA_ATTRIBUTE eAttribute) {
3020 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07003021 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04003022 return;
3023 }
3024 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003025 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003026}
dsinclair5b36f0a2016-07-19 10:56:23 -07003027
dsinclair12a6b0c2016-05-26 11:14:08 -07003028void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04003029 FX_BOOL bSetting,
3030 XFA_ATTRIBUTE eAttribute) {
3031 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07003032 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04003033 return;
3034 }
3035 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07003036 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003037}
tsepezaadedf92016-05-12 10:08:06 -07003038
dsinclair12a6b0c2016-05-26 11:14:08 -07003039void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04003040 FX_BOOL bSetting,
3041 XFA_ATTRIBUTE eAttribute) {
3042 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003043 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003044 InstanceManager_SetInstances(iDesired);
3045 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07003046 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04003047 }
3048}
dsinclair5b36f0a2016-07-19 10:56:23 -07003049
Dan Sinclair1770c022016-03-14 14:14:16 -04003050void CXFA_Node::Script_InstanceManager_MoveInstance(
3051 CFXJSE_Arguments* pArguments) {
3052 int32_t argc = pArguments->GetLength();
3053 if (argc != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003054 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003055 return;
3056 }
3057 int32_t iFrom = pArguments->GetInt32(0);
3058 int32_t iTo = pArguments->GetInt32(1);
3059 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003060 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003061 if (!pNotify) {
3062 return;
3063 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003064 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003065 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003066 pNotify->RunSubformIndexChange(pToInstance);
3067 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003068 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003069 if (pFromInstance &&
3070 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003071 pNotify->RunSubformIndexChange(pFromInstance);
3072 }
3073}
dsinclair5b36f0a2016-07-19 10:56:23 -07003074
Dan Sinclair1770c022016-03-14 14:14:16 -04003075void CXFA_Node::Script_InstanceManager_RemoveInstance(
3076 CFXJSE_Arguments* pArguments) {
3077 int32_t argc = pArguments->GetLength();
3078 if (argc != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003079 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003080 return;
3081 }
3082 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003083 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003084 if (iIndex < 0 || iIndex >= iCount) {
dsinclair2235b7b2016-06-02 07:42:25 -07003085 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
Dan Sinclair1770c022016-03-14 14:14:16 -04003086 return;
3087 }
3088 CXFA_Occur nodeOccur(GetOccurNode());
3089 int32_t iMin = nodeOccur.GetMin();
3090 if (iCount - 1 < iMin) {
dsinclair2235b7b2016-06-02 07:42:25 -07003091 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003092 return;
3093 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003094 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3095 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003096 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003097 if (pNotify) {
3098 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003099 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003100 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003101 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003102 pNotify->RunSubformIndexChange(pSubformInstance);
3103 }
3104 }
3105 }
3106 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3107 if (!pLayoutPro) {
3108 return;
3109 }
3110 pLayoutPro->AddChangedContainer(
3111 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3112}
dsinclair5b36f0a2016-07-19 10:56:23 -07003113
Dan Sinclair1770c022016-03-14 14:14:16 -04003114void CXFA_Node::Script_InstanceManager_SetInstances(
3115 CFXJSE_Arguments* pArguments) {
3116 int32_t argc = pArguments->GetLength();
3117 if (argc != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003118 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003119 return;
3120 }
3121 int32_t iDesired = pArguments->GetInt32(0);
3122 InstanceManager_SetInstances(iDesired);
3123}
dsinclair5b36f0a2016-07-19 10:56:23 -07003124
Dan Sinclair1770c022016-03-14 14:14:16 -04003125void CXFA_Node::Script_InstanceManager_AddInstance(
3126 CFXJSE_Arguments* pArguments) {
3127 int32_t argc = pArguments->GetLength();
3128 if ((argc != 0) && (argc != 1)) {
dsinclair2235b7b2016-06-02 07:42:25 -07003129 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003130 return;
3131 }
3132 FX_BOOL fFlags = TRUE;
3133 if (argc == 1) {
3134 fFlags = pArguments->GetInt32(0) == 0 ? FALSE : TRUE;
3135 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003136 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003137 CXFA_Occur nodeOccur(GetOccurNode());
3138 int32_t iMax = nodeOccur.GetMax();
3139 if (iMax >= 0 && iCount >= iMax) {
dsinclair2235b7b2016-06-02 07:42:25 -07003140 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003141 return;
3142 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003143 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
3144 InsertItem(this, pNewInstance, iCount, iCount, FALSE);
dsinclairf27aeec2016-06-07 19:36:18 -07003145 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003146 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003147 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003148 if (!pNotify) {
3149 return;
3150 }
3151 pNotify->RunNodeInitialize(pNewInstance);
3152 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3153 if (!pLayoutPro) {
3154 return;
3155 }
3156 pLayoutPro->AddChangedContainer(
3157 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3158}
dsinclair5b36f0a2016-07-19 10:56:23 -07003159
Dan Sinclair1770c022016-03-14 14:14:16 -04003160void CXFA_Node::Script_InstanceManager_InsertInstance(
3161 CFXJSE_Arguments* pArguments) {
3162 int32_t argc = pArguments->GetLength();
3163 if ((argc != 1) && (argc != 2)) {
dsinclair2235b7b2016-06-02 07:42:25 -07003164 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003165 return;
3166 }
3167 int32_t iIndex = pArguments->GetInt32(0);
3168 FX_BOOL bBind = FALSE;
3169 if (argc == 2) {
3170 bBind = pArguments->GetInt32(1) == 0 ? FALSE : TRUE;
3171 }
3172 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003173 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003174 if (iIndex < 0 || iIndex > iCount) {
dsinclair2235b7b2016-06-02 07:42:25 -07003175 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
Dan Sinclair1770c022016-03-14 14:14:16 -04003176 return;
3177 }
3178 int32_t iMax = nodeOccur.GetMax();
3179 if (iMax >= 0 && iCount >= iMax) {
dsinclair2235b7b2016-06-02 07:42:25 -07003180 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003181 return;
3182 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003183 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
3184 InsertItem(this, pNewInstance, iIndex, iCount, TRUE);
dsinclairf27aeec2016-06-07 19:36:18 -07003185 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003186 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003187 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003188 if (!pNotify) {
3189 return;
3190 }
3191 pNotify->RunNodeInitialize(pNewInstance);
3192 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3193 if (!pLayoutPro) {
3194 return;
3195 }
3196 pLayoutPro->AddChangedContainer(
3197 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3198}
dsinclair5b36f0a2016-07-19 10:56:23 -07003199
Dan Sinclair1770c022016-03-14 14:14:16 -04003200int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3201 CXFA_Occur nodeOccur(GetOccurNode());
3202 int32_t iMax = nodeOccur.GetMax();
3203 int32_t iMin = nodeOccur.GetMin();
3204 if (iDesired < iMin) {
dsinclair2235b7b2016-06-02 07:42:25 -07003205 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003206 return 1;
3207 }
3208 if ((iMax >= 0) && (iDesired > iMax)) {
dsinclair2235b7b2016-06-02 07:42:25 -07003209 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003210 return 2;
3211 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003212 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003213 if (iDesired == iCount) {
3214 return 0;
3215 }
3216 if (iDesired < iCount) {
3217 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003218 CFX_WideString wsInstanceName =
3219 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3220 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003221 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003222 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003223 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003224 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003225 while (iCount > iDesired) {
3226 CXFA_Node* pRemoveInstance =
3227 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003228 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3229 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003230 continue;
3231 }
dsinclair070fcdf2016-06-22 22:04:54 -07003232 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
dsinclair43854a52016-04-27 12:26:00 -07003233 ASSERT(FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04003234 break;
3235 }
3236 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003237 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003238 iCount--;
3239 }
3240 }
3241 } else if (iDesired > iCount) {
3242 while (iCount < iDesired) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003243 CXFA_Node* pNewInstance = CreateInstance(this, TRUE);
3244 InsertItem(this, pNewInstance, iCount, iCount, FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04003245 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003246 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003247 if (!pNotify) {
3248 return 0;
3249 }
3250 pNotify->RunNodeInitialize(pNewInstance);
3251 }
3252 }
3253 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3254 if (pLayoutPro) {
3255 pLayoutPro->AddChangedContainer(
3256 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3257 }
3258 return 0;
3259}
dsinclair5b36f0a2016-07-19 10:56:23 -07003260
Dan Sinclair1770c022016-03-14 14:14:16 -04003261int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003262 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003263 if (iFrom > iCount || iTo > iCount - 1) {
dsinclair2235b7b2016-06-02 07:42:25 -07003264 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
Dan Sinclair1770c022016-03-14 14:14:16 -04003265 return 1;
3266 }
3267 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3268 return 0;
3269 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003270 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
3271 RemoveItem(this, pMoveInstance, FALSE);
3272 InsertItem(this, pMoveInstance, iTo, iCount - 1, TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04003273 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3274 if (pLayoutPro) {
3275 pLayoutPro->AddChangedContainer(
3276 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3277 }
3278 return 0;
3279}
dsinclair5b36f0a2016-07-19 10:56:23 -07003280
dsinclair12a6b0c2016-05-26 11:14:08 -07003281void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04003282 FX_BOOL bSetting,
3283 XFA_ATTRIBUTE eAttribute) {
3284 CXFA_Occur occur(this);
3285 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003286 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003287 occur.SetMax(iMax);
3288 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003289 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003290 }
3291}
dsinclair5b36f0a2016-07-19 10:56:23 -07003292
dsinclair12a6b0c2016-05-26 11:14:08 -07003293void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04003294 FX_BOOL bSetting,
3295 XFA_ATTRIBUTE eAttribute) {
3296 CXFA_Occur occur(this);
3297 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003298 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003299 occur.SetMin(iMin);
3300 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003301 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003302 }
3303}
dsinclair5b36f0a2016-07-19 10:56:23 -07003304
Dan Sinclair1770c022016-03-14 14:14:16 -04003305void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3306 int32_t argc = pArguments->GetLength();
3307 if ((argc == 0) || (argc == 1)) {
dsinclairf27aeec2016-06-07 19:36:18 -07003308 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003309 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003310 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"metadata");
Dan Sinclair1770c022016-03-14 14:14:16 -04003311 }
3312}
dsinclair5b36f0a2016-07-19 10:56:23 -07003313
Dan Sinclair1770c022016-03-14 14:14:16 -04003314void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
3315 int32_t argc = pArguments->GetLength();
3316 if (argc == 1) {
3317 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3318 if (pDataNode) {
3319 CXFA_NodeArray formItems;
3320 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3321 pFormNodes->SetArrayNodeList(formItems);
dsinclairf27aeec2016-06-07 19:36:18 -07003322 pArguments->GetReturnValue()->SetObject(
3323 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003324 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003325 ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
Dan Sinclair1770c022016-03-14 14:14:16 -04003326 }
3327 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003328 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04003329 }
3330}
dsinclair5b36f0a2016-07-19 10:56:23 -07003331
Dan Sinclair1770c022016-03-14 14:14:16 -04003332void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
3333 int32_t argc = pArguments->GetLength();
3334 if (argc == 0) {
3335 m_pDocument->DoDataRemerge(TRUE);
3336 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003337 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge");
Dan Sinclair1770c022016-03-14 14:14:16 -04003338 }
3339}
dsinclair5b36f0a2016-07-19 10:56:23 -07003340
Dan Sinclair1770c022016-03-14 14:14:16 -04003341void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
3342 int32_t argc = pArguments->GetLength();
3343 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07003344 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003345 if (!pNotify) {
3346 return;
3347 }
3348 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
3349 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003350 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
Dan Sinclair1770c022016-03-14 14:14:16 -04003351 }
3352}
dsinclair5b36f0a2016-07-19 10:56:23 -07003353
Dan Sinclair1770c022016-03-14 14:14:16 -04003354void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3355 CXFA_EventParam* pEventParam =
3356 m_pDocument->GetScriptContext()->GetEventParam();
3357 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3358 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3359 return;
3360 }
3361 int32_t argc = pArguments->GetLength();
3362 if (argc == 1) {
3363 const bool bScriptFlags = pArguments->GetInt32(0) != 0;
dsinclaira1b07722016-07-11 08:20:58 -07003364 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003365 if (!pNotify) {
3366 return;
3367 }
3368 if (bScriptFlags) {
3369 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3370 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3371 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, TRUE);
3372 } else {
3373 }
3374 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003375 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003376 }
3377}
dsinclair5b36f0a2016-07-19 10:56:23 -07003378
Dan Sinclair1770c022016-03-14 14:14:16 -04003379void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
3380 int32_t argc = pArguments->GetLength();
3381 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07003382 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003383 if (!pNotify) {
3384 return;
3385 }
3386 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3387 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003388 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003389 }
3390}
dsinclair5b36f0a2016-07-19 10:56:23 -07003391
Dan Sinclair1770c022016-03-14 14:14:16 -04003392void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
3393 int32_t argc = pArguments->GetLength();
3394 if (argc == 0) {
dsinclaira1b07722016-07-11 08:20:58 -07003395 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003396 if (!pNotify) {
dsinclairf27aeec2016-06-07 19:36:18 -07003397 pArguments->GetReturnValue()->SetBoolean(FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04003398 } else {
3399 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
dsinclairf27aeec2016-06-07 19:36:18 -07003400 pArguments->GetReturnValue()->SetBoolean(
3401 (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04003402 }
3403 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003404 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
Dan Sinclair1770c022016-03-14 14:14:16 -04003405 }
3406}
dsinclair5b36f0a2016-07-19 10:56:23 -07003407
dsinclair12a6b0c2016-05-26 11:14:08 -07003408void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04003409 FX_BOOL bSetting,
3410 XFA_ATTRIBUTE eAttribute) {
3411 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003412 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003413 } else {
3414 CFX_WideString wsChecksum;
3415 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, FALSE);
dsinclairf27aeec2016-06-07 19:36:18 -07003416 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003417 FX_UTF8Encode(wsChecksum.c_str(), wsChecksum.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003418 }
3419}
dsinclair5b36f0a2016-07-19 10:56:23 -07003420
Dan Sinclair1770c022016-03-14 14:14:16 -04003421void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
3422 int32_t argc = pArguments->GetLength();
3423 if (argc == 1) {
3424 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3425 CFX_WideString wsAttributeValue;
dsinclairae95f762016-03-29 16:58:29 -07003426 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003427 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
tsepezbd9748d2016-04-13 21:40:19 -07003428 static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3429 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(),
3430 wsAttributeValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003431 }
dsinclairf27aeec2016-06-07 19:36:18 -07003432 pArguments->GetReturnValue()->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003433 FX_UTF8Encode(wsAttributeValue.c_str(), wsAttributeValue.GetLength())
tsepez4c3debb2016-04-08 12:20:38 -07003434 .AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003435 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003436 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04003437 }
3438}
dsinclair5b36f0a2016-07-19 10:56:23 -07003439
Dan Sinclair1770c022016-03-14 14:14:16 -04003440void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
3441 int32_t argc = pArguments->GetLength();
3442 if (argc == 2) {
3443 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3444 CFX_ByteString bsName = pArguments->GetUTF8String(1);
dsinclairae95f762016-03-29 16:58:29 -07003445 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003446 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003447 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(
3448 CFX_WideString::FromUTF8(bsName.AsStringC()),
3449 CFX_WideString::FromUTF8(bsValue.AsStringC()));
Dan Sinclair1770c022016-03-14 14:14:16 -04003450 }
dsinclairf27aeec2016-06-07 19:36:18 -07003451 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003452 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003453 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04003454 }
3455}
dsinclair5b36f0a2016-07-19 10:56:23 -07003456
Dan Sinclair1770c022016-03-14 14:14:16 -04003457void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
3458 int32_t argc = pArguments->GetLength();
3459 if (argc == 1) {
3460 CFX_ByteString bsName = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07003461 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
dsinclairae95f762016-03-29 16:58:29 -07003462 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003463 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003464 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
tsepezbd9748d2016-04-13 21:40:19 -07003465 if (pXMLElement->HasAttribute(wsName.c_str())) {
3466 pXMLElement->RemoveAttribute(wsName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04003467 }
3468 }
dsinclairf27aeec2016-06-07 19:36:18 -07003469 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003470 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003471 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"removeAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04003472 }
3473}
dsinclair5b36f0a2016-07-19 10:56:23 -07003474
dsinclair12a6b0c2016-05-26 11:14:08 -07003475void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04003476 FX_BOOL bSetting,
3477 XFA_ATTRIBUTE eAttribute) {
3478 if (bSetting) {
dsinclairae95f762016-03-29 16:58:29 -07003479 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003480 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003481 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003482 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003483 }
3484 } else {
3485 CFX_WideString wsTextData;
dsinclairae95f762016-03-29 16:58:29 -07003486 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003487 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003488 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04003489 pXMLElement->GetTextData(wsTextData);
3490 }
dsinclairf27aeec2016-06-07 19:36:18 -07003491 pValue->SetString(
tsepezbd9748d2016-04-13 21:40:19 -07003492 FX_UTF8Encode(wsTextData.c_str(), wsTextData.GetLength()).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003493 }
3494}
dsinclair5b36f0a2016-07-19 10:56:23 -07003495
Dan Sinclair1770c022016-03-14 14:14:16 -04003496void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
3497 int32_t argc = pArguments->GetLength();
3498 if (argc == 0) {
3499 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003500 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003501 }
3502}
dsinclair5b36f0a2016-07-19 10:56:23 -07003503
Dan Sinclair1770c022016-03-14 14:14:16 -04003504void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
3505 int32_t argc = pArguments->GetLength();
3506 if (argc == 0) {
3507 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003508 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003509 }
3510}
dsinclair5b36f0a2016-07-19 10:56:23 -07003511
Dan Sinclair1770c022016-03-14 14:14:16 -04003512void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
3513 int32_t argc = pArguments->GetLength();
3514 if (argc == 0) {
3515 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003516 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003517 }
3518}
dsinclair5b36f0a2016-07-19 10:56:23 -07003519
Dan Sinclair1770c022016-03-14 14:14:16 -04003520void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
3521 int32_t argc = pArguments->GetLength();
3522 if (argc == 0) {
3523 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003524 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003525 }
3526}
dsinclair5b36f0a2016-07-19 10:56:23 -07003527
Dan Sinclair1770c022016-03-14 14:14:16 -04003528void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
3529 int32_t argc = pArguments->GetLength();
3530 if (argc == 0) {
3531 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003532 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003533 }
3534}
dsinclair5b36f0a2016-07-19 10:56:23 -07003535
Dan Sinclair1770c022016-03-14 14:14:16 -04003536void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
3537 int32_t argc = pArguments->GetLength();
3538 if (argc == 0) {
3539 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003540 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003541 }
3542}
dsinclair5b36f0a2016-07-19 10:56:23 -07003543
Dan Sinclair1770c022016-03-14 14:14:16 -04003544void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
3545 int32_t argc = pArguments->GetLength();
3546 if (argc == 0) {
3547 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003548 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003549 }
3550}
dsinclair5b36f0a2016-07-19 10:56:23 -07003551
Dan Sinclair1770c022016-03-14 14:14:16 -04003552void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
3553 int32_t argc = pArguments->GetLength();
3554 if (argc == 0) {
3555 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003556 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003557 }
3558}
dsinclair5b36f0a2016-07-19 10:56:23 -07003559
Dan Sinclair1770c022016-03-14 14:14:16 -04003560void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
3561 int32_t argc = pArguments->GetLength();
3562 if (argc == 0) {
3563 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003564 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003565 }
3566}
dsinclair5b36f0a2016-07-19 10:56:23 -07003567
Dan Sinclair1770c022016-03-14 14:14:16 -04003568void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
3569 int32_t argc = pArguments->GetLength();
3570 if (argc == 0) {
3571 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003572 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003573 }
3574}
dsinclair5b36f0a2016-07-19 10:56:23 -07003575
Dan Sinclair1770c022016-03-14 14:14:16 -04003576void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
3577 int32_t argc = pArguments->GetLength();
3578 if (argc == 0) {
3579 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003580 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003581 }
3582}
dsinclair5b36f0a2016-07-19 10:56:23 -07003583
Dan Sinclair1770c022016-03-14 14:14:16 -04003584void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
3585 int32_t argc = pArguments->GetLength();
3586 if (argc == 0) {
3587 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003588 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003589 }
3590}
dsinclair5b36f0a2016-07-19 10:56:23 -07003591
Dan Sinclair1770c022016-03-14 14:14:16 -04003592void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
3593 int32_t argc = pArguments->GetLength();
3594 if (argc == 0) {
3595 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003596 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003597 }
3598}
dsinclair5b36f0a2016-07-19 10:56:23 -07003599
Dan Sinclair1770c022016-03-14 14:14:16 -04003600void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
3601 int32_t argc = pArguments->GetLength();
3602 if (argc == 0) {
3603 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003604 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003605 }
3606}
dsinclair5b36f0a2016-07-19 10:56:23 -07003607
Dan Sinclair1770c022016-03-14 14:14:16 -04003608void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
3609 int32_t argc = pArguments->GetLength();
3610 if (argc == 0) {
3611 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003612 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003613 }
3614}
dsinclair5b36f0a2016-07-19 10:56:23 -07003615
Dan Sinclair1770c022016-03-14 14:14:16 -04003616void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
3617 int32_t argc = pArguments->GetLength();
3618 if (argc == 0) {
3619 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003620 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003621 }
3622}
dsinclair5b36f0a2016-07-19 10:56:23 -07003623
Dan Sinclair1770c022016-03-14 14:14:16 -04003624void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
3625 int32_t argc = pArguments->GetLength();
3626 if (argc == 0) {
3627 } else {
dsinclair2235b7b2016-06-02 07:42:25 -07003628 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003629 }
3630}
dsinclair5b36f0a2016-07-19 10:56:23 -07003631
dsinclair12a6b0c2016-05-26 11:14:08 -07003632void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04003633 FX_BOOL bSetting,
3634 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003635
dsinclair12a6b0c2016-05-26 11:14:08 -07003636void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04003637 FX_BOOL bSetting,
3638 XFA_ATTRIBUTE eAttribute) {
3639 if (!bSetting) {
3640 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003641 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003642 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003643 }
3644}
dsinclair5b36f0a2016-07-19 10:56:23 -07003645
dsinclair12a6b0c2016-05-26 11:14:08 -07003646void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04003647 FX_BOOL bSetting,
3648 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003649
dsinclair12a6b0c2016-05-26 11:14:08 -07003650void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04003651 FX_BOOL bSetting,
3652 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003653
dsinclair12a6b0c2016-05-26 11:14:08 -07003654void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04003655 FX_BOOL bSetting,
3656 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003657
dsinclair12a6b0c2016-05-26 11:14:08 -07003658void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04003659 FX_BOOL bSetting,
3660 XFA_ATTRIBUTE eAttribute) {
3661 if (bSetting) {
dsinclair2235b7b2016-06-02 07:42:25 -07003662 ThrowException(XFA_IDS_INVAlID_PROP_SET);
Dan Sinclair1770c022016-03-14 14:14:16 -04003663 return;
3664 }
dsinclairf27aeec2016-06-07 19:36:18 -07003665 pValue->SetString(FX_UTF8Encode(FX_WSTRC(L"0")).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003666}
dsinclair5b36f0a2016-07-19 10:56:23 -07003667
dsinclair12a6b0c2016-05-26 11:14:08 -07003668void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04003669 FX_BOOL bSetting,
3670 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003671
Dan Sinclair1770c022016-03-14 14:14:16 -04003672FX_BOOL CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, FX_BOOL bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003673 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003674 return HasMapModuleKey(pKey, bCanInherit);
3675}
dsinclair5b36f0a2016-07-19 10:56:23 -07003676
Dan Sinclair1770c022016-03-14 14:14:16 -04003677FX_BOOL CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3678 const CFX_WideStringC& wsValue,
thestigb1a59592016-04-14 18:29:56 -07003679 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003680 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003681 if (!pAttr)
Dan Sinclair1770c022016-03-14 14:14:16 -04003682 return FALSE;
weili44f8faf2016-06-01 14:03:56 -07003683
Dan Sinclair1770c022016-03-14 14:14:16 -04003684 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3685 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3686 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003687 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003688 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3689 }
3690 switch (eType) {
3691 case XFA_ATTRIBUTETYPE_Enum: {
3692 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3693 return SetEnum(pAttr->eName,
3694 pEnum ? pEnum->eName
3695 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3696 bNotify);
3697 } break;
3698 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003699 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003700 case XFA_ATTRIBUTETYPE_Boolean:
3701 return SetBoolean(pAttr->eName, wsValue != FX_WSTRC(L"0"), bNotify);
3702 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003703 return SetInteger(pAttr->eName,
3704 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3705 wsValue.GetLength(), nullptr)),
3706 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003707 case XFA_ATTRIBUTETYPE_Measure:
3708 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3709 default:
3710 break;
3711 }
3712 return FALSE;
3713}
dsinclair5b36f0a2016-07-19 10:56:23 -07003714
Dan Sinclair1770c022016-03-14 14:14:16 -04003715FX_BOOL CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3716 CFX_WideString& wsValue,
3717 FX_BOOL bUseDefault) {
3718 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003719 if (!pAttr) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003720 return FALSE;
3721 }
3722 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3723 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3724 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003725 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003726 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3727 }
3728 switch (eType) {
3729 case XFA_ATTRIBUTETYPE_Enum: {
3730 XFA_ATTRIBUTEENUM eValue;
3731 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
3732 return FALSE;
3733 }
dsinclair9eb0db12016-07-21 12:01:39 -07003734 wsValue = GetAttributeEnumByID(eValue)->pName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003735 return TRUE;
3736 } break;
3737 case XFA_ATTRIBUTETYPE_Cdata: {
3738 CFX_WideStringC wsValueC;
3739 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
3740 return FALSE;
3741 }
3742 wsValue = wsValueC;
3743 return TRUE;
3744 } break;
3745 case XFA_ATTRIBUTETYPE_Boolean: {
3746 FX_BOOL bValue;
3747 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
3748 return FALSE;
3749 }
3750 wsValue = bValue ? FX_WSTRC(L"1") : FX_WSTRC(L"0");
3751 return TRUE;
3752 } break;
3753 case XFA_ATTRIBUTETYPE_Integer: {
3754 int32_t iValue;
3755 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
3756 return FALSE;
3757 }
3758 wsValue.Format(L"%d", iValue);
3759 return TRUE;
3760 } break;
3761 case XFA_ATTRIBUTETYPE_Measure: {
3762 CXFA_Measurement mValue;
3763 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
3764 return FALSE;
3765 }
3766 mValue.ToString(wsValue);
3767 return TRUE;
3768 } break;
3769 default:
3770 break;
3771 }
3772 return FALSE;
3773}
dsinclair5b36f0a2016-07-19 10:56:23 -07003774
Dan Sinclair1770c022016-03-14 14:14:16 -04003775FX_BOOL CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3776 const CFX_WideStringC& wsValue,
thestigb1a59592016-04-14 18:29:56 -07003777 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003778 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3779 if (pAttributeInfo) {
3780 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3781 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003782 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003783 SetMapModuleString(pKey, wsValue);
3784 return TRUE;
3785}
dsinclair5b36f0a2016-07-19 10:56:23 -07003786
Dan Sinclair1770c022016-03-14 14:14:16 -04003787FX_BOOL CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3788 CFX_WideString& wsValue,
3789 FX_BOOL bUseDefault) {
3790 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3791 if (pAttributeInfo) {
3792 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3793 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003794 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003795 CFX_WideStringC wsValueC;
3796 if (GetMapModuleString(pKey, wsValueC)) {
3797 wsValue = wsValueC;
3798 }
3799 return TRUE;
3800}
dsinclair5b36f0a2016-07-19 10:56:23 -07003801
Dan Sinclair1770c022016-03-14 14:14:16 -04003802FX_BOOL CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003803 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003804 RemoveMapModuleKey(pKey);
3805 return TRUE;
3806}
dsinclair5b36f0a2016-07-19 10:56:23 -07003807
Dan Sinclair1770c022016-03-14 14:14:16 -04003808FX_BOOL CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3809 FX_BOOL& bValue,
3810 FX_BOOL bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003811 void* pValue = nullptr;
3812 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
Dan Sinclair1770c022016-03-14 14:14:16 -04003813 return FALSE;
Dan Sinclair1770c022016-03-14 14:14:16 -04003814 bValue = (FX_BOOL)(uintptr_t)pValue;
3815 return TRUE;
3816}
dsinclair5b36f0a2016-07-19 10:56:23 -07003817
Dan Sinclair1770c022016-03-14 14:14:16 -04003818FX_BOOL CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3819 int32_t& iValue,
3820 FX_BOOL bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003821 void* pValue = nullptr;
3822 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
Dan Sinclair1770c022016-03-14 14:14:16 -04003823 return FALSE;
Dan Sinclair1770c022016-03-14 14:14:16 -04003824 iValue = (int32_t)(uintptr_t)pValue;
3825 return TRUE;
3826}
dsinclair5b36f0a2016-07-19 10:56:23 -07003827
Dan Sinclair1770c022016-03-14 14:14:16 -04003828FX_BOOL CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3829 XFA_ATTRIBUTEENUM& eValue,
3830 FX_BOOL bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003831 void* pValue = nullptr;
3832 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
Dan Sinclair1770c022016-03-14 14:14:16 -04003833 return FALSE;
Dan Sinclair1770c022016-03-14 14:14:16 -04003834 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
3835 return TRUE;
3836}
thestigb1a59592016-04-14 18:29:56 -07003837
Dan Sinclair1770c022016-03-14 14:14:16 -04003838FX_BOOL CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3839 CXFA_Measurement mValue,
thestigb1a59592016-04-14 18:29:56 -07003840 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003841 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003842 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003843 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
thestigb1a59592016-04-14 18:29:56 -07003844 OnChanged(eAttr, bNotify, FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04003845 return TRUE;
3846}
thestigb1a59592016-04-14 18:29:56 -07003847
Dan Sinclair1770c022016-03-14 14:14:16 -04003848FX_BOOL CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3849 CXFA_Measurement& mValue,
3850 FX_BOOL bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003851 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003852 void* pValue;
3853 int32_t iBytes;
3854 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
3855 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
3856 return TRUE;
3857 }
3858 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003859 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003860 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
3861 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
3862 return TRUE;
3863 }
3864 return FALSE;
3865}
3866
3867CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3868 CXFA_Measurement mValue;
3869 return TryMeasure(eAttr, mValue, TRUE) ? mValue : CXFA_Measurement();
3870}
3871
3872FX_BOOL CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3873 const CFX_WideString& wsValue,
thestigb1a59592016-04-14 18:29:56 -07003874 bool bNotify,
Dan Sinclair1770c022016-03-14 14:14:16 -04003875 FX_BOOL bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003876 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003877 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003878 if (eAttr == XFA_ATTRIBUTE_Value) {
3879 CFX_WideString* pClone = new CFX_WideString(wsValue);
3880 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3881 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003882 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003883 if (eAttr == XFA_ATTRIBUTE_Name)
3884 UpdateNameHash();
3885 }
thestigb1a59592016-04-14 18:29:56 -07003886 OnChanged(eAttr, bNotify, bScriptModify);
3887
3888 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3889 eAttr == XFA_ATTRIBUTE_BindingNode) {
3890 return TRUE;
3891 }
3892
dsinclair070fcdf2016-06-22 22:04:54 -07003893 if (eAttr == XFA_ATTRIBUTE_Name &&
3894 (m_elementType == XFA_Element::DataValue ||
3895 m_elementType == XFA_Element::DataGroup)) {
thestigb1a59592016-04-14 18:29:56 -07003896 return TRUE;
3897 }
3898
3899 if (eAttr == XFA_ATTRIBUTE_Value) {
3900 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3901 switch (eXMLType) {
3902 case FDE_XMLNODE_Element:
3903 if (IsAttributeInXML()) {
3904 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003905 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3906 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003907 } else {
3908 FX_BOOL bDeleteChildren = TRUE;
3909 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3910 for (CXFA_Node* pChildDataNode =
3911 GetNodeItem(XFA_NODEITEM_FirstChild);
3912 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3913 XFA_NODEITEM_NextSibling)) {
3914 CXFA_NodeArray formNodes;
3915 if (pChildDataNode->GetBindItems(formNodes) > 0) {
3916 bDeleteChildren = FALSE;
3917 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003918 }
3919 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003920 }
thestigb1a59592016-04-14 18:29:56 -07003921 if (bDeleteChildren) {
3922 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3923 }
3924 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3925 }
3926 break;
3927 case FDE_XMLNODE_Text:
3928 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3929 break;
3930 default:
dsinclair43854a52016-04-27 12:26:00 -07003931 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003932 }
thestigb1a59592016-04-14 18:29:56 -07003933 return TRUE;
3934 }
3935
3936 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3937 if (pInfo) {
dsinclair43854a52016-04-27 12:26:00 -07003938 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003939 CFX_WideString wsAttrName = pInfo->pName;
3940 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
3941 wsAttrName = FX_WSTRC(L"xfa:") + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003942 }
thestigb1a59592016-04-14 18:29:56 -07003943 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003944 }
3945 return TRUE;
3946}
thestigb1a59592016-04-14 18:29:56 -07003947
Dan Sinclair1770c022016-03-14 14:14:16 -04003948FX_BOOL CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3949 const CFX_WideString& wsXMLValue,
thestigb1a59592016-04-14 18:29:56 -07003950 bool bNotify,
Dan Sinclair1770c022016-03-14 14:14:16 -04003951 FX_BOOL bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003952 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003953 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003954 CFX_WideString* pClone = new CFX_WideString(wsValue);
3955 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003956 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003957 if (IsNeedSavingXMLNode()) {
3958 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3959 switch (eXMLType) {
3960 case FDE_XMLNODE_Element:
3961 if (IsAttributeInXML()) {
dsinclairae95f762016-03-29 16:58:29 -07003962 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003963 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3964 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003965 } else {
3966 FX_BOOL bDeleteChildren = TRUE;
3967 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3968 for (CXFA_Node* pChildDataNode =
3969 GetNodeItem(XFA_NODEITEM_FirstChild);
3970 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3971 XFA_NODEITEM_NextSibling)) {
3972 CXFA_NodeArray formNodes;
3973 if (pChildDataNode->GetBindItems(formNodes) > 0) {
3974 bDeleteChildren = FALSE;
3975 break;
3976 }
3977 }
3978 }
3979 if (bDeleteChildren) {
dsinclairae95f762016-03-29 16:58:29 -07003980 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003981 }
dsinclairae95f762016-03-29 16:58:29 -07003982 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003983 }
3984 break;
3985 case FDE_XMLNODE_Text:
dsinclairae95f762016-03-29 16:58:29 -07003986 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003987 break;
3988 default:
dsinclair43854a52016-04-27 12:26:00 -07003989 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003990 }
3991 }
3992 return TRUE;
3993}
dsinclair5b36f0a2016-07-19 10:56:23 -07003994
Dan Sinclair1770c022016-03-14 14:14:16 -04003995FX_BOOL CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3996 CFX_WideString& wsValue,
3997 FX_BOOL bUseDefault,
3998 FX_BOOL bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003999 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004000 if (eAttr == XFA_ATTRIBUTE_Value) {
4001 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
4002 if (pStr) {
4003 wsValue = *pStr;
4004 return TRUE;
4005 }
4006 } else {
4007 CFX_WideStringC wsValueC;
4008 if (GetMapModuleString(pKey, wsValueC)) {
4009 wsValue = wsValueC;
4010 return TRUE;
4011 }
4012 }
4013 if (!bUseDefault) {
4014 return FALSE;
4015 }
weili44f8faf2016-06-01 14:03:56 -07004016 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07004017 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04004018 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
4019 wsValue = (const FX_WCHAR*)pValue;
4020 return TRUE;
4021 }
4022 return FALSE;
4023}
dsinclair5b36f0a2016-07-19 10:56:23 -07004024
Dan Sinclair1770c022016-03-14 14:14:16 -04004025FX_BOOL CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
4026 CFX_WideStringC& wsValue,
4027 FX_BOOL bUseDefault,
4028 FX_BOOL bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004029 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004030 if (eAttr == XFA_ATTRIBUTE_Value) {
4031 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
4032 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07004033 wsValue = pStr->AsStringC();
Dan Sinclair1770c022016-03-14 14:14:16 -04004034 return TRUE;
4035 }
4036 } else {
4037 if (GetMapModuleString(pKey, wsValue)) {
4038 return TRUE;
4039 }
4040 }
4041 if (!bUseDefault) {
4042 return FALSE;
4043 }
weili44f8faf2016-06-01 14:03:56 -07004044 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07004045 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04004046 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
4047 wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue;
4048 return TRUE;
4049 }
4050 return FALSE;
4051}
dsinclair5b36f0a2016-07-19 10:56:23 -07004052
Dan Sinclair1770c022016-03-14 14:14:16 -04004053FX_BOOL CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
4054 void* pData,
4055 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004056 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004057 return SetUserData(pKey, pData, pCallbackInfo);
4058}
dsinclair5b36f0a2016-07-19 10:56:23 -07004059
Dan Sinclair1770c022016-03-14 14:14:16 -04004060FX_BOOL CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004061 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004062 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07004063 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04004064}
dsinclair5b36f0a2016-07-19 10:56:23 -07004065
Dan Sinclair1770c022016-03-14 14:14:16 -04004066FX_BOOL CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
4067 XFA_ATTRIBUTETYPE eType,
4068 void* pValue,
thestigb1a59592016-04-14 18:29:56 -07004069 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004070 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07004071 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004072 SetMapModuleValue(pKey, pValue);
thestigb1a59592016-04-14 18:29:56 -07004073 OnChanged(eAttr, bNotify, FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04004074 if (IsNeedSavingXMLNode()) {
dsinclair43854a52016-04-27 12:26:00 -07004075 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004076 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
4077 if (pInfo) {
4078 switch (eType) {
4079 case XFA_ATTRIBUTETYPE_Enum:
dsinclairae95f762016-03-29 16:58:29 -07004080 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004081 ->SetString(
4082 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07004083 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04004084 ->pName);
4085 break;
4086 case XFA_ATTRIBUTETYPE_Boolean:
dsinclairae95f762016-03-29 16:58:29 -07004087 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07004088 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04004089 break;
4090 case XFA_ATTRIBUTETYPE_Integer:
dsinclairae95f762016-03-29 16:58:29 -07004091 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04004092 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue);
4093 break;
4094 default:
dsinclair43854a52016-04-27 12:26:00 -07004095 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04004096 }
4097 }
4098 }
4099 return TRUE;
4100}
dsinclair5b36f0a2016-07-19 10:56:23 -07004101
Dan Sinclair1770c022016-03-14 14:14:16 -04004102FX_BOOL CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
4103 XFA_ATTRIBUTETYPE eType,
4104 FX_BOOL bUseDefault,
4105 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004106 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004107 if (GetMapModuleValue(pKey, pValue)) {
4108 return TRUE;
4109 }
4110 if (!bUseDefault) {
4111 return FALSE;
4112 }
dsinclair070fcdf2016-06-22 22:04:54 -07004113 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004114 m_ePacket);
4115}
dsinclair5b36f0a2016-07-19 10:56:23 -07004116
Dan Sinclair1770c022016-03-14 14:14:16 -04004117FX_BOOL CXFA_Node::SetUserData(void* pKey,
4118 void* pData,
4119 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4120 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4121 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
4122 return TRUE;
4123}
dsinclair5b36f0a2016-07-19 10:56:23 -07004124
Dan Sinclair1770c022016-03-14 14:14:16 -04004125FX_BOOL CXFA_Node::TryUserData(void* pKey, void*& pData, FX_BOOL bProtoAlso) {
4126 int32_t iBytes = 0;
4127 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
4128 return FALSE;
4129 }
4130 return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes);
4131}
dsinclair5b36f0a2016-07-19 10:56:23 -07004132
Dan Sinclair1770c022016-03-14 14:14:16 -04004133FX_BOOL CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4134 const CFX_WideString& wsXMLValue,
thestigb1a59592016-04-14 18:29:56 -07004135 bool bNotify,
Dan Sinclair1770c022016-03-14 14:14:16 -04004136 FX_BOOL bScriptModify,
4137 FX_BOOL bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004138 CXFA_Node* pNode = nullptr;
4139 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004140 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004141 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004142 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004143 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004144 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004145 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004146 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004147 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
4148 bScriptModify, FALSE);
4149 CXFA_Node* pBind = GetBindData();
4150 if (bSyncData && pBind) {
4151 CFX_WideStringArray wsSaveTextArray;
4152 int32_t iSize = 0;
4153 if (!wsContent.IsEmpty()) {
4154 int32_t iStart = 0;
4155 int32_t iLength = wsContent.GetLength();
4156 int32_t iEnd = wsContent.Find(L'\n', iStart);
4157 iEnd = (iEnd == -1) ? iLength : iEnd;
4158 while (iEnd >= iStart) {
4159 wsSaveTextArray.Add(wsContent.Mid(iStart, iEnd - iStart));
4160 iStart = iEnd + 1;
4161 if (iStart >= iLength) {
4162 break;
4163 }
4164 iEnd = wsContent.Find(L'\n', iStart);
4165 if (iEnd < 0) {
4166 wsSaveTextArray.Add(wsContent.Mid(iStart, iLength - iStart));
4167 }
4168 }
4169 iSize = wsSaveTextArray.GetSize();
4170 }
4171 if (iSize == 0) {
4172 while (CXFA_Node* pChildNode =
4173 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4174 pBind->RemoveChild(pChildNode);
4175 }
4176 } else {
4177 CXFA_NodeArray valueNodes;
4178 int32_t iDatas = pBind->GetNodeList(
dsinclair56a8b192016-06-21 14:15:25 -07004179 valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004180 if (iDatas < iSize) {
4181 int32_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004182 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004183 while (iAddNodes-- > 0) {
4184 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004185 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004186 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004187 pValueNodes->CreateXMLMappingNode();
4188 pBind->InsertChild(pValueNodes);
4189 }
weili44f8faf2016-06-01 14:03:56 -07004190 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004191 } else if (iDatas > iSize) {
4192 int32_t iDelNodes = iDatas - iSize;
4193 while (iDelNodes-- > 0) {
4194 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4195 }
4196 }
4197 int32_t i = 0;
4198 for (CXFA_Node* pValueNode =
4199 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4200 pValueNode; pValueNode = pValueNode->GetNodeItem(
4201 XFA_NODEITEM_NextSibling)) {
4202 pValueNode->SetAttributeValue(wsSaveTextArray[i],
4203 wsSaveTextArray[i], FALSE);
4204 i++;
4205 }
4206 }
4207 CXFA_NodeArray nodeArray;
4208 pBind->GetBindItems(nodeArray);
4209 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004210 if (nodeArray[i] != this) {
4211 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
4212 bScriptModify, FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04004213 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004214 }
4215 }
4216 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004217 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004218 pNode = this;
4219 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004220 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004221 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004222 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004223 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
4224 bScriptModify, FALSE);
4225 }
4226 pBindNode = GetBindData();
4227 if (pBindNode && bSyncData) {
4228 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
4229 bScriptModify, FALSE);
4230 CXFA_NodeArray nodeArray;
4231 pBindNode->GetBindItems(nodeArray);
4232 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004233 if (nodeArray[i] != this) {
4234 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true,
4235 FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04004236 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004237 }
4238 }
weili44f8faf2016-06-01 14:03:56 -07004239 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004240 break;
4241 }
dsinclairc5a8f212016-06-20 11:11:12 -07004242 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004243 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004244 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004245 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE);
tsepez9f2970c2016-04-01 10:23:04 -07004246 if (wsContentType == FX_WSTRC(L"text/html")) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004247 wsContentType = FX_WSTRC(L"");
tsepez4c3debb2016-04-08 12:20:38 -07004248 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004249 }
4250 }
4251 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4252 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004253 pContentRawDataNode = CreateSamePacketNode(
dsinclair56a8b192016-06-21 14:15:25 -07004254 (wsContentType == FX_WSTRC(L"text/xml")) ? XFA_Element::Sharpxml
4255 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004256 InsertChild(pContentRawDataNode);
4257 }
4258 return pContentRawDataNode->SetScriptContent(
4259 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4260 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004261 case XFA_ObjectType::NodeC:
4262 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004263 pNode = this;
4264 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004265 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004266 pNode = this;
4267 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4268 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4269 if (pParent) {
4270 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4271 }
dsinclair070fcdf2016-06-22 22:04:54 -07004272 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004273 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4274 if (pParent && pParent->IsContainerNode()) {
4275 pBindNode = pParent->GetBindData();
4276 if (pBindNode) {
4277 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
4278 bScriptModify, FALSE);
4279 }
4280 }
4281 }
4282 }
4283 break;
4284 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004285 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004286 pNode = this;
4287 pBindNode = this;
4288 }
4289 break;
4290 }
4291 if (pNode) {
4292 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4293 if (pBindNode && bSyncData) {
4294 CXFA_NodeArray nodeArray;
4295 pBindNode->GetBindItems(nodeArray);
4296 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
weilidb444d22016-06-02 15:48:15 -07004297 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
4298 bScriptModify, FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04004299 }
4300 }
4301 return TRUE;
4302 }
4303 return FALSE;
4304}
dsinclair5b36f0a2016-07-19 10:56:23 -07004305
Dan Sinclair1770c022016-03-14 14:14:16 -04004306FX_BOOL CXFA_Node::SetContent(const CFX_WideString& wsContent,
4307 const CFX_WideString& wsXMLValue,
thestigb1a59592016-04-14 18:29:56 -07004308 bool bNotify,
Dan Sinclair1770c022016-03-14 14:14:16 -04004309 FX_BOOL bScriptModify,
4310 FX_BOOL bSyncData) {
4311 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4312 bSyncData);
4313}
dsinclair5b36f0a2016-07-19 10:56:23 -07004314
Dan Sinclair1770c022016-03-14 14:14:16 -04004315CFX_WideString CXFA_Node::GetScriptContent(FX_BOOL bScriptModify) {
4316 CFX_WideString wsContent;
4317 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4318}
dsinclair5b36f0a2016-07-19 10:56:23 -07004319
Dan Sinclair1770c022016-03-14 14:14:16 -04004320CFX_WideString CXFA_Node::GetContent() {
4321 return GetScriptContent();
4322}
dsinclair5b36f0a2016-07-19 10:56:23 -07004323
Dan Sinclair1770c022016-03-14 14:14:16 -04004324FX_BOOL CXFA_Node::TryContent(CFX_WideString& wsContent,
4325 FX_BOOL bScriptModify,
4326 FX_BOOL bProto) {
weili44f8faf2016-06-01 14:03:56 -07004327 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004328 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004329 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004330 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004331 pNode = this;
4332 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004333 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004334 if (!pValue) {
4335 return FALSE;
4336 }
4337 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4338 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
4339 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType,
4340 FX_WSTRC(L"text/xml"));
4341 }
4342 return pChildValue
4343 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
4344 : FALSE;
4345 }
4346 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004347 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004348 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4349 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004350 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004351 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004352 CFX_WideString wsContentType;
4353 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE);
tsepez9f2970c2016-04-01 10:23:04 -07004354 if (wsContentType == FX_WSTRC(L"text/html")) {
dsinclair56a8b192016-06-21 14:15:25 -07004355 element = XFA_Element::SharpxHTML;
tsepez9f2970c2016-04-01 10:23:04 -07004356 } else if (wsContentType == FX_WSTRC(L"text/xml")) {
dsinclair56a8b192016-06-21 14:15:25 -07004357 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004358 }
4359 }
4360 pContentRawDataNode = CreateSamePacketNode(element);
4361 InsertChild(pContentRawDataNode);
4362 }
4363 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4364 }
dsinclairc5a8f212016-06-20 11:11:12 -07004365 case XFA_ObjectType::NodeC:
4366 case XFA_ObjectType::NodeV:
4367 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004368 pNode = this;
4369 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004370 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004371 pNode = this;
4372 }
4373 break;
4374 }
4375 if (pNode) {
4376 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004377 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004378 if (pScriptContext) {
4379 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4380 }
4381 }
4382 return TryCData(XFA_ATTRIBUTE_Value, wsContent, FALSE, bProto);
4383 }
4384 return FALSE;
4385}
dsinclair5b36f0a2016-07-19 10:56:23 -07004386
Dan Sinclair1770c022016-03-14 14:14:16 -04004387CXFA_Node* CXFA_Node::GetModelNode() {
4388 switch (GetPacketID()) {
4389 case XFA_XDPPACKET_XDP:
4390 return m_pDocument->GetRoot();
4391 case XFA_XDPPACKET_Config:
4392 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4393 case XFA_XDPPACKET_Template:
4394 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4395 case XFA_XDPPACKET_Form:
4396 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4397 case XFA_XDPPACKET_Datasets:
4398 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4399 case XFA_XDPPACKET_LocaleSet:
4400 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4401 case XFA_XDPPACKET_ConnectionSet:
4402 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4403 case XFA_XDPPACKET_SourceSet:
4404 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4405 case XFA_XDPPACKET_Xdc:
4406 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4407 default:
4408 return this;
4409 }
4410}
dsinclair5b36f0a2016-07-19 10:56:23 -07004411
Dan Sinclair1770c022016-03-14 14:14:16 -04004412FX_BOOL CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004413 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004414 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
dsinclairae95f762016-03-29 16:58:29 -07004415 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004416 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
4417 return FALSE;
4418 }
dsinclairae95f762016-03-29 16:58:29 -07004419 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004420 return TRUE;
4421 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
dsinclairae95f762016-03-29 16:58:29 -07004422 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004423 if (!pXMLNode) {
4424 return FALSE;
4425 }
4426 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
4427 return TRUE;
4428 }
dsinclair070fcdf2016-06-22 22:04:54 -07004429 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004430 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4431 return XFA_FDEExtension_ResolveNamespaceQualifier(
dsinclairae95f762016-03-29 16:58:29 -07004432 static_cast<CFDE_XMLElement*>(pXMLNode),
4433 GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004434 }
dsinclairae95f762016-03-29 16:58:29 -07004435 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004436 return TRUE;
4437 } else {
4438 CXFA_Node* pModelNode = GetModelNode();
4439 return pModelNode->TryNamespace(wsNamespace);
4440 }
4441}
dsinclair5b36f0a2016-07-19 10:56:23 -07004442
Dan Sinclair1770c022016-03-14 14:14:16 -04004443CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004444 XFA_Element eProperty,
Dan Sinclair1770c022016-03-14 14:14:16 -04004445 FX_BOOL bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004446 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004447 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004448 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004449 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004450 if (!pProperty || index >= pProperty->uOccur)
4451 return nullptr;
4452
Dan Sinclair1770c022016-03-14 14:14:16 -04004453 CXFA_Node* pNode = m_pChild;
4454 int32_t iCount = 0;
4455 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004456 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004457 iCount++;
4458 if (iCount > index) {
4459 return pNode;
4460 }
4461 }
4462 }
weili44f8faf2016-06-01 14:03:56 -07004463 if (!bCreateProperty)
4464 return nullptr;
4465
Dan Sinclair1770c022016-03-14 14:14:16 -04004466 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4467 pNode = m_pChild;
4468 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4469 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004470 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004471 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4472 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004473 }
4474 }
dsinclaira1b07722016-07-11 08:20:58 -07004475
Dan Sinclair1770c022016-03-14 14:14:16 -04004476 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004477 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004478 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004479 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004480 if (!pNewNode)
4481 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004482 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004483 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004484 }
4485 return pNewNode;
4486}
dsinclair5b36f0a2016-07-19 10:56:23 -07004487
dsinclair41cb62e2016-06-23 09:20:32 -07004488int32_t CXFA_Node::CountChildren(XFA_Element eType, FX_BOOL bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004489 CXFA_Node* pNode = m_pChild;
4490 int32_t iCount = 0;
4491 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004492 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004493 if (bOnlyChild) {
4494 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004495 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004496 if (pProperty) {
4497 continue;
4498 }
4499 }
4500 iCount++;
4501 }
4502 }
4503 return iCount;
4504}
dsinclair5b36f0a2016-07-19 10:56:23 -07004505
Dan Sinclair1770c022016-03-14 14:14:16 -04004506CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004507 XFA_Element eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004508 FX_BOOL bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004509 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004510 CXFA_Node* pNode = m_pChild;
4511 int32_t iCount = 0;
4512 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004513 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004514 if (bOnlyChild) {
4515 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004516 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004517 if (pProperty) {
4518 continue;
4519 }
4520 }
4521 iCount++;
4522 if (iCount > index) {
4523 return pNode;
4524 }
4525 }
4526 }
weili44f8faf2016-06-01 14:03:56 -07004527 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004528}
dsinclair5b36f0a2016-07-19 10:56:23 -07004529
Dan Sinclair1770c022016-03-14 14:14:16 -04004530int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4531 ASSERT(!pNode->m_pNext);
4532 pNode->m_pParent = this;
Wei Li5fe7ae72016-05-04 21:13:15 -07004533 FX_BOOL ret = m_pDocument->RemovePurgeNode(pNode);
4534 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004535 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004536
weili44f8faf2016-06-01 14:03:56 -07004537 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004538 if (index > 0) {
4539 return -1;
4540 }
4541 pNode->m_pNext = m_pChild;
4542 m_pChild = pNode;
4543 index = 0;
4544 } else if (index < 0) {
4545 m_pLastChild->m_pNext = pNode;
4546 } else {
4547 CXFA_Node* pPrev = m_pChild;
4548 int32_t iCount = 0;
4549 while (++iCount != index && pPrev->m_pNext) {
4550 pPrev = pPrev->m_pNext;
4551 }
4552 if (index > 0 && index != iCount) {
4553 return -1;
4554 }
4555 pNode->m_pNext = pPrev->m_pNext;
4556 pPrev->m_pNext = pNode;
4557 index = iCount;
4558 }
weili44f8faf2016-06-01 14:03:56 -07004559 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004560 m_pLastChild = pNode;
4561 }
4562 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004563 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004564 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004565 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004566 if (pNotify)
4567 pNotify->OnChildAdded(this);
4568
Dan Sinclair1770c022016-03-14 14:14:16 -04004569 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004570 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004571 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004572 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004573 }
4574 return index;
4575}
weili6e1ae862016-05-04 18:25:27 -07004576
Dan Sinclair1770c022016-03-14 14:14:16 -04004577FX_BOOL CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
4578 if (!pNode || pNode->m_pParent ||
4579 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004580 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004581 return FALSE;
4582 }
Wei Li5fe7ae72016-05-04 21:13:15 -07004583 FX_BOOL ret = m_pDocument->RemovePurgeNode(pNode);
4584 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004585 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004586
4587 int32_t nIndex = -1;
4588 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004589 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004590 pNode->m_pNext = m_pChild;
4591 m_pChild = pNode;
4592 nIndex = 0;
4593 } else if (!pBeforeNode) {
4594 pNode->m_pNext = m_pLastChild->m_pNext;
4595 m_pLastChild->m_pNext = pNode;
4596 } else {
4597 nIndex = 1;
4598 CXFA_Node* pPrev = m_pChild;
4599 while (pPrev->m_pNext != pBeforeNode) {
4600 pPrev = pPrev->m_pNext;
4601 nIndex++;
4602 }
4603 pNode->m_pNext = pPrev->m_pNext;
4604 pPrev->m_pNext = pNode;
4605 }
weili44f8faf2016-06-01 14:03:56 -07004606 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004607 m_pLastChild = pNode;
4608 }
4609 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004610 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004611 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004612 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004613 if (pNotify)
4614 pNotify->OnChildAdded(this);
4615
Dan Sinclair1770c022016-03-14 14:14:16 -04004616 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004617 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004618 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004619 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004620 }
4621 return TRUE;
4622}
dsinclair5b36f0a2016-07-19 10:56:23 -07004623
Dan Sinclair1770c022016-03-14 14:14:16 -04004624CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4625 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004626 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004627 }
4628 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4629 pSibling = pSibling->m_pNext) {
4630 if (pSibling->m_pNext == this) {
4631 return pSibling;
4632 }
4633 }
weili44f8faf2016-06-01 14:03:56 -07004634 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004635}
dsinclair5b36f0a2016-07-19 10:56:23 -07004636
thestigb1a59592016-04-14 18:29:56 -07004637FX_BOOL CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004638 if (!pNode || pNode->m_pParent != this) {
dsinclair43854a52016-04-27 12:26:00 -07004639 ASSERT(FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -04004640 return FALSE;
4641 }
4642 if (m_pChild == pNode) {
4643 m_pChild = pNode->m_pNext;
4644 if (m_pLastChild == pNode) {
4645 m_pLastChild = pNode->m_pNext;
4646 }
weili44f8faf2016-06-01 14:03:56 -07004647 pNode->m_pNext = nullptr;
4648 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004649 } else {
4650 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4651 pPrev->m_pNext = pNode->m_pNext;
4652 if (m_pLastChild == pNode) {
4653 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4654 }
weili44f8faf2016-06-01 14:03:56 -07004655 pNode->m_pNext = nullptr;
4656 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004657 }
weili44f8faf2016-06-01 14:03:56 -07004658 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004659 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004660 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004661 m_pDocument->AddPurgeNode(pNode);
4662 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4663 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004664 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4665 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004666 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07004667 CFDE_XMLElement* pXMLElement =
4668 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004669 CFX_WideStringC wsAttributeName =
4670 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004671 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004672 }
4673 CFX_WideString wsName;
4674 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, FALSE);
dsinclairae95f762016-03-29 16:58:29 -07004675 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004676 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4677 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004678 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004679 }
4680 pNode->m_pXMLNode = pNewXMLElement;
4681 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4682 } else {
4683 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4684 }
dsinclairc5a8f212016-06-20 11:11:12 -07004685 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004686 }
4687 return TRUE;
4688}
dsinclair5b36f0a2016-07-19 10:56:23 -07004689
Dan Sinclair1770c022016-03-14 14:14:16 -04004690CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004691 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004692}
dsinclair5b36f0a2016-07-19 10:56:23 -07004693
tsepez736f28a2016-03-25 14:19:51 -07004694CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004695 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4696 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4697 if (pNode->GetNameHash() == dwNameHash) {
4698 return pNode;
4699 }
4700 }
weili44f8faf2016-06-01 14:03:56 -07004701 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004702}
dsinclair5b36f0a2016-07-19 10:56:23 -07004703
dsinclair41cb62e2016-06-23 09:20:32 -07004704CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004705 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4706 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004707 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004708 return pNode;
4709 }
4710 }
weili44f8faf2016-06-01 14:03:56 -07004711 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004712}
dsinclair5b36f0a2016-07-19 10:56:23 -07004713
tsepez736f28a2016-03-25 14:19:51 -07004714CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004715 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4716 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4717 if (pNode->GetNameHash() == dwNameHash) {
4718 return pNode;
4719 }
4720 }
weili44f8faf2016-06-01 14:03:56 -07004721 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004722}
dsinclair5b36f0a2016-07-19 10:56:23 -07004723
Dan Sinclair1770c022016-03-14 14:14:16 -04004724CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4725 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004726 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004727}
dsinclair5b36f0a2016-07-19 10:56:23 -07004728
dsinclair41cb62e2016-06-23 09:20:32 -07004729CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004730 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4731 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004732 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004733 return pNode;
4734 }
4735 }
weili44f8faf2016-06-01 14:03:56 -07004736 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004737}
dsinclair5b36f0a2016-07-19 10:56:23 -07004738
Dan Sinclair1770c022016-03-14 14:14:16 -04004739int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004740 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004741 if (!pScriptContext) {
4742 return -1;
4743 }
4744 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4745}
dsinclair5b36f0a2016-07-19 10:56:23 -07004746
Dan Sinclair1770c022016-03-14 14:14:16 -04004747int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004748 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004749 if (!pScriptContext) {
4750 return -1;
4751 }
4752 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4753}
dsinclair5b36f0a2016-07-19 10:56:23 -07004754
Dan Sinclair1770c022016-03-14 14:14:16 -04004755void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004756 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004757 if (!pScriptContext) {
4758 return;
4759 }
4760 pScriptContext->GetSomExpression(this, wsSOMExpression);
4761}
dsinclair5b36f0a2016-07-19 10:56:23 -07004762
Dan Sinclair1770c022016-03-14 14:14:16 -04004763CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004764 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004765 if (m_ePacket == XFA_XDPPACKET_Form) {
4766 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004767 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004768 return pInstanceMgr;
4769 }
4770 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4771 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004772 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004773 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004774 pNode->m_dwNameHash != m_dwNameHash) {
4775 break;
4776 }
dsinclair56a8b192016-06-21 14:15:25 -07004777 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004778 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4779 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4780 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4781 wsInstName.Mid(1) == wsName) {
4782 pInstanceMgr = pNode;
4783 }
4784 break;
4785 }
4786 }
4787 }
4788 return pInstanceMgr;
4789}
dsinclair5b36f0a2016-07-19 10:56:23 -07004790
Dan Sinclair1770c022016-03-14 14:14:16 -04004791CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004792 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004793}
dsinclair5b36f0a2016-07-19 10:56:23 -07004794
dsinclairc5a8f212016-06-20 11:11:12 -07004795bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4796 if (m_uNodeFlags & dwFlag)
4797 return true;
4798 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4799 return m_pParent && m_pParent->HasFlag(dwFlag);
4800 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004801}
thestigb1a59592016-04-14 18:29:56 -07004802
4803void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004804 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004805 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004806 if (pNotify) {
4807 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004808 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004809 }
dsinclairc5a8f212016-06-20 11:11:12 -07004810 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004811}
thestigb1a59592016-04-14 18:29:56 -07004812
4813void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004814 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004815}
4816
Dan Sinclair1770c022016-03-14 14:14:16 -04004817FX_BOOL CXFA_Node::IsAttributeInXML() {
4818 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4819}
thestigb1a59592016-04-14 18:29:56 -07004820
4821void CXFA_Node::OnRemoved(bool bNotify) {
4822 if (!bNotify)
4823 return;
4824
dsinclaira1b07722016-07-11 08:20:58 -07004825 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004826 if (pNotify)
4827 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004828}
thestigb1a59592016-04-14 18:29:56 -07004829
4830void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004831 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004832 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004833 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004834 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004835 }
4836 }
4837}
thestigb1a59592016-04-14 18:29:56 -07004838
Dan Sinclair1770c022016-03-14 14:14:16 -04004839void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004840 bool bNotify,
Dan Sinclair1770c022016-03-14 14:14:16 -04004841 FX_BOOL bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004842 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004843 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004844 }
4845}
thestigb1a59592016-04-14 18:29:56 -07004846
Dan Sinclair1770c022016-03-14 14:14:16 -04004847int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004848 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004849 int32_t iRet = XFA_EVENTERROR_NotExist;
4850 const XFA_ExecEventParaInfo* eventParaInfo =
4851 GetEventParaInfoByName(wsEventName);
4852 if (eventParaInfo) {
4853 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004854 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004855 if (!pNotify) {
4856 return iRet;
4857 }
4858 if (validFlags == 1) {
4859 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4860 } else if (validFlags == 2) {
4861 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
4862 FALSE, FALSE);
4863 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004864 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004865 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
4866 FALSE, FALSE);
4867 }
4868 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004869 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004870 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004871 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004872 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004873 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
4874 FALSE, FALSE);
4875 }
4876 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
4877 FALSE, FALSE);
4878 }
4879 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004880 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004881 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
4882 FALSE, FALSE);
4883 }
4884 } else if (validFlags == 6) {
4885 CXFA_WidgetData* pWidgetData = GetWidgetData();
4886 if (pWidgetData) {
4887 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004888 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004889 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
4890 FALSE, FALSE);
4891 }
4892 }
4893 } else if (validFlags == 7) {
4894 CXFA_WidgetData* pWidgetData = GetWidgetData();
4895 if (pWidgetData) {
4896 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004897 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004898 (!pWidgetData->IsListBox())) {
4899 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
4900 FALSE, FALSE);
4901 }
4902 }
4903 }
4904 }
4905 return iRet;
4906}
dsinclair5b36f0a2016-07-19 10:56:23 -07004907
Dan Sinclair1770c022016-03-14 14:14:16 -04004908void CXFA_Node::UpdateNameHash() {
4909 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004910 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004911 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004912 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004913 wsName = GetCData(XFA_ATTRIBUTE_Name);
4914 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004915 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004916 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004917 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004918 }
4919}
dsinclair5b36f0a2016-07-19 10:56:23 -07004920
dsinclairae95f762016-03-29 16:58:29 -07004921CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004922 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004923 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
dsinclairae95f762016-03-29 16:58:29 -07004924 m_pXMLNode = new CFDE_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004925 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004926 }
4927 return m_pXMLNode;
4928}
dsinclair5b36f0a2016-07-19 10:56:23 -07004929
Dan Sinclair1770c022016-03-14 14:14:16 -04004930FX_BOOL CXFA_Node::IsNeedSavingXMLNode() {
4931 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004932 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004933}
4934
4935XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4936 if (!m_pMapModuleData)
4937 m_pMapModuleData = new XFA_MAPMODULEDATA;
4938 return m_pMapModuleData;
4939}
4940
4941XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4942 return m_pMapModuleData;
4943}
4944
4945void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4946 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4947 pModule->m_ValueMap.SetAt(pKey, pValue);
4948}
4949
4950FX_BOOL CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
4951 CXFA_Node* pNode = this;
4952 while (pNode) {
4953 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
4954 if (pModule && pModule->m_ValueMap.Lookup(pKey, pValue)) {
4955 return TRUE;
4956 }
4957 pNode = pNode->GetPacketID() != XFA_XDPPACKET_Datasets
4958 ? pNode->GetTemplateNode()
weili44f8faf2016-06-01 14:03:56 -07004959 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004960 }
4961 return FALSE;
4962}
dsinclair5b36f0a2016-07-19 10:56:23 -07004963
Dan Sinclair1770c022016-03-14 14:14:16 -04004964void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004965 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair1770c022016-03-14 14:14:16 -04004966 wsValue.GetLength() * sizeof(FX_WCHAR));
4967}
dsinclair5b36f0a2016-07-19 10:56:23 -07004968
Dan Sinclair1770c022016-03-14 14:14:16 -04004969FX_BOOL CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
4970 void* pValue;
4971 int32_t iBytes;
4972 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
4973 return FALSE;
4974 }
4975 wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR));
4976 return TRUE;
4977}
dsinclair5b36f0a2016-07-19 10:56:23 -07004978
Dan Sinclair1770c022016-03-14 14:14:16 -04004979void CXFA_Node::SetMapModuleBuffer(
4980 void* pKey,
4981 void* pValue,
4982 int32_t iBytes,
4983 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4984 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4985 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004986 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004987 pBuffer =
4988 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4989 } else if (pBuffer->iBytes != iBytes) {
4990 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4991 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4992 }
4993 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4994 sizeof(XFA_MAPDATABLOCK) + iBytes);
4995 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4996 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4997 }
weili44f8faf2016-06-01 14:03:56 -07004998 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04004999 return;
weili44f8faf2016-06-01 14:03:56 -07005000
Dan Sinclair1770c022016-03-14 14:14:16 -04005001 pBuffer->pCallbackInfo = pCallbackInfo;
5002 pBuffer->iBytes = iBytes;
5003 FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes);
5004}
dsinclair5b36f0a2016-07-19 10:56:23 -07005005
Dan Sinclair1770c022016-03-14 14:14:16 -04005006FX_BOOL CXFA_Node::GetMapModuleBuffer(void* pKey,
5007 void*& pValue,
5008 int32_t& iBytes,
5009 FX_BOOL bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07005010 XFA_MAPDATABLOCK* pBuffer = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005011 const CXFA_Node* pNode = this;
5012 while (pNode) {
5013 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
5014 if (pModule && pModule->m_BufferMap.Lookup(pKey, pBuffer)) {
5015 break;
5016 }
5017 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets)
5018 ? pNode->GetTemplateNode()
weili44f8faf2016-06-01 14:03:56 -07005019 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005020 }
weili44f8faf2016-06-01 14:03:56 -07005021 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005022 return FALSE;
5023 }
5024 pValue = pBuffer->GetData();
5025 iBytes = pBuffer->iBytes;
5026 return TRUE;
5027}
dsinclair5b36f0a2016-07-19 10:56:23 -07005028
Dan Sinclair1770c022016-03-14 14:14:16 -04005029FX_BOOL CXFA_Node::HasMapModuleKey(void* pKey, FX_BOOL bProtoAlso) {
5030 CXFA_Node* pNode = this;
5031 while (pNode) {
5032 void* pVal;
5033 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
5034 if (pModule &&
5035 (pModule->m_ValueMap.Lookup(pKey, pVal) ||
5036 pModule->m_BufferMap.Lookup(pKey, (XFA_MAPDATABLOCK*&)pVal))) {
5037 return TRUE;
5038 }
5039 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets)
5040 ? pNode->GetTemplateNode()
weili44f8faf2016-06-01 14:03:56 -07005041 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005042 }
5043 return FALSE;
5044}
dsinclair5b36f0a2016-07-19 10:56:23 -07005045
Dan Sinclair1770c022016-03-14 14:14:16 -04005046void CXFA_Node::RemoveMapModuleKey(void* pKey) {
5047 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
5048 if (!pModule)
5049 return;
5050
5051 if (pKey) {
weili44f8faf2016-06-01 14:03:56 -07005052 XFA_MAPDATABLOCK* pBuffer = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005053 pModule->m_BufferMap.Lookup(pKey, pBuffer);
5054 if (pBuffer) {
5055 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5056 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5057 }
5058 FX_Free(pBuffer);
5059 }
5060 pModule->m_BufferMap.RemoveKey(pKey);
5061 pModule->m_ValueMap.RemoveKey(pKey);
5062 } else {
5063 XFA_MAPDATABLOCK* pBuffer;
5064 FX_POSITION posBuffer = pModule->m_BufferMap.GetStartPosition();
5065 while (posBuffer) {
5066 pModule->m_BufferMap.GetNextAssoc(posBuffer, pKey, pBuffer);
5067 if (pBuffer) {
5068 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5069 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5070 }
5071 FX_Free(pBuffer);
5072 }
5073 }
5074 pModule->m_BufferMap.RemoveAll();
5075 pModule->m_ValueMap.RemoveAll();
5076 delete pModule;
5077 }
5078}
dsinclair5b36f0a2016-07-19 10:56:23 -07005079
Dan Sinclair1770c022016-03-14 14:14:16 -04005080void CXFA_Node::MergeAllData(void* pDstModule, FX_BOOL bUseSrcAttr) {
5081 XFA_MAPMODULEDATA* pDstModuleData =
5082 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
5083 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
5084 if (!pSrcModuleData) {
5085 return;
5086 }
5087 FX_POSITION psValue = pSrcModuleData->m_ValueMap.GetStartPosition();
5088 while (psValue) {
5089 void* pKey;
5090 void* pValue;
5091 pSrcModuleData->m_ValueMap.GetNextAssoc(psValue, pKey, pValue);
5092 if (bUseSrcAttr || !pDstModuleData->m_ValueMap.GetValueAt(pKey)) {
5093 pDstModuleData->m_ValueMap.SetAt(pKey, pValue);
5094 }
5095 }
5096 FX_POSITION psBuffer = pSrcModuleData->m_BufferMap.GetStartPosition();
5097 while (psBuffer) {
5098 void* pKey;
5099 XFA_MAPDATABLOCK* pSrcBuffer;
5100 pSrcModuleData->m_BufferMap.GetNextAssoc(psBuffer, pKey, pSrcBuffer);
5101 XFA_MAPDATABLOCK*& pBuffer = pDstModuleData->m_BufferMap[pKey];
5102 if (pBuffer && !bUseSrcAttr) {
5103 continue;
5104 }
5105 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
5106 !pSrcBuffer->pCallbackInfo->pCopy) {
5107 if (pBuffer) {
5108 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5109 pDstModuleData->m_BufferMap.RemoveKey(pKey);
5110 }
5111 continue;
5112 }
weili44f8faf2016-06-01 14:03:56 -07005113 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005114 pBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
5115 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5116 } else if (pBuffer->iBytes != pSrcBuffer->iBytes) {
5117 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5118 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5119 }
5120 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
5121 uint8_t, pBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5122 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5123 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5124 }
weili44f8faf2016-06-01 14:03:56 -07005125 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005126 continue;
5127 }
5128 pBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5129 pBuffer->iBytes = pSrcBuffer->iBytes;
5130 FXSYS_memcpy(pBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes);
5131 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pCopy) {
5132 pBuffer->pCallbackInfo->pCopy(*(void**)pBuffer->GetData());
5133 }
5134 }
5135}
dsinclair5b36f0a2016-07-19 10:56:23 -07005136
Dan Sinclair1770c022016-03-14 14:14:16 -04005137void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5138 if (!pDstModule) {
5139 return;
5140 }
5141 FX_BOOL bNeedMove = TRUE;
5142 if (!pKey) {
5143 bNeedMove = FALSE;
5144 }
dsinclair070fcdf2016-06-22 22:04:54 -07005145 if (pDstModule->GetElementType() != GetElementType()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005146 bNeedMove = FALSE;
5147 }
weili44f8faf2016-06-01 14:03:56 -07005148 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5149 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005150 if (bNeedMove) {
5151 pSrcModuleData = GetMapModuleData();
5152 if (!pSrcModuleData) {
5153 bNeedMove = FALSE;
5154 }
5155 pDstModuleData = pDstModule->CreateMapModuleData();
5156 }
5157 if (bNeedMove) {
5158 void* pBufferBlockData = pSrcModuleData->m_BufferMap.GetValueAt(pKey);
5159 if (pBufferBlockData) {
5160 pSrcModuleData->m_BufferMap.RemoveKey(pKey);
5161 pDstModuleData->m_BufferMap.RemoveKey(pKey);
5162 pDstModuleData->m_BufferMap.SetAt(pKey,
5163 (XFA_MAPDATABLOCK*)pBufferBlockData);
5164 }
5165 }
dsinclairc5a8f212016-06-20 11:11:12 -07005166 if (pDstModule->IsNodeV()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005167 CFX_WideString wsValue = pDstModule->GetScriptContent(FALSE);
5168 CFX_WideString wsFormatValue(wsValue);
5169 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5170 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005171 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005172 }
thestigb1a59592016-04-14 18:29:56 -07005173 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, TRUE);
Dan Sinclair1770c022016-03-14 14:14:16 -04005174 }
5175}
dsinclair5b36f0a2016-07-19 10:56:23 -07005176
Dan Sinclair1770c022016-03-14 14:14:16 -04005177void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5178 CXFA_Node* pDstModule,
5179 void* pKey,
5180 FX_BOOL bRecursive) {
5181 if (!pSrcModule || !pDstModule || !pKey) {
5182 return;
5183 }
5184 if (bRecursive) {
5185 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5186 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5187 for (; pSrcChild && pDstChild;
5188 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5189 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
5190 MoveBufferMapData(pSrcChild, pDstChild, pKey, TRUE);
5191 }
5192 }
5193 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5194}