blob: 26dc6bd831239e54422c9777a9b7c7388be37a73 [file] [log] [blame]
dsinclair5b36f0a2016-07-19 10:56:23 -07001// Copyright 2016 PDFium Authors. All rights reserved.
Dan Sinclair1770c022016-03-14 14:14:16 -04002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclairefcae5d2017-03-29 14:47:46 -04007#include "xfa/fxfa/parser/cxfa_node.h"
Dan Sinclair1770c022016-03-14 14:14:16 -04008
dsinclair5b36f0a2016-07-19 10:56:23 -07009#include <map>
tsepezaadedf92016-05-12 10:08:06 -070010#include <memory>
Tom Sepezd4db58f2017-03-02 14:57:59 -080011#include <unordered_set>
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050012#include <utility>
tsepez51709be2016-12-08 10:55:57 -080013#include <vector>
tsepezaadedf92016-05-12 10:08:06 -070014
Dan Sinclairb929ab02017-03-29 15:18:16 -040015#include "core/fxcrt/cfx_decimal.h"
dsinclaira52ab742016-09-29 13:59:29 -070016#include "core/fxcrt/fx_ext.h"
dsinclair43554682016-09-29 17:29:48 -070017#include "fxjs/cfxjse_value.h"
tsepeza9caab92016-12-14 05:57:10 -080018#include "third_party/base/ptr_util.h"
tsepezaadedf92016-05-12 10:08:06 -070019#include "third_party/base/stl_util.h"
Dan Sinclairac355892017-04-03 16:46:21 -040020#include "xfa/fde/xml/cfde_xmlelement.h"
21#include "xfa/fde/xml/cfde_xmlnode.h"
22#include "xfa/fde/xml/cfde_xmltext.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040023#include "xfa/fgas/crt/fgas_codepage.h"
dsinclairdf4bc592016-03-31 20:34:43 -070024#include "xfa/fxfa/app/xfa_ffnotify.h"
dsinclair5b493092016-09-29 20:20:24 -070025#include "xfa/fxfa/cxfa_eventparam.h"
Dan Sinclairefcae5d2017-03-29 14:47:46 -040026#include "xfa/fxfa/cxfa_ffwidget.h"
27#include "xfa/fxfa/parser/cxfa_arraynodelist.h"
28#include "xfa/fxfa/parser/cxfa_attachnodelist.h"
dsinclair16280242016-07-21 12:03:47 -070029#include "xfa/fxfa/parser/cxfa_document.h"
dsinclair0b851ff2016-07-21 12:03:01 -070030#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
dsinclair9eb0db12016-07-21 12:01:39 -070031#include "xfa/fxfa/parser/cxfa_measurement.h"
dsinclair44d054c2016-04-06 10:23:46 -070032#include "xfa/fxfa/parser/cxfa_occur.h"
dsinclair31f87402016-07-20 06:34:45 -070033#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
dsinclair34f86b02016-07-11 08:42:33 -070034#include "xfa/fxfa/parser/cxfa_simple_parser.h"
Dan Sinclairefcae5d2017-03-29 14:47:46 -040035#include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h"
dsinclair5b36f0a2016-07-19 10:56:23 -070036#include "xfa/fxfa/parser/xfa_basic_data.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040037
weili44f8faf2016-06-01 14:03:56 -070038namespace {
39
40void XFA_DeleteWideString(void* pData) {
41 delete static_cast<CFX_WideString*>(pData);
42}
43
44void XFA_CopyWideString(void*& pData) {
45 if (pData) {
46 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
47 pData = pNewData;
48 }
49}
50
51XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
52 XFA_CopyWideString};
53
weili44f8faf2016-06-01 14:03:56 -070054void XFA_DataNodeDeleteBindItem(void* pData) {
Tom Sepezf8a94392017-03-14 12:13:22 -070055 delete static_cast<std::vector<CXFA_Node*>*>(pData);
weili44f8faf2016-06-01 14:03:56 -070056}
57
58XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
59 XFA_DataNodeDeleteBindItem, nullptr};
60
dsinclair5b36f0a2016-07-19 10:56:23 -070061int32_t GetCount(CXFA_Node* pInstMgrNode) {
62 ASSERT(pInstMgrNode);
63 int32_t iCount = 0;
64 uint32_t dwNameHash = 0;
65 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
66 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
67 XFA_Element eCurType = pNode->GetElementType();
68 if (eCurType == XFA_Element::InstanceManager)
69 break;
70 if ((eCurType != XFA_Element::Subform) &&
71 (eCurType != XFA_Element::SubformSet)) {
72 continue;
73 }
74 if (iCount == 0) {
75 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
76 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
77 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
78 wsInstName.Mid(1) != wsName) {
79 return iCount;
80 }
81 dwNameHash = pNode->GetNameHash();
82 }
83 if (dwNameHash != pNode->GetNameHash())
84 break;
weili44f8faf2016-06-01 14:03:56 -070085
dsinclair5b36f0a2016-07-19 10:56:23 -070086 iCount++;
87 }
88 return iCount;
Dan Sinclair1770c022016-03-14 14:14:16 -040089}
weili44f8faf2016-06-01 14:03:56 -070090
Tom Sepez7cdc6602017-03-28 09:56:48 -070091std::vector<CXFA_Node*> NodesSortedByDocumentIdx(
92 const std::unordered_set<CXFA_Node*>& rgNodeSet) {
93 if (rgNodeSet.empty())
94 return std::vector<CXFA_Node*>();
weili44f8faf2016-06-01 14:03:56 -070095
Tom Sepez7cdc6602017-03-28 09:56:48 -070096 std::vector<CXFA_Node*> rgNodeArray;
dsinclair5b36f0a2016-07-19 10:56:23 -070097 CXFA_Node* pCommonParent =
98 (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent);
99 for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild);
Tom Sepez7cdc6602017-03-28 09:56:48 -0700100 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
101 if (pdfium::ContainsValue(rgNodeSet, pNode))
102 rgNodeArray.push_back(pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400103 }
Tom Sepez7cdc6602017-03-28 09:56:48 -0700104 return rgNodeArray;
Dan Sinclair1770c022016-03-14 14:14:16 -0400105}
weili44f8faf2016-06-01 14:03:56 -0700106
Tom Sepezd4db58f2017-03-02 14:57:59 -0800107using CXFA_NodeSetPair =
108 std::pair<std::unordered_set<CXFA_Node*>, std::unordered_set<CXFA_Node*>>;
dsinclair5b36f0a2016-07-19 10:56:23 -0700109using CXFA_NodeSetPairMap =
110 std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>;
111using CXFA_NodeSetPairMapMap =
112 std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>;
113
114CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode,
115 CXFA_NodeSetPairMapMap* pMap) {
116 CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
117 uint32_t dwNameHash = pNode->GetNameHash();
118 if (!pParentNode || !dwNameHash)
119 return nullptr;
120
121 if (!(*pMap)[pParentNode])
tsepeza9caab92016-12-14 05:57:10 -0800122 (*pMap)[pParentNode] = pdfium::MakeUnique<CXFA_NodeSetPairMap>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700123
124 CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get();
125 if (!(*pNodeSetPairMap)[dwNameHash])
tsepeza9caab92016-12-14 05:57:10 -0800126 (*pNodeSetPairMap)[dwNameHash] = pdfium::MakeUnique<CXFA_NodeSetPair>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700127
128 return (*pNodeSetPairMap)[dwNameHash].get();
Dan Sinclair1770c022016-03-14 14:14:16 -0400129}
130
Tom Sepezd4db58f2017-03-02 14:57:59 -0800131void ReorderDataNodes(const std::unordered_set<CXFA_Node*>& sSet1,
132 const std::unordered_set<CXFA_Node*>& sSet2,
tsepezd19e9122016-11-02 15:43:18 -0700133 bool bInsertBefore) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700134 CXFA_NodeSetPairMapMap rgMap;
135 for (CXFA_Node* pNode : sSet1) {
136 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
137 if (pNodeSetPair)
138 pNodeSetPair->first.insert(pNode);
139 }
140 for (CXFA_Node* pNode : sSet2) {
141 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
142 if (pNodeSetPair) {
143 if (pdfium::ContainsValue(pNodeSetPair->first, pNode))
144 pNodeSetPair->first.erase(pNode);
145 else
146 pNodeSetPair->second.insert(pNode);
147 }
148 }
149 for (const auto& iter1 : rgMap) {
150 CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get();
151 if (!pNodeSetPairMap)
152 continue;
153
154 for (const auto& iter2 : *pNodeSetPairMap) {
155 CXFA_NodeSetPair* pNodeSetPair = iter2.second.get();
156 if (!pNodeSetPair)
157 continue;
158 if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) {
Tom Sepez7cdc6602017-03-28 09:56:48 -0700159 std::vector<CXFA_Node*> rgNodeArray1 =
160 NodesSortedByDocumentIdx(pNodeSetPair->first);
161 std::vector<CXFA_Node*> rgNodeArray2 =
162 NodesSortedByDocumentIdx(pNodeSetPair->second);
dsinclair5b36f0a2016-07-19 10:56:23 -0700163 CXFA_Node* pParentNode = nullptr;
164 CXFA_Node* pBeforeNode = nullptr;
165 if (bInsertBefore) {
Tom Sepez7cdc6602017-03-28 09:56:48 -0700166 pBeforeNode = rgNodeArray2.front();
dsinclair5b36f0a2016-07-19 10:56:23 -0700167 pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent);
168 } else {
Tom Sepez7cdc6602017-03-28 09:56:48 -0700169 CXFA_Node* pLastNode = rgNodeArray2.back();
dsinclair5b36f0a2016-07-19 10:56:23 -0700170 pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent);
171 pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling);
172 }
Tom Sepez7cdc6602017-03-28 09:56:48 -0700173 for (auto* pCurNode : rgNodeArray1) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700174 pParentNode->RemoveChild(pCurNode);
175 pParentNode->InsertChild(pCurNode, pBeforeNode);
176 }
177 }
178 }
179 pNodeSetPairMap->clear();
180 }
181}
182
183CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
184 ASSERT(pInstMgrNode);
185 int32_t iCount = 0;
186 uint32_t dwNameHash = 0;
187 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
188 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
189 XFA_Element eCurType = pNode->GetElementType();
190 if (eCurType == XFA_Element::InstanceManager)
191 break;
192 if ((eCurType != XFA_Element::Subform) &&
193 (eCurType != XFA_Element::SubformSet)) {
194 continue;
195 }
196 if (iCount == 0) {
197 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
198 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
199 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
200 wsInstName.Mid(1) != wsName) {
201 return nullptr;
202 }
203 dwNameHash = pNode->GetNameHash();
204 }
205 if (dwNameHash != pNode->GetNameHash())
206 break;
207
208 iCount++;
209 if (iCount > iIndex)
210 return pNode;
211 }
212 return nullptr;
213}
214
215void InsertItem(CXFA_Node* pInstMgrNode,
216 CXFA_Node* pNewInstance,
217 int32_t iPos,
218 int32_t iCount = -1,
tsepezd19e9122016-11-02 15:43:18 -0700219 bool bMoveDataBindingNodes = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700220 if (iCount < 0)
221 iCount = GetCount(pInstMgrNode);
222 if (iPos < 0)
223 iPos = iCount;
224 if (iPos == iCount) {
225 CXFA_Node* pNextSibling =
226 iCount > 0
227 ? GetItem(pInstMgrNode, iCount - 1)
228 ->GetNodeItem(XFA_NODEITEM_NextSibling)
229 : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
230 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
231 ->InsertChild(pNewInstance, pNextSibling);
232 if (bMoveDataBindingNodes) {
Tom Sepezd4db58f2017-03-02 14:57:59 -0800233 std::unordered_set<CXFA_Node*> sNew;
234 std::unordered_set<CXFA_Node*> sAfter;
dsinclair5b36f0a2016-07-19 10:56:23 -0700235 CXFA_NodeIteratorTemplate<CXFA_Node,
236 CXFA_TraverseStrategy_XFAContainerNode>
237 sIteratorNew(pNewInstance);
238 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
239 pNode = sIteratorNew.MoveToNext()) {
240 CXFA_Node* pDataNode = pNode->GetBindData();
241 if (!pDataNode)
242 continue;
243
244 sNew.insert(pDataNode);
245 }
246 CXFA_NodeIteratorTemplate<CXFA_Node,
247 CXFA_TraverseStrategy_XFAContainerNode>
248 sIteratorAfter(pNextSibling);
249 for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode;
250 pNode = sIteratorAfter.MoveToNext()) {
251 CXFA_Node* pDataNode = pNode->GetBindData();
252 if (!pDataNode)
253 continue;
254
255 sAfter.insert(pDataNode);
256 }
tsepezd19e9122016-11-02 15:43:18 -0700257 ReorderDataNodes(sNew, sAfter, false);
dsinclair5b36f0a2016-07-19 10:56:23 -0700258 }
259 } else {
260 CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos);
261 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
262 ->InsertChild(pNewInstance, pBeforeInstance);
263 if (bMoveDataBindingNodes) {
Tom Sepezd4db58f2017-03-02 14:57:59 -0800264 std::unordered_set<CXFA_Node*> sNew;
265 std::unordered_set<CXFA_Node*> sBefore;
dsinclair5b36f0a2016-07-19 10:56:23 -0700266 CXFA_NodeIteratorTemplate<CXFA_Node,
267 CXFA_TraverseStrategy_XFAContainerNode>
268 sIteratorNew(pNewInstance);
269 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
270 pNode = sIteratorNew.MoveToNext()) {
271 CXFA_Node* pDataNode = pNode->GetBindData();
272 if (!pDataNode)
273 continue;
274
275 sNew.insert(pDataNode);
276 }
277 CXFA_NodeIteratorTemplate<CXFA_Node,
278 CXFA_TraverseStrategy_XFAContainerNode>
279 sIteratorBefore(pBeforeInstance);
280 for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode;
281 pNode = sIteratorBefore.MoveToNext()) {
282 CXFA_Node* pDataNode = pNode->GetBindData();
283 if (!pDataNode)
284 continue;
285
286 sBefore.insert(pDataNode);
287 }
tsepezd19e9122016-11-02 15:43:18 -0700288 ReorderDataNodes(sNew, sBefore, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700289 }
290 }
291}
292
293void RemoveItem(CXFA_Node* pInstMgrNode,
294 CXFA_Node* pRemoveInstance,
tsepezd19e9122016-11-02 15:43:18 -0700295 bool bRemoveDataBinding = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700296 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);
297 if (!bRemoveDataBinding)
298 return;
299
300 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode>
301 sIterator(pRemoveInstance);
302 for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode;
303 pFormNode = sIterator.MoveToNext()) {
304 CXFA_Node* pDataNode = pFormNode->GetBindData();
305 if (!pDataNode)
306 continue;
307
308 if (pDataNode->RemoveBindItem(pFormNode) == 0) {
309 if (CXFA_Node* pDataParent =
310 pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) {
311 pDataParent->RemoveChild(pDataNode);
312 }
313 }
314 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
315 }
316}
317
tsepezd19e9122016-11-02 15:43:18 -0700318CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700319 CXFA_Document* pDocument = pInstMgrNode->GetDocument();
320 CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();
321 CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);
322 CXFA_Node* pDataScope = nullptr;
323 for (CXFA_Node* pRootBoundNode = pFormParent;
324 pRootBoundNode && pRootBoundNode->IsContainerNode();
325 pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) {
326 pDataScope = pRootBoundNode->GetBindData();
327 if (pDataScope)
328 break;
329 }
330 if (!pDataScope) {
331 pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record));
332 ASSERT(pDataScope);
333 }
334 CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer(
tsepezd19e9122016-11-02 15:43:18 -0700335 pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700336 if (pInstance) {
337 pDocument->DataMerge_UpdateBindingRelations(pInstance);
338 pFormParent->RemoveChild(pInstance);
339 }
340 return pInstance;
341}
342
343struct XFA_ExecEventParaInfo {
344 public:
345 uint32_t m_uHash;
Dan Sinclair812e96c2017-03-13 16:43:37 -0400346 const wchar_t* m_lpcEventName;
dsinclair5b36f0a2016-07-19 10:56:23 -0700347 XFA_EVENTTYPE m_eventType;
348 uint32_t m_validFlags;
349};
350static const XFA_ExecEventParaInfo gs_eventParaInfos[] = {
351 {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0},
352 {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0},
353 {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5},
354 {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0},
355 {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7},
356 {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1},
357 {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5},
358 {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0},
359 {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0},
360 {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6},
361 {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2},
362 {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0},
363 {0x7233018a, L"validate", XFA_EVENT_Validate, 1},
364 {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3},
365 {0x891f4606, L"change", XFA_EVENT_Change, 4},
366 {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0},
367 {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5},
368 {0xcdce56b3, L"full", XFA_EVENT_Full, 4},
369 {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5},
370 {0xd95657a6, L"click", XFA_EVENT_Click, 4},
371 {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1},
372 {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7},
373 {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2},
374 {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0},
375 {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6},
376};
377
378const XFA_ExecEventParaInfo* GetEventParaInfoByName(
379 const CFX_WideStringC& wsEventName) {
380 uint32_t uHash = FX_HashCode_GetW(wsEventName, false);
381 int32_t iStart = 0;
382 int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
383 do {
384 int32_t iMid = (iStart + iEnd) / 2;
385 const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid];
386 if (uHash == eventParaInfo->m_uHash)
387 return eventParaInfo;
388 if (uHash < eventParaInfo->m_uHash)
389 iEnd = iMid - 1;
390 else
391 iStart = iMid + 1;
392 } while (iStart <= iEnd);
393 return nullptr;
394}
395
396void StrToRGB(const CFX_WideString& strRGB,
397 int32_t& r,
398 int32_t& g,
399 int32_t& b) {
400 r = 0;
401 g = 0;
402 b = 0;
403
Dan Sinclair812e96c2017-03-13 16:43:37 -0400404 wchar_t zero = '0';
dsinclair5b36f0a2016-07-19 10:56:23 -0700405 int32_t iIndex = 0;
406 int32_t iLen = strRGB.GetLength();
407 for (int32_t i = 0; i < iLen; ++i) {
Dan Sinclair812e96c2017-03-13 16:43:37 -0400408 wchar_t ch = strRGB.GetAt(i);
dsinclair5b36f0a2016-07-19 10:56:23 -0700409 if (ch == L',')
410 ++iIndex;
411 if (iIndex > 2)
412 break;
413
414 int32_t iValue = ch - zero;
415 if (iValue >= 0 && iValue <= 9) {
416 switch (iIndex) {
417 case 0:
418 r = r * 10 + iValue;
419 break;
420 case 1:
421 g = g * 10 + iValue;
422 break;
423 default:
424 b = b * 10 + iValue;
425 break;
426 }
427 }
428 }
429}
430
431enum XFA_KEYTYPE {
432 XFA_KEYTYPE_Custom,
433 XFA_KEYTYPE_Element,
434};
435
436void* GetMapKey_Custom(const CFX_WideStringC& wsKey) {
437 uint32_t dwKey = FX_HashCode_GetW(wsKey, false);
438 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom);
439}
440
441void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) {
442 return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) |
443 (eAttribute << 8) | XFA_KEYTYPE_Element);
444}
445
dsinclair9eb0db12016-07-21 12:01:39 -0700446const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement,
447 XFA_ATTRIBUTE eAttribute,
448 uint32_t dwPacket) {
449 int32_t iCount = 0;
450 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount);
451 if (!pAttr || iCount < 1)
452 return nullptr;
453
454 if (!std::binary_search(pAttr, pAttr + iCount, eAttribute))
455 return nullptr;
456
457 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute);
458 ASSERT(pInfo);
459 if (dwPacket == XFA_XDPPACKET_UNKNOWN)
460 return pInfo;
461 return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr;
462}
463
464const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) {
465 return g_XFAEnumData + eName;
466}
467
dsinclair5b36f0a2016-07-19 10:56:23 -0700468} // namespace
469
470static void XFA_DefaultFreeData(void* pData) {}
471
472static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {
473 XFA_DefaultFreeData, nullptr};
474
weili47bcd4c2016-06-16 08:00:06 -0700475XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {}
476
477XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {}
478
dsinclairb9778472016-06-23 13:34:10 -0700479CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
480 uint16_t ePacket,
481 XFA_ObjectType oType,
dsinclairc1df5d42016-07-18 06:36:51 -0700482 XFA_Element eType,
483 const CFX_WideStringC& elementName)
484 : CXFA_Object(pDoc, oType, eType, elementName),
Dan Sinclair1770c022016-03-14 14:14:16 -0400485 m_pNext(nullptr),
486 m_pChild(nullptr),
487 m_pLastChild(nullptr),
488 m_pParent(nullptr),
489 m_pXMLNode(nullptr),
Dan Sinclair1770c022016-03-14 14:14:16 -0400490 m_ePacket(ePacket),
dsinclairc5a8f212016-06-20 11:11:12 -0700491 m_uNodeFlags(XFA_NodeFlag_None),
Dan Sinclair1770c022016-03-14 14:14:16 -0400492 m_dwNameHash(0),
493 m_pAuxNode(nullptr),
494 m_pMapModuleData(nullptr) {
495 ASSERT(m_pDocument);
496}
weili44f8faf2016-06-01 14:03:56 -0700497
Dan Sinclair1770c022016-03-14 14:14:16 -0400498CXFA_Node::~CXFA_Node() {
weili44f8faf2016-06-01 14:03:56 -0700499 ASSERT(!m_pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400500 RemoveMapModuleKey();
weili44f8faf2016-06-01 14:03:56 -0700501 CXFA_Node* pNode = m_pChild;
Dan Sinclair1770c022016-03-14 14:14:16 -0400502 while (pNode) {
weili44f8faf2016-06-01 14:03:56 -0700503 CXFA_Node* pNext = pNode->m_pNext;
504 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400505 delete pNode;
506 pNode = pNext;
507 }
dsinclairc5a8f212016-06-20 11:11:12 -0700508 if (m_pXMLNode && IsOwnXMLNode())
tsepezc757d9a2017-01-23 11:01:42 -0800509 delete m_pXMLNode;
Dan Sinclair1770c022016-03-14 14:14:16 -0400510}
weili44f8faf2016-06-01 14:03:56 -0700511
tsepezd19e9122016-11-02 15:43:18 -0700512CXFA_Node* CXFA_Node::Clone(bool bRecursive) {
dsinclaira1b07722016-07-11 08:20:58 -0700513 CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700514 if (!pClone)
515 return nullptr;
516
Dan Sinclair1770c022016-03-14 14:14:16 -0400517 MergeAllData(pClone);
518 pClone->UpdateNameHash();
519 if (IsNeedSavingXMLNode()) {
Dan Sinclair93bfc262017-04-04 15:10:00 -0400520 std::unique_ptr<CFDE_XMLNode> pCloneXML;
Dan Sinclair1770c022016-03-14 14:14:16 -0400521 if (IsAttributeInXML()) {
522 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -0700523 GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
Dan Sinclair93bfc262017-04-04 15:10:00 -0400524 auto pCloneXMLElement = pdfium::MakeUnique<CFDE_XMLElement>(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -0400525 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
526 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -0700527 pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -0400528 }
Dan Sinclair93bfc262017-04-04 15:10:00 -0400529 pCloneXML.reset(pCloneXMLElement.release());
Dan Sinclair1770c022016-03-14 14:14:16 -0400530 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
531 } else {
Dan Sinclair93bfc262017-04-04 15:10:00 -0400532 pCloneXML = m_pXMLNode->Clone();
Dan Sinclair1770c022016-03-14 14:14:16 -0400533 }
Dan Sinclair93bfc262017-04-04 15:10:00 -0400534 pClone->SetXMLMappingNode(pCloneXML.release());
dsinclairc5a8f212016-06-20 11:11:12 -0700535 pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400536 }
537 if (bRecursive) {
538 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
539 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
540 pClone->InsertChild(pChild->Clone(bRecursive));
541 }
542 }
dsinclairc5a8f212016-06-20 11:11:12 -0700543 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
weili44f8faf2016-06-01 14:03:56 -0700544 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400545 return pClone;
546}
weili44f8faf2016-06-01 14:03:56 -0700547
Dan Sinclair1770c022016-03-14 14:14:16 -0400548CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
549 switch (eItem) {
550 case XFA_NODEITEM_NextSibling:
551 return m_pNext;
552 case XFA_NODEITEM_FirstChild:
553 return m_pChild;
554 case XFA_NODEITEM_Parent:
555 return m_pParent;
556 case XFA_NODEITEM_PrevSibling:
557 if (m_pParent) {
558 CXFA_Node* pSibling = m_pParent->m_pChild;
weili44f8faf2016-06-01 14:03:56 -0700559 CXFA_Node* pPrev = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400560 while (pSibling && pSibling != this) {
561 pPrev = pSibling;
562 pSibling = pSibling->m_pNext;
563 }
564 return pPrev;
565 }
weili44f8faf2016-06-01 14:03:56 -0700566 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400567 default:
568 break;
569 }
weili44f8faf2016-06-01 14:03:56 -0700570 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400571}
weili44f8faf2016-06-01 14:03:56 -0700572
Dan Sinclair1770c022016-03-14 14:14:16 -0400573CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
dsinclairc5a8f212016-06-20 11:11:12 -0700574 XFA_ObjectType eType) const {
weili44f8faf2016-06-01 14:03:56 -0700575 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400576 switch (eItem) {
577 case XFA_NODEITEM_NextSibling:
578 pNode = m_pNext;
dsinclairc5a8f212016-06-20 11:11:12 -0700579 while (pNode && pNode->GetObjectType() != eType)
580 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400581 break;
582 case XFA_NODEITEM_FirstChild:
583 pNode = m_pChild;
dsinclairc5a8f212016-06-20 11:11:12 -0700584 while (pNode && pNode->GetObjectType() != eType)
585 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400586 break;
587 case XFA_NODEITEM_Parent:
588 pNode = m_pParent;
dsinclairc5a8f212016-06-20 11:11:12 -0700589 while (pNode && pNode->GetObjectType() != eType)
590 pNode = pNode->m_pParent;
Dan Sinclair1770c022016-03-14 14:14:16 -0400591 break;
592 case XFA_NODEITEM_PrevSibling:
593 if (m_pParent) {
594 CXFA_Node* pSibling = m_pParent->m_pChild;
595 while (pSibling && pSibling != this) {
dsinclairc5a8f212016-06-20 11:11:12 -0700596 if (eType == pSibling->GetObjectType())
Dan Sinclair1770c022016-03-14 14:14:16 -0400597 pNode = pSibling;
dsinclairc5a8f212016-06-20 11:11:12 -0700598
Dan Sinclair1770c022016-03-14 14:14:16 -0400599 pSibling = pSibling->m_pNext;
600 }
601 }
602 break;
603 default:
604 break;
605 }
606 return pNode;
607}
weili44f8faf2016-06-01 14:03:56 -0700608
Tom Sepezf8a94392017-03-14 12:13:22 -0700609std::vector<CXFA_Node*> CXFA_Node::GetNodeList(uint32_t dwTypeFilter,
610 XFA_Element eTypeFilter) {
611 std::vector<CXFA_Node*> nodes;
dsinclair41cb62e2016-06-23 09:20:32 -0700612 if (eTypeFilter != XFA_Element::Unknown) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700613 for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext) {
614 if (pChild->GetElementType() == eTypeFilter)
615 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400616 }
617 } else if (dwTypeFilter ==
618 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700619 for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext)
620 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400621 } else if (dwTypeFilter != 0) {
weili44f8faf2016-06-01 14:03:56 -0700622 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
623 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
624 bool bFilterOneOfProperties =
625 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
Dan Sinclair1770c022016-03-14 14:14:16 -0400626 CXFA_Node* pChild = m_pChild;
627 while (pChild) {
628 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -0700629 GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -0400630 if (pProperty) {
631 if (bFilterProperties) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700632 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400633 } else if (bFilterOneOfProperties &&
634 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700635 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400636 } else if (bFilterChildren &&
dsinclair070fcdf2016-06-22 22:04:54 -0700637 (pChild->GetElementType() == XFA_Element::Variables ||
638 pChild->GetElementType() == XFA_Element::PageSet)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700639 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400640 }
weili44f8faf2016-06-01 14:03:56 -0700641 } else if (bFilterChildren) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700642 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400643 }
644 pChild = pChild->m_pNext;
645 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700646 if (bFilterOneOfProperties && nodes.empty()) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400647 int32_t iProperties = 0;
648 const XFA_PROPERTY* pProperty =
dsinclair070fcdf2016-06-22 22:04:54 -0700649 XFA_GetElementProperties(GetElementType(), iProperties);
weili44f8faf2016-06-01 14:03:56 -0700650 if (!pProperty || iProperties < 1)
Tom Sepezf8a94392017-03-14 12:13:22 -0700651 return nodes;
Dan Sinclair1770c022016-03-14 14:14:16 -0400652 for (int32_t i = 0; i < iProperties; i++) {
653 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400654 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
655 CXFA_Node* pNewNode =
dsinclaira1b07722016-07-11 08:20:58 -0700656 m_pDocument->CreateNode(pPacket, pProperty[i].eName);
weili44f8faf2016-06-01 14:03:56 -0700657 if (!pNewNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400658 break;
weili44f8faf2016-06-01 14:03:56 -0700659 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -0700660 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Tom Sepezf8a94392017-03-14 12:13:22 -0700661 nodes.push_back(pNewNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400662 break;
663 }
664 }
665 }
666 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700667 return nodes;
Dan Sinclair1770c022016-03-14 14:14:16 -0400668}
weili44f8faf2016-06-01 14:03:56 -0700669
dsinclair41cb62e2016-06-23 09:20:32 -0700670CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
tsepez736f28a2016-03-25 14:19:51 -0700671 uint32_t dwFlags) {
dsinclaira1b07722016-07-11 08:20:58 -0700672 CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
thestigb1a59592016-04-14 18:29:56 -0700673 pNode->SetFlag(dwFlags, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400674 return pNode;
675}
weili44f8faf2016-06-01 14:03:56 -0700676
tsepezd19e9122016-11-02 15:43:18 -0700677CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) {
dsinclair43854a52016-04-27 12:26:00 -0700678 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
dsinclaira1b07722016-07-11 08:20:58 -0700679 CXFA_Node* pClone =
680 m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700681 if (!pClone)
682 return nullptr;
683
Dan Sinclair1770c022016-03-14 14:14:16 -0400684 pClone->SetTemplateNode(this);
685 pClone->UpdateNameHash();
686 pClone->SetXMLMappingNode(GetXMLMappingNode());
687 if (bRecursive) {
688 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
689 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
690 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
691 }
692 }
dsinclairc5a8f212016-06-20 11:11:12 -0700693 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400694 return pClone;
695}
696
697CXFA_Node* CXFA_Node::GetTemplateNode() const {
698 return m_pAuxNode;
699}
700
701void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
702 m_pAuxNode = pTemplateNode;
703}
weili44f8faf2016-06-01 14:03:56 -0700704
Dan Sinclair1770c022016-03-14 14:14:16 -0400705CXFA_Node* CXFA_Node::GetBindData() {
706 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
707 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
708}
weili44f8faf2016-06-01 14:03:56 -0700709
Tom Sepezf8a94392017-03-14 12:13:22 -0700710std::vector<CXFA_Node*> CXFA_Node::GetBindItems() {
dsinclairc5a8f212016-06-20 11:11:12 -0700711 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700712 void* pBinding = nullptr;
713 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
714 return *static_cast<std::vector<CXFA_Node*>*>(pBinding);
Dan Sinclair1770c022016-03-14 14:14:16 -0400715 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700716 std::vector<CXFA_Node*> result;
Dan Sinclair1770c022016-03-14 14:14:16 -0400717 CXFA_Node* pFormNode =
718 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
weili44f8faf2016-06-01 14:03:56 -0700719 if (pFormNode)
Tom Sepezf8a94392017-03-14 12:13:22 -0700720 result.push_back(pFormNode);
721 return result;
Dan Sinclair1770c022016-03-14 14:14:16 -0400722}
723
Dan Sinclair1770c022016-03-14 14:14:16 -0400724int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
725 ASSERT(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700726 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700727 void* pBinding = nullptr;
728 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
729 auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding);
730 if (!pdfium::ContainsValue(*pItems, pFormNode))
731 pItems->push_back(pFormNode);
732 return pdfium::CollectionSize<int32_t>(*pItems);
Dan Sinclair1770c022016-03-14 14:14:16 -0400733 }
734 CXFA_Node* pOldFormItem =
735 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
736 if (!pOldFormItem) {
737 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
738 return 1;
Dan Sinclair1770c022016-03-14 14:14:16 -0400739 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700740 if (pOldFormItem == pFormNode)
741 return 1;
742
743 std::vector<CXFA_Node*>* pItems = new std::vector<CXFA_Node*>;
Dan Sinclair1770c022016-03-14 14:14:16 -0400744 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
Tom Sepezf8a94392017-03-14 12:13:22 -0700745 pItems->push_back(pOldFormItem);
746 pItems->push_back(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700747 m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400748 return 2;
749}
weili44f8faf2016-06-01 14:03:56 -0700750
Dan Sinclair1770c022016-03-14 14:14:16 -0400751int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
dsinclairc5a8f212016-06-20 11:11:12 -0700752 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700753 void* pBinding = nullptr;
754 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
755 auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding);
756 auto iter = std::find(pItems->begin(), pItems->end(), pFormNode);
757 if (iter != pItems->end()) {
758 *iter = pItems->back();
759 pItems->pop_back();
760 if (pItems->size() == 1) {
761 SetObject(XFA_ATTRIBUTE_BindingNode,
762 (*pItems)[0]); // Invalidates pItems.
dsinclairc5a8f212016-06-20 11:11:12 -0700763 m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
Tom Sepezf8a94392017-03-14 12:13:22 -0700764 return 1;
Dan Sinclair1770c022016-03-14 14:14:16 -0400765 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400766 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700767 return pdfium::CollectionSize<int32_t>(*pItems);
Dan Sinclair1770c022016-03-14 14:14:16 -0400768 }
769 CXFA_Node* pOldFormItem =
770 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
Tom Sepezf8a94392017-03-14 12:13:22 -0700771 if (pOldFormItem != pFormNode)
772 return pOldFormItem ? 1 : 0;
773
774 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
775 return 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400776}
weili44f8faf2016-06-01 14:03:56 -0700777
tsepezd19e9122016-11-02 15:43:18 -0700778bool CXFA_Node::HasBindItem() {
weili44f8faf2016-06-01 14:03:56 -0700779 return GetPacketID() == XFA_XDPPACKET_Datasets &&
780 GetObject(XFA_ATTRIBUTE_BindingNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400781}
weili44f8faf2016-06-01 14:03:56 -0700782
Dan Sinclair1770c022016-03-14 14:14:16 -0400783CXFA_WidgetData* CXFA_Node::GetWidgetData() {
784 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
785}
weili44f8faf2016-06-01 14:03:56 -0700786
Dan Sinclair1770c022016-03-14 14:14:16 -0400787CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
weili44f8faf2016-06-01 14:03:56 -0700788 if (GetPacketID() != XFA_XDPPACKET_Form)
789 return nullptr;
dsinclair41cb62e2016-06-23 09:20:32 -0700790 XFA_Element eType = GetElementType();
791 if (eType == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700792 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400793 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700794 if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700795 return nullptr;
796
dsinclair41cb62e2016-06-23 09:20:32 -0700797 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400798 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
799 if (pFieldWidgetData &&
800 pFieldWidgetData->GetChoiceListOpen() ==
801 XFA_ATTRIBUTEENUM_MultiSelect) {
weili44f8faf2016-06-01 14:03:56 -0700802 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400803 } else {
804 CFX_WideString wsPicture;
805 if (pFieldWidgetData) {
806 pFieldWidgetData->GetPictureContent(wsPicture,
807 XFA_VALUEPICTURE_DataBind);
808 }
weili44f8faf2016-06-01 14:03:56 -0700809 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400810 return pFieldWidgetData;
Dan Sinclair1770c022016-03-14 14:14:16 -0400811 CXFA_Node* pDataNode = GetBindData();
weili44f8faf2016-06-01 14:03:56 -0700812 if (!pDataNode)
813 return nullptr;
814 pFieldWidgetData = nullptr;
Tom Sepezf8a94392017-03-14 12:13:22 -0700815 for (CXFA_Node* pFormNode : pDataNode->GetBindItems()) {
dsinclairc5a8f212016-06-20 11:11:12 -0700816 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -0400817 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400818 pFieldWidgetData = pFormNode->GetWidgetData();
819 if (pFieldWidgetData) {
820 pFieldWidgetData->GetPictureContent(wsPicture,
821 XFA_VALUEPICTURE_DataBind);
822 }
weili44f8faf2016-06-01 14:03:56 -0700823 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400824 break;
weili44f8faf2016-06-01 14:03:56 -0700825 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400826 }
827 return pFieldWidgetData;
828 }
829 }
830 CXFA_Node* pGrandNode =
weili44f8faf2016-06-01 14:03:56 -0700831 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400832 CXFA_Node* pValueNode =
dsinclair070fcdf2016-06-22 22:04:54 -0700833 (pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
Dan Sinclair1770c022016-03-14 14:14:16 -0400834 ? pParentNode
weili44f8faf2016-06-01 14:03:56 -0700835 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400836 if (!pValueNode) {
dsinclair070fcdf2016-06-22 22:04:54 -0700837 pValueNode =
838 (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
839 ? pGrandNode
840 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400841 }
842 CXFA_Node* pParentOfValueNode =
weili44f8faf2016-06-01 14:03:56 -0700843 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400844 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
weili44f8faf2016-06-01 14:03:56 -0700845 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400846}
weili44f8faf2016-06-01 14:03:56 -0700847
tsepezd19e9122016-11-02 15:43:18 -0700848bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400849 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
dsinclair56a8b192016-06-21 14:15:25 -0700850 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
dsinclair43854a52016-04-27 12:26:00 -0700851 ASSERT(pTopSubform);
Dan Sinclair1770c022016-03-14 14:14:16 -0400852 CXFA_Node* pLocaleNode = this;
tsepezd19e9122016-11-02 15:43:18 -0700853 bool bLocale = false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400854 do {
tsepezd19e9122016-11-02 15:43:18 -0700855 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400856 if (!bLocale) {
857 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
858 }
859 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
weili44f8faf2016-06-01 14:03:56 -0700860 if (bLocale)
tsepezd19e9122016-11-02 15:43:18 -0700861 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400862 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
863 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
weili44f8faf2016-06-01 14:03:56 -0700864 if (!wsLocaleName.IsEmpty())
tsepezd19e9122016-11-02 15:43:18 -0700865 return true;
weili44f8faf2016-06-01 14:03:56 -0700866 if (pTopSubform &&
tsepezd19e9122016-11-02 15:43:18 -0700867 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) {
868 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400869 }
870 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
871 if (pLocale) {
872 wsLocaleName = pLocale->GetName();
tsepezd19e9122016-11-02 15:43:18 -0700873 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400874 }
tsepezd19e9122016-11-02 15:43:18 -0700875 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400876}
weili44f8faf2016-06-01 14:03:56 -0700877
Dan Sinclair1770c022016-03-14 14:14:16 -0400878XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
dsinclair56a8b192016-06-21 14:15:25 -0700879 CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
Dan Sinclair1770c022016-03-14 14:14:16 -0400880 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
881 if (pKeep) {
882 XFA_ATTRIBUTEENUM eIntact;
tsepezd19e9122016-11-02 15:43:18 -0700883 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400884 if (eIntact == XFA_ATTRIBUTEENUM_None &&
885 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
886 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
dsinclairc5a8f212016-06-20 11:11:12 -0700887 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
888 XFA_ObjectType::ContainerNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400889 if (pPreviewRow &&
890 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
891 XFA_ATTRIBUTEENUM_Row) {
892 XFA_ATTRIBUTEENUM eValue;
tsepezd19e9122016-11-02 15:43:18 -0700893 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700894 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
895 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
896 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400897 }
weili44f8faf2016-06-01 14:03:56 -0700898 CXFA_Node* pNode =
dsinclair56a8b192016-06-21 14:15:25 -0700899 pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
tsepezd19e9122016-11-02 15:43:18 -0700900 if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700901 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
902 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
903 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400904 }
905 }
906 }
907 return eIntact;
908 }
909 }
dsinclair41cb62e2016-06-23 09:20:32 -0700910 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700911 case XFA_Element::Subform:
Dan Sinclair1770c022016-03-14 14:14:16 -0400912 switch (eLayoutType) {
913 case XFA_ATTRIBUTEENUM_Position:
914 case XFA_ATTRIBUTEENUM_Row:
915 return XFA_ATTRIBUTEENUM_ContentArea;
916 case XFA_ATTRIBUTEENUM_Tb:
917 case XFA_ATTRIBUTEENUM_Table:
918 case XFA_ATTRIBUTEENUM_Lr_tb:
919 case XFA_ATTRIBUTEENUM_Rl_tb:
920 return XFA_ATTRIBUTEENUM_None;
921 default:
922 break;
923 }
924 break;
dsinclair56a8b192016-06-21 14:15:25 -0700925 case XFA_Element::Field: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400926 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700927 if (!pParentNode ||
928 pParentNode->GetElementType() == XFA_Element::PageArea)
Dan Sinclair1770c022016-03-14 14:14:16 -0400929 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400930 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
931 XFA_ATTRIBUTEENUM eParLayout =
932 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
933 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
934 eParLayout == XFA_ATTRIBUTEENUM_Row ||
935 eParLayout == XFA_ATTRIBUTEENUM_Table) {
936 return XFA_ATTRIBUTEENUM_None;
937 }
938 XFA_VERSION version = m_pDocument->GetCurVersionMode();
939 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
940 CXFA_Measurement measureH;
tsepezd19e9122016-11-02 15:43:18 -0700941 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false))
Dan Sinclair1770c022016-03-14 14:14:16 -0400942 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400943 }
944 return XFA_ATTRIBUTEENUM_None;
945 }
946 return XFA_ATTRIBUTEENUM_ContentArea;
947 }
dsinclair56a8b192016-06-21 14:15:25 -0700948 case XFA_Element::Draw:
Dan Sinclair1770c022016-03-14 14:14:16 -0400949 return XFA_ATTRIBUTEENUM_ContentArea;
950 default:
951 break;
952 }
953 return XFA_ATTRIBUTEENUM_None;
954}
weili44f8faf2016-06-01 14:03:56 -0700955
Dan Sinclair1770c022016-03-14 14:14:16 -0400956CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
weili44f8faf2016-06-01 14:03:56 -0700957 if (m_ePacket == XFA_XDPPACKET_Datasets)
Dan Sinclair1770c022016-03-14 14:14:16 -0400958 return m_pAuxNode;
weili44f8faf2016-06-01 14:03:56 -0700959 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400960}
weili44f8faf2016-06-01 14:03:56 -0700961
Dan Sinclair1770c022016-03-14 14:14:16 -0400962void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
dsinclair43854a52016-04-27 12:26:00 -0700963 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
Dan Sinclair1770c022016-03-14 14:14:16 -0400964 m_pAuxNode = pDataDescriptionNode;
965}
weili44f8faf2016-06-01 14:03:56 -0700966
Dan Sinclair1770c022016-03-14 14:14:16 -0400967void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
968 int32_t iLength = pArguments->GetLength();
969 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -0500970 ThrowParamCountMismatchException(L"resolveNode");
Dan Sinclair1770c022016-03-14 14:14:16 -0400971 return;
972 }
tsepez6fe7d212016-04-06 10:51:14 -0700973 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -0700974 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclairdf4bc592016-03-31 20:34:43 -0700975 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -0700976 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -0400977 return;
Dan Sinclair1770c022016-03-14 14:14:16 -0400978 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -0700979 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -0400980 refNode = ToNode(pScriptContext->GetThisObject());
tsepez736f28a2016-03-25 14:19:51 -0700981 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -0400982 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
983 XFA_RESOLVENODE_Siblings;
984 XFA_RESOLVENODE_RS resoveNodeRS;
tsepezfc58ad12016-04-05 12:22:15 -0700985 int32_t iRet = pScriptContext->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -0700986 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
dsinclairf27aeec2016-06-07 19:36:18 -0700987 if (iRet < 1) {
988 pArguments->GetReturnValue()->SetNull();
989 return;
990 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400991 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700992 CXFA_Object* pObject = resoveNodeRS.objects.front();
dsinclairf27aeec2016-06-07 19:36:18 -0700993 pArguments->GetReturnValue()->Assign(
Tom Sepezf8a94392017-03-14 12:13:22 -0700994 pScriptContext->GetJSValueFromMap(pObject));
Dan Sinclair1770c022016-03-14 14:14:16 -0400995 } else {
996 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
997 resoveNodeRS.pScriptAttribute;
998 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
Dan Sinclairfdf7d402017-04-18 15:25:58 -0400999 auto pValue =
1000 pdfium::MakeUnique<CFXJSE_Value>(pScriptContext->GetRuntime());
Tom Sepezf8a94392017-03-14 12:13:22 -07001001 (resoveNodeRS.objects.front()->*(lpAttributeInfo->lpfnCallback))(
tsepezd19e9122016-11-02 15:43:18 -07001002 pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
dsinclairf27aeec2016-06-07 19:36:18 -07001003 pArguments->GetReturnValue()->Assign(pValue.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001004 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001005 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001006 }
1007 }
1008}
weili44f8faf2016-06-01 14:03:56 -07001009
Dan Sinclair1770c022016-03-14 14:14:16 -04001010void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
1011 int32_t iLength = pArguments->GetLength();
1012 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001013 ThrowParamCountMismatchException(L"resolveNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04001014 return;
1015 }
tsepez6fe7d212016-04-06 10:51:14 -07001016 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001017 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclair12a6b0c2016-05-26 11:14:08 -07001018 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001019 if (!pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04001020 return;
tsepez736f28a2016-03-25 14:19:51 -07001021 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001022 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1023 XFA_RESOLVENODE_Siblings;
1024 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001025 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001026 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
dsinclair12a6b0c2016-05-26 11:14:08 -07001027 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001028}
weili44f8faf2016-06-01 14:03:56 -07001029
dsinclair12a6b0c2016-05-26 11:14:08 -07001030void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001031 CFX_WideString wsExpression,
tsepez736f28a2016-03-25 14:19:51 -07001032 uint32_t dwFlag,
Dan Sinclair1770c022016-03-14 14:14:16 -04001033 CXFA_Node* refNode) {
dsinclairdf4bc592016-03-31 20:34:43 -07001034 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001035 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001036 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001037 XFA_RESOLVENODE_RS resoveNodeRS;
weili44f8faf2016-06-01 14:03:56 -07001038 if (!refNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04001039 refNode = this;
tsepez4c3debb2016-04-08 12:20:38 -07001040 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
tsepezfc58ad12016-04-05 12:22:15 -07001041 resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001042 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
1043 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
Tom Sepezf8a94392017-03-14 12:13:22 -07001044 for (CXFA_Object* pObject : resoveNodeRS.objects) {
1045 if (pObject->IsNode())
1046 pNodeList->Append(pObject->AsNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001047 }
1048 } else {
dsinclair12a6b0c2016-05-26 11:14:08 -07001049 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
Tom Sepez369fe1f2017-03-27 16:03:43 -07001050 if (resoveNodeRS.GetAttributeResult(&valueArray) > 0) {
Tom Sepezf8a94392017-03-14 12:13:22 -07001051 for (CXFA_Object* pObject : valueArray.GetAttributeObject()) {
1052 if (pObject->IsNode())
1053 pNodeList->Append(pObject->AsNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001054 }
1055 }
1056 }
dsinclairf27aeec2016-06-07 19:36:18 -07001057 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001058}
weili44f8faf2016-06-01 14:03:56 -07001059
dsinclair12a6b0c2016-05-26 11:14:08 -07001060void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001061 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001062 XFA_ATTRIBUTE eAttribute) {
1063 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001064 ThrowInvalidPropertyException();
1065 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001066 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001067
1068 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
1069 CFX_WideString wsName;
1070 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
dan sinclair65c7c232017-02-02 14:05:30 -08001071 CFX_WideString wsExpression = wsName + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001072 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001073}
weili44f8faf2016-06-01 14:03:56 -07001074
dsinclair12a6b0c2016-05-26 11:14:08 -07001075void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001076 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001077 XFA_ATTRIBUTE eAttribute) {
dsinclairdf4bc592016-03-31 20:34:43 -07001078 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001079 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001080 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001081 if (bSetting) {
Dan Sinclairc8fd3312017-01-02 17:17:02 -05001082 CFX_WideString wsMessage = L"Unable to set ";
Tom Sepezf0b65542017-02-13 10:26:01 -08001083 FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001084 } else {
1085 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
dsinclairf27aeec2016-06-07 19:36:18 -07001086 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001087 }
1088}
weili44f8faf2016-06-01 14:03:56 -07001089
dsinclair12a6b0c2016-05-26 11:14:08 -07001090void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001091 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001092 XFA_ATTRIBUTE eAttribute) {
1093 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001094 ThrowInvalidPropertyException();
1095 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001096 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001097 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
dan sinclair65c7c232017-02-02 14:05:30 -08001098 CFX_WideString wsExpression = L"#" + GetClassName() + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001099 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001100}
weili44f8faf2016-06-01 14:03:56 -07001101
dsinclair12a6b0c2016-05-26 11:14:08 -07001102void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001103 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001104 XFA_ATTRIBUTE eAttribute) {
1105 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001106 ThrowInvalidPropertyException();
1107 return;
1108 }
1109 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
1110 if (pParent) {
1111 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001112 } else {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001113 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001114 }
1115}
weili44f8faf2016-06-01 14:03:56 -07001116
dsinclair12a6b0c2016-05-26 11:14:08 -07001117void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001118 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001119 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001120 if (bSetting) {
1121 ThrowInvalidPropertyException();
1122 return;
1123 }
1124 pValue->SetInteger(GetNodeSameNameIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001125}
weili44f8faf2016-06-01 14:03:56 -07001126
dsinclair12a6b0c2016-05-26 11:14:08 -07001127void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001128 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001129 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001130 if (bSetting) {
1131 ThrowInvalidPropertyException();
1132 return;
1133 }
1134 pValue->SetInteger(GetNodeSameClassIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001135}
weili44f8faf2016-06-01 14:03:56 -07001136
dsinclair12a6b0c2016-05-26 11:14:08 -07001137void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001138 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001139 XFA_ATTRIBUTE eAttribute) {
1140 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001141 ThrowInvalidPropertyException();
1142 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001143 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001144 CFX_WideString wsSOMExpression;
1145 GetSOMExpression(wsSOMExpression);
Tom Sepezf0b65542017-02-13 10:26:01 -08001146 pValue->SetString(wsSOMExpression.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001147}
weili44f8faf2016-06-01 14:03:56 -07001148
Dan Sinclair1770c022016-03-14 14:14:16 -04001149void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
1150 int32_t iLength = pArguments->GetLength();
1151 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001152 ThrowParamCountMismatchException(L"applyXSL");
Dan Sinclair1770c022016-03-14 14:14:16 -04001153 return;
1154 }
tsepez6fe7d212016-04-06 10:51:14 -07001155 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001156 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili60607c32016-05-26 11:53:12 -07001157 // TODO(weili): check whether we need to implement this, pdfium:501.
1158 // For now, just put the variables here to avoid unused variable warning.
1159 (void)wsExpression;
Dan Sinclair1770c022016-03-14 14:14:16 -04001160}
weili60607c32016-05-26 11:53:12 -07001161
Dan Sinclair1770c022016-03-14 14:14:16 -04001162void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
1163 int32_t iLength = pArguments->GetLength();
1164 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001165 ThrowParamCountMismatchException(L"assignNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04001166 return;
1167 }
1168 CFX_WideString wsExpression;
1169 CFX_WideString wsValue;
1170 int32_t iAction = 0;
weili44f8faf2016-06-01 14:03:56 -07001171 wsExpression =
1172 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001173 if (iLength >= 2) {
weili60607c32016-05-26 11:53:12 -07001174 wsValue =
1175 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001176 }
weili60607c32016-05-26 11:53:12 -07001177 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001178 iAction = pArguments->GetInt32(2);
weili60607c32016-05-26 11:53:12 -07001179 // TODO(weili): check whether we need to implement this, pdfium:501.
1180 // For now, just put the variables here to avoid unused variable warning.
1181 (void)wsExpression;
1182 (void)wsValue;
1183 (void)iAction;
Dan Sinclair1770c022016-03-14 14:14:16 -04001184}
weili60607c32016-05-26 11:53:12 -07001185
Dan Sinclair1770c022016-03-14 14:14:16 -04001186void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
1187 int32_t iLength = pArguments->GetLength();
1188 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001189 ThrowParamCountMismatchException(L"clone");
Dan Sinclair1770c022016-03-14 14:14:16 -04001190 return;
1191 }
weili44f8faf2016-06-01 14:03:56 -07001192 bool bClone = !!pArguments->GetInt32(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001193 CXFA_Node* pCloneNode = Clone(bClone);
dsinclairf27aeec2016-06-07 19:36:18 -07001194 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001195 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
1196}
weili44f8faf2016-06-01 14:03:56 -07001197
Dan Sinclair1770c022016-03-14 14:14:16 -04001198void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
1199 int32_t iLength = pArguments->GetLength();
1200 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001201 ThrowParamCountMismatchException(L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001202 return;
1203 }
tsepez6fe7d212016-04-06 10:51:14 -07001204 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001205 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001206 CFX_WideString wsValue;
tsepez4c3debb2016-04-08 12:20:38 -07001207 GetAttribute(wsExpression.AsStringC(), wsValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07001208 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001209 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08001210 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001211}
weili44f8faf2016-06-01 14:03:56 -07001212
Dan Sinclair1770c022016-03-14 14:14:16 -04001213void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
1214 int32_t iLength = pArguments->GetLength();
1215 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001216 ThrowParamCountMismatchException(L"getElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001217 return;
1218 }
1219 CFX_WideString wsExpression;
1220 int32_t iValue = 0;
weili44f8faf2016-06-01 14:03:56 -07001221 wsExpression =
1222 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1223 if (iLength >= 2)
Dan Sinclair1770c022016-03-14 14:14:16 -04001224 iValue = pArguments->GetInt32(1);
dsinclair6e124782016-06-23 12:14:55 -07001225 CXFA_Node* pNode =
1226 GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
dsinclairf27aeec2016-06-07 19:36:18 -07001227 pArguments->GetReturnValue()->Assign(
1228 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001229}
weili65be4b12016-05-25 15:47:43 -07001230
Dan Sinclair1770c022016-03-14 14:14:16 -04001231void CXFA_Node::Script_NodeClass_IsPropertySpecified(
1232 CFXJSE_Arguments* pArguments) {
1233 int32_t iLength = pArguments->GetLength();
1234 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001235 ThrowParamCountMismatchException(L"isPropertySpecified");
Dan Sinclair1770c022016-03-14 14:14:16 -04001236 return;
1237 }
1238 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001239 bool bParent = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001240 int32_t iIndex = 0;
weili44f8faf2016-06-01 14:03:56 -07001241 wsExpression =
1242 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili65be4b12016-05-25 15:47:43 -07001243 if (iLength >= 2)
weili44f8faf2016-06-01 14:03:56 -07001244 bParent = !!pArguments->GetInt32(1);
weili65be4b12016-05-25 15:47:43 -07001245 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001246 iIndex = pArguments->GetInt32(2);
tsepezd19e9122016-11-02 15:43:18 -07001247 bool bHas = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001248 const XFA_ATTRIBUTEINFO* pAttributeInfo =
tsepez4c3debb2016-04-08 12:20:38 -07001249 XFA_GetAttributeByName(wsExpression.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001250 CFX_WideString wsValue;
weili65be4b12016-05-25 15:47:43 -07001251 if (pAttributeInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04001252 bHas = HasAttribute(pAttributeInfo->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04001253 if (!bHas) {
dsinclair6e124782016-06-23 12:14:55 -07001254 XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
1255 bHas = !!GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001256 if (!bHas && bParent && m_pParent) {
1257 // Also check on the parent.
1258 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
1259 if (!bHas)
dsinclair6e124782016-06-23 12:14:55 -07001260 bHas = !!m_pParent->GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001261 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001262 }
dsinclair12a6b0c2016-05-26 11:14:08 -07001263 CFXJSE_Value* pValue = pArguments->GetReturnValue();
1264 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001265 pValue->SetBoolean(bHas);
Dan Sinclair1770c022016-03-14 14:14:16 -04001266}
weili65be4b12016-05-25 15:47:43 -07001267
Dan Sinclair1770c022016-03-14 14:14:16 -04001268void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
1269 int32_t iLength = pArguments->GetLength();
1270 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001271 ThrowParamCountMismatchException(L"loadXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001272 return;
1273 }
Dan Sinclairfdf7d402017-04-18 15:25:58 -04001274
weili44f8faf2016-06-01 14:03:56 -07001275 bool bIgnoreRoot = true;
1276 bool bOverwrite = 0;
Dan Sinclairfdf7d402017-04-18 15:25:58 -04001277 CFX_ByteString wsExpression = pArguments->GetUTF8String(0);
weili44f8faf2016-06-01 14:03:56 -07001278 if (wsExpression.IsEmpty())
Tom Sepezd3743ea2016-05-16 15:56:53 -07001279 return;
weili44f8faf2016-06-01 14:03:56 -07001280 if (iLength >= 2)
1281 bIgnoreRoot = !!pArguments->GetInt32(1);
1282 if (iLength >= 3)
1283 bOverwrite = !!pArguments->GetInt32(2);
Dan Sinclairfdf7d402017-04-18 15:25:58 -04001284 auto pParser = pdfium::MakeUnique<CXFA_SimpleParser>(m_pDocument, false);
weili44f8faf2016-06-01 14:03:56 -07001285 if (!pParser)
Dan Sinclair1770c022016-03-14 14:14:16 -04001286 return;
Dan Sinclairfdf7d402017-04-18 15:25:58 -04001287 CFDE_XMLNode* pXMLNode = pParser->ParseXMLData(wsExpression, nullptr);
1288 if (!pXMLNode)
weili44f8faf2016-06-01 14:03:56 -07001289 return;
dsinclairae95f762016-03-29 16:58:29 -07001290 if (bIgnoreRoot &&
1291 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
1292 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
weili44f8faf2016-06-01 14:03:56 -07001293 bIgnoreRoot = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001294 }
tsepezd19e9122016-11-02 15:43:18 -07001295 CXFA_Node* pFakeRoot = Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001296 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
1297 if (!wsContentType.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07001298 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
1299 CFX_WideString(wsContentType));
Dan Sinclair1770c022016-03-14 14:14:16 -04001300 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001301
1302 std::unique_ptr<CFDE_XMLNode> pFakeXMLRoot(pFakeRoot->GetXMLMappingNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001303 if (!pFakeXMLRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001304 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
Dan Sinclair93bfc262017-04-04 15:10:00 -04001305 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone() : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001306 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001307 if (!pFakeXMLRoot) {
1308 pFakeXMLRoot =
1309 pdfium::MakeUnique<CFDE_XMLElement>(CFX_WideString(GetClassName()));
1310 }
dsinclair017052a2016-06-28 07:43:51 -07001311
Dan Sinclair1770c022016-03-14 14:14:16 -04001312 if (bIgnoreRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001313 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001314 while (pXMLChild) {
dsinclairae95f762016-03-29 16:58:29 -07001315 CFDE_XMLNode* pXMLSibling =
1316 pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001317 pXMLNode->RemoveChildNode(pXMLChild);
1318 pFakeXMLRoot->InsertChildNode(pXMLChild);
1319 pXMLChild = pXMLSibling;
1320 }
1321 } else {
dsinclairae95f762016-03-29 16:58:29 -07001322 CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001323 if (pXMLParent) {
1324 pXMLParent->RemoveChildNode(pXMLNode);
1325 }
1326 pFakeXMLRoot->InsertChildNode(pXMLNode);
1327 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001328 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001329 pFakeRoot = pParser->GetRootNode();
Dan Sinclair93bfc262017-04-04 15:10:00 -04001330 if (!pFakeRoot)
1331 return;
1332
1333 if (bOverwrite) {
1334 CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1335 CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1336 int32_t index = 0;
1337 while (pNewChild) {
1338 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1339 pFakeRoot->RemoveChild(pNewChild);
1340 InsertChild(index++, pNewChild);
1341 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
1342 pNewChild = pItem;
Dan Sinclair1770c022016-03-14 14:14:16 -04001343 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001344 while (pChild) {
1345 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1346 RemoveChild(pChild);
1347 pFakeRoot->InsertChild(pChild);
1348 pChild = pItem;
Dan Sinclair1770c022016-03-14 14:14:16 -04001349 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001350 if (GetPacketID() == XFA_XDPPACKET_Form &&
1351 GetElementType() == XFA_Element::ExData) {
1352 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
1353 SetXMLMappingNode(pFakeXMLRoot.release());
1354 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
1355 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent))
1356 pFakeXMLRoot.reset(pTempXMLNode);
1357 else
1358 pFakeXMLRoot = nullptr;
1359 }
1360 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001361 } else {
Dan Sinclair93bfc262017-04-04 15:10:00 -04001362 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1363 while (pChild) {
1364 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1365 pFakeRoot->RemoveChild(pChild);
1366 InsertChild(pChild);
1367 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
1368 pChild = pItem;
1369 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001370 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001371 if (pFakeXMLRoot) {
1372 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot.release());
1373 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
1374 }
1375 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001376}
weili44f8faf2016-06-01 14:03:56 -07001377
Dan Sinclair1770c022016-03-14 14:14:16 -04001378void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
weili44f8faf2016-06-01 14:03:56 -07001379 // TODO(weili): Check whether we need to implement this, pdfium:501.
Dan Sinclair1770c022016-03-14 14:14:16 -04001380}
1381
1382void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1383 int32_t iLength = pArguments->GetLength();
1384 if (iLength < 0 || iLength > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001385 ThrowParamCountMismatchException(L"saveXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001386 return;
1387 }
weili44f8faf2016-06-01 14:03:56 -07001388 bool bPrettyMode = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001389 if (iLength == 1) {
weili65be4b12016-05-25 15:47:43 -07001390 if (pArguments->GetUTF8String(0) != "pretty") {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001391 ThrowArgumentMismatchException();
Dan Sinclair1770c022016-03-14 14:14:16 -04001392 return;
1393 }
weili44f8faf2016-06-01 14:03:56 -07001394 bPrettyMode = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001395 }
Dan Sinclair5ae87922017-04-18 11:54:04 -04001396 CFX_WideString bsXMLHeader = L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
weili65be4b12016-05-25 15:47:43 -07001397 if (GetPacketID() == XFA_XDPPACKET_Form ||
1398 GetPacketID() == XFA_XDPPACKET_Datasets) {
1399 CFDE_XMLNode* pElement = nullptr;
1400 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1401 pElement = GetXMLMappingNode();
1402 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
Dan Sinclair5ae87922017-04-18 11:54:04 -04001403 pArguments->GetReturnValue()->SetString(
1404 bsXMLHeader.UTF8Encode().AsStringC());
weili65be4b12016-05-25 15:47:43 -07001405 return;
1406 }
1407 XFA_DataExporter_DealWithDataGroupNode(this);
1408 }
tsepez833619b2016-12-07 09:21:17 -08001409 CFX_RetainPtr<IFX_MemoryStream> pMemoryStream =
1410 IFX_MemoryStream::Create(true);
Dan Sinclairbf510b72017-04-18 16:35:55 -04001411 auto pStream = pdfium::MakeRetain<CFGAS_Stream>(pMemoryStream, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001412 pStream->SetCodePage(FX_CODEPAGE_UTF8);
Dan Sinclair5ae87922017-04-18 11:54:04 -04001413 pStream->WriteString(bsXMLHeader.AsStringC());
1414
weili65be4b12016-05-25 15:47:43 -07001415 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepez7cda31a2016-12-07 12:10:20 -08001416 XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001417 else
tsepez7cda31a2016-12-07 12:10:20 -08001418 pElement->SaveXMLNode(pStream);
weili65be4b12016-05-25 15:47:43 -07001419 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1420 // For now, just put it here to avoid unused variable warning.
1421 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001422 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001423 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001424 return;
1425 }
dsinclairf27aeec2016-06-07 19:36:18 -07001426 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001427}
1428
1429void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1430 int32_t iLength = pArguments->GetLength();
1431 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001432 ThrowParamCountMismatchException(L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001433 return;
1434 }
tsepez6fe7d212016-04-06 10:51:14 -07001435 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001436 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001437 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001438 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001439 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001440}
weili60607c32016-05-26 11:53:12 -07001441
Dan Sinclair1770c022016-03-14 14:14:16 -04001442void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1443 int32_t iLength = pArguments->GetLength();
1444 if (iLength != 1 && iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001445 ThrowParamCountMismatchException(L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001446 return;
1447 }
weili60607c32016-05-26 11:53:12 -07001448 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001449 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001450 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1451 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001452 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001453 // TODO(weili): check whether we need to implement this, pdfium:501.
1454 // For now, just put the variables here to avoid unused variable warning.
1455 (void)pNode;
1456 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001457}
weili60607c32016-05-26 11:53:12 -07001458
dsinclair12a6b0c2016-05-26 11:14:08 -07001459void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001460 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001461 XFA_ATTRIBUTE eAttribute) {
1462 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001463 ThrowInvalidPropertyException();
1464 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001465 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001466
1467 CFX_WideString wsNameSpace;
1468 TryNamespace(wsNameSpace);
Tom Sepezf0b65542017-02-13 10:26:01 -08001469 pValue->SetString(wsNameSpace.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001470}
weili44f8faf2016-06-01 14:03:56 -07001471
dsinclair12a6b0c2016-05-26 11:14:08 -07001472void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001473 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001474 XFA_ATTRIBUTE eAttribute) {
1475 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001476 ThrowInvalidPropertyException();
1477 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001478 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001479 pValue->Assign(
1480 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
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_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001484 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001485 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001486 if (bSetting) {
1487 ThrowInvalidPropertyException();
1488 return;
1489 }
1490 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001491}
weili44f8faf2016-06-01 14:03:56 -07001492
dsinclair12a6b0c2016-05-26 11:14:08 -07001493void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001494 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001495 XFA_ATTRIBUTE eAttribute) {
1496 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001497 ThrowInvalidPropertyException();
1498 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001499 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001500 if (GetElementType() == XFA_Element::Subform) {
1501 pValue->SetBoolean(false);
1502 return;
1503 }
1504 CFX_WideString strValue;
1505 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001506}
weili44f8faf2016-06-01 14:03:56 -07001507
dsinclair12a6b0c2016-05-26 11:14:08 -07001508void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001509 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001510 XFA_ATTRIBUTE eAttribute) {
1511 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001512 ThrowInvalidPropertyException();
1513 return;
1514 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001515 std::vector<CXFA_Node*> properties =
1516 GetNodeList(XFA_NODEFILTER_OneOfProperty);
1517 if (!properties.empty()) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001518 pValue->Assign(
Tom Sepezf8a94392017-03-14 12:13:22 -07001519 m_pDocument->GetScriptContext()->GetJSValueFromMap(properties.front()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001520 }
1521}
weili44f8faf2016-06-01 14:03:56 -07001522
Dan Sinclair1770c022016-03-14 14:14:16 -04001523void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001524
Dan Sinclair1770c022016-03-14 14:14:16 -04001525void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1526 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001527 pArguments->GetReturnValue()->SetObject(
1528 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001529}
1530void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1531}
dsinclair5b36f0a2016-07-19 10:56:23 -07001532
Dan Sinclair1770c022016-03-14 14:14:16 -04001533void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1534 Script_Template_CreateNode(pArguments);
1535}
dsinclair5b36f0a2016-07-19 10:56:23 -07001536
Dan Sinclair1770c022016-03-14 14:14:16 -04001537void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1538 int32_t iLength = pArguments->GetLength();
1539 if (iLength < 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001540 ThrowParamCountMismatchException(L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001541 return;
1542 }
1543 CFX_WideString wsNameSpace;
1544 if (iLength >= 1) {
1545 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001546 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001547 }
1548 CFX_WideString wsNodeNameSpace;
1549 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001550 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001551 if (pValue)
1552 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001553}
dsinclair5b36f0a2016-07-19 10:56:23 -07001554
dsinclair12a6b0c2016-05-26 11:14:08 -07001555void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001556 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001557 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001558
dsinclair12a6b0c2016-05-26 11:14:08 -07001559void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001560 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001561 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001562
dsinclair12a6b0c2016-05-26 11:14:08 -07001563void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001564 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001565 XFA_ATTRIBUTE eAttribute) {
1566 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001567 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001568 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001569 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001570 }
1571}
dsinclair5b36f0a2016-07-19 10:56:23 -07001572
dsinclair12a6b0c2016-05-26 11:14:08 -07001573void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001574 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001575 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001576 if (bSetting) {
1577 ThrowInvalidPropertyException();
1578 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001579 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001580 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001581}
dsinclair5b36f0a2016-07-19 10:56:23 -07001582
dsinclair12a6b0c2016-05-26 11:14:08 -07001583void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001584 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001585 XFA_ATTRIBUTE eAttribute) {
1586 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001587 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001588 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001589 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001590 }
1591}
dsinclair5b36f0a2016-07-19 10:56:23 -07001592
dsinclair12a6b0c2016-05-26 11:14:08 -07001593void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001594 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001595 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001596 if (bSetting) {
1597 ThrowInvalidPropertyException();
1598 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001599 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001600 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001601}
thestigb1a59592016-04-14 18:29:56 -07001602
Dan Sinclair1770c022016-03-14 14:14:16 -04001603void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001604 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001605 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001606 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001607 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001608 return;
thestigb1a59592016-04-14 18:29:56 -07001609
dsinclaira1b07722016-07-11 08:20:58 -07001610 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001611 if (!pNotify)
1612 return;
1613
1614 uint32_t dwPacket = GetPacketID();
1615 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1616 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001617 return;
1618 }
thestigb1a59592016-04-14 18:29:56 -07001619
1620 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001621 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001622 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001623 bNeedFindContainer = true;
1624 pNotify->OnValueChanged(this, eAttribute, this,
1625 GetNodeItem(XFA_NODEITEM_Parent));
1626 break;
dsinclair56a8b192016-06-21 14:15:25 -07001627 case XFA_Element::Font:
1628 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001629 bNeedFindContainer = true;
1630 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001631 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001632 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1633 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1634 } else {
1635 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1636 }
1637 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001638 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001639 bNeedFindContainer = true;
1640 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001641 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001642 if (pParentNode->IsContainerNode()) {
1643 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001644 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001645 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1646 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1647 } else {
1648 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001649 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001650 pNotify->OnValueChanged(this, eAttribute, pNode,
1651 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001652 }
thestigb1a59592016-04-14 18:29:56 -07001653 }
1654 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001655 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001656 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001657 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001658 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1659 eUIType == XFA_Element::NumericEdit ||
1660 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001661 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001662 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001663 pNotify->OnValueChanged(this, eAttribute, pUINode,
1664 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001665 }
thestigb1a59592016-04-14 18:29:56 -07001666 }
1667 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001668 case XFA_Element::Button:
1669 case XFA_Element::Barcode:
1670 case XFA_Element::ChoiceList:
1671 case XFA_Element::DateTimeEdit:
1672 case XFA_Element::NumericEdit:
1673 case XFA_Element::PasswordEdit:
1674 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001675 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1676 if (pUINode) {
1677 pNotify->OnValueChanged(this, eAttribute, pUINode,
1678 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1679 }
1680 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001681 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001682 bNeedFindContainer = true;
1683 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1684 if (pUINode) {
1685 pNotify->OnValueChanged(this, eAttribute, pUINode,
1686 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1687 }
1688 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001689 case XFA_Element::Keep:
1690 case XFA_Element::Bookend:
1691 case XFA_Element::Break:
1692 case XFA_Element::BreakAfter:
1693 case XFA_Element::BreakBefore:
1694 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001695 bNeedFindContainer = true;
1696 break;
dsinclair56a8b192016-06-21 14:15:25 -07001697 case XFA_Element::Area:
1698 case XFA_Element::Draw:
1699 case XFA_Element::ExclGroup:
1700 case XFA_Element::Field:
1701 case XFA_Element::Subform:
1702 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001703 pLayoutPro->AddChangedContainer(this);
1704 pNotify->OnValueChanged(this, eAttribute, this, this);
1705 break;
dsinclair56a8b192016-06-21 14:15:25 -07001706 case XFA_Element::Sharptext:
1707 case XFA_Element::Sharpxml:
1708 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001709 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1710 if (!pTextNode) {
1711 return;
1712 }
1713 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1714 if (!pValueNode) {
1715 return;
1716 }
dsinclair41cb62e2016-06-23 09:20:32 -07001717 XFA_Element eType = pValueNode->GetElementType();
1718 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001719 bNeedFindContainer = true;
1720 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1721 if (pNode && pNode->IsContainerNode()) {
1722 if (bScriptModify) {
1723 pValueNode = pNode;
1724 }
1725 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1726 } else {
1727 pNotify->OnValueChanged(this, eAttribute, pNode,
1728 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001729 }
thestigb1a59592016-04-14 18:29:56 -07001730 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001731 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001732 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1733 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001734 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001735 }
1736 }
thestigb1a59592016-04-14 18:29:56 -07001737 }
1738 } break;
1739 default:
1740 break;
1741 }
1742 if (bNeedFindContainer) {
1743 CXFA_Node* pParent = this;
1744 while (pParent) {
1745 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001746 break;
thestigb1a59592016-04-14 18:29:56 -07001747
1748 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001749 }
thestigb1a59592016-04-14 18:29:56 -07001750 if (pParent) {
1751 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001752 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001753 }
1754}
thestigb1a59592016-04-14 18:29:56 -07001755
dsinclair12a6b0c2016-05-26 11:14:08 -07001756void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001757 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001758 XFA_ATTRIBUTE eAttribute) {
1759 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001760 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001761 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001762 if (eAttribute == XFA_ATTRIBUTE_Use &&
1763 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001764 CXFA_Node* pTemplateNode =
1765 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1766 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001767 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1768 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001769
1770 CFX_WideString wsID;
1771 CFX_WideString wsSOM;
1772 if (!wsValue.IsEmpty()) {
1773 if (wsValue[0] == '#') {
1774 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001775 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001776 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001777 }
1778 }
weili44f8faf2016-06-01 14:03:56 -07001779 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001780 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001781 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001782 XFA_RESOLVENODE_Attributes |
1783 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1784 XFA_RESOLVENODE_Siblings;
1785 XFA_RESOLVENODE_RS resoveNodeRS;
1786 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001787 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Tom Sepezf8a94392017-03-14 12:13:22 -07001788 if (iRet > 0 && resoveNodeRS.objects.front()->IsNode()) {
1789 pProtoNode = resoveNodeRS.objects.front()->AsNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001790 }
1791 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001792 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001793 }
1794 if (pProtoNode) {
1795 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1796 while (pHeadChild) {
1797 CXFA_Node* pSibling =
1798 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1799 RemoveChild(pHeadChild);
1800 pHeadChild = pSibling;
1801 }
tsepezd19e9122016-11-02 15:43:18 -07001802 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001803 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1804 while (pHeadChild) {
1805 CXFA_Node* pSibling =
1806 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1807 pProtoForm->RemoveChild(pHeadChild);
1808 InsertChild(pHeadChild);
1809 pHeadChild = pSibling;
1810 }
1811 m_pDocument->RemovePurgeNode(pProtoForm);
1812 delete pProtoForm;
1813 }
1814 }
1815 } else {
1816 CFX_WideString wsValue;
1817 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001818 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001819 }
1820}
dsinclair5b36f0a2016-07-19 10:56:23 -07001821
dsinclair12a6b0c2016-05-26 11:14:08 -07001822void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001823 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001824 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001825 if (bSetting) {
1826 ThrowInvalidPropertyException();
1827 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001828 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001829
1830 CFX_WideString wsValue;
1831 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001832 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001833}
dsinclair5b36f0a2016-07-19 10:56:23 -07001834
Dan Sinclair1770c022016-03-14 14:14:16 -04001835void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1836 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001837 if (argc != 0 && argc != 1) {
1838 ThrowParamCountMismatchException(L"execute");
1839 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001840 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001841 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001842}
dsinclair5b36f0a2016-07-19 10:56:23 -07001843
Dan Sinclair1770c022016-03-14 14:14:16 -04001844void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001845 if (pArguments->GetLength() != 0)
1846 ThrowParamCountMismatchException(L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001847}
dsinclair5b36f0a2016-07-19 10:56:23 -07001848
dsinclair12a6b0c2016-05-26 11:14:08 -07001849void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001850 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001851 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001852
dsinclair12a6b0c2016-05-26 11:14:08 -07001853void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001854 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001855 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001856
dsinclair12a6b0c2016-05-26 11:14:08 -07001857void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001858 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001859 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001860
dsinclair12a6b0c2016-05-26 11:14:08 -07001861void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001862 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001863 XFA_SOM_MESSAGETYPE iMessageType) {
1864 CXFA_WidgetData* pWidgetData = GetWidgetData();
1865 if (!pWidgetData) {
1866 return;
1867 }
tsepezd19e9122016-11-02 15:43:18 -07001868 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001869 CXFA_Validate validate = pWidgetData->GetValidate();
1870 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001871 validate = pWidgetData->GetValidate(true);
1872 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001873 }
1874 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001875 switch (iMessageType) {
1876 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001877 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001878 break;
1879 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001880 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001881 break;
1882 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001883 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001884 break;
1885 default:
1886 break;
1887 }
1888 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001889 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001890 if (!pNotify) {
1891 return;
1892 }
1893 pNotify->AddCalcValidate(this);
1894 }
1895 } else {
1896 CFX_WideString wsMessage;
1897 switch (iMessageType) {
1898 case XFA_SOM_ValidationMessage:
1899 validate.GetScriptMessageText(wsMessage);
1900 break;
1901 case XFA_SOM_FormatMessage:
1902 validate.GetFormatMessageText(wsMessage);
1903 break;
1904 case XFA_SOM_MandatoryMessage:
1905 validate.GetNullMessageText(wsMessage);
1906 break;
1907 default:
1908 break;
1909 }
Tom Sepezf0b65542017-02-13 10:26:01 -08001910 pValue->SetString(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001911 }
1912}
dsinclair5b36f0a2016-07-19 10:56:23 -07001913
dsinclair12a6b0c2016-05-26 11:14:08 -07001914void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001915 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001916 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001917 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001918}
dsinclair5b36f0a2016-07-19 10:56:23 -07001919
dsinclair12a6b0c2016-05-26 11:14:08 -07001920void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001921 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001922 XFA_ATTRIBUTE eAttribute) {
1923 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001924 ThrowInvalidPropertyException();
1925 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001926 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001927
1928 CXFA_WidgetData* pWidgetData = GetWidgetData();
1929 if (!pWidgetData) {
1930 pValue->SetInteger(0);
1931 return;
1932 }
1933 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001934}
dsinclair5b36f0a2016-07-19 10:56:23 -07001935
dsinclair12a6b0c2016-05-26 11:14:08 -07001936void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001937 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001938 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001939 XFA_Element eType = GetElementType();
1940 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001941 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001942 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001943 }
1944 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001945 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001946 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001947 }
1948 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001949 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001950 return;
1951 }
1952 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001953 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07001954 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07001955 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07001956
Dan Sinclair1770c022016-03-14 14:14:16 -04001957 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07001958 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001959 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001960 CFX_WideString wsPicture;
Tom Sepezf8a94392017-03-14 12:13:22 -07001961 for (CXFA_Node* pFormNode : GetBindItems()) {
1962 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -04001963 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001964 pContainerWidgetData = pFormNode->GetContainerWidgetData();
1965 if (pContainerWidgetData) {
1966 pContainerWidgetData->GetPictureContent(wsPicture,
1967 XFA_VALUEPICTURE_DataBind);
1968 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001969 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -04001970 break;
weili44f8faf2016-06-01 14:03:56 -07001971 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001972 }
1973 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
1974 pContainerWidgetData = GetContainerWidgetData();
1975 }
1976 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07001977 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04001978 }
tsepezd19e9122016-11-02 15:43:18 -07001979 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001980 } else {
tsepezd19e9122016-11-02 15:43:18 -07001981 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07001982 if (content.IsEmpty() && eType != XFA_Element::Text &&
1983 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07001984 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07001985 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07001986 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07001987 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07001988 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04001989 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04001990 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08001991 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001992 }
1993 }
1994}
dsinclair5b36f0a2016-07-19 10:56:23 -07001995
dsinclair12a6b0c2016-05-26 11:14:08 -07001996void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001997 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001998 XFA_ATTRIBUTE eAttribute) {
1999 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002000 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002001 return;
2002 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002003
tsepezd19e9122016-11-02 15:43:18 -07002004 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002005 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002006 pValue->SetNull();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002007 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002008 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002009 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002010}
dsinclair5b36f0a2016-07-19 10:56:23 -07002011
dsinclair12a6b0c2016-05-26 11:14:08 -07002012void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002013 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002014 XFA_ATTRIBUTE eAttribute) {
2015 if (bSetting) {
2016 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002017 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002018 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002019
tsepezb4c9f3f2016-04-13 15:41:21 -07002020 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002021 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002022 CFX_WideString wsFormatValue(wsNewValue);
2023 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2024 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002025 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002026 }
tsepezd19e9122016-11-02 15:43:18 -07002027 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002028 } else {
tsepezd19e9122016-11-02 15:43:18 -07002029 CFX_WideString wsValue = GetScriptContent(true);
dan sinclair65c7c232017-02-02 14:05:30 -08002030 pValue->SetBoolean(wsValue == L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002031 }
2032}
dsinclair2f5582f2016-06-09 11:48:23 -07002033
dsinclair12a6b0c2016-05-26 11:14:08 -07002034void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002035 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002036 XFA_ATTRIBUTE eAttribute) {
2037 CXFA_WidgetData* pWidgetData = GetWidgetData();
2038 if (!pWidgetData) {
2039 return;
2040 }
tsepezd19e9122016-11-02 15:43:18 -07002041 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002042 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002043 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002044 int32_t r = 0;
2045 int32_t g = 0;
2046 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002047 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002048 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2049 for (int32_t i = 0; i < iSize; ++i) {
2050 CXFA_Edge edge = border.GetEdge(i);
2051 edge.SetColor(rgb);
2052 }
2053 } else {
2054 CXFA_Edge edge = border.GetEdge(0);
2055 FX_ARGB color = edge.GetColor();
2056 int32_t a, r, g, b;
2057 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002058 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002059 strColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002060 pValue->SetString(strColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002061 }
2062}
dsinclair5b36f0a2016-07-19 10:56:23 -07002063
dsinclair12a6b0c2016-05-26 11:14:08 -07002064void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002065 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002066 XFA_ATTRIBUTE eAttribute) {
2067 CXFA_WidgetData* pWidgetData = GetWidgetData();
2068 if (!pWidgetData) {
2069 return;
2070 }
tsepezd19e9122016-11-02 15:43:18 -07002071 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002072 int32_t iSize = border.CountEdges();
2073 CFX_WideString wsThickness;
2074 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002075 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002076 for (int32_t i = 0; i < iSize; ++i) {
2077 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002078 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002079 edge.SetMSThickness(thickness);
2080 }
2081 } else {
2082 CXFA_Edge edge = border.GetEdge(0);
2083 CXFA_Measurement thickness = edge.GetMSThickness();
2084 thickness.ToString(wsThickness);
Tom Sepezf0b65542017-02-13 10:26:01 -08002085 pValue->SetString(wsThickness.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002086 }
2087}
dsinclair5b36f0a2016-07-19 10:56:23 -07002088
dsinclair12a6b0c2016-05-26 11:14:08 -07002089void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002090 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002091 XFA_ATTRIBUTE eAttribute) {
2092 CXFA_WidgetData* pWidgetData = GetWidgetData();
2093 if (!pWidgetData) {
2094 return;
2095 }
tsepezd19e9122016-11-02 15:43:18 -07002096 CXFA_Border border = pWidgetData->GetBorder(true);
2097 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002098 CXFA_Node* pNode = borderfill.GetNode();
2099 if (!pNode) {
2100 return;
2101 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002102 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002103 int32_t r;
2104 int32_t g;
2105 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002106 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002107 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2108 borderfill.SetColor(color);
2109 } else {
2110 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002111 int32_t a;
2112 int32_t r;
2113 int32_t g;
2114 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002115 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002116 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002117 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002118 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002119 }
2120}
dsinclair5b36f0a2016-07-19 10:56:23 -07002121
dsinclair12a6b0c2016-05-26 11:14:08 -07002122void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002123 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002124 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002125 if (bSetting) {
2126 ThrowInvalidPropertyException();
2127 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002128 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002129
2130 CXFA_Node* pDataNode = GetBindData();
2131 if (!pDataNode) {
2132 pValue->SetNull();
2133 return;
2134 }
2135
2136 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002137}
dsinclair5b36f0a2016-07-19 10:56:23 -07002138
dsinclair12a6b0c2016-05-26 11:14:08 -07002139void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002140 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002141 XFA_ATTRIBUTE eAttribute) {
2142 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002143 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002144 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002145 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002146 XFA_Element uiType = pWidgetData->GetUIType();
2147 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002148 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002149 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002150 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002151 }
2152 }
2153 } else {
tsepezd19e9122016-11-02 15:43:18 -07002154 CFX_WideString content = GetScriptContent(true);
Tom Sepezf0b65542017-02-13 10:26:01 -08002155 if (content.IsEmpty())
dsinclairf27aeec2016-06-07 19:36:18 -07002156 pValue->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002157 else
2158 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002159 }
2160}
dsinclair5b36f0a2016-07-19 10:56:23 -07002161
dsinclair12a6b0c2016-05-26 11:14:08 -07002162void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002163 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002164 XFA_ATTRIBUTE eAttribute) {
2165 CXFA_WidgetData* pWidgetData = GetWidgetData();
2166 if (!pWidgetData) {
2167 return;
2168 }
2169 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002170 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002171 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002172 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002173 } else {
2174 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002175 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002176 }
dsinclair2f5582f2016-06-09 11:48:23 -07002177 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002178 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002179 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002180
Dan Sinclair1770c022016-03-14 14:14:16 -04002181 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002182 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002183 int32_t iLeadDigits = 0;
2184 int32_t iFracDigits = 0;
2185 pWidgetData->GetLeadDigits(iLeadDigits);
2186 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002187 wsNewText =
2188 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002189 }
2190 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2191 CFX_WideString wsFormatText(wsNewText);
2192 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002193 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002194 }
tsepezd19e9122016-11-02 15:43:18 -07002195 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002196 } else {
tsepezd19e9122016-11-02 15:43:18 -07002197 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002198 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002199 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002200 } else {
2201 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002202 CXFA_Value defVal = pWidgetData->GetFormValue();
2203 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002204 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002205 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002206 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
Tom Sepezf0b65542017-02-13 10:26:01 -08002207 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002208 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002209 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002210 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002211 }
dsinclair070fcdf2016-06-22 22:04:54 -07002212 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002213 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002214 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002215 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002216 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002217 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002218 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002219 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002220 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002221 }
2222 }
2223 }
2224}
dsinclair5b36f0a2016-07-19 10:56:23 -07002225
dsinclair12a6b0c2016-05-26 11:14:08 -07002226void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002227 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002228 XFA_ATTRIBUTE eAttribute) {
2229 CXFA_WidgetData* pWidgetData = GetWidgetData();
2230 if (!pWidgetData) {
2231 return;
2232 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002233 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002234 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002235 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002236 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002237 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
Tom Sepezf0b65542017-02-13 10:26:01 -08002238 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002239 }
2240}
dsinclair5b36f0a2016-07-19 10:56:23 -07002241
dsinclair12a6b0c2016-05-26 11:14:08 -07002242void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002243 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002244 XFA_ATTRIBUTE eAttribute) {
2245 CXFA_WidgetData* pWidgetData = GetWidgetData();
2246 if (!pWidgetData) {
2247 return;
2248 }
tsepezd19e9122016-11-02 15:43:18 -07002249 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002250 CXFA_Node* pNode = font.GetNode();
2251 if (!pNode) {
2252 return;
2253 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002254 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002255 int32_t r;
2256 int32_t g;
2257 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002258 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002259 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2260 font.SetColor(color);
2261 } else {
2262 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002263 int32_t a;
2264 int32_t r;
2265 int32_t g;
2266 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002267 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002268 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002269 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002270 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002271 }
2272}
dsinclair5b36f0a2016-07-19 10:56:23 -07002273
dsinclair12a6b0c2016-05-26 11:14:08 -07002274void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002275 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002276 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002277 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002278}
dsinclair5b36f0a2016-07-19 10:56:23 -07002279
dsinclair12a6b0c2016-05-26 11:14:08 -07002280void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002281 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002282 XFA_ATTRIBUTE eAttribute) {
2283 CXFA_WidgetData* pWidgetData = GetWidgetData();
2284 if (!pWidgetData) {
2285 return;
2286 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002287 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002288 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002289 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002290 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002291 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
Tom Sepezf0b65542017-02-13 10:26:01 -08002292 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002293 }
2294}
dsinclair5b36f0a2016-07-19 10:56:23 -07002295
dsinclair12a6b0c2016-05-26 11:14:08 -07002296void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002297 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002298 XFA_ATTRIBUTE eAttribute) {
2299 CXFA_WidgetData* pWidgetData = GetWidgetData();
2300 if (!pWidgetData) {
2301 return;
2302 }
tsepezd19e9122016-11-02 15:43:18 -07002303 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002304 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002305 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002306 } else {
2307 int32_t iValue = validate.GetNullTest();
2308 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002309 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002310 CFX_WideString wsValue;
2311 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002312 wsValue = pInfo->pName;
Tom Sepezf0b65542017-02-13 10:26:01 -08002313 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002314 }
2315}
dsinclair5b36f0a2016-07-19 10:56:23 -07002316
dsinclair12a6b0c2016-05-26 11:14:08 -07002317void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002318 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002319 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002320 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002321}
dsinclair5b36f0a2016-07-19 10:56:23 -07002322
dsinclair12a6b0c2016-05-26 11:14:08 -07002323void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002324 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002325 XFA_ATTRIBUTE eAttribute) {
2326 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002327 ThrowInvalidPropertyException();
2328 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002329 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002330 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002331}
dsinclair5b36f0a2016-07-19 10:56:23 -07002332
dsinclair12a6b0c2016-05-26 11:14:08 -07002333void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002334 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002335 XFA_ATTRIBUTE eAttribute) {
2336 CXFA_WidgetData* pWidgetData = GetWidgetData();
2337 if (!pWidgetData) {
2338 return;
2339 }
2340 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002341 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002342 if (iIndex == -1) {
2343 pWidgetData->ClearAllSelections();
2344 return;
2345 }
tsepezd19e9122016-11-02 15:43:18 -07002346 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002347 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002348 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002349 }
2350}
dsinclair5b36f0a2016-07-19 10:56:23 -07002351
Dan Sinclair1770c022016-03-14 14:14:16 -04002352void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2353 CXFA_WidgetData* pWidgetData = GetWidgetData();
2354 if (!pWidgetData) {
2355 return;
2356 }
tsepezd19e9122016-11-02 15:43:18 -07002357 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002358}
dsinclair5b36f0a2016-07-19 10:56:23 -07002359
Dan Sinclair1770c022016-03-14 14:14:16 -04002360void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002361 if (pArguments->GetLength() != 1) {
2362 ThrowParamCountMismatchException(L"execEvent");
2363 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002364 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002365
2366 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2367 int32_t iRet = execSingleEventByName(
2368 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2369 XFA_Element::Field);
2370 if (eventString != "validate")
2371 return;
2372
2373 pArguments->GetReturnValue()->SetBoolean(
2374 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002375}
dsinclair5b36f0a2016-07-19 10:56:23 -07002376
Dan Sinclair1770c022016-03-14 14:14:16 -04002377void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002378 if (pArguments->GetLength() != 0) {
2379 ThrowParamCountMismatchException(L"execInitialize");
2380 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002381 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002382
2383 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2384 if (!pNotify)
2385 return;
2386
2387 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002388}
dsinclair5b36f0a2016-07-19 10:56:23 -07002389
Dan Sinclair1770c022016-03-14 14:14:16 -04002390void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2391 int32_t iLength = pArguments->GetLength();
2392 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002393 ThrowParamCountMismatchException(L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002394 return;
2395 }
2396 CXFA_WidgetData* pWidgetData = GetWidgetData();
2397 if (!pWidgetData) {
2398 return;
2399 }
2400 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002401 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002402 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002403 if (pValue)
2404 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002405}
dsinclair5b36f0a2016-07-19 10:56:23 -07002406
Dan Sinclair1770c022016-03-14 14:14:16 -04002407void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2408 int32_t iLength = pArguments->GetLength();
2409 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002410 ThrowParamCountMismatchException(L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002411 return;
2412 }
2413 int32_t iIndex = pArguments->GetInt32(0);
2414 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002415 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002416 return;
2417 }
2418 CXFA_WidgetData* pWidgetData = GetWidgetData();
2419 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002420 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002421 return;
2422 }
2423 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002424 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002425 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002426 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002427 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002428 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002429}
dsinclair5b36f0a2016-07-19 10:56:23 -07002430
Dan Sinclair1770c022016-03-14 14:14:16 -04002431void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2432 int32_t iLength = pArguments->GetLength();
2433 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002434 ThrowParamCountMismatchException(L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002435 return;
2436 }
2437 CXFA_WidgetData* pWidgetData = GetWidgetData();
2438 if (!pWidgetData) {
2439 return;
2440 }
2441 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002442 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002443 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002444 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002445 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002446 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08002447 pValue->SetString(wsBoundValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002448}
dsinclair5b36f0a2016-07-19 10:56:23 -07002449
Dan Sinclair1770c022016-03-14 14:14:16 -04002450void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2451 int32_t iLength = pArguments->GetLength();
2452 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002453 ThrowParamCountMismatchException(L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002454 return;
2455 }
2456 CXFA_WidgetData* pWidgetData = GetWidgetData();
2457 if (!pWidgetData) {
2458 return;
2459 }
2460 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002461 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002462 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002463 if (pValue)
2464 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002465}
dsinclair5b36f0a2016-07-19 10:56:23 -07002466
Dan Sinclair1770c022016-03-14 14:14:16 -04002467void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002468 if (pArguments->GetLength() != 0) {
2469 ThrowParamCountMismatchException(L"execCalculate");
2470 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002471 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002472
2473 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2474 if (!pNotify)
2475 return;
2476
2477 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002478}
dsinclair5b36f0a2016-07-19 10:56:23 -07002479
Dan Sinclair1770c022016-03-14 14:14:16 -04002480void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002481
Dan Sinclair1770c022016-03-14 14:14:16 -04002482void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2483 int32_t iLength = pArguments->GetLength();
2484 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002485 ThrowParamCountMismatchException(L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002486 return;
2487 }
2488 int32_t iIndex = pArguments->GetInt32(0);
2489 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002490 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002491 return;
2492 }
2493 CXFA_WidgetData* pWidgetData = GetWidgetData();
2494 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002495 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002496 return;
2497 }
2498 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002499 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002500 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002501 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002502 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002503 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002504}
dsinclair5b36f0a2016-07-19 10:56:23 -07002505
Dan Sinclair1770c022016-03-14 14:14:16 -04002506void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2507 int32_t iLength = pArguments->GetLength();
2508 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002509 ThrowParamCountMismatchException(L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002510 return;
2511 }
2512 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002513 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002514 return;
thestig800222e2016-05-26 22:00:29 -07002515
Dan Sinclair1770c022016-03-14 14:14:16 -04002516 int32_t iIndex = pArguments->GetInt32(0);
2517 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002518 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002519 } else {
thestig800222e2016-05-26 22:00:29 -07002520 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002521 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002522 }
2523}
dsinclair5b36f0a2016-07-19 10:56:23 -07002524
Dan Sinclair1770c022016-03-14 14:14:16 -04002525void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2526 int32_t iLength = pArguments->GetLength();
2527 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002528 ThrowParamCountMismatchException(L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002529 return;
2530 }
2531 CXFA_WidgetData* pWidgetData = GetWidgetData();
2532 if (!pWidgetData) {
2533 return;
2534 }
2535 CFX_WideString wsLabel;
2536 CFX_WideString wsValue;
2537 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002538 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002539 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002540 }
2541 if (iLength >= 2) {
2542 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002543 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002544 }
tsepezd19e9122016-11-02 15:43:18 -07002545 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002546}
dsinclair5b36f0a2016-07-19 10:56:23 -07002547
Dan Sinclair1770c022016-03-14 14:14:16 -04002548void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002549 if (pArguments->GetLength() != 0) {
2550 ThrowParamCountMismatchException(L"execValidate");
2551 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002552 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002553
2554 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2555 if (!pNotify) {
2556 pArguments->GetReturnValue()->SetBoolean(false);
2557 return;
2558 }
2559
2560 int32_t iRet =
2561 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
2562 pArguments->GetReturnValue()->SetBoolean(
2563 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002564}
dsinclair5b36f0a2016-07-19 10:56:23 -07002565
dsinclair12a6b0c2016-05-26 11:14:08 -07002566void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002567 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002568 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002569 if (bSetting)
2570 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002571}
dsinclair5b36f0a2016-07-19 10:56:23 -07002572
dsinclair12a6b0c2016-05-26 11:14:08 -07002573void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002574 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002575 XFA_ATTRIBUTE eAttribute) {
2576 CXFA_WidgetData* pWidgetData = GetWidgetData();
2577 if (!pWidgetData) {
2578 return;
2579 }
2580 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002581 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002582 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002583 } else {
tsepezd19e9122016-11-02 15:43:18 -07002584 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002585 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2586 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002587 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002588 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002589 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002590 }
2591 }
2592}
dsinclair5b36f0a2016-07-19 10:56:23 -07002593
dsinclair12a6b0c2016-05-26 11:14:08 -07002594void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002595 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002596 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002597
Dan Sinclair1770c022016-03-14 14:14:16 -04002598void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002599 if (pArguments->GetLength() != 1) {
2600 ThrowParamCountMismatchException(L"execEvent");
2601 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002602 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002603
2604 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2605 execSingleEventByName(
2606 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2607 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002608}
thestig800222e2016-05-26 22:00:29 -07002609
Dan Sinclair1770c022016-03-14 14:14:16 -04002610void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2611 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002612 if (argc < 0 || argc > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002613 ThrowParamCountMismatchException(L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002614 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002615 }
thestig800222e2016-05-26 22:00:29 -07002616
2617 CXFA_WidgetData* pWidgetData = GetWidgetData();
2618 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002619 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002620 return;
2621 }
2622
2623 CXFA_Node* pReturnNode = nullptr;
2624 if (argc == 0) {
2625 pReturnNode = pWidgetData->GetSelectedMember();
2626 } else {
2627 CFX_ByteString szName;
2628 szName = pArguments->GetUTF8String(0);
2629 pReturnNode = pWidgetData->SetSelectedMember(
2630 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2631 }
2632 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002633 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002634 return;
2635 }
dsinclairf27aeec2016-06-07 19:36:18 -07002636 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002637 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002638}
thestig800222e2016-05-26 22:00:29 -07002639
Dan Sinclair1770c022016-03-14 14:14:16 -04002640void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002641 if (pArguments->GetLength() != 0) {
2642 ThrowParamCountMismatchException(L"execInitialize");
2643 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002644 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002645
2646 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2647 if (!pNotify)
2648 return;
2649
2650 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002651}
dsinclair5b36f0a2016-07-19 10:56:23 -07002652
Dan Sinclair1770c022016-03-14 14:14:16 -04002653void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002654 if (pArguments->GetLength() != 0) {
2655 ThrowParamCountMismatchException(L"execCalculate");
2656 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002657 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002658
2659 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2660 if (!pNotify)
2661 return;
2662
2663 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002664}
dsinclair5b36f0a2016-07-19 10:56:23 -07002665
Dan Sinclair1770c022016-03-14 14:14:16 -04002666void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002667 if (pArguments->GetLength() != 0) {
2668 ThrowParamCountMismatchException(L"execValidate");
2669 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002670 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002671
2672 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2673 if (!pNotify) {
2674 pArguments->GetReturnValue()->SetBoolean(false);
2675 return;
2676 }
2677
2678 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2679 pArguments->GetReturnValue()->SetBoolean(
2680 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002681}
dsinclair5b36f0a2016-07-19 10:56:23 -07002682
dsinclair12a6b0c2016-05-26 11:14:08 -07002683void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002684 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002685 XFA_ATTRIBUTE eAttribute) {
2686 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002687 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002688 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002689 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002690 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2691 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002692 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002693 pManagerNode = pNode;
2694 break;
2695 }
2696 }
2697 if (pManagerNode) {
2698 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002699 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002700 if (!pNotify) {
2701 return;
2702 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002703 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002704 if (pToInstance &&
2705 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002706 pNotify->RunSubformIndexChange(pToInstance);
2707 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002708 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002709 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002710 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002711 pNotify->RunSubformIndexChange(pFromInstance);
2712 }
2713 }
2714 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002715 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002716 }
2717}
dsinclair5b36f0a2016-07-19 10:56:23 -07002718
dsinclair12a6b0c2016-05-26 11:14:08 -07002719void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002720 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002721 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002722 if (bSetting) {
2723 ThrowInvalidPropertyException();
2724 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002725 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002726
2727 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2728 CXFA_Node* pInstanceMgr = nullptr;
2729 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2730 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2731 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2732 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2733 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2734 wsInstMgrName.Mid(1) == wsName) {
2735 pInstanceMgr = pNode;
2736 }
2737 break;
2738 }
2739 }
2740 if (!pInstanceMgr) {
2741 pValue->SetNull();
2742 return;
2743 }
2744
2745 pValue->Assign(
2746 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
Dan Sinclair1770c022016-03-14 14:14:16 -04002747}
dsinclair5b36f0a2016-07-19 10:56:23 -07002748
dsinclair12a6b0c2016-05-26 11:14:08 -07002749void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002750 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002751 XFA_ATTRIBUTE eAttribute) {
2752 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002753 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002754 } else {
2755 CFX_WideString wsLocaleName;
2756 GetLocaleName(wsLocaleName);
Tom Sepezf0b65542017-02-13 10:26:01 -08002757 pValue->SetString(wsLocaleName.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002758 }
2759}
dsinclair5b36f0a2016-07-19 10:56:23 -07002760
Dan Sinclair1770c022016-03-14 14:14:16 -04002761void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002762 if (pArguments->GetLength() != 1) {
2763 ThrowParamCountMismatchException(L"execEvent");
2764 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002765 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002766
2767 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2768 execSingleEventByName(
2769 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2770 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002771}
dsinclair5b36f0a2016-07-19 10:56:23 -07002772
Dan Sinclair1770c022016-03-14 14:14:16 -04002773void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002774 if (pArguments->GetLength() != 0) {
2775 ThrowParamCountMismatchException(L"execInitialize");
2776 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002777 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002778
2779 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2780 if (!pNotify)
2781 return;
2782
2783 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002784}
dsinclair5b36f0a2016-07-19 10:56:23 -07002785
Dan Sinclair1770c022016-03-14 14:14:16 -04002786void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002787 if (pArguments->GetLength() != 0) {
2788 ThrowParamCountMismatchException(L"execCalculate");
2789 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002790 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002791
2792 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2793 if (!pNotify)
2794 return;
2795
2796 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002797}
dsinclair5b36f0a2016-07-19 10:56:23 -07002798
Dan Sinclair1770c022016-03-14 14:14:16 -04002799void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002800 if (pArguments->GetLength() != 0) {
2801 ThrowParamCountMismatchException(L"execValidate");
2802 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002803 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002804
2805 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2806 if (!pNotify) {
2807 pArguments->GetReturnValue()->SetBoolean(false);
2808 return;
2809 }
2810
2811 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2812 pArguments->GetReturnValue()->SetBoolean(
2813 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002814}
dsinclair5b36f0a2016-07-19 10:56:23 -07002815
Dan Sinclair1770c022016-03-14 14:14:16 -04002816void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002817 if (pArguments->GetLength() != 0)
2818 ThrowParamCountMismatchException(L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002819}
dsinclair5b36f0a2016-07-19 10:56:23 -07002820
Dan Sinclair1770c022016-03-14 14:14:16 -04002821int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2822 int32_t index = 0;
2823 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2824 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002825 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2826 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002827 index++;
2828 } else {
2829 break;
2830 }
2831 }
2832 return index;
2833}
dsinclair5b36f0a2016-07-19 10:56:23 -07002834
Dan Sinclair1770c022016-03-14 14:14:16 -04002835void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002836 if (pArguments->GetLength() != 1) {
2837 ThrowParamCountMismatchException(L"formNodes");
2838 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002839 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002840 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002841}
dsinclair5b36f0a2016-07-19 10:56:23 -07002842
Dan Sinclair1770c022016-03-14 14:14:16 -04002843void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002844 if (pArguments->GetLength() != 0) {
2845 ThrowParamCountMismatchException(L"remerge");
2846 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002847 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002848 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002849}
dsinclair5b36f0a2016-07-19 10:56:23 -07002850
Dan Sinclair1770c022016-03-14 14:14:16 -04002851void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002852 if (pArguments->GetLength() != 0) {
2853 ThrowParamCountMismatchException(L"execInitialize");
2854 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002855 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002856
2857 CXFA_WidgetData* pWidgetData = GetWidgetData();
2858 if (!pWidgetData) {
2859 pArguments->GetReturnValue()->SetBoolean(false);
2860 return;
2861 }
2862 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002863}
dsinclair5b36f0a2016-07-19 10:56:23 -07002864
Dan Sinclair1770c022016-03-14 14:14:16 -04002865void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2866 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002867 if (argc <= 0 || argc >= 4) {
2868 ThrowParamCountMismatchException(L"createNode");
2869 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002870 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002871
2872 CFX_WideString strName;
2873 CFX_WideString strNameSpace;
2874 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
2875 CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
2876 if (argc > 1) {
2877 CFX_ByteString bsName = pArguments->GetUTF8String(1);
2878 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
2879 if (argc == 3) {
2880 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
2881 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
2882 }
2883 }
2884
2885 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2886 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
2887 if (!pNewNode) {
2888 pArguments->GetReturnValue()->SetNull();
2889 return;
2890 }
2891
2892 if (strName.IsEmpty()) {
2893 pArguments->GetReturnValue()->Assign(
2894 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2895 return;
2896 }
2897
2898 if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2899 XFA_XDPPACKET_UNKNOWN)) {
2900 ThrowMissingPropertyException(strTagName, L"name");
2901 return;
2902 }
2903
2904 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
2905 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets)
2906 pNewNode->CreateXMLMappingNode();
2907
2908 pArguments->GetReturnValue()->Assign(
2909 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002910}
dsinclair5b36f0a2016-07-19 10:56:23 -07002911
Dan Sinclair1770c022016-03-14 14:14:16 -04002912void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002913 if (pArguments->GetLength() != 1) {
2914 ThrowParamCountMismatchException(L"recalculate");
2915 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002916 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002917 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002918}
dsinclair5b36f0a2016-07-19 10:56:23 -07002919
Dan Sinclair1770c022016-03-14 14:14:16 -04002920void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002921 if (pArguments->GetLength() != 0) {
2922 ThrowParamCountMismatchException(L"execCalculate");
2923 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002924 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002925
2926 CXFA_WidgetData* pWidgetData = GetWidgetData();
2927 if (!pWidgetData) {
2928 pArguments->GetReturnValue()->SetBoolean(false);
2929 return;
2930 }
2931 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002932}
dsinclair5b36f0a2016-07-19 10:56:23 -07002933
Dan Sinclair1770c022016-03-14 14:14:16 -04002934void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002935 if (pArguments->GetLength() != 0) {
2936 ThrowParamCountMismatchException(L"execValidate");
2937 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002938 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002939 CXFA_WidgetData* pWidgetData = GetWidgetData();
2940 if (!pWidgetData) {
2941 pArguments->GetReturnValue()->SetBoolean(false);
2942 return;
2943 }
2944 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002945}
dsinclair5b36f0a2016-07-19 10:56:23 -07002946
Dan Sinclair1770c022016-03-14 14:14:16 -04002947void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002948 if (pArguments->GetLength() != 0) {
2949 ThrowParamCountMismatchException(L"evaluate");
2950 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002951 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002952
2953 CXFA_WidgetData* pWidgetData = GetWidgetData();
2954 if (!pWidgetData) {
2955 pArguments->GetReturnValue()->SetBoolean(false);
2956 return;
2957 }
2958 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002959}
dsinclair5b36f0a2016-07-19 10:56:23 -07002960
dsinclair12a6b0c2016-05-26 11:14:08 -07002961void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002962 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002963 XFA_ATTRIBUTE eAttribute) {
2964 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002965 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002966 return;
2967 }
2968 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002969 pValue->SetInteger(nodeOccur.GetMax());
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_Min(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.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04002981}
tsepezaadedf92016-05-12 10:08:06 -07002982
dsinclair12a6b0c2016-05-26 11:14:08 -07002983void CXFA_Node::Script_InstanceManager_Count(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) {
dsinclairf27aeec2016-06-07 19:36:18 -07002987 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002988 InstanceManager_SetInstances(iDesired);
2989 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07002990 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04002991 }
2992}
dsinclair5b36f0a2016-07-19 10:56:23 -07002993
Dan Sinclair1770c022016-03-14 14:14:16 -04002994void CXFA_Node::Script_InstanceManager_MoveInstance(
2995 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002996 if (pArguments->GetLength() != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07002997 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04002998 return;
2999 }
3000 int32_t iFrom = pArguments->GetInt32(0);
3001 int32_t iTo = pArguments->GetInt32(1);
3002 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003003 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003004 if (!pNotify) {
3005 return;
3006 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003007 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003008 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003009 pNotify->RunSubformIndexChange(pToInstance);
3010 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003011 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003012 if (pFromInstance &&
3013 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003014 pNotify->RunSubformIndexChange(pFromInstance);
3015 }
3016}
dsinclair5b36f0a2016-07-19 10:56:23 -07003017
Dan Sinclair1770c022016-03-14 14:14:16 -04003018void CXFA_Node::Script_InstanceManager_RemoveInstance(
3019 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003020 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003021 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003022 return;
3023 }
3024 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003025 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003026 if (iIndex < 0 || iIndex >= iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003027 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003028 return;
3029 }
3030 CXFA_Occur nodeOccur(GetOccurNode());
3031 int32_t iMin = nodeOccur.GetMin();
3032 if (iCount - 1 < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003033 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003034 return;
3035 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003036 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3037 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003038 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003039 if (pNotify) {
3040 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003041 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003042 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003043 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003044 pNotify->RunSubformIndexChange(pSubformInstance);
3045 }
3046 }
3047 }
3048 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3049 if (!pLayoutPro) {
3050 return;
3051 }
3052 pLayoutPro->AddChangedContainer(
3053 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3054}
dsinclair5b36f0a2016-07-19 10:56:23 -07003055
Dan Sinclair1770c022016-03-14 14:14:16 -04003056void CXFA_Node::Script_InstanceManager_SetInstances(
3057 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003058 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003059 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003060 return;
3061 }
3062 int32_t iDesired = pArguments->GetInt32(0);
3063 InstanceManager_SetInstances(iDesired);
3064}
dsinclair5b36f0a2016-07-19 10:56:23 -07003065
Dan Sinclair1770c022016-03-14 14:14:16 -04003066void CXFA_Node::Script_InstanceManager_AddInstance(
3067 CFXJSE_Arguments* pArguments) {
3068 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003069 if (argc != 0 && argc != 1) {
3070 ThrowParamCountMismatchException(L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003071 return;
3072 }
tsepezd19e9122016-11-02 15:43:18 -07003073 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003074 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003075 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003076 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003077 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003078 CXFA_Occur nodeOccur(GetOccurNode());
3079 int32_t iMax = nodeOccur.GetMax();
3080 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003081 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003082 return;
3083 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003084 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003085 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003086 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003087 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003088 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003089 if (!pNotify) {
3090 return;
3091 }
3092 pNotify->RunNodeInitialize(pNewInstance);
3093 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3094 if (!pLayoutPro) {
3095 return;
3096 }
3097 pLayoutPro->AddChangedContainer(
3098 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3099}
dsinclair5b36f0a2016-07-19 10:56:23 -07003100
Dan Sinclair1770c022016-03-14 14:14:16 -04003101void CXFA_Node::Script_InstanceManager_InsertInstance(
3102 CFXJSE_Arguments* pArguments) {
3103 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003104 if (argc != 1 && argc != 2) {
3105 ThrowParamCountMismatchException(L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003106 return;
3107 }
3108 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003109 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003110 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003111 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003112 }
3113 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003114 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003115 if (iIndex < 0 || iIndex > iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003116 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003117 return;
3118 }
3119 int32_t iMax = nodeOccur.GetMax();
3120 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003121 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003122 return;
3123 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003124 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003125 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003126 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003127 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003128 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003129 if (!pNotify) {
3130 return;
3131 }
3132 pNotify->RunNodeInitialize(pNewInstance);
3133 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3134 if (!pLayoutPro) {
3135 return;
3136 }
3137 pLayoutPro->AddChangedContainer(
3138 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3139}
dsinclair5b36f0a2016-07-19 10:56:23 -07003140
Dan Sinclair1770c022016-03-14 14:14:16 -04003141int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3142 CXFA_Occur nodeOccur(GetOccurNode());
3143 int32_t iMax = nodeOccur.GetMax();
3144 int32_t iMin = nodeOccur.GetMin();
3145 if (iDesired < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003146 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003147 return 1;
3148 }
3149 if ((iMax >= 0) && (iDesired > iMax)) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003150 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003151 return 2;
3152 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003153 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003154 if (iDesired == iCount) {
3155 return 0;
3156 }
3157 if (iDesired < iCount) {
3158 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003159 CFX_WideString wsInstanceName =
3160 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3161 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003162 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003163 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003164 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003165 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003166 while (iCount > iDesired) {
3167 CXFA_Node* pRemoveInstance =
3168 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003169 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3170 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003171 continue;
3172 }
dsinclair070fcdf2016-06-22 22:04:54 -07003173 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003174 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003175 break;
3176 }
3177 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003178 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003179 iCount--;
3180 }
3181 }
3182 } else if (iDesired > iCount) {
3183 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003184 CXFA_Node* pNewInstance = CreateInstance(this, true);
3185 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003186 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003187 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003188 if (!pNotify) {
3189 return 0;
3190 }
3191 pNotify->RunNodeInitialize(pNewInstance);
3192 }
3193 }
3194 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3195 if (pLayoutPro) {
3196 pLayoutPro->AddChangedContainer(
3197 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3198 }
3199 return 0;
3200}
dsinclair5b36f0a2016-07-19 10:56:23 -07003201
Dan Sinclair1770c022016-03-14 14:14:16 -04003202int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003203 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003204 if (iFrom > iCount || iTo > iCount - 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003205 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003206 return 1;
3207 }
3208 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3209 return 0;
3210 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003211 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003212 RemoveItem(this, pMoveInstance, false);
3213 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003214 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3215 if (pLayoutPro) {
3216 pLayoutPro->AddChangedContainer(
3217 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3218 }
3219 return 0;
3220}
dsinclair5b36f0a2016-07-19 10:56:23 -07003221
dsinclair12a6b0c2016-05-26 11:14:08 -07003222void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003223 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003224 XFA_ATTRIBUTE eAttribute) {
3225 CXFA_Occur occur(this);
3226 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003227 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003228 occur.SetMax(iMax);
3229 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003230 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003231 }
3232}
dsinclair5b36f0a2016-07-19 10:56:23 -07003233
dsinclair12a6b0c2016-05-26 11:14:08 -07003234void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003235 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003236 XFA_ATTRIBUTE eAttribute) {
3237 CXFA_Occur occur(this);
3238 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003239 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003240 occur.SetMin(iMin);
3241 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003242 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003243 }
3244}
dsinclair5b36f0a2016-07-19 10:56:23 -07003245
Dan Sinclair1770c022016-03-14 14:14:16 -04003246void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3247 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003248 if (argc != 0 && argc != 1) {
3249 ThrowParamCountMismatchException(L"metadata");
3250 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003251 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003252 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003253}
dsinclair5b36f0a2016-07-19 10:56:23 -07003254
Dan Sinclair1770c022016-03-14 14:14:16 -04003255void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003256 if (pArguments->GetLength() != 1) {
3257 ThrowParamCountMismatchException(L"formNodes");
3258 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003259 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003260
3261 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3262 if (!pDataNode) {
3263 ThrowArgumentMismatchException();
3264 return;
3265 }
3266
Tom Sepezf8a94392017-03-14 12:13:22 -07003267 std::vector<CXFA_Node*> formItems;
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003268 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3269 pFormNodes->SetArrayNodeList(formItems);
3270 pArguments->GetReturnValue()->SetObject(
3271 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003272}
dsinclair5b36f0a2016-07-19 10:56:23 -07003273
Dan Sinclair1770c022016-03-14 14:14:16 -04003274void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003275 if (pArguments->GetLength() != 0) {
3276 ThrowParamCountMismatchException(L"remerge");
3277 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003278 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003279
3280 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003281}
dsinclair5b36f0a2016-07-19 10:56:23 -07003282
Dan Sinclair1770c022016-03-14 14:14:16 -04003283void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003284 if (pArguments->GetLength() != 0) {
3285 ThrowParamCountMismatchException(L"execInitialize");
3286 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003287 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003288
3289 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3290 if (!pNotify)
3291 return;
3292
3293 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04003294}
dsinclair5b36f0a2016-07-19 10:56:23 -07003295
Dan Sinclair1770c022016-03-14 14:14:16 -04003296void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3297 CXFA_EventParam* pEventParam =
3298 m_pDocument->GetScriptContext()->GetEventParam();
3299 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3300 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3301 return;
3302 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003303 if (pArguments->GetLength() != 1) {
3304 ThrowParamCountMismatchException(L"recalculate");
3305 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003306 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003307
3308 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3309 if (!pNotify)
3310 return;
3311 if (pArguments->GetInt32(0) != 0)
3312 return;
3313
3314 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3315 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3316 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003317}
dsinclair5b36f0a2016-07-19 10:56:23 -07003318
Dan Sinclair1770c022016-03-14 14:14:16 -04003319void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003320 if (pArguments->GetLength() != 0) {
3321 ThrowParamCountMismatchException(L"execCalculate");
3322 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003323 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003324
3325 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3326 if (!pNotify)
3327 return;
3328
3329 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04003330}
dsinclair5b36f0a2016-07-19 10:56:23 -07003331
Dan Sinclair1770c022016-03-14 14:14:16 -04003332void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003333 if (pArguments->GetLength() != 0) {
3334 ThrowParamCountMismatchException(L"execValidate");
3335 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003336 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003337
3338 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3339 if (!pNotify) {
3340 pArguments->GetReturnValue()->SetBoolean(false);
3341 return;
3342 }
3343
3344 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3345 pArguments->GetReturnValue()->SetBoolean(
3346 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003347}
dsinclair5b36f0a2016-07-19 10:56:23 -07003348
dsinclair12a6b0c2016-05-26 11:14:08 -07003349void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003350 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003351 XFA_ATTRIBUTE eAttribute) {
3352 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003353 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003354 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003355 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003356 CFX_WideString wsChecksum;
3357 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
Tom Sepezf0b65542017-02-13 10:26:01 -08003358 pValue->SetString(wsChecksum.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003359}
dsinclair5b36f0a2016-07-19 10:56:23 -07003360
Dan Sinclair1770c022016-03-14 14:14:16 -04003361void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003362 if (pArguments->GetLength() != 1) {
3363 ThrowParamCountMismatchException(L"getAttribute");
3364 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003365 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003366 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3367 CFX_WideString wsAttributeValue;
3368 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3369 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003370 wsAttributeValue = static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3371 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003372 }
3373 pArguments->GetReturnValue()->SetString(
Tom Sepezf0b65542017-02-13 10:26:01 -08003374 wsAttributeValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003375}
dsinclair5b36f0a2016-07-19 10:56:23 -07003376
Dan Sinclair1770c022016-03-14 14:14:16 -04003377void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003378 if (pArguments->GetLength() != 2) {
3379 ThrowParamCountMismatchException(L"setAttribute");
3380 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003381 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003382 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3383 CFX_ByteString bsName = pArguments->GetUTF8String(1);
3384 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3385 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3386 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(
3387 CFX_WideString::FromUTF8(bsName.AsStringC()),
3388 CFX_WideString::FromUTF8(bsValue.AsStringC()));
3389 }
3390 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003391}
dsinclair5b36f0a2016-07-19 10:56:23 -07003392
Dan Sinclair1770c022016-03-14 14:14:16 -04003393void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003394 if (pArguments->GetLength() != 1) {
3395 ThrowParamCountMismatchException(L"removeAttribute");
3396 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003397 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003398
3399 CFX_ByteString bsName = pArguments->GetUTF8String(0);
3400 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
3401 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3402 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3403 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
3404 if (pXMLElement->HasAttribute(wsName.c_str())) {
3405 pXMLElement->RemoveAttribute(wsName.c_str());
3406 }
3407 }
3408 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003409}
dsinclair5b36f0a2016-07-19 10:56:23 -07003410
dsinclair12a6b0c2016-05-26 11:14:08 -07003411void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003412 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003413 XFA_ATTRIBUTE eAttribute) {
3414 if (bSetting) {
dsinclairae95f762016-03-29 16:58:29 -07003415 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003416 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003417 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003418 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003419 }
3420 } else {
3421 CFX_WideString wsTextData;
dsinclairae95f762016-03-29 16:58:29 -07003422 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003423 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003424 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003425 wsTextData = pXMLElement->GetTextData();
Dan Sinclair1770c022016-03-14 14:14:16 -04003426 }
Tom Sepezf0b65542017-02-13 10:26:01 -08003427 pValue->SetString(wsTextData.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003428 }
3429}
dsinclair5b36f0a2016-07-19 10:56:23 -07003430
Dan Sinclair1770c022016-03-14 14:14:16 -04003431void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003432 if (pArguments->GetLength() != 0)
3433 ThrowParamCountMismatchException(L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003434}
dsinclair5b36f0a2016-07-19 10:56:23 -07003435
Dan Sinclair1770c022016-03-14 14:14:16 -04003436void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003437 if (pArguments->GetLength() != 0)
3438 ThrowParamCountMismatchException(L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003439}
dsinclair5b36f0a2016-07-19 10:56:23 -07003440
Dan Sinclair1770c022016-03-14 14:14:16 -04003441void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003442 if (pArguments->GetLength() != 0)
3443 ThrowParamCountMismatchException(L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003444}
dsinclair5b36f0a2016-07-19 10:56:23 -07003445
Dan Sinclair1770c022016-03-14 14:14:16 -04003446void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003447 if (pArguments->GetLength() != 0)
3448 ThrowParamCountMismatchException(L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003449}
dsinclair5b36f0a2016-07-19 10:56:23 -07003450
Dan Sinclair1770c022016-03-14 14:14:16 -04003451void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003452 if (pArguments->GetLength() != 0)
3453 ThrowParamCountMismatchException(L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003454}
dsinclair5b36f0a2016-07-19 10:56:23 -07003455
Dan Sinclair1770c022016-03-14 14:14:16 -04003456void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003457 if (pArguments->GetLength() != 0)
3458 ThrowParamCountMismatchException(L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003459}
dsinclair5b36f0a2016-07-19 10:56:23 -07003460
Dan Sinclair1770c022016-03-14 14:14:16 -04003461void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003462 if (pArguments->GetLength() != 0)
3463 ThrowParamCountMismatchException(L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003464}
dsinclair5b36f0a2016-07-19 10:56:23 -07003465
Dan Sinclair1770c022016-03-14 14:14:16 -04003466void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003467 if (pArguments->GetLength() != 0)
3468 ThrowParamCountMismatchException(L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003469}
dsinclair5b36f0a2016-07-19 10:56:23 -07003470
Dan Sinclair1770c022016-03-14 14:14:16 -04003471void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003472 if (pArguments->GetLength() != 0)
3473 ThrowParamCountMismatchException(L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003474}
dsinclair5b36f0a2016-07-19 10:56:23 -07003475
Dan Sinclair1770c022016-03-14 14:14:16 -04003476void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003477 if (pArguments->GetLength() != 0)
3478 ThrowParamCountMismatchException(L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003479}
dsinclair5b36f0a2016-07-19 10:56:23 -07003480
Dan Sinclair1770c022016-03-14 14:14:16 -04003481void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003482 if (pArguments->GetLength() != 0)
3483 ThrowParamCountMismatchException(L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003484}
dsinclair5b36f0a2016-07-19 10:56:23 -07003485
Dan Sinclair1770c022016-03-14 14:14:16 -04003486void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003487 if (pArguments->GetLength() != 0)
3488 ThrowParamCountMismatchException(L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003489}
dsinclair5b36f0a2016-07-19 10:56:23 -07003490
Dan Sinclair1770c022016-03-14 14:14:16 -04003491void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003492 if (pArguments->GetLength() != 0)
3493 ThrowParamCountMismatchException(L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003494}
dsinclair5b36f0a2016-07-19 10:56:23 -07003495
Dan Sinclair1770c022016-03-14 14:14:16 -04003496void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003497 if (pArguments->GetLength() != 0)
3498 ThrowParamCountMismatchException(L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003499}
dsinclair5b36f0a2016-07-19 10:56:23 -07003500
Dan Sinclair1770c022016-03-14 14:14:16 -04003501void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003502 if (pArguments->GetLength() != 0)
3503 ThrowParamCountMismatchException(L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003504}
dsinclair5b36f0a2016-07-19 10:56:23 -07003505
Dan Sinclair1770c022016-03-14 14:14:16 -04003506void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003507 if (pArguments->GetLength() != 0)
3508 ThrowParamCountMismatchException(L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003509}
dsinclair5b36f0a2016-07-19 10:56:23 -07003510
Dan Sinclair1770c022016-03-14 14:14:16 -04003511void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003512 if (pArguments->GetLength() != 0)
3513 ThrowParamCountMismatchException(L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003514}
dsinclair5b36f0a2016-07-19 10:56:23 -07003515
dsinclair12a6b0c2016-05-26 11:14:08 -07003516void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003517 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003518 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003519
dsinclair12a6b0c2016-05-26 11:14:08 -07003520void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003521 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003522 XFA_ATTRIBUTE eAttribute) {
3523 if (!bSetting) {
3524 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003525 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003526 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003527 }
3528}
dsinclair5b36f0a2016-07-19 10:56:23 -07003529
dsinclair12a6b0c2016-05-26 11:14:08 -07003530void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003531 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003532 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003533
dsinclair12a6b0c2016-05-26 11:14:08 -07003534void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003535 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003536 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003537
dsinclair12a6b0c2016-05-26 11:14:08 -07003538void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003539 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003540 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003541
dsinclair12a6b0c2016-05-26 11:14:08 -07003542void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003543 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003544 XFA_ATTRIBUTE eAttribute) {
3545 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003546 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003547 return;
3548 }
dan sinclair65c7c232017-02-02 14:05:30 -08003549 pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003550}
dsinclair5b36f0a2016-07-19 10:56:23 -07003551
dsinclair12a6b0c2016-05-26 11:14:08 -07003552void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003553 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003554 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003555
tsepezd19e9122016-11-02 15:43:18 -07003556bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003557 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003558 return HasMapModuleKey(pKey, bCanInherit);
3559}
dsinclair5b36f0a2016-07-19 10:56:23 -07003560
tsepezd19e9122016-11-02 15:43:18 -07003561bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3562 const CFX_WideStringC& wsValue,
3563 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003564 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003565 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003566 return false;
weili44f8faf2016-06-01 14:03:56 -07003567
Dan Sinclair1770c022016-03-14 14:14:16 -04003568 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3569 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3570 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003571 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003572 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3573 }
3574 switch (eType) {
3575 case XFA_ATTRIBUTETYPE_Enum: {
3576 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3577 return SetEnum(pAttr->eName,
3578 pEnum ? pEnum->eName
3579 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3580 bNotify);
3581 } break;
3582 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003583 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003584 case XFA_ATTRIBUTETYPE_Boolean:
dan sinclair65c7c232017-02-02 14:05:30 -08003585 return SetBoolean(pAttr->eName, wsValue != L"0", bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003586 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003587 return SetInteger(pAttr->eName,
3588 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3589 wsValue.GetLength(), nullptr)),
3590 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003591 case XFA_ATTRIBUTETYPE_Measure:
3592 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3593 default:
3594 break;
3595 }
tsepezd19e9122016-11-02 15:43:18 -07003596 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003597}
dsinclair5b36f0a2016-07-19 10:56:23 -07003598
tsepezd19e9122016-11-02 15:43:18 -07003599bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3600 CFX_WideString& wsValue,
3601 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003602 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003603 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003604 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003605 }
3606 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3607 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3608 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003609 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003610 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3611 }
3612 switch (eType) {
3613 case XFA_ATTRIBUTETYPE_Enum: {
3614 XFA_ATTRIBUTEENUM eValue;
3615 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003616 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003617 }
dsinclair9eb0db12016-07-21 12:01:39 -07003618 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003619 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003620 } break;
3621 case XFA_ATTRIBUTETYPE_Cdata: {
3622 CFX_WideStringC wsValueC;
3623 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003624 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003625 }
3626 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003627 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003628 } break;
3629 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003630 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003631 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003632 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003633 }
dan sinclair65c7c232017-02-02 14:05:30 -08003634 wsValue = bValue ? L"1" : L"0";
tsepezd19e9122016-11-02 15:43:18 -07003635 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003636 } break;
3637 case XFA_ATTRIBUTETYPE_Integer: {
3638 int32_t iValue;
3639 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003640 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003641 }
3642 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003643 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003644 } break;
3645 case XFA_ATTRIBUTETYPE_Measure: {
3646 CXFA_Measurement mValue;
3647 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003648 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003649 }
3650 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003651 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003652 } break;
3653 default:
3654 break;
3655 }
tsepezd19e9122016-11-02 15:43:18 -07003656 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003657}
dsinclair5b36f0a2016-07-19 10:56:23 -07003658
tsepezd19e9122016-11-02 15:43:18 -07003659bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3660 const CFX_WideStringC& wsValue,
3661 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003662 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3663 if (pAttributeInfo) {
3664 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3665 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003666 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003667 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003668 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003669}
dsinclair5b36f0a2016-07-19 10:56:23 -07003670
tsepezd19e9122016-11-02 15:43:18 -07003671bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3672 CFX_WideString& wsValue,
3673 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003674 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3675 if (pAttributeInfo) {
3676 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3677 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003678 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003679 CFX_WideStringC wsValueC;
3680 if (GetMapModuleString(pKey, wsValueC)) {
3681 wsValue = wsValueC;
3682 }
tsepezd19e9122016-11-02 15:43:18 -07003683 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003684}
dsinclair5b36f0a2016-07-19 10:56:23 -07003685
tsepezd19e9122016-11-02 15:43:18 -07003686bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003687 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003688 RemoveMapModuleKey(pKey);
tsepezd19e9122016-11-02 15:43:18 -07003689 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003690}
dsinclair5b36f0a2016-07-19 10:56:23 -07003691
tsepezd19e9122016-11-02 15:43:18 -07003692bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3693 bool& bValue,
3694 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003695 void* pValue = nullptr;
3696 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003697 return false;
tsepez478ed622016-10-27 14:32:33 -07003698 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003699 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003700}
dsinclair5b36f0a2016-07-19 10:56:23 -07003701
tsepezd19e9122016-11-02 15:43:18 -07003702bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3703 int32_t& iValue,
3704 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003705 void* pValue = nullptr;
3706 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003707 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003708 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003709 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003710}
dsinclair5b36f0a2016-07-19 10:56:23 -07003711
tsepezd19e9122016-11-02 15:43:18 -07003712bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3713 XFA_ATTRIBUTEENUM& eValue,
3714 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003715 void* pValue = nullptr;
3716 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003717 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003718 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003719 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003720}
thestigb1a59592016-04-14 18:29:56 -07003721
tsepezd19e9122016-11-02 15:43:18 -07003722bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3723 CXFA_Measurement mValue,
3724 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003725 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003726 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003727 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003728 OnChanged(eAttr, bNotify, false);
3729 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003730}
thestigb1a59592016-04-14 18:29:56 -07003731
tsepezd19e9122016-11-02 15:43:18 -07003732bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3733 CXFA_Measurement& mValue,
3734 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003735 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003736 void* pValue;
3737 int32_t iBytes;
3738 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003739 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003740 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003741 }
3742 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003743 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003744 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003745 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003746 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003747 }
tsepezd19e9122016-11-02 15:43:18 -07003748 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003749}
3750
3751CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3752 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003753 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003754}
3755
tsepezd19e9122016-11-02 15:43:18 -07003756bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3757 const CFX_WideString& wsValue,
3758 bool bNotify,
3759 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003760 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003761 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003762 if (eAttr == XFA_ATTRIBUTE_Value) {
3763 CFX_WideString* pClone = new CFX_WideString(wsValue);
3764 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3765 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003766 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003767 if (eAttr == XFA_ATTRIBUTE_Name)
3768 UpdateNameHash();
3769 }
thestigb1a59592016-04-14 18:29:56 -07003770 OnChanged(eAttr, bNotify, bScriptModify);
3771
3772 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3773 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003774 return true;
thestigb1a59592016-04-14 18:29:56 -07003775 }
3776
dsinclair070fcdf2016-06-22 22:04:54 -07003777 if (eAttr == XFA_ATTRIBUTE_Name &&
3778 (m_elementType == XFA_Element::DataValue ||
3779 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003780 return true;
thestigb1a59592016-04-14 18:29:56 -07003781 }
3782
3783 if (eAttr == XFA_ATTRIBUTE_Value) {
3784 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3785 switch (eXMLType) {
3786 case FDE_XMLNODE_Element:
3787 if (IsAttributeInXML()) {
3788 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003789 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3790 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003791 } else {
tsepezd19e9122016-11-02 15:43:18 -07003792 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003793 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3794 for (CXFA_Node* pChildDataNode =
3795 GetNodeItem(XFA_NODEITEM_FirstChild);
3796 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3797 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003798 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003799 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003800 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003801 }
3802 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003803 }
thestigb1a59592016-04-14 18:29:56 -07003804 if (bDeleteChildren) {
3805 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3806 }
3807 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3808 }
3809 break;
3810 case FDE_XMLNODE_Text:
3811 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3812 break;
3813 default:
dsinclair43854a52016-04-27 12:26:00 -07003814 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003815 }
tsepezd19e9122016-11-02 15:43:18 -07003816 return true;
thestigb1a59592016-04-14 18:29:56 -07003817 }
3818
3819 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3820 if (pInfo) {
dsinclair43854a52016-04-27 12:26:00 -07003821 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003822 CFX_WideString wsAttrName = pInfo->pName;
3823 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
dan sinclair65c7c232017-02-02 14:05:30 -08003824 wsAttrName = L"xfa:" + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003825 }
thestigb1a59592016-04-14 18:29:56 -07003826 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003827 }
tsepezd19e9122016-11-02 15:43:18 -07003828 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003829}
thestigb1a59592016-04-14 18:29:56 -07003830
tsepezd19e9122016-11-02 15:43:18 -07003831bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3832 const CFX_WideString& wsXMLValue,
3833 bool bNotify,
3834 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003835 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003836 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003837 CFX_WideString* pClone = new CFX_WideString(wsValue);
3838 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003839 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003840 if (IsNeedSavingXMLNode()) {
3841 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3842 switch (eXMLType) {
3843 case FDE_XMLNODE_Element:
3844 if (IsAttributeInXML()) {
dsinclairae95f762016-03-29 16:58:29 -07003845 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003846 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3847 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003848 } else {
tsepezd19e9122016-11-02 15:43:18 -07003849 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003850 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3851 for (CXFA_Node* pChildDataNode =
3852 GetNodeItem(XFA_NODEITEM_FirstChild);
3853 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3854 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003855 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003856 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003857 break;
3858 }
3859 }
3860 }
3861 if (bDeleteChildren) {
dsinclairae95f762016-03-29 16:58:29 -07003862 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003863 }
dsinclairae95f762016-03-29 16:58:29 -07003864 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003865 }
3866 break;
3867 case FDE_XMLNODE_Text:
dsinclairae95f762016-03-29 16:58:29 -07003868 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003869 break;
3870 default:
dsinclair43854a52016-04-27 12:26:00 -07003871 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003872 }
3873 }
tsepezd19e9122016-11-02 15:43:18 -07003874 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003875}
dsinclair5b36f0a2016-07-19 10:56:23 -07003876
tsepezd19e9122016-11-02 15:43:18 -07003877bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3878 CFX_WideString& wsValue,
3879 bool bUseDefault,
3880 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003881 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003882 if (eAttr == XFA_ATTRIBUTE_Value) {
3883 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3884 if (pStr) {
3885 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07003886 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003887 }
3888 } else {
3889 CFX_WideStringC wsValueC;
3890 if (GetMapModuleString(pKey, wsValueC)) {
3891 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003892 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003893 }
3894 }
3895 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003896 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003897 }
weili44f8faf2016-06-01 14:03:56 -07003898 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003899 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003900 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003901 wsValue = (const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003902 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003903 }
tsepezd19e9122016-11-02 15:43:18 -07003904 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003905}
dsinclair5b36f0a2016-07-19 10:56:23 -07003906
tsepezd19e9122016-11-02 15:43:18 -07003907bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3908 CFX_WideStringC& wsValue,
3909 bool bUseDefault,
3910 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003911 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003912 if (eAttr == XFA_ATTRIBUTE_Value) {
3913 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3914 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07003915 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07003916 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003917 }
3918 } else {
3919 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003920 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003921 }
3922 }
3923 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003924 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003925 }
weili44f8faf2016-06-01 14:03:56 -07003926 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003927 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003928 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003929 wsValue = (CFX_WideStringC)(const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003930 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003931 }
tsepezd19e9122016-11-02 15:43:18 -07003932 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003933}
dsinclair5b36f0a2016-07-19 10:56:23 -07003934
tsepezd19e9122016-11-02 15:43:18 -07003935bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
3936 void* pData,
3937 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003938 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003939 return SetUserData(pKey, pData, pCallbackInfo);
3940}
dsinclair5b36f0a2016-07-19 10:56:23 -07003941
tsepezd19e9122016-11-02 15:43:18 -07003942bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003943 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003944 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07003945 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04003946}
dsinclair5b36f0a2016-07-19 10:56:23 -07003947
tsepezd19e9122016-11-02 15:43:18 -07003948bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
3949 XFA_ATTRIBUTETYPE eType,
3950 void* pValue,
3951 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003952 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003953 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003954 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07003955 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003956 if (IsNeedSavingXMLNode()) {
dsinclair43854a52016-04-27 12:26:00 -07003957 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04003958 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3959 if (pInfo) {
3960 switch (eType) {
3961 case XFA_ATTRIBUTETYPE_Enum:
dsinclairae95f762016-03-29 16:58:29 -07003962 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04003963 ->SetString(
3964 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07003965 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04003966 ->pName);
3967 break;
3968 case XFA_ATTRIBUTETYPE_Boolean:
dsinclairae95f762016-03-29 16:58:29 -07003969 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003970 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04003971 break;
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003972 case XFA_ATTRIBUTETYPE_Integer: {
3973 CFX_WideString wsValue;
3974 wsValue.Format(
3975 L"%d", static_cast<int32_t>(reinterpret_cast<uintptr_t>(pValue)));
dsinclairae95f762016-03-29 16:58:29 -07003976 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003977 ->SetString(pInfo->pName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003978 break;
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003979 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003980 default:
dsinclair43854a52016-04-27 12:26:00 -07003981 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003982 }
3983 }
3984 }
tsepezd19e9122016-11-02 15:43:18 -07003985 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003986}
dsinclair5b36f0a2016-07-19 10:56:23 -07003987
tsepezd19e9122016-11-02 15:43:18 -07003988bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
3989 XFA_ATTRIBUTETYPE eType,
3990 bool bUseDefault,
3991 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003992 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003993 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003994 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003995 }
3996 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003997 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003998 }
dsinclair070fcdf2016-06-22 22:04:54 -07003999 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004000 m_ePacket);
4001}
dsinclair5b36f0a2016-07-19 10:56:23 -07004002
tsepezd19e9122016-11-02 15:43:18 -07004003bool CXFA_Node::SetUserData(void* pKey,
4004 void* pData,
4005 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004006 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4007 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004008 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004009}
dsinclair5b36f0a2016-07-19 10:56:23 -07004010
tsepezd19e9122016-11-02 15:43:18 -07004011bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004012 int32_t iBytes = 0;
4013 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004014 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004015 }
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004016 return iBytes == sizeof(void*) && memcpy(&pData, pData, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004017}
dsinclair5b36f0a2016-07-19 10:56:23 -07004018
tsepezd19e9122016-11-02 15:43:18 -07004019bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4020 const CFX_WideString& wsXMLValue,
4021 bool bNotify,
4022 bool bScriptModify,
4023 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004024 CXFA_Node* pNode = nullptr;
4025 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004026 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004027 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004028 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004029 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004030 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004031 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004032 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004033 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004034 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004035 CXFA_Node* pBind = GetBindData();
4036 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004037 std::vector<CFX_WideString> wsSaveTextArray;
Tom Sepezf8a94392017-03-14 12:13:22 -07004038 size_t iSize = 0;
Dan Sinclair1770c022016-03-14 14:14:16 -04004039 if (!wsContent.IsEmpty()) {
4040 int32_t iStart = 0;
4041 int32_t iLength = wsContent.GetLength();
4042 int32_t iEnd = wsContent.Find(L'\n', iStart);
4043 iEnd = (iEnd == -1) ? iLength : iEnd;
4044 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004045 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004046 iStart = iEnd + 1;
4047 if (iStart >= iLength) {
4048 break;
4049 }
4050 iEnd = wsContent.Find(L'\n', iStart);
4051 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004052 wsSaveTextArray.push_back(
4053 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004054 }
4055 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004056 iSize = wsSaveTextArray.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004057 }
4058 if (iSize == 0) {
4059 while (CXFA_Node* pChildNode =
4060 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4061 pBind->RemoveChild(pChildNode);
4062 }
4063 } else {
Tom Sepezf8a94392017-03-14 12:13:22 -07004064 std::vector<CXFA_Node*> valueNodes = pBind->GetNodeList(
4065 XFA_NODEFILTER_Children, XFA_Element::DataValue);
4066 size_t iDatas = valueNodes.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004067 if (iDatas < iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004068 size_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004069 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004070 while (iAddNodes-- > 0) {
4071 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004072 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004073 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004074 pValueNodes->CreateXMLMappingNode();
4075 pBind->InsertChild(pValueNodes);
4076 }
weili44f8faf2016-06-01 14:03:56 -07004077 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004078 } else if (iDatas > iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004079 size_t iDelNodes = iDatas - iSize;
Dan Sinclair1770c022016-03-14 14:14:16 -04004080 while (iDelNodes-- > 0) {
4081 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4082 }
4083 }
4084 int32_t i = 0;
4085 for (CXFA_Node* pValueNode =
4086 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4087 pValueNode; pValueNode = pValueNode->GetNodeItem(
4088 XFA_NODEITEM_NextSibling)) {
4089 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004090 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004091 i++;
4092 }
4093 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004094 for (CXFA_Node* pArrayNode : pBind->GetBindItems()) {
4095 if (pArrayNode != this) {
4096 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4097 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004098 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004099 }
4100 }
4101 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004102 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004103 pNode = this;
4104 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004105 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004106 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004107 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004108 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004109 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004110 }
4111 pBindNode = GetBindData();
4112 if (pBindNode && bSyncData) {
4113 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004114 bScriptModify, false);
Tom Sepezf8a94392017-03-14 12:13:22 -07004115 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4116 if (pArrayNode != this) {
4117 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, true,
4118 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004119 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004120 }
4121 }
weili44f8faf2016-06-01 14:03:56 -07004122 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004123 break;
4124 }
dsinclairc5a8f212016-06-20 11:11:12 -07004125 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004126 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004127 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004128 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004129 if (wsContentType == L"text/html") {
4130 wsContentType = L"";
tsepez4c3debb2016-04-08 12:20:38 -07004131 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004132 }
4133 }
4134 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4135 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004136 pContentRawDataNode = CreateSamePacketNode(
dan sinclair65c7c232017-02-02 14:05:30 -08004137 (wsContentType == L"text/xml") ? XFA_Element::Sharpxml
4138 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004139 InsertChild(pContentRawDataNode);
4140 }
4141 return pContentRawDataNode->SetScriptContent(
4142 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4143 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004144 case XFA_ObjectType::NodeC:
4145 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004146 pNode = this;
4147 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004148 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004149 pNode = this;
4150 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4151 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4152 if (pParent) {
4153 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4154 }
dsinclair070fcdf2016-06-22 22:04:54 -07004155 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004156 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4157 if (pParent && pParent->IsContainerNode()) {
4158 pBindNode = pParent->GetBindData();
4159 if (pBindNode) {
4160 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004161 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004162 }
4163 }
4164 }
4165 }
4166 break;
4167 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004168 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004169 pNode = this;
4170 pBindNode = this;
4171 }
4172 break;
4173 }
4174 if (pNode) {
4175 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4176 if (pBindNode && bSyncData) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004177 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4178 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4179 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004180 }
4181 }
tsepezd19e9122016-11-02 15:43:18 -07004182 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004183 }
tsepezd19e9122016-11-02 15:43:18 -07004184 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004185}
dsinclair5b36f0a2016-07-19 10:56:23 -07004186
tsepezd19e9122016-11-02 15:43:18 -07004187bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4188 const CFX_WideString& wsXMLValue,
4189 bool bNotify,
4190 bool bScriptModify,
4191 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004192 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4193 bSyncData);
4194}
dsinclair5b36f0a2016-07-19 10:56:23 -07004195
tsepezd19e9122016-11-02 15:43:18 -07004196CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004197 CFX_WideString wsContent;
4198 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4199}
dsinclair5b36f0a2016-07-19 10:56:23 -07004200
Dan Sinclair1770c022016-03-14 14:14:16 -04004201CFX_WideString CXFA_Node::GetContent() {
4202 return GetScriptContent();
4203}
dsinclair5b36f0a2016-07-19 10:56:23 -07004204
tsepezd19e9122016-11-02 15:43:18 -07004205bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4206 bool bScriptModify,
4207 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004208 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004209 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004210 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004211 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004212 pNode = this;
4213 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004214 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004215 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004216 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004217 }
4218 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4219 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
dan sinclair65c7c232017-02-02 14:05:30 -08004220 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004221 }
4222 return pChildValue
4223 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004224 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004225 }
4226 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004227 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004228 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4229 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004230 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004231 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004232 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004233 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004234 if (wsContentType == L"text/html") {
dsinclair56a8b192016-06-21 14:15:25 -07004235 element = XFA_Element::SharpxHTML;
dan sinclair65c7c232017-02-02 14:05:30 -08004236 } else if (wsContentType == L"text/xml") {
dsinclair56a8b192016-06-21 14:15:25 -07004237 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004238 }
4239 }
4240 pContentRawDataNode = CreateSamePacketNode(element);
4241 InsertChild(pContentRawDataNode);
4242 }
4243 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4244 }
dsinclairc5a8f212016-06-20 11:11:12 -07004245 case XFA_ObjectType::NodeC:
4246 case XFA_ObjectType::NodeV:
4247 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004248 pNode = this;
4249 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004250 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004251 pNode = this;
4252 }
4253 break;
4254 }
4255 if (pNode) {
4256 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004257 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004258 if (pScriptContext) {
4259 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4260 }
4261 }
tsepezd19e9122016-11-02 15:43:18 -07004262 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004263 }
tsepezd19e9122016-11-02 15:43:18 -07004264 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004265}
dsinclair5b36f0a2016-07-19 10:56:23 -07004266
Dan Sinclair1770c022016-03-14 14:14:16 -04004267CXFA_Node* CXFA_Node::GetModelNode() {
4268 switch (GetPacketID()) {
4269 case XFA_XDPPACKET_XDP:
4270 return m_pDocument->GetRoot();
4271 case XFA_XDPPACKET_Config:
4272 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4273 case XFA_XDPPACKET_Template:
4274 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4275 case XFA_XDPPACKET_Form:
4276 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4277 case XFA_XDPPACKET_Datasets:
4278 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4279 case XFA_XDPPACKET_LocaleSet:
4280 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4281 case XFA_XDPPACKET_ConnectionSet:
4282 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4283 case XFA_XDPPACKET_SourceSet:
4284 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4285 case XFA_XDPPACKET_Xdc:
4286 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4287 default:
4288 return this;
4289 }
4290}
dsinclair5b36f0a2016-07-19 10:56:23 -07004291
tsepezd19e9122016-11-02 15:43:18 -07004292bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004293 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004294 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
dsinclairae95f762016-03-29 16:58:29 -07004295 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004296 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004297 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004298 }
Dan Sinclair5fa4e982017-04-05 11:48:21 -04004299 wsNamespace = static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI();
tsepezd19e9122016-11-02 15:43:18 -07004300 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004301 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
dsinclairae95f762016-03-29 16:58:29 -07004302 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004303 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004304 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004305 }
4306 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004307 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004308 }
dsinclair070fcdf2016-06-22 22:04:54 -07004309 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004310 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4311 return XFA_FDEExtension_ResolveNamespaceQualifier(
dsinclairae95f762016-03-29 16:58:29 -07004312 static_cast<CFDE_XMLElement*>(pXMLNode),
Dan Sinclair5fa4e982017-04-05 11:48:21 -04004313 GetCData(XFA_ATTRIBUTE_QualifiedName), &wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004314 }
Dan Sinclair5fa4e982017-04-05 11:48:21 -04004315 wsNamespace = static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI();
tsepezd19e9122016-11-02 15:43:18 -07004316 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004317 } else {
4318 CXFA_Node* pModelNode = GetModelNode();
4319 return pModelNode->TryNamespace(wsNamespace);
4320 }
4321}
dsinclair5b36f0a2016-07-19 10:56:23 -07004322
Dan Sinclair1770c022016-03-14 14:14:16 -04004323CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004324 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004325 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004326 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004327 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004328 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004329 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004330 if (!pProperty || index >= pProperty->uOccur)
4331 return nullptr;
4332
Dan Sinclair1770c022016-03-14 14:14:16 -04004333 CXFA_Node* pNode = m_pChild;
4334 int32_t iCount = 0;
4335 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004336 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004337 iCount++;
4338 if (iCount > index) {
4339 return pNode;
4340 }
4341 }
4342 }
weili44f8faf2016-06-01 14:03:56 -07004343 if (!bCreateProperty)
4344 return nullptr;
4345
Dan Sinclair1770c022016-03-14 14:14:16 -04004346 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4347 pNode = m_pChild;
4348 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4349 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004350 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004351 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4352 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004353 }
4354 }
dsinclaira1b07722016-07-11 08:20:58 -07004355
Dan Sinclair1770c022016-03-14 14:14:16 -04004356 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004357 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004358 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004359 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004360 if (!pNewNode)
4361 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004362 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004363 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004364 }
4365 return pNewNode;
4366}
dsinclair5b36f0a2016-07-19 10:56:23 -07004367
tsepezd19e9122016-11-02 15:43:18 -07004368int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004369 CXFA_Node* pNode = m_pChild;
4370 int32_t iCount = 0;
4371 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004372 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004373 if (bOnlyChild) {
4374 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004375 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004376 if (pProperty) {
4377 continue;
4378 }
4379 }
4380 iCount++;
4381 }
4382 }
4383 return iCount;
4384}
dsinclair5b36f0a2016-07-19 10:56:23 -07004385
Dan Sinclair1770c022016-03-14 14:14:16 -04004386CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004387 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004388 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004389 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004390 CXFA_Node* pNode = m_pChild;
4391 int32_t iCount = 0;
4392 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004393 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004394 if (bOnlyChild) {
4395 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004396 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004397 if (pProperty) {
4398 continue;
4399 }
4400 }
4401 iCount++;
4402 if (iCount > index) {
4403 return pNode;
4404 }
4405 }
4406 }
weili44f8faf2016-06-01 14:03:56 -07004407 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004408}
dsinclair5b36f0a2016-07-19 10:56:23 -07004409
Dan Sinclair1770c022016-03-14 14:14:16 -04004410int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4411 ASSERT(!pNode->m_pNext);
4412 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004413 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004414 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004415 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004416
weili44f8faf2016-06-01 14:03:56 -07004417 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004418 if (index > 0) {
4419 return -1;
4420 }
4421 pNode->m_pNext = m_pChild;
4422 m_pChild = pNode;
4423 index = 0;
4424 } else if (index < 0) {
4425 m_pLastChild->m_pNext = pNode;
4426 } else {
4427 CXFA_Node* pPrev = m_pChild;
4428 int32_t iCount = 0;
4429 while (++iCount != index && pPrev->m_pNext) {
4430 pPrev = pPrev->m_pNext;
4431 }
4432 if (index > 0 && index != iCount) {
4433 return -1;
4434 }
4435 pNode->m_pNext = pPrev->m_pNext;
4436 pPrev->m_pNext = pNode;
4437 index = iCount;
4438 }
weili44f8faf2016-06-01 14:03:56 -07004439 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004440 m_pLastChild = pNode;
4441 }
4442 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004443 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004444 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004445 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004446 if (pNotify)
4447 pNotify->OnChildAdded(this);
4448
Dan Sinclair1770c022016-03-14 14:14:16 -04004449 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004450 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004451 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004452 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004453 }
4454 return index;
4455}
weili6e1ae862016-05-04 18:25:27 -07004456
tsepezd19e9122016-11-02 15:43:18 -07004457bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004458 if (!pNode || pNode->m_pParent ||
4459 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004460 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004461 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004462 }
tsepezd19e9122016-11-02 15:43:18 -07004463 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004464 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004465 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004466
4467 int32_t nIndex = -1;
4468 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004469 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004470 pNode->m_pNext = m_pChild;
4471 m_pChild = pNode;
4472 nIndex = 0;
4473 } else if (!pBeforeNode) {
4474 pNode->m_pNext = m_pLastChild->m_pNext;
4475 m_pLastChild->m_pNext = pNode;
4476 } else {
4477 nIndex = 1;
4478 CXFA_Node* pPrev = m_pChild;
4479 while (pPrev->m_pNext != pBeforeNode) {
4480 pPrev = pPrev->m_pNext;
4481 nIndex++;
4482 }
4483 pNode->m_pNext = pPrev->m_pNext;
4484 pPrev->m_pNext = pNode;
4485 }
weili44f8faf2016-06-01 14:03:56 -07004486 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004487 m_pLastChild = pNode;
4488 }
4489 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004490 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004491 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004492 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004493 if (pNotify)
4494 pNotify->OnChildAdded(this);
4495
Dan Sinclair1770c022016-03-14 14:14:16 -04004496 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004497 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004498 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004499 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004500 }
tsepezd19e9122016-11-02 15:43:18 -07004501 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004502}
dsinclair5b36f0a2016-07-19 10:56:23 -07004503
Dan Sinclair1770c022016-03-14 14:14:16 -04004504CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4505 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004506 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004507 }
4508 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4509 pSibling = pSibling->m_pNext) {
4510 if (pSibling->m_pNext == this) {
4511 return pSibling;
4512 }
4513 }
weili44f8faf2016-06-01 14:03:56 -07004514 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004515}
dsinclair5b36f0a2016-07-19 10:56:23 -07004516
tsepezd19e9122016-11-02 15:43:18 -07004517bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004518 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004519 ASSERT(false);
4520 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004521 }
4522 if (m_pChild == pNode) {
4523 m_pChild = pNode->m_pNext;
4524 if (m_pLastChild == pNode) {
4525 m_pLastChild = pNode->m_pNext;
4526 }
weili44f8faf2016-06-01 14:03:56 -07004527 pNode->m_pNext = nullptr;
4528 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004529 } else {
4530 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4531 pPrev->m_pNext = pNode->m_pNext;
4532 if (m_pLastChild == pNode) {
4533 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
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 }
weili44f8faf2016-06-01 14:03:56 -07004538 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004539 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004540 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004541 m_pDocument->AddPurgeNode(pNode);
4542 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4543 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004544 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4545 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004546 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07004547 CFDE_XMLElement* pXMLElement =
4548 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004549 CFX_WideStringC wsAttributeName =
4550 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004551 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004552 }
4553 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004554 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -07004555 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004556 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4557 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004558 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004559 }
4560 pNode->m_pXMLNode = pNewXMLElement;
4561 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4562 } else {
4563 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4564 }
dsinclairc5a8f212016-06-20 11:11:12 -07004565 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004566 }
tsepezd19e9122016-11-02 15:43:18 -07004567 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004568}
dsinclair5b36f0a2016-07-19 10:56:23 -07004569
Dan Sinclair1770c022016-03-14 14:14:16 -04004570CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004571 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004572}
dsinclair5b36f0a2016-07-19 10:56:23 -07004573
tsepez736f28a2016-03-25 14:19:51 -07004574CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004575 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4576 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4577 if (pNode->GetNameHash() == dwNameHash) {
4578 return pNode;
4579 }
4580 }
weili44f8faf2016-06-01 14:03:56 -07004581 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004582}
dsinclair5b36f0a2016-07-19 10:56:23 -07004583
dsinclair41cb62e2016-06-23 09:20:32 -07004584CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004585 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4586 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004587 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004588 return pNode;
4589 }
4590 }
weili44f8faf2016-06-01 14:03:56 -07004591 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004592}
dsinclair5b36f0a2016-07-19 10:56:23 -07004593
tsepez736f28a2016-03-25 14:19:51 -07004594CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004595 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4596 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4597 if (pNode->GetNameHash() == dwNameHash) {
4598 return pNode;
4599 }
4600 }
weili44f8faf2016-06-01 14:03:56 -07004601 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004602}
dsinclair5b36f0a2016-07-19 10:56:23 -07004603
Dan Sinclair1770c022016-03-14 14:14:16 -04004604CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4605 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004606 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004607}
dsinclair5b36f0a2016-07-19 10:56:23 -07004608
dsinclair41cb62e2016-06-23 09:20:32 -07004609CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004610 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4611 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004612 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004613 return pNode;
4614 }
4615 }
weili44f8faf2016-06-01 14:03:56 -07004616 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004617}
dsinclair5b36f0a2016-07-19 10:56:23 -07004618
Dan Sinclair1770c022016-03-14 14:14:16 -04004619int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004620 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004621 if (!pScriptContext) {
4622 return -1;
4623 }
4624 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4625}
dsinclair5b36f0a2016-07-19 10:56:23 -07004626
Dan Sinclair1770c022016-03-14 14:14:16 -04004627int32_t CXFA_Node::GetNodeSameClassIndex() 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->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4633}
dsinclair5b36f0a2016-07-19 10:56:23 -07004634
Dan Sinclair1770c022016-03-14 14:14:16 -04004635void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
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;
4639 }
4640 pScriptContext->GetSomExpression(this, wsSOMExpression);
4641}
dsinclair5b36f0a2016-07-19 10:56:23 -07004642
Dan Sinclair1770c022016-03-14 14:14:16 -04004643CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004644 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004645 if (m_ePacket == XFA_XDPPACKET_Form) {
4646 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004647 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004648 return pInstanceMgr;
4649 }
4650 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4651 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004652 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004653 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004654 pNode->m_dwNameHash != m_dwNameHash) {
4655 break;
4656 }
dsinclair56a8b192016-06-21 14:15:25 -07004657 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004658 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4659 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4660 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4661 wsInstName.Mid(1) == wsName) {
4662 pInstanceMgr = pNode;
4663 }
4664 break;
4665 }
4666 }
4667 }
4668 return pInstanceMgr;
4669}
dsinclair5b36f0a2016-07-19 10:56:23 -07004670
Dan Sinclair1770c022016-03-14 14:14:16 -04004671CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004672 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004673}
dsinclair5b36f0a2016-07-19 10:56:23 -07004674
dsinclairc5a8f212016-06-20 11:11:12 -07004675bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4676 if (m_uNodeFlags & dwFlag)
4677 return true;
4678 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4679 return m_pParent && m_pParent->HasFlag(dwFlag);
4680 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004681}
thestigb1a59592016-04-14 18:29:56 -07004682
4683void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004684 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004685 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004686 if (pNotify) {
4687 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004688 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004689 }
dsinclairc5a8f212016-06-20 11:11:12 -07004690 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004691}
thestigb1a59592016-04-14 18:29:56 -07004692
4693void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004694 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004695}
4696
tsepezd19e9122016-11-02 15:43:18 -07004697bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004698 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4699}
thestigb1a59592016-04-14 18:29:56 -07004700
4701void CXFA_Node::OnRemoved(bool bNotify) {
4702 if (!bNotify)
4703 return;
4704
dsinclaira1b07722016-07-11 08:20:58 -07004705 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004706 if (pNotify)
4707 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004708}
thestigb1a59592016-04-14 18:29:56 -07004709
4710void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004711 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004712 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004713 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004714 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004715 }
4716 }
4717}
thestigb1a59592016-04-14 18:29:56 -07004718
Dan Sinclair1770c022016-03-14 14:14:16 -04004719void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004720 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004721 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004722 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004723 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004724 }
4725}
thestigb1a59592016-04-14 18:29:56 -07004726
Dan Sinclair1770c022016-03-14 14:14:16 -04004727int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004728 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004729 int32_t iRet = XFA_EVENTERROR_NotExist;
4730 const XFA_ExecEventParaInfo* eventParaInfo =
4731 GetEventParaInfoByName(wsEventName);
4732 if (eventParaInfo) {
4733 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004734 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004735 if (!pNotify) {
4736 return iRet;
4737 }
4738 if (validFlags == 1) {
4739 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4740 } else if (validFlags == 2) {
4741 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004742 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004743 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004744 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004745 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004746 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004747 }
4748 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004749 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004750 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004751 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004752 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
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 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004757 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004758 }
4759 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004760 if (eType == XFA_Element::Field) {
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 } else if (validFlags == 6) {
4765 CXFA_WidgetData* pWidgetData = GetWidgetData();
4766 if (pWidgetData) {
4767 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004768 if (pUINode->m_elementType == XFA_Element::Signature) {
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 }
4773 } else if (validFlags == 7) {
4774 CXFA_WidgetData* pWidgetData = GetWidgetData();
4775 if (pWidgetData) {
4776 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004777 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004778 (!pWidgetData->IsListBox())) {
4779 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004780 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004781 }
4782 }
4783 }
4784 }
4785 return iRet;
4786}
dsinclair5b36f0a2016-07-19 10:56:23 -07004787
Dan Sinclair1770c022016-03-14 14:14:16 -04004788void CXFA_Node::UpdateNameHash() {
4789 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004790 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004791 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004792 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004793 wsName = GetCData(XFA_ATTRIBUTE_Name);
4794 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004795 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004796 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004797 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004798 }
4799}
dsinclair5b36f0a2016-07-19 10:56:23 -07004800
dsinclairae95f762016-03-29 16:58:29 -07004801CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004802 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004803 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
dsinclairae95f762016-03-29 16:58:29 -07004804 m_pXMLNode = new CFDE_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004805 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004806 }
4807 return m_pXMLNode;
4808}
dsinclair5b36f0a2016-07-19 10:56:23 -07004809
tsepezd19e9122016-11-02 15:43:18 -07004810bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004811 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004812 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004813}
4814
4815XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4816 if (!m_pMapModuleData)
4817 m_pMapModuleData = new XFA_MAPMODULEDATA;
4818 return m_pMapModuleData;
4819}
4820
4821XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4822 return m_pMapModuleData;
4823}
4824
4825void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4826 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004827 pModule->m_ValueMap[pKey] = pValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04004828}
4829
tsepezd19e9122016-11-02 15:43:18 -07004830bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
tsepez6bb3b892017-01-05 12:18:41 -08004831 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004832 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004833 if (pModule) {
4834 auto it = pModule->m_ValueMap.find(pKey);
4835 if (it != pModule->m_ValueMap.end()) {
4836 pValue = it->second;
4837 return true;
4838 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004839 }
tsepez6bb3b892017-01-05 12:18:41 -08004840 if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4841 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004842 }
tsepezd19e9122016-11-02 15:43:18 -07004843 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004844}
dsinclair5b36f0a2016-07-19 10:56:23 -07004845
Dan Sinclair1770c022016-03-14 14:14:16 -04004846void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004847 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair812e96c2017-03-13 16:43:37 -04004848 wsValue.GetLength() * sizeof(wchar_t));
Dan Sinclair1770c022016-03-14 14:14:16 -04004849}
dsinclair5b36f0a2016-07-19 10:56:23 -07004850
tsepezd19e9122016-11-02 15:43:18 -07004851bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004852 void* pValue;
4853 int32_t iBytes;
4854 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004855 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004856 }
Dan Sinclair812e96c2017-03-13 16:43:37 -04004857 wsValue = CFX_WideStringC((const wchar_t*)pValue, iBytes / sizeof(wchar_t));
tsepezd19e9122016-11-02 15:43:18 -07004858 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004859}
dsinclair5b36f0a2016-07-19 10:56:23 -07004860
Dan Sinclair1770c022016-03-14 14:14:16 -04004861void CXFA_Node::SetMapModuleBuffer(
4862 void* pKey,
4863 void* pValue,
4864 int32_t iBytes,
4865 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4866 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4867 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004868 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004869 pBuffer =
4870 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4871 } else if (pBuffer->iBytes != iBytes) {
4872 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4873 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4874 }
4875 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4876 sizeof(XFA_MAPDATABLOCK) + iBytes);
4877 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4878 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4879 }
weili44f8faf2016-06-01 14:03:56 -07004880 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04004881 return;
weili44f8faf2016-06-01 14:03:56 -07004882
Dan Sinclair1770c022016-03-14 14:14:16 -04004883 pBuffer->pCallbackInfo = pCallbackInfo;
4884 pBuffer->iBytes = iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004885 memcpy(pBuffer->GetData(), pValue, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004886}
dsinclair5b36f0a2016-07-19 10:56:23 -07004887
tsepezd19e9122016-11-02 15:43:18 -07004888bool CXFA_Node::GetMapModuleBuffer(void* pKey,
4889 void*& pValue,
4890 int32_t& iBytes,
4891 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07004892 XFA_MAPDATABLOCK* pBuffer = nullptr;
tsepez6bb3b892017-01-05 12:18:41 -08004893 for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004894 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004895 if (pModule) {
4896 auto it = pModule->m_BufferMap.find(pKey);
4897 if (it != pModule->m_BufferMap.end()) {
4898 pBuffer = it->second;
4899 break;
4900 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004901 }
tsepez6bb3b892017-01-05 12:18:41 -08004902 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4903 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004904 }
tsepez6bb3b892017-01-05 12:18:41 -08004905 if (!pBuffer)
tsepezd19e9122016-11-02 15:43:18 -07004906 return false;
tsepez6bb3b892017-01-05 12:18:41 -08004907
Dan Sinclair1770c022016-03-14 14:14:16 -04004908 pValue = pBuffer->GetData();
4909 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07004910 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004911}
dsinclair5b36f0a2016-07-19 10:56:23 -07004912
tsepezd19e9122016-11-02 15:43:18 -07004913bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
tsepez6bb3b892017-01-05 12:18:41 -08004914 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004915 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004916 if (pModule) {
4917 auto it1 = pModule->m_ValueMap.find(pKey);
4918 if (it1 != pModule->m_ValueMap.end())
4919 return true;
4920
4921 auto it2 = pModule->m_BufferMap.find(pKey);
4922 if (it2 != pModule->m_BufferMap.end())
4923 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004924 }
tsepez6bb3b892017-01-05 12:18:41 -08004925 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4926 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004927 }
tsepezd19e9122016-11-02 15:43:18 -07004928 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004929}
dsinclair5b36f0a2016-07-19 10:56:23 -07004930
Dan Sinclair1770c022016-03-14 14:14:16 -04004931void CXFA_Node::RemoveMapModuleKey(void* pKey) {
4932 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
4933 if (!pModule)
4934 return;
4935
4936 if (pKey) {
tsepez6bb3b892017-01-05 12:18:41 -08004937 auto it = pModule->m_BufferMap.find(pKey);
4938 if (it != pModule->m_BufferMap.end()) {
4939 XFA_MAPDATABLOCK* pBuffer = it->second;
Dan Sinclair1770c022016-03-14 14:14:16 -04004940 if (pBuffer) {
tsepez6bb3b892017-01-05 12:18:41 -08004941 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
Dan Sinclair1770c022016-03-14 14:14:16 -04004942 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004943 FX_Free(pBuffer);
4944 }
tsepez6bb3b892017-01-05 12:18:41 -08004945 pModule->m_BufferMap.erase(it);
Dan Sinclair1770c022016-03-14 14:14:16 -04004946 }
tsepez6bb3b892017-01-05 12:18:41 -08004947 pModule->m_ValueMap.erase(pKey);
4948 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04004949 }
tsepez6bb3b892017-01-05 12:18:41 -08004950
4951 for (auto& pair : pModule->m_BufferMap) {
4952 XFA_MAPDATABLOCK* pBuffer = pair.second;
4953 if (pBuffer) {
4954 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
4955 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4956 FX_Free(pBuffer);
4957 }
4958 }
4959 pModule->m_BufferMap.clear();
4960 pModule->m_ValueMap.clear();
4961 delete pModule;
Dan Sinclair1770c022016-03-14 14:14:16 -04004962}
dsinclair5b36f0a2016-07-19 10:56:23 -07004963
tsepez6bb3b892017-01-05 12:18:41 -08004964void CXFA_Node::MergeAllData(void* pDstModule) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004965 XFA_MAPMODULEDATA* pDstModuleData =
4966 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
4967 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004968 if (!pSrcModuleData)
Dan Sinclair1770c022016-03-14 14:14:16 -04004969 return;
tsepez6bb3b892017-01-05 12:18:41 -08004970
4971 for (const auto& pair : pSrcModuleData->m_ValueMap)
4972 pDstModuleData->m_ValueMap[pair.first] = pair.second;
4973
4974 for (const auto& pair : pSrcModuleData->m_BufferMap) {
4975 XFA_MAPDATABLOCK* pSrcBuffer = pair.second;
4976 XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first];
Dan Sinclair1770c022016-03-14 14:14:16 -04004977 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
4978 !pSrcBuffer->pCallbackInfo->pCopy) {
tsepez6bb3b892017-01-05 12:18:41 -08004979 if (pDstBuffer) {
4980 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
4981 pDstModuleData->m_BufferMap.erase(pair.first);
Dan Sinclair1770c022016-03-14 14:14:16 -04004982 }
4983 continue;
4984 }
tsepez6bb3b892017-01-05 12:18:41 -08004985 if (!pDstBuffer) {
4986 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
Dan Sinclair1770c022016-03-14 14:14:16 -04004987 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08004988 } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) {
4989 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
4990 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004991 }
tsepez6bb3b892017-01-05 12:18:41 -08004992 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
4993 uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
4994 } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
4995 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004996 }
tsepez6bb3b892017-01-05 12:18:41 -08004997 if (!pDstBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004998 continue;
4999 }
tsepez6bb3b892017-01-05 12:18:41 -08005000 pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5001 pDstBuffer->iBytes = pSrcBuffer->iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04005002 memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08005003 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) {
5004 pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005005 }
5006 }
5007}
dsinclair5b36f0a2016-07-19 10:56:23 -07005008
Dan Sinclair1770c022016-03-14 14:14:16 -04005009void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5010 if (!pDstModule) {
5011 return;
5012 }
tsepezd19e9122016-11-02 15:43:18 -07005013 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005014 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005015 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005016 }
dsinclair070fcdf2016-06-22 22:04:54 -07005017 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005018 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005019 }
weili44f8faf2016-06-01 14:03:56 -07005020 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5021 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005022 if (bNeedMove) {
5023 pSrcModuleData = GetMapModuleData();
5024 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005025 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005026 }
5027 pDstModuleData = pDstModule->CreateMapModuleData();
5028 }
5029 if (bNeedMove) {
tsepez6bb3b892017-01-05 12:18:41 -08005030 auto it = pSrcModuleData->m_BufferMap.find(pKey);
5031 if (it != pSrcModuleData->m_BufferMap.end()) {
5032 XFA_MAPDATABLOCK* pBufferBlockData = it->second;
5033 if (pBufferBlockData) {
5034 pSrcModuleData->m_BufferMap.erase(pKey);
5035 pDstModuleData->m_BufferMap[pKey] = pBufferBlockData;
5036 }
Dan Sinclair1770c022016-03-14 14:14:16 -04005037 }
5038 }
dsinclairc5a8f212016-06-20 11:11:12 -07005039 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005040 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005041 CFX_WideString wsFormatValue(wsValue);
5042 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5043 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005044 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005045 }
tsepezd19e9122016-11-02 15:43:18 -07005046 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005047 }
5048}
dsinclair5b36f0a2016-07-19 10:56:23 -07005049
Dan Sinclair1770c022016-03-14 14:14:16 -04005050void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5051 CXFA_Node* pDstModule,
5052 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005053 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005054 if (!pSrcModule || !pDstModule || !pKey) {
5055 return;
5056 }
5057 if (bRecursive) {
5058 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5059 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5060 for (; pSrcChild && pDstChild;
5061 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5062 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005063 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005064 }
5065 }
5066 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5067}
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05005068
5069void CXFA_Node::ThrowMissingPropertyException(
5070 const CFX_WideString& obj,
5071 const CFX_WideString& prop) const {
5072 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(),
5073 prop.c_str());
5074}
5075
5076void CXFA_Node::ThrowTooManyOccurancesException(
5077 const CFX_WideString& obj) const {
5078 ThrowException(
5079 L"The element [%s] has violated its allowable number of occurrences.",
5080 obj.c_str());
5081}