blob: 90e93fbda5859a19bde4a4badaf8114f1cb03dd8 [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()) {
Dan Sinclair93bfc262017-04-04 15:10:00 -0400520 std::unique_ptr<CFDE_XMLNode> pCloneXML;
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);
Dan Sinclair93bfc262017-04-04 15:10:00 -0400524 auto pCloneXMLElement = pdfium::MakeUnique<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 }
Dan Sinclair93bfc262017-04-04 15:10:00 -0400529 pCloneXML.reset(pCloneXMLElement.release());
Dan Sinclair1770c022016-03-14 14:14:16 -0400530 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
531 } else {
Dan Sinclair93bfc262017-04-04 15:10:00 -0400532 pCloneXML = m_pXMLNode->Clone();
Dan Sinclair1770c022016-03-14 14:14:16 -0400533 }
Dan Sinclair93bfc262017-04-04 15:10:00 -0400534 pClone->SetXMLMappingNode(pCloneXML.release());
dsinclairc5a8f212016-06-20 11:11:12 -0700535 pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400536 }
537 if (bRecursive) {
538 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
539 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
540 pClone->InsertChild(pChild->Clone(bRecursive));
541 }
542 }
dsinclairc5a8f212016-06-20 11:11:12 -0700543 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
weili44f8faf2016-06-01 14:03:56 -0700544 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400545 return pClone;
546}
weili44f8faf2016-06-01 14:03:56 -0700547
Dan Sinclair1770c022016-03-14 14:14:16 -0400548CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
549 switch (eItem) {
550 case XFA_NODEITEM_NextSibling:
551 return m_pNext;
552 case XFA_NODEITEM_FirstChild:
553 return m_pChild;
554 case XFA_NODEITEM_Parent:
555 return m_pParent;
556 case XFA_NODEITEM_PrevSibling:
557 if (m_pParent) {
558 CXFA_Node* pSibling = m_pParent->m_pChild;
weili44f8faf2016-06-01 14:03:56 -0700559 CXFA_Node* pPrev = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400560 while (pSibling && pSibling != this) {
561 pPrev = pSibling;
562 pSibling = pSibling->m_pNext;
563 }
564 return pPrev;
565 }
weili44f8faf2016-06-01 14:03:56 -0700566 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400567 default:
568 break;
569 }
weili44f8faf2016-06-01 14:03:56 -0700570 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400571}
weili44f8faf2016-06-01 14:03:56 -0700572
Dan Sinclair1770c022016-03-14 14:14:16 -0400573CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
dsinclairc5a8f212016-06-20 11:11:12 -0700574 XFA_ObjectType eType) const {
weili44f8faf2016-06-01 14:03:56 -0700575 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400576 switch (eItem) {
577 case XFA_NODEITEM_NextSibling:
578 pNode = m_pNext;
dsinclairc5a8f212016-06-20 11:11:12 -0700579 while (pNode && pNode->GetObjectType() != eType)
580 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400581 break;
582 case XFA_NODEITEM_FirstChild:
583 pNode = m_pChild;
dsinclairc5a8f212016-06-20 11:11:12 -0700584 while (pNode && pNode->GetObjectType() != eType)
585 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400586 break;
587 case XFA_NODEITEM_Parent:
588 pNode = m_pParent;
dsinclairc5a8f212016-06-20 11:11:12 -0700589 while (pNode && pNode->GetObjectType() != eType)
590 pNode = pNode->m_pParent;
Dan Sinclair1770c022016-03-14 14:14:16 -0400591 break;
592 case XFA_NODEITEM_PrevSibling:
593 if (m_pParent) {
594 CXFA_Node* pSibling = m_pParent->m_pChild;
595 while (pSibling && pSibling != this) {
dsinclairc5a8f212016-06-20 11:11:12 -0700596 if (eType == pSibling->GetObjectType())
Dan Sinclair1770c022016-03-14 14:14:16 -0400597 pNode = pSibling;
dsinclairc5a8f212016-06-20 11:11:12 -0700598
Dan Sinclair1770c022016-03-14 14:14:16 -0400599 pSibling = pSibling->m_pNext;
600 }
601 }
602 break;
603 default:
604 break;
605 }
606 return pNode;
607}
weili44f8faf2016-06-01 14:03:56 -0700608
Tom Sepezf8a94392017-03-14 12:13:22 -0700609std::vector<CXFA_Node*> CXFA_Node::GetNodeList(uint32_t dwTypeFilter,
610 XFA_Element eTypeFilter) {
611 std::vector<CXFA_Node*> nodes;
dsinclair41cb62e2016-06-23 09:20:32 -0700612 if (eTypeFilter != XFA_Element::Unknown) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700613 for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext) {
614 if (pChild->GetElementType() == eTypeFilter)
615 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400616 }
617 } else if (dwTypeFilter ==
618 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700619 for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext)
620 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400621 } else if (dwTypeFilter != 0) {
weili44f8faf2016-06-01 14:03:56 -0700622 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
623 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
624 bool bFilterOneOfProperties =
625 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
Dan Sinclair1770c022016-03-14 14:14:16 -0400626 CXFA_Node* pChild = m_pChild;
627 while (pChild) {
628 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -0700629 GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -0400630 if (pProperty) {
631 if (bFilterProperties) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700632 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400633 } else if (bFilterOneOfProperties &&
634 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700635 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400636 } else if (bFilterChildren &&
dsinclair070fcdf2016-06-22 22:04:54 -0700637 (pChild->GetElementType() == XFA_Element::Variables ||
638 pChild->GetElementType() == XFA_Element::PageSet)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700639 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400640 }
weili44f8faf2016-06-01 14:03:56 -0700641 } else if (bFilterChildren) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700642 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400643 }
644 pChild = pChild->m_pNext;
645 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700646 if (bFilterOneOfProperties && nodes.empty()) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400647 int32_t iProperties = 0;
648 const XFA_PROPERTY* pProperty =
dsinclair070fcdf2016-06-22 22:04:54 -0700649 XFA_GetElementProperties(GetElementType(), iProperties);
weili44f8faf2016-06-01 14:03:56 -0700650 if (!pProperty || iProperties < 1)
Tom Sepezf8a94392017-03-14 12:13:22 -0700651 return nodes;
Dan Sinclair1770c022016-03-14 14:14:16 -0400652 for (int32_t i = 0; i < iProperties; i++) {
653 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400654 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
655 CXFA_Node* pNewNode =
dsinclaira1b07722016-07-11 08:20:58 -0700656 m_pDocument->CreateNode(pPacket, pProperty[i].eName);
weili44f8faf2016-06-01 14:03:56 -0700657 if (!pNewNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400658 break;
weili44f8faf2016-06-01 14:03:56 -0700659 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -0700660 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Tom Sepezf8a94392017-03-14 12:13:22 -0700661 nodes.push_back(pNewNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400662 break;
663 }
664 }
665 }
666 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700667 return nodes;
Dan Sinclair1770c022016-03-14 14:14:16 -0400668}
weili44f8faf2016-06-01 14:03:56 -0700669
dsinclair41cb62e2016-06-23 09:20:32 -0700670CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
tsepez736f28a2016-03-25 14:19:51 -0700671 uint32_t dwFlags) {
dsinclaira1b07722016-07-11 08:20:58 -0700672 CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
thestigb1a59592016-04-14 18:29:56 -0700673 pNode->SetFlag(dwFlags, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400674 return pNode;
675}
weili44f8faf2016-06-01 14:03:56 -0700676
tsepezd19e9122016-11-02 15:43:18 -0700677CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) {
dsinclair43854a52016-04-27 12:26:00 -0700678 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
dsinclaira1b07722016-07-11 08:20:58 -0700679 CXFA_Node* pClone =
680 m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700681 if (!pClone)
682 return nullptr;
683
Dan Sinclair1770c022016-03-14 14:14:16 -0400684 pClone->SetTemplateNode(this);
685 pClone->UpdateNameHash();
686 pClone->SetXMLMappingNode(GetXMLMappingNode());
687 if (bRecursive) {
688 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
689 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
690 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
691 }
692 }
dsinclairc5a8f212016-06-20 11:11:12 -0700693 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400694 return pClone;
695}
696
697CXFA_Node* CXFA_Node::GetTemplateNode() const {
698 return m_pAuxNode;
699}
700
701void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
702 m_pAuxNode = pTemplateNode;
703}
weili44f8faf2016-06-01 14:03:56 -0700704
Dan Sinclair1770c022016-03-14 14:14:16 -0400705CXFA_Node* CXFA_Node::GetBindData() {
706 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
707 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
708}
weili44f8faf2016-06-01 14:03:56 -0700709
Tom Sepezf8a94392017-03-14 12:13:22 -0700710std::vector<CXFA_Node*> CXFA_Node::GetBindItems() {
dsinclairc5a8f212016-06-20 11:11:12 -0700711 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700712 void* pBinding = nullptr;
713 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
714 return *static_cast<std::vector<CXFA_Node*>*>(pBinding);
Dan Sinclair1770c022016-03-14 14:14:16 -0400715 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700716 std::vector<CXFA_Node*> result;
Dan Sinclair1770c022016-03-14 14:14:16 -0400717 CXFA_Node* pFormNode =
718 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
weili44f8faf2016-06-01 14:03:56 -0700719 if (pFormNode)
Tom Sepezf8a94392017-03-14 12:13:22 -0700720 result.push_back(pFormNode);
721 return result;
Dan Sinclair1770c022016-03-14 14:14:16 -0400722}
723
Dan Sinclair1770c022016-03-14 14:14:16 -0400724int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
725 ASSERT(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700726 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700727 void* pBinding = nullptr;
728 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
729 auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding);
730 if (!pdfium::ContainsValue(*pItems, pFormNode))
731 pItems->push_back(pFormNode);
732 return pdfium::CollectionSize<int32_t>(*pItems);
Dan Sinclair1770c022016-03-14 14:14:16 -0400733 }
734 CXFA_Node* pOldFormItem =
735 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
736 if (!pOldFormItem) {
737 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
738 return 1;
Dan Sinclair1770c022016-03-14 14:14:16 -0400739 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700740 if (pOldFormItem == pFormNode)
741 return 1;
742
743 std::vector<CXFA_Node*>* pItems = new std::vector<CXFA_Node*>;
Dan Sinclair1770c022016-03-14 14:14:16 -0400744 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
Tom Sepezf8a94392017-03-14 12:13:22 -0700745 pItems->push_back(pOldFormItem);
746 pItems->push_back(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700747 m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400748 return 2;
749}
weili44f8faf2016-06-01 14:03:56 -0700750
Dan Sinclair1770c022016-03-14 14:14:16 -0400751int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
dsinclairc5a8f212016-06-20 11:11:12 -0700752 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700753 void* pBinding = nullptr;
754 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
755 auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding);
756 auto iter = std::find(pItems->begin(), pItems->end(), pFormNode);
757 if (iter != pItems->end()) {
758 *iter = pItems->back();
759 pItems->pop_back();
760 if (pItems->size() == 1) {
761 SetObject(XFA_ATTRIBUTE_BindingNode,
762 (*pItems)[0]); // Invalidates pItems.
dsinclairc5a8f212016-06-20 11:11:12 -0700763 m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
Tom Sepezf8a94392017-03-14 12:13:22 -0700764 return 1;
Dan Sinclair1770c022016-03-14 14:14:16 -0400765 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400766 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700767 return pdfium::CollectionSize<int32_t>(*pItems);
Dan Sinclair1770c022016-03-14 14:14:16 -0400768 }
769 CXFA_Node* pOldFormItem =
770 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
Tom Sepezf8a94392017-03-14 12:13:22 -0700771 if (pOldFormItem != pFormNode)
772 return pOldFormItem ? 1 : 0;
773
774 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
775 return 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400776}
weili44f8faf2016-06-01 14:03:56 -0700777
tsepezd19e9122016-11-02 15:43:18 -0700778bool CXFA_Node::HasBindItem() {
weili44f8faf2016-06-01 14:03:56 -0700779 return GetPacketID() == XFA_XDPPACKET_Datasets &&
780 GetObject(XFA_ATTRIBUTE_BindingNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400781}
weili44f8faf2016-06-01 14:03:56 -0700782
Dan Sinclair1770c022016-03-14 14:14:16 -0400783CXFA_WidgetData* CXFA_Node::GetWidgetData() {
784 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
785}
weili44f8faf2016-06-01 14:03:56 -0700786
Dan Sinclair1770c022016-03-14 14:14:16 -0400787CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
weili44f8faf2016-06-01 14:03:56 -0700788 if (GetPacketID() != XFA_XDPPACKET_Form)
789 return nullptr;
dsinclair41cb62e2016-06-23 09:20:32 -0700790 XFA_Element eType = GetElementType();
791 if (eType == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700792 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400793 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700794 if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700795 return nullptr;
796
dsinclair41cb62e2016-06-23 09:20:32 -0700797 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400798 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
799 if (pFieldWidgetData &&
800 pFieldWidgetData->GetChoiceListOpen() ==
801 XFA_ATTRIBUTEENUM_MultiSelect) {
weili44f8faf2016-06-01 14:03:56 -0700802 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400803 } else {
804 CFX_WideString wsPicture;
805 if (pFieldWidgetData) {
806 pFieldWidgetData->GetPictureContent(wsPicture,
807 XFA_VALUEPICTURE_DataBind);
808 }
weili44f8faf2016-06-01 14:03:56 -0700809 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400810 return pFieldWidgetData;
Dan Sinclair1770c022016-03-14 14:14:16 -0400811 CXFA_Node* pDataNode = GetBindData();
weili44f8faf2016-06-01 14:03:56 -0700812 if (!pDataNode)
813 return nullptr;
814 pFieldWidgetData = nullptr;
Tom Sepezf8a94392017-03-14 12:13:22 -0700815 for (CXFA_Node* pFormNode : pDataNode->GetBindItems()) {
dsinclairc5a8f212016-06-20 11:11:12 -0700816 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -0400817 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400818 pFieldWidgetData = pFormNode->GetWidgetData();
819 if (pFieldWidgetData) {
820 pFieldWidgetData->GetPictureContent(wsPicture,
821 XFA_VALUEPICTURE_DataBind);
822 }
weili44f8faf2016-06-01 14:03:56 -0700823 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400824 break;
weili44f8faf2016-06-01 14:03:56 -0700825 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400826 }
827 return pFieldWidgetData;
828 }
829 }
830 CXFA_Node* pGrandNode =
weili44f8faf2016-06-01 14:03:56 -0700831 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400832 CXFA_Node* pValueNode =
dsinclair070fcdf2016-06-22 22:04:54 -0700833 (pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
Dan Sinclair1770c022016-03-14 14:14:16 -0400834 ? pParentNode
weili44f8faf2016-06-01 14:03:56 -0700835 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400836 if (!pValueNode) {
dsinclair070fcdf2016-06-22 22:04:54 -0700837 pValueNode =
838 (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
839 ? pGrandNode
840 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400841 }
842 CXFA_Node* pParentOfValueNode =
weili44f8faf2016-06-01 14:03:56 -0700843 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400844 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
weili44f8faf2016-06-01 14:03:56 -0700845 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400846}
weili44f8faf2016-06-01 14:03:56 -0700847
tsepezd19e9122016-11-02 15:43:18 -0700848bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400849 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
dsinclair56a8b192016-06-21 14:15:25 -0700850 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
dsinclair43854a52016-04-27 12:26:00 -0700851 ASSERT(pTopSubform);
Dan Sinclair1770c022016-03-14 14:14:16 -0400852 CXFA_Node* pLocaleNode = this;
tsepezd19e9122016-11-02 15:43:18 -0700853 bool bLocale = false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400854 do {
tsepezd19e9122016-11-02 15:43:18 -0700855 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400856 if (!bLocale) {
857 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
858 }
859 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
weili44f8faf2016-06-01 14:03:56 -0700860 if (bLocale)
tsepezd19e9122016-11-02 15:43:18 -0700861 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400862 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
863 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
weili44f8faf2016-06-01 14:03:56 -0700864 if (!wsLocaleName.IsEmpty())
tsepezd19e9122016-11-02 15:43:18 -0700865 return true;
weili44f8faf2016-06-01 14:03:56 -0700866 if (pTopSubform &&
tsepezd19e9122016-11-02 15:43:18 -0700867 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) {
868 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400869 }
870 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
871 if (pLocale) {
872 wsLocaleName = pLocale->GetName();
tsepezd19e9122016-11-02 15:43:18 -0700873 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400874 }
tsepezd19e9122016-11-02 15:43:18 -0700875 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400876}
weili44f8faf2016-06-01 14:03:56 -0700877
Dan Sinclair1770c022016-03-14 14:14:16 -0400878XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
dsinclair56a8b192016-06-21 14:15:25 -0700879 CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
Dan Sinclair1770c022016-03-14 14:14:16 -0400880 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
881 if (pKeep) {
882 XFA_ATTRIBUTEENUM eIntact;
tsepezd19e9122016-11-02 15:43:18 -0700883 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400884 if (eIntact == XFA_ATTRIBUTEENUM_None &&
885 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
886 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
dsinclairc5a8f212016-06-20 11:11:12 -0700887 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
888 XFA_ObjectType::ContainerNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400889 if (pPreviewRow &&
890 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
891 XFA_ATTRIBUTEENUM_Row) {
892 XFA_ATTRIBUTEENUM eValue;
tsepezd19e9122016-11-02 15:43:18 -0700893 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700894 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
895 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
896 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400897 }
weili44f8faf2016-06-01 14:03:56 -0700898 CXFA_Node* pNode =
dsinclair56a8b192016-06-21 14:15:25 -0700899 pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
tsepezd19e9122016-11-02 15:43:18 -0700900 if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700901 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
902 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
903 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400904 }
905 }
906 }
907 return eIntact;
908 }
909 }
dsinclair41cb62e2016-06-23 09:20:32 -0700910 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700911 case XFA_Element::Subform:
Dan Sinclair1770c022016-03-14 14:14:16 -0400912 switch (eLayoutType) {
913 case XFA_ATTRIBUTEENUM_Position:
914 case XFA_ATTRIBUTEENUM_Row:
915 return XFA_ATTRIBUTEENUM_ContentArea;
916 case XFA_ATTRIBUTEENUM_Tb:
917 case XFA_ATTRIBUTEENUM_Table:
918 case XFA_ATTRIBUTEENUM_Lr_tb:
919 case XFA_ATTRIBUTEENUM_Rl_tb:
920 return XFA_ATTRIBUTEENUM_None;
921 default:
922 break;
923 }
924 break;
dsinclair56a8b192016-06-21 14:15:25 -0700925 case XFA_Element::Field: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400926 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700927 if (!pParentNode ||
928 pParentNode->GetElementType() == XFA_Element::PageArea)
Dan Sinclair1770c022016-03-14 14:14:16 -0400929 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400930 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
931 XFA_ATTRIBUTEENUM eParLayout =
932 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
933 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
934 eParLayout == XFA_ATTRIBUTEENUM_Row ||
935 eParLayout == XFA_ATTRIBUTEENUM_Table) {
936 return XFA_ATTRIBUTEENUM_None;
937 }
938 XFA_VERSION version = m_pDocument->GetCurVersionMode();
939 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
940 CXFA_Measurement measureH;
tsepezd19e9122016-11-02 15:43:18 -0700941 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false))
Dan Sinclair1770c022016-03-14 14:14:16 -0400942 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400943 }
944 return XFA_ATTRIBUTEENUM_None;
945 }
946 return XFA_ATTRIBUTEENUM_ContentArea;
947 }
dsinclair56a8b192016-06-21 14:15:25 -0700948 case XFA_Element::Draw:
Dan Sinclair1770c022016-03-14 14:14:16 -0400949 return XFA_ATTRIBUTEENUM_ContentArea;
950 default:
951 break;
952 }
953 return XFA_ATTRIBUTEENUM_None;
954}
weili44f8faf2016-06-01 14:03:56 -0700955
Dan Sinclair1770c022016-03-14 14:14:16 -0400956CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
weili44f8faf2016-06-01 14:03:56 -0700957 if (m_ePacket == XFA_XDPPACKET_Datasets)
Dan Sinclair1770c022016-03-14 14:14:16 -0400958 return m_pAuxNode;
weili44f8faf2016-06-01 14:03:56 -0700959 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400960}
weili44f8faf2016-06-01 14:03:56 -0700961
Dan Sinclair1770c022016-03-14 14:14:16 -0400962void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
dsinclair43854a52016-04-27 12:26:00 -0700963 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
Dan Sinclair1770c022016-03-14 14:14:16 -0400964 m_pAuxNode = pDataDescriptionNode;
965}
weili44f8faf2016-06-01 14:03:56 -0700966
Dan Sinclair1770c022016-03-14 14:14:16 -0400967void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
968 int32_t iLength = pArguments->GetLength();
969 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -0500970 ThrowParamCountMismatchException(L"resolveNode");
Dan Sinclair1770c022016-03-14 14:14:16 -0400971 return;
972 }
tsepez6fe7d212016-04-06 10:51:14 -0700973 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -0700974 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclairdf4bc592016-03-31 20:34:43 -0700975 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -0700976 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -0400977 return;
Dan Sinclair1770c022016-03-14 14:14:16 -0400978 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -0700979 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -0400980 refNode = ToNode(pScriptContext->GetThisObject());
tsepez736f28a2016-03-25 14:19:51 -0700981 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -0400982 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
983 XFA_RESOLVENODE_Siblings;
984 XFA_RESOLVENODE_RS resoveNodeRS;
tsepezfc58ad12016-04-05 12:22:15 -0700985 int32_t iRet = pScriptContext->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -0700986 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
dsinclairf27aeec2016-06-07 19:36:18 -0700987 if (iRet < 1) {
988 pArguments->GetReturnValue()->SetNull();
989 return;
990 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400991 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700992 CXFA_Object* pObject = resoveNodeRS.objects.front();
dsinclairf27aeec2016-06-07 19:36:18 -0700993 pArguments->GetReturnValue()->Assign(
Tom Sepezf8a94392017-03-14 12:13:22 -0700994 pScriptContext->GetJSValueFromMap(pObject));
Dan Sinclair1770c022016-03-14 14:14:16 -0400995 } else {
996 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
997 resoveNodeRS.pScriptAttribute;
998 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
Dan Sinclairfdf7d402017-04-18 15:25:58 -0400999 auto pValue =
1000 pdfium::MakeUnique<CFXJSE_Value>(pScriptContext->GetRuntime());
Tom Sepezf8a94392017-03-14 12:13:22 -07001001 (resoveNodeRS.objects.front()->*(lpAttributeInfo->lpfnCallback))(
tsepezd19e9122016-11-02 15:43:18 -07001002 pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
dsinclairf27aeec2016-06-07 19:36:18 -07001003 pArguments->GetReturnValue()->Assign(pValue.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001004 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001005 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001006 }
1007 }
1008}
weili44f8faf2016-06-01 14:03:56 -07001009
Dan Sinclair1770c022016-03-14 14:14:16 -04001010void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
1011 int32_t iLength = pArguments->GetLength();
1012 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001013 ThrowParamCountMismatchException(L"resolveNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04001014 return;
1015 }
tsepez6fe7d212016-04-06 10:51:14 -07001016 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001017 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclair12a6b0c2016-05-26 11:14:08 -07001018 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001019 if (!pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04001020 return;
tsepez736f28a2016-03-25 14:19:51 -07001021 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001022 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1023 XFA_RESOLVENODE_Siblings;
1024 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001025 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001026 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
dsinclair12a6b0c2016-05-26 11:14:08 -07001027 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001028}
weili44f8faf2016-06-01 14:03:56 -07001029
dsinclair12a6b0c2016-05-26 11:14:08 -07001030void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001031 CFX_WideString wsExpression,
tsepez736f28a2016-03-25 14:19:51 -07001032 uint32_t dwFlag,
Dan Sinclair1770c022016-03-14 14:14:16 -04001033 CXFA_Node* refNode) {
dsinclairdf4bc592016-03-31 20:34:43 -07001034 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001035 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001036 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001037 XFA_RESOLVENODE_RS resoveNodeRS;
weili44f8faf2016-06-01 14:03:56 -07001038 if (!refNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04001039 refNode = this;
tsepez4c3debb2016-04-08 12:20:38 -07001040 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
tsepezfc58ad12016-04-05 12:22:15 -07001041 resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001042 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
1043 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
Tom Sepezf8a94392017-03-14 12:13:22 -07001044 for (CXFA_Object* pObject : resoveNodeRS.objects) {
1045 if (pObject->IsNode())
1046 pNodeList->Append(pObject->AsNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001047 }
1048 } else {
dsinclair12a6b0c2016-05-26 11:14:08 -07001049 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
Tom Sepez369fe1f2017-03-27 16:03:43 -07001050 if (resoveNodeRS.GetAttributeResult(&valueArray) > 0) {
Tom Sepezf8a94392017-03-14 12:13:22 -07001051 for (CXFA_Object* pObject : valueArray.GetAttributeObject()) {
1052 if (pObject->IsNode())
1053 pNodeList->Append(pObject->AsNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001054 }
1055 }
1056 }
dsinclairf27aeec2016-06-07 19:36:18 -07001057 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001058}
weili44f8faf2016-06-01 14:03:56 -07001059
dsinclair12a6b0c2016-05-26 11:14:08 -07001060void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001061 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001062 XFA_ATTRIBUTE eAttribute) {
1063 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001064 ThrowInvalidPropertyException();
1065 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001066 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001067
1068 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
1069 CFX_WideString wsName;
1070 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
dan sinclair65c7c232017-02-02 14:05:30 -08001071 CFX_WideString wsExpression = wsName + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001072 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001073}
weili44f8faf2016-06-01 14:03:56 -07001074
dsinclair12a6b0c2016-05-26 11:14:08 -07001075void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001076 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001077 XFA_ATTRIBUTE eAttribute) {
dsinclairdf4bc592016-03-31 20:34:43 -07001078 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001079 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001080 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001081 if (bSetting) {
Dan Sinclairc8fd3312017-01-02 17:17:02 -05001082 CFX_WideString wsMessage = L"Unable to set ";
Tom Sepezf0b65542017-02-13 10:26:01 -08001083 FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001084 } else {
1085 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
dsinclairf27aeec2016-06-07 19:36:18 -07001086 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001087 }
1088}
weili44f8faf2016-06-01 14:03:56 -07001089
dsinclair12a6b0c2016-05-26 11:14:08 -07001090void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001091 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001092 XFA_ATTRIBUTE eAttribute) {
1093 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001094 ThrowInvalidPropertyException();
1095 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001096 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001097 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
dan sinclair65c7c232017-02-02 14:05:30 -08001098 CFX_WideString wsExpression = L"#" + GetClassName() + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001099 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001100}
weili44f8faf2016-06-01 14:03:56 -07001101
dsinclair12a6b0c2016-05-26 11:14:08 -07001102void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001103 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001104 XFA_ATTRIBUTE eAttribute) {
1105 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001106 ThrowInvalidPropertyException();
1107 return;
1108 }
1109 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
1110 if (pParent) {
1111 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001112 } else {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001113 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001114 }
1115}
weili44f8faf2016-06-01 14:03:56 -07001116
dsinclair12a6b0c2016-05-26 11:14:08 -07001117void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001118 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001119 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001120 if (bSetting) {
1121 ThrowInvalidPropertyException();
1122 return;
1123 }
1124 pValue->SetInteger(GetNodeSameNameIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001125}
weili44f8faf2016-06-01 14:03:56 -07001126
dsinclair12a6b0c2016-05-26 11:14:08 -07001127void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001128 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001129 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001130 if (bSetting) {
1131 ThrowInvalidPropertyException();
1132 return;
1133 }
1134 pValue->SetInteger(GetNodeSameClassIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001135}
weili44f8faf2016-06-01 14:03:56 -07001136
dsinclair12a6b0c2016-05-26 11:14:08 -07001137void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001138 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001139 XFA_ATTRIBUTE eAttribute) {
1140 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001141 ThrowInvalidPropertyException();
1142 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001143 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001144 CFX_WideString wsSOMExpression;
1145 GetSOMExpression(wsSOMExpression);
Tom Sepezf0b65542017-02-13 10:26:01 -08001146 pValue->SetString(wsSOMExpression.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001147}
weili44f8faf2016-06-01 14:03:56 -07001148
Dan Sinclair1770c022016-03-14 14:14:16 -04001149void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
1150 int32_t iLength = pArguments->GetLength();
1151 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001152 ThrowParamCountMismatchException(L"applyXSL");
Dan Sinclair1770c022016-03-14 14:14:16 -04001153 return;
1154 }
tsepez6fe7d212016-04-06 10:51:14 -07001155 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001156 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili60607c32016-05-26 11:53:12 -07001157 // TODO(weili): check whether we need to implement this, pdfium:501.
1158 // For now, just put the variables here to avoid unused variable warning.
1159 (void)wsExpression;
Dan Sinclair1770c022016-03-14 14:14:16 -04001160}
weili60607c32016-05-26 11:53:12 -07001161
Dan Sinclair1770c022016-03-14 14:14:16 -04001162void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
1163 int32_t iLength = pArguments->GetLength();
1164 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001165 ThrowParamCountMismatchException(L"assignNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04001166 return;
1167 }
1168 CFX_WideString wsExpression;
1169 CFX_WideString wsValue;
1170 int32_t iAction = 0;
weili44f8faf2016-06-01 14:03:56 -07001171 wsExpression =
1172 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001173 if (iLength >= 2) {
weili60607c32016-05-26 11:53:12 -07001174 wsValue =
1175 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001176 }
weili60607c32016-05-26 11:53:12 -07001177 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001178 iAction = pArguments->GetInt32(2);
weili60607c32016-05-26 11:53:12 -07001179 // TODO(weili): check whether we need to implement this, pdfium:501.
1180 // For now, just put the variables here to avoid unused variable warning.
1181 (void)wsExpression;
1182 (void)wsValue;
1183 (void)iAction;
Dan Sinclair1770c022016-03-14 14:14:16 -04001184}
weili60607c32016-05-26 11:53:12 -07001185
Dan Sinclair1770c022016-03-14 14:14:16 -04001186void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
1187 int32_t iLength = pArguments->GetLength();
1188 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001189 ThrowParamCountMismatchException(L"clone");
Dan Sinclair1770c022016-03-14 14:14:16 -04001190 return;
1191 }
weili44f8faf2016-06-01 14:03:56 -07001192 bool bClone = !!pArguments->GetInt32(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001193 CXFA_Node* pCloneNode = Clone(bClone);
dsinclairf27aeec2016-06-07 19:36:18 -07001194 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001195 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
1196}
weili44f8faf2016-06-01 14:03:56 -07001197
Dan Sinclair1770c022016-03-14 14:14:16 -04001198void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
1199 int32_t iLength = pArguments->GetLength();
1200 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001201 ThrowParamCountMismatchException(L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001202 return;
1203 }
tsepez6fe7d212016-04-06 10:51:14 -07001204 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001205 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001206 CFX_WideString wsValue;
tsepez4c3debb2016-04-08 12:20:38 -07001207 GetAttribute(wsExpression.AsStringC(), wsValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07001208 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001209 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08001210 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001211}
weili44f8faf2016-06-01 14:03:56 -07001212
Dan Sinclair1770c022016-03-14 14:14:16 -04001213void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
1214 int32_t iLength = pArguments->GetLength();
1215 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001216 ThrowParamCountMismatchException(L"getElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001217 return;
1218 }
1219 CFX_WideString wsExpression;
1220 int32_t iValue = 0;
weili44f8faf2016-06-01 14:03:56 -07001221 wsExpression =
1222 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1223 if (iLength >= 2)
Dan Sinclair1770c022016-03-14 14:14:16 -04001224 iValue = pArguments->GetInt32(1);
dsinclair6e124782016-06-23 12:14:55 -07001225 CXFA_Node* pNode =
1226 GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
dsinclairf27aeec2016-06-07 19:36:18 -07001227 pArguments->GetReturnValue()->Assign(
1228 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001229}
weili65be4b12016-05-25 15:47:43 -07001230
Dan Sinclair1770c022016-03-14 14:14:16 -04001231void CXFA_Node::Script_NodeClass_IsPropertySpecified(
1232 CFXJSE_Arguments* pArguments) {
1233 int32_t iLength = pArguments->GetLength();
1234 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001235 ThrowParamCountMismatchException(L"isPropertySpecified");
Dan Sinclair1770c022016-03-14 14:14:16 -04001236 return;
1237 }
1238 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001239 bool bParent = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001240 int32_t iIndex = 0;
weili44f8faf2016-06-01 14:03:56 -07001241 wsExpression =
1242 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili65be4b12016-05-25 15:47:43 -07001243 if (iLength >= 2)
weili44f8faf2016-06-01 14:03:56 -07001244 bParent = !!pArguments->GetInt32(1);
weili65be4b12016-05-25 15:47:43 -07001245 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001246 iIndex = pArguments->GetInt32(2);
tsepezd19e9122016-11-02 15:43:18 -07001247 bool bHas = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001248 const XFA_ATTRIBUTEINFO* pAttributeInfo =
tsepez4c3debb2016-04-08 12:20:38 -07001249 XFA_GetAttributeByName(wsExpression.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001250 CFX_WideString wsValue;
weili65be4b12016-05-25 15:47:43 -07001251 if (pAttributeInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04001252 bHas = HasAttribute(pAttributeInfo->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04001253 if (!bHas) {
dsinclair6e124782016-06-23 12:14:55 -07001254 XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
1255 bHas = !!GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001256 if (!bHas && bParent && m_pParent) {
1257 // Also check on the parent.
1258 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
1259 if (!bHas)
dsinclair6e124782016-06-23 12:14:55 -07001260 bHas = !!m_pParent->GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001261 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001262 }
dsinclair12a6b0c2016-05-26 11:14:08 -07001263 CFXJSE_Value* pValue = pArguments->GetReturnValue();
1264 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001265 pValue->SetBoolean(bHas);
Dan Sinclair1770c022016-03-14 14:14:16 -04001266}
weili65be4b12016-05-25 15:47:43 -07001267
Dan Sinclair1770c022016-03-14 14:14:16 -04001268void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
1269 int32_t iLength = pArguments->GetLength();
1270 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001271 ThrowParamCountMismatchException(L"loadXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001272 return;
1273 }
Dan Sinclairfdf7d402017-04-18 15:25:58 -04001274
weili44f8faf2016-06-01 14:03:56 -07001275 bool bIgnoreRoot = true;
1276 bool bOverwrite = 0;
Dan Sinclairfdf7d402017-04-18 15:25:58 -04001277 CFX_ByteString wsExpression = pArguments->GetUTF8String(0);
weili44f8faf2016-06-01 14:03:56 -07001278 if (wsExpression.IsEmpty())
Tom Sepezd3743ea2016-05-16 15:56:53 -07001279 return;
weili44f8faf2016-06-01 14:03:56 -07001280 if (iLength >= 2)
1281 bIgnoreRoot = !!pArguments->GetInt32(1);
1282 if (iLength >= 3)
1283 bOverwrite = !!pArguments->GetInt32(2);
Dan Sinclairfdf7d402017-04-18 15:25:58 -04001284 auto pParser = pdfium::MakeUnique<CXFA_SimpleParser>(m_pDocument, false);
weili44f8faf2016-06-01 14:03:56 -07001285 if (!pParser)
Dan Sinclair1770c022016-03-14 14:14:16 -04001286 return;
Dan Sinclairfdf7d402017-04-18 15:25:58 -04001287 CFDE_XMLNode* pXMLNode = pParser->ParseXMLData(wsExpression, nullptr);
1288 if (!pXMLNode)
weili44f8faf2016-06-01 14:03:56 -07001289 return;
dsinclairae95f762016-03-29 16:58:29 -07001290 if (bIgnoreRoot &&
1291 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
1292 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
weili44f8faf2016-06-01 14:03:56 -07001293 bIgnoreRoot = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001294 }
tsepezd19e9122016-11-02 15:43:18 -07001295 CXFA_Node* pFakeRoot = Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001296 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
1297 if (!wsContentType.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07001298 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
1299 CFX_WideString(wsContentType));
Dan Sinclair1770c022016-03-14 14:14:16 -04001300 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001301
1302 std::unique_ptr<CFDE_XMLNode> pFakeXMLRoot(pFakeRoot->GetXMLMappingNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001303 if (!pFakeXMLRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001304 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
Dan Sinclair93bfc262017-04-04 15:10:00 -04001305 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone() : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001306 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001307 if (!pFakeXMLRoot) {
1308 pFakeXMLRoot =
1309 pdfium::MakeUnique<CFDE_XMLElement>(CFX_WideString(GetClassName()));
1310 }
dsinclair017052a2016-06-28 07:43:51 -07001311
Dan Sinclair1770c022016-03-14 14:14:16 -04001312 if (bIgnoreRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001313 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001314 while (pXMLChild) {
dsinclairae95f762016-03-29 16:58:29 -07001315 CFDE_XMLNode* pXMLSibling =
1316 pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001317 pXMLNode->RemoveChildNode(pXMLChild);
1318 pFakeXMLRoot->InsertChildNode(pXMLChild);
1319 pXMLChild = pXMLSibling;
1320 }
1321 } else {
dsinclairae95f762016-03-29 16:58:29 -07001322 CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001323 if (pXMLParent) {
1324 pXMLParent->RemoveChildNode(pXMLNode);
1325 }
1326 pFakeXMLRoot->InsertChildNode(pXMLNode);
1327 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001328 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001329 pFakeRoot = pParser->GetRootNode();
Dan Sinclair93bfc262017-04-04 15:10:00 -04001330 if (!pFakeRoot)
1331 return;
1332
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);
1341 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
1342 pNewChild = pItem;
Dan Sinclair1770c022016-03-14 14:14:16 -04001343 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001344 while (pChild) {
1345 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1346 RemoveChild(pChild);
1347 pFakeRoot->InsertChild(pChild);
1348 pChild = pItem;
Dan Sinclair1770c022016-03-14 14:14:16 -04001349 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001350 if (GetPacketID() == XFA_XDPPACKET_Form &&
1351 GetElementType() == XFA_Element::ExData) {
1352 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
1353 SetXMLMappingNode(pFakeXMLRoot.release());
1354 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
1355 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent))
1356 pFakeXMLRoot.reset(pTempXMLNode);
1357 else
1358 pFakeXMLRoot = nullptr;
1359 }
1360 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001361 } else {
Dan Sinclair93bfc262017-04-04 15:10:00 -04001362 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1363 while (pChild) {
1364 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1365 pFakeRoot->RemoveChild(pChild);
1366 InsertChild(pChild);
1367 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
1368 pChild = pItem;
1369 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001370 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001371 if (pFakeXMLRoot) {
1372 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot.release());
1373 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
1374 }
1375 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001376}
weili44f8faf2016-06-01 14:03:56 -07001377
Dan Sinclair1770c022016-03-14 14:14:16 -04001378void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
weili44f8faf2016-06-01 14:03:56 -07001379 // TODO(weili): Check whether we need to implement this, pdfium:501.
Dan Sinclair1770c022016-03-14 14:14:16 -04001380}
1381
1382void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1383 int32_t iLength = pArguments->GetLength();
1384 if (iLength < 0 || iLength > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001385 ThrowParamCountMismatchException(L"saveXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001386 return;
1387 }
weili44f8faf2016-06-01 14:03:56 -07001388 bool bPrettyMode = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001389 if (iLength == 1) {
weili65be4b12016-05-25 15:47:43 -07001390 if (pArguments->GetUTF8String(0) != "pretty") {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001391 ThrowArgumentMismatchException();
Dan Sinclair1770c022016-03-14 14:14:16 -04001392 return;
1393 }
weili44f8faf2016-06-01 14:03:56 -07001394 bPrettyMode = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001395 }
Dan Sinclair5ae87922017-04-18 11:54:04 -04001396 CFX_WideString bsXMLHeader = L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
weili65be4b12016-05-25 15:47:43 -07001397 if (GetPacketID() == XFA_XDPPACKET_Form ||
1398 GetPacketID() == XFA_XDPPACKET_Datasets) {
1399 CFDE_XMLNode* pElement = nullptr;
1400 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1401 pElement = GetXMLMappingNode();
1402 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
Dan Sinclair5ae87922017-04-18 11:54:04 -04001403 pArguments->GetReturnValue()->SetString(
1404 bsXMLHeader.UTF8Encode().AsStringC());
weili65be4b12016-05-25 15:47:43 -07001405 return;
1406 }
1407 XFA_DataExporter_DealWithDataGroupNode(this);
1408 }
tsepez833619b2016-12-07 09:21:17 -08001409 CFX_RetainPtr<IFX_MemoryStream> pMemoryStream =
1410 IFX_MemoryStream::Create(true);
Dan Sinclaird7120ee2017-04-11 09:03:14 -04001411 CFX_RetainPtr<IFGAS_Stream> pStream =
1412 IFGAS_Stream::CreateWriteStream(pMemoryStream);
tsepez833619b2016-12-07 09:21:17 -08001413
Dan Sinclair1770c022016-03-14 14:14:16 -04001414 if (!pStream) {
Dan Sinclair5ae87922017-04-18 11:54:04 -04001415 pArguments->GetReturnValue()->SetString(
1416 bsXMLHeader.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001417 return;
1418 }
1419 pStream->SetCodePage(FX_CODEPAGE_UTF8);
Dan Sinclair5ae87922017-04-18 11:54:04 -04001420 pStream->WriteString(bsXMLHeader.AsStringC());
1421
weili65be4b12016-05-25 15:47:43 -07001422 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepez7cda31a2016-12-07 12:10:20 -08001423 XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001424 else
tsepez7cda31a2016-12-07 12:10:20 -08001425 pElement->SaveXMLNode(pStream);
weili65be4b12016-05-25 15:47:43 -07001426 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1427 // For now, just put it here to avoid unused variable warning.
1428 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001429 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001430 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001431 return;
1432 }
dsinclairf27aeec2016-06-07 19:36:18 -07001433 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001434}
1435
1436void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1437 int32_t iLength = pArguments->GetLength();
1438 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001439 ThrowParamCountMismatchException(L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001440 return;
1441 }
tsepez6fe7d212016-04-06 10:51:14 -07001442 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001443 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001444 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001445 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001446 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001447}
weili60607c32016-05-26 11:53:12 -07001448
Dan Sinclair1770c022016-03-14 14:14:16 -04001449void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1450 int32_t iLength = pArguments->GetLength();
1451 if (iLength != 1 && iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001452 ThrowParamCountMismatchException(L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001453 return;
1454 }
weili60607c32016-05-26 11:53:12 -07001455 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001456 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001457 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1458 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001459 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001460 // TODO(weili): check whether we need to implement this, pdfium:501.
1461 // For now, just put the variables here to avoid unused variable warning.
1462 (void)pNode;
1463 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001464}
weili60607c32016-05-26 11:53:12 -07001465
dsinclair12a6b0c2016-05-26 11:14:08 -07001466void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001467 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001468 XFA_ATTRIBUTE eAttribute) {
1469 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001470 ThrowInvalidPropertyException();
1471 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001472 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001473
1474 CFX_WideString wsNameSpace;
1475 TryNamespace(wsNameSpace);
Tom Sepezf0b65542017-02-13 10:26:01 -08001476 pValue->SetString(wsNameSpace.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001477}
weili44f8faf2016-06-01 14:03:56 -07001478
dsinclair12a6b0c2016-05-26 11:14:08 -07001479void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001480 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001481 XFA_ATTRIBUTE eAttribute) {
1482 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001483 ThrowInvalidPropertyException();
1484 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001485 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001486 pValue->Assign(
1487 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001488}
weili44f8faf2016-06-01 14:03:56 -07001489
dsinclair12a6b0c2016-05-26 11:14:08 -07001490void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001491 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001492 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001493 if (bSetting) {
1494 ThrowInvalidPropertyException();
1495 return;
1496 }
1497 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001498}
weili44f8faf2016-06-01 14:03:56 -07001499
dsinclair12a6b0c2016-05-26 11:14:08 -07001500void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001501 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001502 XFA_ATTRIBUTE eAttribute) {
1503 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001504 ThrowInvalidPropertyException();
1505 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001506 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001507 if (GetElementType() == XFA_Element::Subform) {
1508 pValue->SetBoolean(false);
1509 return;
1510 }
1511 CFX_WideString strValue;
1512 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001513}
weili44f8faf2016-06-01 14:03:56 -07001514
dsinclair12a6b0c2016-05-26 11:14:08 -07001515void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001516 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001517 XFA_ATTRIBUTE eAttribute) {
1518 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001519 ThrowInvalidPropertyException();
1520 return;
1521 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001522 std::vector<CXFA_Node*> properties =
1523 GetNodeList(XFA_NODEFILTER_OneOfProperty);
1524 if (!properties.empty()) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001525 pValue->Assign(
Tom Sepezf8a94392017-03-14 12:13:22 -07001526 m_pDocument->GetScriptContext()->GetJSValueFromMap(properties.front()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001527 }
1528}
weili44f8faf2016-06-01 14:03:56 -07001529
Dan Sinclair1770c022016-03-14 14:14:16 -04001530void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001531
Dan Sinclair1770c022016-03-14 14:14:16 -04001532void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1533 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001534 pArguments->GetReturnValue()->SetObject(
1535 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001536}
1537void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1538}
dsinclair5b36f0a2016-07-19 10:56:23 -07001539
Dan Sinclair1770c022016-03-14 14:14:16 -04001540void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1541 Script_Template_CreateNode(pArguments);
1542}
dsinclair5b36f0a2016-07-19 10:56:23 -07001543
Dan Sinclair1770c022016-03-14 14:14:16 -04001544void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1545 int32_t iLength = pArguments->GetLength();
1546 if (iLength < 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001547 ThrowParamCountMismatchException(L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001548 return;
1549 }
1550 CFX_WideString wsNameSpace;
1551 if (iLength >= 1) {
1552 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001553 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001554 }
1555 CFX_WideString wsNodeNameSpace;
1556 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001557 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001558 if (pValue)
1559 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001560}
dsinclair5b36f0a2016-07-19 10:56:23 -07001561
dsinclair12a6b0c2016-05-26 11:14:08 -07001562void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001563 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001564 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001565
dsinclair12a6b0c2016-05-26 11:14:08 -07001566void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001567 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001568 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001569
dsinclair12a6b0c2016-05-26 11:14:08 -07001570void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001571 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001572 XFA_ATTRIBUTE eAttribute) {
1573 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001574 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001575 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001576 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001577 }
1578}
dsinclair5b36f0a2016-07-19 10:56:23 -07001579
dsinclair12a6b0c2016-05-26 11:14:08 -07001580void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001581 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001582 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001583 if (bSetting) {
1584 ThrowInvalidPropertyException();
1585 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001586 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001587 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001588}
dsinclair5b36f0a2016-07-19 10:56:23 -07001589
dsinclair12a6b0c2016-05-26 11:14:08 -07001590void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001591 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001592 XFA_ATTRIBUTE eAttribute) {
1593 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001594 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001595 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001596 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001597 }
1598}
dsinclair5b36f0a2016-07-19 10:56:23 -07001599
dsinclair12a6b0c2016-05-26 11:14:08 -07001600void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001601 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001602 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001603 if (bSetting) {
1604 ThrowInvalidPropertyException();
1605 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001606 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001607 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001608}
thestigb1a59592016-04-14 18:29:56 -07001609
Dan Sinclair1770c022016-03-14 14:14:16 -04001610void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001611 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001612 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001613 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001614 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001615 return;
thestigb1a59592016-04-14 18:29:56 -07001616
dsinclaira1b07722016-07-11 08:20:58 -07001617 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001618 if (!pNotify)
1619 return;
1620
1621 uint32_t dwPacket = GetPacketID();
1622 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1623 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001624 return;
1625 }
thestigb1a59592016-04-14 18:29:56 -07001626
1627 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001628 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001629 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001630 bNeedFindContainer = true;
1631 pNotify->OnValueChanged(this, eAttribute, this,
1632 GetNodeItem(XFA_NODEITEM_Parent));
1633 break;
dsinclair56a8b192016-06-21 14:15:25 -07001634 case XFA_Element::Font:
1635 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001636 bNeedFindContainer = true;
1637 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001638 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001639 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1640 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1641 } else {
1642 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1643 }
1644 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001645 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001646 bNeedFindContainer = true;
1647 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001648 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001649 if (pParentNode->IsContainerNode()) {
1650 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001651 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001652 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1653 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1654 } else {
1655 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001656 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001657 pNotify->OnValueChanged(this, eAttribute, pNode,
1658 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001659 }
thestigb1a59592016-04-14 18:29:56 -07001660 }
1661 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001662 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001663 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001664 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001665 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1666 eUIType == XFA_Element::NumericEdit ||
1667 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001668 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001669 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001670 pNotify->OnValueChanged(this, eAttribute, pUINode,
1671 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001672 }
thestigb1a59592016-04-14 18:29:56 -07001673 }
1674 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001675 case XFA_Element::Button:
1676 case XFA_Element::Barcode:
1677 case XFA_Element::ChoiceList:
1678 case XFA_Element::DateTimeEdit:
1679 case XFA_Element::NumericEdit:
1680 case XFA_Element::PasswordEdit:
1681 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001682 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1683 if (pUINode) {
1684 pNotify->OnValueChanged(this, eAttribute, pUINode,
1685 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1686 }
1687 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001688 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001689 bNeedFindContainer = true;
1690 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1691 if (pUINode) {
1692 pNotify->OnValueChanged(this, eAttribute, pUINode,
1693 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1694 }
1695 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001696 case XFA_Element::Keep:
1697 case XFA_Element::Bookend:
1698 case XFA_Element::Break:
1699 case XFA_Element::BreakAfter:
1700 case XFA_Element::BreakBefore:
1701 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001702 bNeedFindContainer = true;
1703 break;
dsinclair56a8b192016-06-21 14:15:25 -07001704 case XFA_Element::Area:
1705 case XFA_Element::Draw:
1706 case XFA_Element::ExclGroup:
1707 case XFA_Element::Field:
1708 case XFA_Element::Subform:
1709 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001710 pLayoutPro->AddChangedContainer(this);
1711 pNotify->OnValueChanged(this, eAttribute, this, this);
1712 break;
dsinclair56a8b192016-06-21 14:15:25 -07001713 case XFA_Element::Sharptext:
1714 case XFA_Element::Sharpxml:
1715 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001716 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1717 if (!pTextNode) {
1718 return;
1719 }
1720 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1721 if (!pValueNode) {
1722 return;
1723 }
dsinclair41cb62e2016-06-23 09:20:32 -07001724 XFA_Element eType = pValueNode->GetElementType();
1725 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001726 bNeedFindContainer = true;
1727 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1728 if (pNode && pNode->IsContainerNode()) {
1729 if (bScriptModify) {
1730 pValueNode = pNode;
1731 }
1732 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1733 } else {
1734 pNotify->OnValueChanged(this, eAttribute, pNode,
1735 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001736 }
thestigb1a59592016-04-14 18:29:56 -07001737 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001738 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001739 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1740 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001741 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001742 }
1743 }
thestigb1a59592016-04-14 18:29:56 -07001744 }
1745 } break;
1746 default:
1747 break;
1748 }
1749 if (bNeedFindContainer) {
1750 CXFA_Node* pParent = this;
1751 while (pParent) {
1752 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001753 break;
thestigb1a59592016-04-14 18:29:56 -07001754
1755 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001756 }
thestigb1a59592016-04-14 18:29:56 -07001757 if (pParent) {
1758 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001759 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001760 }
1761}
thestigb1a59592016-04-14 18:29:56 -07001762
dsinclair12a6b0c2016-05-26 11:14:08 -07001763void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001764 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001765 XFA_ATTRIBUTE eAttribute) {
1766 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001767 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001768 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001769 if (eAttribute == XFA_ATTRIBUTE_Use &&
1770 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001771 CXFA_Node* pTemplateNode =
1772 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1773 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001774 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1775 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001776
1777 CFX_WideString wsID;
1778 CFX_WideString wsSOM;
1779 if (!wsValue.IsEmpty()) {
1780 if (wsValue[0] == '#') {
1781 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001782 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001783 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001784 }
1785 }
weili44f8faf2016-06-01 14:03:56 -07001786 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001787 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001788 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001789 XFA_RESOLVENODE_Attributes |
1790 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1791 XFA_RESOLVENODE_Siblings;
1792 XFA_RESOLVENODE_RS resoveNodeRS;
1793 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001794 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Tom Sepezf8a94392017-03-14 12:13:22 -07001795 if (iRet > 0 && resoveNodeRS.objects.front()->IsNode()) {
1796 pProtoNode = resoveNodeRS.objects.front()->AsNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001797 }
1798 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001799 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001800 }
1801 if (pProtoNode) {
1802 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1803 while (pHeadChild) {
1804 CXFA_Node* pSibling =
1805 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1806 RemoveChild(pHeadChild);
1807 pHeadChild = pSibling;
1808 }
tsepezd19e9122016-11-02 15:43:18 -07001809 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001810 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1811 while (pHeadChild) {
1812 CXFA_Node* pSibling =
1813 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1814 pProtoForm->RemoveChild(pHeadChild);
1815 InsertChild(pHeadChild);
1816 pHeadChild = pSibling;
1817 }
1818 m_pDocument->RemovePurgeNode(pProtoForm);
1819 delete pProtoForm;
1820 }
1821 }
1822 } else {
1823 CFX_WideString wsValue;
1824 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001825 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001826 }
1827}
dsinclair5b36f0a2016-07-19 10:56:23 -07001828
dsinclair12a6b0c2016-05-26 11:14:08 -07001829void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001830 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001831 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001832 if (bSetting) {
1833 ThrowInvalidPropertyException();
1834 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001835 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001836
1837 CFX_WideString wsValue;
1838 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001839 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001840}
dsinclair5b36f0a2016-07-19 10:56:23 -07001841
Dan Sinclair1770c022016-03-14 14:14:16 -04001842void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1843 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001844 if (argc != 0 && argc != 1) {
1845 ThrowParamCountMismatchException(L"execute");
1846 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001847 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001848 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001849}
dsinclair5b36f0a2016-07-19 10:56:23 -07001850
Dan Sinclair1770c022016-03-14 14:14:16 -04001851void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001852 if (pArguments->GetLength() != 0)
1853 ThrowParamCountMismatchException(L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001854}
dsinclair5b36f0a2016-07-19 10:56:23 -07001855
dsinclair12a6b0c2016-05-26 11:14:08 -07001856void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001857 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001858 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001859
dsinclair12a6b0c2016-05-26 11:14:08 -07001860void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001861 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001862 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001863
dsinclair12a6b0c2016-05-26 11:14:08 -07001864void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001865 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001866 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001867
dsinclair12a6b0c2016-05-26 11:14:08 -07001868void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001869 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001870 XFA_SOM_MESSAGETYPE iMessageType) {
1871 CXFA_WidgetData* pWidgetData = GetWidgetData();
1872 if (!pWidgetData) {
1873 return;
1874 }
tsepezd19e9122016-11-02 15:43:18 -07001875 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001876 CXFA_Validate validate = pWidgetData->GetValidate();
1877 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001878 validate = pWidgetData->GetValidate(true);
1879 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001880 }
1881 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001882 switch (iMessageType) {
1883 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001884 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001885 break;
1886 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001887 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001888 break;
1889 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001890 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001891 break;
1892 default:
1893 break;
1894 }
1895 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001896 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001897 if (!pNotify) {
1898 return;
1899 }
1900 pNotify->AddCalcValidate(this);
1901 }
1902 } else {
1903 CFX_WideString wsMessage;
1904 switch (iMessageType) {
1905 case XFA_SOM_ValidationMessage:
1906 validate.GetScriptMessageText(wsMessage);
1907 break;
1908 case XFA_SOM_FormatMessage:
1909 validate.GetFormatMessageText(wsMessage);
1910 break;
1911 case XFA_SOM_MandatoryMessage:
1912 validate.GetNullMessageText(wsMessage);
1913 break;
1914 default:
1915 break;
1916 }
Tom Sepezf0b65542017-02-13 10:26:01 -08001917 pValue->SetString(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001918 }
1919}
dsinclair5b36f0a2016-07-19 10:56:23 -07001920
dsinclair12a6b0c2016-05-26 11:14:08 -07001921void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001922 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001923 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001924 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001925}
dsinclair5b36f0a2016-07-19 10:56:23 -07001926
dsinclair12a6b0c2016-05-26 11:14:08 -07001927void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001928 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001929 XFA_ATTRIBUTE eAttribute) {
1930 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001931 ThrowInvalidPropertyException();
1932 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001933 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001934
1935 CXFA_WidgetData* pWidgetData = GetWidgetData();
1936 if (!pWidgetData) {
1937 pValue->SetInteger(0);
1938 return;
1939 }
1940 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001941}
dsinclair5b36f0a2016-07-19 10:56:23 -07001942
dsinclair12a6b0c2016-05-26 11:14:08 -07001943void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001944 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001945 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001946 XFA_Element eType = GetElementType();
1947 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001948 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001949 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001950 }
1951 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001952 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001953 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001954 }
1955 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001956 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001957 return;
1958 }
1959 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001960 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07001961 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07001962 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07001963
Dan Sinclair1770c022016-03-14 14:14:16 -04001964 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07001965 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001966 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001967 CFX_WideString wsPicture;
Tom Sepezf8a94392017-03-14 12:13:22 -07001968 for (CXFA_Node* pFormNode : GetBindItems()) {
1969 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -04001970 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001971 pContainerWidgetData = pFormNode->GetContainerWidgetData();
1972 if (pContainerWidgetData) {
1973 pContainerWidgetData->GetPictureContent(wsPicture,
1974 XFA_VALUEPICTURE_DataBind);
1975 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001976 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -04001977 break;
weili44f8faf2016-06-01 14:03:56 -07001978 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001979 }
1980 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
1981 pContainerWidgetData = GetContainerWidgetData();
1982 }
1983 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07001984 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04001985 }
tsepezd19e9122016-11-02 15:43:18 -07001986 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001987 } else {
tsepezd19e9122016-11-02 15:43:18 -07001988 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07001989 if (content.IsEmpty() && eType != XFA_Element::Text &&
1990 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07001991 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07001992 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07001993 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07001994 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07001995 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04001996 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04001997 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08001998 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001999 }
2000 }
2001}
dsinclair5b36f0a2016-07-19 10:56:23 -07002002
dsinclair12a6b0c2016-05-26 11:14:08 -07002003void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002004 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002005 XFA_ATTRIBUTE eAttribute) {
2006 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002007 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002008 return;
2009 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002010
tsepezd19e9122016-11-02 15:43:18 -07002011 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002012 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002013 pValue->SetNull();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002014 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002015 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002016 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002017}
dsinclair5b36f0a2016-07-19 10:56:23 -07002018
dsinclair12a6b0c2016-05-26 11:14:08 -07002019void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002020 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002021 XFA_ATTRIBUTE eAttribute) {
2022 if (bSetting) {
2023 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002024 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002025 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002026
tsepezb4c9f3f2016-04-13 15:41:21 -07002027 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002028 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002029 CFX_WideString wsFormatValue(wsNewValue);
2030 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2031 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002032 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002033 }
tsepezd19e9122016-11-02 15:43:18 -07002034 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002035 } else {
tsepezd19e9122016-11-02 15:43:18 -07002036 CFX_WideString wsValue = GetScriptContent(true);
dan sinclair65c7c232017-02-02 14:05:30 -08002037 pValue->SetBoolean(wsValue == L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002038 }
2039}
dsinclair2f5582f2016-06-09 11:48:23 -07002040
dsinclair12a6b0c2016-05-26 11:14:08 -07002041void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002042 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002043 XFA_ATTRIBUTE eAttribute) {
2044 CXFA_WidgetData* pWidgetData = GetWidgetData();
2045 if (!pWidgetData) {
2046 return;
2047 }
tsepezd19e9122016-11-02 15:43:18 -07002048 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002049 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002050 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002051 int32_t r = 0;
2052 int32_t g = 0;
2053 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002054 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002055 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2056 for (int32_t i = 0; i < iSize; ++i) {
2057 CXFA_Edge edge = border.GetEdge(i);
2058 edge.SetColor(rgb);
2059 }
2060 } else {
2061 CXFA_Edge edge = border.GetEdge(0);
2062 FX_ARGB color = edge.GetColor();
2063 int32_t a, r, g, b;
2064 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002065 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002066 strColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002067 pValue->SetString(strColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002068 }
2069}
dsinclair5b36f0a2016-07-19 10:56:23 -07002070
dsinclair12a6b0c2016-05-26 11:14:08 -07002071void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002072 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002073 XFA_ATTRIBUTE eAttribute) {
2074 CXFA_WidgetData* pWidgetData = GetWidgetData();
2075 if (!pWidgetData) {
2076 return;
2077 }
tsepezd19e9122016-11-02 15:43:18 -07002078 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002079 int32_t iSize = border.CountEdges();
2080 CFX_WideString wsThickness;
2081 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002082 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002083 for (int32_t i = 0; i < iSize; ++i) {
2084 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002085 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002086 edge.SetMSThickness(thickness);
2087 }
2088 } else {
2089 CXFA_Edge edge = border.GetEdge(0);
2090 CXFA_Measurement thickness = edge.GetMSThickness();
2091 thickness.ToString(wsThickness);
Tom Sepezf0b65542017-02-13 10:26:01 -08002092 pValue->SetString(wsThickness.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002093 }
2094}
dsinclair5b36f0a2016-07-19 10:56:23 -07002095
dsinclair12a6b0c2016-05-26 11:14:08 -07002096void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002097 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002098 XFA_ATTRIBUTE eAttribute) {
2099 CXFA_WidgetData* pWidgetData = GetWidgetData();
2100 if (!pWidgetData) {
2101 return;
2102 }
tsepezd19e9122016-11-02 15:43:18 -07002103 CXFA_Border border = pWidgetData->GetBorder(true);
2104 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002105 CXFA_Node* pNode = borderfill.GetNode();
2106 if (!pNode) {
2107 return;
2108 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002109 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002110 int32_t r;
2111 int32_t g;
2112 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002113 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002114 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2115 borderfill.SetColor(color);
2116 } else {
2117 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002118 int32_t a;
2119 int32_t r;
2120 int32_t g;
2121 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002122 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002123 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002124 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002125 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002126 }
2127}
dsinclair5b36f0a2016-07-19 10:56:23 -07002128
dsinclair12a6b0c2016-05-26 11:14:08 -07002129void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002130 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002131 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002132 if (bSetting) {
2133 ThrowInvalidPropertyException();
2134 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002135 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002136
2137 CXFA_Node* pDataNode = GetBindData();
2138 if (!pDataNode) {
2139 pValue->SetNull();
2140 return;
2141 }
2142
2143 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002144}
dsinclair5b36f0a2016-07-19 10:56:23 -07002145
dsinclair12a6b0c2016-05-26 11:14:08 -07002146void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002147 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002148 XFA_ATTRIBUTE eAttribute) {
2149 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002150 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002151 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002152 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002153 XFA_Element uiType = pWidgetData->GetUIType();
2154 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002155 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002156 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002157 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002158 }
2159 }
2160 } else {
tsepezd19e9122016-11-02 15:43:18 -07002161 CFX_WideString content = GetScriptContent(true);
Tom Sepezf0b65542017-02-13 10:26:01 -08002162 if (content.IsEmpty())
dsinclairf27aeec2016-06-07 19:36:18 -07002163 pValue->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002164 else
2165 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002166 }
2167}
dsinclair5b36f0a2016-07-19 10:56:23 -07002168
dsinclair12a6b0c2016-05-26 11:14:08 -07002169void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002170 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002171 XFA_ATTRIBUTE eAttribute) {
2172 CXFA_WidgetData* pWidgetData = GetWidgetData();
2173 if (!pWidgetData) {
2174 return;
2175 }
2176 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002177 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002178 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002179 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002180 } else {
2181 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002182 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002183 }
dsinclair2f5582f2016-06-09 11:48:23 -07002184 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002185 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002186 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002187
Dan Sinclair1770c022016-03-14 14:14:16 -04002188 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002189 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002190 int32_t iLeadDigits = 0;
2191 int32_t iFracDigits = 0;
2192 pWidgetData->GetLeadDigits(iLeadDigits);
2193 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002194 wsNewText =
2195 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002196 }
2197 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2198 CFX_WideString wsFormatText(wsNewText);
2199 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002200 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002201 }
tsepezd19e9122016-11-02 15:43:18 -07002202 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002203 } else {
tsepezd19e9122016-11-02 15:43:18 -07002204 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002205 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002206 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002207 } else {
2208 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002209 CXFA_Value defVal = pWidgetData->GetFormValue();
2210 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002211 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002212 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002213 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
Tom Sepezf0b65542017-02-13 10:26:01 -08002214 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002215 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002216 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002217 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002218 }
dsinclair070fcdf2016-06-22 22:04:54 -07002219 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002220 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002221 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002222 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002223 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002224 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002225 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002226 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002227 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002228 }
2229 }
2230 }
2231}
dsinclair5b36f0a2016-07-19 10:56:23 -07002232
dsinclair12a6b0c2016-05-26 11:14:08 -07002233void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002234 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002235 XFA_ATTRIBUTE eAttribute) {
2236 CXFA_WidgetData* pWidgetData = GetWidgetData();
2237 if (!pWidgetData) {
2238 return;
2239 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002240 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002241 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002242 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002243 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002244 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
Tom Sepezf0b65542017-02-13 10:26:01 -08002245 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002246 }
2247}
dsinclair5b36f0a2016-07-19 10:56:23 -07002248
dsinclair12a6b0c2016-05-26 11:14:08 -07002249void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002250 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002251 XFA_ATTRIBUTE eAttribute) {
2252 CXFA_WidgetData* pWidgetData = GetWidgetData();
2253 if (!pWidgetData) {
2254 return;
2255 }
tsepezd19e9122016-11-02 15:43:18 -07002256 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002257 CXFA_Node* pNode = font.GetNode();
2258 if (!pNode) {
2259 return;
2260 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002261 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002262 int32_t r;
2263 int32_t g;
2264 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002265 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002266 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2267 font.SetColor(color);
2268 } else {
2269 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002270 int32_t a;
2271 int32_t r;
2272 int32_t g;
2273 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002274 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002275 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002276 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002277 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002278 }
2279}
dsinclair5b36f0a2016-07-19 10:56:23 -07002280
dsinclair12a6b0c2016-05-26 11:14:08 -07002281void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002282 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002283 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002284 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002285}
dsinclair5b36f0a2016-07-19 10:56:23 -07002286
dsinclair12a6b0c2016-05-26 11:14:08 -07002287void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002288 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002289 XFA_ATTRIBUTE eAttribute) {
2290 CXFA_WidgetData* pWidgetData = GetWidgetData();
2291 if (!pWidgetData) {
2292 return;
2293 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002294 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002295 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002296 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002297 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002298 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
Tom Sepezf0b65542017-02-13 10:26:01 -08002299 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002300 }
2301}
dsinclair5b36f0a2016-07-19 10:56:23 -07002302
dsinclair12a6b0c2016-05-26 11:14:08 -07002303void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002304 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002305 XFA_ATTRIBUTE eAttribute) {
2306 CXFA_WidgetData* pWidgetData = GetWidgetData();
2307 if (!pWidgetData) {
2308 return;
2309 }
tsepezd19e9122016-11-02 15:43:18 -07002310 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002311 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002312 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002313 } else {
2314 int32_t iValue = validate.GetNullTest();
2315 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002316 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002317 CFX_WideString wsValue;
2318 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002319 wsValue = pInfo->pName;
Tom Sepezf0b65542017-02-13 10:26:01 -08002320 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002321 }
2322}
dsinclair5b36f0a2016-07-19 10:56:23 -07002323
dsinclair12a6b0c2016-05-26 11:14:08 -07002324void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002325 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002326 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002327 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002328}
dsinclair5b36f0a2016-07-19 10:56:23 -07002329
dsinclair12a6b0c2016-05-26 11:14:08 -07002330void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002331 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002332 XFA_ATTRIBUTE eAttribute) {
2333 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002334 ThrowInvalidPropertyException();
2335 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002336 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002337 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002338}
dsinclair5b36f0a2016-07-19 10:56:23 -07002339
dsinclair12a6b0c2016-05-26 11:14:08 -07002340void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002341 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002342 XFA_ATTRIBUTE eAttribute) {
2343 CXFA_WidgetData* pWidgetData = GetWidgetData();
2344 if (!pWidgetData) {
2345 return;
2346 }
2347 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002348 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002349 if (iIndex == -1) {
2350 pWidgetData->ClearAllSelections();
2351 return;
2352 }
tsepezd19e9122016-11-02 15:43:18 -07002353 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002354 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002355 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002356 }
2357}
dsinclair5b36f0a2016-07-19 10:56:23 -07002358
Dan Sinclair1770c022016-03-14 14:14:16 -04002359void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2360 CXFA_WidgetData* pWidgetData = GetWidgetData();
2361 if (!pWidgetData) {
2362 return;
2363 }
tsepezd19e9122016-11-02 15:43:18 -07002364 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002365}
dsinclair5b36f0a2016-07-19 10:56:23 -07002366
Dan Sinclair1770c022016-03-14 14:14:16 -04002367void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002368 if (pArguments->GetLength() != 1) {
2369 ThrowParamCountMismatchException(L"execEvent");
2370 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002371 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002372
2373 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2374 int32_t iRet = execSingleEventByName(
2375 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2376 XFA_Element::Field);
2377 if (eventString != "validate")
2378 return;
2379
2380 pArguments->GetReturnValue()->SetBoolean(
2381 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002382}
dsinclair5b36f0a2016-07-19 10:56:23 -07002383
Dan Sinclair1770c022016-03-14 14:14:16 -04002384void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002385 if (pArguments->GetLength() != 0) {
2386 ThrowParamCountMismatchException(L"execInitialize");
2387 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002388 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002389
2390 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2391 if (!pNotify)
2392 return;
2393
2394 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002395}
dsinclair5b36f0a2016-07-19 10:56:23 -07002396
Dan Sinclair1770c022016-03-14 14:14:16 -04002397void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2398 int32_t iLength = pArguments->GetLength();
2399 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002400 ThrowParamCountMismatchException(L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002401 return;
2402 }
2403 CXFA_WidgetData* pWidgetData = GetWidgetData();
2404 if (!pWidgetData) {
2405 return;
2406 }
2407 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002408 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002409 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002410 if (pValue)
2411 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002412}
dsinclair5b36f0a2016-07-19 10:56:23 -07002413
Dan Sinclair1770c022016-03-14 14:14:16 -04002414void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2415 int32_t iLength = pArguments->GetLength();
2416 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002417 ThrowParamCountMismatchException(L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002418 return;
2419 }
2420 int32_t iIndex = pArguments->GetInt32(0);
2421 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002422 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002423 return;
2424 }
2425 CXFA_WidgetData* pWidgetData = GetWidgetData();
2426 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002427 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002428 return;
2429 }
2430 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002431 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002432 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002433 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002434 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002435 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002436}
dsinclair5b36f0a2016-07-19 10:56:23 -07002437
Dan Sinclair1770c022016-03-14 14:14:16 -04002438void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2439 int32_t iLength = pArguments->GetLength();
2440 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002441 ThrowParamCountMismatchException(L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002442 return;
2443 }
2444 CXFA_WidgetData* pWidgetData = GetWidgetData();
2445 if (!pWidgetData) {
2446 return;
2447 }
2448 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002449 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002450 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002451 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002452 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002453 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08002454 pValue->SetString(wsBoundValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002455}
dsinclair5b36f0a2016-07-19 10:56:23 -07002456
Dan Sinclair1770c022016-03-14 14:14:16 -04002457void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2458 int32_t iLength = pArguments->GetLength();
2459 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002460 ThrowParamCountMismatchException(L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002461 return;
2462 }
2463 CXFA_WidgetData* pWidgetData = GetWidgetData();
2464 if (!pWidgetData) {
2465 return;
2466 }
2467 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002468 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002469 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002470 if (pValue)
2471 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002472}
dsinclair5b36f0a2016-07-19 10:56:23 -07002473
Dan Sinclair1770c022016-03-14 14:14:16 -04002474void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002475 if (pArguments->GetLength() != 0) {
2476 ThrowParamCountMismatchException(L"execCalculate");
2477 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002478 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002479
2480 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2481 if (!pNotify)
2482 return;
2483
2484 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002485}
dsinclair5b36f0a2016-07-19 10:56:23 -07002486
Dan Sinclair1770c022016-03-14 14:14:16 -04002487void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002488
Dan Sinclair1770c022016-03-14 14:14:16 -04002489void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2490 int32_t iLength = pArguments->GetLength();
2491 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002492 ThrowParamCountMismatchException(L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002493 return;
2494 }
2495 int32_t iIndex = pArguments->GetInt32(0);
2496 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002497 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002498 return;
2499 }
2500 CXFA_WidgetData* pWidgetData = GetWidgetData();
2501 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002502 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002503 return;
2504 }
2505 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002506 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002507 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002508 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002509 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002510 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002511}
dsinclair5b36f0a2016-07-19 10:56:23 -07002512
Dan Sinclair1770c022016-03-14 14:14:16 -04002513void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2514 int32_t iLength = pArguments->GetLength();
2515 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002516 ThrowParamCountMismatchException(L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002517 return;
2518 }
2519 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002520 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002521 return;
thestig800222e2016-05-26 22:00:29 -07002522
Dan Sinclair1770c022016-03-14 14:14:16 -04002523 int32_t iIndex = pArguments->GetInt32(0);
2524 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002525 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002526 } else {
thestig800222e2016-05-26 22:00:29 -07002527 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002528 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002529 }
2530}
dsinclair5b36f0a2016-07-19 10:56:23 -07002531
Dan Sinclair1770c022016-03-14 14:14:16 -04002532void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2533 int32_t iLength = pArguments->GetLength();
2534 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002535 ThrowParamCountMismatchException(L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002536 return;
2537 }
2538 CXFA_WidgetData* pWidgetData = GetWidgetData();
2539 if (!pWidgetData) {
2540 return;
2541 }
2542 CFX_WideString wsLabel;
2543 CFX_WideString wsValue;
2544 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002545 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002546 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002547 }
2548 if (iLength >= 2) {
2549 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002550 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002551 }
tsepezd19e9122016-11-02 15:43:18 -07002552 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002553}
dsinclair5b36f0a2016-07-19 10:56:23 -07002554
Dan Sinclair1770c022016-03-14 14:14:16 -04002555void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002556 if (pArguments->GetLength() != 0) {
2557 ThrowParamCountMismatchException(L"execValidate");
2558 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002559 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002560
2561 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2562 if (!pNotify) {
2563 pArguments->GetReturnValue()->SetBoolean(false);
2564 return;
2565 }
2566
2567 int32_t iRet =
2568 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
2569 pArguments->GetReturnValue()->SetBoolean(
2570 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002571}
dsinclair5b36f0a2016-07-19 10:56:23 -07002572
dsinclair12a6b0c2016-05-26 11:14:08 -07002573void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002574 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002575 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002576 if (bSetting)
2577 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002578}
dsinclair5b36f0a2016-07-19 10:56:23 -07002579
dsinclair12a6b0c2016-05-26 11:14:08 -07002580void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002581 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002582 XFA_ATTRIBUTE eAttribute) {
2583 CXFA_WidgetData* pWidgetData = GetWidgetData();
2584 if (!pWidgetData) {
2585 return;
2586 }
2587 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002588 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002589 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002590 } else {
tsepezd19e9122016-11-02 15:43:18 -07002591 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002592 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2593 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002594 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002595 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002596 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002597 }
2598 }
2599}
dsinclair5b36f0a2016-07-19 10:56:23 -07002600
dsinclair12a6b0c2016-05-26 11:14:08 -07002601void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002602 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002603 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002604
Dan Sinclair1770c022016-03-14 14:14:16 -04002605void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002606 if (pArguments->GetLength() != 1) {
2607 ThrowParamCountMismatchException(L"execEvent");
2608 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002609 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002610
2611 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2612 execSingleEventByName(
2613 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2614 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002615}
thestig800222e2016-05-26 22:00:29 -07002616
Dan Sinclair1770c022016-03-14 14:14:16 -04002617void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2618 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002619 if (argc < 0 || argc > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002620 ThrowParamCountMismatchException(L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002621 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002622 }
thestig800222e2016-05-26 22:00:29 -07002623
2624 CXFA_WidgetData* pWidgetData = GetWidgetData();
2625 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002626 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002627 return;
2628 }
2629
2630 CXFA_Node* pReturnNode = nullptr;
2631 if (argc == 0) {
2632 pReturnNode = pWidgetData->GetSelectedMember();
2633 } else {
2634 CFX_ByteString szName;
2635 szName = pArguments->GetUTF8String(0);
2636 pReturnNode = pWidgetData->SetSelectedMember(
2637 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2638 }
2639 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002640 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002641 return;
2642 }
dsinclairf27aeec2016-06-07 19:36:18 -07002643 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002644 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002645}
thestig800222e2016-05-26 22:00:29 -07002646
Dan Sinclair1770c022016-03-14 14:14:16 -04002647void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002648 if (pArguments->GetLength() != 0) {
2649 ThrowParamCountMismatchException(L"execInitialize");
2650 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002651 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002652
2653 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2654 if (!pNotify)
2655 return;
2656
2657 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002658}
dsinclair5b36f0a2016-07-19 10:56:23 -07002659
Dan Sinclair1770c022016-03-14 14:14:16 -04002660void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002661 if (pArguments->GetLength() != 0) {
2662 ThrowParamCountMismatchException(L"execCalculate");
2663 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002664 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002665
2666 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2667 if (!pNotify)
2668 return;
2669
2670 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002671}
dsinclair5b36f0a2016-07-19 10:56:23 -07002672
Dan Sinclair1770c022016-03-14 14:14:16 -04002673void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002674 if (pArguments->GetLength() != 0) {
2675 ThrowParamCountMismatchException(L"execValidate");
2676 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002677 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002678
2679 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2680 if (!pNotify) {
2681 pArguments->GetReturnValue()->SetBoolean(false);
2682 return;
2683 }
2684
2685 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2686 pArguments->GetReturnValue()->SetBoolean(
2687 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002688}
dsinclair5b36f0a2016-07-19 10:56:23 -07002689
dsinclair12a6b0c2016-05-26 11:14:08 -07002690void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002691 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002692 XFA_ATTRIBUTE eAttribute) {
2693 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002694 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002695 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002696 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002697 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2698 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002699 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002700 pManagerNode = pNode;
2701 break;
2702 }
2703 }
2704 if (pManagerNode) {
2705 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002706 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002707 if (!pNotify) {
2708 return;
2709 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002710 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002711 if (pToInstance &&
2712 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002713 pNotify->RunSubformIndexChange(pToInstance);
2714 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002715 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002716 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002717 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002718 pNotify->RunSubformIndexChange(pFromInstance);
2719 }
2720 }
2721 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002722 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002723 }
2724}
dsinclair5b36f0a2016-07-19 10:56:23 -07002725
dsinclair12a6b0c2016-05-26 11:14:08 -07002726void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002727 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002728 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002729 if (bSetting) {
2730 ThrowInvalidPropertyException();
2731 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002732 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002733
2734 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2735 CXFA_Node* pInstanceMgr = nullptr;
2736 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2737 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2738 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2739 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2740 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2741 wsInstMgrName.Mid(1) == wsName) {
2742 pInstanceMgr = pNode;
2743 }
2744 break;
2745 }
2746 }
2747 if (!pInstanceMgr) {
2748 pValue->SetNull();
2749 return;
2750 }
2751
2752 pValue->Assign(
2753 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
Dan Sinclair1770c022016-03-14 14:14:16 -04002754}
dsinclair5b36f0a2016-07-19 10:56:23 -07002755
dsinclair12a6b0c2016-05-26 11:14:08 -07002756void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002757 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002758 XFA_ATTRIBUTE eAttribute) {
2759 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002760 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002761 } else {
2762 CFX_WideString wsLocaleName;
2763 GetLocaleName(wsLocaleName);
Tom Sepezf0b65542017-02-13 10:26:01 -08002764 pValue->SetString(wsLocaleName.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002765 }
2766}
dsinclair5b36f0a2016-07-19 10:56:23 -07002767
Dan Sinclair1770c022016-03-14 14:14:16 -04002768void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002769 if (pArguments->GetLength() != 1) {
2770 ThrowParamCountMismatchException(L"execEvent");
2771 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002772 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002773
2774 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2775 execSingleEventByName(
2776 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2777 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002778}
dsinclair5b36f0a2016-07-19 10:56:23 -07002779
Dan Sinclair1770c022016-03-14 14:14:16 -04002780void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002781 if (pArguments->GetLength() != 0) {
2782 ThrowParamCountMismatchException(L"execInitialize");
2783 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002784 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002785
2786 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2787 if (!pNotify)
2788 return;
2789
2790 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002791}
dsinclair5b36f0a2016-07-19 10:56:23 -07002792
Dan Sinclair1770c022016-03-14 14:14:16 -04002793void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002794 if (pArguments->GetLength() != 0) {
2795 ThrowParamCountMismatchException(L"execCalculate");
2796 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002797 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002798
2799 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2800 if (!pNotify)
2801 return;
2802
2803 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002804}
dsinclair5b36f0a2016-07-19 10:56:23 -07002805
Dan Sinclair1770c022016-03-14 14:14:16 -04002806void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002807 if (pArguments->GetLength() != 0) {
2808 ThrowParamCountMismatchException(L"execValidate");
2809 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002810 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002811
2812 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2813 if (!pNotify) {
2814 pArguments->GetReturnValue()->SetBoolean(false);
2815 return;
2816 }
2817
2818 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2819 pArguments->GetReturnValue()->SetBoolean(
2820 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002821}
dsinclair5b36f0a2016-07-19 10:56:23 -07002822
Dan Sinclair1770c022016-03-14 14:14:16 -04002823void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002824 if (pArguments->GetLength() != 0)
2825 ThrowParamCountMismatchException(L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002826}
dsinclair5b36f0a2016-07-19 10:56:23 -07002827
Dan Sinclair1770c022016-03-14 14:14:16 -04002828int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2829 int32_t index = 0;
2830 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2831 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002832 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2833 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002834 index++;
2835 } else {
2836 break;
2837 }
2838 }
2839 return index;
2840}
dsinclair5b36f0a2016-07-19 10:56:23 -07002841
Dan Sinclair1770c022016-03-14 14:14:16 -04002842void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002843 if (pArguments->GetLength() != 1) {
2844 ThrowParamCountMismatchException(L"formNodes");
2845 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002846 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002847 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002848}
dsinclair5b36f0a2016-07-19 10:56:23 -07002849
Dan Sinclair1770c022016-03-14 14:14:16 -04002850void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002851 if (pArguments->GetLength() != 0) {
2852 ThrowParamCountMismatchException(L"remerge");
2853 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002854 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002855 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002856}
dsinclair5b36f0a2016-07-19 10:56:23 -07002857
Dan Sinclair1770c022016-03-14 14:14:16 -04002858void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002859 if (pArguments->GetLength() != 0) {
2860 ThrowParamCountMismatchException(L"execInitialize");
2861 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002862 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002863
2864 CXFA_WidgetData* pWidgetData = GetWidgetData();
2865 if (!pWidgetData) {
2866 pArguments->GetReturnValue()->SetBoolean(false);
2867 return;
2868 }
2869 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002870}
dsinclair5b36f0a2016-07-19 10:56:23 -07002871
Dan Sinclair1770c022016-03-14 14:14:16 -04002872void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2873 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002874 if (argc <= 0 || argc >= 4) {
2875 ThrowParamCountMismatchException(L"createNode");
2876 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002877 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002878
2879 CFX_WideString strName;
2880 CFX_WideString strNameSpace;
2881 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
2882 CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
2883 if (argc > 1) {
2884 CFX_ByteString bsName = pArguments->GetUTF8String(1);
2885 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
2886 if (argc == 3) {
2887 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
2888 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
2889 }
2890 }
2891
2892 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2893 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
2894 if (!pNewNode) {
2895 pArguments->GetReturnValue()->SetNull();
2896 return;
2897 }
2898
2899 if (strName.IsEmpty()) {
2900 pArguments->GetReturnValue()->Assign(
2901 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2902 return;
2903 }
2904
2905 if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2906 XFA_XDPPACKET_UNKNOWN)) {
2907 ThrowMissingPropertyException(strTagName, L"name");
2908 return;
2909 }
2910
2911 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
2912 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets)
2913 pNewNode->CreateXMLMappingNode();
2914
2915 pArguments->GetReturnValue()->Assign(
2916 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002917}
dsinclair5b36f0a2016-07-19 10:56:23 -07002918
Dan Sinclair1770c022016-03-14 14:14:16 -04002919void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002920 if (pArguments->GetLength() != 1) {
2921 ThrowParamCountMismatchException(L"recalculate");
2922 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002923 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002924 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002925}
dsinclair5b36f0a2016-07-19 10:56:23 -07002926
Dan Sinclair1770c022016-03-14 14:14:16 -04002927void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002928 if (pArguments->GetLength() != 0) {
2929 ThrowParamCountMismatchException(L"execCalculate");
2930 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002931 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002932
2933 CXFA_WidgetData* pWidgetData = GetWidgetData();
2934 if (!pWidgetData) {
2935 pArguments->GetReturnValue()->SetBoolean(false);
2936 return;
2937 }
2938 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002939}
dsinclair5b36f0a2016-07-19 10:56:23 -07002940
Dan Sinclair1770c022016-03-14 14:14:16 -04002941void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002942 if (pArguments->GetLength() != 0) {
2943 ThrowParamCountMismatchException(L"execValidate");
2944 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002945 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002946 CXFA_WidgetData* pWidgetData = GetWidgetData();
2947 if (!pWidgetData) {
2948 pArguments->GetReturnValue()->SetBoolean(false);
2949 return;
2950 }
2951 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002952}
dsinclair5b36f0a2016-07-19 10:56:23 -07002953
Dan Sinclair1770c022016-03-14 14:14:16 -04002954void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002955 if (pArguments->GetLength() != 0) {
2956 ThrowParamCountMismatchException(L"evaluate");
2957 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002958 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002959
2960 CXFA_WidgetData* pWidgetData = GetWidgetData();
2961 if (!pWidgetData) {
2962 pArguments->GetReturnValue()->SetBoolean(false);
2963 return;
2964 }
2965 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002966}
dsinclair5b36f0a2016-07-19 10:56:23 -07002967
dsinclair12a6b0c2016-05-26 11:14:08 -07002968void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002969 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002970 XFA_ATTRIBUTE eAttribute) {
2971 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002972 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002973 return;
2974 }
2975 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002976 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04002977}
dsinclair5b36f0a2016-07-19 10:56:23 -07002978
dsinclair12a6b0c2016-05-26 11:14:08 -07002979void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002980 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002981 XFA_ATTRIBUTE eAttribute) {
2982 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002983 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002984 return;
2985 }
2986 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002987 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04002988}
tsepezaadedf92016-05-12 10:08:06 -07002989
dsinclair12a6b0c2016-05-26 11:14:08 -07002990void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002991 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002992 XFA_ATTRIBUTE eAttribute) {
2993 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002994 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002995 InstanceManager_SetInstances(iDesired);
2996 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07002997 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04002998 }
2999}
dsinclair5b36f0a2016-07-19 10:56:23 -07003000
Dan Sinclair1770c022016-03-14 14:14:16 -04003001void CXFA_Node::Script_InstanceManager_MoveInstance(
3002 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003003 if (pArguments->GetLength() != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003004 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003005 return;
3006 }
3007 int32_t iFrom = pArguments->GetInt32(0);
3008 int32_t iTo = pArguments->GetInt32(1);
3009 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003010 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003011 if (!pNotify) {
3012 return;
3013 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003014 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003015 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003016 pNotify->RunSubformIndexChange(pToInstance);
3017 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003018 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003019 if (pFromInstance &&
3020 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003021 pNotify->RunSubformIndexChange(pFromInstance);
3022 }
3023}
dsinclair5b36f0a2016-07-19 10:56:23 -07003024
Dan Sinclair1770c022016-03-14 14:14:16 -04003025void CXFA_Node::Script_InstanceManager_RemoveInstance(
3026 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003027 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003028 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003029 return;
3030 }
3031 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003032 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003033 if (iIndex < 0 || iIndex >= iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003034 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003035 return;
3036 }
3037 CXFA_Occur nodeOccur(GetOccurNode());
3038 int32_t iMin = nodeOccur.GetMin();
3039 if (iCount - 1 < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003040 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003041 return;
3042 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003043 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3044 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003045 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003046 if (pNotify) {
3047 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003048 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003049 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003050 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003051 pNotify->RunSubformIndexChange(pSubformInstance);
3052 }
3053 }
3054 }
3055 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3056 if (!pLayoutPro) {
3057 return;
3058 }
3059 pLayoutPro->AddChangedContainer(
3060 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3061}
dsinclair5b36f0a2016-07-19 10:56:23 -07003062
Dan Sinclair1770c022016-03-14 14:14:16 -04003063void CXFA_Node::Script_InstanceManager_SetInstances(
3064 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003065 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003066 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003067 return;
3068 }
3069 int32_t iDesired = pArguments->GetInt32(0);
3070 InstanceManager_SetInstances(iDesired);
3071}
dsinclair5b36f0a2016-07-19 10:56:23 -07003072
Dan Sinclair1770c022016-03-14 14:14:16 -04003073void CXFA_Node::Script_InstanceManager_AddInstance(
3074 CFXJSE_Arguments* pArguments) {
3075 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003076 if (argc != 0 && argc != 1) {
3077 ThrowParamCountMismatchException(L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003078 return;
3079 }
tsepezd19e9122016-11-02 15:43:18 -07003080 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003081 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003082 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003083 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003084 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003085 CXFA_Occur nodeOccur(GetOccurNode());
3086 int32_t iMax = nodeOccur.GetMax();
3087 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003088 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003089 return;
3090 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003091 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003092 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003093 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003094 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003095 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003096 if (!pNotify) {
3097 return;
3098 }
3099 pNotify->RunNodeInitialize(pNewInstance);
3100 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3101 if (!pLayoutPro) {
3102 return;
3103 }
3104 pLayoutPro->AddChangedContainer(
3105 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3106}
dsinclair5b36f0a2016-07-19 10:56:23 -07003107
Dan Sinclair1770c022016-03-14 14:14:16 -04003108void CXFA_Node::Script_InstanceManager_InsertInstance(
3109 CFXJSE_Arguments* pArguments) {
3110 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003111 if (argc != 1 && argc != 2) {
3112 ThrowParamCountMismatchException(L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003113 return;
3114 }
3115 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003116 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003117 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003118 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003119 }
3120 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003121 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003122 if (iIndex < 0 || iIndex > iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003123 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003124 return;
3125 }
3126 int32_t iMax = nodeOccur.GetMax();
3127 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003128 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003129 return;
3130 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003131 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003132 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003133 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003134 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003135 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003136 if (!pNotify) {
3137 return;
3138 }
3139 pNotify->RunNodeInitialize(pNewInstance);
3140 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3141 if (!pLayoutPro) {
3142 return;
3143 }
3144 pLayoutPro->AddChangedContainer(
3145 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3146}
dsinclair5b36f0a2016-07-19 10:56:23 -07003147
Dan Sinclair1770c022016-03-14 14:14:16 -04003148int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3149 CXFA_Occur nodeOccur(GetOccurNode());
3150 int32_t iMax = nodeOccur.GetMax();
3151 int32_t iMin = nodeOccur.GetMin();
3152 if (iDesired < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003153 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003154 return 1;
3155 }
3156 if ((iMax >= 0) && (iDesired > iMax)) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003157 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003158 return 2;
3159 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003160 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003161 if (iDesired == iCount) {
3162 return 0;
3163 }
3164 if (iDesired < iCount) {
3165 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003166 CFX_WideString wsInstanceName =
3167 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3168 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003169 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003170 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003171 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003172 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003173 while (iCount > iDesired) {
3174 CXFA_Node* pRemoveInstance =
3175 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003176 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3177 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003178 continue;
3179 }
dsinclair070fcdf2016-06-22 22:04:54 -07003180 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003181 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003182 break;
3183 }
3184 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003185 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003186 iCount--;
3187 }
3188 }
3189 } else if (iDesired > iCount) {
3190 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003191 CXFA_Node* pNewInstance = CreateInstance(this, true);
3192 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003193 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003194 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003195 if (!pNotify) {
3196 return 0;
3197 }
3198 pNotify->RunNodeInitialize(pNewInstance);
3199 }
3200 }
3201 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3202 if (pLayoutPro) {
3203 pLayoutPro->AddChangedContainer(
3204 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3205 }
3206 return 0;
3207}
dsinclair5b36f0a2016-07-19 10:56:23 -07003208
Dan Sinclair1770c022016-03-14 14:14:16 -04003209int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003210 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003211 if (iFrom > iCount || iTo > iCount - 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003212 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003213 return 1;
3214 }
3215 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3216 return 0;
3217 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003218 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003219 RemoveItem(this, pMoveInstance, false);
3220 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003221 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3222 if (pLayoutPro) {
3223 pLayoutPro->AddChangedContainer(
3224 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3225 }
3226 return 0;
3227}
dsinclair5b36f0a2016-07-19 10:56:23 -07003228
dsinclair12a6b0c2016-05-26 11:14:08 -07003229void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003230 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003231 XFA_ATTRIBUTE eAttribute) {
3232 CXFA_Occur occur(this);
3233 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003234 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003235 occur.SetMax(iMax);
3236 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003237 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003238 }
3239}
dsinclair5b36f0a2016-07-19 10:56:23 -07003240
dsinclair12a6b0c2016-05-26 11:14:08 -07003241void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003242 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003243 XFA_ATTRIBUTE eAttribute) {
3244 CXFA_Occur occur(this);
3245 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003246 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003247 occur.SetMin(iMin);
3248 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003249 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003250 }
3251}
dsinclair5b36f0a2016-07-19 10:56:23 -07003252
Dan Sinclair1770c022016-03-14 14:14:16 -04003253void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3254 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003255 if (argc != 0 && argc != 1) {
3256 ThrowParamCountMismatchException(L"metadata");
3257 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003258 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003259 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003260}
dsinclair5b36f0a2016-07-19 10:56:23 -07003261
Dan Sinclair1770c022016-03-14 14:14:16 -04003262void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003263 if (pArguments->GetLength() != 1) {
3264 ThrowParamCountMismatchException(L"formNodes");
3265 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003266 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003267
3268 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3269 if (!pDataNode) {
3270 ThrowArgumentMismatchException();
3271 return;
3272 }
3273
Tom Sepezf8a94392017-03-14 12:13:22 -07003274 std::vector<CXFA_Node*> formItems;
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003275 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3276 pFormNodes->SetArrayNodeList(formItems);
3277 pArguments->GetReturnValue()->SetObject(
3278 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003279}
dsinclair5b36f0a2016-07-19 10:56:23 -07003280
Dan Sinclair1770c022016-03-14 14:14:16 -04003281void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003282 if (pArguments->GetLength() != 0) {
3283 ThrowParamCountMismatchException(L"remerge");
3284 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003285 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003286
3287 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003288}
dsinclair5b36f0a2016-07-19 10:56:23 -07003289
Dan Sinclair1770c022016-03-14 14:14:16 -04003290void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003291 if (pArguments->GetLength() != 0) {
3292 ThrowParamCountMismatchException(L"execInitialize");
3293 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003294 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003295
3296 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3297 if (!pNotify)
3298 return;
3299
3300 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04003301}
dsinclair5b36f0a2016-07-19 10:56:23 -07003302
Dan Sinclair1770c022016-03-14 14:14:16 -04003303void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3304 CXFA_EventParam* pEventParam =
3305 m_pDocument->GetScriptContext()->GetEventParam();
3306 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3307 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3308 return;
3309 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003310 if (pArguments->GetLength() != 1) {
3311 ThrowParamCountMismatchException(L"recalculate");
3312 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003313 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003314
3315 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3316 if (!pNotify)
3317 return;
3318 if (pArguments->GetInt32(0) != 0)
3319 return;
3320
3321 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3322 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3323 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003324}
dsinclair5b36f0a2016-07-19 10:56:23 -07003325
Dan Sinclair1770c022016-03-14 14:14:16 -04003326void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003327 if (pArguments->GetLength() != 0) {
3328 ThrowParamCountMismatchException(L"execCalculate");
3329 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003330 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003331
3332 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3333 if (!pNotify)
3334 return;
3335
3336 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04003337}
dsinclair5b36f0a2016-07-19 10:56:23 -07003338
Dan Sinclair1770c022016-03-14 14:14:16 -04003339void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003340 if (pArguments->GetLength() != 0) {
3341 ThrowParamCountMismatchException(L"execValidate");
3342 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003343 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003344
3345 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3346 if (!pNotify) {
3347 pArguments->GetReturnValue()->SetBoolean(false);
3348 return;
3349 }
3350
3351 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3352 pArguments->GetReturnValue()->SetBoolean(
3353 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003354}
dsinclair5b36f0a2016-07-19 10:56:23 -07003355
dsinclair12a6b0c2016-05-26 11:14:08 -07003356void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003357 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003358 XFA_ATTRIBUTE eAttribute) {
3359 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003360 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003361 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003362 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003363 CFX_WideString wsChecksum;
3364 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
Tom Sepezf0b65542017-02-13 10:26:01 -08003365 pValue->SetString(wsChecksum.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003366}
dsinclair5b36f0a2016-07-19 10:56:23 -07003367
Dan Sinclair1770c022016-03-14 14:14:16 -04003368void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003369 if (pArguments->GetLength() != 1) {
3370 ThrowParamCountMismatchException(L"getAttribute");
3371 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003372 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003373 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3374 CFX_WideString wsAttributeValue;
3375 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3376 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003377 wsAttributeValue = static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3378 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003379 }
3380 pArguments->GetReturnValue()->SetString(
Tom Sepezf0b65542017-02-13 10:26:01 -08003381 wsAttributeValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003382}
dsinclair5b36f0a2016-07-19 10:56:23 -07003383
Dan Sinclair1770c022016-03-14 14:14:16 -04003384void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003385 if (pArguments->GetLength() != 2) {
3386 ThrowParamCountMismatchException(L"setAttribute");
3387 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003388 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003389 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3390 CFX_ByteString bsName = pArguments->GetUTF8String(1);
3391 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3392 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3393 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(
3394 CFX_WideString::FromUTF8(bsName.AsStringC()),
3395 CFX_WideString::FromUTF8(bsValue.AsStringC()));
3396 }
3397 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003398}
dsinclair5b36f0a2016-07-19 10:56:23 -07003399
Dan Sinclair1770c022016-03-14 14:14:16 -04003400void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003401 if (pArguments->GetLength() != 1) {
3402 ThrowParamCountMismatchException(L"removeAttribute");
3403 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003404 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003405
3406 CFX_ByteString bsName = pArguments->GetUTF8String(0);
3407 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
3408 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3409 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3410 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
3411 if (pXMLElement->HasAttribute(wsName.c_str())) {
3412 pXMLElement->RemoveAttribute(wsName.c_str());
3413 }
3414 }
3415 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003416}
dsinclair5b36f0a2016-07-19 10:56:23 -07003417
dsinclair12a6b0c2016-05-26 11:14:08 -07003418void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003419 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003420 XFA_ATTRIBUTE eAttribute) {
3421 if (bSetting) {
dsinclairae95f762016-03-29 16:58:29 -07003422 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003423 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003424 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003425 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003426 }
3427 } else {
3428 CFX_WideString wsTextData;
dsinclairae95f762016-03-29 16:58:29 -07003429 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003430 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003431 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003432 wsTextData = pXMLElement->GetTextData();
Dan Sinclair1770c022016-03-14 14:14:16 -04003433 }
Tom Sepezf0b65542017-02-13 10:26:01 -08003434 pValue->SetString(wsTextData.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003435 }
3436}
dsinclair5b36f0a2016-07-19 10:56:23 -07003437
Dan Sinclair1770c022016-03-14 14:14:16 -04003438void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003439 if (pArguments->GetLength() != 0)
3440 ThrowParamCountMismatchException(L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003441}
dsinclair5b36f0a2016-07-19 10:56:23 -07003442
Dan Sinclair1770c022016-03-14 14:14:16 -04003443void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003444 if (pArguments->GetLength() != 0)
3445 ThrowParamCountMismatchException(L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003446}
dsinclair5b36f0a2016-07-19 10:56:23 -07003447
Dan Sinclair1770c022016-03-14 14:14:16 -04003448void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003449 if (pArguments->GetLength() != 0)
3450 ThrowParamCountMismatchException(L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003451}
dsinclair5b36f0a2016-07-19 10:56:23 -07003452
Dan Sinclair1770c022016-03-14 14:14:16 -04003453void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003454 if (pArguments->GetLength() != 0)
3455 ThrowParamCountMismatchException(L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003456}
dsinclair5b36f0a2016-07-19 10:56:23 -07003457
Dan Sinclair1770c022016-03-14 14:14:16 -04003458void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003459 if (pArguments->GetLength() != 0)
3460 ThrowParamCountMismatchException(L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003461}
dsinclair5b36f0a2016-07-19 10:56:23 -07003462
Dan Sinclair1770c022016-03-14 14:14:16 -04003463void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003464 if (pArguments->GetLength() != 0)
3465 ThrowParamCountMismatchException(L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003466}
dsinclair5b36f0a2016-07-19 10:56:23 -07003467
Dan Sinclair1770c022016-03-14 14:14:16 -04003468void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003469 if (pArguments->GetLength() != 0)
3470 ThrowParamCountMismatchException(L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003471}
dsinclair5b36f0a2016-07-19 10:56:23 -07003472
Dan Sinclair1770c022016-03-14 14:14:16 -04003473void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003474 if (pArguments->GetLength() != 0)
3475 ThrowParamCountMismatchException(L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003476}
dsinclair5b36f0a2016-07-19 10:56:23 -07003477
Dan Sinclair1770c022016-03-14 14:14:16 -04003478void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003479 if (pArguments->GetLength() != 0)
3480 ThrowParamCountMismatchException(L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003481}
dsinclair5b36f0a2016-07-19 10:56:23 -07003482
Dan Sinclair1770c022016-03-14 14:14:16 -04003483void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003484 if (pArguments->GetLength() != 0)
3485 ThrowParamCountMismatchException(L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003486}
dsinclair5b36f0a2016-07-19 10:56:23 -07003487
Dan Sinclair1770c022016-03-14 14:14:16 -04003488void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003489 if (pArguments->GetLength() != 0)
3490 ThrowParamCountMismatchException(L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003491}
dsinclair5b36f0a2016-07-19 10:56:23 -07003492
Dan Sinclair1770c022016-03-14 14:14:16 -04003493void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003494 if (pArguments->GetLength() != 0)
3495 ThrowParamCountMismatchException(L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003496}
dsinclair5b36f0a2016-07-19 10:56:23 -07003497
Dan Sinclair1770c022016-03-14 14:14:16 -04003498void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003499 if (pArguments->GetLength() != 0)
3500 ThrowParamCountMismatchException(L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003501}
dsinclair5b36f0a2016-07-19 10:56:23 -07003502
Dan Sinclair1770c022016-03-14 14:14:16 -04003503void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003504 if (pArguments->GetLength() != 0)
3505 ThrowParamCountMismatchException(L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003506}
dsinclair5b36f0a2016-07-19 10:56:23 -07003507
Dan Sinclair1770c022016-03-14 14:14:16 -04003508void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003509 if (pArguments->GetLength() != 0)
3510 ThrowParamCountMismatchException(L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003511}
dsinclair5b36f0a2016-07-19 10:56:23 -07003512
Dan Sinclair1770c022016-03-14 14:14:16 -04003513void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003514 if (pArguments->GetLength() != 0)
3515 ThrowParamCountMismatchException(L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003516}
dsinclair5b36f0a2016-07-19 10:56:23 -07003517
Dan Sinclair1770c022016-03-14 14:14:16 -04003518void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003519 if (pArguments->GetLength() != 0)
3520 ThrowParamCountMismatchException(L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003521}
dsinclair5b36f0a2016-07-19 10:56:23 -07003522
dsinclair12a6b0c2016-05-26 11:14:08 -07003523void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003524 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003525 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003526
dsinclair12a6b0c2016-05-26 11:14:08 -07003527void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003528 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003529 XFA_ATTRIBUTE eAttribute) {
3530 if (!bSetting) {
3531 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003532 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003533 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003534 }
3535}
dsinclair5b36f0a2016-07-19 10:56:23 -07003536
dsinclair12a6b0c2016-05-26 11:14:08 -07003537void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003538 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003539 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003540
dsinclair12a6b0c2016-05-26 11:14:08 -07003541void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003542 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003543 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003544
dsinclair12a6b0c2016-05-26 11:14:08 -07003545void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003546 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003547 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003548
dsinclair12a6b0c2016-05-26 11:14:08 -07003549void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003550 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003551 XFA_ATTRIBUTE eAttribute) {
3552 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003553 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003554 return;
3555 }
dan sinclair65c7c232017-02-02 14:05:30 -08003556 pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003557}
dsinclair5b36f0a2016-07-19 10:56:23 -07003558
dsinclair12a6b0c2016-05-26 11:14:08 -07003559void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003560 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003561 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003562
tsepezd19e9122016-11-02 15:43:18 -07003563bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003564 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003565 return HasMapModuleKey(pKey, bCanInherit);
3566}
dsinclair5b36f0a2016-07-19 10:56:23 -07003567
tsepezd19e9122016-11-02 15:43:18 -07003568bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3569 const CFX_WideStringC& wsValue,
3570 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003571 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003572 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003573 return false;
weili44f8faf2016-06-01 14:03:56 -07003574
Dan Sinclair1770c022016-03-14 14:14:16 -04003575 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3576 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3577 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003578 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003579 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3580 }
3581 switch (eType) {
3582 case XFA_ATTRIBUTETYPE_Enum: {
3583 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3584 return SetEnum(pAttr->eName,
3585 pEnum ? pEnum->eName
3586 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3587 bNotify);
3588 } break;
3589 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003590 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003591 case XFA_ATTRIBUTETYPE_Boolean:
dan sinclair65c7c232017-02-02 14:05:30 -08003592 return SetBoolean(pAttr->eName, wsValue != L"0", bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003593 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003594 return SetInteger(pAttr->eName,
3595 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3596 wsValue.GetLength(), nullptr)),
3597 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003598 case XFA_ATTRIBUTETYPE_Measure:
3599 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3600 default:
3601 break;
3602 }
tsepezd19e9122016-11-02 15:43:18 -07003603 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003604}
dsinclair5b36f0a2016-07-19 10:56:23 -07003605
tsepezd19e9122016-11-02 15:43:18 -07003606bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3607 CFX_WideString& wsValue,
3608 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003609 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003610 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003611 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003612 }
3613 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3614 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3615 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003616 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003617 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3618 }
3619 switch (eType) {
3620 case XFA_ATTRIBUTETYPE_Enum: {
3621 XFA_ATTRIBUTEENUM eValue;
3622 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003623 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003624 }
dsinclair9eb0db12016-07-21 12:01:39 -07003625 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003626 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003627 } break;
3628 case XFA_ATTRIBUTETYPE_Cdata: {
3629 CFX_WideStringC wsValueC;
3630 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003631 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003632 }
3633 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003634 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003635 } break;
3636 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003637 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003638 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003639 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003640 }
dan sinclair65c7c232017-02-02 14:05:30 -08003641 wsValue = bValue ? L"1" : L"0";
tsepezd19e9122016-11-02 15:43:18 -07003642 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003643 } break;
3644 case XFA_ATTRIBUTETYPE_Integer: {
3645 int32_t iValue;
3646 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003647 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003648 }
3649 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003650 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003651 } break;
3652 case XFA_ATTRIBUTETYPE_Measure: {
3653 CXFA_Measurement mValue;
3654 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003655 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003656 }
3657 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003658 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003659 } break;
3660 default:
3661 break;
3662 }
tsepezd19e9122016-11-02 15:43:18 -07003663 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003664}
dsinclair5b36f0a2016-07-19 10:56:23 -07003665
tsepezd19e9122016-11-02 15:43:18 -07003666bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3667 const CFX_WideStringC& wsValue,
3668 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003669 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3670 if (pAttributeInfo) {
3671 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3672 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003673 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003674 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003675 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003676}
dsinclair5b36f0a2016-07-19 10:56:23 -07003677
tsepezd19e9122016-11-02 15:43:18 -07003678bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3679 CFX_WideString& wsValue,
3680 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003681 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3682 if (pAttributeInfo) {
3683 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3684 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003685 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003686 CFX_WideStringC wsValueC;
3687 if (GetMapModuleString(pKey, wsValueC)) {
3688 wsValue = wsValueC;
3689 }
tsepezd19e9122016-11-02 15:43:18 -07003690 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003691}
dsinclair5b36f0a2016-07-19 10:56:23 -07003692
tsepezd19e9122016-11-02 15:43:18 -07003693bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003694 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003695 RemoveMapModuleKey(pKey);
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::TryBoolean(XFA_ATTRIBUTE eAttr,
3700 bool& bValue,
3701 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003702 void* pValue = nullptr;
3703 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003704 return false;
tsepez478ed622016-10-27 14:32:33 -07003705 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003706 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003707}
dsinclair5b36f0a2016-07-19 10:56:23 -07003708
tsepezd19e9122016-11-02 15:43:18 -07003709bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3710 int32_t& iValue,
3711 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003712 void* pValue = nullptr;
3713 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003714 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003715 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003716 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003717}
dsinclair5b36f0a2016-07-19 10:56:23 -07003718
tsepezd19e9122016-11-02 15:43:18 -07003719bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3720 XFA_ATTRIBUTEENUM& eValue,
3721 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003722 void* pValue = nullptr;
3723 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003724 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003725 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003726 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003727}
thestigb1a59592016-04-14 18:29:56 -07003728
tsepezd19e9122016-11-02 15:43:18 -07003729bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3730 CXFA_Measurement mValue,
3731 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003732 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003733 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003734 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003735 OnChanged(eAttr, bNotify, false);
3736 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003737}
thestigb1a59592016-04-14 18:29:56 -07003738
tsepezd19e9122016-11-02 15:43:18 -07003739bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3740 CXFA_Measurement& mValue,
3741 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003742 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003743 void* pValue;
3744 int32_t iBytes;
3745 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003746 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003747 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003748 }
3749 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003750 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003751 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
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 }
tsepezd19e9122016-11-02 15:43:18 -07003755 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003756}
3757
3758CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3759 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003760 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003761}
3762
tsepezd19e9122016-11-02 15:43:18 -07003763bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3764 const CFX_WideString& wsValue,
3765 bool bNotify,
3766 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003767 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003768 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003769 if (eAttr == XFA_ATTRIBUTE_Value) {
3770 CFX_WideString* pClone = new CFX_WideString(wsValue);
3771 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3772 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003773 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003774 if (eAttr == XFA_ATTRIBUTE_Name)
3775 UpdateNameHash();
3776 }
thestigb1a59592016-04-14 18:29:56 -07003777 OnChanged(eAttr, bNotify, bScriptModify);
3778
3779 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3780 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003781 return true;
thestigb1a59592016-04-14 18:29:56 -07003782 }
3783
dsinclair070fcdf2016-06-22 22:04:54 -07003784 if (eAttr == XFA_ATTRIBUTE_Name &&
3785 (m_elementType == XFA_Element::DataValue ||
3786 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003787 return true;
thestigb1a59592016-04-14 18:29:56 -07003788 }
3789
3790 if (eAttr == XFA_ATTRIBUTE_Value) {
3791 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3792 switch (eXMLType) {
3793 case FDE_XMLNODE_Element:
3794 if (IsAttributeInXML()) {
3795 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003796 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3797 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003798 } else {
tsepezd19e9122016-11-02 15:43:18 -07003799 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003800 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3801 for (CXFA_Node* pChildDataNode =
3802 GetNodeItem(XFA_NODEITEM_FirstChild);
3803 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3804 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003805 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003806 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003807 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003808 }
3809 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003810 }
thestigb1a59592016-04-14 18:29:56 -07003811 if (bDeleteChildren) {
3812 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3813 }
3814 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3815 }
3816 break;
3817 case FDE_XMLNODE_Text:
3818 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3819 break;
3820 default:
dsinclair43854a52016-04-27 12:26:00 -07003821 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003822 }
tsepezd19e9122016-11-02 15:43:18 -07003823 return true;
thestigb1a59592016-04-14 18:29:56 -07003824 }
3825
3826 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3827 if (pInfo) {
dsinclair43854a52016-04-27 12:26:00 -07003828 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003829 CFX_WideString wsAttrName = pInfo->pName;
3830 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
dan sinclair65c7c232017-02-02 14:05:30 -08003831 wsAttrName = L"xfa:" + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003832 }
thestigb1a59592016-04-14 18:29:56 -07003833 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003834 }
tsepezd19e9122016-11-02 15:43:18 -07003835 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003836}
thestigb1a59592016-04-14 18:29:56 -07003837
tsepezd19e9122016-11-02 15:43:18 -07003838bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3839 const CFX_WideString& wsXMLValue,
3840 bool bNotify,
3841 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003842 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003843 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003844 CFX_WideString* pClone = new CFX_WideString(wsValue);
3845 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003846 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003847 if (IsNeedSavingXMLNode()) {
3848 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3849 switch (eXMLType) {
3850 case FDE_XMLNODE_Element:
3851 if (IsAttributeInXML()) {
dsinclairae95f762016-03-29 16:58:29 -07003852 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003853 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3854 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003855 } else {
tsepezd19e9122016-11-02 15:43:18 -07003856 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003857 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3858 for (CXFA_Node* pChildDataNode =
3859 GetNodeItem(XFA_NODEITEM_FirstChild);
3860 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3861 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003862 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003863 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003864 break;
3865 }
3866 }
3867 }
3868 if (bDeleteChildren) {
dsinclairae95f762016-03-29 16:58:29 -07003869 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003870 }
dsinclairae95f762016-03-29 16:58:29 -07003871 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003872 }
3873 break;
3874 case FDE_XMLNODE_Text:
dsinclairae95f762016-03-29 16:58:29 -07003875 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003876 break;
3877 default:
dsinclair43854a52016-04-27 12:26:00 -07003878 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003879 }
3880 }
tsepezd19e9122016-11-02 15:43:18 -07003881 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003882}
dsinclair5b36f0a2016-07-19 10:56:23 -07003883
tsepezd19e9122016-11-02 15:43:18 -07003884bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3885 CFX_WideString& wsValue,
3886 bool bUseDefault,
3887 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003888 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003889 if (eAttr == XFA_ATTRIBUTE_Value) {
3890 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3891 if (pStr) {
3892 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07003893 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003894 }
3895 } else {
3896 CFX_WideStringC wsValueC;
3897 if (GetMapModuleString(pKey, wsValueC)) {
3898 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003899 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003900 }
3901 }
3902 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003903 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003904 }
weili44f8faf2016-06-01 14:03:56 -07003905 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003906 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003907 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003908 wsValue = (const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003909 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003910 }
tsepezd19e9122016-11-02 15:43:18 -07003911 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003912}
dsinclair5b36f0a2016-07-19 10:56:23 -07003913
tsepezd19e9122016-11-02 15:43:18 -07003914bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3915 CFX_WideStringC& wsValue,
3916 bool bUseDefault,
3917 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003918 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003919 if (eAttr == XFA_ATTRIBUTE_Value) {
3920 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3921 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07003922 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07003923 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003924 }
3925 } else {
3926 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003927 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003928 }
3929 }
3930 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003931 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003932 }
weili44f8faf2016-06-01 14:03:56 -07003933 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003934 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003935 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003936 wsValue = (CFX_WideStringC)(const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003937 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003938 }
tsepezd19e9122016-11-02 15:43:18 -07003939 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003940}
dsinclair5b36f0a2016-07-19 10:56:23 -07003941
tsepezd19e9122016-11-02 15:43:18 -07003942bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
3943 void* pData,
3944 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003945 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003946 return SetUserData(pKey, pData, pCallbackInfo);
3947}
dsinclair5b36f0a2016-07-19 10:56:23 -07003948
tsepezd19e9122016-11-02 15:43:18 -07003949bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003950 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003951 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07003952 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04003953}
dsinclair5b36f0a2016-07-19 10:56:23 -07003954
tsepezd19e9122016-11-02 15:43:18 -07003955bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
3956 XFA_ATTRIBUTETYPE eType,
3957 void* pValue,
3958 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003959 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003960 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003961 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07003962 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003963 if (IsNeedSavingXMLNode()) {
dsinclair43854a52016-04-27 12:26:00 -07003964 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04003965 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3966 if (pInfo) {
3967 switch (eType) {
3968 case XFA_ATTRIBUTETYPE_Enum:
dsinclairae95f762016-03-29 16:58:29 -07003969 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04003970 ->SetString(
3971 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07003972 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04003973 ->pName);
3974 break;
3975 case XFA_ATTRIBUTETYPE_Boolean:
dsinclairae95f762016-03-29 16:58:29 -07003976 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003977 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04003978 break;
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003979 case XFA_ATTRIBUTETYPE_Integer: {
3980 CFX_WideString wsValue;
3981 wsValue.Format(
3982 L"%d", static_cast<int32_t>(reinterpret_cast<uintptr_t>(pValue)));
dsinclairae95f762016-03-29 16:58:29 -07003983 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003984 ->SetString(pInfo->pName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003985 break;
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003986 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003987 default:
dsinclair43854a52016-04-27 12:26:00 -07003988 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003989 }
3990 }
3991 }
tsepezd19e9122016-11-02 15:43:18 -07003992 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003993}
dsinclair5b36f0a2016-07-19 10:56:23 -07003994
tsepezd19e9122016-11-02 15:43:18 -07003995bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
3996 XFA_ATTRIBUTETYPE eType,
3997 bool bUseDefault,
3998 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003999 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004000 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004001 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004002 }
4003 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004004 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004005 }
dsinclair070fcdf2016-06-22 22:04:54 -07004006 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004007 m_ePacket);
4008}
dsinclair5b36f0a2016-07-19 10:56:23 -07004009
tsepezd19e9122016-11-02 15:43:18 -07004010bool CXFA_Node::SetUserData(void* pKey,
4011 void* pData,
4012 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004013 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4014 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004015 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004016}
dsinclair5b36f0a2016-07-19 10:56:23 -07004017
tsepezd19e9122016-11-02 15:43:18 -07004018bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004019 int32_t iBytes = 0;
4020 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004021 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004022 }
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004023 return iBytes == sizeof(void*) && memcpy(&pData, pData, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004024}
dsinclair5b36f0a2016-07-19 10:56:23 -07004025
tsepezd19e9122016-11-02 15:43:18 -07004026bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4027 const CFX_WideString& wsXMLValue,
4028 bool bNotify,
4029 bool bScriptModify,
4030 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004031 CXFA_Node* pNode = nullptr;
4032 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004033 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004034 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004035 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004036 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004037 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004038 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004039 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004040 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004041 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004042 CXFA_Node* pBind = GetBindData();
4043 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004044 std::vector<CFX_WideString> wsSaveTextArray;
Tom Sepezf8a94392017-03-14 12:13:22 -07004045 size_t iSize = 0;
Dan Sinclair1770c022016-03-14 14:14:16 -04004046 if (!wsContent.IsEmpty()) {
4047 int32_t iStart = 0;
4048 int32_t iLength = wsContent.GetLength();
4049 int32_t iEnd = wsContent.Find(L'\n', iStart);
4050 iEnd = (iEnd == -1) ? iLength : iEnd;
4051 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004052 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004053 iStart = iEnd + 1;
4054 if (iStart >= iLength) {
4055 break;
4056 }
4057 iEnd = wsContent.Find(L'\n', iStart);
4058 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004059 wsSaveTextArray.push_back(
4060 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004061 }
4062 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004063 iSize = wsSaveTextArray.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004064 }
4065 if (iSize == 0) {
4066 while (CXFA_Node* pChildNode =
4067 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4068 pBind->RemoveChild(pChildNode);
4069 }
4070 } else {
Tom Sepezf8a94392017-03-14 12:13:22 -07004071 std::vector<CXFA_Node*> valueNodes = pBind->GetNodeList(
4072 XFA_NODEFILTER_Children, XFA_Element::DataValue);
4073 size_t iDatas = valueNodes.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004074 if (iDatas < iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004075 size_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004076 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004077 while (iAddNodes-- > 0) {
4078 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004079 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004080 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004081 pValueNodes->CreateXMLMappingNode();
4082 pBind->InsertChild(pValueNodes);
4083 }
weili44f8faf2016-06-01 14:03:56 -07004084 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004085 } else if (iDatas > iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004086 size_t iDelNodes = iDatas - iSize;
Dan Sinclair1770c022016-03-14 14:14:16 -04004087 while (iDelNodes-- > 0) {
4088 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4089 }
4090 }
4091 int32_t i = 0;
4092 for (CXFA_Node* pValueNode =
4093 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4094 pValueNode; pValueNode = pValueNode->GetNodeItem(
4095 XFA_NODEITEM_NextSibling)) {
4096 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004097 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004098 i++;
4099 }
4100 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004101 for (CXFA_Node* pArrayNode : pBind->GetBindItems()) {
4102 if (pArrayNode != this) {
4103 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4104 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004105 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004106 }
4107 }
4108 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004109 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004110 pNode = this;
4111 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004112 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004113 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004114 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004115 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004116 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004117 }
4118 pBindNode = GetBindData();
4119 if (pBindNode && bSyncData) {
4120 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004121 bScriptModify, false);
Tom Sepezf8a94392017-03-14 12:13:22 -07004122 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4123 if (pArrayNode != this) {
4124 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, true,
4125 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004126 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004127 }
4128 }
weili44f8faf2016-06-01 14:03:56 -07004129 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004130 break;
4131 }
dsinclairc5a8f212016-06-20 11:11:12 -07004132 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004133 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004134 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004135 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004136 if (wsContentType == L"text/html") {
4137 wsContentType = L"";
tsepez4c3debb2016-04-08 12:20:38 -07004138 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004139 }
4140 }
4141 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4142 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004143 pContentRawDataNode = CreateSamePacketNode(
dan sinclair65c7c232017-02-02 14:05:30 -08004144 (wsContentType == L"text/xml") ? XFA_Element::Sharpxml
4145 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004146 InsertChild(pContentRawDataNode);
4147 }
4148 return pContentRawDataNode->SetScriptContent(
4149 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4150 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004151 case XFA_ObjectType::NodeC:
4152 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004153 pNode = this;
4154 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004155 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004156 pNode = this;
4157 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4158 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4159 if (pParent) {
4160 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4161 }
dsinclair070fcdf2016-06-22 22:04:54 -07004162 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004163 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4164 if (pParent && pParent->IsContainerNode()) {
4165 pBindNode = pParent->GetBindData();
4166 if (pBindNode) {
4167 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004168 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004169 }
4170 }
4171 }
4172 }
4173 break;
4174 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004175 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004176 pNode = this;
4177 pBindNode = this;
4178 }
4179 break;
4180 }
4181 if (pNode) {
4182 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4183 if (pBindNode && bSyncData) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004184 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4185 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4186 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004187 }
4188 }
tsepezd19e9122016-11-02 15:43:18 -07004189 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004190 }
tsepezd19e9122016-11-02 15:43:18 -07004191 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004192}
dsinclair5b36f0a2016-07-19 10:56:23 -07004193
tsepezd19e9122016-11-02 15:43:18 -07004194bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4195 const CFX_WideString& wsXMLValue,
4196 bool bNotify,
4197 bool bScriptModify,
4198 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004199 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4200 bSyncData);
4201}
dsinclair5b36f0a2016-07-19 10:56:23 -07004202
tsepezd19e9122016-11-02 15:43:18 -07004203CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004204 CFX_WideString wsContent;
4205 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4206}
dsinclair5b36f0a2016-07-19 10:56:23 -07004207
Dan Sinclair1770c022016-03-14 14:14:16 -04004208CFX_WideString CXFA_Node::GetContent() {
4209 return GetScriptContent();
4210}
dsinclair5b36f0a2016-07-19 10:56:23 -07004211
tsepezd19e9122016-11-02 15:43:18 -07004212bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4213 bool bScriptModify,
4214 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004215 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004216 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004217 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004218 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004219 pNode = this;
4220 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004221 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004222 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004223 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004224 }
4225 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4226 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
dan sinclair65c7c232017-02-02 14:05:30 -08004227 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004228 }
4229 return pChildValue
4230 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004231 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004232 }
4233 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004234 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004235 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4236 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004237 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004238 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004239 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004240 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004241 if (wsContentType == L"text/html") {
dsinclair56a8b192016-06-21 14:15:25 -07004242 element = XFA_Element::SharpxHTML;
dan sinclair65c7c232017-02-02 14:05:30 -08004243 } else if (wsContentType == L"text/xml") {
dsinclair56a8b192016-06-21 14:15:25 -07004244 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004245 }
4246 }
4247 pContentRawDataNode = CreateSamePacketNode(element);
4248 InsertChild(pContentRawDataNode);
4249 }
4250 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4251 }
dsinclairc5a8f212016-06-20 11:11:12 -07004252 case XFA_ObjectType::NodeC:
4253 case XFA_ObjectType::NodeV:
4254 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004255 pNode = this;
4256 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004257 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004258 pNode = this;
4259 }
4260 break;
4261 }
4262 if (pNode) {
4263 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004264 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004265 if (pScriptContext) {
4266 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4267 }
4268 }
tsepezd19e9122016-11-02 15:43:18 -07004269 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004270 }
tsepezd19e9122016-11-02 15:43:18 -07004271 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004272}
dsinclair5b36f0a2016-07-19 10:56:23 -07004273
Dan Sinclair1770c022016-03-14 14:14:16 -04004274CXFA_Node* CXFA_Node::GetModelNode() {
4275 switch (GetPacketID()) {
4276 case XFA_XDPPACKET_XDP:
4277 return m_pDocument->GetRoot();
4278 case XFA_XDPPACKET_Config:
4279 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4280 case XFA_XDPPACKET_Template:
4281 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4282 case XFA_XDPPACKET_Form:
4283 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4284 case XFA_XDPPACKET_Datasets:
4285 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4286 case XFA_XDPPACKET_LocaleSet:
4287 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4288 case XFA_XDPPACKET_ConnectionSet:
4289 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4290 case XFA_XDPPACKET_SourceSet:
4291 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4292 case XFA_XDPPACKET_Xdc:
4293 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4294 default:
4295 return this;
4296 }
4297}
dsinclair5b36f0a2016-07-19 10:56:23 -07004298
tsepezd19e9122016-11-02 15:43:18 -07004299bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004300 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004301 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
dsinclairae95f762016-03-29 16:58:29 -07004302 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004303 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004304 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004305 }
Dan Sinclair5fa4e982017-04-05 11:48:21 -04004306 wsNamespace = static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI();
tsepezd19e9122016-11-02 15:43:18 -07004307 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004308 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
dsinclairae95f762016-03-29 16:58:29 -07004309 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004310 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004311 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004312 }
4313 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004314 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004315 }
dsinclair070fcdf2016-06-22 22:04:54 -07004316 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004317 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4318 return XFA_FDEExtension_ResolveNamespaceQualifier(
dsinclairae95f762016-03-29 16:58:29 -07004319 static_cast<CFDE_XMLElement*>(pXMLNode),
Dan Sinclair5fa4e982017-04-05 11:48:21 -04004320 GetCData(XFA_ATTRIBUTE_QualifiedName), &wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004321 }
Dan Sinclair5fa4e982017-04-05 11:48:21 -04004322 wsNamespace = static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI();
tsepezd19e9122016-11-02 15:43:18 -07004323 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004324 } else {
4325 CXFA_Node* pModelNode = GetModelNode();
4326 return pModelNode->TryNamespace(wsNamespace);
4327 }
4328}
dsinclair5b36f0a2016-07-19 10:56:23 -07004329
Dan Sinclair1770c022016-03-14 14:14:16 -04004330CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004331 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004332 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004333 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004334 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004335 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004336 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004337 if (!pProperty || index >= pProperty->uOccur)
4338 return nullptr;
4339
Dan Sinclair1770c022016-03-14 14:14:16 -04004340 CXFA_Node* pNode = m_pChild;
4341 int32_t iCount = 0;
4342 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004343 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004344 iCount++;
4345 if (iCount > index) {
4346 return pNode;
4347 }
4348 }
4349 }
weili44f8faf2016-06-01 14:03:56 -07004350 if (!bCreateProperty)
4351 return nullptr;
4352
Dan Sinclair1770c022016-03-14 14:14:16 -04004353 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4354 pNode = m_pChild;
4355 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4356 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004357 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004358 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4359 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004360 }
4361 }
dsinclaira1b07722016-07-11 08:20:58 -07004362
Dan Sinclair1770c022016-03-14 14:14:16 -04004363 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004364 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004365 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004366 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004367 if (!pNewNode)
4368 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004369 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004370 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004371 }
4372 return pNewNode;
4373}
dsinclair5b36f0a2016-07-19 10:56:23 -07004374
tsepezd19e9122016-11-02 15:43:18 -07004375int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004376 CXFA_Node* pNode = m_pChild;
4377 int32_t iCount = 0;
4378 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004379 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004380 if (bOnlyChild) {
4381 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004382 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004383 if (pProperty) {
4384 continue;
4385 }
4386 }
4387 iCount++;
4388 }
4389 }
4390 return iCount;
4391}
dsinclair5b36f0a2016-07-19 10:56:23 -07004392
Dan Sinclair1770c022016-03-14 14:14:16 -04004393CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004394 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004395 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004396 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004397 CXFA_Node* pNode = m_pChild;
4398 int32_t iCount = 0;
4399 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004400 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004401 if (bOnlyChild) {
4402 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004403 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004404 if (pProperty) {
4405 continue;
4406 }
4407 }
4408 iCount++;
4409 if (iCount > index) {
4410 return pNode;
4411 }
4412 }
4413 }
weili44f8faf2016-06-01 14:03:56 -07004414 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004415}
dsinclair5b36f0a2016-07-19 10:56:23 -07004416
Dan Sinclair1770c022016-03-14 14:14:16 -04004417int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4418 ASSERT(!pNode->m_pNext);
4419 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004420 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004421 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004422 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004423
weili44f8faf2016-06-01 14:03:56 -07004424 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004425 if (index > 0) {
4426 return -1;
4427 }
4428 pNode->m_pNext = m_pChild;
4429 m_pChild = pNode;
4430 index = 0;
4431 } else if (index < 0) {
4432 m_pLastChild->m_pNext = pNode;
4433 } else {
4434 CXFA_Node* pPrev = m_pChild;
4435 int32_t iCount = 0;
4436 while (++iCount != index && pPrev->m_pNext) {
4437 pPrev = pPrev->m_pNext;
4438 }
4439 if (index > 0 && index != iCount) {
4440 return -1;
4441 }
4442 pNode->m_pNext = pPrev->m_pNext;
4443 pPrev->m_pNext = pNode;
4444 index = iCount;
4445 }
weili44f8faf2016-06-01 14:03:56 -07004446 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004447 m_pLastChild = pNode;
4448 }
4449 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004450 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004451 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004452 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004453 if (pNotify)
4454 pNotify->OnChildAdded(this);
4455
Dan Sinclair1770c022016-03-14 14:14:16 -04004456 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004457 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004458 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004459 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004460 }
4461 return index;
4462}
weili6e1ae862016-05-04 18:25:27 -07004463
tsepezd19e9122016-11-02 15:43:18 -07004464bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004465 if (!pNode || pNode->m_pParent ||
4466 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004467 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004468 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004469 }
tsepezd19e9122016-11-02 15:43:18 -07004470 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004471 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004472 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004473
4474 int32_t nIndex = -1;
4475 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004476 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004477 pNode->m_pNext = m_pChild;
4478 m_pChild = pNode;
4479 nIndex = 0;
4480 } else if (!pBeforeNode) {
4481 pNode->m_pNext = m_pLastChild->m_pNext;
4482 m_pLastChild->m_pNext = pNode;
4483 } else {
4484 nIndex = 1;
4485 CXFA_Node* pPrev = m_pChild;
4486 while (pPrev->m_pNext != pBeforeNode) {
4487 pPrev = pPrev->m_pNext;
4488 nIndex++;
4489 }
4490 pNode->m_pNext = pPrev->m_pNext;
4491 pPrev->m_pNext = pNode;
4492 }
weili44f8faf2016-06-01 14:03:56 -07004493 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004494 m_pLastChild = pNode;
4495 }
4496 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004497 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004498 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004499 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004500 if (pNotify)
4501 pNotify->OnChildAdded(this);
4502
Dan Sinclair1770c022016-03-14 14:14:16 -04004503 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004504 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004505 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004506 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004507 }
tsepezd19e9122016-11-02 15:43:18 -07004508 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004509}
dsinclair5b36f0a2016-07-19 10:56:23 -07004510
Dan Sinclair1770c022016-03-14 14:14:16 -04004511CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4512 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004513 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004514 }
4515 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4516 pSibling = pSibling->m_pNext) {
4517 if (pSibling->m_pNext == this) {
4518 return pSibling;
4519 }
4520 }
weili44f8faf2016-06-01 14:03:56 -07004521 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004522}
dsinclair5b36f0a2016-07-19 10:56:23 -07004523
tsepezd19e9122016-11-02 15:43:18 -07004524bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004525 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004526 ASSERT(false);
4527 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004528 }
4529 if (m_pChild == pNode) {
4530 m_pChild = pNode->m_pNext;
4531 if (m_pLastChild == pNode) {
4532 m_pLastChild = pNode->m_pNext;
4533 }
weili44f8faf2016-06-01 14:03:56 -07004534 pNode->m_pNext = nullptr;
4535 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004536 } else {
4537 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4538 pPrev->m_pNext = pNode->m_pNext;
4539 if (m_pLastChild == pNode) {
4540 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4541 }
weili44f8faf2016-06-01 14:03:56 -07004542 pNode->m_pNext = nullptr;
4543 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004544 }
weili44f8faf2016-06-01 14:03:56 -07004545 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004546 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004547 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004548 m_pDocument->AddPurgeNode(pNode);
4549 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4550 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004551 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4552 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004553 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07004554 CFDE_XMLElement* pXMLElement =
4555 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004556 CFX_WideStringC wsAttributeName =
4557 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004558 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004559 }
4560 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004561 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -07004562 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004563 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4564 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004565 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004566 }
4567 pNode->m_pXMLNode = pNewXMLElement;
4568 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4569 } else {
4570 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4571 }
dsinclairc5a8f212016-06-20 11:11:12 -07004572 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004573 }
tsepezd19e9122016-11-02 15:43:18 -07004574 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004575}
dsinclair5b36f0a2016-07-19 10:56:23 -07004576
Dan Sinclair1770c022016-03-14 14:14:16 -04004577CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004578 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004579}
dsinclair5b36f0a2016-07-19 10:56:23 -07004580
tsepez736f28a2016-03-25 14:19:51 -07004581CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004582 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4583 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4584 if (pNode->GetNameHash() == dwNameHash) {
4585 return pNode;
4586 }
4587 }
weili44f8faf2016-06-01 14:03:56 -07004588 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004589}
dsinclair5b36f0a2016-07-19 10:56:23 -07004590
dsinclair41cb62e2016-06-23 09:20:32 -07004591CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004592 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4593 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004594 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004595 return pNode;
4596 }
4597 }
weili44f8faf2016-06-01 14:03:56 -07004598 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004599}
dsinclair5b36f0a2016-07-19 10:56:23 -07004600
tsepez736f28a2016-03-25 14:19:51 -07004601CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004602 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4603 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4604 if (pNode->GetNameHash() == dwNameHash) {
4605 return pNode;
4606 }
4607 }
weili44f8faf2016-06-01 14:03:56 -07004608 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004609}
dsinclair5b36f0a2016-07-19 10:56:23 -07004610
Dan Sinclair1770c022016-03-14 14:14:16 -04004611CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4612 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004613 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004614}
dsinclair5b36f0a2016-07-19 10:56:23 -07004615
dsinclair41cb62e2016-06-23 09:20:32 -07004616CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004617 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4618 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004619 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004620 return pNode;
4621 }
4622 }
weili44f8faf2016-06-01 14:03:56 -07004623 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004624}
dsinclair5b36f0a2016-07-19 10:56:23 -07004625
Dan Sinclair1770c022016-03-14 14:14:16 -04004626int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004627 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004628 if (!pScriptContext) {
4629 return -1;
4630 }
4631 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4632}
dsinclair5b36f0a2016-07-19 10:56:23 -07004633
Dan Sinclair1770c022016-03-14 14:14:16 -04004634int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004635 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004636 if (!pScriptContext) {
4637 return -1;
4638 }
4639 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4640}
dsinclair5b36f0a2016-07-19 10:56:23 -07004641
Dan Sinclair1770c022016-03-14 14:14:16 -04004642void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004643 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004644 if (!pScriptContext) {
4645 return;
4646 }
4647 pScriptContext->GetSomExpression(this, wsSOMExpression);
4648}
dsinclair5b36f0a2016-07-19 10:56:23 -07004649
Dan Sinclair1770c022016-03-14 14:14:16 -04004650CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004651 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004652 if (m_ePacket == XFA_XDPPACKET_Form) {
4653 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004654 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004655 return pInstanceMgr;
4656 }
4657 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4658 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004659 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004660 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004661 pNode->m_dwNameHash != m_dwNameHash) {
4662 break;
4663 }
dsinclair56a8b192016-06-21 14:15:25 -07004664 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004665 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4666 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4667 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4668 wsInstName.Mid(1) == wsName) {
4669 pInstanceMgr = pNode;
4670 }
4671 break;
4672 }
4673 }
4674 }
4675 return pInstanceMgr;
4676}
dsinclair5b36f0a2016-07-19 10:56:23 -07004677
Dan Sinclair1770c022016-03-14 14:14:16 -04004678CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004679 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004680}
dsinclair5b36f0a2016-07-19 10:56:23 -07004681
dsinclairc5a8f212016-06-20 11:11:12 -07004682bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4683 if (m_uNodeFlags & dwFlag)
4684 return true;
4685 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4686 return m_pParent && m_pParent->HasFlag(dwFlag);
4687 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004688}
thestigb1a59592016-04-14 18:29:56 -07004689
4690void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004691 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004692 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004693 if (pNotify) {
4694 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004695 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004696 }
dsinclairc5a8f212016-06-20 11:11:12 -07004697 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004698}
thestigb1a59592016-04-14 18:29:56 -07004699
4700void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004701 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004702}
4703
tsepezd19e9122016-11-02 15:43:18 -07004704bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004705 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4706}
thestigb1a59592016-04-14 18:29:56 -07004707
4708void CXFA_Node::OnRemoved(bool bNotify) {
4709 if (!bNotify)
4710 return;
4711
dsinclaira1b07722016-07-11 08:20:58 -07004712 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004713 if (pNotify)
4714 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004715}
thestigb1a59592016-04-14 18:29:56 -07004716
4717void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004718 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004719 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004720 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004721 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004722 }
4723 }
4724}
thestigb1a59592016-04-14 18:29:56 -07004725
Dan Sinclair1770c022016-03-14 14:14:16 -04004726void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004727 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004728 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004729 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004730 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004731 }
4732}
thestigb1a59592016-04-14 18:29:56 -07004733
Dan Sinclair1770c022016-03-14 14:14:16 -04004734int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004735 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004736 int32_t iRet = XFA_EVENTERROR_NotExist;
4737 const XFA_ExecEventParaInfo* eventParaInfo =
4738 GetEventParaInfoByName(wsEventName);
4739 if (eventParaInfo) {
4740 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004741 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004742 if (!pNotify) {
4743 return iRet;
4744 }
4745 if (validFlags == 1) {
4746 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4747 } else if (validFlags == 2) {
4748 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004749 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004750 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004751 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004752 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004753 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004754 }
4755 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004756 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004757 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004758 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004759 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004760 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004761 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004762 }
4763 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004764 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004765 }
4766 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004767 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004768 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004769 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004770 }
4771 } else if (validFlags == 6) {
4772 CXFA_WidgetData* pWidgetData = GetWidgetData();
4773 if (pWidgetData) {
4774 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004775 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004776 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004777 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004778 }
4779 }
4780 } else if (validFlags == 7) {
4781 CXFA_WidgetData* pWidgetData = GetWidgetData();
4782 if (pWidgetData) {
4783 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004784 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004785 (!pWidgetData->IsListBox())) {
4786 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004787 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004788 }
4789 }
4790 }
4791 }
4792 return iRet;
4793}
dsinclair5b36f0a2016-07-19 10:56:23 -07004794
Dan Sinclair1770c022016-03-14 14:14:16 -04004795void CXFA_Node::UpdateNameHash() {
4796 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004797 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004798 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004799 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004800 wsName = GetCData(XFA_ATTRIBUTE_Name);
4801 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004802 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004803 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004804 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004805 }
4806}
dsinclair5b36f0a2016-07-19 10:56:23 -07004807
dsinclairae95f762016-03-29 16:58:29 -07004808CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004809 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004810 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
dsinclairae95f762016-03-29 16:58:29 -07004811 m_pXMLNode = new CFDE_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004812 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004813 }
4814 return m_pXMLNode;
4815}
dsinclair5b36f0a2016-07-19 10:56:23 -07004816
tsepezd19e9122016-11-02 15:43:18 -07004817bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004818 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004819 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004820}
4821
4822XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4823 if (!m_pMapModuleData)
4824 m_pMapModuleData = new XFA_MAPMODULEDATA;
4825 return m_pMapModuleData;
4826}
4827
4828XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4829 return m_pMapModuleData;
4830}
4831
4832void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4833 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004834 pModule->m_ValueMap[pKey] = pValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04004835}
4836
tsepezd19e9122016-11-02 15:43:18 -07004837bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
tsepez6bb3b892017-01-05 12:18:41 -08004838 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004839 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004840 if (pModule) {
4841 auto it = pModule->m_ValueMap.find(pKey);
4842 if (it != pModule->m_ValueMap.end()) {
4843 pValue = it->second;
4844 return true;
4845 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004846 }
tsepez6bb3b892017-01-05 12:18:41 -08004847 if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4848 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004849 }
tsepezd19e9122016-11-02 15:43:18 -07004850 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004851}
dsinclair5b36f0a2016-07-19 10:56:23 -07004852
Dan Sinclair1770c022016-03-14 14:14:16 -04004853void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004854 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair812e96c2017-03-13 16:43:37 -04004855 wsValue.GetLength() * sizeof(wchar_t));
Dan Sinclair1770c022016-03-14 14:14:16 -04004856}
dsinclair5b36f0a2016-07-19 10:56:23 -07004857
tsepezd19e9122016-11-02 15:43:18 -07004858bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004859 void* pValue;
4860 int32_t iBytes;
4861 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004862 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004863 }
Dan Sinclair812e96c2017-03-13 16:43:37 -04004864 wsValue = CFX_WideStringC((const wchar_t*)pValue, iBytes / sizeof(wchar_t));
tsepezd19e9122016-11-02 15:43:18 -07004865 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004866}
dsinclair5b36f0a2016-07-19 10:56:23 -07004867
Dan Sinclair1770c022016-03-14 14:14:16 -04004868void CXFA_Node::SetMapModuleBuffer(
4869 void* pKey,
4870 void* pValue,
4871 int32_t iBytes,
4872 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4873 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4874 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004875 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004876 pBuffer =
4877 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4878 } else if (pBuffer->iBytes != iBytes) {
4879 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4880 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4881 }
4882 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4883 sizeof(XFA_MAPDATABLOCK) + iBytes);
4884 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4885 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4886 }
weili44f8faf2016-06-01 14:03:56 -07004887 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04004888 return;
weili44f8faf2016-06-01 14:03:56 -07004889
Dan Sinclair1770c022016-03-14 14:14:16 -04004890 pBuffer->pCallbackInfo = pCallbackInfo;
4891 pBuffer->iBytes = iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004892 memcpy(pBuffer->GetData(), pValue, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004893}
dsinclair5b36f0a2016-07-19 10:56:23 -07004894
tsepezd19e9122016-11-02 15:43:18 -07004895bool CXFA_Node::GetMapModuleBuffer(void* pKey,
4896 void*& pValue,
4897 int32_t& iBytes,
4898 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07004899 XFA_MAPDATABLOCK* pBuffer = nullptr;
tsepez6bb3b892017-01-05 12:18:41 -08004900 for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004901 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004902 if (pModule) {
4903 auto it = pModule->m_BufferMap.find(pKey);
4904 if (it != pModule->m_BufferMap.end()) {
4905 pBuffer = it->second;
4906 break;
4907 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004908 }
tsepez6bb3b892017-01-05 12:18:41 -08004909 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4910 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004911 }
tsepez6bb3b892017-01-05 12:18:41 -08004912 if (!pBuffer)
tsepezd19e9122016-11-02 15:43:18 -07004913 return false;
tsepez6bb3b892017-01-05 12:18:41 -08004914
Dan Sinclair1770c022016-03-14 14:14:16 -04004915 pValue = pBuffer->GetData();
4916 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07004917 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004918}
dsinclair5b36f0a2016-07-19 10:56:23 -07004919
tsepezd19e9122016-11-02 15:43:18 -07004920bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
tsepez6bb3b892017-01-05 12:18:41 -08004921 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004922 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004923 if (pModule) {
4924 auto it1 = pModule->m_ValueMap.find(pKey);
4925 if (it1 != pModule->m_ValueMap.end())
4926 return true;
4927
4928 auto it2 = pModule->m_BufferMap.find(pKey);
4929 if (it2 != pModule->m_BufferMap.end())
4930 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004931 }
tsepez6bb3b892017-01-05 12:18:41 -08004932 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4933 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004934 }
tsepezd19e9122016-11-02 15:43:18 -07004935 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004936}
dsinclair5b36f0a2016-07-19 10:56:23 -07004937
Dan Sinclair1770c022016-03-14 14:14:16 -04004938void CXFA_Node::RemoveMapModuleKey(void* pKey) {
4939 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
4940 if (!pModule)
4941 return;
4942
4943 if (pKey) {
tsepez6bb3b892017-01-05 12:18:41 -08004944 auto it = pModule->m_BufferMap.find(pKey);
4945 if (it != pModule->m_BufferMap.end()) {
4946 XFA_MAPDATABLOCK* pBuffer = it->second;
Dan Sinclair1770c022016-03-14 14:14:16 -04004947 if (pBuffer) {
tsepez6bb3b892017-01-05 12:18:41 -08004948 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
Dan Sinclair1770c022016-03-14 14:14:16 -04004949 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004950 FX_Free(pBuffer);
4951 }
tsepez6bb3b892017-01-05 12:18:41 -08004952 pModule->m_BufferMap.erase(it);
Dan Sinclair1770c022016-03-14 14:14:16 -04004953 }
tsepez6bb3b892017-01-05 12:18:41 -08004954 pModule->m_ValueMap.erase(pKey);
4955 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04004956 }
tsepez6bb3b892017-01-05 12:18:41 -08004957
4958 for (auto& pair : pModule->m_BufferMap) {
4959 XFA_MAPDATABLOCK* pBuffer = pair.second;
4960 if (pBuffer) {
4961 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
4962 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4963 FX_Free(pBuffer);
4964 }
4965 }
4966 pModule->m_BufferMap.clear();
4967 pModule->m_ValueMap.clear();
4968 delete pModule;
Dan Sinclair1770c022016-03-14 14:14:16 -04004969}
dsinclair5b36f0a2016-07-19 10:56:23 -07004970
tsepez6bb3b892017-01-05 12:18:41 -08004971void CXFA_Node::MergeAllData(void* pDstModule) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004972 XFA_MAPMODULEDATA* pDstModuleData =
4973 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
4974 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004975 if (!pSrcModuleData)
Dan Sinclair1770c022016-03-14 14:14:16 -04004976 return;
tsepez6bb3b892017-01-05 12:18:41 -08004977
4978 for (const auto& pair : pSrcModuleData->m_ValueMap)
4979 pDstModuleData->m_ValueMap[pair.first] = pair.second;
4980
4981 for (const auto& pair : pSrcModuleData->m_BufferMap) {
4982 XFA_MAPDATABLOCK* pSrcBuffer = pair.second;
4983 XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first];
Dan Sinclair1770c022016-03-14 14:14:16 -04004984 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
4985 !pSrcBuffer->pCallbackInfo->pCopy) {
tsepez6bb3b892017-01-05 12:18:41 -08004986 if (pDstBuffer) {
4987 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
4988 pDstModuleData->m_BufferMap.erase(pair.first);
Dan Sinclair1770c022016-03-14 14:14:16 -04004989 }
4990 continue;
4991 }
tsepez6bb3b892017-01-05 12:18:41 -08004992 if (!pDstBuffer) {
4993 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
Dan Sinclair1770c022016-03-14 14:14:16 -04004994 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08004995 } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) {
4996 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
4997 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004998 }
tsepez6bb3b892017-01-05 12:18:41 -08004999 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
5000 uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5001 } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5002 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005003 }
tsepez6bb3b892017-01-05 12:18:41 -08005004 if (!pDstBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005005 continue;
5006 }
tsepez6bb3b892017-01-05 12:18:41 -08005007 pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5008 pDstBuffer->iBytes = pSrcBuffer->iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04005009 memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08005010 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) {
5011 pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005012 }
5013 }
5014}
dsinclair5b36f0a2016-07-19 10:56:23 -07005015
Dan Sinclair1770c022016-03-14 14:14:16 -04005016void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5017 if (!pDstModule) {
5018 return;
5019 }
tsepezd19e9122016-11-02 15:43:18 -07005020 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005021 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005022 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005023 }
dsinclair070fcdf2016-06-22 22:04:54 -07005024 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005025 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005026 }
weili44f8faf2016-06-01 14:03:56 -07005027 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5028 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005029 if (bNeedMove) {
5030 pSrcModuleData = GetMapModuleData();
5031 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005032 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005033 }
5034 pDstModuleData = pDstModule->CreateMapModuleData();
5035 }
5036 if (bNeedMove) {
tsepez6bb3b892017-01-05 12:18:41 -08005037 auto it = pSrcModuleData->m_BufferMap.find(pKey);
5038 if (it != pSrcModuleData->m_BufferMap.end()) {
5039 XFA_MAPDATABLOCK* pBufferBlockData = it->second;
5040 if (pBufferBlockData) {
5041 pSrcModuleData->m_BufferMap.erase(pKey);
5042 pDstModuleData->m_BufferMap[pKey] = pBufferBlockData;
5043 }
Dan Sinclair1770c022016-03-14 14:14:16 -04005044 }
5045 }
dsinclairc5a8f212016-06-20 11:11:12 -07005046 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005047 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005048 CFX_WideString wsFormatValue(wsValue);
5049 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5050 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005051 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005052 }
tsepezd19e9122016-11-02 15:43:18 -07005053 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005054 }
5055}
dsinclair5b36f0a2016-07-19 10:56:23 -07005056
Dan Sinclair1770c022016-03-14 14:14:16 -04005057void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5058 CXFA_Node* pDstModule,
5059 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005060 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005061 if (!pSrcModule || !pDstModule || !pKey) {
5062 return;
5063 }
5064 if (bRecursive) {
5065 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5066 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5067 for (; pSrcChild && pDstChild;
5068 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5069 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005070 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005071 }
5072 }
5073 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5074}
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05005075
5076void CXFA_Node::ThrowMissingPropertyException(
5077 const CFX_WideString& obj,
5078 const CFX_WideString& prop) const {
5079 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(),
5080 prop.c_str());
5081}
5082
5083void CXFA_Node::ThrowTooManyOccurancesException(
5084 const CFX_WideString& obj) const {
5085 ThrowException(
5086 L"The element [%s] has violated its allowable number of occurrences.",
5087 obj.c_str());
5088}