blob: 2079127dc9e785163696776f6bd4008dfc7d9b5f [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) {
dsinclair86fad992016-05-31 11:34:04 -0700999 std::unique_ptr<CFXJSE_Value> pValue(
1000 new 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 }
1274 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001275 bool bIgnoreRoot = true;
1276 bool bOverwrite = 0;
1277 wsExpression =
1278 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1279 if (wsExpression.IsEmpty())
Tom Sepezd3743ea2016-05-16 15:56:53 -07001280 return;
weili44f8faf2016-06-01 14:03:56 -07001281 if (iLength >= 2)
1282 bIgnoreRoot = !!pArguments->GetInt32(1);
1283 if (iLength >= 3)
1284 bOverwrite = !!pArguments->GetInt32(2);
dsinclaira1b07722016-07-11 08:20:58 -07001285 std::unique_ptr<CXFA_SimpleParser> pParser(
1286 new CXFA_SimpleParser(m_pDocument, false));
weili44f8faf2016-06-01 14:03:56 -07001287 if (!pParser)
Dan Sinclair1770c022016-03-14 14:14:16 -04001288 return;
weili44f8faf2016-06-01 14:03:56 -07001289 CFDE_XMLNode* pXMLNode = nullptr;
1290 int32_t iParserStatus =
1291 pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
1292 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
1293 return;
dsinclairae95f762016-03-29 16:58:29 -07001294 if (bIgnoreRoot &&
1295 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
1296 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
weili44f8faf2016-06-01 14:03:56 -07001297 bIgnoreRoot = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001298 }
tsepezd19e9122016-11-02 15:43:18 -07001299 CXFA_Node* pFakeRoot = Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001300 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
1301 if (!wsContentType.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07001302 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
1303 CFX_WideString(wsContentType));
Dan Sinclair1770c022016-03-14 14:14:16 -04001304 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001305
1306 std::unique_ptr<CFDE_XMLNode> pFakeXMLRoot(pFakeRoot->GetXMLMappingNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001307 if (!pFakeXMLRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001308 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
Dan Sinclair93bfc262017-04-04 15:10:00 -04001309 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone() : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001310 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001311 if (!pFakeXMLRoot) {
1312 pFakeXMLRoot =
1313 pdfium::MakeUnique<CFDE_XMLElement>(CFX_WideString(GetClassName()));
1314 }
dsinclair017052a2016-06-28 07:43:51 -07001315
Dan Sinclair1770c022016-03-14 14:14:16 -04001316 if (bIgnoreRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001317 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001318 while (pXMLChild) {
dsinclairae95f762016-03-29 16:58:29 -07001319 CFDE_XMLNode* pXMLSibling =
1320 pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001321 pXMLNode->RemoveChildNode(pXMLChild);
1322 pFakeXMLRoot->InsertChildNode(pXMLChild);
1323 pXMLChild = pXMLSibling;
1324 }
1325 } else {
dsinclairae95f762016-03-29 16:58:29 -07001326 CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001327 if (pXMLParent) {
1328 pXMLParent->RemoveChildNode(pXMLNode);
1329 }
1330 pFakeXMLRoot->InsertChildNode(pXMLNode);
1331 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001332 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001333 pFakeRoot = pParser->GetRootNode();
Dan Sinclair93bfc262017-04-04 15:10:00 -04001334 if (!pFakeRoot)
1335 return;
1336
1337 if (bOverwrite) {
1338 CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1339 CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1340 int32_t index = 0;
1341 while (pNewChild) {
1342 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1343 pFakeRoot->RemoveChild(pNewChild);
1344 InsertChild(index++, pNewChild);
1345 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
1346 pNewChild = pItem;
Dan Sinclair1770c022016-03-14 14:14:16 -04001347 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001348 while (pChild) {
1349 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1350 RemoveChild(pChild);
1351 pFakeRoot->InsertChild(pChild);
1352 pChild = pItem;
Dan Sinclair1770c022016-03-14 14:14:16 -04001353 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001354 if (GetPacketID() == XFA_XDPPACKET_Form &&
1355 GetElementType() == XFA_Element::ExData) {
1356 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
1357 SetXMLMappingNode(pFakeXMLRoot.release());
1358 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
1359 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent))
1360 pFakeXMLRoot.reset(pTempXMLNode);
1361 else
1362 pFakeXMLRoot = nullptr;
1363 }
1364 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001365 } else {
Dan Sinclair93bfc262017-04-04 15:10:00 -04001366 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1367 while (pChild) {
1368 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1369 pFakeRoot->RemoveChild(pChild);
1370 InsertChild(pChild);
1371 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
1372 pChild = pItem;
1373 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001374 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001375 if (pFakeXMLRoot) {
1376 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot.release());
1377 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
1378 }
1379 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001380}
weili44f8faf2016-06-01 14:03:56 -07001381
Dan Sinclair1770c022016-03-14 14:14:16 -04001382void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
weili44f8faf2016-06-01 14:03:56 -07001383 // TODO(weili): Check whether we need to implement this, pdfium:501.
Dan Sinclair1770c022016-03-14 14:14:16 -04001384}
1385
1386void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1387 int32_t iLength = pArguments->GetLength();
1388 if (iLength < 0 || iLength > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001389 ThrowParamCountMismatchException(L"saveXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001390 return;
1391 }
weili44f8faf2016-06-01 14:03:56 -07001392 bool bPrettyMode = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001393 if (iLength == 1) {
weili65be4b12016-05-25 15:47:43 -07001394 if (pArguments->GetUTF8String(0) != "pretty") {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001395 ThrowArgumentMismatchException();
Dan Sinclair1770c022016-03-14 14:14:16 -04001396 return;
1397 }
weili44f8faf2016-06-01 14:03:56 -07001398 bPrettyMode = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001399 }
1400 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
weili65be4b12016-05-25 15:47:43 -07001401 if (GetPacketID() == XFA_XDPPACKET_Form ||
1402 GetPacketID() == XFA_XDPPACKET_Datasets) {
1403 CFDE_XMLNode* pElement = nullptr;
1404 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1405 pElement = GetXMLMappingNode();
1406 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
dsinclairf27aeec2016-06-07 19:36:18 -07001407 pArguments->GetReturnValue()->SetString(bsXMLHeader);
weili65be4b12016-05-25 15:47:43 -07001408 return;
1409 }
1410 XFA_DataExporter_DealWithDataGroupNode(this);
1411 }
tsepez833619b2016-12-07 09:21:17 -08001412 CFX_RetainPtr<IFX_MemoryStream> pMemoryStream =
1413 IFX_MemoryStream::Create(true);
1414
1415 // Note: ambiguious below without static_cast.
tsepez7cda31a2016-12-07 12:10:20 -08001416 CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream(
1417 CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream),
1418 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
tsepez833619b2016-12-07 09:21:17 -08001419
Dan Sinclair1770c022016-03-14 14:14:16 -04001420 if (!pStream) {
dsinclairf27aeec2016-06-07 19:36:18 -07001421 pArguments->GetReturnValue()->SetString(bsXMLHeader);
Dan Sinclair1770c022016-03-14 14:14:16 -04001422 return;
1423 }
1424 pStream->SetCodePage(FX_CODEPAGE_UTF8);
dsinclair179bebb2016-04-05 11:02:18 -07001425 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
weili65be4b12016-05-25 15:47:43 -07001426 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepez7cda31a2016-12-07 12:10:20 -08001427 XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001428 else
tsepez7cda31a2016-12-07 12:10:20 -08001429 pElement->SaveXMLNode(pStream);
weili65be4b12016-05-25 15:47:43 -07001430 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1431 // For now, just put it here to avoid unused variable warning.
1432 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001433 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001434 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001435 return;
1436 }
dsinclairf27aeec2016-06-07 19:36:18 -07001437 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001438}
1439
1440void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1441 int32_t iLength = pArguments->GetLength();
1442 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001443 ThrowParamCountMismatchException(L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001444 return;
1445 }
tsepez6fe7d212016-04-06 10:51:14 -07001446 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001447 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001448 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001449 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001450 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001451}
weili60607c32016-05-26 11:53:12 -07001452
Dan Sinclair1770c022016-03-14 14:14:16 -04001453void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1454 int32_t iLength = pArguments->GetLength();
1455 if (iLength != 1 && iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001456 ThrowParamCountMismatchException(L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001457 return;
1458 }
weili60607c32016-05-26 11:53:12 -07001459 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001460 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001461 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1462 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001463 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001464 // TODO(weili): check whether we need to implement this, pdfium:501.
1465 // For now, just put the variables here to avoid unused variable warning.
1466 (void)pNode;
1467 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001468}
weili60607c32016-05-26 11:53:12 -07001469
dsinclair12a6b0c2016-05-26 11:14:08 -07001470void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001471 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001472 XFA_ATTRIBUTE eAttribute) {
1473 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001474 ThrowInvalidPropertyException();
1475 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001476 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001477
1478 CFX_WideString wsNameSpace;
1479 TryNamespace(wsNameSpace);
Tom Sepezf0b65542017-02-13 10:26:01 -08001480 pValue->SetString(wsNameSpace.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001481}
weili44f8faf2016-06-01 14:03:56 -07001482
dsinclair12a6b0c2016-05-26 11:14:08 -07001483void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001484 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001485 XFA_ATTRIBUTE eAttribute) {
1486 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001487 ThrowInvalidPropertyException();
1488 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001489 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001490 pValue->Assign(
1491 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001492}
weili44f8faf2016-06-01 14:03:56 -07001493
dsinclair12a6b0c2016-05-26 11:14:08 -07001494void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001495 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001496 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001497 if (bSetting) {
1498 ThrowInvalidPropertyException();
1499 return;
1500 }
1501 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001502}
weili44f8faf2016-06-01 14:03:56 -07001503
dsinclair12a6b0c2016-05-26 11:14:08 -07001504void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001505 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001506 XFA_ATTRIBUTE eAttribute) {
1507 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001508 ThrowInvalidPropertyException();
1509 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001510 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001511 if (GetElementType() == XFA_Element::Subform) {
1512 pValue->SetBoolean(false);
1513 return;
1514 }
1515 CFX_WideString strValue;
1516 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001517}
weili44f8faf2016-06-01 14:03:56 -07001518
dsinclair12a6b0c2016-05-26 11:14:08 -07001519void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001520 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001521 XFA_ATTRIBUTE eAttribute) {
1522 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001523 ThrowInvalidPropertyException();
1524 return;
1525 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001526 std::vector<CXFA_Node*> properties =
1527 GetNodeList(XFA_NODEFILTER_OneOfProperty);
1528 if (!properties.empty()) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001529 pValue->Assign(
Tom Sepezf8a94392017-03-14 12:13:22 -07001530 m_pDocument->GetScriptContext()->GetJSValueFromMap(properties.front()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001531 }
1532}
weili44f8faf2016-06-01 14:03:56 -07001533
Dan Sinclair1770c022016-03-14 14:14:16 -04001534void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001535
Dan Sinclair1770c022016-03-14 14:14:16 -04001536void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1537 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001538 pArguments->GetReturnValue()->SetObject(
1539 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001540}
1541void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1542}
dsinclair5b36f0a2016-07-19 10:56:23 -07001543
Dan Sinclair1770c022016-03-14 14:14:16 -04001544void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1545 Script_Template_CreateNode(pArguments);
1546}
dsinclair5b36f0a2016-07-19 10:56:23 -07001547
Dan Sinclair1770c022016-03-14 14:14:16 -04001548void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1549 int32_t iLength = pArguments->GetLength();
1550 if (iLength < 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001551 ThrowParamCountMismatchException(L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001552 return;
1553 }
1554 CFX_WideString wsNameSpace;
1555 if (iLength >= 1) {
1556 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001557 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001558 }
1559 CFX_WideString wsNodeNameSpace;
1560 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001561 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001562 if (pValue)
1563 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001564}
dsinclair5b36f0a2016-07-19 10:56:23 -07001565
dsinclair12a6b0c2016-05-26 11:14:08 -07001566void CXFA_Node::Script_ModelClass_Context(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_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001571 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001572 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001573
dsinclair12a6b0c2016-05-26 11:14:08 -07001574void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001575 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001576 XFA_ATTRIBUTE eAttribute) {
1577 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001578 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001579 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001580 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001581 }
1582}
dsinclair5b36f0a2016-07-19 10:56:23 -07001583
dsinclair12a6b0c2016-05-26 11:14:08 -07001584void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001585 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001586 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001587 if (bSetting) {
1588 ThrowInvalidPropertyException();
1589 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001590 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001591 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001592}
dsinclair5b36f0a2016-07-19 10:56:23 -07001593
dsinclair12a6b0c2016-05-26 11:14:08 -07001594void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001595 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001596 XFA_ATTRIBUTE eAttribute) {
1597 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001598 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001599 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001600 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001601 }
1602}
dsinclair5b36f0a2016-07-19 10:56:23 -07001603
dsinclair12a6b0c2016-05-26 11:14:08 -07001604void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001605 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001606 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001607 if (bSetting) {
1608 ThrowInvalidPropertyException();
1609 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001610 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001611 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001612}
thestigb1a59592016-04-14 18:29:56 -07001613
Dan Sinclair1770c022016-03-14 14:14:16 -04001614void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001615 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001616 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001617 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001618 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001619 return;
thestigb1a59592016-04-14 18:29:56 -07001620
dsinclaira1b07722016-07-11 08:20:58 -07001621 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001622 if (!pNotify)
1623 return;
1624
1625 uint32_t dwPacket = GetPacketID();
1626 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1627 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001628 return;
1629 }
thestigb1a59592016-04-14 18:29:56 -07001630
1631 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001632 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001633 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001634 bNeedFindContainer = true;
1635 pNotify->OnValueChanged(this, eAttribute, this,
1636 GetNodeItem(XFA_NODEITEM_Parent));
1637 break;
dsinclair56a8b192016-06-21 14:15:25 -07001638 case XFA_Element::Font:
1639 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001640 bNeedFindContainer = true;
1641 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001642 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001643 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1644 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1645 } else {
1646 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1647 }
1648 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001649 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001650 bNeedFindContainer = true;
1651 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001652 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001653 if (pParentNode->IsContainerNode()) {
1654 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001655 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001656 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1657 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1658 } else {
1659 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001660 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001661 pNotify->OnValueChanged(this, eAttribute, pNode,
1662 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001663 }
thestigb1a59592016-04-14 18:29:56 -07001664 }
1665 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001666 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001667 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001668 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001669 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1670 eUIType == XFA_Element::NumericEdit ||
1671 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001672 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001673 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001674 pNotify->OnValueChanged(this, eAttribute, pUINode,
1675 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001676 }
thestigb1a59592016-04-14 18:29:56 -07001677 }
1678 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001679 case XFA_Element::Button:
1680 case XFA_Element::Barcode:
1681 case XFA_Element::ChoiceList:
1682 case XFA_Element::DateTimeEdit:
1683 case XFA_Element::NumericEdit:
1684 case XFA_Element::PasswordEdit:
1685 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001686 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1687 if (pUINode) {
1688 pNotify->OnValueChanged(this, eAttribute, pUINode,
1689 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1690 }
1691 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001692 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001693 bNeedFindContainer = true;
1694 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1695 if (pUINode) {
1696 pNotify->OnValueChanged(this, eAttribute, pUINode,
1697 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1698 }
1699 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001700 case XFA_Element::Keep:
1701 case XFA_Element::Bookend:
1702 case XFA_Element::Break:
1703 case XFA_Element::BreakAfter:
1704 case XFA_Element::BreakBefore:
1705 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001706 bNeedFindContainer = true;
1707 break;
dsinclair56a8b192016-06-21 14:15:25 -07001708 case XFA_Element::Area:
1709 case XFA_Element::Draw:
1710 case XFA_Element::ExclGroup:
1711 case XFA_Element::Field:
1712 case XFA_Element::Subform:
1713 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001714 pLayoutPro->AddChangedContainer(this);
1715 pNotify->OnValueChanged(this, eAttribute, this, this);
1716 break;
dsinclair56a8b192016-06-21 14:15:25 -07001717 case XFA_Element::Sharptext:
1718 case XFA_Element::Sharpxml:
1719 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001720 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1721 if (!pTextNode) {
1722 return;
1723 }
1724 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1725 if (!pValueNode) {
1726 return;
1727 }
dsinclair41cb62e2016-06-23 09:20:32 -07001728 XFA_Element eType = pValueNode->GetElementType();
1729 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001730 bNeedFindContainer = true;
1731 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1732 if (pNode && pNode->IsContainerNode()) {
1733 if (bScriptModify) {
1734 pValueNode = pNode;
1735 }
1736 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1737 } else {
1738 pNotify->OnValueChanged(this, eAttribute, pNode,
1739 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001740 }
thestigb1a59592016-04-14 18:29:56 -07001741 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001742 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001743 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1744 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001745 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001746 }
1747 }
thestigb1a59592016-04-14 18:29:56 -07001748 }
1749 } break;
1750 default:
1751 break;
1752 }
1753 if (bNeedFindContainer) {
1754 CXFA_Node* pParent = this;
1755 while (pParent) {
1756 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001757 break;
thestigb1a59592016-04-14 18:29:56 -07001758
1759 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001760 }
thestigb1a59592016-04-14 18:29:56 -07001761 if (pParent) {
1762 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001763 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001764 }
1765}
thestigb1a59592016-04-14 18:29:56 -07001766
dsinclair12a6b0c2016-05-26 11:14:08 -07001767void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001768 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001769 XFA_ATTRIBUTE eAttribute) {
1770 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001771 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001772 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001773 if (eAttribute == XFA_ATTRIBUTE_Use &&
1774 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001775 CXFA_Node* pTemplateNode =
1776 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1777 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001778 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1779 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001780
1781 CFX_WideString wsID;
1782 CFX_WideString wsSOM;
1783 if (!wsValue.IsEmpty()) {
1784 if (wsValue[0] == '#') {
1785 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001786 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001787 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001788 }
1789 }
weili44f8faf2016-06-01 14:03:56 -07001790 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001791 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001792 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001793 XFA_RESOLVENODE_Attributes |
1794 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1795 XFA_RESOLVENODE_Siblings;
1796 XFA_RESOLVENODE_RS resoveNodeRS;
1797 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001798 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Tom Sepezf8a94392017-03-14 12:13:22 -07001799 if (iRet > 0 && resoveNodeRS.objects.front()->IsNode()) {
1800 pProtoNode = resoveNodeRS.objects.front()->AsNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001801 }
1802 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001803 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001804 }
1805 if (pProtoNode) {
1806 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1807 while (pHeadChild) {
1808 CXFA_Node* pSibling =
1809 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1810 RemoveChild(pHeadChild);
1811 pHeadChild = pSibling;
1812 }
tsepezd19e9122016-11-02 15:43:18 -07001813 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001814 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1815 while (pHeadChild) {
1816 CXFA_Node* pSibling =
1817 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1818 pProtoForm->RemoveChild(pHeadChild);
1819 InsertChild(pHeadChild);
1820 pHeadChild = pSibling;
1821 }
1822 m_pDocument->RemovePurgeNode(pProtoForm);
1823 delete pProtoForm;
1824 }
1825 }
1826 } else {
1827 CFX_WideString wsValue;
1828 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001829 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001830 }
1831}
dsinclair5b36f0a2016-07-19 10:56:23 -07001832
dsinclair12a6b0c2016-05-26 11:14:08 -07001833void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001834 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001835 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001836 if (bSetting) {
1837 ThrowInvalidPropertyException();
1838 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001839 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001840
1841 CFX_WideString wsValue;
1842 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001843 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001844}
dsinclair5b36f0a2016-07-19 10:56:23 -07001845
Dan Sinclair1770c022016-03-14 14:14:16 -04001846void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1847 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001848 if (argc != 0 && argc != 1) {
1849 ThrowParamCountMismatchException(L"execute");
1850 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001851 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001852 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001853}
dsinclair5b36f0a2016-07-19 10:56:23 -07001854
Dan Sinclair1770c022016-03-14 14:14:16 -04001855void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001856 if (pArguments->GetLength() != 0)
1857 ThrowParamCountMismatchException(L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001858}
dsinclair5b36f0a2016-07-19 10:56:23 -07001859
dsinclair12a6b0c2016-05-26 11:14:08 -07001860void CXFA_Node::Script_Delta_CurrentValue(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_SavedValue(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_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001869 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001870 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001871
dsinclair12a6b0c2016-05-26 11:14:08 -07001872void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001873 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001874 XFA_SOM_MESSAGETYPE iMessageType) {
1875 CXFA_WidgetData* pWidgetData = GetWidgetData();
1876 if (!pWidgetData) {
1877 return;
1878 }
tsepezd19e9122016-11-02 15:43:18 -07001879 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001880 CXFA_Validate validate = pWidgetData->GetValidate();
1881 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001882 validate = pWidgetData->GetValidate(true);
1883 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001884 }
1885 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001886 switch (iMessageType) {
1887 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001888 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001889 break;
1890 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001891 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001892 break;
1893 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001894 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001895 break;
1896 default:
1897 break;
1898 }
1899 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001900 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001901 if (!pNotify) {
1902 return;
1903 }
1904 pNotify->AddCalcValidate(this);
1905 }
1906 } else {
1907 CFX_WideString wsMessage;
1908 switch (iMessageType) {
1909 case XFA_SOM_ValidationMessage:
1910 validate.GetScriptMessageText(wsMessage);
1911 break;
1912 case XFA_SOM_FormatMessage:
1913 validate.GetFormatMessageText(wsMessage);
1914 break;
1915 case XFA_SOM_MandatoryMessage:
1916 validate.GetNullMessageText(wsMessage);
1917 break;
1918 default:
1919 break;
1920 }
Tom Sepezf0b65542017-02-13 10:26:01 -08001921 pValue->SetString(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001922 }
1923}
dsinclair5b36f0a2016-07-19 10:56:23 -07001924
dsinclair12a6b0c2016-05-26 11:14:08 -07001925void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001926 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001927 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001928 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001929}
dsinclair5b36f0a2016-07-19 10:56:23 -07001930
dsinclair12a6b0c2016-05-26 11:14:08 -07001931void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001932 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001933 XFA_ATTRIBUTE eAttribute) {
1934 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001935 ThrowInvalidPropertyException();
1936 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001937 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001938
1939 CXFA_WidgetData* pWidgetData = GetWidgetData();
1940 if (!pWidgetData) {
1941 pValue->SetInteger(0);
1942 return;
1943 }
1944 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001945}
dsinclair5b36f0a2016-07-19 10:56:23 -07001946
dsinclair12a6b0c2016-05-26 11:14:08 -07001947void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001948 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001949 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001950 XFA_Element eType = GetElementType();
1951 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001952 Script_Field_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::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001956 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001957 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001958 }
1959 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001960 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001961 return;
1962 }
1963 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001964 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07001965 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07001966 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07001967
Dan Sinclair1770c022016-03-14 14:14:16 -04001968 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07001969 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001970 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001971 CFX_WideString wsPicture;
Tom Sepezf8a94392017-03-14 12:13:22 -07001972 for (CXFA_Node* pFormNode : GetBindItems()) {
1973 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -04001974 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001975 pContainerWidgetData = pFormNode->GetContainerWidgetData();
1976 if (pContainerWidgetData) {
1977 pContainerWidgetData->GetPictureContent(wsPicture,
1978 XFA_VALUEPICTURE_DataBind);
1979 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001980 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -04001981 break;
weili44f8faf2016-06-01 14:03:56 -07001982 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001983 }
1984 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
1985 pContainerWidgetData = GetContainerWidgetData();
1986 }
1987 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07001988 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04001989 }
tsepezd19e9122016-11-02 15:43:18 -07001990 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001991 } else {
tsepezd19e9122016-11-02 15:43:18 -07001992 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07001993 if (content.IsEmpty() && eType != XFA_Element::Text &&
1994 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07001995 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07001996 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07001997 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07001998 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07001999 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002000 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002001 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002002 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002003 }
2004 }
2005}
dsinclair5b36f0a2016-07-19 10:56:23 -07002006
dsinclair12a6b0c2016-05-26 11:14:08 -07002007void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002008 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002009 XFA_ATTRIBUTE eAttribute) {
2010 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002011 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002012 return;
2013 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002014
tsepezd19e9122016-11-02 15:43:18 -07002015 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002016 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002017 pValue->SetNull();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002018 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002019 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002020 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002021}
dsinclair5b36f0a2016-07-19 10:56:23 -07002022
dsinclair12a6b0c2016-05-26 11:14:08 -07002023void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002024 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002025 XFA_ATTRIBUTE eAttribute) {
2026 if (bSetting) {
2027 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002028 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002029 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002030
tsepezb4c9f3f2016-04-13 15:41:21 -07002031 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002032 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002033 CFX_WideString wsFormatValue(wsNewValue);
2034 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2035 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002036 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002037 }
tsepezd19e9122016-11-02 15:43:18 -07002038 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002039 } else {
tsepezd19e9122016-11-02 15:43:18 -07002040 CFX_WideString wsValue = GetScriptContent(true);
dan sinclair65c7c232017-02-02 14:05:30 -08002041 pValue->SetBoolean(wsValue == L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002042 }
2043}
dsinclair2f5582f2016-06-09 11:48:23 -07002044
dsinclair12a6b0c2016-05-26 11:14:08 -07002045void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002046 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002047 XFA_ATTRIBUTE eAttribute) {
2048 CXFA_WidgetData* pWidgetData = GetWidgetData();
2049 if (!pWidgetData) {
2050 return;
2051 }
tsepezd19e9122016-11-02 15:43:18 -07002052 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002053 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002054 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002055 int32_t r = 0;
2056 int32_t g = 0;
2057 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002058 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002059 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2060 for (int32_t i = 0; i < iSize; ++i) {
2061 CXFA_Edge edge = border.GetEdge(i);
2062 edge.SetColor(rgb);
2063 }
2064 } else {
2065 CXFA_Edge edge = border.GetEdge(0);
2066 FX_ARGB color = edge.GetColor();
2067 int32_t a, r, g, b;
2068 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002069 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002070 strColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002071 pValue->SetString(strColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002072 }
2073}
dsinclair5b36f0a2016-07-19 10:56:23 -07002074
dsinclair12a6b0c2016-05-26 11:14:08 -07002075void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002076 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002077 XFA_ATTRIBUTE eAttribute) {
2078 CXFA_WidgetData* pWidgetData = GetWidgetData();
2079 if (!pWidgetData) {
2080 return;
2081 }
tsepezd19e9122016-11-02 15:43:18 -07002082 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002083 int32_t iSize = border.CountEdges();
2084 CFX_WideString wsThickness;
2085 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002086 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002087 for (int32_t i = 0; i < iSize; ++i) {
2088 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002089 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002090 edge.SetMSThickness(thickness);
2091 }
2092 } else {
2093 CXFA_Edge edge = border.GetEdge(0);
2094 CXFA_Measurement thickness = edge.GetMSThickness();
2095 thickness.ToString(wsThickness);
Tom Sepezf0b65542017-02-13 10:26:01 -08002096 pValue->SetString(wsThickness.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002097 }
2098}
dsinclair5b36f0a2016-07-19 10:56:23 -07002099
dsinclair12a6b0c2016-05-26 11:14:08 -07002100void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002101 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002102 XFA_ATTRIBUTE eAttribute) {
2103 CXFA_WidgetData* pWidgetData = GetWidgetData();
2104 if (!pWidgetData) {
2105 return;
2106 }
tsepezd19e9122016-11-02 15:43:18 -07002107 CXFA_Border border = pWidgetData->GetBorder(true);
2108 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002109 CXFA_Node* pNode = borderfill.GetNode();
2110 if (!pNode) {
2111 return;
2112 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002113 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002114 int32_t r;
2115 int32_t g;
2116 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002117 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002118 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2119 borderfill.SetColor(color);
2120 } else {
2121 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002122 int32_t a;
2123 int32_t r;
2124 int32_t g;
2125 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002126 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002127 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002128 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002129 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002130 }
2131}
dsinclair5b36f0a2016-07-19 10:56:23 -07002132
dsinclair12a6b0c2016-05-26 11:14:08 -07002133void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002134 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002135 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002136 if (bSetting) {
2137 ThrowInvalidPropertyException();
2138 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002139 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002140
2141 CXFA_Node* pDataNode = GetBindData();
2142 if (!pDataNode) {
2143 pValue->SetNull();
2144 return;
2145 }
2146
2147 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002148}
dsinclair5b36f0a2016-07-19 10:56:23 -07002149
dsinclair12a6b0c2016-05-26 11:14:08 -07002150void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002151 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002152 XFA_ATTRIBUTE eAttribute) {
2153 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002154 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002155 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002156 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002157 XFA_Element uiType = pWidgetData->GetUIType();
2158 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002159 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002160 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002161 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002162 }
2163 }
2164 } else {
tsepezd19e9122016-11-02 15:43:18 -07002165 CFX_WideString content = GetScriptContent(true);
Tom Sepezf0b65542017-02-13 10:26:01 -08002166 if (content.IsEmpty())
dsinclairf27aeec2016-06-07 19:36:18 -07002167 pValue->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002168 else
2169 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002170 }
2171}
dsinclair5b36f0a2016-07-19 10:56:23 -07002172
dsinclair12a6b0c2016-05-26 11:14:08 -07002173void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002174 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002175 XFA_ATTRIBUTE eAttribute) {
2176 CXFA_WidgetData* pWidgetData = GetWidgetData();
2177 if (!pWidgetData) {
2178 return;
2179 }
2180 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002181 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002182 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002183 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002184 } else {
2185 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002186 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002187 }
dsinclair2f5582f2016-06-09 11:48:23 -07002188 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002189 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002190 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002191
Dan Sinclair1770c022016-03-14 14:14:16 -04002192 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002193 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002194 int32_t iLeadDigits = 0;
2195 int32_t iFracDigits = 0;
2196 pWidgetData->GetLeadDigits(iLeadDigits);
2197 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002198 wsNewText =
2199 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002200 }
2201 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2202 CFX_WideString wsFormatText(wsNewText);
2203 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002204 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002205 }
tsepezd19e9122016-11-02 15:43:18 -07002206 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002207 } else {
tsepezd19e9122016-11-02 15:43:18 -07002208 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002209 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002210 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002211 } else {
2212 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002213 CXFA_Value defVal = pWidgetData->GetFormValue();
2214 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002215 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002216 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002217 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
Tom Sepezf0b65542017-02-13 10:26:01 -08002218 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002219 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002220 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002221 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002222 }
dsinclair070fcdf2016-06-22 22:04:54 -07002223 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002224 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002225 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002226 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002227 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002228 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002229 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002230 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002231 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002232 }
2233 }
2234 }
2235}
dsinclair5b36f0a2016-07-19 10:56:23 -07002236
dsinclair12a6b0c2016-05-26 11:14:08 -07002237void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002238 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002239 XFA_ATTRIBUTE eAttribute) {
2240 CXFA_WidgetData* pWidgetData = GetWidgetData();
2241 if (!pWidgetData) {
2242 return;
2243 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002244 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002245 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002246 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002247 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002248 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
Tom Sepezf0b65542017-02-13 10:26:01 -08002249 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002250 }
2251}
dsinclair5b36f0a2016-07-19 10:56:23 -07002252
dsinclair12a6b0c2016-05-26 11:14:08 -07002253void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002254 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002255 XFA_ATTRIBUTE eAttribute) {
2256 CXFA_WidgetData* pWidgetData = GetWidgetData();
2257 if (!pWidgetData) {
2258 return;
2259 }
tsepezd19e9122016-11-02 15:43:18 -07002260 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002261 CXFA_Node* pNode = font.GetNode();
2262 if (!pNode) {
2263 return;
2264 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002265 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002266 int32_t r;
2267 int32_t g;
2268 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002269 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002270 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2271 font.SetColor(color);
2272 } else {
2273 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002274 int32_t a;
2275 int32_t r;
2276 int32_t g;
2277 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002278 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002279 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002280 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002281 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002282 }
2283}
dsinclair5b36f0a2016-07-19 10:56:23 -07002284
dsinclair12a6b0c2016-05-26 11:14:08 -07002285void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002286 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002287 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002288 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002289}
dsinclair5b36f0a2016-07-19 10:56:23 -07002290
dsinclair12a6b0c2016-05-26 11:14:08 -07002291void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002292 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002293 XFA_ATTRIBUTE eAttribute) {
2294 CXFA_WidgetData* pWidgetData = GetWidgetData();
2295 if (!pWidgetData) {
2296 return;
2297 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002298 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002299 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002300 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002301 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002302 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
Tom Sepezf0b65542017-02-13 10:26:01 -08002303 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002304 }
2305}
dsinclair5b36f0a2016-07-19 10:56:23 -07002306
dsinclair12a6b0c2016-05-26 11:14:08 -07002307void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002308 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002309 XFA_ATTRIBUTE eAttribute) {
2310 CXFA_WidgetData* pWidgetData = GetWidgetData();
2311 if (!pWidgetData) {
2312 return;
2313 }
tsepezd19e9122016-11-02 15:43:18 -07002314 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002315 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002316 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002317 } else {
2318 int32_t iValue = validate.GetNullTest();
2319 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002320 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002321 CFX_WideString wsValue;
2322 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002323 wsValue = pInfo->pName;
Tom Sepezf0b65542017-02-13 10:26:01 -08002324 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002325 }
2326}
dsinclair5b36f0a2016-07-19 10:56:23 -07002327
dsinclair12a6b0c2016-05-26 11:14:08 -07002328void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002329 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002330 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002331 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002332}
dsinclair5b36f0a2016-07-19 10:56:23 -07002333
dsinclair12a6b0c2016-05-26 11:14:08 -07002334void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002335 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002336 XFA_ATTRIBUTE eAttribute) {
2337 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002338 ThrowInvalidPropertyException();
2339 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002340 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002341 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002342}
dsinclair5b36f0a2016-07-19 10:56:23 -07002343
dsinclair12a6b0c2016-05-26 11:14:08 -07002344void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002345 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002346 XFA_ATTRIBUTE eAttribute) {
2347 CXFA_WidgetData* pWidgetData = GetWidgetData();
2348 if (!pWidgetData) {
2349 return;
2350 }
2351 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002352 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002353 if (iIndex == -1) {
2354 pWidgetData->ClearAllSelections();
2355 return;
2356 }
tsepezd19e9122016-11-02 15:43:18 -07002357 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002358 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002359 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002360 }
2361}
dsinclair5b36f0a2016-07-19 10:56:23 -07002362
Dan Sinclair1770c022016-03-14 14:14:16 -04002363void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2364 CXFA_WidgetData* pWidgetData = GetWidgetData();
2365 if (!pWidgetData) {
2366 return;
2367 }
tsepezd19e9122016-11-02 15:43:18 -07002368 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002369}
dsinclair5b36f0a2016-07-19 10:56:23 -07002370
Dan Sinclair1770c022016-03-14 14:14:16 -04002371void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002372 if (pArguments->GetLength() != 1) {
2373 ThrowParamCountMismatchException(L"execEvent");
2374 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002375 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002376
2377 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2378 int32_t iRet = execSingleEventByName(
2379 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2380 XFA_Element::Field);
2381 if (eventString != "validate")
2382 return;
2383
2384 pArguments->GetReturnValue()->SetBoolean(
2385 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002386}
dsinclair5b36f0a2016-07-19 10:56:23 -07002387
Dan Sinclair1770c022016-03-14 14:14:16 -04002388void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002389 if (pArguments->GetLength() != 0) {
2390 ThrowParamCountMismatchException(L"execInitialize");
2391 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002392 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002393
2394 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2395 if (!pNotify)
2396 return;
2397
2398 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002399}
dsinclair5b36f0a2016-07-19 10:56:23 -07002400
Dan Sinclair1770c022016-03-14 14:14:16 -04002401void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2402 int32_t iLength = pArguments->GetLength();
2403 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002404 ThrowParamCountMismatchException(L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002405 return;
2406 }
2407 CXFA_WidgetData* pWidgetData = GetWidgetData();
2408 if (!pWidgetData) {
2409 return;
2410 }
2411 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002412 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002413 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002414 if (pValue)
2415 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002416}
dsinclair5b36f0a2016-07-19 10:56:23 -07002417
Dan Sinclair1770c022016-03-14 14:14:16 -04002418void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2419 int32_t iLength = pArguments->GetLength();
2420 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002421 ThrowParamCountMismatchException(L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002422 return;
2423 }
2424 int32_t iIndex = pArguments->GetInt32(0);
2425 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002426 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002427 return;
2428 }
2429 CXFA_WidgetData* pWidgetData = GetWidgetData();
2430 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002431 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002432 return;
2433 }
2434 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002435 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002436 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002437 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002438 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002439 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002440}
dsinclair5b36f0a2016-07-19 10:56:23 -07002441
Dan Sinclair1770c022016-03-14 14:14:16 -04002442void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2443 int32_t iLength = pArguments->GetLength();
2444 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002445 ThrowParamCountMismatchException(L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002446 return;
2447 }
2448 CXFA_WidgetData* pWidgetData = GetWidgetData();
2449 if (!pWidgetData) {
2450 return;
2451 }
2452 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002453 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002454 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002455 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002456 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002457 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08002458 pValue->SetString(wsBoundValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002459}
dsinclair5b36f0a2016-07-19 10:56:23 -07002460
Dan Sinclair1770c022016-03-14 14:14:16 -04002461void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2462 int32_t iLength = pArguments->GetLength();
2463 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002464 ThrowParamCountMismatchException(L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002465 return;
2466 }
2467 CXFA_WidgetData* pWidgetData = GetWidgetData();
2468 if (!pWidgetData) {
2469 return;
2470 }
2471 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002472 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002473 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002474 if (pValue)
2475 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002476}
dsinclair5b36f0a2016-07-19 10:56:23 -07002477
Dan Sinclair1770c022016-03-14 14:14:16 -04002478void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002479 if (pArguments->GetLength() != 0) {
2480 ThrowParamCountMismatchException(L"execCalculate");
2481 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002482 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002483
2484 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2485 if (!pNotify)
2486 return;
2487
2488 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002489}
dsinclair5b36f0a2016-07-19 10:56:23 -07002490
Dan Sinclair1770c022016-03-14 14:14:16 -04002491void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002492
Dan Sinclair1770c022016-03-14 14:14:16 -04002493void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2494 int32_t iLength = pArguments->GetLength();
2495 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002496 ThrowParamCountMismatchException(L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002497 return;
2498 }
2499 int32_t iIndex = pArguments->GetInt32(0);
2500 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002501 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002502 return;
2503 }
2504 CXFA_WidgetData* pWidgetData = GetWidgetData();
2505 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002506 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002507 return;
2508 }
2509 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002510 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002511 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002512 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002513 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002514 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002515}
dsinclair5b36f0a2016-07-19 10:56:23 -07002516
Dan Sinclair1770c022016-03-14 14:14:16 -04002517void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2518 int32_t iLength = pArguments->GetLength();
2519 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002520 ThrowParamCountMismatchException(L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002521 return;
2522 }
2523 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002524 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002525 return;
thestig800222e2016-05-26 22:00:29 -07002526
Dan Sinclair1770c022016-03-14 14:14:16 -04002527 int32_t iIndex = pArguments->GetInt32(0);
2528 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002529 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002530 } else {
thestig800222e2016-05-26 22:00:29 -07002531 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002532 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002533 }
2534}
dsinclair5b36f0a2016-07-19 10:56:23 -07002535
Dan Sinclair1770c022016-03-14 14:14:16 -04002536void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2537 int32_t iLength = pArguments->GetLength();
2538 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002539 ThrowParamCountMismatchException(L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002540 return;
2541 }
2542 CXFA_WidgetData* pWidgetData = GetWidgetData();
2543 if (!pWidgetData) {
2544 return;
2545 }
2546 CFX_WideString wsLabel;
2547 CFX_WideString wsValue;
2548 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002549 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002550 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002551 }
2552 if (iLength >= 2) {
2553 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002554 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002555 }
tsepezd19e9122016-11-02 15:43:18 -07002556 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002557}
dsinclair5b36f0a2016-07-19 10:56:23 -07002558
Dan Sinclair1770c022016-03-14 14:14:16 -04002559void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002560 if (pArguments->GetLength() != 0) {
2561 ThrowParamCountMismatchException(L"execValidate");
2562 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002563 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002564
2565 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2566 if (!pNotify) {
2567 pArguments->GetReturnValue()->SetBoolean(false);
2568 return;
2569 }
2570
2571 int32_t iRet =
2572 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
2573 pArguments->GetReturnValue()->SetBoolean(
2574 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002575}
dsinclair5b36f0a2016-07-19 10:56:23 -07002576
dsinclair12a6b0c2016-05-26 11:14:08 -07002577void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002578 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002579 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002580 if (bSetting)
2581 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002582}
dsinclair5b36f0a2016-07-19 10:56:23 -07002583
dsinclair12a6b0c2016-05-26 11:14:08 -07002584void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002585 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002586 XFA_ATTRIBUTE eAttribute) {
2587 CXFA_WidgetData* pWidgetData = GetWidgetData();
2588 if (!pWidgetData) {
2589 return;
2590 }
2591 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002592 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002593 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002594 } else {
tsepezd19e9122016-11-02 15:43:18 -07002595 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002596 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2597 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002598 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002599 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002600 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002601 }
2602 }
2603}
dsinclair5b36f0a2016-07-19 10:56:23 -07002604
dsinclair12a6b0c2016-05-26 11:14:08 -07002605void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002606 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002607 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002608
Dan Sinclair1770c022016-03-14 14:14:16 -04002609void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002610 if (pArguments->GetLength() != 1) {
2611 ThrowParamCountMismatchException(L"execEvent");
2612 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002613 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002614
2615 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2616 execSingleEventByName(
2617 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2618 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002619}
thestig800222e2016-05-26 22:00:29 -07002620
Dan Sinclair1770c022016-03-14 14:14:16 -04002621void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2622 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002623 if (argc < 0 || argc > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002624 ThrowParamCountMismatchException(L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002625 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002626 }
thestig800222e2016-05-26 22:00:29 -07002627
2628 CXFA_WidgetData* pWidgetData = GetWidgetData();
2629 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002630 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002631 return;
2632 }
2633
2634 CXFA_Node* pReturnNode = nullptr;
2635 if (argc == 0) {
2636 pReturnNode = pWidgetData->GetSelectedMember();
2637 } else {
2638 CFX_ByteString szName;
2639 szName = pArguments->GetUTF8String(0);
2640 pReturnNode = pWidgetData->SetSelectedMember(
2641 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2642 }
2643 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002644 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002645 return;
2646 }
dsinclairf27aeec2016-06-07 19:36:18 -07002647 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002648 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002649}
thestig800222e2016-05-26 22:00:29 -07002650
Dan Sinclair1770c022016-03-14 14:14:16 -04002651void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002652 if (pArguments->GetLength() != 0) {
2653 ThrowParamCountMismatchException(L"execInitialize");
2654 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002655 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002656
2657 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2658 if (!pNotify)
2659 return;
2660
2661 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002662}
dsinclair5b36f0a2016-07-19 10:56:23 -07002663
Dan Sinclair1770c022016-03-14 14:14:16 -04002664void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002665 if (pArguments->GetLength() != 0) {
2666 ThrowParamCountMismatchException(L"execCalculate");
2667 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002668 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002669
2670 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2671 if (!pNotify)
2672 return;
2673
2674 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002675}
dsinclair5b36f0a2016-07-19 10:56:23 -07002676
Dan Sinclair1770c022016-03-14 14:14:16 -04002677void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002678 if (pArguments->GetLength() != 0) {
2679 ThrowParamCountMismatchException(L"execValidate");
2680 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002681 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002682
2683 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2684 if (!pNotify) {
2685 pArguments->GetReturnValue()->SetBoolean(false);
2686 return;
2687 }
2688
2689 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2690 pArguments->GetReturnValue()->SetBoolean(
2691 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002692}
dsinclair5b36f0a2016-07-19 10:56:23 -07002693
dsinclair12a6b0c2016-05-26 11:14:08 -07002694void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002695 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002696 XFA_ATTRIBUTE eAttribute) {
2697 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002698 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002699 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002700 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002701 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2702 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002703 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002704 pManagerNode = pNode;
2705 break;
2706 }
2707 }
2708 if (pManagerNode) {
2709 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002710 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002711 if (!pNotify) {
2712 return;
2713 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002714 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002715 if (pToInstance &&
2716 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002717 pNotify->RunSubformIndexChange(pToInstance);
2718 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002719 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002720 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002721 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002722 pNotify->RunSubformIndexChange(pFromInstance);
2723 }
2724 }
2725 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002726 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002727 }
2728}
dsinclair5b36f0a2016-07-19 10:56:23 -07002729
dsinclair12a6b0c2016-05-26 11:14:08 -07002730void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002731 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002732 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002733 if (bSetting) {
2734 ThrowInvalidPropertyException();
2735 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002736 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002737
2738 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2739 CXFA_Node* pInstanceMgr = nullptr;
2740 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2741 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2742 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2743 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2744 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2745 wsInstMgrName.Mid(1) == wsName) {
2746 pInstanceMgr = pNode;
2747 }
2748 break;
2749 }
2750 }
2751 if (!pInstanceMgr) {
2752 pValue->SetNull();
2753 return;
2754 }
2755
2756 pValue->Assign(
2757 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
Dan Sinclair1770c022016-03-14 14:14:16 -04002758}
dsinclair5b36f0a2016-07-19 10:56:23 -07002759
dsinclair12a6b0c2016-05-26 11:14:08 -07002760void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002761 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002762 XFA_ATTRIBUTE eAttribute) {
2763 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002764 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002765 } else {
2766 CFX_WideString wsLocaleName;
2767 GetLocaleName(wsLocaleName);
Tom Sepezf0b65542017-02-13 10:26:01 -08002768 pValue->SetString(wsLocaleName.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002769 }
2770}
dsinclair5b36f0a2016-07-19 10:56:23 -07002771
Dan Sinclair1770c022016-03-14 14:14:16 -04002772void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002773 if (pArguments->GetLength() != 1) {
2774 ThrowParamCountMismatchException(L"execEvent");
2775 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002776 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002777
2778 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2779 execSingleEventByName(
2780 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2781 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002782}
dsinclair5b36f0a2016-07-19 10:56:23 -07002783
Dan Sinclair1770c022016-03-14 14:14:16 -04002784void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002785 if (pArguments->GetLength() != 0) {
2786 ThrowParamCountMismatchException(L"execInitialize");
2787 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002788 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002789
2790 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2791 if (!pNotify)
2792 return;
2793
2794 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002795}
dsinclair5b36f0a2016-07-19 10:56:23 -07002796
Dan Sinclair1770c022016-03-14 14:14:16 -04002797void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002798 if (pArguments->GetLength() != 0) {
2799 ThrowParamCountMismatchException(L"execCalculate");
2800 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002801 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002802
2803 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2804 if (!pNotify)
2805 return;
2806
2807 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002808}
dsinclair5b36f0a2016-07-19 10:56:23 -07002809
Dan Sinclair1770c022016-03-14 14:14:16 -04002810void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002811 if (pArguments->GetLength() != 0) {
2812 ThrowParamCountMismatchException(L"execValidate");
2813 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002814 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002815
2816 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2817 if (!pNotify) {
2818 pArguments->GetReturnValue()->SetBoolean(false);
2819 return;
2820 }
2821
2822 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2823 pArguments->GetReturnValue()->SetBoolean(
2824 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002825}
dsinclair5b36f0a2016-07-19 10:56:23 -07002826
Dan Sinclair1770c022016-03-14 14:14:16 -04002827void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002828 if (pArguments->GetLength() != 0)
2829 ThrowParamCountMismatchException(L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002830}
dsinclair5b36f0a2016-07-19 10:56:23 -07002831
Dan Sinclair1770c022016-03-14 14:14:16 -04002832int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2833 int32_t index = 0;
2834 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2835 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002836 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2837 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002838 index++;
2839 } else {
2840 break;
2841 }
2842 }
2843 return index;
2844}
dsinclair5b36f0a2016-07-19 10:56:23 -07002845
Dan Sinclair1770c022016-03-14 14:14:16 -04002846void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002847 if (pArguments->GetLength() != 1) {
2848 ThrowParamCountMismatchException(L"formNodes");
2849 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002850 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002851 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002852}
dsinclair5b36f0a2016-07-19 10:56:23 -07002853
Dan Sinclair1770c022016-03-14 14:14:16 -04002854void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002855 if (pArguments->GetLength() != 0) {
2856 ThrowParamCountMismatchException(L"remerge");
2857 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002858 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002859 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002860}
dsinclair5b36f0a2016-07-19 10:56:23 -07002861
Dan Sinclair1770c022016-03-14 14:14:16 -04002862void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002863 if (pArguments->GetLength() != 0) {
2864 ThrowParamCountMismatchException(L"execInitialize");
2865 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002866 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002867
2868 CXFA_WidgetData* pWidgetData = GetWidgetData();
2869 if (!pWidgetData) {
2870 pArguments->GetReturnValue()->SetBoolean(false);
2871 return;
2872 }
2873 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002874}
dsinclair5b36f0a2016-07-19 10:56:23 -07002875
Dan Sinclair1770c022016-03-14 14:14:16 -04002876void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2877 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002878 if (argc <= 0 || argc >= 4) {
2879 ThrowParamCountMismatchException(L"createNode");
2880 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002881 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002882
2883 CFX_WideString strName;
2884 CFX_WideString strNameSpace;
2885 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
2886 CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
2887 if (argc > 1) {
2888 CFX_ByteString bsName = pArguments->GetUTF8String(1);
2889 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
2890 if (argc == 3) {
2891 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
2892 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
2893 }
2894 }
2895
2896 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2897 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
2898 if (!pNewNode) {
2899 pArguments->GetReturnValue()->SetNull();
2900 return;
2901 }
2902
2903 if (strName.IsEmpty()) {
2904 pArguments->GetReturnValue()->Assign(
2905 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2906 return;
2907 }
2908
2909 if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2910 XFA_XDPPACKET_UNKNOWN)) {
2911 ThrowMissingPropertyException(strTagName, L"name");
2912 return;
2913 }
2914
2915 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
2916 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets)
2917 pNewNode->CreateXMLMappingNode();
2918
2919 pArguments->GetReturnValue()->Assign(
2920 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002921}
dsinclair5b36f0a2016-07-19 10:56:23 -07002922
Dan Sinclair1770c022016-03-14 14:14:16 -04002923void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002924 if (pArguments->GetLength() != 1) {
2925 ThrowParamCountMismatchException(L"recalculate");
2926 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002927 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002928 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002929}
dsinclair5b36f0a2016-07-19 10:56:23 -07002930
Dan Sinclair1770c022016-03-14 14:14:16 -04002931void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002932 if (pArguments->GetLength() != 0) {
2933 ThrowParamCountMismatchException(L"execCalculate");
2934 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002935 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002936
2937 CXFA_WidgetData* pWidgetData = GetWidgetData();
2938 if (!pWidgetData) {
2939 pArguments->GetReturnValue()->SetBoolean(false);
2940 return;
2941 }
2942 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002943}
dsinclair5b36f0a2016-07-19 10:56:23 -07002944
Dan Sinclair1770c022016-03-14 14:14:16 -04002945void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002946 if (pArguments->GetLength() != 0) {
2947 ThrowParamCountMismatchException(L"execValidate");
2948 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002949 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002950 CXFA_WidgetData* pWidgetData = GetWidgetData();
2951 if (!pWidgetData) {
2952 pArguments->GetReturnValue()->SetBoolean(false);
2953 return;
2954 }
2955 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002956}
dsinclair5b36f0a2016-07-19 10:56:23 -07002957
Dan Sinclair1770c022016-03-14 14:14:16 -04002958void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002959 if (pArguments->GetLength() != 0) {
2960 ThrowParamCountMismatchException(L"evaluate");
2961 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002962 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002963
2964 CXFA_WidgetData* pWidgetData = GetWidgetData();
2965 if (!pWidgetData) {
2966 pArguments->GetReturnValue()->SetBoolean(false);
2967 return;
2968 }
2969 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002970}
dsinclair5b36f0a2016-07-19 10:56:23 -07002971
dsinclair12a6b0c2016-05-26 11:14:08 -07002972void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002973 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002974 XFA_ATTRIBUTE eAttribute) {
2975 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002976 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002977 return;
2978 }
2979 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002980 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04002981}
dsinclair5b36f0a2016-07-19 10:56:23 -07002982
dsinclair12a6b0c2016-05-26 11:14:08 -07002983void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002984 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002985 XFA_ATTRIBUTE eAttribute) {
2986 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002987 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002988 return;
2989 }
2990 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002991 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04002992}
tsepezaadedf92016-05-12 10:08:06 -07002993
dsinclair12a6b0c2016-05-26 11:14:08 -07002994void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002995 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002996 XFA_ATTRIBUTE eAttribute) {
2997 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002998 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002999 InstanceManager_SetInstances(iDesired);
3000 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07003001 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04003002 }
3003}
dsinclair5b36f0a2016-07-19 10:56:23 -07003004
Dan Sinclair1770c022016-03-14 14:14:16 -04003005void CXFA_Node::Script_InstanceManager_MoveInstance(
3006 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003007 if (pArguments->GetLength() != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003008 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003009 return;
3010 }
3011 int32_t iFrom = pArguments->GetInt32(0);
3012 int32_t iTo = pArguments->GetInt32(1);
3013 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003014 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003015 if (!pNotify) {
3016 return;
3017 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003018 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003019 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003020 pNotify->RunSubformIndexChange(pToInstance);
3021 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003022 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003023 if (pFromInstance &&
3024 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003025 pNotify->RunSubformIndexChange(pFromInstance);
3026 }
3027}
dsinclair5b36f0a2016-07-19 10:56:23 -07003028
Dan Sinclair1770c022016-03-14 14:14:16 -04003029void CXFA_Node::Script_InstanceManager_RemoveInstance(
3030 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003031 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003032 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003033 return;
3034 }
3035 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003036 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003037 if (iIndex < 0 || iIndex >= iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003038 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003039 return;
3040 }
3041 CXFA_Occur nodeOccur(GetOccurNode());
3042 int32_t iMin = nodeOccur.GetMin();
3043 if (iCount - 1 < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003044 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003045 return;
3046 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003047 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3048 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003049 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003050 if (pNotify) {
3051 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003052 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003053 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003054 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003055 pNotify->RunSubformIndexChange(pSubformInstance);
3056 }
3057 }
3058 }
3059 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3060 if (!pLayoutPro) {
3061 return;
3062 }
3063 pLayoutPro->AddChangedContainer(
3064 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3065}
dsinclair5b36f0a2016-07-19 10:56:23 -07003066
Dan Sinclair1770c022016-03-14 14:14:16 -04003067void CXFA_Node::Script_InstanceManager_SetInstances(
3068 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003069 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003070 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003071 return;
3072 }
3073 int32_t iDesired = pArguments->GetInt32(0);
3074 InstanceManager_SetInstances(iDesired);
3075}
dsinclair5b36f0a2016-07-19 10:56:23 -07003076
Dan Sinclair1770c022016-03-14 14:14:16 -04003077void CXFA_Node::Script_InstanceManager_AddInstance(
3078 CFXJSE_Arguments* pArguments) {
3079 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003080 if (argc != 0 && argc != 1) {
3081 ThrowParamCountMismatchException(L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003082 return;
3083 }
tsepezd19e9122016-11-02 15:43:18 -07003084 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003085 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003086 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003087 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003088 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003089 CXFA_Occur nodeOccur(GetOccurNode());
3090 int32_t iMax = nodeOccur.GetMax();
3091 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003092 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003093 return;
3094 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003095 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003096 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003097 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003098 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003099 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003100 if (!pNotify) {
3101 return;
3102 }
3103 pNotify->RunNodeInitialize(pNewInstance);
3104 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3105 if (!pLayoutPro) {
3106 return;
3107 }
3108 pLayoutPro->AddChangedContainer(
3109 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3110}
dsinclair5b36f0a2016-07-19 10:56:23 -07003111
Dan Sinclair1770c022016-03-14 14:14:16 -04003112void CXFA_Node::Script_InstanceManager_InsertInstance(
3113 CFXJSE_Arguments* pArguments) {
3114 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003115 if (argc != 1 && argc != 2) {
3116 ThrowParamCountMismatchException(L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003117 return;
3118 }
3119 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003120 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003121 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003122 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003123 }
3124 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003125 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003126 if (iIndex < 0 || iIndex > iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003127 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003128 return;
3129 }
3130 int32_t iMax = nodeOccur.GetMax();
3131 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003132 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003133 return;
3134 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003135 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003136 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003137 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003138 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003139 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003140 if (!pNotify) {
3141 return;
3142 }
3143 pNotify->RunNodeInitialize(pNewInstance);
3144 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3145 if (!pLayoutPro) {
3146 return;
3147 }
3148 pLayoutPro->AddChangedContainer(
3149 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3150}
dsinclair5b36f0a2016-07-19 10:56:23 -07003151
Dan Sinclair1770c022016-03-14 14:14:16 -04003152int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3153 CXFA_Occur nodeOccur(GetOccurNode());
3154 int32_t iMax = nodeOccur.GetMax();
3155 int32_t iMin = nodeOccur.GetMin();
3156 if (iDesired < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003157 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003158 return 1;
3159 }
3160 if ((iMax >= 0) && (iDesired > iMax)) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003161 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003162 return 2;
3163 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003164 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003165 if (iDesired == iCount) {
3166 return 0;
3167 }
3168 if (iDesired < iCount) {
3169 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003170 CFX_WideString wsInstanceName =
3171 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3172 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003173 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003174 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003175 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003176 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003177 while (iCount > iDesired) {
3178 CXFA_Node* pRemoveInstance =
3179 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003180 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3181 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003182 continue;
3183 }
dsinclair070fcdf2016-06-22 22:04:54 -07003184 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003185 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003186 break;
3187 }
3188 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003189 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003190 iCount--;
3191 }
3192 }
3193 } else if (iDesired > iCount) {
3194 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003195 CXFA_Node* pNewInstance = CreateInstance(this, true);
3196 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003197 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003198 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003199 if (!pNotify) {
3200 return 0;
3201 }
3202 pNotify->RunNodeInitialize(pNewInstance);
3203 }
3204 }
3205 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3206 if (pLayoutPro) {
3207 pLayoutPro->AddChangedContainer(
3208 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3209 }
3210 return 0;
3211}
dsinclair5b36f0a2016-07-19 10:56:23 -07003212
Dan Sinclair1770c022016-03-14 14:14:16 -04003213int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003214 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003215 if (iFrom > iCount || iTo > iCount - 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003216 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003217 return 1;
3218 }
3219 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3220 return 0;
3221 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003222 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003223 RemoveItem(this, pMoveInstance, false);
3224 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003225 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3226 if (pLayoutPro) {
3227 pLayoutPro->AddChangedContainer(
3228 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3229 }
3230 return 0;
3231}
dsinclair5b36f0a2016-07-19 10:56:23 -07003232
dsinclair12a6b0c2016-05-26 11:14:08 -07003233void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003234 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003235 XFA_ATTRIBUTE eAttribute) {
3236 CXFA_Occur occur(this);
3237 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003238 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003239 occur.SetMax(iMax);
3240 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003241 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003242 }
3243}
dsinclair5b36f0a2016-07-19 10:56:23 -07003244
dsinclair12a6b0c2016-05-26 11:14:08 -07003245void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003246 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003247 XFA_ATTRIBUTE eAttribute) {
3248 CXFA_Occur occur(this);
3249 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003250 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003251 occur.SetMin(iMin);
3252 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003253 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003254 }
3255}
dsinclair5b36f0a2016-07-19 10:56:23 -07003256
Dan Sinclair1770c022016-03-14 14:14:16 -04003257void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3258 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003259 if (argc != 0 && argc != 1) {
3260 ThrowParamCountMismatchException(L"metadata");
3261 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003262 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003263 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003264}
dsinclair5b36f0a2016-07-19 10:56:23 -07003265
Dan Sinclair1770c022016-03-14 14:14:16 -04003266void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003267 if (pArguments->GetLength() != 1) {
3268 ThrowParamCountMismatchException(L"formNodes");
3269 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003270 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003271
3272 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3273 if (!pDataNode) {
3274 ThrowArgumentMismatchException();
3275 return;
3276 }
3277
Tom Sepezf8a94392017-03-14 12:13:22 -07003278 std::vector<CXFA_Node*> formItems;
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003279 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3280 pFormNodes->SetArrayNodeList(formItems);
3281 pArguments->GetReturnValue()->SetObject(
3282 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003283}
dsinclair5b36f0a2016-07-19 10:56:23 -07003284
Dan Sinclair1770c022016-03-14 14:14:16 -04003285void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003286 if (pArguments->GetLength() != 0) {
3287 ThrowParamCountMismatchException(L"remerge");
3288 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003289 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003290
3291 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003292}
dsinclair5b36f0a2016-07-19 10:56:23 -07003293
Dan Sinclair1770c022016-03-14 14:14:16 -04003294void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003295 if (pArguments->GetLength() != 0) {
3296 ThrowParamCountMismatchException(L"execInitialize");
3297 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003298 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003299
3300 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3301 if (!pNotify)
3302 return;
3303
3304 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04003305}
dsinclair5b36f0a2016-07-19 10:56:23 -07003306
Dan Sinclair1770c022016-03-14 14:14:16 -04003307void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3308 CXFA_EventParam* pEventParam =
3309 m_pDocument->GetScriptContext()->GetEventParam();
3310 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3311 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3312 return;
3313 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003314 if (pArguments->GetLength() != 1) {
3315 ThrowParamCountMismatchException(L"recalculate");
3316 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003317 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003318
3319 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3320 if (!pNotify)
3321 return;
3322 if (pArguments->GetInt32(0) != 0)
3323 return;
3324
3325 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3326 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3327 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003328}
dsinclair5b36f0a2016-07-19 10:56:23 -07003329
Dan Sinclair1770c022016-03-14 14:14:16 -04003330void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003331 if (pArguments->GetLength() != 0) {
3332 ThrowParamCountMismatchException(L"execCalculate");
3333 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003334 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003335
3336 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3337 if (!pNotify)
3338 return;
3339
3340 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04003341}
dsinclair5b36f0a2016-07-19 10:56:23 -07003342
Dan Sinclair1770c022016-03-14 14:14:16 -04003343void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003344 if (pArguments->GetLength() != 0) {
3345 ThrowParamCountMismatchException(L"execValidate");
3346 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003347 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003348
3349 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3350 if (!pNotify) {
3351 pArguments->GetReturnValue()->SetBoolean(false);
3352 return;
3353 }
3354
3355 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3356 pArguments->GetReturnValue()->SetBoolean(
3357 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003358}
dsinclair5b36f0a2016-07-19 10:56:23 -07003359
dsinclair12a6b0c2016-05-26 11:14:08 -07003360void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003361 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003362 XFA_ATTRIBUTE eAttribute) {
3363 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003364 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003365 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003366 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003367 CFX_WideString wsChecksum;
3368 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
Tom Sepezf0b65542017-02-13 10:26:01 -08003369 pValue->SetString(wsChecksum.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003370}
dsinclair5b36f0a2016-07-19 10:56:23 -07003371
Dan Sinclair1770c022016-03-14 14:14:16 -04003372void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003373 if (pArguments->GetLength() != 1) {
3374 ThrowParamCountMismatchException(L"getAttribute");
3375 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003376 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003377 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3378 CFX_WideString wsAttributeValue;
3379 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3380 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3381 static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3382 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(),
3383 wsAttributeValue);
3384 }
3385 pArguments->GetReturnValue()->SetString(
Tom Sepezf0b65542017-02-13 10:26:01 -08003386 wsAttributeValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003387}
dsinclair5b36f0a2016-07-19 10:56:23 -07003388
Dan Sinclair1770c022016-03-14 14:14:16 -04003389void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003390 if (pArguments->GetLength() != 2) {
3391 ThrowParamCountMismatchException(L"setAttribute");
3392 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003393 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003394 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3395 CFX_ByteString bsName = pArguments->GetUTF8String(1);
3396 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3397 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3398 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(
3399 CFX_WideString::FromUTF8(bsName.AsStringC()),
3400 CFX_WideString::FromUTF8(bsValue.AsStringC()));
3401 }
3402 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003403}
dsinclair5b36f0a2016-07-19 10:56:23 -07003404
Dan Sinclair1770c022016-03-14 14:14:16 -04003405void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003406 if (pArguments->GetLength() != 1) {
3407 ThrowParamCountMismatchException(L"removeAttribute");
3408 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003409 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003410
3411 CFX_ByteString bsName = pArguments->GetUTF8String(0);
3412 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
3413 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3414 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3415 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
3416 if (pXMLElement->HasAttribute(wsName.c_str())) {
3417 pXMLElement->RemoveAttribute(wsName.c_str());
3418 }
3419 }
3420 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003421}
dsinclair5b36f0a2016-07-19 10:56:23 -07003422
dsinclair12a6b0c2016-05-26 11:14:08 -07003423void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003424 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003425 XFA_ATTRIBUTE eAttribute) {
3426 if (bSetting) {
dsinclairae95f762016-03-29 16:58:29 -07003427 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003428 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003429 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003430 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003431 }
3432 } else {
3433 CFX_WideString wsTextData;
dsinclairae95f762016-03-29 16:58:29 -07003434 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003435 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003436 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04003437 pXMLElement->GetTextData(wsTextData);
3438 }
Tom Sepezf0b65542017-02-13 10:26:01 -08003439 pValue->SetString(wsTextData.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003440 }
3441}
dsinclair5b36f0a2016-07-19 10:56:23 -07003442
Dan Sinclair1770c022016-03-14 14:14:16 -04003443void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003444 if (pArguments->GetLength() != 0)
3445 ThrowParamCountMismatchException(L"next");
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_CancelBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003449 if (pArguments->GetLength() != 0)
3450 ThrowParamCountMismatchException(L"cancelBatch");
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_First(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003454 if (pArguments->GetLength() != 0)
3455 ThrowParamCountMismatchException(L"first");
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_UpdateBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003459 if (pArguments->GetLength() != 0)
3460 ThrowParamCountMismatchException(L"updateBatch");
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_Previous(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003464 if (pArguments->GetLength() != 0)
3465 ThrowParamCountMismatchException(L"previous");
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_IsBOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003469 if (pArguments->GetLength() != 0)
3470 ThrowParamCountMismatchException(L"isBOF");
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_IsEOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003474 if (pArguments->GetLength() != 0)
3475 ThrowParamCountMismatchException(L"isEOF");
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_Cancel(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003479 if (pArguments->GetLength() != 0)
3480 ThrowParamCountMismatchException(L"cancel");
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_Update(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003484 if (pArguments->GetLength() != 0)
3485 ThrowParamCountMismatchException(L"update");
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_Open(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003489 if (pArguments->GetLength() != 0)
3490 ThrowParamCountMismatchException(L"open");
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_Delete(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003494 if (pArguments->GetLength() != 0)
3495 ThrowParamCountMismatchException(L"delete");
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_AddNew(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003499 if (pArguments->GetLength() != 0)
3500 ThrowParamCountMismatchException(L"addNew");
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_Requery(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003504 if (pArguments->GetLength() != 0)
3505 ThrowParamCountMismatchException(L"requery");
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_Resync(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003509 if (pArguments->GetLength() != 0)
3510 ThrowParamCountMismatchException(L"resync");
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_Close(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003514 if (pArguments->GetLength() != 0)
3515 ThrowParamCountMismatchException(L"close");
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_Last(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003519 if (pArguments->GetLength() != 0)
3520 ThrowParamCountMismatchException(L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003521}
dsinclair5b36f0a2016-07-19 10:56:23 -07003522
Dan Sinclair1770c022016-03-14 14:14:16 -04003523void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003524 if (pArguments->GetLength() != 0)
3525 ThrowParamCountMismatchException(L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003526}
dsinclair5b36f0a2016-07-19 10:56:23 -07003527
dsinclair12a6b0c2016-05-26 11:14:08 -07003528void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003529 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003530 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003531
dsinclair12a6b0c2016-05-26 11:14:08 -07003532void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003533 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003534 XFA_ATTRIBUTE eAttribute) {
3535 if (!bSetting) {
3536 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003537 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003538 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003539 }
3540}
dsinclair5b36f0a2016-07-19 10:56:23 -07003541
dsinclair12a6b0c2016-05-26 11:14:08 -07003542void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003543 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003544 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003545
dsinclair12a6b0c2016-05-26 11:14:08 -07003546void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003547 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003548 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003549
dsinclair12a6b0c2016-05-26 11:14:08 -07003550void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003551 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003552 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003553
dsinclair12a6b0c2016-05-26 11:14:08 -07003554void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003555 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003556 XFA_ATTRIBUTE eAttribute) {
3557 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003558 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003559 return;
3560 }
dan sinclair65c7c232017-02-02 14:05:30 -08003561 pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003562}
dsinclair5b36f0a2016-07-19 10:56:23 -07003563
dsinclair12a6b0c2016-05-26 11:14:08 -07003564void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003565 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003566 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003567
tsepezd19e9122016-11-02 15:43:18 -07003568bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003569 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003570 return HasMapModuleKey(pKey, bCanInherit);
3571}
dsinclair5b36f0a2016-07-19 10:56:23 -07003572
tsepezd19e9122016-11-02 15:43:18 -07003573bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3574 const CFX_WideStringC& wsValue,
3575 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003576 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003577 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003578 return false;
weili44f8faf2016-06-01 14:03:56 -07003579
Dan Sinclair1770c022016-03-14 14:14:16 -04003580 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3581 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3582 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003583 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003584 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3585 }
3586 switch (eType) {
3587 case XFA_ATTRIBUTETYPE_Enum: {
3588 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3589 return SetEnum(pAttr->eName,
3590 pEnum ? pEnum->eName
3591 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3592 bNotify);
3593 } break;
3594 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003595 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003596 case XFA_ATTRIBUTETYPE_Boolean:
dan sinclair65c7c232017-02-02 14:05:30 -08003597 return SetBoolean(pAttr->eName, wsValue != L"0", bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003598 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003599 return SetInteger(pAttr->eName,
3600 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3601 wsValue.GetLength(), nullptr)),
3602 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003603 case XFA_ATTRIBUTETYPE_Measure:
3604 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3605 default:
3606 break;
3607 }
tsepezd19e9122016-11-02 15:43:18 -07003608 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003609}
dsinclair5b36f0a2016-07-19 10:56:23 -07003610
tsepezd19e9122016-11-02 15:43:18 -07003611bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3612 CFX_WideString& wsValue,
3613 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003614 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003615 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003616 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003617 }
3618 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3619 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3620 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003621 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003622 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3623 }
3624 switch (eType) {
3625 case XFA_ATTRIBUTETYPE_Enum: {
3626 XFA_ATTRIBUTEENUM eValue;
3627 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003628 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003629 }
dsinclair9eb0db12016-07-21 12:01:39 -07003630 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003631 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003632 } break;
3633 case XFA_ATTRIBUTETYPE_Cdata: {
3634 CFX_WideStringC wsValueC;
3635 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003636 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003637 }
3638 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003639 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003640 } break;
3641 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003642 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003643 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003644 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003645 }
dan sinclair65c7c232017-02-02 14:05:30 -08003646 wsValue = bValue ? L"1" : L"0";
tsepezd19e9122016-11-02 15:43:18 -07003647 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003648 } break;
3649 case XFA_ATTRIBUTETYPE_Integer: {
3650 int32_t iValue;
3651 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003652 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003653 }
3654 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003655 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003656 } break;
3657 case XFA_ATTRIBUTETYPE_Measure: {
3658 CXFA_Measurement mValue;
3659 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003660 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003661 }
3662 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003663 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003664 } break;
3665 default:
3666 break;
3667 }
tsepezd19e9122016-11-02 15:43:18 -07003668 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003669}
dsinclair5b36f0a2016-07-19 10:56:23 -07003670
tsepezd19e9122016-11-02 15:43:18 -07003671bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3672 const CFX_WideStringC& wsValue,
3673 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003674 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3675 if (pAttributeInfo) {
3676 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3677 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003678 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003679 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003680 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003681}
dsinclair5b36f0a2016-07-19 10:56:23 -07003682
tsepezd19e9122016-11-02 15:43:18 -07003683bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3684 CFX_WideString& wsValue,
3685 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003686 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3687 if (pAttributeInfo) {
3688 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3689 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003690 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003691 CFX_WideStringC wsValueC;
3692 if (GetMapModuleString(pKey, wsValueC)) {
3693 wsValue = wsValueC;
3694 }
tsepezd19e9122016-11-02 15:43:18 -07003695 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003696}
dsinclair5b36f0a2016-07-19 10:56:23 -07003697
tsepezd19e9122016-11-02 15:43:18 -07003698bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003699 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003700 RemoveMapModuleKey(pKey);
tsepezd19e9122016-11-02 15:43:18 -07003701 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003702}
dsinclair5b36f0a2016-07-19 10:56:23 -07003703
tsepezd19e9122016-11-02 15:43:18 -07003704bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3705 bool& bValue,
3706 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003707 void* pValue = nullptr;
3708 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003709 return false;
tsepez478ed622016-10-27 14:32:33 -07003710 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003711 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003712}
dsinclair5b36f0a2016-07-19 10:56:23 -07003713
tsepezd19e9122016-11-02 15:43:18 -07003714bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3715 int32_t& iValue,
3716 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003717 void* pValue = nullptr;
3718 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003719 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003720 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003721 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003722}
dsinclair5b36f0a2016-07-19 10:56:23 -07003723
tsepezd19e9122016-11-02 15:43:18 -07003724bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3725 XFA_ATTRIBUTEENUM& eValue,
3726 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003727 void* pValue = nullptr;
3728 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003729 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003730 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003731 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003732}
thestigb1a59592016-04-14 18:29:56 -07003733
tsepezd19e9122016-11-02 15:43:18 -07003734bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3735 CXFA_Measurement mValue,
3736 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003737 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003738 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003739 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003740 OnChanged(eAttr, bNotify, false);
3741 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003742}
thestigb1a59592016-04-14 18:29:56 -07003743
tsepezd19e9122016-11-02 15:43:18 -07003744bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3745 CXFA_Measurement& mValue,
3746 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003747 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003748 void* pValue;
3749 int32_t iBytes;
3750 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003751 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003752 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003753 }
3754 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003755 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003756 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003757 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003758 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003759 }
tsepezd19e9122016-11-02 15:43:18 -07003760 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003761}
3762
3763CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3764 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003765 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003766}
3767
tsepezd19e9122016-11-02 15:43:18 -07003768bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3769 const CFX_WideString& wsValue,
3770 bool bNotify,
3771 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003772 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003773 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003774 if (eAttr == XFA_ATTRIBUTE_Value) {
3775 CFX_WideString* pClone = new CFX_WideString(wsValue);
3776 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3777 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003778 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003779 if (eAttr == XFA_ATTRIBUTE_Name)
3780 UpdateNameHash();
3781 }
thestigb1a59592016-04-14 18:29:56 -07003782 OnChanged(eAttr, bNotify, bScriptModify);
3783
3784 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3785 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003786 return true;
thestigb1a59592016-04-14 18:29:56 -07003787 }
3788
dsinclair070fcdf2016-06-22 22:04:54 -07003789 if (eAttr == XFA_ATTRIBUTE_Name &&
3790 (m_elementType == XFA_Element::DataValue ||
3791 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003792 return true;
thestigb1a59592016-04-14 18:29:56 -07003793 }
3794
3795 if (eAttr == XFA_ATTRIBUTE_Value) {
3796 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3797 switch (eXMLType) {
3798 case FDE_XMLNODE_Element:
3799 if (IsAttributeInXML()) {
3800 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003801 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3802 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003803 } else {
tsepezd19e9122016-11-02 15:43:18 -07003804 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003805 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3806 for (CXFA_Node* pChildDataNode =
3807 GetNodeItem(XFA_NODEITEM_FirstChild);
3808 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3809 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003810 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003811 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003812 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003813 }
3814 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003815 }
thestigb1a59592016-04-14 18:29:56 -07003816 if (bDeleteChildren) {
3817 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3818 }
3819 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3820 }
3821 break;
3822 case FDE_XMLNODE_Text:
3823 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3824 break;
3825 default:
dsinclair43854a52016-04-27 12:26:00 -07003826 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003827 }
tsepezd19e9122016-11-02 15:43:18 -07003828 return true;
thestigb1a59592016-04-14 18:29:56 -07003829 }
3830
3831 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3832 if (pInfo) {
dsinclair43854a52016-04-27 12:26:00 -07003833 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003834 CFX_WideString wsAttrName = pInfo->pName;
3835 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
dan sinclair65c7c232017-02-02 14:05:30 -08003836 wsAttrName = L"xfa:" + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003837 }
thestigb1a59592016-04-14 18:29:56 -07003838 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003839 }
tsepezd19e9122016-11-02 15:43:18 -07003840 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003841}
thestigb1a59592016-04-14 18:29:56 -07003842
tsepezd19e9122016-11-02 15:43:18 -07003843bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3844 const CFX_WideString& wsXMLValue,
3845 bool bNotify,
3846 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003847 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003848 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003849 CFX_WideString* pClone = new CFX_WideString(wsValue);
3850 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003851 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003852 if (IsNeedSavingXMLNode()) {
3853 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3854 switch (eXMLType) {
3855 case FDE_XMLNODE_Element:
3856 if (IsAttributeInXML()) {
dsinclairae95f762016-03-29 16:58:29 -07003857 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003858 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3859 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003860 } else {
tsepezd19e9122016-11-02 15:43:18 -07003861 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003862 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3863 for (CXFA_Node* pChildDataNode =
3864 GetNodeItem(XFA_NODEITEM_FirstChild);
3865 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3866 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003867 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003868 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003869 break;
3870 }
3871 }
3872 }
3873 if (bDeleteChildren) {
dsinclairae95f762016-03-29 16:58:29 -07003874 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003875 }
dsinclairae95f762016-03-29 16:58:29 -07003876 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003877 }
3878 break;
3879 case FDE_XMLNODE_Text:
dsinclairae95f762016-03-29 16:58:29 -07003880 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003881 break;
3882 default:
dsinclair43854a52016-04-27 12:26:00 -07003883 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003884 }
3885 }
tsepezd19e9122016-11-02 15:43:18 -07003886 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003887}
dsinclair5b36f0a2016-07-19 10:56:23 -07003888
tsepezd19e9122016-11-02 15:43:18 -07003889bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3890 CFX_WideString& wsValue,
3891 bool bUseDefault,
3892 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003893 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003894 if (eAttr == XFA_ATTRIBUTE_Value) {
3895 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3896 if (pStr) {
3897 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07003898 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003899 }
3900 } else {
3901 CFX_WideStringC wsValueC;
3902 if (GetMapModuleString(pKey, wsValueC)) {
3903 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003904 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003905 }
3906 }
3907 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003908 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003909 }
weili44f8faf2016-06-01 14:03:56 -07003910 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003911 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003912 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003913 wsValue = (const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003914 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003915 }
tsepezd19e9122016-11-02 15:43:18 -07003916 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003917}
dsinclair5b36f0a2016-07-19 10:56:23 -07003918
tsepezd19e9122016-11-02 15:43:18 -07003919bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3920 CFX_WideStringC& wsValue,
3921 bool bUseDefault,
3922 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003923 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003924 if (eAttr == XFA_ATTRIBUTE_Value) {
3925 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3926 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07003927 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07003928 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003929 }
3930 } else {
3931 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003932 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003933 }
3934 }
3935 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003936 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003937 }
weili44f8faf2016-06-01 14:03:56 -07003938 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003939 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003940 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003941 wsValue = (CFX_WideStringC)(const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003942 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003943 }
tsepezd19e9122016-11-02 15:43:18 -07003944 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003945}
dsinclair5b36f0a2016-07-19 10:56:23 -07003946
tsepezd19e9122016-11-02 15:43:18 -07003947bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
3948 void* pData,
3949 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003950 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003951 return SetUserData(pKey, pData, pCallbackInfo);
3952}
dsinclair5b36f0a2016-07-19 10:56:23 -07003953
tsepezd19e9122016-11-02 15:43:18 -07003954bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003955 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003956 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07003957 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04003958}
dsinclair5b36f0a2016-07-19 10:56:23 -07003959
tsepezd19e9122016-11-02 15:43:18 -07003960bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
3961 XFA_ATTRIBUTETYPE eType,
3962 void* pValue,
3963 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003964 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003965 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003966 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07003967 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003968 if (IsNeedSavingXMLNode()) {
dsinclair43854a52016-04-27 12:26:00 -07003969 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04003970 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3971 if (pInfo) {
3972 switch (eType) {
3973 case XFA_ATTRIBUTETYPE_Enum:
dsinclairae95f762016-03-29 16:58:29 -07003974 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04003975 ->SetString(
3976 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07003977 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04003978 ->pName);
3979 break;
3980 case XFA_ATTRIBUTETYPE_Boolean:
dsinclairae95f762016-03-29 16:58:29 -07003981 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003982 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04003983 break;
3984 case XFA_ATTRIBUTETYPE_Integer:
dsinclairae95f762016-03-29 16:58:29 -07003985 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04003986 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue);
3987 break;
3988 default:
dsinclair43854a52016-04-27 12:26:00 -07003989 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003990 }
3991 }
3992 }
tsepezd19e9122016-11-02 15:43:18 -07003993 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003994}
dsinclair5b36f0a2016-07-19 10:56:23 -07003995
tsepezd19e9122016-11-02 15:43:18 -07003996bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
3997 XFA_ATTRIBUTETYPE eType,
3998 bool bUseDefault,
3999 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07004000 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004001 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004002 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004003 }
4004 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004005 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004006 }
dsinclair070fcdf2016-06-22 22:04:54 -07004007 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004008 m_ePacket);
4009}
dsinclair5b36f0a2016-07-19 10:56:23 -07004010
tsepezd19e9122016-11-02 15:43:18 -07004011bool CXFA_Node::SetUserData(void* pKey,
4012 void* pData,
4013 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004014 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4015 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004016 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004017}
dsinclair5b36f0a2016-07-19 10:56:23 -07004018
tsepezd19e9122016-11-02 15:43:18 -07004019bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004020 int32_t iBytes = 0;
4021 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004022 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004023 }
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004024 return iBytes == sizeof(void*) && memcpy(&pData, pData, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004025}
dsinclair5b36f0a2016-07-19 10:56:23 -07004026
tsepezd19e9122016-11-02 15:43:18 -07004027bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4028 const CFX_WideString& wsXMLValue,
4029 bool bNotify,
4030 bool bScriptModify,
4031 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004032 CXFA_Node* pNode = nullptr;
4033 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004034 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004035 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004036 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004037 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004038 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004039 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004040 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004041 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004042 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004043 CXFA_Node* pBind = GetBindData();
4044 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004045 std::vector<CFX_WideString> wsSaveTextArray;
Tom Sepezf8a94392017-03-14 12:13:22 -07004046 size_t iSize = 0;
Dan Sinclair1770c022016-03-14 14:14:16 -04004047 if (!wsContent.IsEmpty()) {
4048 int32_t iStart = 0;
4049 int32_t iLength = wsContent.GetLength();
4050 int32_t iEnd = wsContent.Find(L'\n', iStart);
4051 iEnd = (iEnd == -1) ? iLength : iEnd;
4052 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004053 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004054 iStart = iEnd + 1;
4055 if (iStart >= iLength) {
4056 break;
4057 }
4058 iEnd = wsContent.Find(L'\n', iStart);
4059 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004060 wsSaveTextArray.push_back(
4061 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004062 }
4063 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004064 iSize = wsSaveTextArray.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004065 }
4066 if (iSize == 0) {
4067 while (CXFA_Node* pChildNode =
4068 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4069 pBind->RemoveChild(pChildNode);
4070 }
4071 } else {
Tom Sepezf8a94392017-03-14 12:13:22 -07004072 std::vector<CXFA_Node*> valueNodes = pBind->GetNodeList(
4073 XFA_NODEFILTER_Children, XFA_Element::DataValue);
4074 size_t iDatas = valueNodes.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004075 if (iDatas < iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004076 size_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004077 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004078 while (iAddNodes-- > 0) {
4079 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004080 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004081 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004082 pValueNodes->CreateXMLMappingNode();
4083 pBind->InsertChild(pValueNodes);
4084 }
weili44f8faf2016-06-01 14:03:56 -07004085 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004086 } else if (iDatas > iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004087 size_t iDelNodes = iDatas - iSize;
Dan Sinclair1770c022016-03-14 14:14:16 -04004088 while (iDelNodes-- > 0) {
4089 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4090 }
4091 }
4092 int32_t i = 0;
4093 for (CXFA_Node* pValueNode =
4094 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4095 pValueNode; pValueNode = pValueNode->GetNodeItem(
4096 XFA_NODEITEM_NextSibling)) {
4097 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004098 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004099 i++;
4100 }
4101 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004102 for (CXFA_Node* pArrayNode : pBind->GetBindItems()) {
4103 if (pArrayNode != this) {
4104 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4105 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004106 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004107 }
4108 }
4109 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004110 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004111 pNode = this;
4112 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004113 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004114 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004115 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004116 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004117 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004118 }
4119 pBindNode = GetBindData();
4120 if (pBindNode && bSyncData) {
4121 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004122 bScriptModify, false);
Tom Sepezf8a94392017-03-14 12:13:22 -07004123 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4124 if (pArrayNode != this) {
4125 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, true,
4126 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004127 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004128 }
4129 }
weili44f8faf2016-06-01 14:03:56 -07004130 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004131 break;
4132 }
dsinclairc5a8f212016-06-20 11:11:12 -07004133 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004134 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004135 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004136 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004137 if (wsContentType == L"text/html") {
4138 wsContentType = L"";
tsepez4c3debb2016-04-08 12:20:38 -07004139 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004140 }
4141 }
4142 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4143 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004144 pContentRawDataNode = CreateSamePacketNode(
dan sinclair65c7c232017-02-02 14:05:30 -08004145 (wsContentType == L"text/xml") ? XFA_Element::Sharpxml
4146 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004147 InsertChild(pContentRawDataNode);
4148 }
4149 return pContentRawDataNode->SetScriptContent(
4150 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4151 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004152 case XFA_ObjectType::NodeC:
4153 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004154 pNode = this;
4155 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004156 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004157 pNode = this;
4158 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4159 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4160 if (pParent) {
4161 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4162 }
dsinclair070fcdf2016-06-22 22:04:54 -07004163 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004164 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4165 if (pParent && pParent->IsContainerNode()) {
4166 pBindNode = pParent->GetBindData();
4167 if (pBindNode) {
4168 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004169 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004170 }
4171 }
4172 }
4173 }
4174 break;
4175 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004176 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004177 pNode = this;
4178 pBindNode = this;
4179 }
4180 break;
4181 }
4182 if (pNode) {
4183 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4184 if (pBindNode && bSyncData) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004185 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4186 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4187 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004188 }
4189 }
tsepezd19e9122016-11-02 15:43:18 -07004190 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004191 }
tsepezd19e9122016-11-02 15:43:18 -07004192 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004193}
dsinclair5b36f0a2016-07-19 10:56:23 -07004194
tsepezd19e9122016-11-02 15:43:18 -07004195bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4196 const CFX_WideString& wsXMLValue,
4197 bool bNotify,
4198 bool bScriptModify,
4199 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004200 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4201 bSyncData);
4202}
dsinclair5b36f0a2016-07-19 10:56:23 -07004203
tsepezd19e9122016-11-02 15:43:18 -07004204CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004205 CFX_WideString wsContent;
4206 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4207}
dsinclair5b36f0a2016-07-19 10:56:23 -07004208
Dan Sinclair1770c022016-03-14 14:14:16 -04004209CFX_WideString CXFA_Node::GetContent() {
4210 return GetScriptContent();
4211}
dsinclair5b36f0a2016-07-19 10:56:23 -07004212
tsepezd19e9122016-11-02 15:43:18 -07004213bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4214 bool bScriptModify,
4215 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004216 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004217 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004218 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004219 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004220 pNode = this;
4221 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004222 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004223 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004224 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004225 }
4226 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4227 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
dan sinclair65c7c232017-02-02 14:05:30 -08004228 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004229 }
4230 return pChildValue
4231 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004232 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004233 }
4234 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004235 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004236 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4237 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004238 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004239 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004240 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004241 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004242 if (wsContentType == L"text/html") {
dsinclair56a8b192016-06-21 14:15:25 -07004243 element = XFA_Element::SharpxHTML;
dan sinclair65c7c232017-02-02 14:05:30 -08004244 } else if (wsContentType == L"text/xml") {
dsinclair56a8b192016-06-21 14:15:25 -07004245 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004246 }
4247 }
4248 pContentRawDataNode = CreateSamePacketNode(element);
4249 InsertChild(pContentRawDataNode);
4250 }
4251 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4252 }
dsinclairc5a8f212016-06-20 11:11:12 -07004253 case XFA_ObjectType::NodeC:
4254 case XFA_ObjectType::NodeV:
4255 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004256 pNode = this;
4257 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004258 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004259 pNode = this;
4260 }
4261 break;
4262 }
4263 if (pNode) {
4264 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004265 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004266 if (pScriptContext) {
4267 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4268 }
4269 }
tsepezd19e9122016-11-02 15:43:18 -07004270 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004271 }
tsepezd19e9122016-11-02 15:43:18 -07004272 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004273}
dsinclair5b36f0a2016-07-19 10:56:23 -07004274
Dan Sinclair1770c022016-03-14 14:14:16 -04004275CXFA_Node* CXFA_Node::GetModelNode() {
4276 switch (GetPacketID()) {
4277 case XFA_XDPPACKET_XDP:
4278 return m_pDocument->GetRoot();
4279 case XFA_XDPPACKET_Config:
4280 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4281 case XFA_XDPPACKET_Template:
4282 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4283 case XFA_XDPPACKET_Form:
4284 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4285 case XFA_XDPPACKET_Datasets:
4286 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4287 case XFA_XDPPACKET_LocaleSet:
4288 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4289 case XFA_XDPPACKET_ConnectionSet:
4290 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4291 case XFA_XDPPACKET_SourceSet:
4292 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4293 case XFA_XDPPACKET_Xdc:
4294 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4295 default:
4296 return this;
4297 }
4298}
dsinclair5b36f0a2016-07-19 10:56:23 -07004299
tsepezd19e9122016-11-02 15:43:18 -07004300bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004301 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004302 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
dsinclairae95f762016-03-29 16:58:29 -07004303 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004304 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004305 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004306 }
dsinclairae95f762016-03-29 16:58:29 -07004307 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004308 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004309 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
dsinclairae95f762016-03-29 16:58:29 -07004310 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004311 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004312 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004313 }
4314 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004315 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004316 }
dsinclair070fcdf2016-06-22 22:04:54 -07004317 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004318 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4319 return XFA_FDEExtension_ResolveNamespaceQualifier(
dsinclairae95f762016-03-29 16:58:29 -07004320 static_cast<CFDE_XMLElement*>(pXMLNode),
4321 GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004322 }
dsinclairae95f762016-03-29 16:58:29 -07004323 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004324 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004325 } else {
4326 CXFA_Node* pModelNode = GetModelNode();
4327 return pModelNode->TryNamespace(wsNamespace);
4328 }
4329}
dsinclair5b36f0a2016-07-19 10:56:23 -07004330
Dan Sinclair1770c022016-03-14 14:14:16 -04004331CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004332 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004333 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004334 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004335 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004336 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004337 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004338 if (!pProperty || index >= pProperty->uOccur)
4339 return nullptr;
4340
Dan Sinclair1770c022016-03-14 14:14:16 -04004341 CXFA_Node* pNode = m_pChild;
4342 int32_t iCount = 0;
4343 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004344 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004345 iCount++;
4346 if (iCount > index) {
4347 return pNode;
4348 }
4349 }
4350 }
weili44f8faf2016-06-01 14:03:56 -07004351 if (!bCreateProperty)
4352 return nullptr;
4353
Dan Sinclair1770c022016-03-14 14:14:16 -04004354 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4355 pNode = m_pChild;
4356 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4357 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004358 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004359 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4360 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004361 }
4362 }
dsinclaira1b07722016-07-11 08:20:58 -07004363
Dan Sinclair1770c022016-03-14 14:14:16 -04004364 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004365 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004366 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004367 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004368 if (!pNewNode)
4369 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004370 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004371 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004372 }
4373 return pNewNode;
4374}
dsinclair5b36f0a2016-07-19 10:56:23 -07004375
tsepezd19e9122016-11-02 15:43:18 -07004376int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004377 CXFA_Node* pNode = m_pChild;
4378 int32_t iCount = 0;
4379 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004380 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004381 if (bOnlyChild) {
4382 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004383 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004384 if (pProperty) {
4385 continue;
4386 }
4387 }
4388 iCount++;
4389 }
4390 }
4391 return iCount;
4392}
dsinclair5b36f0a2016-07-19 10:56:23 -07004393
Dan Sinclair1770c022016-03-14 14:14:16 -04004394CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004395 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004396 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004397 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004398 CXFA_Node* pNode = m_pChild;
4399 int32_t iCount = 0;
4400 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004401 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004402 if (bOnlyChild) {
4403 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004404 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004405 if (pProperty) {
4406 continue;
4407 }
4408 }
4409 iCount++;
4410 if (iCount > index) {
4411 return pNode;
4412 }
4413 }
4414 }
weili44f8faf2016-06-01 14:03:56 -07004415 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004416}
dsinclair5b36f0a2016-07-19 10:56:23 -07004417
Dan Sinclair1770c022016-03-14 14:14:16 -04004418int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4419 ASSERT(!pNode->m_pNext);
4420 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004421 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004422 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004423 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004424
weili44f8faf2016-06-01 14:03:56 -07004425 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004426 if (index > 0) {
4427 return -1;
4428 }
4429 pNode->m_pNext = m_pChild;
4430 m_pChild = pNode;
4431 index = 0;
4432 } else if (index < 0) {
4433 m_pLastChild->m_pNext = pNode;
4434 } else {
4435 CXFA_Node* pPrev = m_pChild;
4436 int32_t iCount = 0;
4437 while (++iCount != index && pPrev->m_pNext) {
4438 pPrev = pPrev->m_pNext;
4439 }
4440 if (index > 0 && index != iCount) {
4441 return -1;
4442 }
4443 pNode->m_pNext = pPrev->m_pNext;
4444 pPrev->m_pNext = pNode;
4445 index = iCount;
4446 }
weili44f8faf2016-06-01 14:03:56 -07004447 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004448 m_pLastChild = pNode;
4449 }
4450 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004451 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004452 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004453 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004454 if (pNotify)
4455 pNotify->OnChildAdded(this);
4456
Dan Sinclair1770c022016-03-14 14:14:16 -04004457 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004458 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004459 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004460 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004461 }
4462 return index;
4463}
weili6e1ae862016-05-04 18:25:27 -07004464
tsepezd19e9122016-11-02 15:43:18 -07004465bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004466 if (!pNode || pNode->m_pParent ||
4467 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004468 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004469 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004470 }
tsepezd19e9122016-11-02 15:43:18 -07004471 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004472 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004473 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004474
4475 int32_t nIndex = -1;
4476 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004477 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004478 pNode->m_pNext = m_pChild;
4479 m_pChild = pNode;
4480 nIndex = 0;
4481 } else if (!pBeforeNode) {
4482 pNode->m_pNext = m_pLastChild->m_pNext;
4483 m_pLastChild->m_pNext = pNode;
4484 } else {
4485 nIndex = 1;
4486 CXFA_Node* pPrev = m_pChild;
4487 while (pPrev->m_pNext != pBeforeNode) {
4488 pPrev = pPrev->m_pNext;
4489 nIndex++;
4490 }
4491 pNode->m_pNext = pPrev->m_pNext;
4492 pPrev->m_pNext = pNode;
4493 }
weili44f8faf2016-06-01 14:03:56 -07004494 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004495 m_pLastChild = pNode;
4496 }
4497 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004498 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004499 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004500 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004501 if (pNotify)
4502 pNotify->OnChildAdded(this);
4503
Dan Sinclair1770c022016-03-14 14:14:16 -04004504 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004505 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004506 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004507 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004508 }
tsepezd19e9122016-11-02 15:43:18 -07004509 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004510}
dsinclair5b36f0a2016-07-19 10:56:23 -07004511
Dan Sinclair1770c022016-03-14 14:14:16 -04004512CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4513 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004514 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004515 }
4516 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4517 pSibling = pSibling->m_pNext) {
4518 if (pSibling->m_pNext == this) {
4519 return pSibling;
4520 }
4521 }
weili44f8faf2016-06-01 14:03:56 -07004522 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004523}
dsinclair5b36f0a2016-07-19 10:56:23 -07004524
tsepezd19e9122016-11-02 15:43:18 -07004525bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004526 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004527 ASSERT(false);
4528 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004529 }
4530 if (m_pChild == pNode) {
4531 m_pChild = pNode->m_pNext;
4532 if (m_pLastChild == pNode) {
4533 m_pLastChild = pNode->m_pNext;
4534 }
weili44f8faf2016-06-01 14:03:56 -07004535 pNode->m_pNext = nullptr;
4536 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004537 } else {
4538 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4539 pPrev->m_pNext = pNode->m_pNext;
4540 if (m_pLastChild == pNode) {
4541 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4542 }
weili44f8faf2016-06-01 14:03:56 -07004543 pNode->m_pNext = nullptr;
4544 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004545 }
weili44f8faf2016-06-01 14:03:56 -07004546 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004547 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004548 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004549 m_pDocument->AddPurgeNode(pNode);
4550 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4551 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004552 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4553 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004554 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07004555 CFDE_XMLElement* pXMLElement =
4556 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004557 CFX_WideStringC wsAttributeName =
4558 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004559 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004560 }
4561 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004562 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -07004563 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004564 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4565 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004566 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004567 }
4568 pNode->m_pXMLNode = pNewXMLElement;
4569 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4570 } else {
4571 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4572 }
dsinclairc5a8f212016-06-20 11:11:12 -07004573 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004574 }
tsepezd19e9122016-11-02 15:43:18 -07004575 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004576}
dsinclair5b36f0a2016-07-19 10:56:23 -07004577
Dan Sinclair1770c022016-03-14 14:14:16 -04004578CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004579 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004580}
dsinclair5b36f0a2016-07-19 10:56:23 -07004581
tsepez736f28a2016-03-25 14:19:51 -07004582CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004583 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4584 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4585 if (pNode->GetNameHash() == dwNameHash) {
4586 return pNode;
4587 }
4588 }
weili44f8faf2016-06-01 14:03:56 -07004589 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004590}
dsinclair5b36f0a2016-07-19 10:56:23 -07004591
dsinclair41cb62e2016-06-23 09:20:32 -07004592CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004593 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4594 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004595 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004596 return pNode;
4597 }
4598 }
weili44f8faf2016-06-01 14:03:56 -07004599 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004600}
dsinclair5b36f0a2016-07-19 10:56:23 -07004601
tsepez736f28a2016-03-25 14:19:51 -07004602CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004603 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4604 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4605 if (pNode->GetNameHash() == dwNameHash) {
4606 return pNode;
4607 }
4608 }
weili44f8faf2016-06-01 14:03:56 -07004609 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004610}
dsinclair5b36f0a2016-07-19 10:56:23 -07004611
Dan Sinclair1770c022016-03-14 14:14:16 -04004612CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4613 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004614 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004615}
dsinclair5b36f0a2016-07-19 10:56:23 -07004616
dsinclair41cb62e2016-06-23 09:20:32 -07004617CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004618 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4619 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004620 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004621 return pNode;
4622 }
4623 }
weili44f8faf2016-06-01 14:03:56 -07004624 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004625}
dsinclair5b36f0a2016-07-19 10:56:23 -07004626
Dan Sinclair1770c022016-03-14 14:14:16 -04004627int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004628 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004629 if (!pScriptContext) {
4630 return -1;
4631 }
4632 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4633}
dsinclair5b36f0a2016-07-19 10:56:23 -07004634
Dan Sinclair1770c022016-03-14 14:14:16 -04004635int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004636 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004637 if (!pScriptContext) {
4638 return -1;
4639 }
4640 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4641}
dsinclair5b36f0a2016-07-19 10:56:23 -07004642
Dan Sinclair1770c022016-03-14 14:14:16 -04004643void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004644 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004645 if (!pScriptContext) {
4646 return;
4647 }
4648 pScriptContext->GetSomExpression(this, wsSOMExpression);
4649}
dsinclair5b36f0a2016-07-19 10:56:23 -07004650
Dan Sinclair1770c022016-03-14 14:14:16 -04004651CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004652 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004653 if (m_ePacket == XFA_XDPPACKET_Form) {
4654 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004655 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004656 return pInstanceMgr;
4657 }
4658 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4659 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004660 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004661 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004662 pNode->m_dwNameHash != m_dwNameHash) {
4663 break;
4664 }
dsinclair56a8b192016-06-21 14:15:25 -07004665 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004666 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4667 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4668 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4669 wsInstName.Mid(1) == wsName) {
4670 pInstanceMgr = pNode;
4671 }
4672 break;
4673 }
4674 }
4675 }
4676 return pInstanceMgr;
4677}
dsinclair5b36f0a2016-07-19 10:56:23 -07004678
Dan Sinclair1770c022016-03-14 14:14:16 -04004679CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004680 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004681}
dsinclair5b36f0a2016-07-19 10:56:23 -07004682
dsinclairc5a8f212016-06-20 11:11:12 -07004683bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4684 if (m_uNodeFlags & dwFlag)
4685 return true;
4686 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4687 return m_pParent && m_pParent->HasFlag(dwFlag);
4688 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004689}
thestigb1a59592016-04-14 18:29:56 -07004690
4691void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004692 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004693 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004694 if (pNotify) {
4695 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004696 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004697 }
dsinclairc5a8f212016-06-20 11:11:12 -07004698 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004699}
thestigb1a59592016-04-14 18:29:56 -07004700
4701void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004702 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004703}
4704
tsepezd19e9122016-11-02 15:43:18 -07004705bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004706 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4707}
thestigb1a59592016-04-14 18:29:56 -07004708
4709void CXFA_Node::OnRemoved(bool bNotify) {
4710 if (!bNotify)
4711 return;
4712
dsinclaira1b07722016-07-11 08:20:58 -07004713 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004714 if (pNotify)
4715 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004716}
thestigb1a59592016-04-14 18:29:56 -07004717
4718void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004719 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004720 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004721 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004722 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004723 }
4724 }
4725}
thestigb1a59592016-04-14 18:29:56 -07004726
Dan Sinclair1770c022016-03-14 14:14:16 -04004727void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004728 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004729 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004730 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004731 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004732 }
4733}
thestigb1a59592016-04-14 18:29:56 -07004734
Dan Sinclair1770c022016-03-14 14:14:16 -04004735int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004736 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004737 int32_t iRet = XFA_EVENTERROR_NotExist;
4738 const XFA_ExecEventParaInfo* eventParaInfo =
4739 GetEventParaInfoByName(wsEventName);
4740 if (eventParaInfo) {
4741 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004742 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004743 if (!pNotify) {
4744 return iRet;
4745 }
4746 if (validFlags == 1) {
4747 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4748 } else if (validFlags == 2) {
4749 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004750 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004751 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004752 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004753 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004754 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004755 }
4756 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004757 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004758 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004759 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004760 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004761 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004762 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004763 }
4764 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004765 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004766 }
4767 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004768 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004769 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004770 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004771 }
4772 } else if (validFlags == 6) {
4773 CXFA_WidgetData* pWidgetData = GetWidgetData();
4774 if (pWidgetData) {
4775 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004776 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004777 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004778 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004779 }
4780 }
4781 } else if (validFlags == 7) {
4782 CXFA_WidgetData* pWidgetData = GetWidgetData();
4783 if (pWidgetData) {
4784 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004785 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004786 (!pWidgetData->IsListBox())) {
4787 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004788 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004789 }
4790 }
4791 }
4792 }
4793 return iRet;
4794}
dsinclair5b36f0a2016-07-19 10:56:23 -07004795
Dan Sinclair1770c022016-03-14 14:14:16 -04004796void CXFA_Node::UpdateNameHash() {
4797 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004798 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004799 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004800 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004801 wsName = GetCData(XFA_ATTRIBUTE_Name);
4802 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004803 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004804 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004805 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004806 }
4807}
dsinclair5b36f0a2016-07-19 10:56:23 -07004808
dsinclairae95f762016-03-29 16:58:29 -07004809CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004810 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004811 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
dsinclairae95f762016-03-29 16:58:29 -07004812 m_pXMLNode = new CFDE_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004813 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004814 }
4815 return m_pXMLNode;
4816}
dsinclair5b36f0a2016-07-19 10:56:23 -07004817
tsepezd19e9122016-11-02 15:43:18 -07004818bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004819 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004820 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004821}
4822
4823XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4824 if (!m_pMapModuleData)
4825 m_pMapModuleData = new XFA_MAPMODULEDATA;
4826 return m_pMapModuleData;
4827}
4828
4829XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4830 return m_pMapModuleData;
4831}
4832
4833void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4834 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004835 pModule->m_ValueMap[pKey] = pValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04004836}
4837
tsepezd19e9122016-11-02 15:43:18 -07004838bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
tsepez6bb3b892017-01-05 12:18:41 -08004839 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004840 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004841 if (pModule) {
4842 auto it = pModule->m_ValueMap.find(pKey);
4843 if (it != pModule->m_ValueMap.end()) {
4844 pValue = it->second;
4845 return true;
4846 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004847 }
tsepez6bb3b892017-01-05 12:18:41 -08004848 if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4849 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004850 }
tsepezd19e9122016-11-02 15:43:18 -07004851 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004852}
dsinclair5b36f0a2016-07-19 10:56:23 -07004853
Dan Sinclair1770c022016-03-14 14:14:16 -04004854void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004855 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair812e96c2017-03-13 16:43:37 -04004856 wsValue.GetLength() * sizeof(wchar_t));
Dan Sinclair1770c022016-03-14 14:14:16 -04004857}
dsinclair5b36f0a2016-07-19 10:56:23 -07004858
tsepezd19e9122016-11-02 15:43:18 -07004859bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004860 void* pValue;
4861 int32_t iBytes;
4862 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004863 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004864 }
Dan Sinclair812e96c2017-03-13 16:43:37 -04004865 wsValue = CFX_WideStringC((const wchar_t*)pValue, iBytes / sizeof(wchar_t));
tsepezd19e9122016-11-02 15:43:18 -07004866 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004867}
dsinclair5b36f0a2016-07-19 10:56:23 -07004868
Dan Sinclair1770c022016-03-14 14:14:16 -04004869void CXFA_Node::SetMapModuleBuffer(
4870 void* pKey,
4871 void* pValue,
4872 int32_t iBytes,
4873 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4874 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4875 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004876 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004877 pBuffer =
4878 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4879 } else if (pBuffer->iBytes != iBytes) {
4880 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4881 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4882 }
4883 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4884 sizeof(XFA_MAPDATABLOCK) + iBytes);
4885 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4886 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4887 }
weili44f8faf2016-06-01 14:03:56 -07004888 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04004889 return;
weili44f8faf2016-06-01 14:03:56 -07004890
Dan Sinclair1770c022016-03-14 14:14:16 -04004891 pBuffer->pCallbackInfo = pCallbackInfo;
4892 pBuffer->iBytes = iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004893 memcpy(pBuffer->GetData(), pValue, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004894}
dsinclair5b36f0a2016-07-19 10:56:23 -07004895
tsepezd19e9122016-11-02 15:43:18 -07004896bool CXFA_Node::GetMapModuleBuffer(void* pKey,
4897 void*& pValue,
4898 int32_t& iBytes,
4899 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07004900 XFA_MAPDATABLOCK* pBuffer = nullptr;
tsepez6bb3b892017-01-05 12:18:41 -08004901 for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004902 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004903 if (pModule) {
4904 auto it = pModule->m_BufferMap.find(pKey);
4905 if (it != pModule->m_BufferMap.end()) {
4906 pBuffer = it->second;
4907 break;
4908 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004909 }
tsepez6bb3b892017-01-05 12:18:41 -08004910 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4911 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004912 }
tsepez6bb3b892017-01-05 12:18:41 -08004913 if (!pBuffer)
tsepezd19e9122016-11-02 15:43:18 -07004914 return false;
tsepez6bb3b892017-01-05 12:18:41 -08004915
Dan Sinclair1770c022016-03-14 14:14:16 -04004916 pValue = pBuffer->GetData();
4917 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07004918 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004919}
dsinclair5b36f0a2016-07-19 10:56:23 -07004920
tsepezd19e9122016-11-02 15:43:18 -07004921bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
tsepez6bb3b892017-01-05 12:18:41 -08004922 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004923 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004924 if (pModule) {
4925 auto it1 = pModule->m_ValueMap.find(pKey);
4926 if (it1 != pModule->m_ValueMap.end())
4927 return true;
4928
4929 auto it2 = pModule->m_BufferMap.find(pKey);
4930 if (it2 != pModule->m_BufferMap.end())
4931 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004932 }
tsepez6bb3b892017-01-05 12:18:41 -08004933 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4934 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004935 }
tsepezd19e9122016-11-02 15:43:18 -07004936 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004937}
dsinclair5b36f0a2016-07-19 10:56:23 -07004938
Dan Sinclair1770c022016-03-14 14:14:16 -04004939void CXFA_Node::RemoveMapModuleKey(void* pKey) {
4940 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
4941 if (!pModule)
4942 return;
4943
4944 if (pKey) {
tsepez6bb3b892017-01-05 12:18:41 -08004945 auto it = pModule->m_BufferMap.find(pKey);
4946 if (it != pModule->m_BufferMap.end()) {
4947 XFA_MAPDATABLOCK* pBuffer = it->second;
Dan Sinclair1770c022016-03-14 14:14:16 -04004948 if (pBuffer) {
tsepez6bb3b892017-01-05 12:18:41 -08004949 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
Dan Sinclair1770c022016-03-14 14:14:16 -04004950 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004951 FX_Free(pBuffer);
4952 }
tsepez6bb3b892017-01-05 12:18:41 -08004953 pModule->m_BufferMap.erase(it);
Dan Sinclair1770c022016-03-14 14:14:16 -04004954 }
tsepez6bb3b892017-01-05 12:18:41 -08004955 pModule->m_ValueMap.erase(pKey);
4956 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04004957 }
tsepez6bb3b892017-01-05 12:18:41 -08004958
4959 for (auto& pair : pModule->m_BufferMap) {
4960 XFA_MAPDATABLOCK* pBuffer = pair.second;
4961 if (pBuffer) {
4962 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
4963 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4964 FX_Free(pBuffer);
4965 }
4966 }
4967 pModule->m_BufferMap.clear();
4968 pModule->m_ValueMap.clear();
4969 delete pModule;
Dan Sinclair1770c022016-03-14 14:14:16 -04004970}
dsinclair5b36f0a2016-07-19 10:56:23 -07004971
tsepez6bb3b892017-01-05 12:18:41 -08004972void CXFA_Node::MergeAllData(void* pDstModule) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004973 XFA_MAPMODULEDATA* pDstModuleData =
4974 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
4975 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004976 if (!pSrcModuleData)
Dan Sinclair1770c022016-03-14 14:14:16 -04004977 return;
tsepez6bb3b892017-01-05 12:18:41 -08004978
4979 for (const auto& pair : pSrcModuleData->m_ValueMap)
4980 pDstModuleData->m_ValueMap[pair.first] = pair.second;
4981
4982 for (const auto& pair : pSrcModuleData->m_BufferMap) {
4983 XFA_MAPDATABLOCK* pSrcBuffer = pair.second;
4984 XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first];
Dan Sinclair1770c022016-03-14 14:14:16 -04004985 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
4986 !pSrcBuffer->pCallbackInfo->pCopy) {
tsepez6bb3b892017-01-05 12:18:41 -08004987 if (pDstBuffer) {
4988 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
4989 pDstModuleData->m_BufferMap.erase(pair.first);
Dan Sinclair1770c022016-03-14 14:14:16 -04004990 }
4991 continue;
4992 }
tsepez6bb3b892017-01-05 12:18:41 -08004993 if (!pDstBuffer) {
4994 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
Dan Sinclair1770c022016-03-14 14:14:16 -04004995 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08004996 } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) {
4997 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
4998 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004999 }
tsepez6bb3b892017-01-05 12:18:41 -08005000 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
5001 uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5002 } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5003 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005004 }
tsepez6bb3b892017-01-05 12:18:41 -08005005 if (!pDstBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005006 continue;
5007 }
tsepez6bb3b892017-01-05 12:18:41 -08005008 pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5009 pDstBuffer->iBytes = pSrcBuffer->iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04005010 memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08005011 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) {
5012 pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005013 }
5014 }
5015}
dsinclair5b36f0a2016-07-19 10:56:23 -07005016
Dan Sinclair1770c022016-03-14 14:14:16 -04005017void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5018 if (!pDstModule) {
5019 return;
5020 }
tsepezd19e9122016-11-02 15:43:18 -07005021 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005022 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005023 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005024 }
dsinclair070fcdf2016-06-22 22:04:54 -07005025 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005026 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005027 }
weili44f8faf2016-06-01 14:03:56 -07005028 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5029 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005030 if (bNeedMove) {
5031 pSrcModuleData = GetMapModuleData();
5032 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005033 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005034 }
5035 pDstModuleData = pDstModule->CreateMapModuleData();
5036 }
5037 if (bNeedMove) {
tsepez6bb3b892017-01-05 12:18:41 -08005038 auto it = pSrcModuleData->m_BufferMap.find(pKey);
5039 if (it != pSrcModuleData->m_BufferMap.end()) {
5040 XFA_MAPDATABLOCK* pBufferBlockData = it->second;
5041 if (pBufferBlockData) {
5042 pSrcModuleData->m_BufferMap.erase(pKey);
5043 pDstModuleData->m_BufferMap[pKey] = pBufferBlockData;
5044 }
Dan Sinclair1770c022016-03-14 14:14:16 -04005045 }
5046 }
dsinclairc5a8f212016-06-20 11:11:12 -07005047 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005048 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005049 CFX_WideString wsFormatValue(wsValue);
5050 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5051 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005052 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005053 }
tsepezd19e9122016-11-02 15:43:18 -07005054 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005055 }
5056}
dsinclair5b36f0a2016-07-19 10:56:23 -07005057
Dan Sinclair1770c022016-03-14 14:14:16 -04005058void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5059 CXFA_Node* pDstModule,
5060 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005061 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005062 if (!pSrcModule || !pDstModule || !pKey) {
5063 return;
5064 }
5065 if (bRecursive) {
5066 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5067 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5068 for (; pSrcChild && pDstChild;
5069 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5070 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005071 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005072 }
5073 }
5074 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5075}
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05005076
5077void CXFA_Node::ThrowMissingPropertyException(
5078 const CFX_WideString& obj,
5079 const CFX_WideString& prop) const {
5080 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(),
5081 prop.c_str());
5082}
5083
5084void CXFA_Node::ThrowTooManyOccurancesException(
5085 const CFX_WideString& obj) const {
5086 ThrowException(
5087 L"The element [%s] has violated its allowable number of occurrences.",
5088 obj.c_str());
5089}