blob: 61107bf156a4c612845390d74b255df82db66e45 [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
Dan Sinclairefcae5d2017-03-29 14:47:46 -04007#include "xfa/fxfa/parser/cxfa_node.h"
Dan Sinclair1770c022016-03-14 14:14:16 -04008
dsinclair5b36f0a2016-07-19 10:56:23 -07009#include <map>
tsepezaadedf92016-05-12 10:08:06 -070010#include <memory>
Tom Sepezd4db58f2017-03-02 14:57:59 -080011#include <unordered_set>
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050012#include <utility>
tsepez51709be2016-12-08 10:55:57 -080013#include <vector>
tsepezaadedf92016-05-12 10:08:06 -070014
Dan Sinclairb929ab02017-03-29 15:18:16 -040015#include "core/fxcrt/cfx_decimal.h"
dsinclaira52ab742016-09-29 13:59:29 -070016#include "core/fxcrt/fx_ext.h"
dsinclair43554682016-09-29 17:29:48 -070017#include "fxjs/cfxjse_value.h"
tsepeza9caab92016-12-14 05:57:10 -080018#include "third_party/base/ptr_util.h"
tsepezaadedf92016-05-12 10:08:06 -070019#include "third_party/base/stl_util.h"
Dan Sinclairac355892017-04-03 16:46:21 -040020#include "xfa/fde/xml/cfde_xmlelement.h"
21#include "xfa/fde/xml/cfde_xmlnode.h"
22#include "xfa/fde/xml/cfde_xmltext.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040023#include "xfa/fgas/crt/fgas_codepage.h"
dsinclairdf4bc592016-03-31 20:34:43 -070024#include "xfa/fxfa/app/xfa_ffnotify.h"
dsinclair5b493092016-09-29 20:20:24 -070025#include "xfa/fxfa/cxfa_eventparam.h"
Dan Sinclairefcae5d2017-03-29 14:47:46 -040026#include "xfa/fxfa/cxfa_ffwidget.h"
27#include "xfa/fxfa/parser/cxfa_arraynodelist.h"
28#include "xfa/fxfa/parser/cxfa_attachnodelist.h"
dsinclair16280242016-07-21 12:03:47 -070029#include "xfa/fxfa/parser/cxfa_document.h"
dsinclair0b851ff2016-07-21 12:03:01 -070030#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
dsinclair9eb0db12016-07-21 12:01:39 -070031#include "xfa/fxfa/parser/cxfa_measurement.h"
dsinclair44d054c2016-04-06 10:23:46 -070032#include "xfa/fxfa/parser/cxfa_occur.h"
dsinclair31f87402016-07-20 06:34:45 -070033#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
dsinclair34f86b02016-07-11 08:42:33 -070034#include "xfa/fxfa/parser/cxfa_simple_parser.h"
Dan Sinclairefcae5d2017-03-29 14:47:46 -040035#include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h"
dsinclair5b36f0a2016-07-19 10:56:23 -070036#include "xfa/fxfa/parser/xfa_basic_data.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040037
weili44f8faf2016-06-01 14:03:56 -070038namespace {
39
40void XFA_DeleteWideString(void* pData) {
41 delete static_cast<CFX_WideString*>(pData);
42}
43
44void XFA_CopyWideString(void*& pData) {
45 if (pData) {
46 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
47 pData = pNewData;
48 }
49}
50
51XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
52 XFA_CopyWideString};
53
weili44f8faf2016-06-01 14:03:56 -070054void XFA_DataNodeDeleteBindItem(void* pData) {
Tom Sepezf8a94392017-03-14 12:13:22 -070055 delete static_cast<std::vector<CXFA_Node*>*>(pData);
weili44f8faf2016-06-01 14:03:56 -070056}
57
58XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
59 XFA_DataNodeDeleteBindItem, nullptr};
60
dsinclair5b36f0a2016-07-19 10:56:23 -070061int32_t GetCount(CXFA_Node* pInstMgrNode) {
62 ASSERT(pInstMgrNode);
63 int32_t iCount = 0;
64 uint32_t dwNameHash = 0;
65 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
66 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
67 XFA_Element eCurType = pNode->GetElementType();
68 if (eCurType == XFA_Element::InstanceManager)
69 break;
70 if ((eCurType != XFA_Element::Subform) &&
71 (eCurType != XFA_Element::SubformSet)) {
72 continue;
73 }
74 if (iCount == 0) {
75 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
76 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
77 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
78 wsInstName.Mid(1) != wsName) {
79 return iCount;
80 }
81 dwNameHash = pNode->GetNameHash();
82 }
83 if (dwNameHash != pNode->GetNameHash())
84 break;
weili44f8faf2016-06-01 14:03:56 -070085
dsinclair5b36f0a2016-07-19 10:56:23 -070086 iCount++;
87 }
88 return iCount;
Dan Sinclair1770c022016-03-14 14:14:16 -040089}
weili44f8faf2016-06-01 14:03:56 -070090
Tom Sepez7cdc6602017-03-28 09:56:48 -070091std::vector<CXFA_Node*> NodesSortedByDocumentIdx(
92 const std::unordered_set<CXFA_Node*>& rgNodeSet) {
93 if (rgNodeSet.empty())
94 return std::vector<CXFA_Node*>();
weili44f8faf2016-06-01 14:03:56 -070095
Tom Sepez7cdc6602017-03-28 09:56:48 -070096 std::vector<CXFA_Node*> rgNodeArray;
dsinclair5b36f0a2016-07-19 10:56:23 -070097 CXFA_Node* pCommonParent =
98 (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent);
99 for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild);
Tom Sepez7cdc6602017-03-28 09:56:48 -0700100 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
101 if (pdfium::ContainsValue(rgNodeSet, pNode))
102 rgNodeArray.push_back(pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400103 }
Tom Sepez7cdc6602017-03-28 09:56:48 -0700104 return rgNodeArray;
Dan Sinclair1770c022016-03-14 14:14:16 -0400105}
weili44f8faf2016-06-01 14:03:56 -0700106
Tom Sepezd4db58f2017-03-02 14:57:59 -0800107using CXFA_NodeSetPair =
108 std::pair<std::unordered_set<CXFA_Node*>, std::unordered_set<CXFA_Node*>>;
dsinclair5b36f0a2016-07-19 10:56:23 -0700109using CXFA_NodeSetPairMap =
110 std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>;
111using CXFA_NodeSetPairMapMap =
112 std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>;
113
114CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode,
115 CXFA_NodeSetPairMapMap* pMap) {
116 CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
117 uint32_t dwNameHash = pNode->GetNameHash();
118 if (!pParentNode || !dwNameHash)
119 return nullptr;
120
121 if (!(*pMap)[pParentNode])
tsepeza9caab92016-12-14 05:57:10 -0800122 (*pMap)[pParentNode] = pdfium::MakeUnique<CXFA_NodeSetPairMap>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700123
124 CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get();
125 if (!(*pNodeSetPairMap)[dwNameHash])
tsepeza9caab92016-12-14 05:57:10 -0800126 (*pNodeSetPairMap)[dwNameHash] = pdfium::MakeUnique<CXFA_NodeSetPair>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700127
128 return (*pNodeSetPairMap)[dwNameHash].get();
Dan Sinclair1770c022016-03-14 14:14:16 -0400129}
130
Tom Sepezd4db58f2017-03-02 14:57:59 -0800131void ReorderDataNodes(const std::unordered_set<CXFA_Node*>& sSet1,
132 const std::unordered_set<CXFA_Node*>& sSet2,
tsepezd19e9122016-11-02 15:43:18 -0700133 bool bInsertBefore) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700134 CXFA_NodeSetPairMapMap rgMap;
135 for (CXFA_Node* pNode : sSet1) {
136 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
137 if (pNodeSetPair)
138 pNodeSetPair->first.insert(pNode);
139 }
140 for (CXFA_Node* pNode : sSet2) {
141 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
142 if (pNodeSetPair) {
143 if (pdfium::ContainsValue(pNodeSetPair->first, pNode))
144 pNodeSetPair->first.erase(pNode);
145 else
146 pNodeSetPair->second.insert(pNode);
147 }
148 }
149 for (const auto& iter1 : rgMap) {
150 CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get();
151 if (!pNodeSetPairMap)
152 continue;
153
154 for (const auto& iter2 : *pNodeSetPairMap) {
155 CXFA_NodeSetPair* pNodeSetPair = iter2.second.get();
156 if (!pNodeSetPair)
157 continue;
158 if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) {
Tom Sepez7cdc6602017-03-28 09:56:48 -0700159 std::vector<CXFA_Node*> rgNodeArray1 =
160 NodesSortedByDocumentIdx(pNodeSetPair->first);
161 std::vector<CXFA_Node*> rgNodeArray2 =
162 NodesSortedByDocumentIdx(pNodeSetPair->second);
dsinclair5b36f0a2016-07-19 10:56:23 -0700163 CXFA_Node* pParentNode = nullptr;
164 CXFA_Node* pBeforeNode = nullptr;
165 if (bInsertBefore) {
Tom Sepez7cdc6602017-03-28 09:56:48 -0700166 pBeforeNode = rgNodeArray2.front();
dsinclair5b36f0a2016-07-19 10:56:23 -0700167 pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent);
168 } else {
Tom Sepez7cdc6602017-03-28 09:56:48 -0700169 CXFA_Node* pLastNode = rgNodeArray2.back();
dsinclair5b36f0a2016-07-19 10:56:23 -0700170 pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent);
171 pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling);
172 }
Tom Sepez7cdc6602017-03-28 09:56:48 -0700173 for (auto* pCurNode : rgNodeArray1) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700174 pParentNode->RemoveChild(pCurNode);
175 pParentNode->InsertChild(pCurNode, pBeforeNode);
176 }
177 }
178 }
179 pNodeSetPairMap->clear();
180 }
181}
182
183CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
184 ASSERT(pInstMgrNode);
185 int32_t iCount = 0;
186 uint32_t dwNameHash = 0;
187 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
188 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
189 XFA_Element eCurType = pNode->GetElementType();
190 if (eCurType == XFA_Element::InstanceManager)
191 break;
192 if ((eCurType != XFA_Element::Subform) &&
193 (eCurType != XFA_Element::SubformSet)) {
194 continue;
195 }
196 if (iCount == 0) {
197 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
198 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
199 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
200 wsInstName.Mid(1) != wsName) {
201 return nullptr;
202 }
203 dwNameHash = pNode->GetNameHash();
204 }
205 if (dwNameHash != pNode->GetNameHash())
206 break;
207
208 iCount++;
209 if (iCount > iIndex)
210 return pNode;
211 }
212 return nullptr;
213}
214
215void InsertItem(CXFA_Node* pInstMgrNode,
216 CXFA_Node* pNewInstance,
217 int32_t iPos,
218 int32_t iCount = -1,
tsepezd19e9122016-11-02 15:43:18 -0700219 bool bMoveDataBindingNodes = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700220 if (iCount < 0)
221 iCount = GetCount(pInstMgrNode);
222 if (iPos < 0)
223 iPos = iCount;
224 if (iPos == iCount) {
225 CXFA_Node* pNextSibling =
226 iCount > 0
227 ? GetItem(pInstMgrNode, iCount - 1)
228 ->GetNodeItem(XFA_NODEITEM_NextSibling)
229 : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
230 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
231 ->InsertChild(pNewInstance, pNextSibling);
232 if (bMoveDataBindingNodes) {
Tom Sepezd4db58f2017-03-02 14:57:59 -0800233 std::unordered_set<CXFA_Node*> sNew;
234 std::unordered_set<CXFA_Node*> sAfter;
dsinclair5b36f0a2016-07-19 10:56:23 -0700235 CXFA_NodeIteratorTemplate<CXFA_Node,
236 CXFA_TraverseStrategy_XFAContainerNode>
237 sIteratorNew(pNewInstance);
238 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
239 pNode = sIteratorNew.MoveToNext()) {
240 CXFA_Node* pDataNode = pNode->GetBindData();
241 if (!pDataNode)
242 continue;
243
244 sNew.insert(pDataNode);
245 }
246 CXFA_NodeIteratorTemplate<CXFA_Node,
247 CXFA_TraverseStrategy_XFAContainerNode>
248 sIteratorAfter(pNextSibling);
249 for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode;
250 pNode = sIteratorAfter.MoveToNext()) {
251 CXFA_Node* pDataNode = pNode->GetBindData();
252 if (!pDataNode)
253 continue;
254
255 sAfter.insert(pDataNode);
256 }
tsepezd19e9122016-11-02 15:43:18 -0700257 ReorderDataNodes(sNew, sAfter, false);
dsinclair5b36f0a2016-07-19 10:56:23 -0700258 }
259 } else {
260 CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos);
261 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
262 ->InsertChild(pNewInstance, pBeforeInstance);
263 if (bMoveDataBindingNodes) {
Tom Sepezd4db58f2017-03-02 14:57:59 -0800264 std::unordered_set<CXFA_Node*> sNew;
265 std::unordered_set<CXFA_Node*> sBefore;
dsinclair5b36f0a2016-07-19 10:56:23 -0700266 CXFA_NodeIteratorTemplate<CXFA_Node,
267 CXFA_TraverseStrategy_XFAContainerNode>
268 sIteratorNew(pNewInstance);
269 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
270 pNode = sIteratorNew.MoveToNext()) {
271 CXFA_Node* pDataNode = pNode->GetBindData();
272 if (!pDataNode)
273 continue;
274
275 sNew.insert(pDataNode);
276 }
277 CXFA_NodeIteratorTemplate<CXFA_Node,
278 CXFA_TraverseStrategy_XFAContainerNode>
279 sIteratorBefore(pBeforeInstance);
280 for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode;
281 pNode = sIteratorBefore.MoveToNext()) {
282 CXFA_Node* pDataNode = pNode->GetBindData();
283 if (!pDataNode)
284 continue;
285
286 sBefore.insert(pDataNode);
287 }
tsepezd19e9122016-11-02 15:43:18 -0700288 ReorderDataNodes(sNew, sBefore, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700289 }
290 }
291}
292
293void RemoveItem(CXFA_Node* pInstMgrNode,
294 CXFA_Node* pRemoveInstance,
tsepezd19e9122016-11-02 15:43:18 -0700295 bool bRemoveDataBinding = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700296 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);
297 if (!bRemoveDataBinding)
298 return;
299
300 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode>
301 sIterator(pRemoveInstance);
302 for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode;
303 pFormNode = sIterator.MoveToNext()) {
304 CXFA_Node* pDataNode = pFormNode->GetBindData();
305 if (!pDataNode)
306 continue;
307
308 if (pDataNode->RemoveBindItem(pFormNode) == 0) {
309 if (CXFA_Node* pDataParent =
310 pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) {
311 pDataParent->RemoveChild(pDataNode);
312 }
313 }
314 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
315 }
316}
317
tsepezd19e9122016-11-02 15:43:18 -0700318CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700319 CXFA_Document* pDocument = pInstMgrNode->GetDocument();
320 CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();
321 CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);
322 CXFA_Node* pDataScope = nullptr;
323 for (CXFA_Node* pRootBoundNode = pFormParent;
324 pRootBoundNode && pRootBoundNode->IsContainerNode();
325 pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) {
326 pDataScope = pRootBoundNode->GetBindData();
327 if (pDataScope)
328 break;
329 }
330 if (!pDataScope) {
331 pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record));
332 ASSERT(pDataScope);
333 }
334 CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer(
tsepezd19e9122016-11-02 15:43:18 -0700335 pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700336 if (pInstance) {
337 pDocument->DataMerge_UpdateBindingRelations(pInstance);
338 pFormParent->RemoveChild(pInstance);
339 }
340 return pInstance;
341}
342
343struct XFA_ExecEventParaInfo {
344 public:
345 uint32_t m_uHash;
Dan Sinclair812e96c2017-03-13 16:43:37 -0400346 const wchar_t* m_lpcEventName;
dsinclair5b36f0a2016-07-19 10:56:23 -0700347 XFA_EVENTTYPE m_eventType;
348 uint32_t m_validFlags;
349};
350static const XFA_ExecEventParaInfo gs_eventParaInfos[] = {
351 {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0},
352 {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0},
353 {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5},
354 {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0},
355 {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7},
356 {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1},
357 {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5},
358 {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0},
359 {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0},
360 {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6},
361 {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2},
362 {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0},
363 {0x7233018a, L"validate", XFA_EVENT_Validate, 1},
364 {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3},
365 {0x891f4606, L"change", XFA_EVENT_Change, 4},
366 {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0},
367 {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5},
368 {0xcdce56b3, L"full", XFA_EVENT_Full, 4},
369 {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5},
370 {0xd95657a6, L"click", XFA_EVENT_Click, 4},
371 {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1},
372 {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7},
373 {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2},
374 {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0},
375 {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6},
376};
377
378const XFA_ExecEventParaInfo* GetEventParaInfoByName(
379 const CFX_WideStringC& wsEventName) {
380 uint32_t uHash = FX_HashCode_GetW(wsEventName, false);
381 int32_t iStart = 0;
382 int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
383 do {
384 int32_t iMid = (iStart + iEnd) / 2;
385 const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid];
386 if (uHash == eventParaInfo->m_uHash)
387 return eventParaInfo;
388 if (uHash < eventParaInfo->m_uHash)
389 iEnd = iMid - 1;
390 else
391 iStart = iMid + 1;
392 } while (iStart <= iEnd);
393 return nullptr;
394}
395
396void StrToRGB(const CFX_WideString& strRGB,
397 int32_t& r,
398 int32_t& g,
399 int32_t& b) {
400 r = 0;
401 g = 0;
402 b = 0;
403
Dan Sinclair812e96c2017-03-13 16:43:37 -0400404 wchar_t zero = '0';
dsinclair5b36f0a2016-07-19 10:56:23 -0700405 int32_t iIndex = 0;
406 int32_t iLen = strRGB.GetLength();
407 for (int32_t i = 0; i < iLen; ++i) {
Dan Sinclair812e96c2017-03-13 16:43:37 -0400408 wchar_t ch = strRGB.GetAt(i);
dsinclair5b36f0a2016-07-19 10:56:23 -0700409 if (ch == L',')
410 ++iIndex;
411 if (iIndex > 2)
412 break;
413
414 int32_t iValue = ch - zero;
415 if (iValue >= 0 && iValue <= 9) {
416 switch (iIndex) {
417 case 0:
418 r = r * 10 + iValue;
419 break;
420 case 1:
421 g = g * 10 + iValue;
422 break;
423 default:
424 b = b * 10 + iValue;
425 break;
426 }
427 }
428 }
429}
430
431enum XFA_KEYTYPE {
432 XFA_KEYTYPE_Custom,
433 XFA_KEYTYPE_Element,
434};
435
436void* GetMapKey_Custom(const CFX_WideStringC& wsKey) {
437 uint32_t dwKey = FX_HashCode_GetW(wsKey, false);
438 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom);
439}
440
441void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) {
442 return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) |
443 (eAttribute << 8) | XFA_KEYTYPE_Element);
444}
445
dsinclair9eb0db12016-07-21 12:01:39 -0700446const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement,
447 XFA_ATTRIBUTE eAttribute,
448 uint32_t dwPacket) {
449 int32_t iCount = 0;
450 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount);
451 if (!pAttr || iCount < 1)
452 return nullptr;
453
454 if (!std::binary_search(pAttr, pAttr + iCount, eAttribute))
455 return nullptr;
456
457 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute);
458 ASSERT(pInfo);
459 if (dwPacket == XFA_XDPPACKET_UNKNOWN)
460 return pInfo;
461 return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr;
462}
463
464const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) {
465 return g_XFAEnumData + eName;
466}
467
dsinclair5b36f0a2016-07-19 10:56:23 -0700468} // namespace
469
470static void XFA_DefaultFreeData(void* pData) {}
471
472static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {
473 XFA_DefaultFreeData, nullptr};
474
weili47bcd4c2016-06-16 08:00:06 -0700475XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {}
476
477XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {}
478
dsinclairb9778472016-06-23 13:34:10 -0700479CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
480 uint16_t ePacket,
481 XFA_ObjectType oType,
dsinclairc1df5d42016-07-18 06:36:51 -0700482 XFA_Element eType,
483 const CFX_WideStringC& elementName)
484 : CXFA_Object(pDoc, oType, eType, elementName),
Dan Sinclair1770c022016-03-14 14:14:16 -0400485 m_pNext(nullptr),
486 m_pChild(nullptr),
487 m_pLastChild(nullptr),
488 m_pParent(nullptr),
489 m_pXMLNode(nullptr),
Dan Sinclair1770c022016-03-14 14:14:16 -0400490 m_ePacket(ePacket),
dsinclairc5a8f212016-06-20 11:11:12 -0700491 m_uNodeFlags(XFA_NodeFlag_None),
Dan Sinclair1770c022016-03-14 14:14:16 -0400492 m_dwNameHash(0),
493 m_pAuxNode(nullptr),
494 m_pMapModuleData(nullptr) {
495 ASSERT(m_pDocument);
496}
weili44f8faf2016-06-01 14:03:56 -0700497
Dan Sinclair1770c022016-03-14 14:14:16 -0400498CXFA_Node::~CXFA_Node() {
weili44f8faf2016-06-01 14:03:56 -0700499 ASSERT(!m_pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400500 RemoveMapModuleKey();
weili44f8faf2016-06-01 14:03:56 -0700501 CXFA_Node* pNode = m_pChild;
Dan Sinclair1770c022016-03-14 14:14:16 -0400502 while (pNode) {
weili44f8faf2016-06-01 14:03:56 -0700503 CXFA_Node* pNext = pNode->m_pNext;
504 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400505 delete pNode;
506 pNode = pNext;
507 }
dsinclairc5a8f212016-06-20 11:11:12 -0700508 if (m_pXMLNode && IsOwnXMLNode())
tsepezc757d9a2017-01-23 11:01:42 -0800509 delete m_pXMLNode;
Dan Sinclair1770c022016-03-14 14:14:16 -0400510}
weili44f8faf2016-06-01 14:03:56 -0700511
tsepezd19e9122016-11-02 15:43:18 -0700512CXFA_Node* CXFA_Node::Clone(bool bRecursive) {
dsinclaira1b07722016-07-11 08:20:58 -0700513 CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700514 if (!pClone)
515 return nullptr;
516
Dan Sinclair1770c022016-03-14 14:14:16 -0400517 MergeAllData(pClone);
518 pClone->UpdateNameHash();
519 if (IsNeedSavingXMLNode()) {
weili44f8faf2016-06-01 14:03:56 -0700520 CFDE_XMLNode* pCloneXML = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400521 if (IsAttributeInXML()) {
522 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -0700523 GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -0700524 CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -0400525 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
526 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -0700527 pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -0400528 }
529 pCloneXML = pCloneXMLElement;
weili44f8faf2016-06-01 14:03:56 -0700530 pCloneXMLElement = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400531 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
532 } else {
tsepezd19e9122016-11-02 15:43:18 -0700533 pCloneXML = m_pXMLNode->Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400534 }
535 pClone->SetXMLMappingNode(pCloneXML);
dsinclairc5a8f212016-06-20 11:11:12 -0700536 pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400537 }
538 if (bRecursive) {
539 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
540 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
541 pClone->InsertChild(pChild->Clone(bRecursive));
542 }
543 }
dsinclairc5a8f212016-06-20 11:11:12 -0700544 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
weili44f8faf2016-06-01 14:03:56 -0700545 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400546 return pClone;
547}
weili44f8faf2016-06-01 14:03:56 -0700548
Dan Sinclair1770c022016-03-14 14:14:16 -0400549CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
550 switch (eItem) {
551 case XFA_NODEITEM_NextSibling:
552 return m_pNext;
553 case XFA_NODEITEM_FirstChild:
554 return m_pChild;
555 case XFA_NODEITEM_Parent:
556 return m_pParent;
557 case XFA_NODEITEM_PrevSibling:
558 if (m_pParent) {
559 CXFA_Node* pSibling = m_pParent->m_pChild;
weili44f8faf2016-06-01 14:03:56 -0700560 CXFA_Node* pPrev = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400561 while (pSibling && pSibling != this) {
562 pPrev = pSibling;
563 pSibling = pSibling->m_pNext;
564 }
565 return pPrev;
566 }
weili44f8faf2016-06-01 14:03:56 -0700567 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400568 default:
569 break;
570 }
weili44f8faf2016-06-01 14:03:56 -0700571 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400572}
weili44f8faf2016-06-01 14:03:56 -0700573
Dan Sinclair1770c022016-03-14 14:14:16 -0400574CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
dsinclairc5a8f212016-06-20 11:11:12 -0700575 XFA_ObjectType eType) const {
weili44f8faf2016-06-01 14:03:56 -0700576 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400577 switch (eItem) {
578 case XFA_NODEITEM_NextSibling:
579 pNode = m_pNext;
dsinclairc5a8f212016-06-20 11:11:12 -0700580 while (pNode && pNode->GetObjectType() != eType)
581 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400582 break;
583 case XFA_NODEITEM_FirstChild:
584 pNode = m_pChild;
dsinclairc5a8f212016-06-20 11:11:12 -0700585 while (pNode && pNode->GetObjectType() != eType)
586 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400587 break;
588 case XFA_NODEITEM_Parent:
589 pNode = m_pParent;
dsinclairc5a8f212016-06-20 11:11:12 -0700590 while (pNode && pNode->GetObjectType() != eType)
591 pNode = pNode->m_pParent;
Dan Sinclair1770c022016-03-14 14:14:16 -0400592 break;
593 case XFA_NODEITEM_PrevSibling:
594 if (m_pParent) {
595 CXFA_Node* pSibling = m_pParent->m_pChild;
596 while (pSibling && pSibling != this) {
dsinclairc5a8f212016-06-20 11:11:12 -0700597 if (eType == pSibling->GetObjectType())
Dan Sinclair1770c022016-03-14 14:14:16 -0400598 pNode = pSibling;
dsinclairc5a8f212016-06-20 11:11:12 -0700599
Dan Sinclair1770c022016-03-14 14:14:16 -0400600 pSibling = pSibling->m_pNext;
601 }
602 }
603 break;
604 default:
605 break;
606 }
607 return pNode;
608}
weili44f8faf2016-06-01 14:03:56 -0700609
Tom Sepezf8a94392017-03-14 12:13:22 -0700610std::vector<CXFA_Node*> CXFA_Node::GetNodeList(uint32_t dwTypeFilter,
611 XFA_Element eTypeFilter) {
612 std::vector<CXFA_Node*> nodes;
dsinclair41cb62e2016-06-23 09:20:32 -0700613 if (eTypeFilter != XFA_Element::Unknown) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700614 for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext) {
615 if (pChild->GetElementType() == eTypeFilter)
616 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400617 }
618 } else if (dwTypeFilter ==
619 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700620 for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext)
621 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400622 } else if (dwTypeFilter != 0) {
weili44f8faf2016-06-01 14:03:56 -0700623 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
624 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
625 bool bFilterOneOfProperties =
626 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
Dan Sinclair1770c022016-03-14 14:14:16 -0400627 CXFA_Node* pChild = m_pChild;
628 while (pChild) {
629 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -0700630 GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -0400631 if (pProperty) {
632 if (bFilterProperties) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700633 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400634 } else if (bFilterOneOfProperties &&
635 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700636 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400637 } else if (bFilterChildren &&
dsinclair070fcdf2016-06-22 22:04:54 -0700638 (pChild->GetElementType() == XFA_Element::Variables ||
639 pChild->GetElementType() == XFA_Element::PageSet)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700640 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400641 }
weili44f8faf2016-06-01 14:03:56 -0700642 } else if (bFilterChildren) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700643 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400644 }
645 pChild = pChild->m_pNext;
646 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700647 if (bFilterOneOfProperties && nodes.empty()) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400648 int32_t iProperties = 0;
649 const XFA_PROPERTY* pProperty =
dsinclair070fcdf2016-06-22 22:04:54 -0700650 XFA_GetElementProperties(GetElementType(), iProperties);
weili44f8faf2016-06-01 14:03:56 -0700651 if (!pProperty || iProperties < 1)
Tom Sepezf8a94392017-03-14 12:13:22 -0700652 return nodes;
Dan Sinclair1770c022016-03-14 14:14:16 -0400653 for (int32_t i = 0; i < iProperties; i++) {
654 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400655 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
656 CXFA_Node* pNewNode =
dsinclaira1b07722016-07-11 08:20:58 -0700657 m_pDocument->CreateNode(pPacket, pProperty[i].eName);
weili44f8faf2016-06-01 14:03:56 -0700658 if (!pNewNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400659 break;
weili44f8faf2016-06-01 14:03:56 -0700660 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -0700661 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Tom Sepezf8a94392017-03-14 12:13:22 -0700662 nodes.push_back(pNewNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400663 break;
664 }
665 }
666 }
667 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700668 return nodes;
Dan Sinclair1770c022016-03-14 14:14:16 -0400669}
weili44f8faf2016-06-01 14:03:56 -0700670
dsinclair41cb62e2016-06-23 09:20:32 -0700671CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
tsepez736f28a2016-03-25 14:19:51 -0700672 uint32_t dwFlags) {
dsinclaira1b07722016-07-11 08:20:58 -0700673 CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
thestigb1a59592016-04-14 18:29:56 -0700674 pNode->SetFlag(dwFlags, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400675 return pNode;
676}
weili44f8faf2016-06-01 14:03:56 -0700677
tsepezd19e9122016-11-02 15:43:18 -0700678CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) {
dsinclair43854a52016-04-27 12:26:00 -0700679 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
dsinclaira1b07722016-07-11 08:20:58 -0700680 CXFA_Node* pClone =
681 m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700682 if (!pClone)
683 return nullptr;
684
Dan Sinclair1770c022016-03-14 14:14:16 -0400685 pClone->SetTemplateNode(this);
686 pClone->UpdateNameHash();
687 pClone->SetXMLMappingNode(GetXMLMappingNode());
688 if (bRecursive) {
689 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
690 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
691 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
692 }
693 }
dsinclairc5a8f212016-06-20 11:11:12 -0700694 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400695 return pClone;
696}
697
698CXFA_Node* CXFA_Node::GetTemplateNode() const {
699 return m_pAuxNode;
700}
701
702void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
703 m_pAuxNode = pTemplateNode;
704}
weili44f8faf2016-06-01 14:03:56 -0700705
Dan Sinclair1770c022016-03-14 14:14:16 -0400706CXFA_Node* CXFA_Node::GetBindData() {
707 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
708 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
709}
weili44f8faf2016-06-01 14:03:56 -0700710
Tom Sepezf8a94392017-03-14 12:13:22 -0700711std::vector<CXFA_Node*> CXFA_Node::GetBindItems() {
dsinclairc5a8f212016-06-20 11:11:12 -0700712 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700713 void* pBinding = nullptr;
714 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
715 return *static_cast<std::vector<CXFA_Node*>*>(pBinding);
Dan Sinclair1770c022016-03-14 14:14:16 -0400716 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700717 std::vector<CXFA_Node*> result;
Dan Sinclair1770c022016-03-14 14:14:16 -0400718 CXFA_Node* pFormNode =
719 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
weili44f8faf2016-06-01 14:03:56 -0700720 if (pFormNode)
Tom Sepezf8a94392017-03-14 12:13:22 -0700721 result.push_back(pFormNode);
722 return result;
Dan Sinclair1770c022016-03-14 14:14:16 -0400723}
724
Dan Sinclair1770c022016-03-14 14:14:16 -0400725int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
726 ASSERT(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700727 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700728 void* pBinding = nullptr;
729 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
730 auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding);
731 if (!pdfium::ContainsValue(*pItems, pFormNode))
732 pItems->push_back(pFormNode);
733 return pdfium::CollectionSize<int32_t>(*pItems);
Dan Sinclair1770c022016-03-14 14:14:16 -0400734 }
735 CXFA_Node* pOldFormItem =
736 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
737 if (!pOldFormItem) {
738 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
739 return 1;
Dan Sinclair1770c022016-03-14 14:14:16 -0400740 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700741 if (pOldFormItem == pFormNode)
742 return 1;
743
744 std::vector<CXFA_Node*>* pItems = new std::vector<CXFA_Node*>;
Dan Sinclair1770c022016-03-14 14:14:16 -0400745 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
Tom Sepezf8a94392017-03-14 12:13:22 -0700746 pItems->push_back(pOldFormItem);
747 pItems->push_back(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700748 m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400749 return 2;
750}
weili44f8faf2016-06-01 14:03:56 -0700751
Dan Sinclair1770c022016-03-14 14:14:16 -0400752int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
dsinclairc5a8f212016-06-20 11:11:12 -0700753 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700754 void* pBinding = nullptr;
755 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
756 auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding);
757 auto iter = std::find(pItems->begin(), pItems->end(), pFormNode);
758 if (iter != pItems->end()) {
759 *iter = pItems->back();
760 pItems->pop_back();
761 if (pItems->size() == 1) {
762 SetObject(XFA_ATTRIBUTE_BindingNode,
763 (*pItems)[0]); // Invalidates pItems.
dsinclairc5a8f212016-06-20 11:11:12 -0700764 m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
Tom Sepezf8a94392017-03-14 12:13:22 -0700765 return 1;
Dan Sinclair1770c022016-03-14 14:14:16 -0400766 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400767 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700768 return pdfium::CollectionSize<int32_t>(*pItems);
Dan Sinclair1770c022016-03-14 14:14:16 -0400769 }
770 CXFA_Node* pOldFormItem =
771 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
Tom Sepezf8a94392017-03-14 12:13:22 -0700772 if (pOldFormItem != pFormNode)
773 return pOldFormItem ? 1 : 0;
774
775 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
776 return 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400777}
weili44f8faf2016-06-01 14:03:56 -0700778
tsepezd19e9122016-11-02 15:43:18 -0700779bool CXFA_Node::HasBindItem() {
weili44f8faf2016-06-01 14:03:56 -0700780 return GetPacketID() == XFA_XDPPACKET_Datasets &&
781 GetObject(XFA_ATTRIBUTE_BindingNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400782}
weili44f8faf2016-06-01 14:03:56 -0700783
Dan Sinclair1770c022016-03-14 14:14:16 -0400784CXFA_WidgetData* CXFA_Node::GetWidgetData() {
785 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
786}
weili44f8faf2016-06-01 14:03:56 -0700787
Dan Sinclair1770c022016-03-14 14:14:16 -0400788CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
weili44f8faf2016-06-01 14:03:56 -0700789 if (GetPacketID() != XFA_XDPPACKET_Form)
790 return nullptr;
dsinclair41cb62e2016-06-23 09:20:32 -0700791 XFA_Element eType = GetElementType();
792 if (eType == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700793 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400794 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700795 if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700796 return nullptr;
797
dsinclair41cb62e2016-06-23 09:20:32 -0700798 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400799 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
800 if (pFieldWidgetData &&
801 pFieldWidgetData->GetChoiceListOpen() ==
802 XFA_ATTRIBUTEENUM_MultiSelect) {
weili44f8faf2016-06-01 14:03:56 -0700803 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400804 } else {
805 CFX_WideString wsPicture;
806 if (pFieldWidgetData) {
807 pFieldWidgetData->GetPictureContent(wsPicture,
808 XFA_VALUEPICTURE_DataBind);
809 }
weili44f8faf2016-06-01 14:03:56 -0700810 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400811 return pFieldWidgetData;
Dan Sinclair1770c022016-03-14 14:14:16 -0400812 CXFA_Node* pDataNode = GetBindData();
weili44f8faf2016-06-01 14:03:56 -0700813 if (!pDataNode)
814 return nullptr;
815 pFieldWidgetData = nullptr;
Tom Sepezf8a94392017-03-14 12:13:22 -0700816 for (CXFA_Node* pFormNode : pDataNode->GetBindItems()) {
dsinclairc5a8f212016-06-20 11:11:12 -0700817 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -0400818 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400819 pFieldWidgetData = pFormNode->GetWidgetData();
820 if (pFieldWidgetData) {
821 pFieldWidgetData->GetPictureContent(wsPicture,
822 XFA_VALUEPICTURE_DataBind);
823 }
weili44f8faf2016-06-01 14:03:56 -0700824 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400825 break;
weili44f8faf2016-06-01 14:03:56 -0700826 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400827 }
828 return pFieldWidgetData;
829 }
830 }
831 CXFA_Node* pGrandNode =
weili44f8faf2016-06-01 14:03:56 -0700832 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400833 CXFA_Node* pValueNode =
dsinclair070fcdf2016-06-22 22:04:54 -0700834 (pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
Dan Sinclair1770c022016-03-14 14:14:16 -0400835 ? pParentNode
weili44f8faf2016-06-01 14:03:56 -0700836 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400837 if (!pValueNode) {
dsinclair070fcdf2016-06-22 22:04:54 -0700838 pValueNode =
839 (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
840 ? pGrandNode
841 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400842 }
843 CXFA_Node* pParentOfValueNode =
weili44f8faf2016-06-01 14:03:56 -0700844 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400845 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
weili44f8faf2016-06-01 14:03:56 -0700846 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400847}
weili44f8faf2016-06-01 14:03:56 -0700848
tsepezd19e9122016-11-02 15:43:18 -0700849bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400850 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
dsinclair56a8b192016-06-21 14:15:25 -0700851 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
dsinclair43854a52016-04-27 12:26:00 -0700852 ASSERT(pTopSubform);
Dan Sinclair1770c022016-03-14 14:14:16 -0400853 CXFA_Node* pLocaleNode = this;
tsepezd19e9122016-11-02 15:43:18 -0700854 bool bLocale = false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400855 do {
tsepezd19e9122016-11-02 15:43:18 -0700856 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400857 if (!bLocale) {
858 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
859 }
860 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
weili44f8faf2016-06-01 14:03:56 -0700861 if (bLocale)
tsepezd19e9122016-11-02 15:43:18 -0700862 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400863 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
864 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
weili44f8faf2016-06-01 14:03:56 -0700865 if (!wsLocaleName.IsEmpty())
tsepezd19e9122016-11-02 15:43:18 -0700866 return true;
weili44f8faf2016-06-01 14:03:56 -0700867 if (pTopSubform &&
tsepezd19e9122016-11-02 15:43:18 -0700868 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) {
869 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400870 }
871 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
872 if (pLocale) {
873 wsLocaleName = pLocale->GetName();
tsepezd19e9122016-11-02 15:43:18 -0700874 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400875 }
tsepezd19e9122016-11-02 15:43:18 -0700876 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400877}
weili44f8faf2016-06-01 14:03:56 -0700878
Dan Sinclair1770c022016-03-14 14:14:16 -0400879XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
dsinclair56a8b192016-06-21 14:15:25 -0700880 CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
Dan Sinclair1770c022016-03-14 14:14:16 -0400881 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
882 if (pKeep) {
883 XFA_ATTRIBUTEENUM eIntact;
tsepezd19e9122016-11-02 15:43:18 -0700884 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400885 if (eIntact == XFA_ATTRIBUTEENUM_None &&
886 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
887 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
dsinclairc5a8f212016-06-20 11:11:12 -0700888 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
889 XFA_ObjectType::ContainerNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400890 if (pPreviewRow &&
891 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
892 XFA_ATTRIBUTEENUM_Row) {
893 XFA_ATTRIBUTEENUM eValue;
tsepezd19e9122016-11-02 15:43:18 -0700894 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700895 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
896 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
897 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400898 }
weili44f8faf2016-06-01 14:03:56 -0700899 CXFA_Node* pNode =
dsinclair56a8b192016-06-21 14:15:25 -0700900 pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
tsepezd19e9122016-11-02 15:43:18 -0700901 if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700902 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
903 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
904 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400905 }
906 }
907 }
908 return eIntact;
909 }
910 }
dsinclair41cb62e2016-06-23 09:20:32 -0700911 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700912 case XFA_Element::Subform:
Dan Sinclair1770c022016-03-14 14:14:16 -0400913 switch (eLayoutType) {
914 case XFA_ATTRIBUTEENUM_Position:
915 case XFA_ATTRIBUTEENUM_Row:
916 return XFA_ATTRIBUTEENUM_ContentArea;
917 case XFA_ATTRIBUTEENUM_Tb:
918 case XFA_ATTRIBUTEENUM_Table:
919 case XFA_ATTRIBUTEENUM_Lr_tb:
920 case XFA_ATTRIBUTEENUM_Rl_tb:
921 return XFA_ATTRIBUTEENUM_None;
922 default:
923 break;
924 }
925 break;
dsinclair56a8b192016-06-21 14:15:25 -0700926 case XFA_Element::Field: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400927 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700928 if (!pParentNode ||
929 pParentNode->GetElementType() == XFA_Element::PageArea)
Dan Sinclair1770c022016-03-14 14:14:16 -0400930 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400931 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
932 XFA_ATTRIBUTEENUM eParLayout =
933 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
934 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
935 eParLayout == XFA_ATTRIBUTEENUM_Row ||
936 eParLayout == XFA_ATTRIBUTEENUM_Table) {
937 return XFA_ATTRIBUTEENUM_None;
938 }
939 XFA_VERSION version = m_pDocument->GetCurVersionMode();
940 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
941 CXFA_Measurement measureH;
tsepezd19e9122016-11-02 15:43:18 -0700942 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false))
Dan Sinclair1770c022016-03-14 14:14:16 -0400943 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400944 }
945 return XFA_ATTRIBUTEENUM_None;
946 }
947 return XFA_ATTRIBUTEENUM_ContentArea;
948 }
dsinclair56a8b192016-06-21 14:15:25 -0700949 case XFA_Element::Draw:
Dan Sinclair1770c022016-03-14 14:14:16 -0400950 return XFA_ATTRIBUTEENUM_ContentArea;
951 default:
952 break;
953 }
954 return XFA_ATTRIBUTEENUM_None;
955}
weili44f8faf2016-06-01 14:03:56 -0700956
Dan Sinclair1770c022016-03-14 14:14:16 -0400957CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
weili44f8faf2016-06-01 14:03:56 -0700958 if (m_ePacket == XFA_XDPPACKET_Datasets)
Dan Sinclair1770c022016-03-14 14:14:16 -0400959 return m_pAuxNode;
weili44f8faf2016-06-01 14:03:56 -0700960 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400961}
weili44f8faf2016-06-01 14:03:56 -0700962
Dan Sinclair1770c022016-03-14 14:14:16 -0400963void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
dsinclair43854a52016-04-27 12:26:00 -0700964 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
Dan Sinclair1770c022016-03-14 14:14:16 -0400965 m_pAuxNode = pDataDescriptionNode;
966}
weili44f8faf2016-06-01 14:03:56 -0700967
Dan Sinclair1770c022016-03-14 14:14:16 -0400968void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
969 int32_t iLength = pArguments->GetLength();
970 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -0500971 ThrowParamCountMismatchException(L"resolveNode");
Dan Sinclair1770c022016-03-14 14:14:16 -0400972 return;
973 }
tsepez6fe7d212016-04-06 10:51:14 -0700974 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -0700975 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclairdf4bc592016-03-31 20:34:43 -0700976 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -0700977 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -0400978 return;
Dan Sinclair1770c022016-03-14 14:14:16 -0400979 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -0700980 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -0400981 refNode = ToNode(pScriptContext->GetThisObject());
tsepez736f28a2016-03-25 14:19:51 -0700982 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -0400983 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
984 XFA_RESOLVENODE_Siblings;
985 XFA_RESOLVENODE_RS resoveNodeRS;
tsepezfc58ad12016-04-05 12:22:15 -0700986 int32_t iRet = pScriptContext->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -0700987 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
dsinclairf27aeec2016-06-07 19:36:18 -0700988 if (iRet < 1) {
989 pArguments->GetReturnValue()->SetNull();
990 return;
991 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400992 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700993 CXFA_Object* pObject = resoveNodeRS.objects.front();
dsinclairf27aeec2016-06-07 19:36:18 -0700994 pArguments->GetReturnValue()->Assign(
Tom Sepezf8a94392017-03-14 12:13:22 -0700995 pScriptContext->GetJSValueFromMap(pObject));
Dan Sinclair1770c022016-03-14 14:14:16 -0400996 } else {
997 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
998 resoveNodeRS.pScriptAttribute;
999 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
dsinclair86fad992016-05-31 11:34:04 -07001000 std::unique_ptr<CFXJSE_Value> pValue(
1001 new CFXJSE_Value(pScriptContext->GetRuntime()));
Tom Sepezf8a94392017-03-14 12:13:22 -07001002 (resoveNodeRS.objects.front()->*(lpAttributeInfo->lpfnCallback))(
tsepezd19e9122016-11-02 15:43:18 -07001003 pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
dsinclairf27aeec2016-06-07 19:36:18 -07001004 pArguments->GetReturnValue()->Assign(pValue.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001005 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001006 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001007 }
1008 }
1009}
weili44f8faf2016-06-01 14:03:56 -07001010
Dan Sinclair1770c022016-03-14 14:14:16 -04001011void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
1012 int32_t iLength = pArguments->GetLength();
1013 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001014 ThrowParamCountMismatchException(L"resolveNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04001015 return;
1016 }
tsepez6fe7d212016-04-06 10:51:14 -07001017 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001018 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclair12a6b0c2016-05-26 11:14:08 -07001019 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001020 if (!pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04001021 return;
tsepez736f28a2016-03-25 14:19:51 -07001022 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001023 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1024 XFA_RESOLVENODE_Siblings;
1025 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001026 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001027 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
dsinclair12a6b0c2016-05-26 11:14:08 -07001028 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001029}
weili44f8faf2016-06-01 14:03:56 -07001030
dsinclair12a6b0c2016-05-26 11:14:08 -07001031void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001032 CFX_WideString wsExpression,
tsepez736f28a2016-03-25 14:19:51 -07001033 uint32_t dwFlag,
Dan Sinclair1770c022016-03-14 14:14:16 -04001034 CXFA_Node* refNode) {
dsinclairdf4bc592016-03-31 20:34:43 -07001035 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001036 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001037 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001038 XFA_RESOLVENODE_RS resoveNodeRS;
weili44f8faf2016-06-01 14:03:56 -07001039 if (!refNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04001040 refNode = this;
tsepez4c3debb2016-04-08 12:20:38 -07001041 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
tsepezfc58ad12016-04-05 12:22:15 -07001042 resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001043 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
1044 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
Tom Sepezf8a94392017-03-14 12:13:22 -07001045 for (CXFA_Object* pObject : resoveNodeRS.objects) {
1046 if (pObject->IsNode())
1047 pNodeList->Append(pObject->AsNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001048 }
1049 } else {
dsinclair12a6b0c2016-05-26 11:14:08 -07001050 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
Tom Sepez369fe1f2017-03-27 16:03:43 -07001051 if (resoveNodeRS.GetAttributeResult(&valueArray) > 0) {
Tom Sepezf8a94392017-03-14 12:13:22 -07001052 for (CXFA_Object* pObject : valueArray.GetAttributeObject()) {
1053 if (pObject->IsNode())
1054 pNodeList->Append(pObject->AsNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001055 }
1056 }
1057 }
dsinclairf27aeec2016-06-07 19:36:18 -07001058 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001059}
weili44f8faf2016-06-01 14:03:56 -07001060
dsinclair12a6b0c2016-05-26 11:14:08 -07001061void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001062 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001063 XFA_ATTRIBUTE eAttribute) {
1064 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001065 ThrowInvalidPropertyException();
1066 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001067 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001068
1069 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
1070 CFX_WideString wsName;
1071 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
dan sinclair65c7c232017-02-02 14:05:30 -08001072 CFX_WideString wsExpression = wsName + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001073 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001074}
weili44f8faf2016-06-01 14:03:56 -07001075
dsinclair12a6b0c2016-05-26 11:14:08 -07001076void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001077 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001078 XFA_ATTRIBUTE eAttribute) {
dsinclairdf4bc592016-03-31 20:34:43 -07001079 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001080 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001081 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001082 if (bSetting) {
Dan Sinclairc8fd3312017-01-02 17:17:02 -05001083 CFX_WideString wsMessage = L"Unable to set ";
Tom Sepezf0b65542017-02-13 10:26:01 -08001084 FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001085 } else {
1086 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
dsinclairf27aeec2016-06-07 19:36:18 -07001087 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001088 }
1089}
weili44f8faf2016-06-01 14:03:56 -07001090
dsinclair12a6b0c2016-05-26 11:14:08 -07001091void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001092 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001093 XFA_ATTRIBUTE eAttribute) {
1094 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001095 ThrowInvalidPropertyException();
1096 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001097 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001098 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
dan sinclair65c7c232017-02-02 14:05:30 -08001099 CFX_WideString wsExpression = L"#" + GetClassName() + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001100 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001101}
weili44f8faf2016-06-01 14:03:56 -07001102
dsinclair12a6b0c2016-05-26 11:14:08 -07001103void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001104 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001105 XFA_ATTRIBUTE eAttribute) {
1106 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001107 ThrowInvalidPropertyException();
1108 return;
1109 }
1110 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
1111 if (pParent) {
1112 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001113 } else {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001114 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001115 }
1116}
weili44f8faf2016-06-01 14:03:56 -07001117
dsinclair12a6b0c2016-05-26 11:14:08 -07001118void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001119 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001120 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001121 if (bSetting) {
1122 ThrowInvalidPropertyException();
1123 return;
1124 }
1125 pValue->SetInteger(GetNodeSameNameIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001126}
weili44f8faf2016-06-01 14:03:56 -07001127
dsinclair12a6b0c2016-05-26 11:14:08 -07001128void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001129 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001130 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001131 if (bSetting) {
1132 ThrowInvalidPropertyException();
1133 return;
1134 }
1135 pValue->SetInteger(GetNodeSameClassIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001136}
weili44f8faf2016-06-01 14:03:56 -07001137
dsinclair12a6b0c2016-05-26 11:14:08 -07001138void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001139 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001140 XFA_ATTRIBUTE eAttribute) {
1141 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001142 ThrowInvalidPropertyException();
1143 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001144 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001145 CFX_WideString wsSOMExpression;
1146 GetSOMExpression(wsSOMExpression);
Tom Sepezf0b65542017-02-13 10:26:01 -08001147 pValue->SetString(wsSOMExpression.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001148}
weili44f8faf2016-06-01 14:03:56 -07001149
Dan Sinclair1770c022016-03-14 14:14:16 -04001150void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
1151 int32_t iLength = pArguments->GetLength();
1152 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001153 ThrowParamCountMismatchException(L"applyXSL");
Dan Sinclair1770c022016-03-14 14:14:16 -04001154 return;
1155 }
tsepez6fe7d212016-04-06 10:51:14 -07001156 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001157 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili60607c32016-05-26 11:53:12 -07001158 // TODO(weili): check whether we need to implement this, pdfium:501.
1159 // For now, just put the variables here to avoid unused variable warning.
1160 (void)wsExpression;
Dan Sinclair1770c022016-03-14 14:14:16 -04001161}
weili60607c32016-05-26 11:53:12 -07001162
Dan Sinclair1770c022016-03-14 14:14:16 -04001163void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
1164 int32_t iLength = pArguments->GetLength();
1165 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001166 ThrowParamCountMismatchException(L"assignNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04001167 return;
1168 }
1169 CFX_WideString wsExpression;
1170 CFX_WideString wsValue;
1171 int32_t iAction = 0;
weili44f8faf2016-06-01 14:03:56 -07001172 wsExpression =
1173 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001174 if (iLength >= 2) {
weili60607c32016-05-26 11:53:12 -07001175 wsValue =
1176 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001177 }
weili60607c32016-05-26 11:53:12 -07001178 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001179 iAction = pArguments->GetInt32(2);
weili60607c32016-05-26 11:53:12 -07001180 // TODO(weili): check whether we need to implement this, pdfium:501.
1181 // For now, just put the variables here to avoid unused variable warning.
1182 (void)wsExpression;
1183 (void)wsValue;
1184 (void)iAction;
Dan Sinclair1770c022016-03-14 14:14:16 -04001185}
weili60607c32016-05-26 11:53:12 -07001186
Dan Sinclair1770c022016-03-14 14:14:16 -04001187void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
1188 int32_t iLength = pArguments->GetLength();
1189 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001190 ThrowParamCountMismatchException(L"clone");
Dan Sinclair1770c022016-03-14 14:14:16 -04001191 return;
1192 }
weili44f8faf2016-06-01 14:03:56 -07001193 bool bClone = !!pArguments->GetInt32(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001194 CXFA_Node* pCloneNode = Clone(bClone);
dsinclairf27aeec2016-06-07 19:36:18 -07001195 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001196 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
1197}
weili44f8faf2016-06-01 14:03:56 -07001198
Dan Sinclair1770c022016-03-14 14:14:16 -04001199void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
1200 int32_t iLength = pArguments->GetLength();
1201 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001202 ThrowParamCountMismatchException(L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001203 return;
1204 }
tsepez6fe7d212016-04-06 10:51:14 -07001205 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001206 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001207 CFX_WideString wsValue;
tsepez4c3debb2016-04-08 12:20:38 -07001208 GetAttribute(wsExpression.AsStringC(), wsValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07001209 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001210 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08001211 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001212}
weili44f8faf2016-06-01 14:03:56 -07001213
Dan Sinclair1770c022016-03-14 14:14:16 -04001214void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
1215 int32_t iLength = pArguments->GetLength();
1216 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001217 ThrowParamCountMismatchException(L"getElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001218 return;
1219 }
1220 CFX_WideString wsExpression;
1221 int32_t iValue = 0;
weili44f8faf2016-06-01 14:03:56 -07001222 wsExpression =
1223 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1224 if (iLength >= 2)
Dan Sinclair1770c022016-03-14 14:14:16 -04001225 iValue = pArguments->GetInt32(1);
dsinclair6e124782016-06-23 12:14:55 -07001226 CXFA_Node* pNode =
1227 GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
dsinclairf27aeec2016-06-07 19:36:18 -07001228 pArguments->GetReturnValue()->Assign(
1229 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001230}
weili65be4b12016-05-25 15:47:43 -07001231
Dan Sinclair1770c022016-03-14 14:14:16 -04001232void CXFA_Node::Script_NodeClass_IsPropertySpecified(
1233 CFXJSE_Arguments* pArguments) {
1234 int32_t iLength = pArguments->GetLength();
1235 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001236 ThrowParamCountMismatchException(L"isPropertySpecified");
Dan Sinclair1770c022016-03-14 14:14:16 -04001237 return;
1238 }
1239 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001240 bool bParent = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001241 int32_t iIndex = 0;
weili44f8faf2016-06-01 14:03:56 -07001242 wsExpression =
1243 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili65be4b12016-05-25 15:47:43 -07001244 if (iLength >= 2)
weili44f8faf2016-06-01 14:03:56 -07001245 bParent = !!pArguments->GetInt32(1);
weili65be4b12016-05-25 15:47:43 -07001246 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001247 iIndex = pArguments->GetInt32(2);
tsepezd19e9122016-11-02 15:43:18 -07001248 bool bHas = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001249 const XFA_ATTRIBUTEINFO* pAttributeInfo =
tsepez4c3debb2016-04-08 12:20:38 -07001250 XFA_GetAttributeByName(wsExpression.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001251 CFX_WideString wsValue;
weili65be4b12016-05-25 15:47:43 -07001252 if (pAttributeInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04001253 bHas = HasAttribute(pAttributeInfo->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04001254 if (!bHas) {
dsinclair6e124782016-06-23 12:14:55 -07001255 XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
1256 bHas = !!GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001257 if (!bHas && bParent && m_pParent) {
1258 // Also check on the parent.
1259 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
1260 if (!bHas)
dsinclair6e124782016-06-23 12:14:55 -07001261 bHas = !!m_pParent->GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001262 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001263 }
dsinclair12a6b0c2016-05-26 11:14:08 -07001264 CFXJSE_Value* pValue = pArguments->GetReturnValue();
1265 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001266 pValue->SetBoolean(bHas);
Dan Sinclair1770c022016-03-14 14:14:16 -04001267}
weili65be4b12016-05-25 15:47:43 -07001268
Dan Sinclair1770c022016-03-14 14:14:16 -04001269void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
1270 int32_t iLength = pArguments->GetLength();
1271 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001272 ThrowParamCountMismatchException(L"loadXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001273 return;
1274 }
1275 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001276 bool bIgnoreRoot = true;
1277 bool bOverwrite = 0;
1278 wsExpression =
1279 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1280 if (wsExpression.IsEmpty())
Tom Sepezd3743ea2016-05-16 15:56:53 -07001281 return;
weili44f8faf2016-06-01 14:03:56 -07001282 if (iLength >= 2)
1283 bIgnoreRoot = !!pArguments->GetInt32(1);
1284 if (iLength >= 3)
1285 bOverwrite = !!pArguments->GetInt32(2);
dsinclaira1b07722016-07-11 08:20:58 -07001286 std::unique_ptr<CXFA_SimpleParser> pParser(
1287 new CXFA_SimpleParser(m_pDocument, false));
weili44f8faf2016-06-01 14:03:56 -07001288 if (!pParser)
Dan Sinclair1770c022016-03-14 14:14:16 -04001289 return;
weili44f8faf2016-06-01 14:03:56 -07001290 CFDE_XMLNode* pXMLNode = nullptr;
1291 int32_t iParserStatus =
1292 pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
1293 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
1294 return;
dsinclairae95f762016-03-29 16:58:29 -07001295 if (bIgnoreRoot &&
1296 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
1297 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
weili44f8faf2016-06-01 14:03:56 -07001298 bIgnoreRoot = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001299 }
tsepezd19e9122016-11-02 15:43:18 -07001300 CXFA_Node* pFakeRoot = Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001301 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
1302 if (!wsContentType.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07001303 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
1304 CFX_WideString(wsContentType));
Dan Sinclair1770c022016-03-14 14:14:16 -04001305 }
dsinclairae95f762016-03-29 16:58:29 -07001306 CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001307 if (!pFakeXMLRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001308 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
tsepezd19e9122016-11-02 15:43:18 -07001309 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001310 }
dsinclair017052a2016-06-28 07:43:51 -07001311 if (!pFakeXMLRoot)
1312 pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName()));
1313
Dan Sinclair1770c022016-03-14 14:14:16 -04001314 if (bIgnoreRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001315 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001316 while (pXMLChild) {
dsinclairae95f762016-03-29 16:58:29 -07001317 CFDE_XMLNode* pXMLSibling =
1318 pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001319 pXMLNode->RemoveChildNode(pXMLChild);
1320 pFakeXMLRoot->InsertChildNode(pXMLChild);
1321 pXMLChild = pXMLSibling;
1322 }
1323 } else {
dsinclairae95f762016-03-29 16:58:29 -07001324 CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001325 if (pXMLParent) {
1326 pXMLParent->RemoveChildNode(pXMLNode);
1327 }
1328 pFakeXMLRoot->InsertChildNode(pXMLNode);
1329 }
1330 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot);
1331 pFakeRoot = pParser->GetRootNode();
1332 if (pFakeRoot) {
1333 if (bOverwrite) {
1334 CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1335 CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1336 int32_t index = 0;
1337 while (pNewChild) {
1338 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1339 pFakeRoot->RemoveChild(pNewChild);
1340 InsertChild(index++, pNewChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001341 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001342 pNewChild = pItem;
1343 }
1344 while (pChild) {
1345 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1346 RemoveChild(pChild);
1347 pFakeRoot->InsertChild(pChild);
1348 pChild = pItem;
1349 }
1350 if (GetPacketID() == XFA_XDPPACKET_Form &&
dsinclair070fcdf2016-06-22 22:04:54 -07001351 GetElementType() == XFA_Element::ExData) {
dsinclairae95f762016-03-29 16:58:29 -07001352 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001353 SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001354 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
weili44f8faf2016-06-01 14:03:56 -07001355 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001356 pFakeXMLRoot = pTempXMLNode;
1357 } else {
weili44f8faf2016-06-01 14:03:56 -07001358 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001359 }
1360 }
tsepezd19e9122016-11-02 15:43:18 -07001361 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001362 } else {
1363 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1364 while (pChild) {
1365 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1366 pFakeRoot->RemoveChild(pChild);
1367 InsertChild(pChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001368 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001369 pChild = pItem;
1370 }
1371 }
1372 if (pFakeXMLRoot) {
1373 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001374 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001375 }
dsinclairc5a8f212016-06-20 11:11:12 -07001376 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001377 } else {
tsepezc757d9a2017-01-23 11:01:42 -08001378 delete pFakeXMLRoot;
1379 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001380 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001381}
weili44f8faf2016-06-01 14:03:56 -07001382
Dan Sinclair1770c022016-03-14 14:14:16 -04001383void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
weili44f8faf2016-06-01 14:03:56 -07001384 // TODO(weili): Check whether we need to implement this, pdfium:501.
Dan Sinclair1770c022016-03-14 14:14:16 -04001385}
1386
1387void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1388 int32_t iLength = pArguments->GetLength();
1389 if (iLength < 0 || iLength > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001390 ThrowParamCountMismatchException(L"saveXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001391 return;
1392 }
weili44f8faf2016-06-01 14:03:56 -07001393 bool bPrettyMode = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001394 if (iLength == 1) {
weili65be4b12016-05-25 15:47:43 -07001395 if (pArguments->GetUTF8String(0) != "pretty") {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001396 ThrowArgumentMismatchException();
Dan Sinclair1770c022016-03-14 14:14:16 -04001397 return;
1398 }
weili44f8faf2016-06-01 14:03:56 -07001399 bPrettyMode = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001400 }
1401 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
weili65be4b12016-05-25 15:47:43 -07001402 if (GetPacketID() == XFA_XDPPACKET_Form ||
1403 GetPacketID() == XFA_XDPPACKET_Datasets) {
1404 CFDE_XMLNode* pElement = nullptr;
1405 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1406 pElement = GetXMLMappingNode();
1407 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
dsinclairf27aeec2016-06-07 19:36:18 -07001408 pArguments->GetReturnValue()->SetString(bsXMLHeader);
weili65be4b12016-05-25 15:47:43 -07001409 return;
1410 }
1411 XFA_DataExporter_DealWithDataGroupNode(this);
1412 }
tsepez833619b2016-12-07 09:21:17 -08001413 CFX_RetainPtr<IFX_MemoryStream> pMemoryStream =
1414 IFX_MemoryStream::Create(true);
1415
1416 // Note: ambiguious below without static_cast.
tsepez7cda31a2016-12-07 12:10:20 -08001417 CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream(
1418 CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream),
1419 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
tsepez833619b2016-12-07 09:21:17 -08001420
Dan Sinclair1770c022016-03-14 14:14:16 -04001421 if (!pStream) {
dsinclairf27aeec2016-06-07 19:36:18 -07001422 pArguments->GetReturnValue()->SetString(bsXMLHeader);
Dan Sinclair1770c022016-03-14 14:14:16 -04001423 return;
1424 }
1425 pStream->SetCodePage(FX_CODEPAGE_UTF8);
dsinclair179bebb2016-04-05 11:02:18 -07001426 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
weili65be4b12016-05-25 15:47:43 -07001427 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepez7cda31a2016-12-07 12:10:20 -08001428 XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001429 else
tsepez7cda31a2016-12-07 12:10:20 -08001430 pElement->SaveXMLNode(pStream);
weili65be4b12016-05-25 15:47:43 -07001431 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1432 // For now, just put it here to avoid unused variable warning.
1433 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001434 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001435 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001436 return;
1437 }
dsinclairf27aeec2016-06-07 19:36:18 -07001438 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001439}
1440
1441void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1442 int32_t iLength = pArguments->GetLength();
1443 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001444 ThrowParamCountMismatchException(L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001445 return;
1446 }
tsepez6fe7d212016-04-06 10:51:14 -07001447 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001448 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001449 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001450 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001451 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001452}
weili60607c32016-05-26 11:53:12 -07001453
Dan Sinclair1770c022016-03-14 14:14:16 -04001454void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1455 int32_t iLength = pArguments->GetLength();
1456 if (iLength != 1 && iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001457 ThrowParamCountMismatchException(L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001458 return;
1459 }
weili60607c32016-05-26 11:53:12 -07001460 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001461 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001462 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1463 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001464 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001465 // TODO(weili): check whether we need to implement this, pdfium:501.
1466 // For now, just put the variables here to avoid unused variable warning.
1467 (void)pNode;
1468 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001469}
weili60607c32016-05-26 11:53:12 -07001470
dsinclair12a6b0c2016-05-26 11:14:08 -07001471void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001472 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001473 XFA_ATTRIBUTE eAttribute) {
1474 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001475 ThrowInvalidPropertyException();
1476 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001477 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001478
1479 CFX_WideString wsNameSpace;
1480 TryNamespace(wsNameSpace);
Tom Sepezf0b65542017-02-13 10:26:01 -08001481 pValue->SetString(wsNameSpace.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001482}
weili44f8faf2016-06-01 14:03:56 -07001483
dsinclair12a6b0c2016-05-26 11:14:08 -07001484void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001485 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001486 XFA_ATTRIBUTE eAttribute) {
1487 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001488 ThrowInvalidPropertyException();
1489 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001490 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001491 pValue->Assign(
1492 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001493}
weili44f8faf2016-06-01 14:03:56 -07001494
dsinclair12a6b0c2016-05-26 11:14:08 -07001495void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001496 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001497 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001498 if (bSetting) {
1499 ThrowInvalidPropertyException();
1500 return;
1501 }
1502 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001503}
weili44f8faf2016-06-01 14:03:56 -07001504
dsinclair12a6b0c2016-05-26 11:14:08 -07001505void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001506 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001507 XFA_ATTRIBUTE eAttribute) {
1508 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001509 ThrowInvalidPropertyException();
1510 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001511 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001512 if (GetElementType() == XFA_Element::Subform) {
1513 pValue->SetBoolean(false);
1514 return;
1515 }
1516 CFX_WideString strValue;
1517 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001518}
weili44f8faf2016-06-01 14:03:56 -07001519
dsinclair12a6b0c2016-05-26 11:14:08 -07001520void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001521 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001522 XFA_ATTRIBUTE eAttribute) {
1523 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001524 ThrowInvalidPropertyException();
1525 return;
1526 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001527 std::vector<CXFA_Node*> properties =
1528 GetNodeList(XFA_NODEFILTER_OneOfProperty);
1529 if (!properties.empty()) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001530 pValue->Assign(
Tom Sepezf8a94392017-03-14 12:13:22 -07001531 m_pDocument->GetScriptContext()->GetJSValueFromMap(properties.front()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001532 }
1533}
weili44f8faf2016-06-01 14:03:56 -07001534
Dan Sinclair1770c022016-03-14 14:14:16 -04001535void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001536
Dan Sinclair1770c022016-03-14 14:14:16 -04001537void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1538 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001539 pArguments->GetReturnValue()->SetObject(
1540 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001541}
1542void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1543}
dsinclair5b36f0a2016-07-19 10:56:23 -07001544
Dan Sinclair1770c022016-03-14 14:14:16 -04001545void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1546 Script_Template_CreateNode(pArguments);
1547}
dsinclair5b36f0a2016-07-19 10:56:23 -07001548
Dan Sinclair1770c022016-03-14 14:14:16 -04001549void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1550 int32_t iLength = pArguments->GetLength();
1551 if (iLength < 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001552 ThrowParamCountMismatchException(L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001553 return;
1554 }
1555 CFX_WideString wsNameSpace;
1556 if (iLength >= 1) {
1557 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001558 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001559 }
1560 CFX_WideString wsNodeNameSpace;
1561 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001562 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001563 if (pValue)
1564 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001565}
dsinclair5b36f0a2016-07-19 10:56:23 -07001566
dsinclair12a6b0c2016-05-26 11:14:08 -07001567void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001568 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001569 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001570
dsinclair12a6b0c2016-05-26 11:14:08 -07001571void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001572 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001573 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001574
dsinclair12a6b0c2016-05-26 11:14:08 -07001575void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001576 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001577 XFA_ATTRIBUTE eAttribute) {
1578 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001579 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001580 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001581 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001582 }
1583}
dsinclair5b36f0a2016-07-19 10:56:23 -07001584
dsinclair12a6b0c2016-05-26 11:14:08 -07001585void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001586 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001587 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001588 if (bSetting) {
1589 ThrowInvalidPropertyException();
1590 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001591 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001592 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001593}
dsinclair5b36f0a2016-07-19 10:56:23 -07001594
dsinclair12a6b0c2016-05-26 11:14:08 -07001595void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001596 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001597 XFA_ATTRIBUTE eAttribute) {
1598 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001599 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001600 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001601 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001602 }
1603}
dsinclair5b36f0a2016-07-19 10:56:23 -07001604
dsinclair12a6b0c2016-05-26 11:14:08 -07001605void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001606 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001607 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001608 if (bSetting) {
1609 ThrowInvalidPropertyException();
1610 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001611 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001612 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001613}
thestigb1a59592016-04-14 18:29:56 -07001614
Dan Sinclair1770c022016-03-14 14:14:16 -04001615void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001616 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001617 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001618 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001619 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001620 return;
thestigb1a59592016-04-14 18:29:56 -07001621
dsinclaira1b07722016-07-11 08:20:58 -07001622 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001623 if (!pNotify)
1624 return;
1625
1626 uint32_t dwPacket = GetPacketID();
1627 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1628 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001629 return;
1630 }
thestigb1a59592016-04-14 18:29:56 -07001631
1632 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001633 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001634 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001635 bNeedFindContainer = true;
1636 pNotify->OnValueChanged(this, eAttribute, this,
1637 GetNodeItem(XFA_NODEITEM_Parent));
1638 break;
dsinclair56a8b192016-06-21 14:15:25 -07001639 case XFA_Element::Font:
1640 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001641 bNeedFindContainer = true;
1642 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001643 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001644 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1645 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1646 } else {
1647 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1648 }
1649 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001650 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001651 bNeedFindContainer = true;
1652 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001653 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001654 if (pParentNode->IsContainerNode()) {
1655 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001656 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001657 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1658 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1659 } else {
1660 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001661 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001662 pNotify->OnValueChanged(this, eAttribute, pNode,
1663 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001664 }
thestigb1a59592016-04-14 18:29:56 -07001665 }
1666 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001667 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001668 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001669 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001670 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1671 eUIType == XFA_Element::NumericEdit ||
1672 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001673 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001674 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001675 pNotify->OnValueChanged(this, eAttribute, pUINode,
1676 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001677 }
thestigb1a59592016-04-14 18:29:56 -07001678 }
1679 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001680 case XFA_Element::Button:
1681 case XFA_Element::Barcode:
1682 case XFA_Element::ChoiceList:
1683 case XFA_Element::DateTimeEdit:
1684 case XFA_Element::NumericEdit:
1685 case XFA_Element::PasswordEdit:
1686 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001687 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1688 if (pUINode) {
1689 pNotify->OnValueChanged(this, eAttribute, pUINode,
1690 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1691 }
1692 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001693 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001694 bNeedFindContainer = true;
1695 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1696 if (pUINode) {
1697 pNotify->OnValueChanged(this, eAttribute, pUINode,
1698 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1699 }
1700 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001701 case XFA_Element::Keep:
1702 case XFA_Element::Bookend:
1703 case XFA_Element::Break:
1704 case XFA_Element::BreakAfter:
1705 case XFA_Element::BreakBefore:
1706 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001707 bNeedFindContainer = true;
1708 break;
dsinclair56a8b192016-06-21 14:15:25 -07001709 case XFA_Element::Area:
1710 case XFA_Element::Draw:
1711 case XFA_Element::ExclGroup:
1712 case XFA_Element::Field:
1713 case XFA_Element::Subform:
1714 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001715 pLayoutPro->AddChangedContainer(this);
1716 pNotify->OnValueChanged(this, eAttribute, this, this);
1717 break;
dsinclair56a8b192016-06-21 14:15:25 -07001718 case XFA_Element::Sharptext:
1719 case XFA_Element::Sharpxml:
1720 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001721 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1722 if (!pTextNode) {
1723 return;
1724 }
1725 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1726 if (!pValueNode) {
1727 return;
1728 }
dsinclair41cb62e2016-06-23 09:20:32 -07001729 XFA_Element eType = pValueNode->GetElementType();
1730 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001731 bNeedFindContainer = true;
1732 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1733 if (pNode && pNode->IsContainerNode()) {
1734 if (bScriptModify) {
1735 pValueNode = pNode;
1736 }
1737 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1738 } else {
1739 pNotify->OnValueChanged(this, eAttribute, pNode,
1740 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001741 }
thestigb1a59592016-04-14 18:29:56 -07001742 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001743 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001744 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1745 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001746 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001747 }
1748 }
thestigb1a59592016-04-14 18:29:56 -07001749 }
1750 } break;
1751 default:
1752 break;
1753 }
1754 if (bNeedFindContainer) {
1755 CXFA_Node* pParent = this;
1756 while (pParent) {
1757 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001758 break;
thestigb1a59592016-04-14 18:29:56 -07001759
1760 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001761 }
thestigb1a59592016-04-14 18:29:56 -07001762 if (pParent) {
1763 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001764 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001765 }
1766}
thestigb1a59592016-04-14 18:29:56 -07001767
dsinclair12a6b0c2016-05-26 11:14:08 -07001768void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001769 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001770 XFA_ATTRIBUTE eAttribute) {
1771 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001772 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001773 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001774 if (eAttribute == XFA_ATTRIBUTE_Use &&
1775 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001776 CXFA_Node* pTemplateNode =
1777 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1778 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001779 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1780 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001781
1782 CFX_WideString wsID;
1783 CFX_WideString wsSOM;
1784 if (!wsValue.IsEmpty()) {
1785 if (wsValue[0] == '#') {
1786 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001787 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001788 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001789 }
1790 }
weili44f8faf2016-06-01 14:03:56 -07001791 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001792 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001793 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001794 XFA_RESOLVENODE_Attributes |
1795 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1796 XFA_RESOLVENODE_Siblings;
1797 XFA_RESOLVENODE_RS resoveNodeRS;
1798 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001799 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Tom Sepezf8a94392017-03-14 12:13:22 -07001800 if (iRet > 0 && resoveNodeRS.objects.front()->IsNode()) {
1801 pProtoNode = resoveNodeRS.objects.front()->AsNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001802 }
1803 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001804 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001805 }
1806 if (pProtoNode) {
1807 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1808 while (pHeadChild) {
1809 CXFA_Node* pSibling =
1810 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1811 RemoveChild(pHeadChild);
1812 pHeadChild = pSibling;
1813 }
tsepezd19e9122016-11-02 15:43:18 -07001814 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001815 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1816 while (pHeadChild) {
1817 CXFA_Node* pSibling =
1818 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1819 pProtoForm->RemoveChild(pHeadChild);
1820 InsertChild(pHeadChild);
1821 pHeadChild = pSibling;
1822 }
1823 m_pDocument->RemovePurgeNode(pProtoForm);
1824 delete pProtoForm;
1825 }
1826 }
1827 } else {
1828 CFX_WideString wsValue;
1829 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001830 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001831 }
1832}
dsinclair5b36f0a2016-07-19 10:56:23 -07001833
dsinclair12a6b0c2016-05-26 11:14:08 -07001834void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001835 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001836 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001837 if (bSetting) {
1838 ThrowInvalidPropertyException();
1839 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001840 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001841
1842 CFX_WideString wsValue;
1843 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001844 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001845}
dsinclair5b36f0a2016-07-19 10:56:23 -07001846
Dan Sinclair1770c022016-03-14 14:14:16 -04001847void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1848 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001849 if (argc != 0 && argc != 1) {
1850 ThrowParamCountMismatchException(L"execute");
1851 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001852 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001853 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001854}
dsinclair5b36f0a2016-07-19 10:56:23 -07001855
Dan Sinclair1770c022016-03-14 14:14:16 -04001856void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001857 if (pArguments->GetLength() != 0)
1858 ThrowParamCountMismatchException(L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001859}
dsinclair5b36f0a2016-07-19 10:56:23 -07001860
dsinclair12a6b0c2016-05-26 11:14:08 -07001861void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001862 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001863 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001864
dsinclair12a6b0c2016-05-26 11:14:08 -07001865void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001866 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001867 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001868
dsinclair12a6b0c2016-05-26 11:14:08 -07001869void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001870 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001871 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001872
dsinclair12a6b0c2016-05-26 11:14:08 -07001873void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001874 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001875 XFA_SOM_MESSAGETYPE iMessageType) {
1876 CXFA_WidgetData* pWidgetData = GetWidgetData();
1877 if (!pWidgetData) {
1878 return;
1879 }
tsepezd19e9122016-11-02 15:43:18 -07001880 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001881 CXFA_Validate validate = pWidgetData->GetValidate();
1882 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001883 validate = pWidgetData->GetValidate(true);
1884 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001885 }
1886 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001887 switch (iMessageType) {
1888 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001889 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001890 break;
1891 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001892 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001893 break;
1894 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001895 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001896 break;
1897 default:
1898 break;
1899 }
1900 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001901 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001902 if (!pNotify) {
1903 return;
1904 }
1905 pNotify->AddCalcValidate(this);
1906 }
1907 } else {
1908 CFX_WideString wsMessage;
1909 switch (iMessageType) {
1910 case XFA_SOM_ValidationMessage:
1911 validate.GetScriptMessageText(wsMessage);
1912 break;
1913 case XFA_SOM_FormatMessage:
1914 validate.GetFormatMessageText(wsMessage);
1915 break;
1916 case XFA_SOM_MandatoryMessage:
1917 validate.GetNullMessageText(wsMessage);
1918 break;
1919 default:
1920 break;
1921 }
Tom Sepezf0b65542017-02-13 10:26:01 -08001922 pValue->SetString(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001923 }
1924}
dsinclair5b36f0a2016-07-19 10:56:23 -07001925
dsinclair12a6b0c2016-05-26 11:14:08 -07001926void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001927 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001928 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001929 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001930}
dsinclair5b36f0a2016-07-19 10:56:23 -07001931
dsinclair12a6b0c2016-05-26 11:14:08 -07001932void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001933 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001934 XFA_ATTRIBUTE eAttribute) {
1935 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001936 ThrowInvalidPropertyException();
1937 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001938 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001939
1940 CXFA_WidgetData* pWidgetData = GetWidgetData();
1941 if (!pWidgetData) {
1942 pValue->SetInteger(0);
1943 return;
1944 }
1945 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001946}
dsinclair5b36f0a2016-07-19 10:56:23 -07001947
dsinclair12a6b0c2016-05-26 11:14:08 -07001948void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001949 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001950 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001951 XFA_Element eType = GetElementType();
1952 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001953 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001954 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001955 }
1956 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001957 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001958 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001959 }
1960 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001961 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001962 return;
1963 }
1964 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001965 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07001966 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07001967 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07001968
Dan Sinclair1770c022016-03-14 14:14:16 -04001969 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07001970 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001971 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001972 CFX_WideString wsPicture;
Tom Sepezf8a94392017-03-14 12:13:22 -07001973 for (CXFA_Node* pFormNode : GetBindItems()) {
1974 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -04001975 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001976 pContainerWidgetData = pFormNode->GetContainerWidgetData();
1977 if (pContainerWidgetData) {
1978 pContainerWidgetData->GetPictureContent(wsPicture,
1979 XFA_VALUEPICTURE_DataBind);
1980 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001981 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -04001982 break;
weili44f8faf2016-06-01 14:03:56 -07001983 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001984 }
1985 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
1986 pContainerWidgetData = GetContainerWidgetData();
1987 }
1988 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07001989 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04001990 }
tsepezd19e9122016-11-02 15:43:18 -07001991 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001992 } else {
tsepezd19e9122016-11-02 15:43:18 -07001993 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07001994 if (content.IsEmpty() && eType != XFA_Element::Text &&
1995 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07001996 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07001997 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07001998 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07001999 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07002000 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002001 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002002 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002003 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002004 }
2005 }
2006}
dsinclair5b36f0a2016-07-19 10:56:23 -07002007
dsinclair12a6b0c2016-05-26 11:14:08 -07002008void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002009 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002010 XFA_ATTRIBUTE eAttribute) {
2011 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002012 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002013 return;
2014 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002015
tsepezd19e9122016-11-02 15:43:18 -07002016 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002017 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002018 pValue->SetNull();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002019 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002020 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002021 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002022}
dsinclair5b36f0a2016-07-19 10:56:23 -07002023
dsinclair12a6b0c2016-05-26 11:14:08 -07002024void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002025 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002026 XFA_ATTRIBUTE eAttribute) {
2027 if (bSetting) {
2028 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002029 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002030 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002031
tsepezb4c9f3f2016-04-13 15:41:21 -07002032 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002033 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002034 CFX_WideString wsFormatValue(wsNewValue);
2035 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2036 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002037 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002038 }
tsepezd19e9122016-11-02 15:43:18 -07002039 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002040 } else {
tsepezd19e9122016-11-02 15:43:18 -07002041 CFX_WideString wsValue = GetScriptContent(true);
dan sinclair65c7c232017-02-02 14:05:30 -08002042 pValue->SetBoolean(wsValue == L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002043 }
2044}
dsinclair2f5582f2016-06-09 11:48:23 -07002045
dsinclair12a6b0c2016-05-26 11:14:08 -07002046void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002047 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002048 XFA_ATTRIBUTE eAttribute) {
2049 CXFA_WidgetData* pWidgetData = GetWidgetData();
2050 if (!pWidgetData) {
2051 return;
2052 }
tsepezd19e9122016-11-02 15:43:18 -07002053 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002054 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002055 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002056 int32_t r = 0;
2057 int32_t g = 0;
2058 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002059 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002060 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2061 for (int32_t i = 0; i < iSize; ++i) {
2062 CXFA_Edge edge = border.GetEdge(i);
2063 edge.SetColor(rgb);
2064 }
2065 } else {
2066 CXFA_Edge edge = border.GetEdge(0);
2067 FX_ARGB color = edge.GetColor();
2068 int32_t a, r, g, b;
2069 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002070 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002071 strColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002072 pValue->SetString(strColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002073 }
2074}
dsinclair5b36f0a2016-07-19 10:56:23 -07002075
dsinclair12a6b0c2016-05-26 11:14:08 -07002076void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002077 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002078 XFA_ATTRIBUTE eAttribute) {
2079 CXFA_WidgetData* pWidgetData = GetWidgetData();
2080 if (!pWidgetData) {
2081 return;
2082 }
tsepezd19e9122016-11-02 15:43:18 -07002083 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002084 int32_t iSize = border.CountEdges();
2085 CFX_WideString wsThickness;
2086 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002087 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002088 for (int32_t i = 0; i < iSize; ++i) {
2089 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002090 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002091 edge.SetMSThickness(thickness);
2092 }
2093 } else {
2094 CXFA_Edge edge = border.GetEdge(0);
2095 CXFA_Measurement thickness = edge.GetMSThickness();
2096 thickness.ToString(wsThickness);
Tom Sepezf0b65542017-02-13 10:26:01 -08002097 pValue->SetString(wsThickness.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002098 }
2099}
dsinclair5b36f0a2016-07-19 10:56:23 -07002100
dsinclair12a6b0c2016-05-26 11:14:08 -07002101void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002102 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002103 XFA_ATTRIBUTE eAttribute) {
2104 CXFA_WidgetData* pWidgetData = GetWidgetData();
2105 if (!pWidgetData) {
2106 return;
2107 }
tsepezd19e9122016-11-02 15:43:18 -07002108 CXFA_Border border = pWidgetData->GetBorder(true);
2109 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002110 CXFA_Node* pNode = borderfill.GetNode();
2111 if (!pNode) {
2112 return;
2113 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002114 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002115 int32_t r;
2116 int32_t g;
2117 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002118 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002119 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2120 borderfill.SetColor(color);
2121 } else {
2122 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002123 int32_t a;
2124 int32_t r;
2125 int32_t g;
2126 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002127 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002128 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002129 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002130 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002131 }
2132}
dsinclair5b36f0a2016-07-19 10:56:23 -07002133
dsinclair12a6b0c2016-05-26 11:14:08 -07002134void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002135 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002136 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002137 if (bSetting) {
2138 ThrowInvalidPropertyException();
2139 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002140 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002141
2142 CXFA_Node* pDataNode = GetBindData();
2143 if (!pDataNode) {
2144 pValue->SetNull();
2145 return;
2146 }
2147
2148 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002149}
dsinclair5b36f0a2016-07-19 10:56:23 -07002150
dsinclair12a6b0c2016-05-26 11:14:08 -07002151void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002152 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002153 XFA_ATTRIBUTE eAttribute) {
2154 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002155 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002156 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002157 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002158 XFA_Element uiType = pWidgetData->GetUIType();
2159 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002160 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002161 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002162 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002163 }
2164 }
2165 } else {
tsepezd19e9122016-11-02 15:43:18 -07002166 CFX_WideString content = GetScriptContent(true);
Tom Sepezf0b65542017-02-13 10:26:01 -08002167 if (content.IsEmpty())
dsinclairf27aeec2016-06-07 19:36:18 -07002168 pValue->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002169 else
2170 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002171 }
2172}
dsinclair5b36f0a2016-07-19 10:56:23 -07002173
dsinclair12a6b0c2016-05-26 11:14:08 -07002174void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002175 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002176 XFA_ATTRIBUTE eAttribute) {
2177 CXFA_WidgetData* pWidgetData = GetWidgetData();
2178 if (!pWidgetData) {
2179 return;
2180 }
2181 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002182 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002183 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002184 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002185 } else {
2186 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002187 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002188 }
dsinclair2f5582f2016-06-09 11:48:23 -07002189 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002190 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002191 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002192
Dan Sinclair1770c022016-03-14 14:14:16 -04002193 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002194 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002195 int32_t iLeadDigits = 0;
2196 int32_t iFracDigits = 0;
2197 pWidgetData->GetLeadDigits(iLeadDigits);
2198 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002199 wsNewText =
2200 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002201 }
2202 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2203 CFX_WideString wsFormatText(wsNewText);
2204 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002205 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002206 }
tsepezd19e9122016-11-02 15:43:18 -07002207 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002208 } else {
tsepezd19e9122016-11-02 15:43:18 -07002209 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002210 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002211 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002212 } else {
2213 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002214 CXFA_Value defVal = pWidgetData->GetFormValue();
2215 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002216 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002217 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002218 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
Tom Sepezf0b65542017-02-13 10:26:01 -08002219 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002220 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002221 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002222 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002223 }
dsinclair070fcdf2016-06-22 22:04:54 -07002224 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002225 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002226 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002227 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002228 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002229 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002230 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002231 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002232 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002233 }
2234 }
2235 }
2236}
dsinclair5b36f0a2016-07-19 10:56:23 -07002237
dsinclair12a6b0c2016-05-26 11:14:08 -07002238void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002239 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002240 XFA_ATTRIBUTE eAttribute) {
2241 CXFA_WidgetData* pWidgetData = GetWidgetData();
2242 if (!pWidgetData) {
2243 return;
2244 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002245 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002246 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002247 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002248 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002249 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
Tom Sepezf0b65542017-02-13 10:26:01 -08002250 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002251 }
2252}
dsinclair5b36f0a2016-07-19 10:56:23 -07002253
dsinclair12a6b0c2016-05-26 11:14:08 -07002254void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002255 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002256 XFA_ATTRIBUTE eAttribute) {
2257 CXFA_WidgetData* pWidgetData = GetWidgetData();
2258 if (!pWidgetData) {
2259 return;
2260 }
tsepezd19e9122016-11-02 15:43:18 -07002261 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002262 CXFA_Node* pNode = font.GetNode();
2263 if (!pNode) {
2264 return;
2265 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002266 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002267 int32_t r;
2268 int32_t g;
2269 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002270 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002271 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2272 font.SetColor(color);
2273 } else {
2274 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002275 int32_t a;
2276 int32_t r;
2277 int32_t g;
2278 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002279 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002280 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002281 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002282 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002283 }
2284}
dsinclair5b36f0a2016-07-19 10:56:23 -07002285
dsinclair12a6b0c2016-05-26 11:14:08 -07002286void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002287 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002288 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002289 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002290}
dsinclair5b36f0a2016-07-19 10:56:23 -07002291
dsinclair12a6b0c2016-05-26 11:14:08 -07002292void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002293 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002294 XFA_ATTRIBUTE eAttribute) {
2295 CXFA_WidgetData* pWidgetData = GetWidgetData();
2296 if (!pWidgetData) {
2297 return;
2298 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002299 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002300 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002301 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002302 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002303 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
Tom Sepezf0b65542017-02-13 10:26:01 -08002304 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002305 }
2306}
dsinclair5b36f0a2016-07-19 10:56:23 -07002307
dsinclair12a6b0c2016-05-26 11:14:08 -07002308void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002309 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002310 XFA_ATTRIBUTE eAttribute) {
2311 CXFA_WidgetData* pWidgetData = GetWidgetData();
2312 if (!pWidgetData) {
2313 return;
2314 }
tsepezd19e9122016-11-02 15:43:18 -07002315 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002316 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002317 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002318 } else {
2319 int32_t iValue = validate.GetNullTest();
2320 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002321 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002322 CFX_WideString wsValue;
2323 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002324 wsValue = pInfo->pName;
Tom Sepezf0b65542017-02-13 10:26:01 -08002325 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002326 }
2327}
dsinclair5b36f0a2016-07-19 10:56:23 -07002328
dsinclair12a6b0c2016-05-26 11:14:08 -07002329void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002330 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002331 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002332 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002333}
dsinclair5b36f0a2016-07-19 10:56:23 -07002334
dsinclair12a6b0c2016-05-26 11:14:08 -07002335void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002336 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002337 XFA_ATTRIBUTE eAttribute) {
2338 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002339 ThrowInvalidPropertyException();
2340 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002341 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002342 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002343}
dsinclair5b36f0a2016-07-19 10:56:23 -07002344
dsinclair12a6b0c2016-05-26 11:14:08 -07002345void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002346 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002347 XFA_ATTRIBUTE eAttribute) {
2348 CXFA_WidgetData* pWidgetData = GetWidgetData();
2349 if (!pWidgetData) {
2350 return;
2351 }
2352 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002353 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002354 if (iIndex == -1) {
2355 pWidgetData->ClearAllSelections();
2356 return;
2357 }
tsepezd19e9122016-11-02 15:43:18 -07002358 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002359 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002360 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002361 }
2362}
dsinclair5b36f0a2016-07-19 10:56:23 -07002363
Dan Sinclair1770c022016-03-14 14:14:16 -04002364void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2365 CXFA_WidgetData* pWidgetData = GetWidgetData();
2366 if (!pWidgetData) {
2367 return;
2368 }
tsepezd19e9122016-11-02 15:43:18 -07002369 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002370}
dsinclair5b36f0a2016-07-19 10:56:23 -07002371
Dan Sinclair1770c022016-03-14 14:14:16 -04002372void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002373 if (pArguments->GetLength() != 1) {
2374 ThrowParamCountMismatchException(L"execEvent");
2375 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002376 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002377
2378 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2379 int32_t iRet = execSingleEventByName(
2380 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2381 XFA_Element::Field);
2382 if (eventString != "validate")
2383 return;
2384
2385 pArguments->GetReturnValue()->SetBoolean(
2386 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002387}
dsinclair5b36f0a2016-07-19 10:56:23 -07002388
Dan Sinclair1770c022016-03-14 14:14:16 -04002389void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002390 if (pArguments->GetLength() != 0) {
2391 ThrowParamCountMismatchException(L"execInitialize");
2392 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002393 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002394
2395 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2396 if (!pNotify)
2397 return;
2398
2399 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002400}
dsinclair5b36f0a2016-07-19 10:56:23 -07002401
Dan Sinclair1770c022016-03-14 14:14:16 -04002402void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2403 int32_t iLength = pArguments->GetLength();
2404 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002405 ThrowParamCountMismatchException(L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002406 return;
2407 }
2408 CXFA_WidgetData* pWidgetData = GetWidgetData();
2409 if (!pWidgetData) {
2410 return;
2411 }
2412 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002413 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002414 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002415 if (pValue)
2416 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002417}
dsinclair5b36f0a2016-07-19 10:56:23 -07002418
Dan Sinclair1770c022016-03-14 14:14:16 -04002419void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2420 int32_t iLength = pArguments->GetLength();
2421 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002422 ThrowParamCountMismatchException(L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002423 return;
2424 }
2425 int32_t iIndex = pArguments->GetInt32(0);
2426 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002427 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002428 return;
2429 }
2430 CXFA_WidgetData* pWidgetData = GetWidgetData();
2431 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002432 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002433 return;
2434 }
2435 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002436 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002437 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002438 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002439 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002440 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002441}
dsinclair5b36f0a2016-07-19 10:56:23 -07002442
Dan Sinclair1770c022016-03-14 14:14:16 -04002443void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2444 int32_t iLength = pArguments->GetLength();
2445 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002446 ThrowParamCountMismatchException(L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002447 return;
2448 }
2449 CXFA_WidgetData* pWidgetData = GetWidgetData();
2450 if (!pWidgetData) {
2451 return;
2452 }
2453 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002454 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002455 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002456 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002457 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002458 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08002459 pValue->SetString(wsBoundValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002460}
dsinclair5b36f0a2016-07-19 10:56:23 -07002461
Dan Sinclair1770c022016-03-14 14:14:16 -04002462void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2463 int32_t iLength = pArguments->GetLength();
2464 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002465 ThrowParamCountMismatchException(L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002466 return;
2467 }
2468 CXFA_WidgetData* pWidgetData = GetWidgetData();
2469 if (!pWidgetData) {
2470 return;
2471 }
2472 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002473 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002474 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002475 if (pValue)
2476 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002477}
dsinclair5b36f0a2016-07-19 10:56:23 -07002478
Dan Sinclair1770c022016-03-14 14:14:16 -04002479void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002480 if (pArguments->GetLength() != 0) {
2481 ThrowParamCountMismatchException(L"execCalculate");
2482 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002483 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002484
2485 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2486 if (!pNotify)
2487 return;
2488
2489 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002490}
dsinclair5b36f0a2016-07-19 10:56:23 -07002491
Dan Sinclair1770c022016-03-14 14:14:16 -04002492void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002493
Dan Sinclair1770c022016-03-14 14:14:16 -04002494void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2495 int32_t iLength = pArguments->GetLength();
2496 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002497 ThrowParamCountMismatchException(L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002498 return;
2499 }
2500 int32_t iIndex = pArguments->GetInt32(0);
2501 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002502 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002503 return;
2504 }
2505 CXFA_WidgetData* pWidgetData = GetWidgetData();
2506 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002507 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002508 return;
2509 }
2510 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002511 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002512 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002513 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002514 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002515 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002516}
dsinclair5b36f0a2016-07-19 10:56:23 -07002517
Dan Sinclair1770c022016-03-14 14:14:16 -04002518void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2519 int32_t iLength = pArguments->GetLength();
2520 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002521 ThrowParamCountMismatchException(L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002522 return;
2523 }
2524 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002525 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002526 return;
thestig800222e2016-05-26 22:00:29 -07002527
Dan Sinclair1770c022016-03-14 14:14:16 -04002528 int32_t iIndex = pArguments->GetInt32(0);
2529 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002530 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002531 } else {
thestig800222e2016-05-26 22:00:29 -07002532 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002533 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002534 }
2535}
dsinclair5b36f0a2016-07-19 10:56:23 -07002536
Dan Sinclair1770c022016-03-14 14:14:16 -04002537void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2538 int32_t iLength = pArguments->GetLength();
2539 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002540 ThrowParamCountMismatchException(L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002541 return;
2542 }
2543 CXFA_WidgetData* pWidgetData = GetWidgetData();
2544 if (!pWidgetData) {
2545 return;
2546 }
2547 CFX_WideString wsLabel;
2548 CFX_WideString wsValue;
2549 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002550 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002551 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002552 }
2553 if (iLength >= 2) {
2554 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002555 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002556 }
tsepezd19e9122016-11-02 15:43:18 -07002557 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002558}
dsinclair5b36f0a2016-07-19 10:56:23 -07002559
Dan Sinclair1770c022016-03-14 14:14:16 -04002560void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002561 if (pArguments->GetLength() != 0) {
2562 ThrowParamCountMismatchException(L"execValidate");
2563 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002564 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002565
2566 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2567 if (!pNotify) {
2568 pArguments->GetReturnValue()->SetBoolean(false);
2569 return;
2570 }
2571
2572 int32_t iRet =
2573 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
2574 pArguments->GetReturnValue()->SetBoolean(
2575 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002576}
dsinclair5b36f0a2016-07-19 10:56:23 -07002577
dsinclair12a6b0c2016-05-26 11:14:08 -07002578void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002579 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002580 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002581 if (bSetting)
2582 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002583}
dsinclair5b36f0a2016-07-19 10:56:23 -07002584
dsinclair12a6b0c2016-05-26 11:14:08 -07002585void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002586 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002587 XFA_ATTRIBUTE eAttribute) {
2588 CXFA_WidgetData* pWidgetData = GetWidgetData();
2589 if (!pWidgetData) {
2590 return;
2591 }
2592 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002593 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002594 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002595 } else {
tsepezd19e9122016-11-02 15:43:18 -07002596 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002597 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2598 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002599 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002600 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002601 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002602 }
2603 }
2604}
dsinclair5b36f0a2016-07-19 10:56:23 -07002605
dsinclair12a6b0c2016-05-26 11:14:08 -07002606void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002607 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002608 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002609
Dan Sinclair1770c022016-03-14 14:14:16 -04002610void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002611 if (pArguments->GetLength() != 1) {
2612 ThrowParamCountMismatchException(L"execEvent");
2613 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002614 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002615
2616 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2617 execSingleEventByName(
2618 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2619 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002620}
thestig800222e2016-05-26 22:00:29 -07002621
Dan Sinclair1770c022016-03-14 14:14:16 -04002622void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2623 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002624 if (argc < 0 || argc > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002625 ThrowParamCountMismatchException(L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002626 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002627 }
thestig800222e2016-05-26 22:00:29 -07002628
2629 CXFA_WidgetData* pWidgetData = GetWidgetData();
2630 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002631 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002632 return;
2633 }
2634
2635 CXFA_Node* pReturnNode = nullptr;
2636 if (argc == 0) {
2637 pReturnNode = pWidgetData->GetSelectedMember();
2638 } else {
2639 CFX_ByteString szName;
2640 szName = pArguments->GetUTF8String(0);
2641 pReturnNode = pWidgetData->SetSelectedMember(
2642 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2643 }
2644 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002645 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002646 return;
2647 }
dsinclairf27aeec2016-06-07 19:36:18 -07002648 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002649 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002650}
thestig800222e2016-05-26 22:00:29 -07002651
Dan Sinclair1770c022016-03-14 14:14:16 -04002652void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002653 if (pArguments->GetLength() != 0) {
2654 ThrowParamCountMismatchException(L"execInitialize");
2655 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002656 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002657
2658 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2659 if (!pNotify)
2660 return;
2661
2662 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002663}
dsinclair5b36f0a2016-07-19 10:56:23 -07002664
Dan Sinclair1770c022016-03-14 14:14:16 -04002665void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002666 if (pArguments->GetLength() != 0) {
2667 ThrowParamCountMismatchException(L"execCalculate");
2668 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002669 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002670
2671 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2672 if (!pNotify)
2673 return;
2674
2675 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002676}
dsinclair5b36f0a2016-07-19 10:56:23 -07002677
Dan Sinclair1770c022016-03-14 14:14:16 -04002678void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002679 if (pArguments->GetLength() != 0) {
2680 ThrowParamCountMismatchException(L"execValidate");
2681 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002682 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002683
2684 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2685 if (!pNotify) {
2686 pArguments->GetReturnValue()->SetBoolean(false);
2687 return;
2688 }
2689
2690 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2691 pArguments->GetReturnValue()->SetBoolean(
2692 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002693}
dsinclair5b36f0a2016-07-19 10:56:23 -07002694
dsinclair12a6b0c2016-05-26 11:14:08 -07002695void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002696 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002697 XFA_ATTRIBUTE eAttribute) {
2698 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002699 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002700 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002701 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002702 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2703 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002704 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002705 pManagerNode = pNode;
2706 break;
2707 }
2708 }
2709 if (pManagerNode) {
2710 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
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 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002715 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002716 if (pToInstance &&
2717 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002718 pNotify->RunSubformIndexChange(pToInstance);
2719 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002720 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002721 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002722 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002723 pNotify->RunSubformIndexChange(pFromInstance);
2724 }
2725 }
2726 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002727 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002728 }
2729}
dsinclair5b36f0a2016-07-19 10:56:23 -07002730
dsinclair12a6b0c2016-05-26 11:14:08 -07002731void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002732 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002733 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002734 if (bSetting) {
2735 ThrowInvalidPropertyException();
2736 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002737 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002738
2739 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2740 CXFA_Node* pInstanceMgr = nullptr;
2741 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2742 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2743 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2744 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2745 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2746 wsInstMgrName.Mid(1) == wsName) {
2747 pInstanceMgr = pNode;
2748 }
2749 break;
2750 }
2751 }
2752 if (!pInstanceMgr) {
2753 pValue->SetNull();
2754 return;
2755 }
2756
2757 pValue->Assign(
2758 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
Dan Sinclair1770c022016-03-14 14:14:16 -04002759}
dsinclair5b36f0a2016-07-19 10:56:23 -07002760
dsinclair12a6b0c2016-05-26 11:14:08 -07002761void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002762 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002763 XFA_ATTRIBUTE eAttribute) {
2764 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002765 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002766 } else {
2767 CFX_WideString wsLocaleName;
2768 GetLocaleName(wsLocaleName);
Tom Sepezf0b65542017-02-13 10:26:01 -08002769 pValue->SetString(wsLocaleName.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002770 }
2771}
dsinclair5b36f0a2016-07-19 10:56:23 -07002772
Dan Sinclair1770c022016-03-14 14:14:16 -04002773void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002774 if (pArguments->GetLength() != 1) {
2775 ThrowParamCountMismatchException(L"execEvent");
2776 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002777 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002778
2779 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2780 execSingleEventByName(
2781 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2782 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002783}
dsinclair5b36f0a2016-07-19 10:56:23 -07002784
Dan Sinclair1770c022016-03-14 14:14:16 -04002785void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002786 if (pArguments->GetLength() != 0) {
2787 ThrowParamCountMismatchException(L"execInitialize");
2788 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002789 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002790
2791 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2792 if (!pNotify)
2793 return;
2794
2795 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002796}
dsinclair5b36f0a2016-07-19 10:56:23 -07002797
Dan Sinclair1770c022016-03-14 14:14:16 -04002798void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002799 if (pArguments->GetLength() != 0) {
2800 ThrowParamCountMismatchException(L"execCalculate");
2801 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002802 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002803
2804 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2805 if (!pNotify)
2806 return;
2807
2808 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002809}
dsinclair5b36f0a2016-07-19 10:56:23 -07002810
Dan Sinclair1770c022016-03-14 14:14:16 -04002811void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002812 if (pArguments->GetLength() != 0) {
2813 ThrowParamCountMismatchException(L"execValidate");
2814 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002815 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002816
2817 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2818 if (!pNotify) {
2819 pArguments->GetReturnValue()->SetBoolean(false);
2820 return;
2821 }
2822
2823 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2824 pArguments->GetReturnValue()->SetBoolean(
2825 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002826}
dsinclair5b36f0a2016-07-19 10:56:23 -07002827
Dan Sinclair1770c022016-03-14 14:14:16 -04002828void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002829 if (pArguments->GetLength() != 0)
2830 ThrowParamCountMismatchException(L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002831}
dsinclair5b36f0a2016-07-19 10:56:23 -07002832
Dan Sinclair1770c022016-03-14 14:14:16 -04002833int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2834 int32_t index = 0;
2835 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2836 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002837 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2838 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002839 index++;
2840 } else {
2841 break;
2842 }
2843 }
2844 return index;
2845}
dsinclair5b36f0a2016-07-19 10:56:23 -07002846
Dan Sinclair1770c022016-03-14 14:14:16 -04002847void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002848 if (pArguments->GetLength() != 1) {
2849 ThrowParamCountMismatchException(L"formNodes");
2850 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002851 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002852 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002853}
dsinclair5b36f0a2016-07-19 10:56:23 -07002854
Dan Sinclair1770c022016-03-14 14:14:16 -04002855void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002856 if (pArguments->GetLength() != 0) {
2857 ThrowParamCountMismatchException(L"remerge");
2858 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002859 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002860 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002861}
dsinclair5b36f0a2016-07-19 10:56:23 -07002862
Dan Sinclair1770c022016-03-14 14:14:16 -04002863void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002864 if (pArguments->GetLength() != 0) {
2865 ThrowParamCountMismatchException(L"execInitialize");
2866 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002867 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002868
2869 CXFA_WidgetData* pWidgetData = GetWidgetData();
2870 if (!pWidgetData) {
2871 pArguments->GetReturnValue()->SetBoolean(false);
2872 return;
2873 }
2874 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002875}
dsinclair5b36f0a2016-07-19 10:56:23 -07002876
Dan Sinclair1770c022016-03-14 14:14:16 -04002877void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2878 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002879 if (argc <= 0 || argc >= 4) {
2880 ThrowParamCountMismatchException(L"createNode");
2881 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002882 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002883
2884 CFX_WideString strName;
2885 CFX_WideString strNameSpace;
2886 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
2887 CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
2888 if (argc > 1) {
2889 CFX_ByteString bsName = pArguments->GetUTF8String(1);
2890 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
2891 if (argc == 3) {
2892 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
2893 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
2894 }
2895 }
2896
2897 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2898 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
2899 if (!pNewNode) {
2900 pArguments->GetReturnValue()->SetNull();
2901 return;
2902 }
2903
2904 if (strName.IsEmpty()) {
2905 pArguments->GetReturnValue()->Assign(
2906 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2907 return;
2908 }
2909
2910 if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2911 XFA_XDPPACKET_UNKNOWN)) {
2912 ThrowMissingPropertyException(strTagName, L"name");
2913 return;
2914 }
2915
2916 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
2917 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets)
2918 pNewNode->CreateXMLMappingNode();
2919
2920 pArguments->GetReturnValue()->Assign(
2921 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002922}
dsinclair5b36f0a2016-07-19 10:56:23 -07002923
Dan Sinclair1770c022016-03-14 14:14:16 -04002924void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002925 if (pArguments->GetLength() != 1) {
2926 ThrowParamCountMismatchException(L"recalculate");
2927 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002928 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002929 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002930}
dsinclair5b36f0a2016-07-19 10:56:23 -07002931
Dan Sinclair1770c022016-03-14 14:14:16 -04002932void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002933 if (pArguments->GetLength() != 0) {
2934 ThrowParamCountMismatchException(L"execCalculate");
2935 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002936 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002937
2938 CXFA_WidgetData* pWidgetData = GetWidgetData();
2939 if (!pWidgetData) {
2940 pArguments->GetReturnValue()->SetBoolean(false);
2941 return;
2942 }
2943 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002944}
dsinclair5b36f0a2016-07-19 10:56:23 -07002945
Dan Sinclair1770c022016-03-14 14:14:16 -04002946void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002947 if (pArguments->GetLength() != 0) {
2948 ThrowParamCountMismatchException(L"execValidate");
2949 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002950 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002951 CXFA_WidgetData* pWidgetData = GetWidgetData();
2952 if (!pWidgetData) {
2953 pArguments->GetReturnValue()->SetBoolean(false);
2954 return;
2955 }
2956 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002957}
dsinclair5b36f0a2016-07-19 10:56:23 -07002958
Dan Sinclair1770c022016-03-14 14:14:16 -04002959void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002960 if (pArguments->GetLength() != 0) {
2961 ThrowParamCountMismatchException(L"evaluate");
2962 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002963 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002964
2965 CXFA_WidgetData* pWidgetData = GetWidgetData();
2966 if (!pWidgetData) {
2967 pArguments->GetReturnValue()->SetBoolean(false);
2968 return;
2969 }
2970 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002971}
dsinclair5b36f0a2016-07-19 10:56:23 -07002972
dsinclair12a6b0c2016-05-26 11:14:08 -07002973void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002974 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002975 XFA_ATTRIBUTE eAttribute) {
2976 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002977 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002978 return;
2979 }
2980 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002981 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04002982}
dsinclair5b36f0a2016-07-19 10:56:23 -07002983
dsinclair12a6b0c2016-05-26 11:14:08 -07002984void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002985 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002986 XFA_ATTRIBUTE eAttribute) {
2987 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002988 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002989 return;
2990 }
2991 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002992 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04002993}
tsepezaadedf92016-05-12 10:08:06 -07002994
dsinclair12a6b0c2016-05-26 11:14:08 -07002995void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002996 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002997 XFA_ATTRIBUTE eAttribute) {
2998 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002999 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003000 InstanceManager_SetInstances(iDesired);
3001 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07003002 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04003003 }
3004}
dsinclair5b36f0a2016-07-19 10:56:23 -07003005
Dan Sinclair1770c022016-03-14 14:14:16 -04003006void CXFA_Node::Script_InstanceManager_MoveInstance(
3007 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003008 if (pArguments->GetLength() != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003009 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003010 return;
3011 }
3012 int32_t iFrom = pArguments->GetInt32(0);
3013 int32_t iTo = pArguments->GetInt32(1);
3014 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003015 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003016 if (!pNotify) {
3017 return;
3018 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003019 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003020 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003021 pNotify->RunSubformIndexChange(pToInstance);
3022 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003023 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003024 if (pFromInstance &&
3025 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003026 pNotify->RunSubformIndexChange(pFromInstance);
3027 }
3028}
dsinclair5b36f0a2016-07-19 10:56:23 -07003029
Dan Sinclair1770c022016-03-14 14:14:16 -04003030void CXFA_Node::Script_InstanceManager_RemoveInstance(
3031 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003032 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003033 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003034 return;
3035 }
3036 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003037 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003038 if (iIndex < 0 || iIndex >= iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003039 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003040 return;
3041 }
3042 CXFA_Occur nodeOccur(GetOccurNode());
3043 int32_t iMin = nodeOccur.GetMin();
3044 if (iCount - 1 < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003045 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003046 return;
3047 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003048 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3049 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003050 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003051 if (pNotify) {
3052 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003053 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003054 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003055 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003056 pNotify->RunSubformIndexChange(pSubformInstance);
3057 }
3058 }
3059 }
3060 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3061 if (!pLayoutPro) {
3062 return;
3063 }
3064 pLayoutPro->AddChangedContainer(
3065 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3066}
dsinclair5b36f0a2016-07-19 10:56:23 -07003067
Dan Sinclair1770c022016-03-14 14:14:16 -04003068void CXFA_Node::Script_InstanceManager_SetInstances(
3069 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003070 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003071 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003072 return;
3073 }
3074 int32_t iDesired = pArguments->GetInt32(0);
3075 InstanceManager_SetInstances(iDesired);
3076}
dsinclair5b36f0a2016-07-19 10:56:23 -07003077
Dan Sinclair1770c022016-03-14 14:14:16 -04003078void CXFA_Node::Script_InstanceManager_AddInstance(
3079 CFXJSE_Arguments* pArguments) {
3080 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003081 if (argc != 0 && argc != 1) {
3082 ThrowParamCountMismatchException(L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003083 return;
3084 }
tsepezd19e9122016-11-02 15:43:18 -07003085 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003086 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003087 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003088 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003089 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003090 CXFA_Occur nodeOccur(GetOccurNode());
3091 int32_t iMax = nodeOccur.GetMax();
3092 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003093 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003094 return;
3095 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003096 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003097 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003098 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003099 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003100 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003101 if (!pNotify) {
3102 return;
3103 }
3104 pNotify->RunNodeInitialize(pNewInstance);
3105 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3106 if (!pLayoutPro) {
3107 return;
3108 }
3109 pLayoutPro->AddChangedContainer(
3110 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3111}
dsinclair5b36f0a2016-07-19 10:56:23 -07003112
Dan Sinclair1770c022016-03-14 14:14:16 -04003113void CXFA_Node::Script_InstanceManager_InsertInstance(
3114 CFXJSE_Arguments* pArguments) {
3115 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003116 if (argc != 1 && argc != 2) {
3117 ThrowParamCountMismatchException(L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003118 return;
3119 }
3120 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003121 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003122 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003123 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003124 }
3125 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003126 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003127 if (iIndex < 0 || iIndex > iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003128 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003129 return;
3130 }
3131 int32_t iMax = nodeOccur.GetMax();
3132 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003133 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003134 return;
3135 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003136 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003137 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003138 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003139 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003140 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003141 if (!pNotify) {
3142 return;
3143 }
3144 pNotify->RunNodeInitialize(pNewInstance);
3145 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3146 if (!pLayoutPro) {
3147 return;
3148 }
3149 pLayoutPro->AddChangedContainer(
3150 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3151}
dsinclair5b36f0a2016-07-19 10:56:23 -07003152
Dan Sinclair1770c022016-03-14 14:14:16 -04003153int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3154 CXFA_Occur nodeOccur(GetOccurNode());
3155 int32_t iMax = nodeOccur.GetMax();
3156 int32_t iMin = nodeOccur.GetMin();
3157 if (iDesired < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003158 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003159 return 1;
3160 }
3161 if ((iMax >= 0) && (iDesired > iMax)) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003162 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003163 return 2;
3164 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003165 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003166 if (iDesired == iCount) {
3167 return 0;
3168 }
3169 if (iDesired < iCount) {
3170 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003171 CFX_WideString wsInstanceName =
3172 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3173 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003174 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003175 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003176 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003177 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003178 while (iCount > iDesired) {
3179 CXFA_Node* pRemoveInstance =
3180 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003181 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3182 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003183 continue;
3184 }
dsinclair070fcdf2016-06-22 22:04:54 -07003185 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003186 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003187 break;
3188 }
3189 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003190 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003191 iCount--;
3192 }
3193 }
3194 } else if (iDesired > iCount) {
3195 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003196 CXFA_Node* pNewInstance = CreateInstance(this, true);
3197 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003198 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003199 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003200 if (!pNotify) {
3201 return 0;
3202 }
3203 pNotify->RunNodeInitialize(pNewInstance);
3204 }
3205 }
3206 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3207 if (pLayoutPro) {
3208 pLayoutPro->AddChangedContainer(
3209 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3210 }
3211 return 0;
3212}
dsinclair5b36f0a2016-07-19 10:56:23 -07003213
Dan Sinclair1770c022016-03-14 14:14:16 -04003214int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003215 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003216 if (iFrom > iCount || iTo > iCount - 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003217 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003218 return 1;
3219 }
3220 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3221 return 0;
3222 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003223 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003224 RemoveItem(this, pMoveInstance, false);
3225 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003226 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3227 if (pLayoutPro) {
3228 pLayoutPro->AddChangedContainer(
3229 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3230 }
3231 return 0;
3232}
dsinclair5b36f0a2016-07-19 10:56:23 -07003233
dsinclair12a6b0c2016-05-26 11:14:08 -07003234void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003235 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003236 XFA_ATTRIBUTE eAttribute) {
3237 CXFA_Occur occur(this);
3238 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003239 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003240 occur.SetMax(iMax);
3241 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003242 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003243 }
3244}
dsinclair5b36f0a2016-07-19 10:56:23 -07003245
dsinclair12a6b0c2016-05-26 11:14:08 -07003246void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003247 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003248 XFA_ATTRIBUTE eAttribute) {
3249 CXFA_Occur occur(this);
3250 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003251 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003252 occur.SetMin(iMin);
3253 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003254 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003255 }
3256}
dsinclair5b36f0a2016-07-19 10:56:23 -07003257
Dan Sinclair1770c022016-03-14 14:14:16 -04003258void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3259 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003260 if (argc != 0 && argc != 1) {
3261 ThrowParamCountMismatchException(L"metadata");
3262 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003263 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003264 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003265}
dsinclair5b36f0a2016-07-19 10:56:23 -07003266
Dan Sinclair1770c022016-03-14 14:14:16 -04003267void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003268 if (pArguments->GetLength() != 1) {
3269 ThrowParamCountMismatchException(L"formNodes");
3270 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003271 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003272
3273 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3274 if (!pDataNode) {
3275 ThrowArgumentMismatchException();
3276 return;
3277 }
3278
Tom Sepezf8a94392017-03-14 12:13:22 -07003279 std::vector<CXFA_Node*> formItems;
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003280 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3281 pFormNodes->SetArrayNodeList(formItems);
3282 pArguments->GetReturnValue()->SetObject(
3283 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003284}
dsinclair5b36f0a2016-07-19 10:56:23 -07003285
Dan Sinclair1770c022016-03-14 14:14:16 -04003286void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003287 if (pArguments->GetLength() != 0) {
3288 ThrowParamCountMismatchException(L"remerge");
3289 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003290 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003291
3292 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003293}
dsinclair5b36f0a2016-07-19 10:56:23 -07003294
Dan Sinclair1770c022016-03-14 14:14:16 -04003295void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003296 if (pArguments->GetLength() != 0) {
3297 ThrowParamCountMismatchException(L"execInitialize");
3298 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003299 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003300
3301 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3302 if (!pNotify)
3303 return;
3304
3305 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04003306}
dsinclair5b36f0a2016-07-19 10:56:23 -07003307
Dan Sinclair1770c022016-03-14 14:14:16 -04003308void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3309 CXFA_EventParam* pEventParam =
3310 m_pDocument->GetScriptContext()->GetEventParam();
3311 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3312 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3313 return;
3314 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003315 if (pArguments->GetLength() != 1) {
3316 ThrowParamCountMismatchException(L"recalculate");
3317 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003318 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003319
3320 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3321 if (!pNotify)
3322 return;
3323 if (pArguments->GetInt32(0) != 0)
3324 return;
3325
3326 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3327 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3328 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003329}
dsinclair5b36f0a2016-07-19 10:56:23 -07003330
Dan Sinclair1770c022016-03-14 14:14:16 -04003331void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003332 if (pArguments->GetLength() != 0) {
3333 ThrowParamCountMismatchException(L"execCalculate");
3334 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003335 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003336
3337 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3338 if (!pNotify)
3339 return;
3340
3341 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04003342}
dsinclair5b36f0a2016-07-19 10:56:23 -07003343
Dan Sinclair1770c022016-03-14 14:14:16 -04003344void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003345 if (pArguments->GetLength() != 0) {
3346 ThrowParamCountMismatchException(L"execValidate");
3347 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003348 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003349
3350 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3351 if (!pNotify) {
3352 pArguments->GetReturnValue()->SetBoolean(false);
3353 return;
3354 }
3355
3356 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3357 pArguments->GetReturnValue()->SetBoolean(
3358 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003359}
dsinclair5b36f0a2016-07-19 10:56:23 -07003360
dsinclair12a6b0c2016-05-26 11:14:08 -07003361void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003362 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003363 XFA_ATTRIBUTE eAttribute) {
3364 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003365 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003366 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003367 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003368 CFX_WideString wsChecksum;
3369 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
Tom Sepezf0b65542017-02-13 10:26:01 -08003370 pValue->SetString(wsChecksum.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003371}
dsinclair5b36f0a2016-07-19 10:56:23 -07003372
Dan Sinclair1770c022016-03-14 14:14:16 -04003373void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003374 if (pArguments->GetLength() != 1) {
3375 ThrowParamCountMismatchException(L"getAttribute");
3376 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003377 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003378 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3379 CFX_WideString wsAttributeValue;
3380 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3381 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3382 static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3383 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(),
3384 wsAttributeValue);
3385 }
3386 pArguments->GetReturnValue()->SetString(
Tom Sepezf0b65542017-02-13 10:26:01 -08003387 wsAttributeValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003388}
dsinclair5b36f0a2016-07-19 10:56:23 -07003389
Dan Sinclair1770c022016-03-14 14:14:16 -04003390void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003391 if (pArguments->GetLength() != 2) {
3392 ThrowParamCountMismatchException(L"setAttribute");
3393 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003394 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003395 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3396 CFX_ByteString bsName = pArguments->GetUTF8String(1);
3397 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3398 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3399 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(
3400 CFX_WideString::FromUTF8(bsName.AsStringC()),
3401 CFX_WideString::FromUTF8(bsValue.AsStringC()));
3402 }
3403 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003404}
dsinclair5b36f0a2016-07-19 10:56:23 -07003405
Dan Sinclair1770c022016-03-14 14:14:16 -04003406void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003407 if (pArguments->GetLength() != 1) {
3408 ThrowParamCountMismatchException(L"removeAttribute");
3409 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003410 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003411
3412 CFX_ByteString bsName = pArguments->GetUTF8String(0);
3413 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
3414 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3415 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3416 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
3417 if (pXMLElement->HasAttribute(wsName.c_str())) {
3418 pXMLElement->RemoveAttribute(wsName.c_str());
3419 }
3420 }
3421 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003422}
dsinclair5b36f0a2016-07-19 10:56:23 -07003423
dsinclair12a6b0c2016-05-26 11:14:08 -07003424void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003425 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003426 XFA_ATTRIBUTE eAttribute) {
3427 if (bSetting) {
dsinclairae95f762016-03-29 16:58:29 -07003428 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003429 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003430 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003431 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003432 }
3433 } else {
3434 CFX_WideString wsTextData;
dsinclairae95f762016-03-29 16:58:29 -07003435 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003436 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003437 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04003438 pXMLElement->GetTextData(wsTextData);
3439 }
Tom Sepezf0b65542017-02-13 10:26:01 -08003440 pValue->SetString(wsTextData.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003441 }
3442}
dsinclair5b36f0a2016-07-19 10:56:23 -07003443
Dan Sinclair1770c022016-03-14 14:14:16 -04003444void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003445 if (pArguments->GetLength() != 0)
3446 ThrowParamCountMismatchException(L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003447}
dsinclair5b36f0a2016-07-19 10:56:23 -07003448
Dan Sinclair1770c022016-03-14 14:14:16 -04003449void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003450 if (pArguments->GetLength() != 0)
3451 ThrowParamCountMismatchException(L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003452}
dsinclair5b36f0a2016-07-19 10:56:23 -07003453
Dan Sinclair1770c022016-03-14 14:14:16 -04003454void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003455 if (pArguments->GetLength() != 0)
3456 ThrowParamCountMismatchException(L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003457}
dsinclair5b36f0a2016-07-19 10:56:23 -07003458
Dan Sinclair1770c022016-03-14 14:14:16 -04003459void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003460 if (pArguments->GetLength() != 0)
3461 ThrowParamCountMismatchException(L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003462}
dsinclair5b36f0a2016-07-19 10:56:23 -07003463
Dan Sinclair1770c022016-03-14 14:14:16 -04003464void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003465 if (pArguments->GetLength() != 0)
3466 ThrowParamCountMismatchException(L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003467}
dsinclair5b36f0a2016-07-19 10:56:23 -07003468
Dan Sinclair1770c022016-03-14 14:14:16 -04003469void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003470 if (pArguments->GetLength() != 0)
3471 ThrowParamCountMismatchException(L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003472}
dsinclair5b36f0a2016-07-19 10:56:23 -07003473
Dan Sinclair1770c022016-03-14 14:14:16 -04003474void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003475 if (pArguments->GetLength() != 0)
3476 ThrowParamCountMismatchException(L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003477}
dsinclair5b36f0a2016-07-19 10:56:23 -07003478
Dan Sinclair1770c022016-03-14 14:14:16 -04003479void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003480 if (pArguments->GetLength() != 0)
3481 ThrowParamCountMismatchException(L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003482}
dsinclair5b36f0a2016-07-19 10:56:23 -07003483
Dan Sinclair1770c022016-03-14 14:14:16 -04003484void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003485 if (pArguments->GetLength() != 0)
3486 ThrowParamCountMismatchException(L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003487}
dsinclair5b36f0a2016-07-19 10:56:23 -07003488
Dan Sinclair1770c022016-03-14 14:14:16 -04003489void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003490 if (pArguments->GetLength() != 0)
3491 ThrowParamCountMismatchException(L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003492}
dsinclair5b36f0a2016-07-19 10:56:23 -07003493
Dan Sinclair1770c022016-03-14 14:14:16 -04003494void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003495 if (pArguments->GetLength() != 0)
3496 ThrowParamCountMismatchException(L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003497}
dsinclair5b36f0a2016-07-19 10:56:23 -07003498
Dan Sinclair1770c022016-03-14 14:14:16 -04003499void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003500 if (pArguments->GetLength() != 0)
3501 ThrowParamCountMismatchException(L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003502}
dsinclair5b36f0a2016-07-19 10:56:23 -07003503
Dan Sinclair1770c022016-03-14 14:14:16 -04003504void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003505 if (pArguments->GetLength() != 0)
3506 ThrowParamCountMismatchException(L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003507}
dsinclair5b36f0a2016-07-19 10:56:23 -07003508
Dan Sinclair1770c022016-03-14 14:14:16 -04003509void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003510 if (pArguments->GetLength() != 0)
3511 ThrowParamCountMismatchException(L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003512}
dsinclair5b36f0a2016-07-19 10:56:23 -07003513
Dan Sinclair1770c022016-03-14 14:14:16 -04003514void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003515 if (pArguments->GetLength() != 0)
3516 ThrowParamCountMismatchException(L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003517}
dsinclair5b36f0a2016-07-19 10:56:23 -07003518
Dan Sinclair1770c022016-03-14 14:14:16 -04003519void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003520 if (pArguments->GetLength() != 0)
3521 ThrowParamCountMismatchException(L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003522}
dsinclair5b36f0a2016-07-19 10:56:23 -07003523
Dan Sinclair1770c022016-03-14 14:14:16 -04003524void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003525 if (pArguments->GetLength() != 0)
3526 ThrowParamCountMismatchException(L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003527}
dsinclair5b36f0a2016-07-19 10:56:23 -07003528
dsinclair12a6b0c2016-05-26 11:14:08 -07003529void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003530 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003531 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003532
dsinclair12a6b0c2016-05-26 11:14:08 -07003533void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003534 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003535 XFA_ATTRIBUTE eAttribute) {
3536 if (!bSetting) {
3537 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003538 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003539 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003540 }
3541}
dsinclair5b36f0a2016-07-19 10:56:23 -07003542
dsinclair12a6b0c2016-05-26 11:14:08 -07003543void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003544 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003545 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003546
dsinclair12a6b0c2016-05-26 11:14:08 -07003547void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003548 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003549 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003550
dsinclair12a6b0c2016-05-26 11:14:08 -07003551void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003552 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003553 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003554
dsinclair12a6b0c2016-05-26 11:14:08 -07003555void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003556 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003557 XFA_ATTRIBUTE eAttribute) {
3558 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003559 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003560 return;
3561 }
dan sinclair65c7c232017-02-02 14:05:30 -08003562 pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003563}
dsinclair5b36f0a2016-07-19 10:56:23 -07003564
dsinclair12a6b0c2016-05-26 11:14:08 -07003565void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003566 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003567 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003568
tsepezd19e9122016-11-02 15:43:18 -07003569bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003570 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003571 return HasMapModuleKey(pKey, bCanInherit);
3572}
dsinclair5b36f0a2016-07-19 10:56:23 -07003573
tsepezd19e9122016-11-02 15:43:18 -07003574bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3575 const CFX_WideStringC& wsValue,
3576 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003577 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003578 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003579 return false;
weili44f8faf2016-06-01 14:03:56 -07003580
Dan Sinclair1770c022016-03-14 14:14:16 -04003581 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3582 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3583 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003584 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003585 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3586 }
3587 switch (eType) {
3588 case XFA_ATTRIBUTETYPE_Enum: {
3589 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3590 return SetEnum(pAttr->eName,
3591 pEnum ? pEnum->eName
3592 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3593 bNotify);
3594 } break;
3595 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003596 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003597 case XFA_ATTRIBUTETYPE_Boolean:
dan sinclair65c7c232017-02-02 14:05:30 -08003598 return SetBoolean(pAttr->eName, wsValue != L"0", bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003599 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003600 return SetInteger(pAttr->eName,
3601 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3602 wsValue.GetLength(), nullptr)),
3603 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003604 case XFA_ATTRIBUTETYPE_Measure:
3605 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3606 default:
3607 break;
3608 }
tsepezd19e9122016-11-02 15:43:18 -07003609 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003610}
dsinclair5b36f0a2016-07-19 10:56:23 -07003611
tsepezd19e9122016-11-02 15:43:18 -07003612bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3613 CFX_WideString& wsValue,
3614 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003615 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003616 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003617 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003618 }
3619 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3620 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3621 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003622 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003623 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3624 }
3625 switch (eType) {
3626 case XFA_ATTRIBUTETYPE_Enum: {
3627 XFA_ATTRIBUTEENUM eValue;
3628 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003629 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003630 }
dsinclair9eb0db12016-07-21 12:01:39 -07003631 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003632 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003633 } break;
3634 case XFA_ATTRIBUTETYPE_Cdata: {
3635 CFX_WideStringC wsValueC;
3636 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003637 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003638 }
3639 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003640 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003641 } break;
3642 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003643 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003644 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003645 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003646 }
dan sinclair65c7c232017-02-02 14:05:30 -08003647 wsValue = bValue ? L"1" : L"0";
tsepezd19e9122016-11-02 15:43:18 -07003648 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003649 } break;
3650 case XFA_ATTRIBUTETYPE_Integer: {
3651 int32_t iValue;
3652 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003653 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003654 }
3655 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003656 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003657 } break;
3658 case XFA_ATTRIBUTETYPE_Measure: {
3659 CXFA_Measurement mValue;
3660 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003661 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003662 }
3663 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003664 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003665 } break;
3666 default:
3667 break;
3668 }
tsepezd19e9122016-11-02 15:43:18 -07003669 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003670}
dsinclair5b36f0a2016-07-19 10:56:23 -07003671
tsepezd19e9122016-11-02 15:43:18 -07003672bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3673 const CFX_WideStringC& wsValue,
3674 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003675 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3676 if (pAttributeInfo) {
3677 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3678 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003679 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003680 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003681 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003682}
dsinclair5b36f0a2016-07-19 10:56:23 -07003683
tsepezd19e9122016-11-02 15:43:18 -07003684bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3685 CFX_WideString& wsValue,
3686 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003687 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3688 if (pAttributeInfo) {
3689 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3690 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003691 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003692 CFX_WideStringC wsValueC;
3693 if (GetMapModuleString(pKey, wsValueC)) {
3694 wsValue = wsValueC;
3695 }
tsepezd19e9122016-11-02 15:43:18 -07003696 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003697}
dsinclair5b36f0a2016-07-19 10:56:23 -07003698
tsepezd19e9122016-11-02 15:43:18 -07003699bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003700 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003701 RemoveMapModuleKey(pKey);
tsepezd19e9122016-11-02 15:43:18 -07003702 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003703}
dsinclair5b36f0a2016-07-19 10:56:23 -07003704
tsepezd19e9122016-11-02 15:43:18 -07003705bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3706 bool& bValue,
3707 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003708 void* pValue = nullptr;
3709 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003710 return false;
tsepez478ed622016-10-27 14:32:33 -07003711 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003712 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003713}
dsinclair5b36f0a2016-07-19 10:56:23 -07003714
tsepezd19e9122016-11-02 15:43:18 -07003715bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3716 int32_t& iValue,
3717 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003718 void* pValue = nullptr;
3719 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003720 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003721 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003722 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003723}
dsinclair5b36f0a2016-07-19 10:56:23 -07003724
tsepezd19e9122016-11-02 15:43:18 -07003725bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3726 XFA_ATTRIBUTEENUM& eValue,
3727 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003728 void* pValue = nullptr;
3729 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003730 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003731 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003732 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003733}
thestigb1a59592016-04-14 18:29:56 -07003734
tsepezd19e9122016-11-02 15:43:18 -07003735bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3736 CXFA_Measurement mValue,
3737 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003738 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003739 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003740 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003741 OnChanged(eAttr, bNotify, false);
3742 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003743}
thestigb1a59592016-04-14 18:29:56 -07003744
tsepezd19e9122016-11-02 15:43:18 -07003745bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3746 CXFA_Measurement& mValue,
3747 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003748 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003749 void* pValue;
3750 int32_t iBytes;
3751 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003752 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003753 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003754 }
3755 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003756 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003757 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003758 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003759 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003760 }
tsepezd19e9122016-11-02 15:43:18 -07003761 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003762}
3763
3764CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3765 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003766 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003767}
3768
tsepezd19e9122016-11-02 15:43:18 -07003769bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3770 const CFX_WideString& wsValue,
3771 bool bNotify,
3772 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003773 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003774 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003775 if (eAttr == XFA_ATTRIBUTE_Value) {
3776 CFX_WideString* pClone = new CFX_WideString(wsValue);
3777 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3778 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003779 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003780 if (eAttr == XFA_ATTRIBUTE_Name)
3781 UpdateNameHash();
3782 }
thestigb1a59592016-04-14 18:29:56 -07003783 OnChanged(eAttr, bNotify, bScriptModify);
3784
3785 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3786 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003787 return true;
thestigb1a59592016-04-14 18:29:56 -07003788 }
3789
dsinclair070fcdf2016-06-22 22:04:54 -07003790 if (eAttr == XFA_ATTRIBUTE_Name &&
3791 (m_elementType == XFA_Element::DataValue ||
3792 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003793 return true;
thestigb1a59592016-04-14 18:29:56 -07003794 }
3795
3796 if (eAttr == XFA_ATTRIBUTE_Value) {
3797 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3798 switch (eXMLType) {
3799 case FDE_XMLNODE_Element:
3800 if (IsAttributeInXML()) {
3801 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003802 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3803 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003804 } else {
tsepezd19e9122016-11-02 15:43:18 -07003805 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003806 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3807 for (CXFA_Node* pChildDataNode =
3808 GetNodeItem(XFA_NODEITEM_FirstChild);
3809 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3810 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003811 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003812 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003813 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003814 }
3815 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003816 }
thestigb1a59592016-04-14 18:29:56 -07003817 if (bDeleteChildren) {
3818 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3819 }
3820 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3821 }
3822 break;
3823 case FDE_XMLNODE_Text:
3824 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3825 break;
3826 default:
dsinclair43854a52016-04-27 12:26:00 -07003827 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003828 }
tsepezd19e9122016-11-02 15:43:18 -07003829 return true;
thestigb1a59592016-04-14 18:29:56 -07003830 }
3831
3832 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3833 if (pInfo) {
dsinclair43854a52016-04-27 12:26:00 -07003834 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003835 CFX_WideString wsAttrName = pInfo->pName;
3836 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
dan sinclair65c7c232017-02-02 14:05:30 -08003837 wsAttrName = L"xfa:" + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003838 }
thestigb1a59592016-04-14 18:29:56 -07003839 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003840 }
tsepezd19e9122016-11-02 15:43:18 -07003841 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003842}
thestigb1a59592016-04-14 18:29:56 -07003843
tsepezd19e9122016-11-02 15:43:18 -07003844bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3845 const CFX_WideString& wsXMLValue,
3846 bool bNotify,
3847 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003848 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003849 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003850 CFX_WideString* pClone = new CFX_WideString(wsValue);
3851 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003852 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003853 if (IsNeedSavingXMLNode()) {
3854 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3855 switch (eXMLType) {
3856 case FDE_XMLNODE_Element:
3857 if (IsAttributeInXML()) {
dsinclairae95f762016-03-29 16:58:29 -07003858 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003859 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3860 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003861 } else {
tsepezd19e9122016-11-02 15:43:18 -07003862 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003863 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3864 for (CXFA_Node* pChildDataNode =
3865 GetNodeItem(XFA_NODEITEM_FirstChild);
3866 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3867 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003868 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003869 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003870 break;
3871 }
3872 }
3873 }
3874 if (bDeleteChildren) {
dsinclairae95f762016-03-29 16:58:29 -07003875 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003876 }
dsinclairae95f762016-03-29 16:58:29 -07003877 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003878 }
3879 break;
3880 case FDE_XMLNODE_Text:
dsinclairae95f762016-03-29 16:58:29 -07003881 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003882 break;
3883 default:
dsinclair43854a52016-04-27 12:26:00 -07003884 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003885 }
3886 }
tsepezd19e9122016-11-02 15:43:18 -07003887 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003888}
dsinclair5b36f0a2016-07-19 10:56:23 -07003889
tsepezd19e9122016-11-02 15:43:18 -07003890bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3891 CFX_WideString& wsValue,
3892 bool bUseDefault,
3893 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003894 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003895 if (eAttr == XFA_ATTRIBUTE_Value) {
3896 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3897 if (pStr) {
3898 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07003899 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003900 }
3901 } else {
3902 CFX_WideStringC wsValueC;
3903 if (GetMapModuleString(pKey, wsValueC)) {
3904 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003905 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003906 }
3907 }
3908 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003909 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003910 }
weili44f8faf2016-06-01 14:03:56 -07003911 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003912 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003913 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003914 wsValue = (const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003915 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003916 }
tsepezd19e9122016-11-02 15:43:18 -07003917 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003918}
dsinclair5b36f0a2016-07-19 10:56:23 -07003919
tsepezd19e9122016-11-02 15:43:18 -07003920bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3921 CFX_WideStringC& wsValue,
3922 bool bUseDefault,
3923 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003924 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003925 if (eAttr == XFA_ATTRIBUTE_Value) {
3926 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3927 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07003928 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07003929 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003930 }
3931 } else {
3932 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003933 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003934 }
3935 }
3936 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003937 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003938 }
weili44f8faf2016-06-01 14:03:56 -07003939 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003940 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003941 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003942 wsValue = (CFX_WideStringC)(const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003943 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003944 }
tsepezd19e9122016-11-02 15:43:18 -07003945 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003946}
dsinclair5b36f0a2016-07-19 10:56:23 -07003947
tsepezd19e9122016-11-02 15:43:18 -07003948bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
3949 void* pData,
3950 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003951 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003952 return SetUserData(pKey, pData, pCallbackInfo);
3953}
dsinclair5b36f0a2016-07-19 10:56:23 -07003954
tsepezd19e9122016-11-02 15:43:18 -07003955bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003956 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003957 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07003958 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04003959}
dsinclair5b36f0a2016-07-19 10:56:23 -07003960
tsepezd19e9122016-11-02 15:43:18 -07003961bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
3962 XFA_ATTRIBUTETYPE eType,
3963 void* pValue,
3964 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003965 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003966 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003967 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07003968 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003969 if (IsNeedSavingXMLNode()) {
dsinclair43854a52016-04-27 12:26:00 -07003970 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04003971 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3972 if (pInfo) {
3973 switch (eType) {
3974 case XFA_ATTRIBUTETYPE_Enum:
dsinclairae95f762016-03-29 16:58:29 -07003975 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04003976 ->SetString(
3977 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07003978 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04003979 ->pName);
3980 break;
3981 case XFA_ATTRIBUTETYPE_Boolean:
dsinclairae95f762016-03-29 16:58:29 -07003982 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003983 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04003984 break;
3985 case XFA_ATTRIBUTETYPE_Integer:
dsinclairae95f762016-03-29 16:58:29 -07003986 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04003987 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue);
3988 break;
3989 default:
dsinclair43854a52016-04-27 12:26:00 -07003990 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003991 }
3992 }
3993 }
tsepezd19e9122016-11-02 15:43:18 -07003994 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003995}
dsinclair5b36f0a2016-07-19 10:56:23 -07003996
tsepezd19e9122016-11-02 15:43:18 -07003997bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
3998 XFA_ATTRIBUTETYPE eType,
3999 bool bUseDefault,
4000 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004001 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004002 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004003 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004004 }
4005 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004006 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004007 }
dsinclair070fcdf2016-06-22 22:04:54 -07004008 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004009 m_ePacket);
4010}
dsinclair5b36f0a2016-07-19 10:56:23 -07004011
tsepezd19e9122016-11-02 15:43:18 -07004012bool CXFA_Node::SetUserData(void* pKey,
4013 void* pData,
4014 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004015 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4016 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004017 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004018}
dsinclair5b36f0a2016-07-19 10:56:23 -07004019
tsepezd19e9122016-11-02 15:43:18 -07004020bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004021 int32_t iBytes = 0;
4022 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004023 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004024 }
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004025 return iBytes == sizeof(void*) && memcpy(&pData, pData, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004026}
dsinclair5b36f0a2016-07-19 10:56:23 -07004027
tsepezd19e9122016-11-02 15:43:18 -07004028bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4029 const CFX_WideString& wsXMLValue,
4030 bool bNotify,
4031 bool bScriptModify,
4032 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004033 CXFA_Node* pNode = nullptr;
4034 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004035 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004036 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004037 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004038 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004039 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004040 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004041 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004042 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004043 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004044 CXFA_Node* pBind = GetBindData();
4045 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004046 std::vector<CFX_WideString> wsSaveTextArray;
Tom Sepezf8a94392017-03-14 12:13:22 -07004047 size_t iSize = 0;
Dan Sinclair1770c022016-03-14 14:14:16 -04004048 if (!wsContent.IsEmpty()) {
4049 int32_t iStart = 0;
4050 int32_t iLength = wsContent.GetLength();
4051 int32_t iEnd = wsContent.Find(L'\n', iStart);
4052 iEnd = (iEnd == -1) ? iLength : iEnd;
4053 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004054 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004055 iStart = iEnd + 1;
4056 if (iStart >= iLength) {
4057 break;
4058 }
4059 iEnd = wsContent.Find(L'\n', iStart);
4060 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004061 wsSaveTextArray.push_back(
4062 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004063 }
4064 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004065 iSize = wsSaveTextArray.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004066 }
4067 if (iSize == 0) {
4068 while (CXFA_Node* pChildNode =
4069 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4070 pBind->RemoveChild(pChildNode);
4071 }
4072 } else {
Tom Sepezf8a94392017-03-14 12:13:22 -07004073 std::vector<CXFA_Node*> valueNodes = pBind->GetNodeList(
4074 XFA_NODEFILTER_Children, XFA_Element::DataValue);
4075 size_t iDatas = valueNodes.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004076 if (iDatas < iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004077 size_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004078 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004079 while (iAddNodes-- > 0) {
4080 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004081 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004082 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004083 pValueNodes->CreateXMLMappingNode();
4084 pBind->InsertChild(pValueNodes);
4085 }
weili44f8faf2016-06-01 14:03:56 -07004086 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004087 } else if (iDatas > iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004088 size_t iDelNodes = iDatas - iSize;
Dan Sinclair1770c022016-03-14 14:14:16 -04004089 while (iDelNodes-- > 0) {
4090 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4091 }
4092 }
4093 int32_t i = 0;
4094 for (CXFA_Node* pValueNode =
4095 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4096 pValueNode; pValueNode = pValueNode->GetNodeItem(
4097 XFA_NODEITEM_NextSibling)) {
4098 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004099 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004100 i++;
4101 }
4102 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004103 for (CXFA_Node* pArrayNode : pBind->GetBindItems()) {
4104 if (pArrayNode != this) {
4105 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4106 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004107 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004108 }
4109 }
4110 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004111 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004112 pNode = this;
4113 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004114 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004115 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004116 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004117 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004118 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004119 }
4120 pBindNode = GetBindData();
4121 if (pBindNode && bSyncData) {
4122 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004123 bScriptModify, false);
Tom Sepezf8a94392017-03-14 12:13:22 -07004124 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4125 if (pArrayNode != this) {
4126 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, true,
4127 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004128 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004129 }
4130 }
weili44f8faf2016-06-01 14:03:56 -07004131 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004132 break;
4133 }
dsinclairc5a8f212016-06-20 11:11:12 -07004134 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004135 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004136 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004137 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004138 if (wsContentType == L"text/html") {
4139 wsContentType = L"";
tsepez4c3debb2016-04-08 12:20:38 -07004140 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004141 }
4142 }
4143 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4144 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004145 pContentRawDataNode = CreateSamePacketNode(
dan sinclair65c7c232017-02-02 14:05:30 -08004146 (wsContentType == L"text/xml") ? XFA_Element::Sharpxml
4147 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004148 InsertChild(pContentRawDataNode);
4149 }
4150 return pContentRawDataNode->SetScriptContent(
4151 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4152 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004153 case XFA_ObjectType::NodeC:
4154 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004155 pNode = this;
4156 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004157 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004158 pNode = this;
4159 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4160 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4161 if (pParent) {
4162 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4163 }
dsinclair070fcdf2016-06-22 22:04:54 -07004164 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004165 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4166 if (pParent && pParent->IsContainerNode()) {
4167 pBindNode = pParent->GetBindData();
4168 if (pBindNode) {
4169 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004170 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004171 }
4172 }
4173 }
4174 }
4175 break;
4176 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004177 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004178 pNode = this;
4179 pBindNode = this;
4180 }
4181 break;
4182 }
4183 if (pNode) {
4184 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4185 if (pBindNode && bSyncData) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004186 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4187 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4188 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004189 }
4190 }
tsepezd19e9122016-11-02 15:43:18 -07004191 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004192 }
tsepezd19e9122016-11-02 15:43:18 -07004193 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004194}
dsinclair5b36f0a2016-07-19 10:56:23 -07004195
tsepezd19e9122016-11-02 15:43:18 -07004196bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4197 const CFX_WideString& wsXMLValue,
4198 bool bNotify,
4199 bool bScriptModify,
4200 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004201 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4202 bSyncData);
4203}
dsinclair5b36f0a2016-07-19 10:56:23 -07004204
tsepezd19e9122016-11-02 15:43:18 -07004205CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004206 CFX_WideString wsContent;
4207 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4208}
dsinclair5b36f0a2016-07-19 10:56:23 -07004209
Dan Sinclair1770c022016-03-14 14:14:16 -04004210CFX_WideString CXFA_Node::GetContent() {
4211 return GetScriptContent();
4212}
dsinclair5b36f0a2016-07-19 10:56:23 -07004213
tsepezd19e9122016-11-02 15:43:18 -07004214bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4215 bool bScriptModify,
4216 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004217 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004218 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004219 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004220 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004221 pNode = this;
4222 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004223 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004224 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004225 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004226 }
4227 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4228 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
dan sinclair65c7c232017-02-02 14:05:30 -08004229 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004230 }
4231 return pChildValue
4232 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004233 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004234 }
4235 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004236 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004237 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4238 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004239 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004240 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004241 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004242 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004243 if (wsContentType == L"text/html") {
dsinclair56a8b192016-06-21 14:15:25 -07004244 element = XFA_Element::SharpxHTML;
dan sinclair65c7c232017-02-02 14:05:30 -08004245 } else if (wsContentType == L"text/xml") {
dsinclair56a8b192016-06-21 14:15:25 -07004246 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004247 }
4248 }
4249 pContentRawDataNode = CreateSamePacketNode(element);
4250 InsertChild(pContentRawDataNode);
4251 }
4252 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4253 }
dsinclairc5a8f212016-06-20 11:11:12 -07004254 case XFA_ObjectType::NodeC:
4255 case XFA_ObjectType::NodeV:
4256 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004257 pNode = this;
4258 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004259 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004260 pNode = this;
4261 }
4262 break;
4263 }
4264 if (pNode) {
4265 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004266 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004267 if (pScriptContext) {
4268 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4269 }
4270 }
tsepezd19e9122016-11-02 15:43:18 -07004271 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004272 }
tsepezd19e9122016-11-02 15:43:18 -07004273 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004274}
dsinclair5b36f0a2016-07-19 10:56:23 -07004275
Dan Sinclair1770c022016-03-14 14:14:16 -04004276CXFA_Node* CXFA_Node::GetModelNode() {
4277 switch (GetPacketID()) {
4278 case XFA_XDPPACKET_XDP:
4279 return m_pDocument->GetRoot();
4280 case XFA_XDPPACKET_Config:
4281 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4282 case XFA_XDPPACKET_Template:
4283 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4284 case XFA_XDPPACKET_Form:
4285 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4286 case XFA_XDPPACKET_Datasets:
4287 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4288 case XFA_XDPPACKET_LocaleSet:
4289 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4290 case XFA_XDPPACKET_ConnectionSet:
4291 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4292 case XFA_XDPPACKET_SourceSet:
4293 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4294 case XFA_XDPPACKET_Xdc:
4295 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4296 default:
4297 return this;
4298 }
4299}
dsinclair5b36f0a2016-07-19 10:56:23 -07004300
tsepezd19e9122016-11-02 15:43:18 -07004301bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004302 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004303 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
dsinclairae95f762016-03-29 16:58:29 -07004304 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004305 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004306 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004307 }
dsinclairae95f762016-03-29 16:58:29 -07004308 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004309 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004310 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
dsinclairae95f762016-03-29 16:58:29 -07004311 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004312 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004313 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004314 }
4315 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004316 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004317 }
dsinclair070fcdf2016-06-22 22:04:54 -07004318 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004319 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4320 return XFA_FDEExtension_ResolveNamespaceQualifier(
dsinclairae95f762016-03-29 16:58:29 -07004321 static_cast<CFDE_XMLElement*>(pXMLNode),
4322 GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004323 }
dsinclairae95f762016-03-29 16:58:29 -07004324 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004325 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004326 } else {
4327 CXFA_Node* pModelNode = GetModelNode();
4328 return pModelNode->TryNamespace(wsNamespace);
4329 }
4330}
dsinclair5b36f0a2016-07-19 10:56:23 -07004331
Dan Sinclair1770c022016-03-14 14:14:16 -04004332CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004333 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004334 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004335 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004336 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004337 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004338 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004339 if (!pProperty || index >= pProperty->uOccur)
4340 return nullptr;
4341
Dan Sinclair1770c022016-03-14 14:14:16 -04004342 CXFA_Node* pNode = m_pChild;
4343 int32_t iCount = 0;
4344 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004345 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004346 iCount++;
4347 if (iCount > index) {
4348 return pNode;
4349 }
4350 }
4351 }
weili44f8faf2016-06-01 14:03:56 -07004352 if (!bCreateProperty)
4353 return nullptr;
4354
Dan Sinclair1770c022016-03-14 14:14:16 -04004355 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4356 pNode = m_pChild;
4357 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4358 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004359 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004360 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4361 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004362 }
4363 }
dsinclaira1b07722016-07-11 08:20:58 -07004364
Dan Sinclair1770c022016-03-14 14:14:16 -04004365 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004366 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004367 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004368 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004369 if (!pNewNode)
4370 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004371 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004372 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004373 }
4374 return pNewNode;
4375}
dsinclair5b36f0a2016-07-19 10:56:23 -07004376
tsepezd19e9122016-11-02 15:43:18 -07004377int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004378 CXFA_Node* pNode = m_pChild;
4379 int32_t iCount = 0;
4380 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004381 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004382 if (bOnlyChild) {
4383 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004384 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004385 if (pProperty) {
4386 continue;
4387 }
4388 }
4389 iCount++;
4390 }
4391 }
4392 return iCount;
4393}
dsinclair5b36f0a2016-07-19 10:56:23 -07004394
Dan Sinclair1770c022016-03-14 14:14:16 -04004395CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004396 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004397 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004398 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004399 CXFA_Node* pNode = m_pChild;
4400 int32_t iCount = 0;
4401 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004402 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004403 if (bOnlyChild) {
4404 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004405 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004406 if (pProperty) {
4407 continue;
4408 }
4409 }
4410 iCount++;
4411 if (iCount > index) {
4412 return pNode;
4413 }
4414 }
4415 }
weili44f8faf2016-06-01 14:03:56 -07004416 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004417}
dsinclair5b36f0a2016-07-19 10:56:23 -07004418
Dan Sinclair1770c022016-03-14 14:14:16 -04004419int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4420 ASSERT(!pNode->m_pNext);
4421 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004422 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004423 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004424 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004425
weili44f8faf2016-06-01 14:03:56 -07004426 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004427 if (index > 0) {
4428 return -1;
4429 }
4430 pNode->m_pNext = m_pChild;
4431 m_pChild = pNode;
4432 index = 0;
4433 } else if (index < 0) {
4434 m_pLastChild->m_pNext = pNode;
4435 } else {
4436 CXFA_Node* pPrev = m_pChild;
4437 int32_t iCount = 0;
4438 while (++iCount != index && pPrev->m_pNext) {
4439 pPrev = pPrev->m_pNext;
4440 }
4441 if (index > 0 && index != iCount) {
4442 return -1;
4443 }
4444 pNode->m_pNext = pPrev->m_pNext;
4445 pPrev->m_pNext = pNode;
4446 index = iCount;
4447 }
weili44f8faf2016-06-01 14:03:56 -07004448 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004449 m_pLastChild = pNode;
4450 }
4451 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004452 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004453 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004454 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004455 if (pNotify)
4456 pNotify->OnChildAdded(this);
4457
Dan Sinclair1770c022016-03-14 14:14:16 -04004458 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004459 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004460 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004461 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004462 }
4463 return index;
4464}
weili6e1ae862016-05-04 18:25:27 -07004465
tsepezd19e9122016-11-02 15:43:18 -07004466bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004467 if (!pNode || pNode->m_pParent ||
4468 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004469 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004470 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004471 }
tsepezd19e9122016-11-02 15:43:18 -07004472 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004473 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004474 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004475
4476 int32_t nIndex = -1;
4477 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004478 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004479 pNode->m_pNext = m_pChild;
4480 m_pChild = pNode;
4481 nIndex = 0;
4482 } else if (!pBeforeNode) {
4483 pNode->m_pNext = m_pLastChild->m_pNext;
4484 m_pLastChild->m_pNext = pNode;
4485 } else {
4486 nIndex = 1;
4487 CXFA_Node* pPrev = m_pChild;
4488 while (pPrev->m_pNext != pBeforeNode) {
4489 pPrev = pPrev->m_pNext;
4490 nIndex++;
4491 }
4492 pNode->m_pNext = pPrev->m_pNext;
4493 pPrev->m_pNext = pNode;
4494 }
weili44f8faf2016-06-01 14:03:56 -07004495 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004496 m_pLastChild = pNode;
4497 }
4498 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004499 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004500 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004501 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004502 if (pNotify)
4503 pNotify->OnChildAdded(this);
4504
Dan Sinclair1770c022016-03-14 14:14:16 -04004505 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004506 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004507 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004508 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004509 }
tsepezd19e9122016-11-02 15:43:18 -07004510 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004511}
dsinclair5b36f0a2016-07-19 10:56:23 -07004512
Dan Sinclair1770c022016-03-14 14:14:16 -04004513CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4514 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004515 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004516 }
4517 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4518 pSibling = pSibling->m_pNext) {
4519 if (pSibling->m_pNext == this) {
4520 return pSibling;
4521 }
4522 }
weili44f8faf2016-06-01 14:03:56 -07004523 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004524}
dsinclair5b36f0a2016-07-19 10:56:23 -07004525
tsepezd19e9122016-11-02 15:43:18 -07004526bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004527 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004528 ASSERT(false);
4529 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004530 }
4531 if (m_pChild == pNode) {
4532 m_pChild = pNode->m_pNext;
4533 if (m_pLastChild == pNode) {
4534 m_pLastChild = pNode->m_pNext;
4535 }
weili44f8faf2016-06-01 14:03:56 -07004536 pNode->m_pNext = nullptr;
4537 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004538 } else {
4539 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4540 pPrev->m_pNext = pNode->m_pNext;
4541 if (m_pLastChild == pNode) {
4542 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4543 }
weili44f8faf2016-06-01 14:03:56 -07004544 pNode->m_pNext = nullptr;
4545 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004546 }
weili44f8faf2016-06-01 14:03:56 -07004547 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004548 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004549 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004550 m_pDocument->AddPurgeNode(pNode);
4551 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4552 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004553 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4554 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004555 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07004556 CFDE_XMLElement* pXMLElement =
4557 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004558 CFX_WideStringC wsAttributeName =
4559 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004560 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004561 }
4562 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004563 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -07004564 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004565 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4566 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004567 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004568 }
4569 pNode->m_pXMLNode = pNewXMLElement;
4570 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4571 } else {
4572 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4573 }
dsinclairc5a8f212016-06-20 11:11:12 -07004574 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004575 }
tsepezd19e9122016-11-02 15:43:18 -07004576 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004577}
dsinclair5b36f0a2016-07-19 10:56:23 -07004578
Dan Sinclair1770c022016-03-14 14:14:16 -04004579CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004580 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004581}
dsinclair5b36f0a2016-07-19 10:56:23 -07004582
tsepez736f28a2016-03-25 14:19:51 -07004583CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004584 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4585 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4586 if (pNode->GetNameHash() == dwNameHash) {
4587 return pNode;
4588 }
4589 }
weili44f8faf2016-06-01 14:03:56 -07004590 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004591}
dsinclair5b36f0a2016-07-19 10:56:23 -07004592
dsinclair41cb62e2016-06-23 09:20:32 -07004593CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004594 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4595 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004596 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004597 return pNode;
4598 }
4599 }
weili44f8faf2016-06-01 14:03:56 -07004600 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004601}
dsinclair5b36f0a2016-07-19 10:56:23 -07004602
tsepez736f28a2016-03-25 14:19:51 -07004603CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004604 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4605 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4606 if (pNode->GetNameHash() == dwNameHash) {
4607 return pNode;
4608 }
4609 }
weili44f8faf2016-06-01 14:03:56 -07004610 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004611}
dsinclair5b36f0a2016-07-19 10:56:23 -07004612
Dan Sinclair1770c022016-03-14 14:14:16 -04004613CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4614 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004615 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004616}
dsinclair5b36f0a2016-07-19 10:56:23 -07004617
dsinclair41cb62e2016-06-23 09:20:32 -07004618CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004619 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4620 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004621 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004622 return pNode;
4623 }
4624 }
weili44f8faf2016-06-01 14:03:56 -07004625 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004626}
dsinclair5b36f0a2016-07-19 10:56:23 -07004627
Dan Sinclair1770c022016-03-14 14:14:16 -04004628int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004629 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004630 if (!pScriptContext) {
4631 return -1;
4632 }
4633 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4634}
dsinclair5b36f0a2016-07-19 10:56:23 -07004635
Dan Sinclair1770c022016-03-14 14:14:16 -04004636int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004637 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004638 if (!pScriptContext) {
4639 return -1;
4640 }
4641 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4642}
dsinclair5b36f0a2016-07-19 10:56:23 -07004643
Dan Sinclair1770c022016-03-14 14:14:16 -04004644void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004645 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004646 if (!pScriptContext) {
4647 return;
4648 }
4649 pScriptContext->GetSomExpression(this, wsSOMExpression);
4650}
dsinclair5b36f0a2016-07-19 10:56:23 -07004651
Dan Sinclair1770c022016-03-14 14:14:16 -04004652CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004653 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004654 if (m_ePacket == XFA_XDPPACKET_Form) {
4655 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004656 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004657 return pInstanceMgr;
4658 }
4659 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4660 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004661 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004662 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004663 pNode->m_dwNameHash != m_dwNameHash) {
4664 break;
4665 }
dsinclair56a8b192016-06-21 14:15:25 -07004666 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004667 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4668 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4669 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4670 wsInstName.Mid(1) == wsName) {
4671 pInstanceMgr = pNode;
4672 }
4673 break;
4674 }
4675 }
4676 }
4677 return pInstanceMgr;
4678}
dsinclair5b36f0a2016-07-19 10:56:23 -07004679
Dan Sinclair1770c022016-03-14 14:14:16 -04004680CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004681 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004682}
dsinclair5b36f0a2016-07-19 10:56:23 -07004683
dsinclairc5a8f212016-06-20 11:11:12 -07004684bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4685 if (m_uNodeFlags & dwFlag)
4686 return true;
4687 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4688 return m_pParent && m_pParent->HasFlag(dwFlag);
4689 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004690}
thestigb1a59592016-04-14 18:29:56 -07004691
4692void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004693 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004694 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004695 if (pNotify) {
4696 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004697 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004698 }
dsinclairc5a8f212016-06-20 11:11:12 -07004699 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004700}
thestigb1a59592016-04-14 18:29:56 -07004701
4702void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004703 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004704}
4705
tsepezd19e9122016-11-02 15:43:18 -07004706bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004707 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4708}
thestigb1a59592016-04-14 18:29:56 -07004709
4710void CXFA_Node::OnRemoved(bool bNotify) {
4711 if (!bNotify)
4712 return;
4713
dsinclaira1b07722016-07-11 08:20:58 -07004714 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004715 if (pNotify)
4716 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004717}
thestigb1a59592016-04-14 18:29:56 -07004718
4719void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004720 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004721 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004722 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004723 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004724 }
4725 }
4726}
thestigb1a59592016-04-14 18:29:56 -07004727
Dan Sinclair1770c022016-03-14 14:14:16 -04004728void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004729 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004730 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004731 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004732 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004733 }
4734}
thestigb1a59592016-04-14 18:29:56 -07004735
Dan Sinclair1770c022016-03-14 14:14:16 -04004736int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004737 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004738 int32_t iRet = XFA_EVENTERROR_NotExist;
4739 const XFA_ExecEventParaInfo* eventParaInfo =
4740 GetEventParaInfoByName(wsEventName);
4741 if (eventParaInfo) {
4742 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004743 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004744 if (!pNotify) {
4745 return iRet;
4746 }
4747 if (validFlags == 1) {
4748 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4749 } else if (validFlags == 2) {
4750 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004751 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004752 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004753 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004754 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004755 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004756 }
4757 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004758 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004759 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004760 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004761 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004762 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004763 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004764 }
4765 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004766 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004767 }
4768 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004769 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004770 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004771 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004772 }
4773 } else if (validFlags == 6) {
4774 CXFA_WidgetData* pWidgetData = GetWidgetData();
4775 if (pWidgetData) {
4776 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004777 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004778 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004779 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004780 }
4781 }
4782 } else if (validFlags == 7) {
4783 CXFA_WidgetData* pWidgetData = GetWidgetData();
4784 if (pWidgetData) {
4785 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004786 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004787 (!pWidgetData->IsListBox())) {
4788 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004789 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004790 }
4791 }
4792 }
4793 }
4794 return iRet;
4795}
dsinclair5b36f0a2016-07-19 10:56:23 -07004796
Dan Sinclair1770c022016-03-14 14:14:16 -04004797void CXFA_Node::UpdateNameHash() {
4798 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004799 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004800 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004801 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004802 wsName = GetCData(XFA_ATTRIBUTE_Name);
4803 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004804 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004805 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004806 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004807 }
4808}
dsinclair5b36f0a2016-07-19 10:56:23 -07004809
dsinclairae95f762016-03-29 16:58:29 -07004810CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004811 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004812 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
dsinclairae95f762016-03-29 16:58:29 -07004813 m_pXMLNode = new CFDE_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004814 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004815 }
4816 return m_pXMLNode;
4817}
dsinclair5b36f0a2016-07-19 10:56:23 -07004818
tsepezd19e9122016-11-02 15:43:18 -07004819bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004820 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004821 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004822}
4823
4824XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4825 if (!m_pMapModuleData)
4826 m_pMapModuleData = new XFA_MAPMODULEDATA;
4827 return m_pMapModuleData;
4828}
4829
4830XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4831 return m_pMapModuleData;
4832}
4833
4834void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4835 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004836 pModule->m_ValueMap[pKey] = pValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04004837}
4838
tsepezd19e9122016-11-02 15:43:18 -07004839bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
tsepez6bb3b892017-01-05 12:18:41 -08004840 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004841 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004842 if (pModule) {
4843 auto it = pModule->m_ValueMap.find(pKey);
4844 if (it != pModule->m_ValueMap.end()) {
4845 pValue = it->second;
4846 return true;
4847 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004848 }
tsepez6bb3b892017-01-05 12:18:41 -08004849 if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4850 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004851 }
tsepezd19e9122016-11-02 15:43:18 -07004852 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004853}
dsinclair5b36f0a2016-07-19 10:56:23 -07004854
Dan Sinclair1770c022016-03-14 14:14:16 -04004855void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004856 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair812e96c2017-03-13 16:43:37 -04004857 wsValue.GetLength() * sizeof(wchar_t));
Dan Sinclair1770c022016-03-14 14:14:16 -04004858}
dsinclair5b36f0a2016-07-19 10:56:23 -07004859
tsepezd19e9122016-11-02 15:43:18 -07004860bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004861 void* pValue;
4862 int32_t iBytes;
4863 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004864 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004865 }
Dan Sinclair812e96c2017-03-13 16:43:37 -04004866 wsValue = CFX_WideStringC((const wchar_t*)pValue, iBytes / sizeof(wchar_t));
tsepezd19e9122016-11-02 15:43:18 -07004867 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004868}
dsinclair5b36f0a2016-07-19 10:56:23 -07004869
Dan Sinclair1770c022016-03-14 14:14:16 -04004870void CXFA_Node::SetMapModuleBuffer(
4871 void* pKey,
4872 void* pValue,
4873 int32_t iBytes,
4874 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4875 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4876 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004877 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004878 pBuffer =
4879 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4880 } else if (pBuffer->iBytes != iBytes) {
4881 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4882 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4883 }
4884 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4885 sizeof(XFA_MAPDATABLOCK) + iBytes);
4886 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4887 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4888 }
weili44f8faf2016-06-01 14:03:56 -07004889 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04004890 return;
weili44f8faf2016-06-01 14:03:56 -07004891
Dan Sinclair1770c022016-03-14 14:14:16 -04004892 pBuffer->pCallbackInfo = pCallbackInfo;
4893 pBuffer->iBytes = iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004894 memcpy(pBuffer->GetData(), pValue, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004895}
dsinclair5b36f0a2016-07-19 10:56:23 -07004896
tsepezd19e9122016-11-02 15:43:18 -07004897bool CXFA_Node::GetMapModuleBuffer(void* pKey,
4898 void*& pValue,
4899 int32_t& iBytes,
4900 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07004901 XFA_MAPDATABLOCK* pBuffer = nullptr;
tsepez6bb3b892017-01-05 12:18:41 -08004902 for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004903 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004904 if (pModule) {
4905 auto it = pModule->m_BufferMap.find(pKey);
4906 if (it != pModule->m_BufferMap.end()) {
4907 pBuffer = it->second;
4908 break;
4909 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004910 }
tsepez6bb3b892017-01-05 12:18:41 -08004911 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4912 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004913 }
tsepez6bb3b892017-01-05 12:18:41 -08004914 if (!pBuffer)
tsepezd19e9122016-11-02 15:43:18 -07004915 return false;
tsepez6bb3b892017-01-05 12:18:41 -08004916
Dan Sinclair1770c022016-03-14 14:14:16 -04004917 pValue = pBuffer->GetData();
4918 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07004919 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004920}
dsinclair5b36f0a2016-07-19 10:56:23 -07004921
tsepezd19e9122016-11-02 15:43:18 -07004922bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
tsepez6bb3b892017-01-05 12:18:41 -08004923 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004924 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004925 if (pModule) {
4926 auto it1 = pModule->m_ValueMap.find(pKey);
4927 if (it1 != pModule->m_ValueMap.end())
4928 return true;
4929
4930 auto it2 = pModule->m_BufferMap.find(pKey);
4931 if (it2 != pModule->m_BufferMap.end())
4932 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004933 }
tsepez6bb3b892017-01-05 12:18:41 -08004934 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4935 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004936 }
tsepezd19e9122016-11-02 15:43:18 -07004937 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004938}
dsinclair5b36f0a2016-07-19 10:56:23 -07004939
Dan Sinclair1770c022016-03-14 14:14:16 -04004940void CXFA_Node::RemoveMapModuleKey(void* pKey) {
4941 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
4942 if (!pModule)
4943 return;
4944
4945 if (pKey) {
tsepez6bb3b892017-01-05 12:18:41 -08004946 auto it = pModule->m_BufferMap.find(pKey);
4947 if (it != pModule->m_BufferMap.end()) {
4948 XFA_MAPDATABLOCK* pBuffer = it->second;
Dan Sinclair1770c022016-03-14 14:14:16 -04004949 if (pBuffer) {
tsepez6bb3b892017-01-05 12:18:41 -08004950 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
Dan Sinclair1770c022016-03-14 14:14:16 -04004951 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004952 FX_Free(pBuffer);
4953 }
tsepez6bb3b892017-01-05 12:18:41 -08004954 pModule->m_BufferMap.erase(it);
Dan Sinclair1770c022016-03-14 14:14:16 -04004955 }
tsepez6bb3b892017-01-05 12:18:41 -08004956 pModule->m_ValueMap.erase(pKey);
4957 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04004958 }
tsepez6bb3b892017-01-05 12:18:41 -08004959
4960 for (auto& pair : pModule->m_BufferMap) {
4961 XFA_MAPDATABLOCK* pBuffer = pair.second;
4962 if (pBuffer) {
4963 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
4964 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4965 FX_Free(pBuffer);
4966 }
4967 }
4968 pModule->m_BufferMap.clear();
4969 pModule->m_ValueMap.clear();
4970 delete pModule;
Dan Sinclair1770c022016-03-14 14:14:16 -04004971}
dsinclair5b36f0a2016-07-19 10:56:23 -07004972
tsepez6bb3b892017-01-05 12:18:41 -08004973void CXFA_Node::MergeAllData(void* pDstModule) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004974 XFA_MAPMODULEDATA* pDstModuleData =
4975 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
4976 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004977 if (!pSrcModuleData)
Dan Sinclair1770c022016-03-14 14:14:16 -04004978 return;
tsepez6bb3b892017-01-05 12:18:41 -08004979
4980 for (const auto& pair : pSrcModuleData->m_ValueMap)
4981 pDstModuleData->m_ValueMap[pair.first] = pair.second;
4982
4983 for (const auto& pair : pSrcModuleData->m_BufferMap) {
4984 XFA_MAPDATABLOCK* pSrcBuffer = pair.second;
4985 XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first];
Dan Sinclair1770c022016-03-14 14:14:16 -04004986 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
4987 !pSrcBuffer->pCallbackInfo->pCopy) {
tsepez6bb3b892017-01-05 12:18:41 -08004988 if (pDstBuffer) {
4989 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
4990 pDstModuleData->m_BufferMap.erase(pair.first);
Dan Sinclair1770c022016-03-14 14:14:16 -04004991 }
4992 continue;
4993 }
tsepez6bb3b892017-01-05 12:18:41 -08004994 if (!pDstBuffer) {
4995 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
Dan Sinclair1770c022016-03-14 14:14:16 -04004996 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08004997 } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) {
4998 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
4999 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005000 }
tsepez6bb3b892017-01-05 12:18:41 -08005001 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
5002 uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5003 } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5004 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005005 }
tsepez6bb3b892017-01-05 12:18:41 -08005006 if (!pDstBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005007 continue;
5008 }
tsepez6bb3b892017-01-05 12:18:41 -08005009 pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5010 pDstBuffer->iBytes = pSrcBuffer->iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04005011 memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08005012 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) {
5013 pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005014 }
5015 }
5016}
dsinclair5b36f0a2016-07-19 10:56:23 -07005017
Dan Sinclair1770c022016-03-14 14:14:16 -04005018void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5019 if (!pDstModule) {
5020 return;
5021 }
tsepezd19e9122016-11-02 15:43:18 -07005022 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005023 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005024 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005025 }
dsinclair070fcdf2016-06-22 22:04:54 -07005026 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005027 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005028 }
weili44f8faf2016-06-01 14:03:56 -07005029 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5030 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005031 if (bNeedMove) {
5032 pSrcModuleData = GetMapModuleData();
5033 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005034 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005035 }
5036 pDstModuleData = pDstModule->CreateMapModuleData();
5037 }
5038 if (bNeedMove) {
tsepez6bb3b892017-01-05 12:18:41 -08005039 auto it = pSrcModuleData->m_BufferMap.find(pKey);
5040 if (it != pSrcModuleData->m_BufferMap.end()) {
5041 XFA_MAPDATABLOCK* pBufferBlockData = it->second;
5042 if (pBufferBlockData) {
5043 pSrcModuleData->m_BufferMap.erase(pKey);
5044 pDstModuleData->m_BufferMap[pKey] = pBufferBlockData;
5045 }
Dan Sinclair1770c022016-03-14 14:14:16 -04005046 }
5047 }
dsinclairc5a8f212016-06-20 11:11:12 -07005048 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005049 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005050 CFX_WideString wsFormatValue(wsValue);
5051 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5052 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005053 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005054 }
tsepezd19e9122016-11-02 15:43:18 -07005055 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005056 }
5057}
dsinclair5b36f0a2016-07-19 10:56:23 -07005058
Dan Sinclair1770c022016-03-14 14:14:16 -04005059void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5060 CXFA_Node* pDstModule,
5061 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005062 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005063 if (!pSrcModule || !pDstModule || !pKey) {
5064 return;
5065 }
5066 if (bRecursive) {
5067 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5068 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5069 for (; pSrcChild && pDstChild;
5070 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5071 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005072 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005073 }
5074 }
5075 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5076}
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05005077
5078void CXFA_Node::ThrowMissingPropertyException(
5079 const CFX_WideString& obj,
5080 const CFX_WideString& prop) const {
5081 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(),
5082 prop.c_str());
5083}
5084
5085void CXFA_Node::ThrowTooManyOccurancesException(
5086 const CFX_WideString& obj) const {
5087 ThrowException(
5088 L"The element [%s] has violated its allowable number of occurrences.",
5089 obj.c_str());
5090}